:root {
  --c: #0f9e80; --c-strong: #0b7f67; --c-soft: #e3f5ef; --ink: #0e1726; --muted: #5d6a7c; --line: #e3e8ef; --bg: #f4f6fa; --card: #ffffff;
  --side: #0b1424; --side-2: #111d33; --side-ink: #aebbd0; --side-line: rgba(255,255,255,.08);
  --ok: #15803d; --ok-soft: #e3f5e9; --bad: #b42318; --bad-soft: #fdecec; --warn: #8a5a00; --warn-soft: #fff4d6;
  --radius: 12px; --shadow: 0 1px 2px rgba(14,23,38,.05), 0 1px 1px rgba(14,23,38,.03);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c: #34d3ae; --c-strong: #2bbd9b; --c-soft: #133a32; --ink: #e8edf3; --muted: #97a4b6; --line: #252e3b; --bg: #0d121a; --card: #141b26;
    --side: #080d16; --side-2: #0f1724;
    --ok: #4ac26b; --ok-soft: #173422; --bad: #ff7b72; --bad-soft: #3a1d1d; --warn: #e3b341; --warn-soft: #3a2f12;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14.5px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--c-soft); }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; font-weight: 550; box-shadow: var(--shadow); transition: border-color .15s, background .15s, transform .15s, box-shadow .15s; }
.btn:hover { border-color: #c5cfdc; background: #fbfcfe; }
.btn.primary { background: var(--c); border-color: var(--c); color: #fff; font-weight: 600; box-shadow: 0 6px 16px -8px var(--c); }
.btn.primary:hover { background: var(--c-strong); border-color: var(--c-strong); transform: translateY(-1px); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
input[type=text], input[type=password], input[type=number], input[type=color], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #c9d2de; }
input:focus, select:focus, textarea:focus { border-color: var(--c); box-shadow: 0 0 0 3px var(--c-soft); }
textarea { resize: vertical; min-height: 72px; }
input[type=color] { padding: 3px; height: 40px; }
label.f { display: block; margin-bottom: 16px; }
label.f > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
label.f small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .row2 { grid-template-columns: 1fr; } }

/* ---------- login ---------- */
#login { min-height: 100%; display: grid; grid-template-columns: 1fr 1fr; }
#login .side-art { background: radial-gradient(700px 400px at 90% 0%, rgba(92,184,255,.22), transparent 60%), radial-gradient(600px 400px at 0% 100%, rgba(52,211,174,.22), transparent 60%), var(--side); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
#login .side-art .lg { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
#login .side-art .lg i { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #34d3ae, #1c8cd9); display: grid; place-items: center; }
#login .side-art .lg i svg { width: 19px; height: 19px; }
#login .side-art h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.03em; margin: 0 0 14px; max-width: 440px; }
#login .side-art p { color: #a9b6c9; max-width: 420px; margin: 0; font-size: 15.5px; }
#login .side-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; color: #c9d4e3; font-size: 14.5px; }
#login .side-art li::before { content: "✓"; color: #34d3ae; font-weight: 700; margin-right: 10px; }
#login .side-art small { color: #6f819c; font-size: 12.5px; }
#login .form-side { display: grid; place-items: center; padding: 24px; }
#login form { width: 100%; max-width: 380px; }
#login h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 6px; }
#login p { color: var(--muted); margin: 0 0 24px; font-size: 14.5px; }
#login .btn.primary { justify-content: center; padding: 11px 16px; font-size: 15px; }
#login .back { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 13.5px; text-decoration: none; }
#login .back:hover { color: var(--c); }
.err-text { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }
@media (max-width: 860px) { #login { grid-template-columns: 1fr; } #login .side-art { display: none; } }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 60px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 15.5px; margin-right: 8px; display: flex; align-items: center; gap: 10px; letter-spacing: -.01em; }
.brand::before { content: ""; width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2306231b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E") center / 16px no-repeat, linear-gradient(135deg, #34d3ae, #1c8cd9); }
.brand b { color: var(--c); }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; font-weight: 500; }
.pill.live { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.sim { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.dirty { background: var(--warn-soft); color: var(--warn); border-color: transparent; font-weight: 600; }
.spacer { flex: 1; }

.layout { display: grid; grid-template-columns: 224px minmax(0, 1fr) 390px; height: calc(100vh - 60px); }
.side { background: var(--side); padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.side::before { content: "WORKSPACE"; font-size: 11px; font-weight: 700; letter-spacing: .12em; color: #5e6f89; padding: 4px 12px 10px; }
.side button { display: flex; width: 100%; justify-content: space-between; align-items: center; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 9px; cursor: pointer; color: var(--side-ink); font-weight: 500; transition: background .15s, color .15s; position: relative; }
.side button:hover { background: var(--side-2); color: #fff; }
.side button.on { background: rgba(52,211,174,.12); color: #fff; font-weight: 600; }
.side button.on::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #34d3ae; }
.side .count { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,.08); color: #c9d4e3; }
.side button.on .count { background: rgba(52,211,174,.22); color: #b9f3e4; }
.side .narrow-only { display: none; }
#view { overflow-y: auto; padding: 28px 32px 64px; }
.preview { border-left: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; min-height: 0; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { flex-direction: row; gap: 4px; overflow-x: auto; padding: 8px; }
  .side::before { display: none; }
  .side button { width: auto; white-space: nowrap; }
  .side button.on::before { display: none; }
  .side .count { display: none; }
  .side .narrow-only { display: flex; }
  #view { padding: 20px 16px 60px; }
  .preview { display: none; border-left: 0; height: calc(100vh - 116px); }
  body.show-preview .preview { display: flex; }
  body.show-preview #view { display: none; }
}

/* ---------- views ---------- */
h1.v { font-size: 24px; margin: 0 0 6px; letter-spacing: -.025em; }
p.sub { color: var(--muted); margin: 0 0 22px; max-width: 720px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.toolbar input { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c); opacity: .7; }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 500; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 14px; align-items: flex-start; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.item:hover { border-color: #cbd4e0; box-shadow: 0 6px 18px -12px rgba(14,23,38,.25); }
.item.off { opacity: .55; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 650; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item .d { color: var(--muted); font-size: 13.5px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .acts { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.id { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--bg); padding: 1px 6px; border-radius: 5px; }
.tag { font-size: 11.5px; padding: 2px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); font-weight: 550; }
.tag.core { background: #fde8e8; color: #9b1c1c; border-color: transparent; }
.tag.high { background: #fff1db; color: #8a4b00; border-color: transparent; }
.tag.normal { background: var(--c-soft); color: var(--c-strong); border-color: transparent; }
.tag.low { background: var(--bg); }
.tag.new { background: #e0ecff; color: #1d4ed8; border-color: transparent; }
.tag.edited { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag.core { background: #3a1d1d; color: #ff9b94; }
  :root:not([data-theme="light"]) .tag.high { background: #3a2a12; color: #f0b25a; }
  :root:not([data-theme="light"]) .tag.new { background: #1b2a45; color: #8fb3ff; }
  :root:not([data-theme="light"]) .tag.normal { color: var(--c); }
}
.cat-h { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 22px 0 8px; }
.cat-h:first-child { margin-top: 0; }
@media (max-width: 640px) { .item { flex-direction: column; } .item .acts { align-self: flex-end; } }

.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; margin-top: 1px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #d5dce6; border-radius: 22px; cursor: pointer; transition: .18s; }
.switch i::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--c); }
.switch input:checked + i::after { transform: translateX(16px); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel h2 { font-size: 15.5px; margin: 0 0 14px; letter-spacing: -.01em; }
.empty { color: var(--muted); padding: 36px; text-align: center; background: var(--card); border: 1px dashed #cdd5e0; border-radius: var(--radius); }

.result { border-left: 4px solid var(--line); }
.result.pass { border-left-color: var(--ok); }
.result.fail { border-left-color: var(--bad); }
.verdict { font-weight: 700; font-size: 11.5px; letter-spacing: .04em; padding: 3px 9px; border-radius: 6px; }
.verdict.pass { background: var(--ok-soft); color: var(--ok); }
.verdict.fail { background: var(--bad-soft); color: var(--bad); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 14px; font-size: 13.5px; margin-top: 10px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; white-space: pre-wrap; }
.bar { height: 10px; background: var(--bad-soft); border-radius: 10px; overflow: hidden; margin: 10px 0 18px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #22c55e); border-radius: 10px; transition: width .4s; }

table.t { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 13.5px; box-shadow: var(--shadow); }
table.t th, table.t td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: var(--bg); font-weight: 650; }
table.t tbody tr:hover td { background: #fafbfd; }
table.t tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }
table.edit td { padding: 5px; }
table.edit input { padding: 7px 9px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) table.t tbody tr:hover td { background: #172030; } }

details.conv { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px; box-shadow: var(--shadow); }
details.conv[open] { border-color: #cbd4e0; }
details.conv summary { cursor: pointer; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
details.conv summary .first { flex: 1; min-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.transcript { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.transcript div { padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; font-size: 13.5px; }
.transcript .u { background: var(--c); color: #fff; align-self: flex-end; max-width: 85%; border-bottom-right-radius: 4px; }
.transcript .a { background: var(--bg); align-self: flex-start; max-width: 85%; border-bottom-left-radius: 4px; }
.transcript .tc { font-family: var(--mono); font-size: 11.5px; color: var(--c-strong); background: transparent; padding: 0 12px; }

pre.code { background: #0b1424; color: #d7e1ee; border: 1px solid #0b1424; border-radius: 10px; padding: 14px 16px; overflow: auto; font: 12.5px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 60vh; }
.snip { position: relative; }
.snip .btn { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.08); color: #d7e1ee; border-color: rgba(255,255,255,.14); box-shadow: none; }
.snip .btn:hover { background: rgba(255,255,255,.16); }

/* ---------- preview chat ---------- */
.pv-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.pv-head b { flex: 1; font-size: 14.5px; }
.pv-head small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.pv-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 9px; background: var(--bg); }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; animation: pv-in .2s ease-out; }
@keyframes pv-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: var(--c); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 5px; box-shadow: 0 0 0 1px var(--line); }
.msg.error { align-self: flex-start; background: var(--bad-soft); color: var(--bad); }
.toolchip { align-self: flex-start; font: 11.5px/1.4 var(--mono); color: var(--c-strong); background: var(--card); border: 1px dashed #c6d9d3; border-radius: 8px; padding: 5px 9px; max-width: 100%; overflow-wrap: anywhere; }
.pv-hint { color: var(--muted); font-size: 13px; text-align: center; margin: auto 0; padding: 24px; }
.pv-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.pv-form textarea { min-height: 42px; height: 42px; resize: none; }
.pv-stats { font-size: 11.5px; color: var(--muted); padding: 8px 14px; background: var(--bg); border-top: 1px solid var(--line); font-family: var(--mono); }
.pv-stats:empty { display: none; }

/* ---------- modal & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--card); color: var(--ink); box-shadow: 0 40px 80px -24px rgba(0,0,0,.45); }
dialog::backdrop { background: rgba(8, 13, 22, .55); backdrop-filter: blur(3px); }
.m-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.m-head h2 { flex: 1; font-size: 17px; margin: 0; letter-spacing: -.01em; }
.m-body { padding: 20px; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--card); }
.test-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.test-row textarea { min-height: 56px; }
@media (max-width: 640px) { .test-row { grid-template-columns: 1fr; } }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px); background: #0b1424; color: #fff; padding: 11px 18px; border-radius: 11px; font-size: 14px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); box-shadow: 0 16px 40px -12px rgba(0,0,0,.5); }
#toast.on { opacity: 1; transform: translateX(-50%); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .7s linear infinite; vertical-align: -2px; }
@keyframes s { to { transform: rotate(360deg); } }
