/* Shared styles for the interactive demos. Builds on ../style.css tokens. */

:root {
  --series-1: #0f9ec2;   /* model / prediction */
  --series-2: #8f62ec;   /* comparison / baseline */
  --series-ink: #c9d3dd; /* ground truth */
  --grid: rgba(255, 255, 255, 0.07);
  --shade: rgba(255, 255, 255, 0.04);
  --good: #2fbf71;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --series-1: #0089b0; --series-2: #7340d8; --series-ink: #3a4552;
    --grid: rgba(15, 23, 34, 0.08); --shade: rgba(15, 23, 34, 0.04); --good: #1a8a52;
  }
}
:root[data-theme="light"] {
  --series-1: #0089b0; --series-2: #7340d8; --series-ink: #3a4552;
  --grid: rgba(15, 23, 34, 0.08); --shade: rgba(15, 23, 34, 0.04); --good: #1a8a52;
}

.demo { max-width: 1040px; padding-block: clamp(32px, 6vw, 64px); }
.demo h1 { font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -0.03em; margin-bottom: 12px; }
.demo-lede { color: var(--text-soft); max-width: 68ch; margin: 0 0 28px; font-size: 1.08rem; }

.demo-layout { display: grid; grid-template-columns: 290px 1fr; gap: 20px; align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 20px;
}
.controls { display: grid; gap: 22px; position: sticky; top: 84px; }
.control > label, .control > .control-label { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 0.95rem; margin-bottom: 8px; }
.control output { font-weight: 500; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.control .hint { font-size: 0.85rem; color: var(--text-faint); margin: 6px 0 0; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  flex: 1 1 auto; min-height: 38px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-soft);
  font: 500 0.9rem var(--font-body); cursor: pointer; font-variant-numeric: tabular-nums;
}
.segmented button:hover { color: var(--text); background: var(--surface-2); }
.segmented button[aria-pressed="true"] { background: var(--cyan); border-color: var(--cyan); color: var(--on-accent); }

input[type="range"] { width: 100%; accent-color: var(--cyan); height: 28px; }

.demo-results { display: grid; gap: 16px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.stat { display: flex; flex-direction: column; background: var(--surface); padding: 14px 16px; }
.stat .label { font-size: 0.85rem; color: var(--text-faint); }
.stat .value { font: 700 1.6rem var(--font-display); font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { font-size: 0.82rem; line-height: 1.35; color: var(--text-faint); margin-top: 4px; }
.stat .value.good { color: var(--good); }

.chart-panel { padding: 16px 16px 10px; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; margin-bottom: 8px; }
.chart-head h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0; padding: 0; font-size: 0.88rem; color: var(--text-soft); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .key { width: 20px; height: 0; border-top: 2px solid; }
.legend .key.dashed { border-top-style: dashed; }
.legend .key.shade { height: 10px; border: 1px solid var(--line); background: var(--shade); }

.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; width: 100%; height: 420px; touch-action: pan-y; }
.chart-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-faint); font-size: 0.95rem; pointer-events: none; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 2; min-width: 170px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 0.84rem; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  font-variant-numeric: tabular-nums;
}
.tooltip[hidden] { display: none; }
.tooltip .t-head { color: var(--text-faint); margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .t-row span:first-child { display: flex; align-items: center; gap: 6px; color: var(--text-soft); }
.tooltip .sw { width: 12px; border-top: 2px solid; }

.demo-notes { margin-top: 40px; max-width: 72ch; }
.demo-notes h2 { font-size: 1.35rem; margin: 0 0 10px; }
.demo-notes p, .demo-notes li { color: var(--text-soft); }
.demo-notes li { margin-bottom: 6px; }

details.table-view { margin-top: 8px; font-size: 0.9rem; }
details.table-view summary { cursor: pointer; color: var(--link); font-weight: 500; }
details.table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
details.table-view th, details.table-view td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); }
details.table-view th:first-child, details.table-view td:first-child { text-align: left; }
details.table-view th { color: var(--text-faint); font-weight: 500; }

@media (max-width: 860px) {
  .demo-layout { grid-template-columns: 1fr; }
  .controls { position: static; }
  .chart-wrap canvas { height: 340px; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .stat { display: grid; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 12px; }
  .stat .value { grid-column: 2; grid-row: 1 / span 2; margin: 0; align-self: center; font-size: 1.4rem; }
  .stat .label, .stat .sub { grid-column: 1; margin-top: 0; }
}

/* ---- Distribution demo ---- */
.lock-row { display: flex; gap: 8px; }
.lock-row input {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px;
}
.lock-row input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cyan) 25%, transparent); }
.lock-row .btn { min-height: 40px; padding: 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 10px 0 0; padding: 0; }
.chips:empty { display: none; }
.chips li {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.88rem;
}
.chips button { border: 0; background: none; color: var(--text-faint); cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 6px; border-radius: 999px; }
.chips button:hover { color: var(--text); background: var(--line); }

.legend .key.dot { width: 10px; height: 10px; border: 0; border-radius: 50%; }
.legend .key.dot.center { background: var(--series-1); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--series-1); }
.legend .key.dot.city { width: 7px; height: 7px; background: var(--series-ink); opacity: .7; }

.chart-wrap canvas.globe { height: auto; aspect-ratio: 1 / 1; max-height: 560px; margin-inline: auto; cursor: grab; touch-action: none; }
.chart-wrap canvas.globe:active { cursor: grabbing; }
.globe-hint { text-align: center; margin: 6px 0 2px; }

table.sites { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
table.sites th, table.sites td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.sites th { color: var(--text-faint); font-weight: 500; font-size: 0.88rem; }
table.sites tr:last-child td { border-bottom: 0; }
table.sites .bar { display: flex; align-items: center; gap: 10px; }
table.sites .bar span.track { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
table.sites .bar span.fill { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
table.sites .bar b { font-weight: 600; min-width: 3.2em; text-align: right; }
table.sites .lock-tag { font-size: 0.78rem; color: var(--text-faint); margin-left: 6px; }
.demo-layout > * { min-width: 0; }
.lock-row input { width: 100%; }

/* ---- Fraud demo ---- */
.controls .control-group { font: 600 0.78rem var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); margin: 0 0 -8px; }
.controls .control-group ~ .control-group { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 2px; }
.btn.btn-small { min-height: 34px; padding: 0 14px; font-size: 0.88rem; margin-top: 10px; }
.flag { display: inline-flex; align-items: center; gap: 6px; }
.flag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.flag.on::before { background: var(--warn); }
.flag.off::before { background: var(--good); }
:root { --warn: #e8a317; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --warn: #a66a00; } }
:root[data-theme="light"] { --warn: #a66a00; }
.legend .key.marker { width: 0; height: 12px; border-top: 0; border-left: 1.5px dashed var(--text-faint); }
.tx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.tx-row .hint { margin: 0; }
.tx-row .btn.btn-small { margin-top: 0; }
.tx-row .btn.btn-small { white-space: nowrap; }
.chart-wrap canvas.bars { height: 280px; }

/* ---- Distribution demo additions ---- */
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.9rem; color: var(--text-soft); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--cyan); margin: 0; }
.check.disabled { opacity: 0.55; cursor: default; }
input[type="range"]:disabled { opacity: 0.5; }
.table-note { font-size: 0.88rem; color: var(--text-faint); margin: 0 0 10px; }
.control > label.check { justify-content: flex-start; font-weight: 400; margin-bottom: 0; }
