/* app.css — application chrome ONLY. Widget visual language lives in the framework
   (style.js injects the token bundle; components carry their own styles per doc 03/04). */

:root {
  --ui-bg: #0e1114;
  --ui-panel: #15191e;
  --ui-panel2: #1a1f25;
  --ui-line: #262d35;
  --ui-text: #e8ecef;
  --ui-dim: #8b97a3;
  --ui-faint: #5c6873;
  --ui-accent: #3aa0ff;
  --ui-good: #34d399;
  --ui-bad: #ff4d5e;
  --ui-mono: "IBM Plex Mono", ui-monospace, monospace;
  --ui-sans: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ui-sans);
  background: var(--ui-bg);
  color: var(--ui-text);
  font-weight: 400;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--ui-line);
  background: var(--ui-panel);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: 0.2px; }
.brand-mark {
  width: 10px; height: 10px; border-radius: 50%;
  background: conic-gradient(from 220deg, var(--ui-accent) 0 270deg, transparent 270deg 360deg);
  border: 2px solid var(--ui-line);
  align-self: center;
}
.brand-sub { font-size: 11px; color: var(--ui-faint); font-family: var(--ui-mono); }
.top-actions { display: flex; gap: 8px; align-items: center; }

button.ghost {
  background: transparent;
  border: 1px solid var(--ui-line);
  color: var(--ui-dim);
  font: 500 11px var(--ui-sans);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
button.ghost:hover { color: var(--ui-text); border-color: var(--ui-faint); }

#wallpapers { display: flex; gap: 6px; margin-right: 8px; }
#wallpapers button {
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--ui-line);
}
#wallpapers button.active { outline: 2px solid var(--ui-accent); outline-offset: 1px; }

/* ---------- layout ---------- */
#layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 52px);
}

/* ---------- chat ---------- */
#chat {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ui-line);
  background: var(--ui-panel);
  min-height: 0;
}
#transcript { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.45; }
.msg.user { align-self: flex-end; background: #233140; color: var(--ui-text); }
.msg.system {
  align-self: flex-start;
  background: var(--ui-panel2);
  border: 1px solid var(--ui-line);
  color: var(--ui-dim);
  font-family: var(--ui-mono);
  font-size: 11px;
  width: 100%;
  max-width: 100%;
}
.msg .ok { color: var(--ui-good); }
.msg .bad { color: var(--ui-bad); }
.msg .hi { color: var(--ui-accent); }

.trace { margin-top: 6px; border-top: 1px dashed var(--ui-line); padding-top: 6px; }
.trace-row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.trace-row .t-stage { color: var(--ui-text); }
.trace-row .t-engine { color: var(--ui-faint); font-size: 10px; }
.trace-row .t-ms { color: var(--ui-dim); }
.trace-bars { margin-top: 4px; }
.trace-bar { height: 4px; border-radius: 2px; background: var(--ui-accent); margin: 2px 0; opacity: 0.8; }

#chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--ui-line); }
#chat-input {
  flex: 1;
  background: var(--ui-panel2);
  border: 1px solid var(--ui-line);
  color: var(--ui-text);
  font: 400 13px var(--ui-sans);
  padding: 10px 12px;
  border-radius: 8px;
  outline: none;
}
#chat-input:focus { border-color: var(--ui-accent); }
#chat-send {
  background: var(--ui-accent);
  color: #06121f;
  border: 0;
  font: 600 12px var(--ui-sans);
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
}

/* ---------- stage / boards ---------- */
#stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
#stage-row, #panel-row { display: grid; gap: 12px; padding: 12px; }
#stage-row { grid-template-columns: minmax(340px, 460px) 1fr; }
#panel-row { grid-template-columns: 1fr 1fr 1fr; padding-top: 0; }
@media (max-width: 1280px) { #panel-row { grid-template-columns: 1fr 1fr; } }

.panel {
  background: var(--ui-panel);
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}
.panel-head {
  font: 600 11px var(--ui-sans);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ui-dim);
  padding: 12px 14px 8px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.panel-sub { font: 400 10px var(--ui-mono); color: var(--ui-faint); text-transform: none; letter-spacing: 0; }

.panel-body, #stage-body, #board-body, #inspector-body, #kev-body {
  padding: 10px 14px 14px;
  flex: 1;
  min-height: 0;
}
.empty-hint { color: var(--ui-faint); font-size: 12px; padding: 18px 4px; }

#stage-body {
  display: flex;
  align-items: center;
  justify-content: center;
  /* wallpaper behind the widget — the widget's material reads against it */
  background: var(--wallpaper, linear-gradient(135deg, #2b3a4a, #171e26));
  border-radius: 10px;
  min-height: 300px;
}
#stage-meta { font: 400 10px var(--ui-mono); color: var(--ui-faint); padding: 0 14px 12px; }

#board-body { display: flex; align-items: center; justify-content: center; }

/* inspector table */
.checks { width: 100%; border-collapse: collapse; font: 400 11px var(--ui-mono); }
.checks td { padding: 4px 6px; border-bottom: 1px solid var(--ui-line); vertical-align: top; }
.checks .cid { color: var(--ui-text); white-space: nowrap; font-weight: 500; }
.checks .cname { color: var(--ui-dim); }
.checks .cpass { text-align: right; white-space: nowrap; }
.checks .pass { color: var(--ui-good); }
.checks .fail { color: var(--ui-bad); }
.checks .warn { color: #e5b567; }
.verdict { font: 600 12px var(--ui-sans); margin: 4px 0 10px; }
.verdict.pass { color: var(--ui-good); }
.verdict.fail { color: var(--ui-bad); }
.verdict.unver { color: #e5b567; }

/* kev log */
.kev-entry { border: 1px solid var(--ui-line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-family: var(--ui-mono); font-size: 10.5px; }
.kev-head { display: flex; justify-content: space-between; color: var(--ui-dim); margin-bottom: 4px; }
.kev-choice { color: var(--ui-accent); font-weight: 500; }
.kev-probs { display: flex; flex-direction: column; gap: 3px; }
.kev-prob { display: grid; grid-template-columns: 86px 1fr 44px; align-items: center; gap: 6px; }
.kev-prob .bar { height: 4px; border-radius: 2px; background: var(--ui-accent); opacity: 0.85; }
.kev-prob .lbl { color: var(--ui-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kev-prob .p { color: var(--ui-faint); text-align: right; }
.kev-prob.win .lbl { color: var(--ui-text); }
.kev-prob.win .bar { background: var(--ui-good); }

/* perf panel */
.perf-device { font: 400 10px var(--ui-mono); color: var(--ui-faint); margin-bottom: 8px; line-height: 1.5; }
.perf-rows { width: 100%; font: 400 11px var(--ui-mono); border-collapse: collapse; }
.perf-rows td { padding: 3px 6px 3px 0; border-bottom: 1px solid var(--ui-line); }
.perf-rows td:nth-child(2) { text-align: right; color: var(--ui-dim); white-space: nowrap; }
.perf-rows td:nth-child(3) { text-align: right; color: var(--ui-dim); white-space: nowrap; }
.perf-rows td:nth-child(4) { text-align: right; color: var(--ui-faint); white-space: nowrap; }
.perf-sec { font: 600 10px var(--ui-sans); letter-spacing: 1px; text-transform: uppercase; color: var(--ui-dim); margin: 8px 0 4px; }
#btn-bench { margin-top: 10px; }

/* view switcher + catalog */
#view-switch { display: flex; margin-right: 10px; }
#view-switch .ghost, #catalog-states .ghost { border-radius: 0; border-right-width: 0; }
#view-switch .ghost:first-child, #catalog-states .ghost:first-child { border-radius: 6px 0 0 6px; }
#view-switch .ghost:last-child, #catalog-states .ghost:last-child { border-radius: 0 6px 6px 0; border-right-width: 1px; }
#view-switch .ghost.on, #catalog-states .ghost.on { color: var(--ui-text); background: #1d242c; }
#catalog-states { display: flex; width: max-content; margin: 0 auto 14px; }

#catalog-root { height: calc(100vh - 52px); overflow-y: auto; display: none; }
body.catalog-view #catalog-root { display: block; }
body.catalog-view #layout { display: none; }
.catalog { max-width: none; margin: 0 auto; padding: 18px 22px 80px; }
.catalog-title { font: 600 15px var(--ui-sans); }
.catalog-sub { font: 400 11px var(--ui-mono); color: var(--ui-faint); margin-top: 4px; line-height: 1.6; }
.catalog-summary { font: 400 11px var(--ui-mono); color: var(--ui-dim); margin-top: 10px; padding: 10px 12px; border: 1px solid var(--ui-line); border-radius: 8px; background: var(--ui-panel); line-height: 1.7; }
.catalog-summary .dim, .catalog-sub .dim { color: var(--ui-faint); }
.catalog-summary b.ok { color: var(--ui-good); }
.catalog-grid { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; justify-content: center; padding: 8px 4px 40px; }
.cat-board { width: 393px; padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 14px; border-radius: 28px; background-size: cover; background-position: center; }
.cat-row { display: flex; gap: 14px; align-items: flex-start; }
.specimen { position: relative; flex: 0 0 auto; cursor: pointer; }
.specimen:hover { outline: 2px solid rgba(255,255,255,.35); outline-offset: 3px; border-radius: 26px; }
.specimen-badge { position: absolute; top: -7px; right: -7px; z-index: 5; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; font: 600 10px/20px var(--ui-mono); text-align: center; background: #10141a; border: 1px solid var(--ui-line); color: var(--ui-dim); }
.specimen-badge.good { color: var(--ui-good); border-color: rgba(52,211,153,.4); }
.specimen-badge.bad { color: var(--ui-bad); border-color: rgba(255,77,94,.4); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a323b; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
