:root {
  --paper: #FAF9F5;
  --panel: #F0EEE6;
  --panel-2: #E8E5DA;
  --ink: #1F1E1D;
  --ink-2: #3D3C38;
  --muted: #73726C;
  --line: #E3E0D5;
  --clay: #D97757;
  --clay-press: #C6613F;
  --clay-soft: #F5E6DE;
  --code-bg: #F3F1EA;
  --danger: #B5462F;
  --ok: #5B8A5A;
  --serif: "Tiempos Text", "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: "Styrene B", ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
[data-theme="dark"] {
  --paper: #262624;
  --panel: #30302E;
  --panel-2: #3A3937;
  --ink: #F5F4EE;
  --ink-2: #DEDCD3;
  --muted: #A3A097;
  --line: #3D3C39;
  --clay-soft: #4A3229;
  --code-bg: #1F1E1D;
  --danger: #E07A62;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
body { font: 15.5px/1.55 var(--sans); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--clay); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--clay-press); }
[data-theme="dark"] a { color: #E99A7E; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 820px; margin: 0 auto; }

/* ---------- верхняя панель ---------- */
.bar { display: flex; align-items: center; gap: 6px; padding: 10px 10px 8px; border-bottom: 1px solid transparent; flex: none; }
.bar.scrolled { border-bottom-color: var(--line); }
.bar-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding-left: 4px; }
.bar-text { min-width: 0; }
.bar-h { font: 600 16px/1.25 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub:empty { display: none; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); flex: none; }
.icon-btn:active { background: var(--panel); }

.spark { width: 22px; height: 22px; flex: none; background: url(icon.svg) center/contain no-repeat; display: inline-block; }
.spark.spin { animation: spin 2.4s cubic-bezier(.5,.1,.5,.9) infinite; }
@keyframes spin { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(180deg) scale(.82); } 100% { transform: rotate(360deg) scale(1); } }
@media (prefers-reduced-motion: reduce) { .spark.spin { animation: pulse 2s ease-in-out infinite; } @keyframes pulse { 50% { opacity: .45; } } }

.menu { position: absolute; right: max(10px, calc((100vw - 820px) / 2 + 10px)); top: 54px; z-index: 20; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 6px; min-width: 220px; box-shadow: 0 10px 30px rgba(31, 30, 29, .14); }
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 9px; }
.menu button:active { background: var(--panel); }

#view { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 0 16px 20px; }

/* ---------- главная ---------- */
.hello { padding: 34px 4px 22px; }
.hello h1 { font: 400 31px/1.2 var(--serif); letter-spacing: -.01em; margin: 0; display: flex; align-items: center; gap: 12px; }
.hello h1 .spark { width: 30px; height: 30px; }
.hello p { margin: 10px 0 0; color: var(--muted); }

.quick { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 12px 12px 10px 16px; }
.quick textarea { width: 100%; border: 0; background: transparent; resize: none; font: inherit; color: var(--ink); outline: none; min-height: 52px; max-height: 200px; }
.quick-row { display: flex; align-items: center; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); font-size: 13.5px; color: var(--ink-2); max-width: 70%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip svg { width: 15px; height: 15px; flex: none; }
.quick-row .send { margin-left: auto; }

.section-h { font: 600 13px/1 var(--sans); color: var(--muted); margin: 28px 4px 10px; display: flex; justify-content: space-between; align-items: center; }
.section-h button { color: var(--clay-press); font-weight: 500; }
[data-theme="dark"] .section-h button { color: #E99A7E; }

.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--panel); }
.row-main { flex: 1; min-width: 0; }
.row-t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row-meta { font-size: 12.5px; color: var(--muted); flex: none; text-align: right; }
.folder { width: 36px; height: 36px; border-radius: 10px; background: var(--panel); display: grid; place-items: center; flex: none; font: 600 15px/1 var(--serif); color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--clay); display: inline-block; flex: none; }
.row .dot { animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

.search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; outline: none; margin: 4px 0 6px; }
.empty { color: var(--muted); padding: 30px 6px; text-align: center; }
.more { display: block; margin: 12px auto; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); font-size: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); font-weight: 500; }
.btn.ghost { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }

/* ---------- чат ---------- */
.chat { padding-top: 8px; display: flex; flex-direction: column; gap: 14px; }
.msg-user { align-self: flex-end; max-width: 86%; background: var(--panel); border-radius: 18px 18px 6px 18px; padding: 9px 14px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-user .imgs { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 6px; }
.msg-user .imgs img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--panel-2); }
.msg-user .via { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg-user.pending { opacity: .7; }

.msg-ai { max-width: 100%; overflow-wrap: anywhere; color: var(--ink); }
.msg-ai > :first-child { margin-top: 0; }
.msg-ai > :last-child { margin-bottom: 0; }
.msg-ai p { margin: 0 0 .7em; }
.msg-ai h1, .msg-ai h2, .msg-ai h3, .msg-ai h4 { font-family: var(--serif); font-weight: 500; line-height: 1.3; margin: 1em 0 .45em; }
.msg-ai h1 { font-size: 1.35em; } .msg-ai h2 { font-size: 1.22em; } .msg-ai h3, .msg-ai h4 { font-size: 1.08em; }
.msg-ai ul, .msg-ai ol { margin: 0 0 .7em; padding-left: 1.35em; }
.msg-ai li { margin: .2em 0; }
.msg-ai li::marker { color: var(--muted); }
.msg-ai blockquote { margin: 0 0 .7em; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--ink-2); }
.msg-ai hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.msg-ai code { font: 13.5px/1.4 var(--mono); background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.msg-ai .pre { position: relative; margin: 0 0 .8em; border: 1px solid var(--line); border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.msg-ai .pre-h { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px 5px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.msg-ai .pre-h button { font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.msg-ai pre { margin: 0; padding: 10px 12px; overflow-x: auto; font: 13px/1.5 var(--mono); }
.msg-ai pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.msg-ai .table { overflow-x: auto; margin: 0 0 .8em; }
.msg-ai table { border-collapse: collapse; font-size: 14px; }
.msg-ai th, .msg-ai td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.msg-ai th { background: var(--panel); font-weight: 600; }

.tools { border-left: 2px solid var(--line); padding-left: 12px; margin-left: 2px; font-size: 13.5px; color: var(--muted); }
.tools-h { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 2px 0; color: var(--muted); }
.tools-h svg { width: 14px; height: 14px; transition: transform .15s; flex: none; }
.tools.open > .tools-h svg { transform: rotate(90deg); }
.tools-h .last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tools-body { display: none; padding: 4px 0 2px; }
.tools.open > .tools-body { display: block; }
.tool { padding: 3px 0; }
.tool-h { display: flex; gap: 6px; width: 100%; text-align: left; align-items: baseline; color: var(--ink-2); }
.tool-h b { font-weight: 600; flex: none; }
.tool-h span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--muted); }
.tool.err .tool-h b { color: var(--danger); }
.tool-d { display: none; margin: 4px 0 6px; }
.tool.open .tool-d { display: block; }
.tool-d pre { margin: 0 0 4px; padding: 8px 10px; border-radius: 9px; background: var(--code-bg); border: 1px solid var(--line); font: 12px/1.45 var(--mono); color: var(--ink-2); white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; }

.sys { align-self: center; font-size: 12.5px; color: var(--muted); padding: 2px 10px; text-align: center; }
.sig-photo img { max-width: min(100%, 360px); max-height: 420px; border-radius: 12px; display: block; cursor: zoom-in; border: 1px solid var(--line); }
.sig-cap { margin-top: 6px; }
.card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); background: var(--paper); max-width: 420px; }
.card:active { background: var(--panel); }
.card .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--clay-soft); color: var(--clay-press); display: grid; place-items: center; flex: none; }
[data-theme="dark"] .card .ic { color: #E99A7E; }
.card .ic svg { width: 19px; height: 19px; }
.card .ct { min-width: 0; }
.card .ct div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .ct .cs { font-size: 12.5px; color: var(--muted); }
.from-pc { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; display: flex; align-items: center; gap: 5px; }
.from-pc .spark { width: 13px; height: 13px; }

.err-box { border: 1px solid var(--danger); color: var(--danger); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; }

/* ---------- поле ввода ---------- */
.composer { flex: none; padding: 6px 12px calc(10px + var(--safe-b)); background: linear-gradient(to bottom, transparent, var(--paper) 14px); }
.working { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); padding: 2px 6px 8px; min-width: 0; }
.working span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.working .spark { width: 18px; height: 18px; }
.input-row { display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 5px; box-shadow: 0 1px 0 rgba(31, 30, 29, .03); }
.input-row:focus-within { border-color: color-mix(in srgb, var(--clay) 45%, var(--line)); }
.input-row textarea { flex: 1; border: 0; background: transparent; resize: none; font: inherit; color: var(--ink); outline: none; padding: 8px 4px; max-height: 180px; min-height: 38px; line-height: 1.4; }
.input-row .attach { border-radius: 50%; color: var(--muted); }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--clay); color: #fff; display: grid; place-items: center; flex: none; }
.send:active { background: var(--clay-press); }
.send:disabled { opacity: .4; }
.send svg { width: 20px; height: 20px; stroke-width: 2.3; }
.send.stop { background: var(--ink); color: var(--paper); }
.send.stop svg { fill: currentColor; stroke: none; }
.attach-strip { display: flex; gap: 8px; padding: 0 4px 8px; overflow-x: auto; }
.att { position: relative; flex: none; }
.att img, .att .fbox { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); display: grid; place-items: center; background: var(--panel); font-size: 11px; color: var(--muted); text-align: center; padding: 4px; overflow: hidden; word-break: break-all; }
.att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--paper); display: grid; place-items: center; font-size: 14px; line-height: 1; }

/* ---------- настройки и команды ---------- */
.opts { display: flex; gap: 6px; overflow-x: auto; padding: 0 2px 8px; scrollbar-width: none; }
.opts::-webkit-scrollbar { display: none; }
.opt { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.opt svg { width: 13px; height: 13px; color: var(--muted); }
.opt.on { background: var(--clay-soft); border-color: color-mix(in srgb, var(--clay) 40%, var(--line)); color: var(--clay-press); }
[data-theme="dark"] .opt.on { color: #F0B49C; }
.slash-btn { font: 600 18px/1 var(--mono); }

.slash { max-height: 46vh; overflow-y: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; margin: 0 0 8px; box-shadow: 0 10px 30px rgba(31, 30, 29, .12); padding: 4px; }
.slash button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px; }
.slash button:active, .slash button.sel { background: var(--panel); }
.slash b { font: 600 14px/1.3 var(--mono); color: var(--ink); }
.slash b i { font-style: normal; color: var(--muted); font-weight: 400; }
.slash span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slash .group { font-size: 12px; color: var(--muted); padding: 8px 10px 4px; }

.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(20, 20, 19, .38); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 820px; max-height: 82vh; overflow-y: auto; background: var(--paper); border-radius: 20px 20px 0 0; padding: 6px 12px calc(14px + var(--safe-b)); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet-h { font: 500 20px/1.3 var(--serif); padding: 0 6px; }
.sheet-sub { font-size: 13px; color: var(--muted); padding: 4px 6px 8px; }
.sheet-sub:empty { display: none; }
.sheet-list button { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 11px 8px; border-radius: 12px; }
.sheet-list button:active { background: var(--panel); }
.sheet-list .mk { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line); flex: none; margin-top: 1px; display: grid; place-items: center; }
.sheet-list button.sel .mk { border-color: var(--clay); background: var(--clay); }
.sheet-list button.sel .mk::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.sheet-list .st { font-weight: 500; }
.sheet-list .sd { font-size: 13px; color: var(--muted); margin-top: 1px; }
.sheet-list button:disabled { opacity: .45; }

.lightbox { position: fixed; inset: 0; background: rgba(20, 20, 19, .92); display: grid; place-items: center; z-index: 50; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: 90vw; }

.login { padding: 80px 20px; text-align: center; }
.login h1 { font: 400 28px/1.25 var(--serif); margin: 18px 0 8px; }
.login p { color: var(--muted); }
.login .spark { width: 44px; height: 44px; }
.sheet-list.actions .mk { display: none; }
.sheet-list.actions button { padding-left: 10px; }
.slash b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* живой ответ, пока Claude пишет */
.msg-ai.streaming > :last-child::after { content: ""; display: inline-block; width: .5em; height: 1em; margin-left: 2px; vertical-align: -.12em; background: var(--clay); border-radius: 1px; animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
