:root {
  --bg: #10141d; --panel: #172033; --panel2: #1c2740; --line: #2c3951; --text: #eef2ff; --muted: #aebbd0;
  --accent: #5b7bb5; --accent2: #7d9be0; --ok: #3fb27f; --warn: #e0a84a; --bad: #e06c6c; --field: #0f1626;
  --mono: ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); margin: 0; }
[hidden] { display: none !important; }
a { color: var(--accent2); }
h1:focus { outline: none; }

/* shell */
.shell { min-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); flex-wrap: wrap; }
.top .brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.top .who { margin-left: auto; font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.top form { margin: 0; }
.top .help { order: 2; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; text-decoration: none; color: var(--text); border: 1px solid var(--line); background: rgba(255,255,255,.04); }
.top .help:hover { border-color: var(--accent, #6ea8ff); color: var(--accent, #6ea8ff); }
.top .who { order: 1; }
.layout { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
nav.side { border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
nav.side .label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 12px 8px 4px; }
nav.side a { display: flex; justify-content: space-between; gap: 8px; color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 10px; font-size: 14px; }
nav.side a:hover { background: var(--field); }
nav.side a.active { background: var(--accent); }
nav.side a small { color: var(--muted); font-size: 12px; }
nav.side a.active small { color: var(--text); }
nav.side a.off { opacity: .55; }
main.view { min-width: 0; overflow: auto; }
.pad { padding: 20px 16px 48px; max-width: 1180px; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; }
  nav.side .label { width: 100%; margin: 6px 4px 2px; }
}

/* text */
h1 { margin: 0 0 6px; font-size: 22px; }
h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 .right, .right { margin-left: auto; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 16px; line-height: 1.5; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.meta { font-size: 12px; color: var(--muted); }
.mono, code { font-family: var(--mono); font-size: 12.5px; }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; }
.ok { color: var(--ok); font-size: 13px; margin-top: 8px; }
.alert { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; background: var(--panel); }
.alert.bad { border-color: var(--bad); color: #ffd0d0; }
.alert.good { border-color: var(--ok); }
.alert.warn { border-color: var(--warn); }

/* panels */
section.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* forms */
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; cursor: pointer; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.invalid { outline: 2px solid var(--bad) !important; }

button, .btn { background: var(--accent); border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; color: var(--text); font-size: 14px; }
button:hover, .btn:hover { background: var(--accent2); }
button.ghost, .btn.ghost { background: transparent; border: 1px solid var(--line); }
button.ghost:hover, .btn.ghost:hover { border-color: var(--accent); }
button.danger { background: transparent; border: 1px solid var(--line); color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button.small, .btn.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.off td { opacity: .55; }
tr.off td.actions { opacity: 1; }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--panel2); }
tr.sel td { background: var(--panel2); }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * + * { margin-left: 6px; }

.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--field); border: 1px solid var(--line); color: var(--accent2); white-space: nowrap; }
.tag.ok { color: var(--ok); } .tag.off { color: var(--muted); } .tag.warn { color: var(--warn); } .tag.bad { color: var(--bad); }
.mod { font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); }
.mod.core { color: #e0b77d; } .mod.mcp { color: #7dc4e0; } .mod.rag { color: #b59be0; }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 12px 16px 0; border-bottom: 1px solid var(--line); align-items: end; flex-wrap: wrap; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.tabs .title { font-size: 19px; font-weight: 650; margin: 0 16px 10px 0; }
.tabs a { border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0; padding: 8px 12px; color: var(--muted); text-decoration: none; font-size: 14px; }
.tabs a.active { background: var(--panel); border-color: var(--line); color: var(--text); }

/* stats */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 140px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding-top: 6px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.bars div.fail { background: var(--bad); }

/* modal */
.backdrop { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 480px; padding: 20px; }
.modal.wide { max-width: 860px; }
.modal h2 { margin-bottom: 14px; }

.keybox { background: var(--field); border: 1px solid var(--ok); border-radius: 10px; padding: 12px; margin-top: 12px; }
.keybox code { display: block; word-break: break-all; font-size: 14px; margin: 6px 0; }
pre.out { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 10px; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0 0; }
.diff-old { color: var(--bad); text-decoration: line-through; }
.diff-new { color: var(--ok); }

/* sign-in pages */
.signin { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.signin .box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px; width: 100%; max-width: 400px; }
.signin h1 { font-size: 20px; margin-bottom: 4px; }
.signin button { width: 100%; margin-top: 6px; }

#blazor-error-ui { background: #5a1d1d; color: #fff; bottom: 0; display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.assist { margin: 10px 0 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.suggestion { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--accent2); border-radius: 10px; background: rgba(125,155,224,.07); }
.suggestion p { margin: 6px 0; }
code.wrap { white-space: normal; word-break: break-all; }

.test-dot { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; vertical-align: middle; margin-right: 4px; }
.test-dot.ok { background: var(--ok); color: #08130d; }
.test-dot.bad { background: var(--bad); color: #1a0606; }
.test-dot.run { color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; gap: 10px; align-items: flex-start; max-width: 420px; padding: 12px 14px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: toast-in .2s ease-out; }
.toast .icon { flex: none; display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.toast.ok { border-color: var(--ok); } .toast.ok .icon { background: var(--ok); color: #08130d; }
.toast.bad { border-color: var(--bad); } .toast.bad .icon { background: var(--bad); color: #1a0606; }
.toast .meta { word-break: break-word; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spinner { display: inline-block; width: 12px; height: 12px; margin-left: 6px; vertical-align: -1px; border: 2px solid var(--line); border-top-color: var(--accent2); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn { padding: 0 7px; margin-left: 6px; line-height: 18px; font-size: 13px; vertical-align: 1px; }

.qlist { width: 100%; font-size: 13px; padding: 4px; }
.qlist option { padding: 4px 6px; border-radius: 4px; }
select.small-select { padding: 3px 6px; font-size: 13px; min-width: 110px; }
button.active { border-color: var(--accent2); color: var(--text); }

input.small-input { padding: 3px 6px; font-size: 13px; min-width: 110px; max-width: 180px; }

/* Conversations: timeline of one conversation. */
.timeline { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.timeline .msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--field); border: 1px solid var(--line); font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.timeline .msg.user { align-self: flex-end; background: var(--panel2); }
.timeline .msg .meta { display: block; margin-bottom: 2px; }
.timeline .evt { align-self: center; font-size: 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 2px 10px; cursor: default; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel2); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border-radius: 0; background: transparent; color: var(--text); border: 0; padding: 6px 14px; }
.seg button.on { background: var(--accent); }
