/* ===== Токены ===== */
:root {
  --bg: #ffffff;
  --surface: #f4f8f7;
  --surface-2: #e9f1f0;
  --text: #0d1a19;
  --muted: #5c6c6b;
  --accent: #0f766e;         /* тёмно-бирюзовый */
  --accent-strong: #0c5f59;
  --accent-ink: #ffffff;
  --user-bubble: #0f766e;
  --user-ink: #ffffff;
  --line: rgba(0, 0, 0, 0.08);
  --danger: #d1495b;
  --rec: #e5484d;
  --shadow-border:
    0 0 0 1px rgba(0, 0, 0, 0.05),
    0 1px 2px -1px rgba(0, 0, 0, 0.06),
    0 2px 6px 0 rgba(0, 0, 0, 0.04);
  --shadow-border-hover:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    0 2px 4px -1px rgba(0, 0, 0, 0.08),
    0 4px 12px 0 rgba(0, 0, 0, 0.06);
  --shadow-pop:
    0 0 0 1px rgba(0, 0, 0, 0.05),
    0 8px 24px -6px rgba(0, 0, 0, 0.18),
    0 16px 48px -12px rgba(0, 0, 0, 0.14);
  --r-xl: 24px; --r-lg: 18px; --r-md: 13px; --r-sm: 9px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --header-h: 54px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}
[data-theme="dark"] {
  --bg: #0b1413;
  --surface: #13201f;
  --surface-2: #1b2c2a;
  --text: #e7f0ef;
  --muted: #91a5a3;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --accent-ink: #04201c;
  --user-bubble: #14524b;
  --user-ink: #eafaf7;
  --line: rgba(255, 255, 255, 0.09);
  --shadow-border: 0 0 0 1px rgba(255, 255, 255, 0.08);
  --shadow-border-hover: 0 0 0 1px rgba(255, 255, 255, 0.14);
  --shadow-pop: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 12px 40px -8px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; height: 100dvh;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
body { overflow: hidden; }
.hidden { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.view { height: 100dvh; }

/* Кнопки */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink); border-radius: var(--r-md);
  padding: 14px 18px; font-weight: 600; font-size: 16px;
  transition-property: scale, background-color, box-shadow; transition-duration: 150ms; transition-timing-function: var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.btn-primary.sm { padding: 10px 16px; font-size: 15px; }
.btn-primary:active { scale: 0.96; background: var(--accent-strong); }
.btn-primary[disabled] { opacity: .55; }

.icon-btn {
  position: relative; min-width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: var(--r-md); color: var(--text);
  transition-property: scale, background-color, color; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.icon-btn:active { scale: 0.94; background: var(--surface-2); }
.icon-btn.round { border-radius: 50%; width: 44px; height: 44px; }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 8px -1px color-mix(in srgb, var(--accent) 45%, transparent); }
.icon-btn.accent:active { background: var(--accent-strong); }
.link-btn { color: var(--accent); font-size: 14px; font-weight: 500; padding: 8px; margin: -8px; }

/* ===== Enter-анимации (split & stagger) ===== */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); filter: blur(4px); } to { opacity: 1; transform: none; filter: blur(0); } }
.stagger { opacity: 0; animation: fadeInUp 460ms var(--ease) forwards; }
.stagger:nth-child(1) { animation-delay: 40ms; }
.stagger:nth-child(2) { animation-delay: 120ms; }
.stagger:nth-child(3) { animation-delay: 200ms; }
.stagger:nth-child(4) { animation-delay: 280ms; }
.stagger:nth-child(5) { animation-delay: 360ms; }

/* ===== Логин ===== */
.login { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--r-xl);
  padding: 30px 24px; box-shadow: var(--shadow-pop);
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 28px; font-weight: 700; letter-spacing: -.6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(140deg, var(--accent), #14b8a6 70%, #22d3ee); box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--accent) 50%, transparent); }
.login-sub { color: var(--muted); margin: 8px 0 24px; font-size: 14.5px; text-wrap: pretty; }
#loginForm { display: grid; gap: 12px; }
input, textarea {
  width: 100%; background: var(--bg); color: var(--text); border-radius: var(--r-md);
  padding: 14px; font-size: 16px; outline: none; border: 1px solid var(--line);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.login-error { color: var(--danger); font-size: 14px; min-height: 18px; text-align: center; text-wrap: pretty; }

/* ===== Каркас ===== */
.app { display: flex; flex-direction: column; }
.topbar {
  height: calc(var(--header-h) + var(--safe-top)); padding-top: var(--safe-top);
  display: flex; align-items: center; gap: 6px; padding-inline: 8px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.topbar-title { flex: 1; text-align: center; font-weight: 600; font-size: 16.5px; letter-spacing: -.2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Сообщения ===== */
.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 12px 10px;
  display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 6px; animation: fadeInUp 340ms var(--ease); }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }
.bubble { padding: 11px 14px; border-radius: var(--r-lg); line-height: 1.46; font-size: 15.5px;
  word-wrap: break-word; white-space: pre-wrap; text-wrap: pretty; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-ink); border-bottom-right-radius: var(--r-sm); }
.msg.assistant .bubble { background: var(--surface); border-bottom-left-radius: var(--r-sm); box-shadow: var(--shadow-border); }
.bubble b { font-weight: 700; }
.bubble.speaking { box-shadow: var(--shadow-border), 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.step { font-size: 12px; color: var(--muted); background: var(--surface); border-radius: 999px; padding: 4px 10px; box-shadow: var(--shadow-border); }
.step.send { color: var(--accent); }
.step.warn { color: var(--danger); }
.typing { display: inline-flex; gap: 5px; padding: 15px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 300px; text-wrap: balance; }
.empty .brand-mark { width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 16px; }
.empty p { text-wrap: pretty; line-height: 1.5; }

/* ===== Композер ===== */
.composer { padding: 8px 10px calc(8px + var(--safe-bot));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.6) blur(14px); border-top: 1px solid var(--line); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.swap-in { animation: swapIn 240ms var(--ease); }
@keyframes swapIn { from { opacity: 0; transform: translateY(8px) scale(0.985); } }

/* Голосовой режим — большая кнопка */
.big-mic { flex: 1; height: 52px; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent); color: var(--accent-ink); border-radius: 26px; font-weight: 600; font-size: 16px;
  box-shadow: 0 4px 14px -3px color-mix(in srgb, var(--accent) 55%, transparent);
  transition-property: scale, background-color, box-shadow; transition-duration: 160ms; transition-timing-function: var(--ease); }
.big-mic:active { scale: 0.97; }
.big-mic svg { width: 22px; height: 22px; }
.big-mic.recording { background: var(--rec); box-shadow: 0 4px 16px -3px color-mix(in srgb, var(--rec) 55%, transparent); font-size: 14.5px; }
.big-mic.recording svg { animation: micpulse 1.1s infinite; }
@keyframes micpulse { 50% { opacity: .55; } }
.mode-btn { background: var(--surface); box-shadow: var(--shadow-border); flex: none; }

/* Текстовый режим */
.input-wrap { flex: 1; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-border); padding: 5px 14px; display: flex; }
#input { flex: 1; resize: none; max-height: 132px; padding: 7px 0; border: none; background: transparent; border-radius: 0; line-height: 1.35; }
#input:focus { box-shadow: none; }

/* Подсказка «Команды агенту» */
.help { padding: 0 12px 2px; }
.help-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: var(--r-md);
  font-weight: 500; font-size: 14.5px; transition: background-color 140ms var(--ease); }
.help-head:active { background: var(--surface); }
.help-head > svg:first-child { width: 18px; height: 18px; color: var(--accent); flex: none; }
.help-head .chev { margin-left: auto; width: 18px; height: 18px; color: var(--muted); transition: transform 220ms var(--ease); }
.help-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.help-body { padding: 2px 14px 10px; font-size: 13.5px; color: var(--muted); animation: fadeInUp 240ms var(--ease); }
.help-body p { margin: 2px 0 8px; }
.help-body ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.help-body li { padding-left: 15px; position: relative; line-height: 1.4; text-wrap: pretty; }
.help-body li::before { content: "•"; position: absolute; left: 2px; color: var(--accent); }

.mini-select { background: var(--surface); color: var(--text); border: none; box-shadow: var(--shadow-border);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 14px; }

.rec-bar { position: absolute; left: 10px; right: 10px; bottom: calc(76px + var(--safe-bot));
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop); z-index: 6; animation: fadeInUp 220ms var(--ease); }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rec); animation: recpulse 1s infinite; }
@keyframes recpulse { 50% { opacity: .3; transform: scale(.8); } }
.rec-hint { color: var(--muted); font-size: 13px; flex: 1; }
#recTime { font-weight: 600; }

.wake-chip { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(78px + var(--safe-bot));
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; font-size: 13px; color: var(--accent);
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow-border); z-index: 6; animation: fadeInUp 220ms var(--ease); }
.wake-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: recpulse 1.3s infinite; }

/* ===== Панель / настройки ===== */
.drawer { position: fixed; inset: 0 auto 0 0; width: 84%; max-width: 330px; z-index: 20;
  background: var(--bg); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; padding-top: var(--safe-top);
  transform: translateX(-102%); transition: transform 260ms var(--ease); }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 10px 18px; font-size: 19px; font-weight: 700; }
.drawer-new { display: flex; align-items: center; gap: 10px; margin: 2px 12px 8px; padding: 12px 14px;
  border-radius: var(--r-md); background: var(--surface); font-weight: 600; box-shadow: var(--shadow-border);
  transition: scale 150ms var(--ease); }
.drawer-new:active { scale: 0.97; }
.drawer-new svg { width: 19px; height: 19px; color: var(--accent); }
.conv-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.conv { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 11px 12px;
  border-radius: var(--r-md); margin-bottom: 3px; transition: background-color 140ms var(--ease); animation: fadeInUp 300ms var(--ease); }
.conv:active { background: var(--surface); }
.conv.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.conv-main { min-width: 0; flex: 1; }
.conv-title { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-prev { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv-del { position: relative; color: var(--muted); min-width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center; transition: color 140ms, background-color 140ms; }
.conv-del:active { background: var(--surface-2); color: var(--danger); }
.conv-del svg { width: 18px; height: 18px; }

.settings { border-top: 1px solid var(--line); padding: 10px 16px 6px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; font-size: 15px; }
.set-note { font-size: 12.5px; color: var(--muted); padding: 2px 0 8px; text-wrap: pretty; }
.switch { position: relative; width: 46px; height: 28px; border-radius: 999px; background: var(--surface-2);
  transition: background-color 200ms var(--ease); flex: none; }
.switch::after { content: ""; }
.switch i { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform 220ms var(--ease); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(18px); }

.drawer-foot { border-top: 1px solid var(--line); padding: 14px 18px calc(14px + var(--safe-bot));
  display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.42); z-index: 15; opacity: 0;
  pointer-events: none; transition: opacity 260ms var(--ease); }
.backdrop.open { opacity: 1; pointer-events: auto; }

/* ===== Установка ===== */
.install { position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bot)); z-index: 30;
  background: var(--bg); border-radius: var(--r-lg); padding: 15px 16px; box-shadow: var(--shadow-pop); animation: fadeInUp 320ms var(--ease); }
.install-text { font-size: 14px; line-height: 1.5; margin-bottom: 12px; text-wrap: pretty; }
.install-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
