:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b212b;
  --line: #262d39;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #5aa9ff;
  --accent-ink: #06121f;
  --ok: #4cc38a;
  --warn: #e5b45c;
  --bad: #ef6b6b;
  --me: #1f3a5c;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
h2:first-child { margin-top: 4px; }
button { font: inherit; color: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); padding: 8px 14px; }
button:hover { border-color: #3a4556; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.yes { background: var(--ok); color: #05190f; border-color: var(--ok); font-weight: 600; }
button.no { background: transparent; color: var(--bad); border-color: #55303a; }
input, textarea { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: none; max-height: 160px; overflow-y: hidden; }

.logo { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, #2b6cb0, #5aa9ff); color: #fff; font-weight: 700; font-size: 28px; }
.logo.small { width: 30px; height: 30px; border-radius: 9px; font-size: 16px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 12px; justify-items: center; text-align: center; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.chips { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; justify-content: flex-end; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.chip.warn { color: var(--warn); border-color: #5a4a26; }
.chip.bad { color: var(--bad); border-color: #55303a; }
.chip.busy { color: var(--accent); border-color: #2c4a6b; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 12px; padding: 12px 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.chat { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); border-color: #2a4d78; }
.msg.digest { border-left: 3px solid var(--accent); }
.msg.notice, .msg.error { border-left: 3px solid var(--warn); }
.msg.error { border-left-color: var(--bad); }
.msg.card { border-left: 3px solid var(--ok); }
.msg .meta { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.hint { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.hint p { margin: 0; color: var(--muted); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }

.side { min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.side .tab { flex: 1; overflow-y: auto; min-height: 0; }
.tabs, .tabs-mobile { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button, .tabs-mobile button { padding: 6px 12px; font-size: 14px; }
.tabs button.active, .tabs-mobile button.active { background: var(--panel-2); border-color: var(--accent); color: var(--accent); }
.tabs-mobile { display: none; padding: 8px 16px 0; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; margin-left: 4px; }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.card .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.card .why { color: var(--muted); font-size: 12px; margin-top: 6px; }
.card details { margin-top: 8px; }
.card pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin: 6px 0 0; font-size: 13px; }
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.item { border-bottom: 1px solid var(--line); padding: 8px 0; overflow-wrap: anywhere; }
.item:last-child { border-bottom: 0; }
.item .k { color: var(--accent); font-size: 12px; }
.item .t { color: var(--muted); font-size: 12px; margin-left: 6px; }
.item .p { color: var(--muted); font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.empty { color: var(--muted); padding: 6px 0; }

@media (max-width: 860px) {
  .tabs-mobile { display: flex; }
  .layout { grid-template-columns: 1fr; padding: 8px 12px 12px; }
  .side .tabs { display: none; }
  body[data-view="chat"] .side { display: none; }
  body[data-view="cards"] .chat, body[data-view="more"] .chat { display: none; }
  body[data-view="cards"] #tab-cards { display: block !important; }
  body[data-view="cards"] .tab:not(#tab-cards) { display: none !important; }
  body[data-view="more"] #tab-cards { display: none !important; }
  body[data-view="more"] .tab:not(#tab-cards) { display: block !important; margin-bottom: 10px; }
  .side { overflow-y: auto; }
  .msg { max-width: 92%; }
  .chips { display: none; }
}
.msg.understanding { border-left: 3px solid var(--accent); }
