:root {
  --bg: #1b1b1f;
  --side: #222227;
  --card: #2a2a31;
  --line: #34343c;
  --text: #e6e6ea;
  --muted: #8d8d98;
  --accent: #d97757;
  --busy: #d9a441;
  --wait: #e5534b;
  --done: #3fb950;
  --tg: #4a8fd8;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.screen.center { align-items: center; justify-content: center; padding: 24px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.bar { flex: none; display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 12px 6px 16px; border-bottom: 1px solid var(--line); background: var(--side); }
.bar h1 { margin: 0; font-size: 18px; font-weight: 650; flex: 1; }
.icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 10px; }
.icon:active { background: var(--card); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.usage { display: flex; gap: 6px; font-size: 12px; color: var(--muted); }
.usage span { padding: 3px 8px; border-radius: 99px; background: var(--card); }
.usage .high { color: var(--wait); }

.search { padding: 10px 12px 4px; }
.search input { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--side); outline: none; }
.search input:focus { border-color: var(--accent); }

/* проекты */
.project { margin: 8px 10px; border-radius: 12px; background: var(--side); overflow: hidden; }
.project-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 13px 14px; text-align: left; font-weight: 600; }
.project-head .caret { color: var(--muted); transition: transform .15s; font-size: 12px; }
.project.open .caret { transform: rotate(90deg); }
.project-head .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-head .pin, .chat-row .pin { color: var(--accent); font-size: 12px; }
.project-head .new { font-size: 13px; color: var(--accent); font-weight: 500; padding: 4px 8px; border-radius: 8px; }
.project-head .new:active { background: var(--card); }
.chat-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 14px; text-align: left; border-top: 1px solid var(--line); }
.chat-row:active { background: var(--card); }
.chat-row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .when { color: var(--muted); font-size: 12px; flex: none; }
.more-row { width: 100%; padding: 10px 14px; text-align: left; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.dot.busy { background: var(--busy); animation: pulse 1.2s infinite; }
.dot.wait { background: var(--wait); }
.dot.done { background: var(--done); }
.dot.idle { background: var(--muted); opacity: .5; }
@keyframes pulse { 50% { opacity: .35; } }
.badge { flex: none; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(74, 143, 216, .18); color: var(--tg); }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }

/* чат */
.titles { flex: 1; min-width: 0; }
#chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat-sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#messages { padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 8px; }
.load-older { align-self: center; padding: 6px 14px; border-radius: 99px; background: var(--side); color: var(--muted); font-size: 13px; }
.msg { max-width: 92%; padding: 9px 13px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: #3a2a24; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--side); border-bottom-left-radius: 5px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h4 { margin: 10px 0 6px; font-size: 15px; }
.msg.assistant ul { margin: 0 0 8px; padding-left: 20px; }
.msg.assistant a { color: var(--accent); }
.msg code { font: 13px/1.4 "Cascadia Mono", ui-monospace, Menlo, monospace; background: rgba(255, 255, 255, .07); padding: 1px 4px; border-radius: 4px; }
.msg pre { margin: 6px 0 8px; padding: 9px 10px; border-radius: 8px; background: #141417; overflow-x: auto; }
.msg pre code { background: none; padding: 0; white-space: pre; }
.tools { align-self: flex-start; max-width: 92%; font-size: 13px; color: var(--muted); }
.tools summary { list-style: none; padding: 3px 10px; border-radius: 99px; background: rgba(255, 255, 255, .04); cursor: pointer; }
.tools summary::-webkit-details-marker { display: none; }
.tools div { padding: 3px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools b { color: var(--text); font-weight: 500; }
.note { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 10px; }
.photo { align-self: flex-end; max-width: 70%; border-radius: 14px; overflow: hidden; background: var(--side); }
.photo img { display: block; max-width: 100%; max-height: 320px; }

#banner { flex: none; display: flex; align-items: center; gap: 10px; padding: 9px 14px; font-size: 14px; border-top: 1px solid var(--line); background: var(--side); }
#banner .grow { flex: 1; }
#banner button { padding: 6px 12px; border-radius: 8px; background: var(--card); }
#banner.wait { background: rgba(229, 83, 75, .14); }

#composer { flex: none; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--side); }
.compose-row { display: flex; align-items: flex-end; gap: 4px; }
#input { flex: 1; min-height: 42px; max-height: 40vh; resize: none; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); outline: none; }
#input:focus { border-color: var(--accent); }
.send { background: var(--accent); color: #fff; border-radius: 50%; }
.send:disabled { opacity: .5; }
.attach { color: var(--muted); }
#attached { display: flex; gap: 8px; padding: 0 4px 8px; }
#attached .thumb { position: relative; }
#attached img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
#attached button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--card); font-size: 13px; }

/* экран ноутбука */
#sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; background: rgba(0, 0, 0, .5); }
.sheet-box { width: 100%; max-height: 85vh; display: flex; flex-direction: column; border-radius: 16px 16px 0 0; background: var(--side); padding: 6px 12px calc(12px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding-left: 4px; }
#screen { flex: 1; overflow: auto; margin: 4px 0 10px; padding: 10px; border-radius: 10px; background: #141417; font: 11.5px/1.35 "Cascadia Mono", ui-monospace, Menlo, monospace; white-space: pre; min-height: 160px; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.keys button { padding: 12px 0; border-radius: 10px; background: var(--card); font-weight: 500; }
.keys button.primary { background: var(--accent); color: #fff; }
.keys button:active { filter: brightness(1.3); }

.login-box { max-width: 340px; text-align: center; color: var(--muted); }
.login-box h1 { color: var(--text); }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20; padding: 11px 14px; border-radius: 12px; background: #3a3a44; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); font-size: 14px; }
