/* ============================================================
   styles.css — base, header, controls, KPI cards,
   chart card, target card, health table, footer
   ============================================================ */

:root {
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --surface-2: #F0F4F9;
  --ink: #0F1B2D;
  --ink-2: #3D4A5C;
  --muted: #6B7A8F;
  --faint: #A8B4C4;
  --border: #D9E2EC;
  --border-strong: #B8C6D6;
  --accent: #1B5FDB;
  --accent-ink: #0F3FA8;
  --accent-soft: #E3EEFC;
  --good: #0E7C3A;
  --good-soft: #E2F4E9;
  --bad: #C03A2B;
  --bad-soft: #FBEAE7;
  --warn: #9A6A0A;
  --warn-soft: #FBF3DC;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 27, 45, .06), 0 1px 2px rgba(15, 27, 45, .04);
  --shadow-lift: 0 4px 12px rgba(15, 27, 45, .08);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 36px 32px 24px;
}

/* ---------- header ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.head-title h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.live-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(27, 95, 219, .15);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(27, 95, 219, .15); }
  50% { box-shadow: 0 0 0 6px rgba(27, 95, 219, .06); }
}
.subtitle {
  margin: 7px 0 0;
  color: var(--ink-2);
  font-size: 14px;
}
.subtitle em {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16.5px;
  color: var(--ink);
}

.head-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

/* ---------- controls: buttons, dropdowns, popovers ---------- */

.ctl {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 13px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.ctl:hover { border-color: var(--muted); box-shadow: 0 1px 3px rgba(29, 27, 22, .08); }
.ctl.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.ctl.primary:hover { background: #1550B8; }
.ctl-count {
  min-width: 18px; height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.dd { position: relative; }

.pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lift);
  z-index: 60;
  overflow: hidden;
  animation: popIn .14s ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.pop-title {
  padding: 10px 14px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.pop-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.pop-item:hover { background: var(--surface-2); }
.pop-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.pop-item .pop-side {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
.pop-item.active .pop-side { color: var(--accent-ink); }
.pop-sep { height: 1px; background: var(--border); margin: 5px 0; }
.pop-hint {
  padding: 9px 14px 11px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* filter popover */
#filtersPop { min-width: 264px; }
.filter-group { padding: 4px 0 8px; }
.filter-label {
  padding: 8px 14px 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.radio-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 14px;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.radio-row:hover { background: var(--surface-2); }
.radio-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--faint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.radio-row.active .radio-dot { border-color: var(--accent); }
.radio-row.active .radio-dot::after {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.radio-row.active { color: var(--accent-ink); font-weight: 600; }

/* ---------- KPI grid ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 18px 14px;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, transform .16s;
  position: relative;
  outline: none;
}
.kpi:hover, .kpi:focus-visible {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lift);
  transform: translateY(-1px);
}
.kpi-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
}
.kpi-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: .01em;
}
.kpi-value {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 9px 0 3px;
  font-variant-numeric: tabular-nums;
}
.kpi-value.masked { color: var(--faint); letter-spacing: .12em; }
.kpi-sub {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}
.delta {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
}
.delta.good { color: var(--good); background: var(--good-soft); }
.delta.bad { color: var(--bad); background: var(--bad-soft); }
.delta.none { color: var(--muted); background: var(--surface-2); }
.delta-vs { font-size: 11.5px; color: var(--muted); }
.kpi-spark { margin: 2px 0 10px; }
.kpi-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 9px;
}
.foot-fresh { color: var(--muted); }
.foot-cached { color: var(--ink-2); }
.foot-stale { color: var(--warn); }
.foot-cov {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 1px 6px;
  border-radius: 5px;
}

/* ---------- status badges (subtle, neutral) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2.5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--faint);
}
.badge.fresh i { background: var(--good); }
.badge.partial { border-color: #C6D5E5; background: #EEF3F9; color: #3D5A80; }
.badge.partial i { background: #3D5A80; }
.badge.stale { border-color: var(--border-strong); background: var(--surface-2); color: var(--ink-2); }
.badge.stale i { background: var(--muted); }
.badge.denied { border-color: #D9E2EC; background: #F4F7FB; color: #3D4A5C; }
.badge.denied i { background: var(--bad); }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 0;
  flex-wrap: wrap;
}
.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.card-foot {
  padding: 11px 20px 14px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1.9fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
  align-items: stretch;
}

/* ---------- momentum chart ---------- */

.chart-card { padding-bottom: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 11px;
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .14s;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); }
.chip.active {
  background: var(--accent-soft);
  border-color: #BCD2C4;
  color: var(--accent-ink);
  font-weight: 600;
}
.chart-body {
  position: relative;
  padding: 8px 12px 4px;
  min-height: 280px;
}
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #F5F3EE;
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12px;
  box-shadow: 0 6px 18px rgba(29, 27, 22, .25);
  z-index: 5;
  min-width: 128px;
}
.tip-date { color: #B9B4A6; font-size: 11px; margin-bottom: 2px; }
.tip-value { font-family: var(--mono); font-weight: 600; font-size: 14px; }
.tip-delta { font-family: var(--mono); font-size: 10.5px; display: block; margin-top: 3px; }
.tip-delta.good { color: #8FD6B4; }
.tip-delta.bad { color: #F0A58D; }

.axis-tick {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--muted);
}
.axis-target {
  font-family: var(--mono);
  font-size: 9.5px;
  fill: var(--accent);
  font-weight: 600;
}
.momentum-line { animation: lineIn .5s ease-out; }
@keyframes lineIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- target attainment ---------- */

.target-card { display: flex; flex-direction: column; }
#targetBody { padding: 8px 14px 6px; flex: 1; }
.trow {
  padding: 10px 6px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
  transition: background .14s;
}
.trow:first-child { border-top: 0; }
.trow:hover { background: var(--surface-2); }
.t-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.t-name { font-size: 12.5px; font-weight: 600; }
.t-nums { font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.t-cur { font-weight: 600; }
.t-tgt { color: var(--muted); margin-left: 5px; }
.t-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin: 8px 0 6px;
  overflow: hidden;
}
.t-bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width .5s ease;
}
.t-bar i.ok { background: var(--good); }
.t-bar i.near { background: #C39A2E; }
.t-bar i.risk { background: var(--bad); }
.t-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.t-pct { font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.t-pct.ok { color: var(--good); }
.t-pct.near { color: var(--warn); }
.t-pct.risk { color: var(--bad); }
.t-word { font-size: 11px; color: var(--muted); }

/* ---------- metric health table ---------- */

.table-card { overflow: hidden; }
table.health {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}
.health th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.health td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}
.health tbody tr { cursor: pointer; transition: background .13s; }
.health tbody tr:hover { background: var(--surface-2); }
.health tbody tr:last-child td { border-bottom: 0; }
.th-metric { min-width: 230px; }
.metric-cell { display: flex; flex-direction: column; gap: 1px; }
.metric-name { font-weight: 600; }
.metric-id {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
}
.metric-fresh { font-size: 11px; color: var(--muted); }
.cov-cell { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.cov-bar {
  width: 52px; height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.cov-bar i { display: block; height: 100%; background: var(--good); }
.cov-bar i.low { background: #C39A2E; }
.cov-num { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }
.change-cell { font-family: var(--mono); }
.trend-cell { width: 130px; }
.chev { color: var(--faint); text-align: right; width: 30px; }

.empty-state {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty-state strong { color: var(--ink-2); display: block; margin-bottom: 4px; font-size: 14px; }
.empty-state button {
  margin-top: 12px;
}

/* ---------- footer ---------- */

.page-foot {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-foot .foot-link {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
}
.page-foot .foot-link:hover { color: var(--ink); }

/* ---------- skeletons ---------- */

.skel {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, #F7FAFC 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
.kpi.skel-card { cursor: default; }
.kpi.skel-card:hover { transform: none; box-shadow: var(--shadow); border-color: var(--border); }

