/* Claude palette + Telegram layout */
:root {
  --bg: #F5F4EF;
  --surface: #FFFFFF;
  --surface-2: #EFEDE6;
  --text: #1F1E1D;
  --muted: #7A786F;
  --line: #E3E0D6;
  --accent: #D97757;
  --accent-press: #C15F3C;
  --user: #E8E5DA;
  --code-bg: #F0EEE7;
  --danger: #C2412D;
  --ok: #5E8B57;
  --shadow: 0 6px 24px rgba(40, 30, 20, .14);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --surface: #30302E;
    --surface-2: #383835;
    --text: #F2F1EC;
    --muted: #A3A199;
    --line: #3D3D3A;
    --user: #3A3A37;
    --code-bg: #1E1E1C;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { overscroll-behavior: none; }
/* интерфейс не выделяется — иначе Chrome на Android по касанию открывает «Поиск по нажатию» (плашка Google снизу) */
/* только элементы интерфейса, НЕ общий предок поля ввода: user-select:none над textarea на Android
   открывает и сразу прячет клавиатуру */
.bar, .chats, .avatar, .fab, button, .install-hint, #sheet h2, #sheet label, #sheet .dirs, .stats-body, .msg .time, .msg-actions, .msg.system {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#st-table td { -webkit-user-select: text; user-select: text; }
body.guard .msg, body.guard .msg * { -webkit-user-select: none !important; user-select: none !important; }
#app { height: 100dvh; position: relative; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* bars */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) 10px 8px; min-height: calc(56px + var(--safe-t));
  background: var(--bg); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.bar-title { font-size: 22px; font-weight: 650; margin: 0 0 0 8px; flex: 1; letter-spacing: -.01em; }
.bar-info { flex: 1; min-width: 0; }
.bar-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub.typing { color: var(--accent); }
.icon-btn {
  background: none; border: 0; color: var(--text); width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--ok); }

/* login */
.login-box { margin: auto; width: min(340px, 88vw); text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: var(--shadow); }
.login-box h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; margin: 16px 0 4px; }
.login-box form { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; outline: none; width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.danger { color: var(--danger); }

/* chat list */
.chats { list-style: none; margin: 0; padding: 4px 0 calc(90px + var(--safe-b)); overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 9px 14px; align-items: center; cursor: pointer; }
.chat-item:active { background: var(--surface-2); }
.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 20px; position: relative;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.emoji { font-size: 28px; font-weight: 400; }
.avatar.sm.emoji { font-size: 21px; }
.icon-edit { display: flex; align-items: center; gap: 16px; margin: 4px 0 12px; }
.icon-edit .avatar { width: 72px; height: 72px; font-size: 26px; }
.icon-edit .avatar.emoji { font-size: 38px; }
.icon-btns { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-bottom: 8px; }
.icon-grid button {
  background: none; border: 0; font-size: 24px; padding: 6px 0; border-radius: 10px; cursor: pointer; line-height: 1;
}
.icon-grid button:active { background: var(--surface-2); }
.avatar .spin {
  position: absolute; inset: -3px; border-radius: 50%; border: 2.5px solid transparent;
  border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chat-main { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.chat-item:last-child .chat-main { border-bottom: 0; }
.chat-top { display: flex; align-items: baseline; gap: 8px; }
.chat-name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.chat-time { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.chat-bottom { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.chat-preview {
  flex: 1; color: var(--muted); font-size: 15px; line-height: 1.3; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chat-preview .who { color: var(--text); }
.chat-preview.typing { color: var(--accent); }
.badge {
  background: var(--accent); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 7px;
  font-size: 13px; font-weight: 600; display: grid; place-items: center; flex-shrink: 0;
}
.pin { color: var(--muted); font-size: 13px; }
.fab {
  position: absolute; right: 18px; bottom: calc(22px + var(--safe-b)); width: 58px; height: 58px; border-radius: 18px;
  border: 0; background: var(--accent); color: #fff; box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer;
}
.fab:active { background: var(--accent-press); }
.install-hint {
  margin: 10px 12px 0; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  font-size: 14px; line-height: 1.4;
}
.install-hint b { color: var(--accent); }

/* messages */
.messages {
  flex: 1; overflow-y: auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 100%; line-height: 1.55; font-size: 16.5px; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end; max-width: 85%; background: var(--user); padding: 9px 14px; border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap; font-family: var(--sans); font-size: 16px; line-height: 1.4;
}
.msg.assistant { font-family: var(--serif); align-self: stretch; }
.msg.assistant.live::after {
  content: ""; display: inline-block; width: 9px; height: 9px; margin-left: 4px; border-radius: 50%;
  background: var(--accent); animation: pulse 1s ease-in-out infinite; vertical-align: middle;
}
@keyframes pulse { 50% { opacity: .25; } }
.msg .time { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-family: var(--sans); }
.msg.user .time { text-align: right; }
.msg-actions { display: flex; gap: 4px; margin-top: 2px; }
.msg-actions button {
  background: none; border: 0; color: var(--muted); padding: 4px 6px; border-radius: 8px; font-size: 13px; cursor: pointer;
  display: inline-flex; gap: 4px; align-items: center; font-family: var(--sans);
}
.msg-actions svg { width: 15px; height: 15px; }
.msg.system, .msg.divider { align-self: center; font-size: 13px; color: var(--muted); font-family: var(--sans); text-align: center; }
.msg.divider { width: 100%; display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.msg.divider::before, .msg.divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.msg.error {
  font-family: var(--mono); font-size: 13px; background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap;
}
.tools {
  align-self: flex-start; font-family: var(--sans); font-size: 14px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; max-width: 100%;
}
.tools summary { padding: 7px 12px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary svg { width: 16px; height: 16px; }
.tools ol { margin: 0; padding: 0 12px 10px 30px; font-size: 13px; }
.tools li { margin: 3px 0; overflow-wrap: anywhere; }
.tools li b { color: var(--text); font-weight: 600; }
.working { align-self: flex-start; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.working .claude-spark { width: 22px; height: 22px; color: var(--accent); animation: spin 2.4s linear infinite; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; margin: 1em 0 .45em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md a { color: var(--accent); }
.md blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: .12em .35em; border-radius: 5px; }
.md pre { position: relative; background: var(--code-bg); border-radius: 12px; padding: 12px 14px; overflow-x: auto; margin: 0 0 .8em; border: 1px solid var(--line); }
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; white-space: pre; }
.md pre .copy {
  position: absolute; top: 6px; right: 6px; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; font-size: 12px; padding: 3px 8px; font-family: var(--sans); cursor: pointer;
}
.md .table-wrap { overflow-x: auto; margin: 0 0 .8em; }
.md table { border-collapse: collapse; font-family: var(--sans); font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.attach { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.attach img { max-width: 220px; max-height: 260px; border-radius: 12px; display: block; }

.to-bottom {
  position: absolute; right: 14px; bottom: calc(80px + var(--safe-b)); width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); box-shadow: var(--shadow); display: grid; place-items: center;
}

/* composer */
.composer {
  flex-shrink: 0; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line);
}
.compose-row { display: flex; align-items: flex-end; gap: 6px; }
.compose-row textarea {
  resize: none; max-height: 40vh; min-height: 44px; line-height: 1.4; border-radius: 22px; padding: 11px 16px;
  font-size: 16px; /* >=16px: iOS doesn't zoom */
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex-shrink: 0; cursor: pointer;
}
.send-btn:active { background: var(--accent-press); }
.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn svg { width: 22px; height: 22px; stroke-width: 2.4; }
.send-btn.stop svg { fill: currentColor; stroke: none; }
.recording { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-label { flex: 1; }
.file-chip {
  margin-top: 6px; display: flex; align-items: center; gap: 8px; font-size: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px;
}
.file-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }

/* bottom sheet */
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); max-height: 88dvh; overflow-y: auto;
  box-shadow: var(--shadow); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { font-size: 18px; margin: 4px 0 12px; }
.sheet .item {
  display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 16px; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; color: var(--text); text-align: left;
}
.sheet .item:last-child { border-bottom: 0; }
.sheet .item.danger { color: var(--danger); }
.sheet .item small { color: var(--muted); margin-left: auto; font-size: 14px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.sheet .row { display: flex; gap: 10px; margin-top: 16px; }
.sheet .row .btn { flex: 1; }
.dirs { max-height: 34dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; }
.dirs div { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 15px; }
.dirs div:last-child { border-bottom: 0; }
.dirs div:active { background: var(--surface-2); }
.dir-path { font-family: var(--mono); font-size: 13px; word-break: break-all; }

.toast {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-b)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86vw; text-align: center;
}

/* analytics */
:root {
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s-other: #a8a69e;
  --grid: #ECEAE3; --axis: #C9C6BB;
  --m-ok: #2a78d6; --m-ok-track: #cde2fb; --m-warn: #fab219; --m-warn-track: #fde7b0; --m-bad: #d03b3b; --m-bad-track: #f5cccc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s-other: #7d7b74;
    --grid: #3A3A37; --axis: #4A4A46;
    --m-ok: #3987e5; --m-ok-track: #1d3554; --m-warn: #fab219; --m-warn-track: #4a3c1a; --m-bad: #e66767; --m-bad-track: #4d2626;
  }
}
.stats-body { flex: 1; overflow-y: auto; padding: 12px 12px calc(24px + var(--safe-b)); transition: opacity .2s; }
.stats-body.loading { opacity: .6; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.card { background: var(--surface); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.meter { margin-bottom: 12px; }
.meter:last-child { margin-bottom: 0; }
.meter-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.meter-val { font-weight: 600; }
.meter-track { height: 8px; border-radius: 4px; overflow: hidden; background: var(--m-ok-track); }
.meter-fill { height: 100%; border-radius: 4px; background: var(--m-ok); }
.meter.warn .meter-track { background: var(--m-warn-track); } .meter.warn .meter-fill { background: var(--m-warn); }
.meter.bad .meter-track { background: var(--m-bad-track); } .meter.bad .meter-fill { background: var(--m-bad); }
.meter-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-val { font-size: 22px; font-weight: 650; margin-top: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg-box { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; margin-right: 6px; vertical-align: -1px; }
.lg .lg-box { margin-right: 0; }
.lg-line { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.chart svg { display: block; width: 100%; height: auto; fill: initial; stroke: none; stroke-width: 0; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-family: var(--sans); }
.chart .col { transition: opacity .15s; }
.chart .col.dim { opacity: .45; }
.chart rect:focus { outline: none; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .ring { stroke: var(--surface); stroke-width: 2; }
.chart .hidden { display: none; }
.st-note { color: var(--muted); font-size: 14px; margin: 4px 0; }
.table-wrap { overflow-x: auto; }
#st-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#st-table th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
#st-table td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
#st-table th:first-child, #st-table td:first-child { text-align: left; white-space: normal; }
#st-table tr:last-child td { border-bottom: 0; }
.st-tip {
  position: absolute; z-index: 30; pointer-events: none; background: var(--surface); color: var(--text);
  border-radius: 10px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 13px; min-width: 120px;
}
.tip-title { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tip-row b { font-weight: 650; }
.tip-row span:last-child { color: var(--muted); }
.tip-key { display: inline-block; width: 10px; height: 2px; border-radius: 1px; }
