:root {
  --bg: #f6f7f7; --surface: #ffffff; --text: #1b2524; --muted: #5d6b69; --border: #dbe2e1;
  --accent: #0f766e; --accent-text: #ffffff; --user: #d9f0ed; --warn-bg: #fff4d6; --warn-text: #6b4a00;
  --error-bg: #fde8e8; --error-text: #8a1c1c; --bar: #0f766e; --bar-neg: #b42318; --track: #e6ecea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1514; --surface: #17201f; --text: #e6efed; --muted: #9db0ad; --border: #2a3735;
    --accent: #2dd4bf; --accent-text: #06201d; --user: #16413c; --warn-bg: #3b3210; --warn-text: #f5d97a;
    --error-bg: #3d1717; --error-text: #f5b1b1; --bar: #2dd4bf; --bar-neg: #f97066; --track: #22302e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; display: grid; gap: 12px; }
.login-card h1 { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login-card input { font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }

/* app shell: header, scrolling messages, sticky composer */
.app { height: 100%; height: 100dvh; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .muted { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.empty { margin: auto; text-align: center; max-width: 30ch; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { flex: 1; resize: none; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); max-height: 160px; }

button { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 14px; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* messages */
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 100%; border-radius: 14px; padding: 10px 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); max-width: 85%; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); width: 100%; }
.text p { margin: 0 0 8px; } .text p:last-child { margin-bottom: 0; }
.text ul, .text ol { margin: 0 0 8px; padding-left: 22px; }
.text code { background: var(--track); padding: 1px 5px; border-radius: 5px; font-size: 90%; }
.md-h { font-weight: 700; }
.status { color: var(--muted); font-size: 14px; } .status:empty { display: none; }
.foot { display: grid; gap: 8px; } .foot:empty { display: none; }
.warn, .error { border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-top: 8px; }
.warn { background: var(--warn-bg); color: var(--warn-text); }
.error { background: var(--error-bg); color: var(--error-text); }
.feedback { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.feedback .note { flex: 1; min-width: 12ch; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }

/* data blocks */
.blocks { display: grid; gap: 10px; } .blocks:not(:empty) { margin-top: 10px; }
.block { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--bg); }
.block-title { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.stat-main { border-color: var(--accent); }
.stat-value { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; gap: 2px 8px; margin-bottom: 8px; }
.bar-label { grid-area: label; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-value { grid-area: value; font-size: 14px; font-variant-numeric: tabular-nums; }
.bar-track { grid-area: track; height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 4px; } .bar-fill.neg { background: var(--bar-neg); }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 8px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td:first-child, th:first-child { white-space: normal; min-width: 12ch; }
th { color: var(--muted); font-weight: 600; } .num { text-align: right; font-variant-numeric: tabular-nums; }
.block-note { color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: no-preference) { .bar-fill { transition: width .3s ease; } }

/* developer console */
body.konsol { overflow-y: auto; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--border); background: var(--surface); overflow-x: auto; }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 8px 12px; }
.tab.active { border-bottom-color: var(--accent); font-weight: 600; }
.kmain { max-width: 1000px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
.linkbtn { text-decoration: none; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; color: inherit; font-size: 14px; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: var(--track); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0; } .facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
pre { background: var(--track); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font-size: 13px; margin: 4px 0 8px; }
.toolname { font-weight: 600; font-size: 14px; }
.cards { display: grid; gap: 10px; margin-top: 10px; }
select { font-size: 16px; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
