/* Гермес Дом — Apple-стиль. Светлая и тёмная темы, авто по системе. */

:root {
  /* ── Нейтральная база: системные серые Apple (HIG) ── */
  --bg: #f2f2f7;                                    /* systemGroupedBackground (light) */
  --bg-elev: rgba(242, 242, 247, 0.72);             /* стекло поверх фона */
  --surface: #ffffff;                               /* secondarySystemGroupedBackground */
  --surface-2: #f2f2f7;                             /* tertiarySystemGroupedBackground */
  --surface-3: #e5e5ea;                             /* systemGray5 (light) */
  --text: #000000;                                  /* label */
  --text-2: rgba(60, 60, 67, 0.60);                 /* secondaryLabel #3C3C4399 */
  --text-3: rgba(60, 60, 67, 0.30);                 /* tertiaryLabel  #3C3C434D */
  --separator: rgba(60, 60, 67, 0.29);              /* separator (light) */
  --hairline: rgba(60, 60, 67, 0.12);               /* тонкий разделитель */
  --fill: rgba(120, 120, 128, 0.12);                /* systemFill */
  --fill-2: rgba(120, 120, 128, 0.16);              /* secondarySystemFill */
  --gray: #8e8e93;                                  /* systemGray */
  /* ── Акцент: systemBlue ── */
  --accent: #007aff;                                /* systemBlue (light) */
  --accent-hover: #0071e3;                          /* затемнённый systemBlue для hover */
  --accent-soft: rgba(0, 122, 255, 0.10);           /* systemBlue @ 10% */
  --accent-press: rgba(0, 122, 255, 0.20);
  /* ── Семантические цвета Apple ── */
  --green: #34c759;                                 /* systemGreen */
  --orange: #ff9500;                                /* systemOrange */
  --red: #ff3b30;                                   /* systemRed */
  --purple: #af52de;                                /* systemPurple */
  --pink: #ff2d55;                                  /* systemPink */
  --teal: #5ac8fa;                                  /* systemTeal (в HIG — light blue) */
  --yellow: #ffcc00;                                /* systemYellow */
  --indigo: #5856d6;                                /* systemIndigo */
  --mint: #00c7be;                                  /* systemMint */
  --brown: #a2845e;                                 /* systemBrown */
  /* полупрозрачные «плашки» под бейджи/карточки */
  --green-soft: rgba(52, 199, 89, 0.15);
  --orange-soft: rgba(255, 149, 0, 0.15);
  --red-soft: rgba(255, 59, 48, 0.15);
  --purple-soft: rgba(175, 82, 222, 0.15);
  --radius: 18px;
  --radius-sm: 11px;
  --radius-xs: 8px;
  /* Единая шкала скруглений (концентрические радиусы) */
  --r-pill: 999px;
  --shadow-color: 220 40% 20%;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px -6px rgba(28, 32, 46, 0.10);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.05), 0 24px 56px -12px rgba(28, 32, 46, 0.18);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "Segoe UI", "Inter", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "SF Pro Text", "Helvetica Neue", "Segoe UI", "Inter", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  /* Плавная «физичная» кривая — единая для всего интерфейса */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* ── Нейтральная база: системные серые Apple (dark) ── */
    --bg: #000000;                                  /* systemBackground (dark) */
    --bg-elev: rgba(28, 28, 30, 0.72);
    --surface: #1c1c1e;                             /* secondarySystemGroupedBackground (dark) */
    --surface-2: #2c2c2e;                           /* tertiarySystemGroupedBackground (dark) */
    --surface-3: #3a3a3c;                           /* systemGray4 (dark) */
    --text: #ffffff;                                /* label (dark) */
    --text-2: rgba(235, 235, 245, 0.60);            /* secondaryLabel (dark) #EBEBF599 */
    --text-3: rgba(235, 235, 245, 0.30);            /* tertiaryLabel  (dark) #EBEBF54D */
    --separator: rgba(84, 84, 88, 0.60);            /* separator (dark) */
    --hairline: rgba(84, 84, 88, 0.36);             /* тонкий разделитель */
    --fill: rgba(120, 120, 128, 0.36);              /* systemFill (dark) */
    --fill-2: rgba(120, 120, 128, 0.44);
    --gray: #8e8e93;                                /* systemGray */
    /* ── Акцент: systemBlue (dark) ── */
    --accent: #0a84ff;                              /* systemBlue (dark) */
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.18);
    --accent-press: rgba(10, 132, 255, 0.32);
    /* ── Семантические цвета Apple (dark) ── */
    --green: #30d158;                               /* systemGreen (dark) */
    --orange: #ff9f0a;                              /* systemOrange (dark) */
    --red: #ff453a;                                 /* systemRed (dark) */
    --purple: #bf5af2;                              /* systemPurple (dark) */
    --pink: #ff375f;                                /* systemPink (dark) */
    --teal: #64d2ff;                                /* systemTeal (dark) */
    --yellow: #ffd60a;                              /* systemYellow (dark) */
    --indigo: #5e5ce6;                              /* systemIndigo (dark) */
    --mint: #63e6e2;                                /* systemMint (dark) */
    --brown: #ac8e68;                               /* systemBrown (dark) */
    --green-soft: rgba(48, 209, 88, 0.20);
    --orange-soft: rgba(255, 159, 10, 0.20);
    --red-soft: rgba(255, 69, 58, 0.20);
    --purple-soft: rgba(191, 90, 242, 0.20);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 2px 8px rgba(0, 0, 0, 0.45), 0 24px 56px rgba(0, 0, 0, 0.6);
  }
}

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

html, body, #app { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ── Экран входа ─────────────────────────────────────────────────────────── */
.login-wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 22px;
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--separator);
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 18px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--accent), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  box-shadow: 0 8px 24px var(--accent-soft);
}
.login-card h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.login-card p { color: var(--text-2); font-size: 14px; margin: 6px 0 26px; }
.field {
  width: 100%; padding: 13px 16px; margin-bottom: 12px;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.btn-primary {
  width: 100%; padding: 13px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; }
.login-err { color: var(--red); font-size: 13px; margin-top: 14px; min-height: 18px; }

/* ── Каркас приложения ───────────────────────────────────────────────────── */
.shell { display: flex; height: 100%; }

.sidebar {
  width: 268px; flex-shrink: 0;
  background: var(--bg-elev);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--separator);
  display: flex; flex-direction: column;
}
.side-head {
  padding: 16px 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.side-title { font-weight: 650; font-size: 17px; letter-spacing: -0.02em; display: flex; align-items: center; gap: 9px; }
.side-title .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(52,199,89,0.18); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: 17px;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.side-scroll { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.side-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-3);
  padding: 14px 8px 6px;
}
.sess-item {
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 2px;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.sess-item:hover { background: var(--accent-soft); }
.sess-item.active { background: var(--accent-soft); border-color: var(--accent); }
.sess-item .t { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-item .m { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.side-foot { padding: 10px 12px 14px; border-top: 1px solid var(--separator); }

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--accent-soft); color: var(--accent); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ── Область чата ────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg-elev);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.topbar h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.model-pill {
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--separator); white-space: nowrap;
}
.dev-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-2); user-select: none;
  padding: 6px 10px; border-radius: 20px; transition: background 0.15s;
}
.dev-toggle:hover { background: var(--surface-2); }
.switch {
  width: 40px; height: 24px; border-radius: 12px;
  background: var(--text-3); position: relative; transition: background 0.25s;
  flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(16px); }

.messages { flex: 1; overflow-y: auto; padding: 24px 0 20px; }
.msg-inner { max-width: 760px; margin: 0 auto; padding: 0 22px; }

.msg { margin-bottom: 22px; animation: fadein 0.35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
.msg-role { font-size: 12px; font-weight: 600; color: var(--text-3); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.bubble {
  padding: 13px 17px; border-radius: 18px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--separator); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.bubble code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.msg.user .bubble code { background: rgba(255,255,255,0.2); }
.bubble pre {
  background: var(--surface-2); padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; margin: 8px 0; border: 1px solid var(--separator);
}
.bubble pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }

.cursor::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.tool-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-family: var(--mono);
  background: var(--surface-2); border: 1px solid var(--separator);
  padding: 5px 11px; border-radius: 8px; margin: 6px 0;
  color: var(--text-2);
}
.tool-chip .sp { width: 11px; height: 11px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Композер ────────────────────────────────────────────────────────────── */
.composer-wrap { flex-shrink: 0; padding: 12px 22px 20px; contain: layout style; }
.composer {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: 24px; padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.composer textarea {
  flex: 1; background: transparent; border: 0; outline: none; resize: none;
  font: inherit; color: var(--text-1); max-height: 180px;
  /* стабильная однострочная высота через вертикальные паддинги (равно кнопкам
     34px) и запрет схлопывания — набор не «плывёт», курсор не теряется */
  padding: 5px 0; line-height: 24px;
  height: 34px; min-height: 34px; box-sizing: border-box;
  overflow-y: hidden; overflow-x: hidden; white-space: pre-wrap; word-break: break-word;
}
/* кнопка-скрепка */
.attach-btn {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  background: transparent; color: var(--text-2); border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.attach-btn:hover { background: var(--surface-2); color: var(--accent); }
.attach-btn:active { transform: scale(0.92); }
/* полоска прикреплённых файлов */
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-chip {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--separator); border-radius: 12px; padding: 6px 8px;
  max-width: 220px; font-size: 12.5px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 8px; }
.attach-chip .ficon { font-size: 24px; line-height: 1; }
.attach-chip .aname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.attach-chip .ax {
  border: 0; background: transparent; color: var(--text-3); cursor: pointer;
  font-size: 14px; padding: 2px 4px; border-radius: 6px;
}
.attach-chip .ax:hover { background: var(--red, #ff3b30); color: #fff; }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.35; }
.hint { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 9px; }

/* ── Панель «Для разработчика» ───────────────────────────────────────────── */
.dev-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--separator);
  box-shadow: var(--shadow-lg); z-index: 50;
  transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.dev-panel.open { transform: translateX(0); }
.dev-head {
  height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; border-bottom: 1px solid var(--separator);
}
.dev-head h3 { font-size: 15px; font-weight: 600; flex: 1; }
/* Кнопки в шапке панели, когда она развёрнута на весь экран:
   держим их фиксированными поверх контента (в т.ч. iframe), чтобы ✕ и ⛶
   всегда были доступны и не «уезжали» при прокрутке встроенной страницы. */
.panel-fs-tools {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 4px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-sm, 0 2px 10px rgba(0,0,0,.12));
}
.panel-fs-tools .icon-btn { width: 34px; height: 34px; font-size: 18px; opacity: 0.95; }
.panel-fs-tools .icon-btn.active { background: var(--accent-soft); color: var(--accent); }
/* В обычном (колоночном) режиме шапка видна и в ней уже есть ✕ —
   поэтому «дублирующая» кнопка закрытия в плавающем блоке не нужна,
   оставляем только ⛶ для раскрытия на весь экран. */
.pvz-panel:not(.fs-mode) .panel-fs-tools,
.crew-panel:not(.fs-mode) .panel-fs-tools,
.fin-panel:not(.fs-mode) .panel-fs-tools {
  top: 11px; right: 56px; background: transparent; border: 0;
  box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; padding: 0;
}
.pvz-panel:not(.fs-mode) .panel-fs-tools .icon-btn:not(.fs-toggle),
.crew-panel:not(.fs-mode) .panel-fs-tools .icon-btn:not(.fs-toggle),
.fin-panel:not(.fs-mode) .panel-fs-tools .icon-btn:not(.fs-toggle) { display: none; }

/* ── Полноэкранный режим панелей (ПВЗ / Офис / Финансы) ─────────────────── */
/* По умолчанию (если владелец не переключал) — на весь экран. */
.pvz-panel.fs-mode,
.crew-panel.fs-mode,
.fin-panel.fs-mode {
  width: 100vw !important; max-width: 100vw !important;
  height: 100dvh; height: 100vh;
  border-left: 0;
}
/* Когда панель на весь экран — шапку делаем минимальной и «плавающей»,
   сам контент (iframe/тело) начинается от верха окна. */
.pvz-panel.fs-mode .dev-head,
.crew-panel.fs-mode .dev-head,
.fin-panel.fs-mode .dev-head {
  position: absolute; top: 0; left: 0; right: 0; height: 0;
  padding: 0; border-bottom: 0; overflow: visible;
}
.pvz-panel.fs-mode .dev-head h3,
.crew-panel.fs-mode .dev-head h3,
.fin-panel.fs-mode .dev-head h3 { display: none; }
.pvz-panel.fs-mode .pvz-frame,
.crew-panel.fs-mode .crew-frame { min-height: 100vh; }
.pvz-panel.fs-mode .fin-body,
.crew-panel.fs-mode .fin-body,
.fin-panel.fs-mode .fin-body { padding-top: 60px; }

/* На мобильном/планшете — всегда на весь экран, независимо от выбора. */
@media (max-width: 820px) {
  .pvz-panel,
  .crew-panel,
  .fin-panel { width: 100vw !important; max-width: 100vw !important; border-left: 0; }
  .pvz-panel .dev-head,
  .crew-panel .dev-head,
  .fin-panel .dev-head {
    position: absolute; top: 0; left: 0; right: 0; height: 0;
    padding: 0; border-bottom: 0; overflow: visible;
  }
  .pvz-panel .dev-head h3,
  .crew-panel .dev-head h3,
  .fin-panel .dev-head h3 { display: none; }
  .pvz-panel .pvz-frame,
  .crew-panel .crew-frame { min-height: 100vh; }
  .fin-panel .fin-body { padding-top: 60px; }
  /* кнопку переключения на мобильном прячем — там всегда полный экран */
  .panel-fs-tools .fs-toggle { display: none; }
}
.dev-tabs { display: flex; gap: 4px; padding: 12px 16px 0; flex-wrap: wrap; }
.dev-tab {
  padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
  color: var(--text-2); background: var(--surface-2); transition: all 0.15s;
}
.dev-tab:hover { color: var(--accent); }
.dev-tab.active { background: var(--accent); color: #fff; }
.dev-body { flex: 1; overflow-y: auto; padding: 16px; }
.dev-sec { margin-bottom: 22px; }
.dev-sec h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 10px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--separator); font-size: 13.5px; }
.kv .k { color: var(--text-2); }
.kv .v { font-weight: 500; text-align: right; word-break: break-word; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.no { background: var(--red-soft); color: var(--red); }
.mono-box {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  background: var(--surface-2); border: 1px solid var(--separator);
  border-radius: 10px; padding: 12px; white-space: pre-wrap; word-break: break-all;
  max-height: 300px; overflow-y: auto;
}
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-tag {
  font-size: 12.5px; font-family: var(--mono); padding: 5px 10px;
  background: var(--surface-2); border: 1px solid var(--separator);
  border-radius: 8px; color: var(--text-2);
}

/* ── Панель «Гермес ПВЗ» ─────────────────────────────────────────────────── */
.pvz-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--separator);
  box-shadow: var(--shadow-lg); z-index: 51;
  transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.pvz-panel.open { transform: translateX(0); }
.pvz-frame { flex: 1; border: 0; width: 100%; background: var(--bg); }

/* ── Панель «Офис агентов» ───────────────────────────────────────────────── */
.crew-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 900px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--separator);
  box-shadow: var(--shadow-lg); z-index: 51;
  transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.crew-panel.open { transform: translateX(0); }
.crew-frame { flex: 1; border: 0; width: 100%; background: #0d1117; }

/* ── Панель «Сервисы» ────────────────────────────────────────────────────── */
.serv-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--separator);
  box-shadow: var(--shadow-lg); z-index: 52;
  transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.serv-panel.open { transform: translateX(0); }
.serv-body { flex: 1; overflow-y: auto; padding: 16px; }
.serv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.serv-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: left; padding: 16px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--separator);
  cursor: pointer; transition: all 0.16s; font-family: inherit;
}
.serv-tile:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-2px); }
.serv-tile:active { transform: scale(0.97); }
.serv-ico { font-size: 26px; line-height: 1; margin-bottom: 4px; }
.serv-name { font-size: 14.5px; font-weight: 600; color: var(--text); }
.serv-hint { font-size: 12px; color: var(--text-3); line-height: 1.35; }
.serv-note {
  margin-top: 18px; padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--separator);
  font-size: 12.5px; color: var(--text-2); line-height: 1.5;
}
@media (max-width: 560px) { .serv-grid { grid-template-columns: 1fr; } }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 49; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.scrim.open { opacity: 1; pointer-events: auto; }

.empty { text-align: center; color: var(--text-3); padding: 80px 20px; }
.empty .big { font-size: 44px; margin-bottom: 14px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--surface); border: 1px solid var(--separator);
  padding: 12px 20px; border-radius: 14px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; z-index: 100; opacity: 0; transition: all 0.35s cubic-bezier(0.16,1,0.3,1);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── Мобильный ───────────────────────────────────────────────────────────── */
.menu-btn { display: none; }
@media (max-width: 820px) {
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%); transition: transform 0.35s cubic-bezier(0.16,1,0.3,1);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: flex; }
  .msg-inner, .composer { padding-left: 16px; padding-right: 16px; }
}

/* ── Панель «Финансы» ────────────────────────────────────────────────────── */
.fin-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 620px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--separator);
  box-shadow: var(--shadow-lg); z-index: 51;
  transform: translateX(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column;
}
.fin-panel.open { transform: translateX(0); }
.fin-body { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }
.fin-loading, .fin-err { color: var(--text-2); text-align: center; padding: 40px 20px; }
.fin-err { color: var(--red); }
.fin-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
.fin-card { background: var(--surface-2); border: 1px solid var(--separator);
  border-radius: 14px; padding: 16px; }
.fin-card.pos { border-color: rgba(52,199,89,.35); background: var(--green-soft); }
.fin-card.neg { border-color: rgba(255,59,48,.35); background: var(--red-soft); }
.fin-num { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.fin-lbl { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.fin-block { background: var(--surface-2); border: 1px solid var(--separator);
  border-radius: 16px; padding: 16px 18px; margin-bottom: 16px; }
.fin-h { font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.fin-h-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.fin-h-row .fin-h { margin-bottom: 0; }
.fin-tip { display: flex; gap: 10px; font-size: 14px; line-height: 1.45; margin-bottom: 10px; }
.fin-tip.bad { color: var(--red); }
.fin-tip.warn { color: var(--orange); }
.fin-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--separator); }
.fin-row:last-child { border-bottom: 0; }
.fin-row.off { opacity: .45; }
.fin-title { font-size: 15.5px; font-weight: 600; }
.fin-sub { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.fin-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.fin-amt { font-size: 16px; font-weight: 700; }
.fin-bad { color: var(--red); }
.fin-empty { color: var(--text-2); font-size: 14px; padding: 10px 0; }
.fin-cat { margin-bottom: 13px; }
.fin-cat-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.fin-cat-top span { color: var(--text-2); }
.fin-bar { height: 7px; background: var(--surface); border-radius: 100px; overflow: hidden; }
.fin-bar i { display: block; height: 100%; background: var(--accent); border-radius: 100px; transition: width .5s; }
.fin-bar i.warn { background: var(--orange); }
.fin-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.fin-btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer; }
.fin-btn:hover { filter: brightness(1.08); }
.fin-btn.sec { background: var(--surface); color: var(--text); border: 1px solid var(--separator); }
.fin-btn.ghost { background: transparent; border: 1px solid var(--separator); color: var(--text-2); }
.fin-btn.sm { padding: 6px 11px; font-size: 12.5px; }
.fin-modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.fin-modal { background: var(--surface); border: 1px solid var(--separator); border-radius: 18px;
  padding: 22px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.fin-modal h3 { margin: 0 0 16px; font-size: 18px; }
.fin-kind { display: flex; gap: 10px; margin-bottom: 14px; }
.fin-f { display: block; margin-bottom: 12px; }
.fin-f span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.fin-f input, .fin-f select { width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--separator); background: var(--surface-2); color: var(--text);
  font-size: 15px; box-sizing: border-box; }
.fin-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fin-url { word-break: break-all; background: var(--surface-2); border: 1px solid var(--separator);
  padding: 12px; border-radius: 10px; font-size: 13px; font-family: var(--mono); }

/* ── Панель «Доступы» ─────────────────────────────────────────────────────── */
.acc-form { max-width: 420px; }
.acc-form .fin-f { margin-bottom: 12px; }
.acc-pw { background: var(--surface-2); border: 1px solid var(--separator);
  border-radius: 14px; padding: 16px; margin: 12px 0; text-align: center; }
.acc-pw-big { font-size: 30px; font-weight: 800; letter-spacing: 3px;
  font-family: var(--mono); margin-top: 8px; user-select: all; }

/* ── Панель «Задачи бригаде» ──────────────────────────────────────────────── */
#taskbody textarea { width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--separator); background: var(--surface-2); color: var(--text);
  font-size: 15px; font-family: inherit; resize: vertical; box-sizing: border-box; }
.task-badge { font-family: var(--mono); font-size: 11.5px; padding: 3px 8px;
  border-radius: 100px; background: var(--surface-2); border: 1px solid var(--separator); color: var(--text-2); }
.task-badge.running { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.task-badge.done { background: var(--green-soft); color: var(--green); border-color: transparent; }
.task-badge.blocked { background: var(--red-soft); color: var(--red); border-color: transparent; }
.task-badge.triage, .task-badge.todo { background: var(--orange-soft); color: var(--orange); border-color: transparent; }

/* ══════════════════════════════════════════════════════════════════════════
   ПРЕМИУМ-СЛОЙ (дизайн-аудит): благородная типографика, спокойные тени,
   живые состояния, стекло, крупные тапы. Только переопределения — база не тронута.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Типографика: крупнее и благороднее ─────────────────────────────── */
body { font-size: 15.5px; line-height: 1.55; }
.side-title, .login-card h1, .dev-head h3, .fin-h, .fin-title,
h1, h2, h3 { font-family: var(--font-display); }
/* цифры — табличные, ровные по разрядам */
.fin-num, .fin-amt, .acc-pw-big, .model-pill, .kv .v,
.task-badge, .fin-sub {
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
/* крупные заголовки — плотнее трекинг, аккуратные переносы */
.topbar h2 { font-size: 15.5px; letter-spacing: -0.015em; }
.msg-role { letter-spacing: 0.08em; font-size: 11.5px; }
.side-label, .dev-sec h4 { letter-spacing: 0.075em; }
.fin-h { font-size: 16px; letter-spacing: -0.015em; }
.fin-num { font-size: 24px; letter-spacing: -0.03em; }
.empty div, .fin-empty, .dev-sec p { text-wrap: pretty; }
.topbar h2, .fin-h, .login-card h1 { text-wrap: balance; }

/* ── 2. Тени и границы: единый мягкий свет, тёплый оттенок ──────────────── */
.login-card, .dev-panel, .pvz-panel, .crew-panel, .fin-panel,
.serv-panel, .toast { box-shadow: var(--shadow-lg); }
.composer { box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 10px 30px -12px rgba(28,32,46,0.14); }
.msg.assistant .bubble {
  box-shadow: 0 1px 1.5px rgba(0,0,0,0.035), 0 10px 28px -16px rgba(28,32,46,0.16);
  border-color: var(--hairline);
}
/* тонированные «карточки» финансов мягче: без резких цветных рамок */
.fin-card, .fin-block, .serv-tile, .mono-box, .serv-note, .acc-pw {
  border-color: var(--hairline);
}
.fin-card.pos { border-color: rgba(52,199,89,.30); background: var(--green-soft); }
.fin-card.neg { border-color: rgba(255,59,48,.30); background: var(--red-soft); }

/* ── 3. Скругления: вложенность, а не «всё по 16» ──────────────────────── */
.fin-card { border-radius: var(--radius); }
.fin-block { border-radius: var(--radius); }
.serv-tile { border-radius: var(--radius); }
.composer { border-radius: 24px; }
.msg.assistant .bubble { border-radius: 20px; border-bottom-left-radius: 7px; }
.msg.user .bubble { border-radius: 20px; border-bottom-right-radius: 7px; }

/* ── 4. Состояния: hover/active/focus — интерфейс «живой» ──────────────── */
.icon-btn { transition: background .2s var(--ease), color .2s var(--ease), transform .12s var(--ease); }
.icon-btn:active { transform: scale(0.9); }
.nav-btn {
  transition: background .2s var(--ease), color .2s var(--ease), transform .12s var(--ease);
  border-radius: var(--radius-sm);
}
.nav-btn:hover { background: var(--accent-soft); color: var(--accent); }
.nav-btn:active { transform: scale(0.97); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.serv-tile { transition: transform .22s var(--ease), box-shadow .22s var(--ease),
  border-color .22s var(--ease), background .22s var(--ease); }
.serv-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04), 0 16px 36px -18px rgba(28,32,46,0.28);
  border-color: var(--accent);
}
.serv-tile:active { transform: scale(0.975); }

.fin-btn { transition: filter .18s var(--ease), transform .12s var(--ease), background .18s var(--ease); }
.fin-btn:active { transform: scale(0.96); }
.fin-btn.sec:hover, .fin-btn.ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.fin-row { border-radius: var(--radius-sm); transition: background .18s var(--ease); }
.fin-row:not(:last-child):hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.attach-btn, .send-btn, .btn-primary, .dev-tab, .field, .switch {
  transition: background .2s var(--ease), color .2s var(--ease),
    transform .12s var(--ease), border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.btn-primary:active, .send-btn:active { transform: scale(0.94); }
.dev-tab:active { transform: scale(0.96); }
.panel-fs-tools .icon-btn:active { transform: scale(0.9); }

/* Видимый focus-ring для клавиатуры — доступность (обязательно) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
.field:focus-visible, .composer:focus-within { outline: none; }

/* ── 5. Стекло и «дорогая» глубина поверхностей ───────────────────────── */
.sidebar { box-shadow: inset -1px 0 0 var(--separator); }
.topbar { box-shadow: 0 1px 0 var(--hairline); }
/* экран входа — «двойной борт» (double-bezel): мягкое стекло вокруг карточки */
.login-wrap {
  background:
    radial-gradient(900px 480px at 50% -8%, var(--accent-soft), transparent 68%),
    radial-gradient(700px 420px at 88% 108%, var(--purple-soft), transparent 70%),
    var(--bg);
}
.login-card {
  border-radius: 26px;
  padding: 44px 34px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border: 1px solid var(--hairline);
}
.login-logo {
  width: 72px; height: 72px; border-radius: 20px;
  box-shadow: 0 10px 30px -8px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,0.35);
}
.login-card h1 { font-size: 26px; letter-spacing: -0.03em; }
.login-card p { font-size: 14.5px; }
.field { padding: 14px 16px; border-radius: 13px; }
.btn-primary { padding: 14px; border-radius: 13px; }

/* ── 6. Пустое состояние: «с чего начать», а не голый эмодзи ───────────── */
.empty { padding: 72px 20px; color: var(--text-2); }
.empty .big {
  width: 76px; height: 76px; margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
}
.empty .big + div { font-size: 15px; line-height: 1.6; }

/* ── 7. Композер: чуть крупнее, дышит ──────────────────────────────────── */
.composer { padding: 9px 9px 9px 18px; }
.composer textarea { font-size: 15.5px; line-height: 1.5; }
.send-btn { width: 40px; height: 40px; }
.attach-btn { width: 36px; height: 36px; }

/* ── 8. Анимации: плавные, «физичные» ──────────────────────────────────── */
.msg { animation: fadein .45s var(--ease-out); }
.sidebar, .dev-panel, .pvz-panel, .crew-panel, .fin-panel, .serv-panel, .toast {
  transition: transform .45s var(--ease);
}
.toast { transition: transform .4s var(--ease), opacity .4s var(--ease); }
.scrim { transition: opacity .35s var(--ease); }
.serv-tile, .fin-block, .fin-kpi > .fin-card { animation: rise .5s var(--ease-out) backwards; }
.serv-tile:nth-child(2) { animation-delay: .04s; }
.serv-tile:nth-child(3) { animation-delay: .08s; }
.serv-tile:nth-child(4) { animation-delay: .12s; }
.serv-tile:nth-child(5) { animation-delay: .16s; }
.serv-tile:nth-child(6) { animation-delay: .2s; }
.fin-kpi > .fin-card:nth-child(2) { animation-delay: .05s; }
.fin-kpi > .fin-card:nth-child(3) { animation-delay: .1s; }
.fin-kpi > .fin-card:nth-child(4) { animation-delay: .15s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0 !important;
    transition-duration: .001ms !important; }
}

/* ── 9. Мобильный: воздух, крупные тапы (≥44px) ────────────────────────── */
@media (max-width: 820px) {
  .topbar { height: 54px; padding: 0 14px; gap: 8px; }
  .topbar h2 { font-size: 15px; }
  .dev-toggle { padding: 6px 8px; }
  .nav-btn { padding: 13px 12px; min-height: 48px; font-size: 15px; }
  .side-head { padding: 16px 16px 8px; }
  .icon-btn { width: 38px; height: 38px; }
  .messages { padding: 18px 0 16px; }
  .msg-inner { padding: 0 14px; }
  .composer-wrap { padding: 10px 12px max(16px, env(safe-area-inset-bottom)); }
  .composer { padding: 7px 7px 7px 15px; border-radius: 22px; }
  .send-btn { width: 42px; height: 42px; }
  .attach-btn { width: 40px; height: 40px; }
  .hint { font-size: 11px; margin-top: 7px; }
  .msg.user .bubble, .msg.assistant .bubble { font-size: 15.5px; }
  .fin-body { padding: 16px 14px 44px; }
  .fin-kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .fin-num { font-size: 21px; }
  .serv-body { padding: 14px; }
  .acc-pw-big { font-size: 26px; letter-spacing: 2px; }
}
@media (max-width: 420px) {
  .dev-toggle span:first-child { display: none; }  /* на узком экране — только тумблер */
}

/* ── Иконки навигации (SVG вместо эмодзи) ─────────────────────────────────── */
.nav-btn { display: flex; align-items: center; gap: 10px; }
.nav-ico { display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; color: var(--text-2); flex: 0 0 auto; }
.nav-btn:hover .nav-ico, .nav-btn.active .nav-ico { color: var(--accent); }
.nav-lbl { flex: 1; text-align: left; }

/* ── Полировка «дорогого» вида (дизайн-аудит) ─────────────────────────────── */

/* 2. Кнопка «новый чат» — крупнее и заметнее */
.side-head .icon-btn {
  width: 36px; height: 36px; font-size: 20px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--separator);
  color: var(--text);
}
.side-head .icon-btn:hover { background: var(--accent); color: #fff; border-color: transparent; }

/* 3. Кастомный скроллбар — в тон интерфейсу, а не системный */
* { scrollbar-width: thin; scrollbar-color: rgba(120,120,128,0.35) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(120,120,128,0.3); border-radius: 100px;
  border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(120,120,128,0.55); background-clip: content-box; }

/* 4. Детали: плавные переходы и фокус для доступности */
.nav-btn { transition: background .16s var(--ease, ease), color .16s var(--ease, ease); }
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}
/* 5. Заголовки/бренд — плотнее трекинг, благороднее */
.side-title { letter-spacing: -0.025em; }

/* ── Живой голос: кнопки озвучки, микрофон, переключатель ─────────────────── */
.msg-tts { background: transparent; border: 0; color: var(--text-3); cursor: pointer;
  font-size: 15px; padding: 2px 6px; border-radius: 8px; align-self: flex-end;
  transition: color .15s, background .15s; }
.msg-tts:hover { color: var(--accent); background: var(--surface-2); }

.mic-btn { width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%;
  border: 1px solid var(--separator); background: var(--surface-2); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .15s, color .15s, transform .1s; }
.mic-btn:hover { color: var(--accent); }
.mic-btn.recording { background: #FF3B30; color: #fff; border-color: transparent;
  animation: micPulse 1.2s infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,59,48,.5); }
  50% { box-shadow: 0 0 0 8px rgba(255,59,48,0); } }

.voice-toggle { display: inline-flex; align-items: center; gap: 6px; height: 30px;
  padding: 0 11px; border-radius: 100px; border: 1px solid var(--separator);
  background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .16s; }
.voice-toggle:hover { color: var(--text); }
.voice-toggle.on { background: #007AFF; color: #fff; border-color: transparent; }
.voice-toggle span { font-size: 12px; }
@media (max-width: 560px) { .voice-toggle span { display: none; } }
