/* CALM web client — styles (redesign) */
:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f1f3f7;
  --ink: #12161c;
  --ink-soft: #5a626d;
  --ink-faint: #8b929d;
  --line: #e2e6ec;
  --line-soft: #edf0f4;
  --accent: #3b6ef5;
  --accent-ink: #ffffff;
  --accent-soft: #e7eeff;
  --ok: #12855a;
  --ok-bg: #e2f4ea;
  --bad: #c93636;
  --bad-bg: #fbe6e3;
  --warn: #9a6b00;
  --warn-bg: #fbf0d3;
  --shadow: 0 1px 2px rgba(16,22,28,.04), 0 4px 16px rgba(16,22,28,.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 12px;
  --r-sm: 8px;
}
:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  --dark-on: initial;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #171b21; --panel-2: #1e242c; --ink: #eef1f5;
    --ink-soft: #a3abb6; --ink-faint: #727a86; --line: #2a313b; --line-soft: #222831;
    --accent: #5e8bff; --accent-ink: #0b0e12; --accent-soft: #1c2740;
    --ok: #45c98a; --ok-bg: #122c22; --bad: #f0796b; --bad-bg: #331b19;
    --warn: #e2b64f; --warn-bg: #302807;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --panel: #171b21; --panel-2: #1e242c; --ink: #eef1f5;
  --ink-soft: #a3abb6; --ink-faint: #727a86; --line: #2a313b; --line-soft: #222831;
  --accent: #5e8bff; --accent-ink: #0b0e12; --accent-soft: #1c2740;
  --ok: #45c98a; --ok-bg: #122c22; --bad: #f0796b; --bad-bg: #331b19;
  --warn: #e2b64f; --warn-bg: #302807;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  padding: 0 20px 72px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
h1,h2,h3 { letter-spacing: -0.012em; }

/* ---------- Header ---------- */
header.top { max-width: 1200px; margin: 0 auto; padding: 22px 0 10px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand .mark {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  font-size: 22px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.brandtext { flex: 1; min-width: 0; }
.brandtext h1 { margin: 0; font-size: 21px; }
.brandtext .sub { color: var(--ink-soft); font-size: 13px; margin-top: 1px; }
.brandtext .sub b { color: var(--ink); font-weight: 700; }
.brandactions { display: flex; gap: 8px; }

.chip {
  font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 999px; padding: 7px 13px; cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.accent:hover { color: var(--accent-ink); filter: brightness(1.06); }

.about {
  max-width: 1200px; margin: 12px auto 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow);
}
.about p { margin: 0 0 6px; font-size: 13.5px; }
.about p:last-child { margin-bottom: 0; }
.about .muted { color: var(--ink-soft); font-size: 12.5px; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1200px; margin: 16px auto 0; display: grid;
  grid-template-columns: 348px 1fr; gap: 18px; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow);
}
.phead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); }
.panel h3 { margin: 0; font-size: 14px; }
.hint, .phead .hint { font-size: 11px; color: var(--ink-faint); }

.sidebar { position: sticky; top: 14px; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 900px) { .sidebar { position: static; } }

/* ---------- Buttons ---------- */
button, .btn { font: inherit; cursor: pointer; }
button.primary {
  background: var(--accent); border: 1px solid var(--accent); color: var(--accent-ink);
  border-radius: var(--r-sm); padding: 11px 14px; font-weight: 650; font-size: 14px; width: 100%;
  transition: filter .12s, opacity .12s; box-shadow: var(--shadow);
}
button.primary:hover { filter: brightness(1.06); }
button.primary:disabled { opacity: .5; cursor: not-allowed; filter: none; }
button.ghost {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-sm); padding: 8px 12px;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.small { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Presets ---------- */
.presets { display: flex; flex-direction: column; gap: 8px; }
.preset {
  display: grid; text-align: left; gap: 1px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px;
  transition: border-color .12s, background .12s, transform .06s;
}
.preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset:active { transform: translateY(1px); }
.preset .pname { font-weight: 650; font-size: 13.5px; }
.preset .pdesc { font-size: 12px; color: var(--ink-soft); }
.preset .ptime { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); margin-top: 2px; }

/* ---------- Form ---------- */
fieldset { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; margin: 0 0 12px; }
fieldset:last-of-type { margin-bottom: 0; }
fieldset legend { padding: 0 6px; font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.lgnote { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink-faint); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.field label {
  display: flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px;
}
.field label span { color: var(--ink-faint); font-family: var(--mono); font-size: 11px; }
.field input, .field select {
  width: 100%; font: inherit; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--bg); color: var(--ink); transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input:disabled { color: var(--ink-faint); }

table.anneal { width: 100%; border-collapse: collapse; }
table.anneal th { font-size: 11px; color: var(--ink-faint); font-weight: 500; text-align: left; padding: 2px 3px; }
table.anneal td { padding: 2px 3px; }
table.anneal input { width: 100%; font: 13px var(--mono); padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
table.anneal input:focus { outline: none; border-color: var(--accent); }
table.anneal button { padding: 3px 8px; background: transparent; border: 1px solid var(--line); border-radius: 6px; color: var(--ink-soft); }
table.anneal button:hover { border-color: var(--bad); color: var(--bad); }
#addSeg { margin-top: 8px; }

/* ---------- Run panel ---------- */
.runpanel { display: flex; flex-direction: column; gap: 10px; }
.runbar { display: flex; gap: 8px; align-items: center; }
.progress-wrap { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.runmeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.runmeta .status { font-size: 12.5px; color: var(--ink-soft); font-family: var(--mono); }
.live { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.live input { accent-color: var(--accent); width: 15px; height: 15px; }
.statwrap { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.spinner {
  width: 13px; height: 13px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busychip {
  position: sticky; top: 8px; z-index: 5; align-self: flex-start; width: max-content;
  display: inline-flex; align-items: center; gap: 8px; margin: 0 auto 2px;
  background: var(--panel); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 999px; padding: 6px 13px; font-size: 12.5px; font-weight: 600; box-shadow: var(--shadow);
}
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.cost { font-size: 11px; border-radius: 999px; padding: 3px 10px; border: 1px solid var(--line); white-space: nowrap; }
.cost .badge { font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.cost.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.cost.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.cost.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.nums { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); word-break: break-word; }

/* ---------- Permalink ---------- */
.linkbar { display: flex; gap: 8px; align-items: center; }
.linkbar input {
  flex: 1; min-width: 0; font: 12px var(--mono); padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--bg); color: var(--ink-soft);
}
.copied { color: var(--ok); font-size: 12px; margin-top: 8px; }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.hidden { display: none !important; }

.mockflag {
  background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn); border-radius: var(--r-sm); padding: 10px 12px; font-size: 12.5px;
}

/* Empty state */
.empty {
  background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r);
  padding: 56px 24px; text-align: center; box-shadow: var(--shadow);
}
.empty-badge {
  width: 56px; height: 56px; margin: 0 auto 14px; display: grid; place-items: center;
  font-size: 26px; background: var(--accent-soft); border-radius: 16px;
}
.empty h2 { margin: 0 0 6px; font-size: 18px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.empty p { margin: 0 auto 16px; max-width: 420px; color: var(--ink-soft); font-size: 13.5px; }
.empty-presets { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Metric cards */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 720px) { .metrics { grid-template-columns: 1fr 1fr; } }
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 15px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.metric .mlabel { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.metric .mval { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 2px; line-height: 1.1; }
.metric .msub { font-size: 11.5px; color: var(--ink-faint); }
.metric.pass { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.metric.pass .mval { color: var(--ok); }
.metric.fail .mval { color: var(--bad); }
.metric.warnv .mval { color: var(--warn); }
.mbar { height: 5px; background: var(--panel-2); border-radius: 3px; margin-top: 9px; overflow: hidden; }
.mbarfill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

/* Criteria detail */
.criteria { display: grid; gap: 8px; }
.crit {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 12px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2);
}
.crit .mark {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 14px; background: var(--bg); color: var(--ink-faint);
}
.crit.pass .mark { color: var(--accent-ink); background: var(--ok); }
.crit.fail .mark { color: var(--accent-ink); background: var(--bad); }
.crit .title { font-size: 13.5px; font-weight: 550; }
.crit .title small { display: block; color: var(--ink-soft); font-size: 11.5px; font-weight: 400; margin-top: 1px; }
.crit .val { font-family: var(--mono); font-size: 13px; font-weight: 650; }

.coverage {
  font-family: var(--mono); font-size: 12px; color: var(--ink-soft); margin-top: 12px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2);
}
.coverage .ok { color: var(--ok); font-weight: 700; }
.coverage .bad { color: var(--bad); font-weight: 700; }

/* Charts */
.cv { position: relative; height: 240px; }
.cv.hero { height: 300px; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .charts { grid-template-columns: 1fr; } }
.note { font-size: 11.5px; color: var(--ink-faint); margin-top: 8px; }

.footer-note { max-width: 1200px; margin: 22px auto 0; color: var(--ink-faint); font-size: 12px; }
