:root {
  --bg: #0b0e14; --panel: #11151f; --panel2: #161b26; --border: #232a3b; --text: #d8dee9; --muted: #7f8aa8;
  --accent: #7aa2f7; --green: #9ece6a; --yellow: #e0af68; --red: #f7768e; --purple: #bb9af7; --cyan: #7dcfff;
  --term-bg: #0b0e14; --term-fg: #c0caf5; --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6fb; --panel: #ffffff; --panel2: #eef1f8; --border: #d9deea; --text: #1d2433; --muted: #5d6680;
    --accent: #3b63d6; --green: #2f8a3a; --yellow: #a86a00; --red: #c4314b; --purple: #7b4fd1; --cyan: #127c98;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
button, .btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0b0e14; font-weight: 600; }
button.danger:hover { border-color: var(--red); color: var(--red); }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label > input, label > textarea, label > select { margin-top: 4px; color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h2, .card h3 { margin: 0 0 8px; font-size: 14px; }
.card h3 { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.authcard { width: 100%; max-width: 380px; }
.authcard h1 { font-size: 18px; margin: 0 0 12px; }
.authcard button { margin-top: 16px; width: 100%; justify-content: center; }
.qr { background: #fff; border-radius: 8px; padding: 8px; display: grid; place-items: center; margin: 12px 0; }
.qr svg { width: 220px; height: 220px; }
.secret { word-break: break-all; }
.logo { color: var(--accent); }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 15px; color: var(--text); }
.brand:hover { text-decoration: none; }
.totals { display: flex; gap: 14px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.totals b { color: var(--text); font-weight: 600; }
main.page { padding: 16px; max-width: 1800px; margin: 0 auto; }

/* dashboard */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); gap: 14px; }
.ws-card { display: flex; flex-direction: column; gap: 10px; }
.ws-card .name { font-size: 16px; font-weight: 700; color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.dot.bad { background: var(--red); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 6px 8px; min-width: 0; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-direction: column; gap: 6px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--panel2); color: var(--text); min-width: 0; }
.chip:hover { text-decoration: none; outline: 1px solid var(--border); }
.chip .detail { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.preview { margin: 0; max-height: 220px; overflow: hidden; font-size: 11px; line-height: 1.3; padding: 8px 10px; border-radius: 8px;
  background: var(--term-bg); color: var(--term-fg); white-space: pre; border: 1px solid var(--border); }
.empty { text-align: center; padding: 48px 16px; }

/* state badges */
.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--panel2); color: var(--muted);
  border: 1px solid var(--border); white-space: nowrap; flex: none; }
.st-working { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.st-waiting { color: #0b0e14; background: var(--yellow); border-color: var(--yellow); }
.st-idle { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.st-ended, .st-shell { color: var(--muted); }
@keyframes pulse { 50% { background: color-mix(in srgb, var(--accent) 18%, transparent); } }

/* limit bars */
.limits { display: grid; gap: 6px; }
.limit { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.bar { height: 7px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.bar > i.warn { background: var(--yellow); }
.bar > i.crit { background: var(--red); }

/* workspace page */
.ws-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ws-head h1 { margin: 0; font-size: 20px; }
.ws-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
@media (max-width: 1300px) { .ws-layout { grid-template-columns: 260px minmax(0, 1fr); } .ws-side { grid-column: 1 / -1; } }
@media (max-width: 820px) { .ws-layout { grid-template-columns: minmax(0, 1fr); } }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ws-side { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 14px; align-content: start; }
@media (min-width: 1301px) { .ws-side { grid-template-columns: minmax(0, 1fr); } }
.panes { display: flex; flex-direction: column; gap: 6px; }
.pane-item { text-align: left; display: flex; flex-direction: column; align-items: stretch; gap: 3px; width: 100%; padding: 8px 10px;
  border-radius: 9px; background: var(--panel2); border: 1px solid transparent; white-space: normal; }
.pane-item.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel2)); }
.pane-item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-item .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer { display: flex; flex-direction: column; gap: 10px; }
.viewer-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.viewer-head .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.term { margin: 0; background: var(--term-bg); color: var(--term-fg); font: 12.5px/1.25 var(--mono); padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border); white-space: pre; overflow: auto; height: min(62vh, 760px); tab-size: 8; }
.term-frame { width: 100%; height: min(72vh, 860px); border: 1px solid var(--border); border-radius: 10px; background: #000; }
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer textarea { min-height: 64px; resize: vertical; font-family: var(--mono); font-size: 13px; }
.keys { display: flex; gap: 6px; flex-wrap: wrap; }
.keys button { font-family: var(--mono); font-size: 12px; padding: 4px 9px; }
.tabs { display: inline-flex; background: var(--panel2); border-radius: 8px; padding: 2px; border: 1px solid var(--border); }
.tabs button { border: 0; background: transparent; padding: 4px 10px; }
.tabs button.on { background: var(--panel); color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { min-width: 0; overflow-wrap: anywhere; }
.textblock { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; background: var(--panel2); padding: 8px 10px;
  border-radius: 8px; max-height: 260px; overflow: auto; margin: 4px 0 0; }
.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.tasks li { display: flex; gap: 8px; align-items: baseline; }
.tasks li.completed { color: var(--muted); text-decoration: line-through; }
.tasks li.in_progress { color: var(--accent); font-weight: 600; }
.feed { display: flex; flex-direction: column; gap: 2px; max-height: 460px; overflow: auto; font-size: 12.5px; }
.ev { display: grid; grid-template-columns: 54px 92px 1fr; gap: 8px; padding: 4px 2px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.ev .time { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev .kind { color: var(--purple); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .sum { overflow-wrap: anywhere; min-width: 0; }
.ev.err .sum { color: var(--red); }
.ev.wait .kind, .ev.wait .sum { color: var(--yellow); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
.chart { width: 100%; height: 64px; display: block; }
.charts { display: grid; gap: 10px; }
.chartbox .row { font-size: 12px; }
.toast-area { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--yellow); border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
.toast.info { border-color: var(--accent); }
.toast.err { border-color: var(--red); }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 6px; font-size: 17px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.log { max-height: 280px; overflow: auto; font-size: 12px; background: var(--term-bg); color: var(--term-fg); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
@media (max-width: 600px) {
  main.page { padding: 12px; }
  .term { height: 52vh; font-size: 11px; }
  .ev { grid-template-columns: 48px 1fr; }
  .ev .kind { display: none; }
}
