/* ============================================================
   ASK GOD — дизайн-система
   Светлая и тёмная темы, мобильный-first, DeepSeek-подобный чат
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f5f5f9;
  --bg-elev: #ffffff;
  --bg-soft: #ececf3;
  --bg-inset: #f0f0f6;
  --text: #1d1e2a;
  --text-2: #71738c;
  --text-3: #9b9db2;
  --line: #e4e5ef;
  --accent: #5b5ce2;
  --accent-2: #8a7bff;
  --accent-soft: #ecebfe;
  --accent-text: #4b4cd0;
  --user-bubble: #e4e4fd;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --ok: #30a46c;
  --code-bg: #171826;
  --code-text: #e6e7f2;
  --shadow-1: 0 1px 2px rgba(24,24,52,.06), 0 4px 16px rgba(24,24,52,.07);
  --shadow-2: 0 8px 40px rgba(20,20,60,.16);
  --radius: 20px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Georgia", "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0f1019;
  --bg-elev: #191a28;
  --bg-soft: #222336;
  --bg-inset: #131422;
  --text: #e9eaf4;
  --text-2: #9b9db8;
  --text-3: #6f7190;
  --line: #2a2b40;
  --accent: #7b7cf0;
  --accent-2: #9d8cff;
  --accent-soft: #26274a;
  --accent-text: #aeb0ff;
  --user-bubble: #343661;
  --danger: #ff6369;
  --danger-soft: #3a2026;
  --ok: #3dd68c;
  --code-bg: #0c0d17;
  --code-text: #d9daea;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-2: 0 8px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active { opacity: .85; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
input, textarea { font: inherit; color: inherit; }

.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- переходы страниц ---------- */
.page { animation: pageIn .24s ease both; width: 100%; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- общие элементы ---------- */
.icon-btn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .15s ease, color .15s ease, transform .1s ease;
  flex: none;
}
.icon-btn:active { background: var(--bg-soft); transform: scale(.94); }
.icon-btn.accent { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  font-weight: 600; font-size: 15px;
  background: var(--bg-soft);
  color: var(--text);
  transition: transform .1s ease, filter .15s ease;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(91,92,226,.35);
}
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ============================================================
   ГЛАВНАЯ (каналы)
   ============================================================ */
.home {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 620px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px);
}
.home-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 18px;
  background:
    radial-gradient(circle at 30% 28%, rgba(255,255,255,.85) 0%, rgba(255,255,255,0) 34%),
    linear-gradient(140deg, #6a5cf5 0%, #8a7bff 45%, #4d9df8 100%);
  box-shadow: 0 6px 20px rgba(106,92,245,.4);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 0;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4l1.8 5.2L19 11l-5.2 1.8L12 18l-1.8-5.2L5 11l5.2-1.8L12 4z" fill="white"/></svg>') center/62% no-repeat;
  filter: drop-shadow(0 1px 2px rgba(40,20,120,.35));
}
.brand h1 {
  margin: 0; font-size: 24px; font-weight: 800; letter-spacing: .12em;
  background: linear-gradient(120deg, var(--accent), var(--accent-2) 60%, #4d9df8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }

.channel-grid { display: flex; flex-direction: column; gap: 14px; }
.channel-card {
  display: flex; align-items: center; gap: 16px;
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  text-align: left;
  transition: transform .12s ease, box-shadow .15s ease;
}
.channel-card:active { transform: scale(.985); }
.channel-ava {
  width: 54px; height: 54px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 21px;
  text-shadow: 0 1px 3px rgba(0,0,0,.25);
  flex: none;
}
.channel-info { flex: 1; min-width: 0; }
.channel-name { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-preset { font-size: 12.5px; color: var(--text-2); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }

.channel-add {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 600;
  transition: color .15s ease, border-color .15s ease, transform .12s ease;
}
.channel-add .ic { width: 20px; height: 20px; }
.channel-add:active { transform: scale(.985); }
.channel-add:hover { color: var(--accent); border-color: var(--accent); }

.home-foot { margin-top: auto; padding-top: 30px; text-align: center; color: var(--text-3); font-size: 12px; }

/* ============================================================
   НАСТРОЙКИ
   ============================================================ */
.subpage {
  max-width: 620px; margin: 0 auto;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-bottom: calc(env(safe-area-inset-bottom) + 30px);
}
.sub-head {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.sub-head h2 { margin: 0; font-size: 19px; font-weight: 700; flex: 1; }

.settings-body { padding: 10px 20px; display: flex; flex-direction: column; gap: 22px; }
.section-title {
  font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-2); margin: 0 4px 10px;
}
.section-card { padding: 6px 16px; }
.field-row { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.field-row:last-child { border-bottom: 0; }
.field-icon { color: var(--accent); width: 22px; height: 22px; }
.field-main { flex: 1; min-width: 0; }
.field-label { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field-input {
  width: 100%; border: 0; background: none; padding: 0;
  font-size: 15px; color: var(--text);
}
.field-input.mono { font-size: 13.5px; letter-spacing: .02em; }
.field-input::placeholder { color: var(--text-3); }
.field-trail { display: flex; align-items: center; gap: 4px; }
.field-trail .icon-btn { width: 34px; height: 34px; }
.field-trail .icon-btn .ic { width: 19px; height: 19px; }
.hint { font-size: 12.5px; color: var(--text-3); padding: 10px 4px 0; line-height: 1.5; }
.hint a { color: var(--accent-text); text-decoration: none; font-weight: 600; }

.settings-actions { display: flex; flex-direction: column; gap: 10px; }
.status-line { font-size: 12.5px; color: var(--text-3); padding: 2px 4px; }

.seg { display: flex; background: var(--bg-soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; padding: 8px 6px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s ease, color .15s ease;
}
.seg button .ic { width: 16px; height: 16px; }
.seg button.on { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

/* ============================================================
   ЧАТ
   ============================================================ */
.chat {
  height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 780px; margin: 0 auto; width: 100%;
  position: relative;
}
.chat-top {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 5;
}
.chat-title {
  flex: 1; text-align: center;
  font-size: 16px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 0;
}
.chat-title .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.chat-scroll {
  flex: 1; overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-inner { max-width: 700px; margin: 0 auto; padding: 18px 16px 12px; display: flex; flex-direction: column; }

/* приветствие */
.greeting {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 24px calc(30px + env(safe-area-inset-bottom));
  animation: greetIn .6s ease both;
}
@keyframes greetIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.greeting-halo {
  width: 120px; height: 120px; border-radius: 50%;
  margin-bottom: 30px;
  background:
    radial-gradient(circle at 34% 30%, rgba(255,255,255,.9), rgba(255,255,255,0) 40%),
    linear-gradient(140deg, #6a5cf5, #8a7bff 50%, #4d9df8);
  box-shadow: 0 0 60px rgba(122,108,245,.45), 0 0 120px rgba(77,157,248,.18);
  animation: halo 5s ease-in-out infinite;
  position: relative;
}
.greeting-halo::after {
  content: "";
  position: absolute; inset: 0;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4l1.8 5.2L19 11l-5.2 1.8L12 18l-1.8-5.2L5 11l5.2-1.8L12 4z" fill="white"/></svg>') center/56% no-repeat;
  filter: drop-shadow(0 1px 3px rgba(40,20,120,.4));
}
@keyframes halo {
  0%, 100% { transform: scale(1); box-shadow: 0 0 60px rgba(122,108,245,.45), 0 0 120px rgba(77,157,248,.18); }
  50% { transform: scale(1.06); box-shadow: 0 0 80px rgba(122,108,245,.6), 0 0 140px rgba(77,157,248,.26); }
}
.greeting h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px; font-weight: 600; line-height: 1.3;
  background: linear-gradient(120deg, var(--text), var(--accent-text));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.greeting p { margin: 14px 0 0; color: var(--text-2); font-size: 15px; }
.greeting .key-missing {
  margin-top: 22px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 13.5px; font-weight: 600;
}

/* сообщения */
.msg { margin: 3px 0; animation: msgIn .24s ease both; max-width: 100%; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-user-col { display: flex; justify-content: flex-end; }
.msg-user-col .bubble {
  max-width: 86%;
  background: var(--user-bubble);
  color: var(--text);
  border-radius: 20px 20px 6px 20px;
  padding: 11px 16px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 15.5px;
}
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 6px; }
.attach-thumb {
  width: 84px; height: 84px; border-radius: 14px; object-fit: cover;
  border: 1px solid var(--line);
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 12px;
  background: var(--bg-soft); font-size: 12.5px;
  max-width: 200px; overflow: hidden;
}
.attach-chip .ic { width: 15px; height: 15px; color: var(--accent); }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msg-ai { display: flex; gap: 10px; align-items: flex-start; }
.ai-ava {
  width: 30px; height: 30px; border-radius: 50%;
  margin-top: 2px; flex: none;
  background:
    radial-gradient(circle at 32% 30%, rgba(255,255,255,.85), rgba(255,255,255,0) 42%),
    linear-gradient(140deg, var(--accent), var(--accent-2) 55%, #4d9df8);
  position: relative;
}
.ai-ava::after {
  content: "";
  position: absolute; inset: 0;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4l1.8 5.2L19 11l-5.2 1.8L12 18l-1.8-5.2L5 11l5.2-1.8L12 4z" fill="white"/></svg>') center/58% no-repeat;
}
.ai-body { flex: 1; min-width: 0; }
.ai-content { font-size: 15.5px; overflow-wrap: break-word; }
.ai-content > :first-child { margin-top: 0; }
.ai-content > :last-child { margin-bottom: 0; }
.msg-tools { display: flex; gap: 2px; margin: 2px 0 4px 40px; opacity: 0; transition: opacity .15s ease; }
.msg:hover .msg-tools, .msg-tools:focus-within { opacity: 1; }
@media (hover: none) { .msg-tools { opacity: .6; } }
.msg-tools .icon-btn { width: 30px; height: 30px; }
.msg-tools .icon-btn .ic { width: 16px; height: 16px; }

.msg-error {
  margin: 10px 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.msg-error button {
  font-weight: 700; color: var(--danger);
  display: inline-flex; align-items: center; gap: 5px;
}
.msg-error button .ic { width: 15px; height: 15px; }

/* индикатор набора */
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

.stream-caret::after {
  content: "";
  display: inline-block;
  width: 8px; height: 17px;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* markdown */
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.35; }
.md h1 { font-size: 21px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15.5px; }
.md p { margin: 9px 0; }
.md ul, .md ol { margin: 9px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md a { color: var(--accent-text); }
.md blockquote {
  margin: 10px 0; padding: 6px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  color: var(--text-2);
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md code.inline {
  font-family: var(--mono); font-size: .88em;
  background: var(--bg-soft);
  padding: 2px 6px; border-radius: 6px;
}
.md .codeblock {
  background: var(--code-bg);
  border-radius: 14px;
  margin: 12px 0;
  overflow: hidden;
}
.md .codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  color: #8f92b2; font-size: 12px;
  font-family: var(--mono);
}
.md .codeblock-head button {
  color: #aeb1d0; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
}
.md .codeblock-head button .ic { width: 14px; height: 14px; }
.md .codeblock pre {
  margin: 0; padding: 4px 16px 14px;
  overflow-x: auto;
  color: var(--code-text);
  font-family: var(--mono); font-size: 13.5px; line-height: 1.55;
}
.md .md-table { border-collapse: collapse; margin: 12px 0; font-size: 14px; width: 100%; display: block; overflow-x: auto; }
.md .md-table th, .md .md-table td {
  border: 1px solid var(--line);
  padding: 7px 12px; text-align: left;
}
.md .md-table th { background: var(--bg-soft); font-weight: 700; }

/* композер */
.composer-wrap {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  position: relative;
}
.composer-wrap::before {
  content: "";
  position: absolute; top: -26px; left: 0; right: 0; height: 26px;
  background: linear-gradient(to top, color-mix(in srgb, var(--bg) 92%, transparent), transparent);
  pointer-events: none;
}
.attrib-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 4px 8px; }
.attrib-row .attach-chip { background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.attrib-row .attach-chip button { display: inline-flex; color: var(--text-2); }
.attrib-row .attach-chip .ic { width: 14px; height: 14px; }

.composer {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 6px 8px;
  box-shadow: var(--shadow-1);
  max-width: 700px;
  margin: 0 auto;
  transition: border-color .15s ease;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  border: 0; background: none; resize: none;
  padding: 9px 6px;
  max-height: 132px;
  font-size: 15.5px; line-height: 1.45;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-3); }
.composer textarea:focus { outline: none; }
.composer .icon-btn { width: 38px; height: 38px; }
.composer .icon-btn .ic { width: 21px; height: 21px; }

.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(91,92,226,.4);
  transition: transform .12s ease, opacity .15s ease;
  flex: none;
}
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .35; box-shadow: none; }
.send-btn.stop { background: var(--bg-soft); color: var(--text); box-shadow: none; }

#btn-mic.recording {
  color: var(--danger);
  background: var(--danger-soft);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(229,72,77,.35); }
  70% { box-shadow: 0 0 0 12px rgba(229,72,77,0); }
  100% { box-shadow: 0 0 0 0 rgba(229,72,77,0); }
}

.composer-note { text-align: center; font-size: 11.5px; color: var(--text-3); padding: 7px 0 2px; }

.scroll-down {
  position: absolute; right: 18px; bottom: 118px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
  color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 4;
  animation: pageIn .2s ease both;
}
.scroll-down .ic { width: 19px; height: 19px; }

/* ============================================================
   БОКОВАЯ ПАНЕЛЬ (дерево диалогов)
   ============================================================ */
.sb-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(12,12,30,.45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.sb-overlay.open { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 41;
  width: min(320px, 86vw);
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  border-radius: 0 26px 26px 0;
  transform: translateX(-104%);
  transition: transform .28s cubic-bezier(.32,.72,.28,1);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) 0 calc(env(safe-area-inset-bottom) + 10px);
}
.sidebar.open { transform: none; box-shadow: var(--shadow-2); }
.sb-head { display: flex; align-items: center; gap: 2px; padding: 0 10px 6px 20px; }
.sb-head h3 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; }
.sb-search {
  margin: 6px 14px 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-inset);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text-3);
}
.sb-search .ic { width: 17px; height: 17px; }
.sb-search input { flex: 1; border: 0; background: none; font-size: 14.5px; min-width: 0; }
.sb-search input:focus { outline: none; }

.sb-list { flex: 1; overflow-y: auto; padding: 2px 10px; overscroll-behavior: contain; }
.sb-section {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 10px 6px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3);
}
.sb-section .ic { width: 14px; height: 14px; }
.sb-section .grow { flex: 1; }
.sb-section .mini-btn { display: inline-flex; color: var(--text-3); padding: 3px; border-radius: 8px; }
.sb-section .mini-btn:active { color: var(--accent); }
.sb-section .mini-btn .ic { width: 16px; height: 16px; }

.sb-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 10px 10px;
  border-radius: 13px;
  transition: background .13s ease;
}
.sb-item:active { background: var(--bg-soft); }
.sb-item.active { background: var(--accent-soft); }
.sb-item.active .sb-item-title { color: var(--accent-text); }
.sb-item .ic { width: 17px; height: 17px; color: var(--text-3); flex: none; }
.sb-item.active > .ic { color: var(--accent); }
.sb-item-main { flex: 1; min-width: 0; }
.sb-item-title {
  font-size: 14.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-item-meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .icon-btn { width: 28px; height: 28px; }
.sb-item .icon-btn .ic { width: 17px; height: 17px; }

.sb-empty { text-align: center; color: var(--text-3); font-size: 13.5px; padding: 36px 20px; }

.sb-foot {
  display: flex; align-items: center; gap: 4px;
  border-top: 1px solid var(--line);
  padding: 8px 10px 0;
  margin: 6px 14px 0;
}
.sb-foot .foot-btn {
  flex: 1;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 8px;
  border-radius: 12px;
  font-size: 14px; font-weight: 600; color: var(--text-2);
}
.sb-foot .foot-btn:active { background: var(--bg-soft); color: var(--text); }
.sb-foot .foot-btn .ic { width: 18px; height: 18px; }

/* ============================================================
   МОДАЛКИ / ШИТЫ / ТОСТЫ
   ============================================================ */
.ov {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(12,12,30,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn .18s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.ov.closing { animation: fadeOut .16s ease both; }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
.modal {
  width: 100%; max-width: 400px;
  background: var(--bg-elev);
  border-radius: 22px;
  padding: 22px 20px 16px;
  box-shadow: var(--shadow-2);
  animation: popIn .2s cubic-bezier(.3,1.2,.4,1) both;
}
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(10px); } to { opacity: 1; transform: none; } }
.ov.closing .modal { animation: popOut .16s ease both; }
@keyframes popOut { to { opacity: 0; transform: scale(.96); } }
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.modal .modal-text { color: var(--text-2); font-size: 14.5px; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; padding: 12px; }

.modal .form-field { margin-top: 14px; }
.modal .form-field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.modal .form-field input {
  width: 100%;
  background: var(--bg-inset);
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  transition: border-color .15s ease;
}
.modal .form-field input:focus { outline: none; border-color: var(--accent); }
.modal .form-field input.mono { font-size: 13.5px; font-family: var(--mono); }

/* bottom sheet */
.sheet-ov {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(12,12,30,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .18s ease both;
}
.sheet-ov.closing { animation: fadeOut .16s ease both; }
.sheet {
  width: 100%; max-width: 440px;
  background: var(--bg-elev);
  border-radius: 24px 24px 0 0;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  animation: sheetUp .26s cubic-bezier(.32,.72,.28,1) both;
}
@keyframes sheetUp { from { transform: translateY(60%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-ov.closing .sheet { animation: sheetDown .18s ease both; }
@keyframes sheetDown { to { transform: translateY(100%); opacity: .4; } }
.sheet-title { text-align: center; font-size: 13px; color: var(--text-3); font-weight: 600; padding: 8px 0 10px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 14px 14px;
  border-radius: 14px;
  font-size: 15.5px; font-weight: 500;
  transition: background .12s ease;
}
.sheet-item:active { background: var(--bg-soft); }
.sheet-item .ic { width: 20px; height: 20px; color: var(--text-2); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.danger .ic { color: var(--danger); }
.sheet-cancel {
  width: 100%; margin-top: 6px;
  padding: 14px; border-radius: 14px;
  background: var(--bg-soft);
  font-weight: 700; font-size: 15.5px;
}

/* тосты */
#toast-root {
  position: fixed; left: 0; right: 0;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: color-mix(in srgb, var(--text) 92%, transparent);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-2);
  animation: toastIn .22s cubic-bezier(.3,1.1,.4,1) both;
  max-width: 86vw;
  text-align: center;
}
.toast.out { animation: toastOut .2s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.96); } }

/* утилиты */
.hidden { display: none !important; }
.spin { animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .greeting h2 { font-size: 34px; }
}
