/* ===========================================================================
   Вафелька — Admin Panel · iOS-style 2026
   Palette: mocha + cream brand colors, iOS structure (grouped inset lists,
   hairline separators, system font, native-feeling toggles & sliders).
   ========================================================================= */

/* Inter (self-hosted variable woff2) — latin + cyrillic, без внешних зависимостей */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  color-scheme: light;

  /* Нейтральная чёрно-белая шкала — единственный источник цвета панели */
  --n-50:#fafafa; --n-100:#f5f5f5; --n-200:#e5e5e5; --n-300:#d4d4d4;
  --n-400:#a3a3a3; --n-500:#737373; --n-600:#525252; --n-700:#404040;
  --n-800:#262626; --n-900:#171717; --white:#ffffff;

  /* Канвас + карточки */
  --ios-bg:        var(--n-50);
  --ios-bg-soft:   var(--n-100);
  --ios-card:      #ffffff;
  --ios-card-sub:  var(--n-50);
  --ios-sep:       var(--n-200);
  --ios-sep-strong: var(--n-300);

  /* Текст: ink / secondary / footnote / faint */
  --c-text:        var(--n-900);
  --c-text-2:      var(--n-600);
  --c-text-3:      var(--n-500);
  --c-text-soft:   var(--n-400);
  /* совместимость со старыми именами из шаблонов (были «битые») */
  --c-surface-2:   var(--n-100);
  --c-surface-3:   var(--n-200);
  --text-soft:     var(--n-400);

  /* Акцент = чернила (единственный «цвет»: primary-кнопки, активная навигация, аватары) */
  --c-accent:      var(--n-900);
  --c-accent-2:    var(--n-700);
  --c-accent-soft: var(--n-100);
  --c-accent-warm: var(--n-200);

  /* Статусные цвета — только функционально и тонко */
  --c-ok:          #16a34a;  --c-ok-soft:     #dcfce7;
  --c-warn:        #d97706;  --c-warn-soft:   #fef3c7;
  --c-danger:      #dc2626;  --c-danger-soft: #fee2e2;
  --c-info:        var(--n-600);

  /* Icon-squircles → монохром */
  --ic-blue:#262626; --ic-green:#262626; --ic-orange:#262626; --ic-pink:#262626;
  --ic-purple:#262626; --ic-yellow:#262626; --ic-mocha:#262626;

  /* Радиусы (компактнее под admin) */
  --r-xs: 6px;  --r-sm: 8px;  --r-md: 10px;  --r-lg: 12px;  --r-xl: 14px;  --r-pill: 9999px;

  /* Spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 44px;

  /* Тени — нейтральные, stacked + лёгкий inset-ring */
  --sh-sm: 0 1px 2px rgba(0,0,0,.04);
  --sh-md: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px -4px rgba(0,0,0,.08);
  --sh-lg: 0 16px 40px -16px rgba(0,0,0,.18), 0 4px 10px -4px rgba(0,0,0,.06);

  /* Типографика */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--c-text);
  background: var(--ios-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss03", "cv02";
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: .92em; background: var(--ios-bg-soft); padding: .1em .35em; border-radius: 4px; }
::selection { background: var(--c-accent-soft); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ios-card);
  border-right: 1px solid var(--ios-sep);
  padding: 18px 12px 12px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--ios-sep);
  margin-bottom: 12px;
}
.brand-mark {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-2));
  border-radius: 11px;
  display: grid; place-items: center;
  color: white;
  box-shadow: var(--sh-sm);
}
.brand-mark i { width: 22px; height: 22px; }
.auth-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 60px; height: 60px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-2));
  color: #fff;
  box-shadow: var(--sh-md);
}
.auth-logo i { width: 30px; height: 30px; }
.brand-name {
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.brand-sub { font-size: 11.5px; color: var(--c-text-3); letter-spacing: .04em; }

.nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
.nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--c-text-3); font-weight: 600;
  padding: 14px 12px 4px;
}
.nav-section:first-child { margin-top: 0; padding-top: 4px; }

/* Свёрнутый раздел «Для разработчика» — техническое прячется от Виты */
.nav-dev { margin-top: 10px; border-top: 1px solid var(--ios-sep); padding-top: 2px; }
.nav-dev > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--c-text-3); font-weight: 600;
  padding: 12px 12px 6px;
}
.nav-dev > summary::-webkit-details-marker { display: none; }
.nav-dev > summary::marker { content: ""; }
.nav-dev > summary i { width: 14px; height: 14px; }
.nav-dev > summary .nav-dev-chev { margin-left: auto; transition: transform .15s; }
.nav-dev[open] > summary .nav-dev-chev { transform: rotate(180deg); }
.nav-dev > summary:hover { color: var(--c-text); }

/* Переключатель вкладок внутри раздела (рационы и т.п.) */
.seg { display: inline-flex; gap: 2px; background: var(--ios-bg-soft); border: 1px solid var(--ios-sep); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg a { padding: 7px 14px; border-radius: 8px; font-size: .9rem; font-weight: 600; color: var(--c-text-2); text-decoration: none; white-space: nowrap; }
.seg a.on { background: var(--ios-card); color: var(--c-text); box-shadow: var(--sh-sm); }
.seg a:hover { text-decoration: none; color: var(--c-text); }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-weight: 500; font-size: 14.5px;
  transition: background .12s, color .12s, transform .08s;
}
.nav-item:hover { background: var(--ios-bg-soft); text-decoration: none; }
.nav-item.is-active {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}
.nav-item.is-active span { color: var(--c-text); }
.nav-item i { width: 18px; height: 18px; color: var(--c-text-2); flex-shrink: 0; }
.nav-item.is-active i { color: var(--c-accent); }

.sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--ios-sep); }
.bot-state {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--r-sm);
  background: var(--ios-bg-soft);
  font-size: 13px; color: var(--c-text-2);
  margin-bottom: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--c-text-soft); }
.dot.on  { background: var(--c-ok);     box-shadow: 0 0 0 4px rgba(76, 175, 131, .18); }
.dot.off { background: var(--c-danger); box-shadow: 0 0 0 4px rgba(220, 38, 38, .18); }
.logout button { width: 100%; }

/* ---------- Top bar / content ---------- */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 30px;
  background: rgba(250, 250, 250, .82);
  backdrop-filter: saturate(170%) blur(14px);
  -webkit-backdrop-filter: saturate(170%) blur(14px);
  border-bottom: 1px solid var(--ios-sep);
}
.topbar-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.topbar-right { margin-left: auto; }
.hello { color: var(--c-text-2); font-size: 13px; }
.burger {
  display: none; background: none; border: 1px solid var(--ios-sep);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
}
.page {
  padding: 22px 28px 60px;
  flex: 1;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}
.footer { padding: 18px 30px; color: var(--c-text-soft); font-size: 12px; text-align: center; }

/* ---------- iOS Large Title ---------- */
.large-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.subtitle {
  color: var(--c-text-2);
  font-size: 14px;
  margin: 0 0 22px;
}

/* ===========================================================================
   iOS Grouped Inset List — основа всех настроек/контента
   ========================================================================= */

.ios-section { margin: 0 0 28px; }
.ios-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-3);
  padding: 6px 16px 8px;
}
.ios-section-footer {
  font-size: 12.5px;
  color: var(--c-text-2);
  padding: 8px 16px 0;
  line-height: 1.45;
}

.ios-card {
  background: var(--ios-card);
  border-radius: var(--r-lg);
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

.ios-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding: 11px 16px;
  background: var(--ios-card);
  position: relative;
}
.ios-row + .ios-row {
  /* hairline separator, начинающийся ПОСЛЕ иконки */
  box-shadow: inset 52px .5px 0 -.5px var(--ios-sep);
}
.ios-row.no-indent + .ios-row {
  box-shadow: inset 0 .5px 0 -.5px var(--ios-sep);
}

.ios-row .icon {
  width: 29px; height: 29px;
  border-radius: 7px;
  display: inline-grid; place-items: center;
  color: white;
  background: var(--ic-mocha);
  flex-shrink: 0;
}
.ios-row .icon i { width: 17px; height: 17px; }
.ios-row .icon.blue   { background: var(--ic-blue); }
.ios-row .icon.green  { background: var(--ic-green); }
.ios-row .icon.orange { background: var(--ic-orange); }
.ios-row .icon.pink   { background: var(--ic-pink); }
.ios-row .icon.purple { background: var(--ic-purple); }
.ios-row .icon.yellow { background: var(--ic-yellow); color: #5a3e00; }
.ios-row .icon.mocha  { background: var(--c-accent); }

.ios-row .label {
  flex: 1 1 0;
  min-width: 0;          /* критично: иначе flex-item не сжимается и текст идёт по букве */
  font-size: 15.5px;
  color: var(--c-text);
  word-break: normal;
  overflow-wrap: anywhere;
}
.ios-row .label-sub {
  font-size: 12.5px;
  color: var(--c-text-2);
  margin-top: 2px;
  line-height: 1.35;
  word-break: normal;
  overflow-wrap: break-word;
}
.ios-row > * { min-width: 0; }
.ios-row .ios-input-inline { max-width: 60%; }
.ios-row .ios-switch, .ios-row .icon { min-width: auto; flex-shrink: 0; }
.ios-row .value {
  color: var(--c-text-2);
  font-size: 14.5px;
  font-variant-numeric: tabular-nums;
}
.ios-row .chev {
  color: var(--c-text-3); font-size: 18px; font-weight: 600;
  margin-left: 4px;
}

/* iOS row as link (clickable) */
a.ios-row { color: inherit; }
a.ios-row:hover { background: var(--ios-bg-soft); text-decoration: none; }

/* Row with vertical content (slider, control under label) */
.ios-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 16px 16px;
}
.ios-row-stack .row-head {
  display: flex; align-items: center; gap: 12px;
}
.ios-row-stack .row-head .label { flex: 1; }
.ios-row-stack .row-control { width: 100%; }
.ios-row-stack + .ios-row { box-shadow: inset 0 .5px 0 -.5px var(--ios-sep); }
.ios-row + .ios-row-stack { box-shadow: inset 0 .5px 0 -.5px var(--ios-sep); }

/* ===========================================================================
   iOS Toggle (switch)
   ========================================================================= */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 51px; height: 31px;
  flex-shrink: 0;
}
.ios-switch input {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.ios-switch .slider {
  position: absolute; inset: 0;
  background: #E9E9EA;
  border-radius: 9999px;
  cursor: pointer;
  transition: background .2s ease;
}
.ios-switch .slider::before {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.06);
  transition: transform .22s cubic-bezier(.3,.1,.4,1.6);
}
.ios-switch input:checked + .slider {
  background: var(--c-accent);
}
.ios-switch input:checked + .slider::before {
  transform: translateX(20px);
}
.ios-switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px var(--c-accent-soft);
}

/* Legacy .toggle class — переадресуется на iOS */
.toggle {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  padding: 10px; border-radius: var(--r-sm);
  background: var(--ios-card-sub); border: 1px solid var(--ios-sep);
}
.toggle input { display: none; }
.toggle .slider {
  position: relative; width: 51px; height: 31px;
  background: #E9E9EA; border-radius: 9999px;
  transition: background .2s; flex-shrink: 0;
}
.toggle .slider::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: white;
  transition: transform .22s cubic-bezier(.3,.1,.4,1.6);
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.06);
}
.toggle input:checked + .slider { background: var(--c-accent); }
.toggle input:checked + .slider::after { transform: translateX(20px); }
.toggle-label { font-weight: 500; }

/* ===========================================================================
   iOS Slider (range)
   ========================================================================= */
.ios-slider-wrap {
  position: relative;
  padding: 4px 0 22px;
}
.ios-slider-wrap .slider-meta {
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--c-text-3);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.ios-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(
    to right,
    var(--c-accent) 0 var(--val, 50%),
    #E5E5EA var(--val, 50%) 100%
  );
  border-radius: 9999px;
  outline: none;
  margin: 0;
}
.ios-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 0 0 .5px rgba(0,0,0,.04),
    0 3px 8px rgba(0,0,0,.18),
    0 1px 1px rgba(0,0,0,.04);
  border: 0;
  cursor: pointer;
}
.ios-slider::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 .5px rgba(0,0,0,.04), 0 3px 8px rgba(0,0,0,.18);
  border: 0; cursor: pointer;
}
.ios-slider::-webkit-slider-thumb:active,
.ios-slider::-moz-range-thumb:active { transform: scale(1.08); }
.ios-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px var(--c-accent-soft), 0 3px 8px rgba(0,0,0,.18);
}

.ios-slider-bubble {
  position: absolute;
  bottom: 100%;
  transform: translateX(-50%) translateY(-4px);
  background: var(--c-accent);
  color: white;
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  white-space: nowrap;
}
.ios-slider-wrap.show-bubble .ios-slider-bubble { opacity: 1; }

/* ===========================================================================
   iOS Time Range (два time-picker'а: от — до)
   ========================================================================= */
.ios-time-range {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.ios-time-range .tp-label {
  font-size: 13px; color: var(--c-text-2); flex-shrink: 0;
}
.ios-time-range input[type="time"] {
  width: auto;
  min-width: 110px;
  padding: 8px 12px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  background: var(--ios-card-sub);
  border: 1px solid var(--ios-sep-strong);
  border-radius: var(--r-sm);
  color: var(--c-text);
}
.ios-time-range .tp-sep { color: var(--c-text-3); }

/* Inline time picker внутри ios-row (одна настройка времени) */
.ios-time-inline {
  width: 130px;
  padding: 8px 12px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  background: var(--ios-card-sub);
  border: 1px solid var(--ios-sep-strong);
  border-radius: var(--r-sm);
  color: var(--c-text);
  text-align: center;
}

/* ===========================================================================
   iOS Segmented Control
   ========================================================================= */
.ios-segmented {
  display: inline-flex;
  background: #E9E9EB;
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.ios-segmented label {
  position: relative;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--c-text);
  transition: background .15s, color .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.ios-segmented input {
  position: absolute; opacity: 0; pointer-events: none;
}
.ios-segmented label:has(input:checked) {
  background: var(--ios-card);
  box-shadow:
    0 3px 8px -2px rgba(0,0,0,.12),
    0 0 0 .5px rgba(0,0,0,.04);
  color: var(--c-text);
}

/* ===========================================================================
   Buttons (iOS-ish)
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  font: 600 14.5px/1 var(--font);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--ios-bg-soft);
  color: var(--c-text);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .12s, background .12s, color .12s;
  min-height: 36px;
}
.btn:active { transform: scale(.98); }
.btn i { width: 16px; height: 16px; }
.btn-primary {
  background: var(--c-accent);
  color: white;
  box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .16);
}
.btn-primary:hover { background: #cf6c4d; }
.btn-ghost {
  background: transparent;
  border-color: var(--ios-sep-strong);
  color: var(--c-text);
}
.btn-ghost:hover { background: var(--ios-bg-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; min-height: 30px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn-ghost.danger { color: var(--c-danger); border-color: var(--c-danger-soft); }
.btn-ghost.danger:hover { background: var(--c-danger-soft); }

/* ===========================================================================
   Forms — inputs adopt iOS look
   ========================================================================= */
.form .field, .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 12.5px; color: var(--c-text-2); font-weight: 500; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input:not([type]), select, textarea {
  width: 100%;
  background: var(--ios-card);
  border: 1px solid var(--ios-sep-strong);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font: 400 15px/1.45 var(--font);
  color: var(--c-text);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-soft);
}
textarea { resize: vertical; min-height: 100px; }
textarea.textarea-xl { min-height: 280px; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.55; }

/* Compact inline input (used in iOS row stack) */
.ios-input-inline {
  background: transparent;
  border: 0;
  text-align: right;
  color: var(--c-text-2);
  font-size: 14.5px;
  padding: 0;
  width: auto;
  font-variant-numeric: tabular-nums;
}
.ios-input-inline:focus {
  outline: none; box-shadow: none;
  color: var(--c-text);
}

.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.form-actions.between { justify-content: space-between; }
.hint { color: var(--c-text-2); font-size: 12.5px; }
.form-stack > * { margin-bottom: 18px; }

/* ===========================================================================
   Cards / KPIs (kept for dashboard backward compat)
   ========================================================================= */
.card {
  background: var(--ios-card);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--sh-sm);
  margin-bottom: 18px;
}
.card h2 {
  margin: 0; font-weight: 700; font-size: 17px; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 9px;
}
.card h2 i { color: var(--c-accent); width: 18px; height: 18px; }
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 16px;
}
.card-sub { color: var(--c-text-2); font-size: 13px; margin-top: 4px; line-height: 1.4; }
.card-aside { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--ios-card);
  border-radius: var(--r-lg);
  padding: 16px 18px 14px;
  box-shadow: var(--sh-sm);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--c-accent), var(--c-accent-2));
}
.kpi-label { color: var(--c-text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi-value { font-weight: 700; font-size: 28px; letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi-foot { color: var(--c-text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.kpi-foot i { width: 13px; height: 13px; color: var(--c-accent); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; }
.grid-2-tight { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) { .grid-2-tight { grid-template-columns: 1fr; } }

/* ===========================================================================
   Tables (kept for users / messages / topics)
   ========================================================================= */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--c-text-3); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--ios-sep);
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--ios-sep);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--ios-bg-soft); }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--c-text-2); font-size: 12px; font-family: var(--font-mono); }
.actions { display: flex; gap: 6px; align-items: center; }
.empty { color: var(--c-text-2); text-align: center; padding: 28px 16px; }
.empty-block { background: var(--ios-bg-soft); border-radius: var(--r-md); padding: 18px; line-height: 1.55; }

/* ===========================================================================
   Badges & chips
   ========================================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 9999px;
  font-size: 11px; font-weight: 600; text-transform: lowercase;
}
.badge-ok { background: var(--c-ok-soft); color: #2b6b50; }
.badge-warn { background: var(--c-warn-soft); color: #7a5113; }
.badge-danger { background: var(--c-danger-soft); color: #803121; }
.badge-muted { background: var(--ios-bg-soft); color: var(--c-text-2); }
.badge-soft { background: #f6dede; color: #8a3f3f; }
.badge-soft-warm { background: var(--c-accent-soft); color: #7a3f23; }
.badge-tier-lite { background: #e8f0fe; color: #2c5dab; font-variant-numeric: tabular-nums; }
.badge-tier-full { background: #f3e8ff; color: #6b21a8; font-variant-numeric: tabular-nums; }
.dm-bubble-tag.tag-tier-lite { color: #2c5dab; }
.dm-bubble-tag.tag-tier-full { color: #6b21a8; }
.chip {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 9999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--ios-bg-soft); color: var(--c-text-2);
}
.chip-soft { background: var(--c-accent-soft); color: #803a1c; }

/* ===========================================================================
   Messages feed / chat
   ========================================================================= */
.msg-feed, .msg-list { display: flex; flex-direction: column; gap: 10px; max-height: 700px; overflow-y: auto; }
.msg-feed-tall { max-height: 70vh; }
.msg {
  padding: 12px 14px;
  background: var(--ios-card);
  border: 1px solid var(--ios-sep);
  border-radius: var(--r-md);
}
.msg-user { background: var(--ios-card); }
.msg-assistant {
  background: linear-gradient(135deg, #fff7ef 0%, #fcebdc 100%);
  border-color: var(--c-accent-warm);
}
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.msg-author { font-weight: 600; }
.msg-time { color: var(--c-text-soft); font-size: 11.5px; margin-left: auto; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-foot { color: var(--c-text-soft); font-size: 11px; margin-top: 4px; }

/* ===========================================================================
   Detail grid (user profile / DM detail)
   ========================================================================= */
.grid-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 1fr);
  gap: 18px;
}
@media (max-width: 1100px) { .grid-detail { grid-template-columns: 1fr; } }
.col-right { display: flex; flex-direction: column; gap: 18px; }

/* Coach panel (DM user detail) */
.card-coach {
  background: linear-gradient(180deg, #fff 0%, #fef3e7 100%);
  border-color: var(--c-accent-warm);
}
.coach-feed {
  max-height: 360px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding-right: 4px; margin-bottom: 12px;
}
.coach-note {
  background: white;
  border: 1px solid var(--ios-sep);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  transition: opacity .2s;
}
.coach-note.is-off { opacity: .45; background: var(--ios-bg-soft); }
.coach-row { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; }
.coach-row + .coach-row { border-top: 1px dashed var(--ios-sep); padding-top: 6px; margin-top: 4px; }
.coach-tag {
  flex-shrink: 0; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 5px;
  background: var(--ios-bg-soft); color: var(--c-text-2);
}
.coach-tag.tag-ai { background: var(--c-accent-soft); color: #803a1c; }
.coach-tag.tag-inst { background: #e9e4f6; color: #4d3a8c; }
.coach-text { flex: 1; line-height: 1.45; word-wrap: break-word; min-width: 0; }
.coach-time { color: var(--c-text-soft); font-size: 11px; margin-left: auto; flex-shrink: 0; }
.coach-actions {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--ios-sep);
}
.mini-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--c-text-2); cursor: pointer;
}
.mini-toggle input { accent-color: var(--c-accent); }
.coach-form { display: flex; flex-direction: column; gap: 8px; }
.coach-form textarea { font-size: 13.5px; min-height: 70px; }
.coach-form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ===========================================================================
   DM chat split view (iOS Messages-like)
   ========================================================================= */
.dm-chat {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 200px);
  min-height: 540px;
}
.dm-list {
  background: var(--ios-card);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.dm-list-head {
  padding: 14px 16px 8px;
  font-size: 12px; font-weight: 600;
  color: var(--c-text-3);
  text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--ios-sep);
}
.dm-list-body {
  list-style: none; padding: 4px; margin: 0;
  overflow-y: auto;
  flex: 1;
}
.dm-list-body li { padding: 0; margin: 0; }
.dm-list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--c-text);
  text-decoration: none;
  margin-bottom: 1px;
  min-height: 56px;
}
.dm-list-item:hover { background: var(--ios-bg-soft); text-decoration: none; }
.dm-list-item.is-active {
  background: var(--c-accent-soft);
}
.dm-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent-warm), var(--c-accent-soft));
  color: var(--c-accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.dm-avatar.lg {
  width: 46px; height: 46px;
  font-size: 18px;
}
.dm-list-item.is-active .dm-avatar {
  background: var(--c-accent);
  color: white;
}
.dm-item-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.dm-item-name {
  font-size: 14.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dm-item-meta {
  font-size: 12px; color: var(--c-text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dm-item-time {
  font-size: 11px; color: var(--c-text-3);
  flex-shrink: 0; align-self: flex-start; margin-top: 2px;
}

.dm-thread {
  background: var(--ios-card);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.dm-thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--ios-sep);
  background: rgba(250, 250, 250, .6);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
}
.dm-thread-meta { flex: 1; min-width: 0; }
.dm-thread-name {
  font-size: 16px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dm-thread-sub {
  font-size: 12.5px; color: var(--c-text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dm-thread-body {
  flex: 1;
  padding: 16px 18px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--ios-card-sub);
}
.dm-bubble {
  max-width: 76%;
  padding: 9px 13px;
  border-radius: 17px;
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}
.dm-bubble-content {
  white-space: pre-wrap;
}
.dm-bubble-time {
  font-size: 10.5px;
  color: var(--c-text-3);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.dm-bubble-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px;
  color: var(--c-text-2);
  margin-bottom: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.dm-bubble-tag i { width: 12px; height: 12px; }
.dm-bubble-tag.tag-proactive { color: var(--c-accent); }
/* Reply от подружки — слева, серое */
.dm-bubble-user {
  align-self: flex-start;
  background: #e9e5df;
  color: var(--c-text);
  border-bottom-left-radius: 5px;
}
.dm-bubble-user .dm-bubble-time { text-align: left; }
/* Reply от Вафельки — справа, мокко */
.dm-bubble-bot {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-2));
  color: #fff;
  border-bottom-right-radius: 5px;
}
.dm-bubble-bot .dm-bubble-time { text-align: right; color: rgba(255, 255, 255, .75); }
.dm-bubble-bot .dm-bubble-tag { color: rgba(255, 255, 255, .85); }

@media (max-width: 900px) {
  .dm-chat { grid-template-columns: 1fr; height: auto; }
  .dm-list { max-height: 280px; }
  .dm-thread { min-height: 60vh; }
}

/* ===========================================================================
   Quick presets (settings page)
   ========================================================================= */
.presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.preset {
  background: var(--ios-card);
  border: 1px solid var(--ios-sep);
  border-radius: var(--r-md);
  padding: 14px;
  cursor: pointer;
  transition: transform .08s, box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column; gap: 6px;
  text-align: left;
  font-family: inherit;
}
.preset:hover {
  transform: translateY(-1px);
  box-shadow: var(--sh-md);
  border-color: var(--c-accent-warm);
}
.preset.active {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
}
.preset .preset-emoji {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--c-accent-soft);
  color: var(--c-accent);
}
.preset .preset-emoji i { width: 20px; height: 20px; }
.preset.active .preset-emoji {
  background: var(--c-accent);
  color: #fff;
}
.preset .preset-name { font-weight: 700; font-size: 14.5px; }
.preset .preset-desc { color: var(--c-text-2); font-size: 12.5px; line-height: 1.4; }

/* ===========================================================================
   Live preview box (shows current behavior summary)
   ========================================================================= */
.preview-box {
  background: linear-gradient(135deg, #fff7ef 0%, #f6e3d8 100%);
  border-radius: var(--r-md);
  padding: 14px 16px;
  font-size: 13.5px;
  color: var(--c-text);
  margin-bottom: 14px;
  border: 1px solid var(--c-accent-warm);
}
.preview-box strong { color: var(--c-text); }
.preview-box .preview-line { display: flex; gap: 8px; padding: 2px 0; }
.preview-box .preview-line i { width: 16px; height: 16px; color: var(--c-accent); flex-shrink: 0; margin-top: 2px; }

/* ===========================================================================
   Charts
   ========================================================================= */
.chart-wrap { height: 320px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.bar-chart {
  display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px;
  align-items: end; height: 110px;
}
.bar {
  background: linear-gradient(180deg, var(--c-accent-2), var(--c-accent));
  border-radius: 4px 4px 0 0; min-height: 2px;
}
.bar-axis {
  display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px;
  font-size: 10px; color: var(--c-text-soft); margin-top: 4px;
}
.bar-axis div { text-align: center; }
.cost-line { font-size: 13px; color: var(--c-text-2); margin-top: 8px; }
.cost-line b { color: var(--c-text); font-size: 14px; }

/* ===========================================================================
   Flashes
   ========================================================================= */
.flashes { padding: 12px 30px 0; max-width: 920px; margin: 0 auto; }
.flash {
  padding: 10px 14px; border-radius: var(--r-sm); margin-bottom: 10px;
  border: 1px solid; font-size: 14px;
}
.flash-success { background: var(--c-ok-soft); color: #2b6b50; border-color: #b6dec5; }
.flash-danger  { background: var(--c-danger-soft); color: #803121; border-color: #eab4a8; }
.flash-info    { background: var(--c-accent-soft); color: #803a1c; border-color: var(--c-accent-warm); }

/* ===========================================================================
   Modal
   ========================================================================= */
.modal {
  position: fixed; inset: 0; background: rgba(40, 25, 15, .35);
  display: none; align-items: center; justify-content: center; z-index: 99;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal.open { display: flex; }
.modal-card {
  width: min(520px, 92vw); background: white;
  border-radius: var(--r-xl); padding: 20px;
  box-shadow: var(--sh-lg);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }

/* ===========================================================================
   Auth
   ========================================================================= */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 800px at 90% 0%, #f8d3b5 0%, transparent 60%),
    radial-gradient(800px 600px at 10% 90%, #f3d2e1 0%, transparent 60%),
    var(--ios-bg);
}
.auth-card {
  width: min(420px, 100%); background: white;
  border-radius: 22px; padding: 32px 28px 24px;
  box-shadow: var(--sh-lg); text-align: center;
}
/* старый .auth-logo переопределён выше иконочной версией */
.auth-card h1 { margin: 0 0 4px; font-weight: 700; letter-spacing: -.02em; }
.auth-sub { color: var(--c-text-2); margin: 0 0 22px; font-size: 13.5px; }
.auth-form .field { text-align: left; }
.auth-foot { margin-top: 22px; color: var(--c-text-soft); font-size: 12px; }

/* ===========================================================================
   Topic editor (prompts page collapsibles)
   ========================================================================= */
.topic-list { display: flex; flex-direction: column; gap: 12px; }
.topic-card {
  border: 1px solid var(--ios-sep);
  border-radius: var(--r-lg);
  background: var(--ios-card);
  overflow: hidden;
  transition: box-shadow .2s;
}
.topic-card[open] { box-shadow: var(--sh-md); }
.topic-card summary {
  cursor: pointer;
  padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
  list-style: none;
  background: linear-gradient(180deg, #fff 0%, #fcf7f1 100%);
}
.topic-card summary::-webkit-details-marker { display: none; }
.topic-summary { flex: 1; }
.topic-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 15px;
}
.topic-emoji {
  width: 24px; height: 24px; display: grid; place-items: center;
  background: var(--c-accent-soft); color: var(--c-accent);
  border-radius: 7px; font-weight: 700;
}
.topic-meta { color: var(--c-text-2); font-size: 12.5px; margin-top: 2px; }
.chev { transition: transform .2s; width: 18px; height: 18px; color: var(--c-text-2); }
.topic-card[open] .chev { transform: rotate(180deg); }
.topic-card .form { padding: 18px; border-top: 1px solid var(--ios-sep); background: var(--ios-card-sub); }

/* ===========================================================================
   Inline edit (users)
   ========================================================================= */
.inline-edit { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-edit input { width: 150px; padding: 6px 9px; font-size: 13px; }
.inline-edit input.long { width: 220px; }
.muted { color: var(--c-text-soft); font-size: 12px; }
.filter select { padding: 7px 10px; font-size: 13px; }

/* ===========================================================================
   Mobile
   ========================================================================= */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: -280px; width: 264px; height: 100vh;
    transition: left .22s; z-index: 50;
  }
  .sidebar.open { left: 0; box-shadow: var(--sh-lg); }
  .burger { display: inline-flex; align-items: center; justify-content: center; }
  .page { padding: 18px; }
  .topbar { padding: 12px 16px; }
}

/* ============================================================
   Access page additions
   ============================================================ */

/* Badge на пункте навигации (например, «3 ожидают доступа») */
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  margin-left: 6px; border-radius: 9px;
  background: var(--c-accent, #c98463); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
}
.nav-badge-muted {
  background: var(--ios-bg-soft, #efe7df);
  color: var(--c-text-2, #6e6258);
}

/* Группа iOS-radio в форме */
.ios-radio-row {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.ios-radio-row label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--c-surface-2, #f4eee7);
  cursor: pointer;
  transition: background .15s ease;
  font-size: 14px;
}
.ios-radio-row label:hover { background: var(--c-surface-3, #ecdcc7); }
.ios-radio-row input[type="radio"] { margin: 0; cursor: pointer; }
.ios-radio-row label:has(input:checked) {
  background: var(--c-accent, #c98463); color: #fff;
}
