:root {
  --bg: #f7f6f2; --surface: #ffffff; --surface-2: #efede6; --text: #1d1c1a; --muted: #75716a; --line: #e4e1d8;
  --accent: #c96442; --accent-text: #ffffff; --ok: #2f8f4e; --bad: #c8392b; --warn: #b7791f;
  --code-bg: #f1efe8; --add: #e7f4ea; --del: #fbe9e6; --user: #ece9e0;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1c; --surface: #2a2926; --surface-2: #33312d; --text: #f0eee8; --muted: #a29d93; --line: #3b3935;
    --accent: #d97757; --ok: #4cb36d; --bad: #ef6a5a; --warn: #e3a64a;
    --code-bg: #24231f; --add: #1d3324; --del: #3d201c; --user: #393731;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); font-size: 14px; }

/* --- каркас ------------------------------------------------------------- */
#app { min-height: 100%; }
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--line);
}
.topbar .titles { flex: 1; min-width: 0; text-align: center; }
.topbar .t1 { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; color: var(--text); flex: none; }
.iconbtn:active { background: var(--surface-2); }
.content { flex: 1; padding: 12px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 720px; width: 100%; margin: 0 auto; }
.brand { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin: 6px 4px 0; font-family: ui-serif, "New York", Georgia, serif; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 2px 4px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.wait { background: var(--warn); }
.dot.busy { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }
h2.section { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; }

/* --- списки ------------------------------------------------------------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .r1 { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--muted); font-size: 18px; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }

/* --- карточки ----------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin: 0 0 12px; }
.card.attn { border-color: color-mix(in srgb, var(--warn) 60%, var(--line)); }
.card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.card .ttl { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.label { font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
pre {
  background: var(--code-bg); border-radius: 10px; padding: 10px 12px; margin: 6px 0 0; border: 1px solid var(--line);
  font: 12.5px/1.5 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 55vh; overflow: auto;
}
pre.add { background: var(--add); }
pre.del { background: var(--del); }
code { font: 0.9em ui-monospace, "SF Mono", Menlo, monospace; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.btn { flex: 1; min-height: 46px; border-radius: 12px; font-weight: 600; padding: 0 14px; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.allow { background: var(--ok); color: #fff; }
.btn.deny { background: var(--surface-2); color: var(--bad); }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: scale(.98); }
.opt { display: block; width: 100%; text-align: left; padding: 11px 13px; margin-top: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.opt.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.opt .desc { display: block; font-size: 13px; color: var(--muted); }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
select, input, textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; min-height: 96px; }
input.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; text-transform: uppercase; }

/* --- переписка ---------------------------------------------------------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg-user { align-self: flex-end; max-width: 86%; background: var(--user); padding: 9px 14px; border-radius: 18px 18px 6px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { align-self: stretch; overflow-wrap: anywhere; }
.msg-ai p { margin: 0 0 8px; }
.msg-ai p:last-child { margin-bottom: 0; }
.msg-ai h3, .msg-ai h4 { margin: 10px 0 6px; font-size: 16px; }
.msg-ai ul, .msg-ai ol { margin: 4px 0 8px; padding-left: 22px; }
.msg-ai li { margin: 2px 0; }
.msg-sys { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 10px; background: var(--surface-2); border-radius: 99px; }
.tool { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.tool > button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 8px 12px; font-size: 14px; }
.tool .tname { font-weight: 600; flex: none; }
.tool .tsum { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.tool .tst { flex: none; font-size: 13px; }
.tool .tst.ok { color: var(--ok); }
.tool .tst.bad { color: var(--bad); }
.tool .tbody { padding: 0 12px 12px; }
.typing { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }

/* --- нижняя панель ------------------------------------------------------ */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.composer .inner { max-width: 720px; margin: 0 auto; }
.composer .box { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 6px 6px 6px 14px; }
.composer textarea { border: 0; padding: 7px 0; min-height: 22px; max-height: 160px; background: transparent; line-height: 1.4; }
.composer .send { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 18px; flex: none; }
.composer .send:disabled { opacity: .35; }
.composer .stop { width: 36px; height: 36px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 14px; flex: none; }
.composer .hint { font-size: 12px; color: var(--muted); padding: 4px 6px 0; display: flex; gap: 10px; flex-wrap: wrap; }
.composer .hint .err { font-size: 12px; }
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 18px); z-index: 6; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 28px; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

/* --- пустые и служебные экраны ----------------------------------------- */
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px 24px; gap: 10px; }
.center .big { font-size: 22px; font-weight: 650; font-family: ui-serif, "New York", Georgia, serif; }
.center .p { color: var(--muted); max-width: 340px; }
ol.howto { text-align: left; padding-left: 20px; max-width: 340px; }
ol.howto li { margin: 6px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px); z-index: 9; background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-size: 14px; max-width: 90vw; }

/* --- вспомогательные классы (CSP запрещает inline-стили) ------------------- */
.btn-wide { flex: none; margin-top: 12px; min-width: 200px; }
.note { margin: 16px 4px; }
.hintline { margin: 6px 2px 0; }
.content.with-composer { padding-bottom: calc(env(safe-area-inset-bottom) + 170px); }
.content.top-safe { padding-top: calc(env(safe-area-inset-top) + 24px); }
.card.spaced { margin-top: 14px; }
.actions.narrow { width: 100%; max-width: 340px; }
.danger { color: var(--bad); }
select.mini { width: auto; padding: 2px 6px; border-radius: 8px; font-size: 12px; }
.card pre { max-height: none; }
.flag { display: inline-block; font-size: 12px; font-weight: 600; color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); border-radius: 6px; padding: 1px 6px; margin: 6px 6px 0 0; }
.inv { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); border-radius: 3px; }
