/* Пульт Claude — дизайн: синтез Claude (тёплая бумага, засечки),
   Gemini (чистая колонка, круглая отправка), Kimi (воздух, крупные радиусы). */

:root {
  color-scheme: light;
  --bg: #f5f3ee;            /* тёплая бумага */
  --bg-side: #efede6;
  --surface: #ffffff;
  --surface2: #f8f7f3;
  --line: #e5e2d9;
  --line2: #d8d4c8;
  --text: #21201c;
  --muted: #807a6e;
  --accent: #c9613d;        /* терракота */
  --accent-h: #b5512f;
  --accent-soft: #f3e5dd;
  --ok: #3d8f63;
  --err: #bf4640;
  --err-soft: #f8e9e6;
  --warn: #b97c1f;
  --user-bubble: #eae7de;
  --shadow: 0 1px 2px rgba(60,50,30,.06), 0 8px 28px rgba(60,50,30,.09);
  --shadow-big: 0 4px 12px rgba(50,40,20,.08), 0 24px 64px rgba(50,40,20,.16);
  --r: 14px;
  --r-big: 22px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Cascadia Mono", monospace;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1b18;
  --bg-side: #191815;
  --surface: #26241f;
  --surface2: #211f1b;
  --line: #37342c;
  --line2: #454136;
  --text: #eceadf;
  --muted: #9a948a;
  --accent: #d97757;
  --accent-h: #e08a6d;
  --accent-soft: #3a2b23;
  --ok: #5cb885;
  --err: #e0756a;
  --err-soft: #3a2624;
  --warn: #d9a04a;
  --user-bubble: #32302a;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 28px rgba(0,0,0,.35);
  --shadow-big: 0 4px 12px rgba(0,0,0,.3), 0 24px 64px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
@supports (height: 100dvh) { html, body, #app { height: 100dvh; } }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); overflow: hidden;
  -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; }
button:hover { border-color: var(--line2); background: var(--surface2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
button.danger { background: transparent; border-color: var(--line); color: var(--err); }
button.danger:hover { background: var(--err-soft); border-color: var(--err); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--surface2); border-color: transparent; color: var(--text); }
button.small { padding: 4px 12px; font-size: 13px; }
button.wide { width: 100%; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
select option { background: var(--surface); color: var(--text); }
select { cursor: pointer; appearance: none; -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" fill="none" stroke="%23807a6e" stroke-width="1.6" stroke-linecap="round"/></svg>');
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }
textarea { resize: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row input, .row select { flex: 1; min-width: 0; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
pre { font-family: var(--mono); font-size: 13px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

#app { display: grid; grid-template-columns: 292px 1fr; height: 100%; }

/* ── боковая панель ── */
#side { background: var(--bg-side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 19px; letter-spacing: .2px; padding: 2px 4px; }
.logo { color: var(--accent); font-size: 20px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--err); margin-left: auto; transition: background .3s; }
.conn.on { background: var(--ok); }

.limits { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-big); padding: 14px; box-shadow: 0 1px 2px rgba(60,50,30,.04); }
.gauge-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.gauge-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--ok), #6fbe92); transition: width .5s ease; }
.bar i.warn { background: linear-gradient(90deg, #d1971f, #e7b34a); }
.bar i.crit { background: linear-gradient(90deg, #c4453b, #e0756a); }
.gauge-foot { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.gauge-actions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }

.proj label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); display: block; margin: 0 4px 6px; }
.proj select { width: 100%; }
.proj .row button { flex: 0 0 auto; width: 38px; padding: 8px 0; text-align: center; }

#newSession { box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent); }

#sessions { list-style: none; margin: 0; padding: 2px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
#sessions li { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 12px; cursor: pointer; color: var(--text); border: 1px solid transparent; }
#sessions li:hover { background: var(--surface); }
#sessions li.active { background: var(--surface); border-color: var(--line); box-shadow: 0 1px 2px rgba(60,50,30,.05); }
#sessions li .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
#sessions li .st { width: 7px; height: 7px; border-radius: 50%; background: var(--line2); flex: 0 0 auto; }
#sessions li .st.busy { background: var(--accent); animation: pulse 1.2s infinite; }
#sessions li .st.pending { background: var(--warn); animation: pulse 1.2s infinite; }
#sessions li .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 8px; }
#sessions li:hover .del { opacity: 1; }
#sessions li .del:hover { color: var(--err); background: var(--err-soft); }
#sessions li .when { color: var(--muted); font-size: 11px; flex: 0 0 auto; }
@keyframes pulse { 50% { opacity: .35; } }

.side-foot { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }

/* ── основная область ── */
#main { display: flex; flex-direction: column; min-width: 0; position: relative; }
#head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; }
#head #title { flex: 0 1 340px; min-width: 120px; background: transparent; border-color: transparent; font-family: var(--serif); font-size: 17px; padding: 6px 10px; border-radius: 10px; }
#head #title:hover { background: var(--surface2); }
#head #title:focus { background: var(--surface); border-color: var(--accent); }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status.busy { color: var(--accent); }
.status.pending { color: var(--warn); }
#head select { background-color: transparent; border-color: transparent; color: var(--muted); font-size: 13px; }
#head select:hover { background-color: var(--surface2); }
#burger { display: none; }
#backBtn { font-size: 17px; padding: 6px 12px; }
#offlineBar { background: var(--warn); color: #fff; text-align: center; font-size: 13px; padding: 6px 12px; }
#composerHint { text-align: center; margin-top: 8px; font-size: 11.5px; opacity: .8; }
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list button { text-align: left; justify-content: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; }
/* домашний экран */
.home { max-width: 640px !important; margin: 6vh auto 0 !important; text-align: center; }
.home h1 { font-family: var(--serif); font-weight: 600; font-size: 27px; margin: 0 0 6px; }
.home .sub { color: var(--muted); margin-bottom: 22px; }
.home .home-new { font-size: 16px; padding: 12px 26px; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent); }
.home-recent { margin-top: 26px; text-align: left; }
.home-recent .hr-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; }
.home-recent .hr-item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.home-recent .hr-item:hover { border-color: var(--line2); transform: translateY(-1px); }
.home-recent .hr-item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-recent .hr-item .when { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

/* лента */
#log { flex: 1; overflow-y: auto; padding: 10px 20px 22px; scroll-behavior: smooth; }
#log > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 60vh; color: var(--muted); font-family: var(--serif); font-size: 21px; text-align: center; gap: 6px; }
.empty::before { content: "✦"; color: var(--accent); font-size: 30px; }

.msg { margin: 14px auto; }
.msg.user { background: var(--user-bubble); border-radius: var(--r-big); border-bottom-right-radius: 8px; padding: 12px 16px; width: fit-content; max-width: min(640px, 88%); white-space: pre-wrap; word-wrap: break-word; }
#log > .msg.user { margin-left: auto; margin-right: max(calc((100% - 780px) / 2), 0px); }
.msg.user img { max-width: 220px; border-radius: 10px; display: block; margin-top: 8px; }
.msg.assistant { position: relative; padding-left: 26px; }
.msg.assistant::before { content: "✦"; position: absolute; left: 0; top: 2px; color: var(--accent); font-size: 15px; }
.msg.assistant.live::after { content: ""; display: inline-block; width: 8px; height: 15px; background: var(--accent); margin-left: 3px; vertical-align: text-bottom; animation: blink 1s steps(2) infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.md { overflow-wrap: break-word; }
.md p { margin: .45em 0; }
.md h1, .md h2, .md h3 { font-family: var(--serif); font-weight: 600; margin: .9em 0 .35em; line-height: 1.25; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { margin: .4em 0; padding-left: 1.4em; }
.md li { margin: .18em 0; }
.md a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.md pre { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; box-shadow: 0 1px 2px rgba(60,50,30,.04); }
.md pre code { background: none; border: 0; padding: 0; }

.sys { text-align: center; color: var(--muted); font-size: 12.5px; margin: 12px auto; }
.sys.err { color: var(--err); background: var(--err-soft); border: 1px solid color-mix(in srgb, var(--err) 25%, transparent); border-radius: var(--r); padding: 10px 14px; font-size: 13.5px; text-align: left; white-space: pre-wrap; }
.sys.perm { color: var(--warn); }

.raw { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; white-space: pre-wrap; }

/* карточки инструментов */
.tool { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin: 8px auto; overflow: hidden; box-shadow: 0 1px 2px rgba(60,50,30,.04); }
.tool-head { display: flex; align-items: center; gap: 10px; padding: 9px 13px; cursor: pointer; user-select: none; }
.tool-head:hover { background: var(--surface2); }
.tool-head::before { content: "⚙"; color: var(--muted); font-size: 13px; }
.tool-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.tool-sum { color: var(--muted); font-size: 12.5px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tool-state { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.tool-state.ok { color: var(--ok); }
.tool-state.err { color: var(--err); }
.tool-body { display: none; border-top: 1px solid var(--line); padding: 10px 13px; max-height: 340px; overflow: auto; background: var(--surface2); }
.tool.open .tool-body { display: block; }
.tool-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
.res-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 10px 0 4px; }

/* индикатор набора */
#typing { display: none; padding-left: 26px; margin: 14px auto; }
#typing.on { display: block; }
#typing i { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--muted); animation: tp 1.2s infinite; }
#typing i:nth-child(2) { animation-delay: .2s; } #typing i:nth-child(3) { animation-delay: .4s; }
@keyframes tp { 30% { transform: translateY(-4px); opacity: .5; } }

/* пресеты и композер */
#presets { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 20px 10px; max-width: 820px; margin: 0 auto; width: 100%; }
button.preset { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; color: var(--text); background: var(--surface); border: 1px solid var(--line); padding: 7px 14px; font-size: 13.5px; box-shadow: 0 1px 2px rgba(60,50,30,.05); }
button.preset:hover { border-color: var(--line2); transform: translateY(-1px); }
button.preset .e { font-size: 15px; }
button.preset .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

#composer { padding: 0 20px 18px; width: 100%; max-width: 820px; margin: 0 auto; }
#composer .shell { background: var(--surface); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); padding: 6px 8px 6px 18px; display: flex; align-items: flex-end; gap: 10px; transition: border-color .15s, box-shadow .15s; }
#composer .shell:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
#composer textarea { flex: 1; border: 0; background: none; box-shadow: none; padding: 10px 0; max-height: 220px; line-height: 1.5; }
#sendBtn { flex: 0 0 auto; width: 40px; height: 40px; padding: 0; border-radius: 50%; background: var(--accent); border-color: var(--accent); color: #fff; font-size: 18px; line-height: 1; display: flex; align-items: center; justify-content: center; }
#sendBtn:hover { background: var(--accent-h); }
#stopBtn { border: 0; }
#attach { display: flex; gap: 8px; padding: 0 0 8px; }
#attach .att { position: relative; display: inline-block; }
#attach img { height: 54px; border-radius: 10px; border: 1px solid var(--line); display: block; }
#attach .att-x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; padding: 0; font-size: 11px; line-height: 1; border-radius: 50%; background: var(--text); color: var(--bg); border: 0; }

/* диалоги */
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--r-big); padding: 22px; max-width: 560px; width: calc(100vw - 48px); box-shadow: var(--shadow-big); }
dialog.wide { max-width: 760px; }
dialog::backdrop { background: rgba(30,25,15,.45); backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 12px; font-family: var(--serif); font-size: 19px; font-weight: 600; }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
dialog input, dialog textarea, dialog select { width: 100%; margin: 4px 0 10px; }
dialog label { font-size: 12.5px; color: var(--muted); }

.perm-body .k { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 10px 0 4px; }
.perm-body pre { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 6px; max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.perm-body pre.diff-old { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.perm-body pre.diff-new { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }

.ask-q { margin-bottom: 14px; }
.ask-q .qh { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent); margin-bottom: 3px; }
.ask-q .qt { font-weight: 600; margin-bottom: 8px; }
label.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin: 6px 0; cursor: pointer; transition: border-color .12s, background .12s; }
label.opt:hover { border-color: var(--accent); background: var(--surface2); }
label.opt input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
label.opt .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
input.other { margin-top: 4px; }

.preset-row { display: grid; grid-template-columns: 46px 40px 1fr 34px; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding: 12px 0; }
.preset-row .pp { grid-column: 1 / -1; min-height: 54px; resize: vertical; }
.preset-row .pa { grid-column: 1 / -1; }
.preset-row input[type=color] { padding: 2px; height: 38px; cursor: pointer; }
.preset-row .pd { padding: 6px 8px; }

/* вход */
.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 50; }
.overlay .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-big); box-shadow: var(--shadow-big); max-width: 520px; width: calc(100vw - 48px); padding: 30px; }
.overlay h2 { font-family: var(--serif); font-weight: 600; margin: 0 0 10px; }
.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 14px; margin: 14px 0; }
.steps input { width: 100%; }
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 999px; padding: 10px 20px; z-index: 100; box-shadow: var(--shadow-big); font-size: 14px; transition: opacity .3s; }
.toast.err { background: var(--err); color: #fff; }
.toast.hidden { opacity: 0; pointer-events: none; }

/* мобильная вёрстка */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side { position: fixed; inset: 0 64px 0 0; z-index: 40; box-shadow: var(--shadow-big); transform: translateX(-102%); transition: transform .25s ease; max-width: 340px; }
  #side.open { transform: none; }
  #scrim { position: fixed; inset: 0; z-index: 39; background: rgba(20,15,8,.4); opacity: 0; pointer-events: none; transition: opacity .25s; }
  #scrim.on { opacity: 1; pointer-events: auto; }
  #burger { display: inline-flex; }
  #head { padding: 10px 12px; flex-wrap: wrap; }
  #log { padding: 8px 14px 18px; }
  #presets, #composer { padding-left: 14px; padding-right: 14px; }
  #composerHint { display: none; }
  .msg.user { max-width: 94%; }
  #sessions li .del { opacity: 1; }
}
@media (hover: none) { #sessions li .del { opacity: 1; } }
/* таблицы в ответах */
.tbl-wrap { overflow-x: auto; margin: .5em 0; }
.md table { border-collapse: collapse; font-size: 13.5px; min-width: 50%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface2); font-weight: 600; }
