/* tableYOU KPI dashboard. Colours are roles, defined once per theme. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-raised: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6b6a66;
  --border: rgba(11, 11, 11, 0.1);
  --gridline: #e1e0d9;
  --accent: #2a78d6;
  --accent-track: #cde2fb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --must-bg: #1c5cab;
  --must-text: #ffffff;
  --partial-bg: #fff3d6;
  --partial-text: #6b4a00;
  --never-bg: #fbe3e3;
  --never-text: #8a1f1f;
  --error-bg: #fbe3e3;
  --error-border: #d03b3b;
  --skeleton: #ecebe6;
  --focus: #2a78d6;
  --radius: 12px;
  --gap: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-raised: #222220;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #a3a29a;
    --border: rgba(255, 255, 255, 0.1);
    --gridline: #2c2c2a;
    --accent: #3987e5;
    --accent-track: #184f95;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --must-bg: #86b6ef;
    --must-text: #0b0b0b;
    --partial-bg: #4a3a12;
    --partial-text: #ffe2a3;
    --never-bg: #4a1d1d;
    --never-text: #ffd0d0;
    --error-bg: #3a1717;
    --error-border: #e66767;
    --skeleton: #2c2c2a;
    --focus: #86b6ef;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-raised: #222220;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #a3a29a;
  --border: rgba(255, 255, 255, 0.1);
  --gridline: #2c2c2a;
  --accent: #3987e5;
  --accent-track: #184f95;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --must-bg: #86b6ef;
  --must-text: #0b0b0b;
  --partial-bg: #4a3a12;
  --partial-text: #ffe2a3;
  --never-bg: #4a1d1d;
  --never-text: #ffd0d0;
  --error-bg: #3a1717;
  --error-border: #e66767;
  --skeleton: #2c2c2a;
  --focus: #86b6ef;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

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

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.button-primary,
.button-ghost {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
}
.button-primary { background: var(--accent); color: #ffffff; border: 0; font-weight: 600; }
.button-ghost { background: transparent; border: 1px solid var(--border); }
.button-ghost:hover { background: var(--surface-raised); }

/* --- Login --------------------------------------------------------------- */

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.login-title { font-size: 1.5rem; margin-bottom: 4px; }
.login-form { display: grid; gap: 8px; margin-top: 20px; }
.login-form input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
}
.login-form button { margin-top: 12px; }
.login-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-left: 4px solid var(--error-border);
  background: var(--error-bg);
  border-radius: 6px;
}

/* --- Layout -------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner,
.page { max-width: 1200px; margin: 0 auto; padding: 12px 16px; }
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.brand { font-size: 1.15rem; }
.topbar-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent); color: #ffffff; font-weight: 600; }

.generated { margin: 4px 0 16px; font-size: 0.9rem; }

.panel,
.hero,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel { padding: 16px 20px; margin-bottom: var(--gap); }
.panel-title { font-size: 1rem; margin-bottom: 12px; }

/* --- North star ---------------------------------------------------------- */

.hero { padding: 24px; margin-bottom: var(--gap); min-height: 180px; }
.hero-eyebrow { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.hero-name { font-size: 1.35rem; margin: 6px 0 12px; }
.hero-value { font-size: 56px; font-weight: 600; line-height: 1; }
.hero-body { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .hero-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); } }
.hero .definition { margin: 0; color: var(--text-secondary); }

/* --- Coverage ------------------------------------------------------------ */

.stack { display: flex; height: 28px; gap: 2px; border-radius: 6px; overflow: hidden; }
.stack-segment { min-width: 4px; }
.stack-segment[data-slot="1"] { background: var(--series-1); }
.stack-segment[data-slot="2"] { background: var(--series-2); }
.stack-segment[data-slot="3"] { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 10px; padding: 0; list-style: none; }
.legend li { display: flex; gap: 8px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch[data-slot="1"] { background: var(--series-1); }
.swatch[data-slot="2"] { background: var(--series-2); }
.swatch[data-slot="3"] { background: var(--series-3); }

/* --- Filters ------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin: 8px 0 var(--gap);
}
.filters label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--text-secondary); }
.filters select {
  min-height: 44px;
  min-width: 180px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
}

.empty {
  text-align: center;
  padding: 32px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* --- Areas and cards ----------------------------------------------------- */

.area { margin-bottom: 28px; scroll-margin-top: 80px; }
.area-head { margin-bottom: 12px; }
.area-title { font-size: 1.2rem; }
.area-question { margin: 2px 0 0; color: var(--text-secondary); }

.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  width: 100%;
  min-width: 0;
}
.card:hover { border-color: var(--accent); }
.card.is-must { border-left: 4px solid var(--must-bg); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.card-id { font-size: 0.8rem; color: var(--text-muted); }
.card-name { font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
.card-value { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.card-unit { font-size: 0.95rem; font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
.card-reason { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
.card-meta { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.extras { margin: 0; padding: 0; list-style: none; font-size: 0.9rem; color: var(--text-secondary); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge-must { background: var(--must-bg); color: var(--must-text); border-color: transparent; }
.badge-partial { background: var(--partial-bg); color: var(--partial-text); border-color: transparent; }
.badge-never { background: var(--never-bg); color: var(--never-text); border-color: transparent; }

.state-label { font-size: 1.1rem; font-weight: 600; color: var(--text-secondary); }

/* Meter: a same-ramp track, so the bar reads as one shape. */
.meter { margin: 8px 0 6px; height: 8px; border-radius: 4px; background: var(--accent-track); overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }

/* --- Breakdown bars ------------------------------------------------------ */

.bars { display: grid; gap: 6px; margin: 4px 0 0; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(80px, 38%) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
}
.bar-label { overflow-wrap: anywhere; color: var(--text-secondary); }
.bar-track { height: 10px; position: relative; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--text-primary); white-space: nowrap; }
.bar-row.is-suppressed .bar-value { color: var(--text-muted); font-style: italic; }
.bar-row:hover .bar-fill { filter: brightness(1.1); }

.breakdown + .breakdown { margin-top: 12px; }
.breakdown-title { font-size: 0.85rem; font-weight: 600; margin: 0 0 4px; }

.table-toggle { margin-top: 8px; font-size: 0.85rem; }
.table-toggle summary { cursor: pointer; color: var(--text-secondary); }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; margin-top: 6px; }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--gridline); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Details dialog ------------------------------------------------------ */

dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-primary);
  padding: 20px;
}
#details-body { display: grid; gap: 12px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 12px; }
.details-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 16px; margin: 0; }
@media (min-width: 560px) { .details-list { grid-template-columns: 180px minmax(0, 1fr); } }
.details-list dt { font-weight: 600; color: var(--text-secondary); padding-top: 8px; }
.details-list dd { margin: 0; padding-top: 8px; overflow-wrap: anywhere; }

/* --- States -------------------------------------------------------------- */

.error-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: var(--gap);
  background: var(--error-bg);
  border-left: 4px solid var(--error-border);
  border-radius: 8px;
}

.skeleton { background: var(--skeleton); border-color: transparent; animation: pulse 1.4s ease-in-out infinite; }
.skeleton-line { height: 28px; border-radius: 6px; }
.skeleton-card { height: 150px; border-radius: var(--radius); }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface-raised);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

[hidden] { display: none !important; }

@media (forced-colors: active) {
  .meter-fill, .bar-fill, .stack-segment { forced-color-adjust: none; background: Highlight; }
}
