:root {
  --paper: #E1E3DD;
  --panel: #EEF0EA;
  --ink: #15171A;
  --gray: #5D6259;
  --line: #B9BDB3;
  --accent: #2438D9;
  --on-accent: #ffffff;
  --danger: #A6261F;
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121416; --panel: #1B1E22; --ink: #E6E8E1; --gray: #9AA095;
    --line: #30353A; --accent: #8C9AFF; --on-accent: #0E1030; --danger: #FF8A80;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mark { width: 28px; height: 28px; flex: none; }
.mark .dither { fill: currentColor; }

/* ---------- кнопки и поля ---------- */
.primary {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 6px;
  padding: 9px 16px; font-weight: 600;
}
.primary:disabled { opacity: .55; cursor: default; }
.quiet {
  background: none; border: 0; padding: 4px 6px; color: var(--gray); border-radius: 4px;
}
.quiet:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.quiet.danger:hover { color: var(--danger); }
input[type=search], input[type=password], input.title-input, textarea {
  width: 100%; background: var(--panel); border: 1.5px solid var(--line); border-radius: 6px;
  padding: 9px 12px; outline-offset: 0;
}
input:focus, textarea:focus { border-color: var(--ink); }
.error { color: var(--danger); margin: 8px 0 0; font-size: 14px; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; isolation: isolate; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1.5px solid var(--ink);
  border-radius: 10px; padding: 28px 24px; position: relative;
}
.login-card::after {
  content: ""; position: absolute; inset: 0; transform: translate(6px, 6px); z-index: -1; border-radius: 10px;
  background: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0) 0 0 / 4px 4px;
}
.login-card h1 { margin: 12px 0 0; font-size: 26px; letter-spacing: -.01em; }
.login-card .sub { margin: 2px 0 20px; color: var(--gray); }
.login-card label { display: block; font-weight: 500; margin-bottom: 6px; }
.login-card .primary { width: 100%; margin-top: 16px; }

/* ---------- каркас ---------- */
.shell { height: 100dvh; display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.rail {
  display: flex; flex-direction: column; min-height: 0; border-right: 1.5px solid var(--ink);
  background: var(--paper);
}
.rail-head { padding: 18px 16px 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
.device-status { margin: 8px 0 0; display: flex; align-items: center; gap: 8px; color: var(--gray); font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--gray); flex: none; }
.device-status.live .dot { background: var(--accent); border-color: var(--accent); }
.rail-tools { padding: 8px 16px 12px; display: grid; gap: 8px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--ink); border-radius: 8px; overflow: hidden; }
.tab { font: inherit; font-weight: 600; font-size: 15px; padding: 8px 0; background: none; color: var(--ink); border: 0; cursor: pointer; }
.tab.on { background: var(--ink); color: var(--paper); }
.note-body { flex: 1; width: 100%; box-sizing: border-box; min-height: 40vh; resize: none; font: inherit; font-size: 17px; line-height: 1.5; padding: 14px; margin: 0; border: 0; background: transparent; color: var(--ink); }
.note-body:focus { outline: none; }
.note-state { color: var(--gray); font-size: 14px; padding: 0 14px 10px; min-height: 1em; }
.list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.group { margin: 14px 8px 4px; font-size: 13px; font-weight: 600; color: var(--gray); }
.item {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px;
  padding: 9px 8px; margin: 1px 0; border-left: 3px solid transparent;
}
.item:hover { background: var(--panel); }
.item.active { background: var(--panel); border-left-color: var(--ink); }
.item .t { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .p { display: block; color: var(--gray); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .m { display: flex; gap: 8px; align-items: center; color: var(--gray); font-size: 12px; margin-top: 2px; }
.glyph { width: 12px; height: 9px; border: 1.5px solid currentColor; border-radius: 2px; position: relative; flex: none; }
.glyph::after { content: ""; position: absolute; left: 1px; right: 1px; bottom: 1px; height: 2px; background: currentColor; }
.empty-list { color: var(--gray); padding: 16px 12px; font-size: 15px; }
.rail-foot { padding: 8px 12px 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; }

/* ---------- сцена ---------- */
.stage { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.stage-empty { margin: auto; max-width: 34ch; text-align: center; color: var(--gray); padding: 24px; }
.stage-empty h2 { color: var(--ink); margin: 0 0 8px; font-size: 20px; }
.chat-head {
  display: flex; align-items: center; gap: 4px; padding: 14px 20px; min-width: 0; border-bottom: 1.5px solid var(--ink);
}
.back { display: none; }
.chat-title {
  flex: 1; min-width: 0; margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em;
  background: none; border: 0; text-align: left; padding: 4px 6px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-title:hover { background: var(--panel); }
input.title-input { flex: 1; font-size: 20px; font-weight: 600; padding: 4px 8px; }
.thread { flex: 1; overflow-y: auto; padding: 24px 20px 12px; }
.thread-inner { max-width: 720px; margin: 0 auto; display: grid; gap: 26px; isolation: isolate; }

.msg { max-width: 68ch; }
.msg .who { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 14px; color: var(--gray); margin-bottom: 6px; }
.msg .who b { color: var(--ink); font-weight: 600; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .body { background: var(--panel); border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 14px; position: relative; }
.msg.user.device .body { border: 1.5px solid var(--ink); border-radius: 4px; }
.msg.user.device .body::after {
  content: ""; position: absolute; inset: 0; transform: translate(6px, 6px); z-index: -1; border-radius: 4px;
  background: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0) 0 0 / 4px 4px;
}
.msg.assistant { padding-left: 14px; border-left: 3px solid var(--accent); }
.msg audio { width: 100%; max-width: 360px; height: 36px; margin-top: 10px; }
.actions { display: flex; gap: 2px; margin-top: 2px; opacity: 0; transition: opacity .12s; }
.msg:hover .actions, .msg:focus-within .actions { opacity: 1; }
@media (hover: none) { .actions { opacity: 1; } }
.actions .quiet { font-size: 14px; }
.edit-box textarea { min-height: 96px; resize: vertical; }
.edit-row { display: flex; gap: 8px; margin-top: 8px; }
.pending { color: var(--gray); font-style: italic; }
.note-error { color: var(--danger); font-size: 14px; }

.composer { border-top: 1.5px solid var(--ink); padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: var(--paper); }
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; }
.hint { max-width: 720px; margin: 6px auto 0; font-size: 13px; color: var(--gray); display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; }
.auto-speak { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.auto-speak input { width: auto; margin: 0; }

/* ---------- телефон: два экрана ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail, .stage { grid-column: 1; grid-row: 1; }
  body:not(.view-chat) .stage { display: none; }
  body.view-chat .rail { display: none; }
  .back { display: inline-block; }
  .chat-head, .thread, .composer { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
a.quiet { text-decoration: none; }

.note-audio { padding: 0 14px; }
.note-audio:empty { display: none; }
.note-audio audio { display: block; width: 100%; margin: 8px 0; }

#tabRecordings { grid-column: 1 / -1; border-top: 1px solid var(--ink); }
.storage-state { color: var(--gray); font-size: 14px; }
