/* Palette: the dataviz reference instance. Both modes validated against their
   own surface (light #fcfcfb, dark #1a1a19) — see README. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ed;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-1-soft: #cde2fb;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --shadow: none;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-1-soft: #184f95;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a {
  color: var(--series-1);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

/* ---------- shell ---------- */

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.brand span {
  color: var(--text-muted);
  font-weight: 400;
}

.spacer {
  flex: 1;
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

select,
input[type='text'],
input[type='date'],
input[type='number'] {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.55rem;
  min-width: 0;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

button {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: background 0.12s;
}

button:hover:not(:disabled) {
  background: var(--surface-2);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
  font-weight: 500;
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

nav.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--page);
  position: sticky;
  top: 53px;
  z-index: 19;
  overflow-x: auto;
}

nav.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.6rem 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

nav.tabs button[aria-selected='true'] {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
  font-weight: 500;
}

main {
  max-width: 78rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 5rem;
}

.panel[hidden] {
  display: none;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card > h2 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.card > .sub {
  color: var(--text-secondary);
  font-size: 0.84rem;
  margin: 0 0 1rem;
}

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.tile .label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.tile .value {
  font-size: 1.9rem;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tile .value.alarm {
  color: var(--critical);
}

.tile .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ---------- charts ---------- */

.chart-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.legend .item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.chart {
  position: relative;
  width: 100%;
}

.chart svg {
  display: block;
  width: 100%;
}

.chart .tick-label,
.chart .axis-label {
  font-size: 10px;
  fill: var(--text-muted);
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.08s;
}

.tooltip.on {
  opacity: 1;
}

.tooltip b {
  font-variant-numeric: tabular-nums;
}

/* ---------- burst cards ---------- */

.burst {
  border: 1px solid var(--border);
  border-left: 3px solid var(--axis);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  margin-bottom: 0.85rem;
  background: var(--surface-1);
  box-shadow: var(--shadow);
}

.burst.bot-wave {
  border-left-color: var(--critical);
}

.burst.suspicious {
  border-left-color: var(--warning);
}

.burst.organic-spike {
  border-left-color: var(--series-1);
}

.burst-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.burst-head .when {
  font-size: 1.02rem;
  font-weight: 600;
}

.burst-head .facts {
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.verdict {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}

.verdict.bot-wave {
  color: var(--critical);
  border-color: var(--critical);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
}

.verdict.suspicious {
  color: var(--serious);
  border-color: var(--serious);
  background: color-mix(in srgb, var(--serious) 12%, transparent);
}

.verdict.organic-spike {
  color: var(--text-secondary);
  border-color: var(--axis);
}

.burst-body {
  display: grid;
  grid-template-columns: minmax(15rem, 1fr) minmax(16rem, 1.1fr);
  gap: 1.5rem;
}

@media (max-width: 46rem) {
  .burst-body {
    grid-template-columns: 1fr;
  }
}

.signals {
  display: grid;
  gap: 0.45rem;
}

.signal {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.6rem;
  align-items: center;
  font-size: 0.8rem;
}

.signal .name {
  color: var(--text-secondary);
}

.signal .pct {
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 500;
}

.signal .track {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.signal .fill {
  height: 100%;
  border-radius: 3px;
  background: var(--series-1);
}

.signal.hot .fill {
  background: var(--critical);
}

/* ---------- tables ---------- */

.table-wrap {
  overflow: auto;
  max-height: 24rem;
  border: 1px solid var(--border);
  border-radius: 9px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8rem;
}

th,
td {
  text-align: left;
  padding: 0.34rem 0.6rem;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-weight: 600;
  z-index: 1;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.94em;
}

/* ---------- misc ---------- */

.row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.log {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  max-height: 11rem;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty h3 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.empty p {
  margin: 0 auto;
  max-width: 32rem;
  font-size: 0.87rem;
}

.callout {
  border-radius: 9px;
  padding: 0.7rem 0.9rem;
  font-size: 0.86rem;
  border: 1px solid;
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.callout .ico {
  font-size: 1rem;
  line-height: 1.3;
}

.callout.bad {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--critical) 45%, transparent);
  background: color-mix(in srgb, var(--critical) 9%, transparent);
}

.callout.ok {
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
  background: color-mix(in srgb, var(--good) 9%, transparent);
}

.callout.info {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
}

.chip {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-2);
}

details > summary {
  cursor: pointer;
  font-size: 0.83rem;
  color: var(--text-secondary);
  padding: 0.3rem 0;
}

.msg-list {
  display: grid;
  gap: 0.3rem;
  max-height: 22rem;
  overflow: auto;
}

.msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem;
  font-size: 0.83rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--grid);
}

.msg .ts {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  padding-top: 0.1rem;
}

.spin {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--series-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -1px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spin {
    animation-duration: 2s;
  }
  * {
    transition: none !important;
  }
}
