/* ==========================================================================
   macOS 27 Golden Gate — компоненты для веб-CRM
   Требует tokens.css. Префикс классов: .m-
   Разделы: 1 База · 2 Стекло · 3 Каркас · 4 Боковая панель · 5 Панель инструментов
            6 Кнопки · 7 Сегменты · 8 Поля · 9 Таблица · 10 Метки · 11 Группы
            12 Меню · 13 Лист · 14 Инспектор · 15 Уведомления · 16 Пусто · 17 Телефон
   ========================================================================== */

/* ---------- 1. База ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  color: var(--label-1);
  background:
    radial-gradient(60% 50% at 0% 0%, var(--wallpaper-glow-1), transparent 70%),
    radial-gradient(50% 60% at 100% 100%, var(--wallpaper-glow-2), transparent 70%),
    var(--wallpaper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-item); }
.m-num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.m-secondary { color: var(--label-2); }
.m-tertiary { color: var(--label-3); }

.m-large-title { font: var(--weight-bold) var(--text-large-title)/var(--leading-tight) var(--font-display); letter-spacing: var(--tracking-display); margin: 0; }
.m-title2 { font: var(--weight-semibold) var(--text-title2)/var(--leading-tight) var(--font-display); letter-spacing: -0.01em; margin: 0; }
.m-title3 { font: var(--weight-semibold) var(--text-title3)/var(--leading-tight) var(--font-sans); margin: 0; }
.m-headline { font-weight: var(--weight-semibold); }
.m-subhead { font-size: var(--text-subhead); color: var(--label-2); }

/* ---------- 2. Стекло ---------- */
/* Только для хрома: боковая панель, панель инструментов, меню, листы, плавающие панели */
.m-glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),        /* яркий блик сверху */
    inset 0 0 0 0.5px var(--glass-highlight-soft),
    0 0 0 0.5px var(--glass-edge);               /* тёмная кромка */
}
.m-glass--float { box-shadow: inset 0 1px 0 var(--glass-highlight), inset 0 0 0 0.5px var(--glass-highlight-soft), var(--shadow-float); }

/* ---------- 3. Каркас ---------- */
/*
  <div class="m-app">
    <aside class="m-sidebar m-glass">…</aside>
    <main class="m-main">
      <header class="m-toolbar">…</header>
      <div class="m-content">…</div>
    </main>
    <aside class="m-inspector">…</aside>   (необязательно)
  </div>
*/
.m-app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) auto;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
.m-main {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface-content);
  box-shadow: -0.5px 0 0 var(--separator);
}
.m-content { flex: 1; overflow: auto; min-height: 0; }
.m-content--padded { padding: var(--space-6); background: var(--surface-window); }

/* ---------- 4. Боковая панель ---------- */
.m-sidebar {
  display: flex; flex-direction: column;
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
  border-radius: 0;                          /* до края окна */
  box-shadow: inset -0.5px 0 0 var(--glass-edge), inset 0 1px 0 var(--glass-highlight);
}
.m-sidebar__brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-4); font-weight: var(--weight-semibold); }
.m-sidebar__section { font-size: var(--text-subhead); font-weight: var(--weight-semibold); color: var(--label-3); padding: var(--space-4) var(--space-2) var(--space-1); }
.m-sidebar__item {
  display: flex; align-items: center; gap: var(--space-2);
  height: 28px; padding: 0 var(--space-2);
  border-radius: var(--radius-item);
  color: var(--label-1); text-decoration: none;
  cursor: default; user-select: none;
}
.m-sidebar__item:hover { background: var(--surface-hover); }
.m-sidebar__item[aria-current="page"] { background: var(--surface-selected-inactive); font-weight: var(--weight-medium); }
.m-sidebar__icon { width: 16px; height: 16px; flex: none; color: var(--icon-color, var(--accent)); stroke-width: 1.75; }
.m-sidebar__count { margin-left: auto; font-size: var(--text-subhead); color: var(--label-2); font-variant-numeric: tabular-nums; }
/* Цветные значки разделов: style="--icon-color: var(--c-green)" */

/* ---------- 5. Панель инструментов (единая) ---------- */
.m-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--space-2);
  height: var(--toolbar-height); padding: 0 var(--space-4);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: 0 0.5px 0 var(--separator);
}
.m-toolbar__title { font: var(--weight-semibold) var(--text-title3)/1 var(--font-display); margin: 0 var(--space-3) 0 0; white-space: nowrap; }
.m-toolbar__subtitle { font-size: var(--text-subhead); color: var(--label-2); margin-left: calc(var(--space-2) * -1); margin-right: var(--space-3); }
.m-toolbar__spacer { flex: 1; }
/* Группа действий — стеклянная капсула */
.m-toolbar__group {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px;
  border-radius: var(--radius-capsule);
  background: var(--surface-control);
  box-shadow: var(--shadow-control);
}

/* ---------- 6. Кнопки ---------- */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-height); padding: 0 var(--space-3);
  font: var(--weight-medium) var(--text-body)/1 var(--font-sans);
  color: var(--label-1);
  background: var(--surface-control);
  border: none; border-radius: var(--radius-control);
  box-shadow: var(--shadow-control);
  cursor: default; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.m-btn:hover { background: color-mix(in srgb, var(--surface-control) 88%, var(--label-1) 6%); }
.m-btn:active { background: var(--surface-control-pressed); transform: scale(0.98); }
.m-btn:disabled { color: var(--label-3); box-shadow: none; }
.m-btn--primary { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 0.5px 1px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.18); }
.m-btn--primary:hover { background: var(--accent-hover); }
.m-btn--danger { color: var(--c-red); }
.m-btn--plain { background: transparent; box-shadow: none; }
.m-btn--plain:hover { background: var(--surface-hover); }
.m-btn--capsule { border-radius: var(--radius-capsule); }
.m-btn--icon { width: var(--control-height); padding: 0; }
.m-btn--lg { height: var(--control-height-lg); padding: 0 var(--space-4); }
.m-btn svg { width: 16px; height: 16px; stroke-width: 1.75; }

/* ---------- 7. Сегменты (переключатель вкладок) ---------- */
.m-segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  border-radius: var(--radius-capsule);
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 0.5px var(--separator);
}
.m-segmented button {
  height: calc(var(--control-height) - 4px); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-capsule);
  background: transparent; color: var(--label-2);
  font: var(--weight-medium) var(--text-callout)/1 var(--font-sans);
  cursor: default;
}
.m-segmented button[aria-pressed="true"] {
  background: var(--surface-control); color: var(--label-1);
  box-shadow: var(--shadow-control);
}

/* ---------- 8. Поля ---------- */
.m-field { display: grid; gap: var(--space-1); }
.m-field__label { font-size: var(--text-subhead); color: var(--label-2); font-weight: var(--weight-medium); }
.m-input, .m-select, .m-textarea {
  width: 100%; height: var(--control-height);
  padding: 0 var(--space-2);
  font: var(--text-body)/1 var(--font-sans); color: var(--label-1);
  background: var(--surface-control);
  border: 0.5px solid var(--border-control); border-radius: var(--radius-control);
  box-shadow: inset 0 0.5px 1px rgba(0,0,0,.05);
  transition: box-shadow var(--dur-fast) var(--ease);
}
.m-textarea { height: auto; min-height: 72px; padding: var(--space-2); line-height: var(--leading-body); resize: vertical; }
.m-input:focus, .m-select:focus, .m-textarea:focus { outline: none; box-shadow: var(--focus-ring); border-color: var(--accent); }
.m-input[aria-invalid="true"] { border-color: var(--c-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-red) 25%, transparent); }
.m-field__hint { font-size: var(--text-subhead); color: var(--label-2); }
.m-field__error { font-size: var(--text-subhead); color: var(--c-red); }

/* Поиск — капсула на панели инструментов */
.m-search { position: relative; width: 220px; }
.m-search input { height: var(--control-height); width: 100%; padding: 0 var(--space-3) 0 28px; border-radius: var(--radius-capsule); border: 0; background: var(--surface-hover); color: var(--label-1); font: var(--text-body)/1 var(--font-sans); }
.m-search input::placeholder { color: var(--label-3); }
.m-search input:focus { outline: none; background: var(--surface-control); box-shadow: var(--focus-ring); }
.m-search svg { position: absolute; left: 9px; top: 50%; translate: 0 -50%; width: 14px; height: 14px; color: var(--label-2); }

/* Переключатель (да/нет) */
.m-switch { appearance: none; width: 32px; height: 18px; border-radius: 999px; background: var(--label-4); position: relative; transition: background var(--dur-fast) var(--ease); cursor: default; margin: 0; }
.m-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: translate var(--dur-fast) var(--ease); }
.m-switch:checked { background: var(--c-green); }
.m-switch:checked::after { translate: 14px 0; }

/* ---------- 9. Таблица (сплошной фон, без стекла) ---------- */
.m-table-wrap { overflow: auto; }
.m-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-body); }
.m-table thead th {
  position: sticky; top: 0; z-index: 2;
  height: 28px; padding: 0 var(--space-3);
  text-align: left; font-size: var(--text-subhead); font-weight: var(--weight-semibold); color: var(--label-2);
  background: color-mix(in srgb, var(--surface-content) 94%, transparent);   /* без размытия */
  box-shadow: inset 0 -0.5px 0 var(--separator-strong);
  white-space: nowrap; user-select: none;
}
.m-table thead th[aria-sort] { color: var(--label-1); }
.m-table tbody td {
  height: var(--row-height); padding: 0 var(--space-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px;
}
.m-table tbody tr:nth-child(even) td { background: var(--surface-alt-row); }   /* чередование, как в Finder */
.m-table tbody tr:hover td { background: var(--surface-hover); }
.m-table tbody td:first-child { border-radius: var(--radius-item) 0 0 var(--radius-item); }
.m-table tbody td:last-child { border-radius: 0 var(--radius-item) var(--radius-item) 0; }
.m-table .m-num, .m-table th.m-num { text-align: right; font-variant-numeric: tabular-nums; }
/* Выделение: акцент, когда фокус в таблице; серое — когда фокус ушёл */
.m-table tbody tr[aria-selected="true"] td { background: var(--surface-selected-inactive); }
.m-table:focus-within tbody tr[aria-selected="true"] td { background: var(--accent); color: var(--accent-contrast); }
.m-table:focus-within tbody tr[aria-selected="true"] .m-badge { background: rgba(255,255,255,.22); color: #fff; }
.m-table:focus-within tbody tr[aria-selected="true"] .m-secondary { color: rgba(255,255,255,.8); }
.m-table:focus { outline: none; }
.m-table-inset { padding: 0 var(--space-2) var(--space-4); }   /* поля по бокам, чтобы скругление строк было видно */

/* ---------- 10. Метки статусов ---------- */
/* <span class="m-badge" style="--badge: var(--c-green)">Активен</span> */
.m-badge {
  --badge: var(--c-gray);
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 7px;
  font-size: var(--text-subhead); font-weight: var(--weight-semibold);
  color: color-mix(in srgb, var(--badge) 78%, var(--label-1));
  background: color-mix(in srgb, var(--badge) 14%, transparent);
  border-radius: var(--radius-badge);
  white-space: nowrap;
}
.m-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--badge, var(--c-gray)); flex: none; }

/* ---------- 11. Группы (как в «Системных настройках») ---------- */
/*
  <section class="m-group">
    <h3 class="m-group__title">Абонемент</h3>
    <div class="m-group__box">
      <div class="m-row"><span>Тип</span><span class="m-row__value">8 занятий</span></div>
    </div>
  </section>
*/
.m-group { margin-bottom: var(--space-5); }
.m-group__title { font-size: var(--text-body); font-weight: var(--weight-semibold); margin: 0 0 var(--space-2) var(--space-1); }
.m-group__box { background: var(--surface-group); border-radius: var(--radius-group); box-shadow: var(--shadow-group); overflow: hidden; }
.m-row { display: flex; align-items: center; gap: var(--space-3); min-height: 36px; padding: var(--space-2) var(--space-3); }
.m-row + .m-row { box-shadow: inset 0 0.5px 0 var(--separator); }
.m-row__value { margin-left: auto; color: var(--label-2); text-align: right; font-variant-numeric: tabular-nums; }
.m-row--link { cursor: default; }
.m-row--link:hover { background: var(--surface-hover); }

/* Показатель сводки — внутри .m-group__box, не отдельная «карточка с градиентом» */
.m-stat { padding: var(--space-3) var(--space-4); }
.m-stat__label { font-size: var(--text-subhead); color: var(--label-2); }
.m-stat__value { font: var(--weight-semibold) var(--text-title1)/1.1 var(--font-display); letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums; margin-top: 2px; }
.m-stat__delta { font-size: var(--text-subhead); font-weight: var(--weight-medium); }
.m-stat__delta--up { color: var(--c-green); }
.m-stat__delta--down { color: var(--c-red); }
.m-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.m-stats > .m-stat + .m-stat { box-shadow: inset 0.5px 0 0 var(--separator); }

/* ---------- 12. Меню ---------- */
.m-menu {
  min-width: 200px; padding: 5px;
  border-radius: var(--radius-group);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-float);
  animation: m-pop var(--dur-fast) var(--ease);
}
.m-menu__item { display: flex; align-items: center; gap: var(--space-2); height: 26px; padding: 0 var(--space-2); border-radius: var(--radius-item); cursor: default; }
.m-menu__item:hover, .m-menu__item:focus { background: var(--accent); color: var(--accent-contrast); outline: none; }
.m-menu__item--danger { color: var(--c-red); }
.m-menu__shortcut { margin-left: auto; color: var(--label-3); font-size: var(--text-callout); }
.m-menu__sep { height: 0.5px; margin: 5px var(--space-2); background: var(--separator-strong); }
@keyframes m-pop { from { opacity: 0; transform: scale(.97) translateY(-2px); } to { opacity: 1; transform: none; } }

/* ---------- 13. Лист (модальное окно) ---------- */
.m-sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.18); display: grid; place-items: start center; padding-top: calc(var(--toolbar-height) + var(--space-2)); animation: m-fade var(--dur-base) var(--ease); }
.m-sheet {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - var(--toolbar-height) - 48px);
  display: flex; flex-direction: column;
  border-radius: var(--radius-window);
  background: rgba(var(--glass-rgb), max(var(--glass-alpha), 0.9));   /* лист плотнее: внутри форма */
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-sheet);
  animation: m-drop var(--dur-base) var(--ease);
}
.m-sheet__body { padding: var(--space-5); overflow: auto; display: grid; gap: var(--space-4); }
.m-sheet__footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5) var(--space-4); }
@keyframes m-fade { from { opacity: 0; } }
@keyframes m-drop { from { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* ---------- 14. Инспектор (панель справа: карточка клиента, сделки) ---------- */
.m-inspector {
  width: var(--inspector-width); overflow-y: auto;
  background: var(--surface-window);
  box-shadow: inset 0.5px 0 0 var(--separator);
  padding: var(--space-4);
}
.m-inspector[hidden] { display: none; }
.m-inspector__head { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-5); }
.m-avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: var(--weight-semibold); color: #fff; background: var(--avatar, var(--c-indigo)); flex: none; }
.m-avatar--sm { width: 22px; height: 22px; font-size: 10px; }

/* ---------- 15. Уведомления ---------- */
.m-toast {
  position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 60;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-group);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  box-shadow: inset 0 1px 0 var(--glass-highlight), var(--shadow-float);
  animation: m-drop var(--dur-base) var(--ease);
}

/* ---------- 16. Пустое состояние ---------- */
.m-empty { display: grid; place-items: center; gap: var(--space-2); padding: var(--space-10) var(--space-4); text-align: center; color: var(--label-2); }
.m-empty svg { width: 36px; height: 36px; color: var(--label-3); stroke-width: 1.5; }
.m-empty__title { font-size: var(--text-title3); font-weight: var(--weight-semibold); color: var(--label-1); }

/* ---------- 17. Телефон и узкие экраны ---------- */
@media (max-width: 1100px) {
  .m-app { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .m-inspector { position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow-sheet); }
}
@media (max-width: 760px) {
  .m-app { grid-template-columns: 1fr; }
  .m-sidebar { position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); z-index: 45; transform: translateX(-100%); transition: transform var(--dur-base) var(--ease); }
  .m-app[data-sidebar="open"] .m-sidebar { transform: none; box-shadow: var(--shadow-sheet); }
  .m-inspector { width: 100%; }
  .m-search { width: auto; flex: 1; }
  .m-toolbar { padding: 0 var(--space-3); }
  .m-toolbar__subtitle { display: none; }
  .m-table .m-hide-mobile { display: none; }
}
