:root {
  color-scheme: light dark;
  --bg: #f6f7f6; --panel: #ffffff; --panel2: #eef1ef; --text: #17201f; --muted: #66726f; --line: #dbe1de;
  --accent: #1f6f6b; --accent-ink: #ffffff; --accent-soft: #d9eeec;
  --ok: #1d7a46; --warn: #a8690a; --bad: #b3261e; --bad-soft: #fbe3e1; --warn-soft: #fbefd5; --ok-soft: #dcf1e4;
  --radius: 10px; --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514; --panel: #171e1d; --panel2: #1e2726; --text: #e6ecea; --muted: #8d9b97; --line: #2a3634;
    --accent: #43b3ac; --accent-ink: #07211f; --accent-soft: #17302e;
    --ok: #5cc48a; --warn: #e0a64a; --bad: #f0786f; --bad-soft: #3a1f1d; --warn-soft: #3a2d14; --ok-soft: #16301f;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; font-weight: 650; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); font-size: .88em; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; } .grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: .9rem; }

/* controls */
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .45rem .8rem; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); } button.danger:hover:not(:disabled) { border-color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.tiny { padding: .15rem .5rem; font-size: .82rem; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; padding: 0; accent-color: var(--accent); }
label.field { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-size: 1rem; }
label.check { display: inline-flex; gap: .4rem; align-items: center; }

/* shell */
.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; letter-spacing: -.02em; display: flex; gap: .5rem; align-items: center; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.nav { display: flex; gap: .2rem; } .nav a { padding: .35rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill { padding: .15rem .6rem; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); font-size: .85rem; }
.page { max-width: 1200px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; } .grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); } .grid.c4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat b { display: block; font-size: 1.6rem; letter-spacing: -.02em; } .stat span { color: var(--muted); font-size: .85rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .4rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .78rem; border: 1px solid var(--line); background: var(--panel2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; min-width: 70px; } .bar > div { height: 100%; background: var(--ok); }
.bar.warn > div { background: var(--warn); } .bar.hot > div { background: var(--bad); }
.limits { display: grid; grid-template-columns: auto 1fr auto; gap: .15rem .6rem; align-items: center; font-size: .78rem; }
.callout { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius); padding: .8rem 1rem; }
.callout.bad { border-color: var(--bad); background: var(--bad-soft); }
.keybox { font-family: var(--mono); word-break: break-all; background: var(--panel); border: 1px dashed var(--accent); padding: .5rem .7rem; border-radius: 8px; user-select: all; }
pre.snippet { background: var(--panel2); padding: .8rem; border-radius: 8px; overflow-x: auto; margin: 0; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 1rem; }
.err { color: var(--bad); min-height: 1.3em; font-size: .9rem; }

/* toast */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; max-width: min(420px, 92vw); }
.toast { background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: 8px; box-shadow: 0 6px 24px #0004; }
.toast.bad { background: var(--bad); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: #0006; display: grid; place-items: center; z-index: 40; padding: 1rem; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; width: min(520px, 100%); max-height: 90vh; overflow: auto; }

/* chat */
.chat { display: grid; grid-template-columns: 260px 1fr; height: calc(100vh - 53px); }
.chat .side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chat .convs { overflow-y: auto; flex: 1; padding: .4rem; }
.conv { display: flex; align-items: center; gap: .3rem; padding: .45rem .6rem; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); }
.conv:hover, .conv.on { background: var(--panel2); } .conv.on { font-weight: 600; }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv button { opacity: 0; border: 0; background: none; padding: 0 .3rem; } .conv:hover button { opacity: .7; }
.chat .main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat .head { padding: .6rem 1rem; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.chat .head select { max-width: 340px; }
.msgs { flex: 1; overflow-y: auto; padding: 1.2rem 1rem; scroll-behavior: smooth; }
.msgs .inner { max-width: 820px; margin: 0 auto; display: grid; gap: 1rem; }
.msg { display: grid; gap: .2rem; } .msg .who { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.msg.user .body { background: var(--accent-soft); border-radius: 12px; padding: .6rem .9rem; justify-self: start; max-width: 100%; }
.body { overflow-wrap: anywhere; } .body p { margin: .4em 0; } .body pre { background: var(--panel2); border-radius: 8px; padding: .7rem; overflow-x: auto; position: relative; }
.body code.inline { background: var(--panel2); padding: .05rem .3rem; border-radius: 4px; }
.body pre button { position: absolute; top: .3rem; right: .3rem; }
.body h1, .body h2, .body h3 { margin: .8em 0 .3em; } .body ul, .body ol { margin: .3em 0; padding-left: 1.4rem; }
.composer { border-top: 1px solid var(--line); padding: .8rem 1rem; background: var(--panel); }
.composer .inner { max-width: 820px; margin: 0 auto; display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 220px; min-height: 44px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); } @keyframes blink { 50% { opacity: 0; } }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; }
@media (max-width: 760px) { .chat { grid-template-columns: 1fr; } .chat .side { display: none; } .top { flex-wrap: wrap; } }
.msg.user .body { white-space: pre-wrap; }
