/* Dark theme like the approved mockups: near-black page, flat cards with hairline borders, light text,
   one blue accent. No gradients, glows or drop shadows. Dark only. */
:root {
  color-scheme: dark;
  --bg: #141413;
  --surface: #1f1e1d;
  --surface-2: #2a2927;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-2: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.15);
  --amber: #fac775;
  --success: #97c459;
  --danger: #f09595;
  --warning: #fac775;
  --warning-soft: rgba(239, 159, 39, 0.15);
  --glow: none;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: none;
  --shadow-lg: none;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  scrollbar-color: var(--border-strong) transparent;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-corner { background: transparent; }

.num { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ── Header */
.header {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
  padding: 18px 24px;
}
.header-inner {
  position: relative;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: none; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 500; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.header-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 400;
  background: transparent;
  border: 0.5px solid var(--border-strong);
  color: var(--text-2);
  white-space: nowrap;
}
.chip-live::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--success); animation: pulse 2s infinite;
}
.chip-demo, .chip-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); font-weight: 500; }
a.chip { text-decoration: none; transition: background 0.2s, border-color 0.2s; }
a.chip:hover { background: var(--surface-2); }

/* ── Layout */
.page { max-width: 1400px; margin: 0 auto; padding: 22px 24px 36px; }
.stack { display: grid; gap: 18px; }
.stack > * { animation: rise 0.45s ease both; }
.stack > *:nth-child(2) { animation-delay: 0.04s; }
.stack > *:nth-child(3) { animation-delay: 0.08s; }
.stack > *:nth-child(4) { animation-delay: 0.12s; }
.stack > *:nth-child(5) { animation-delay: 0.16s; }

.card {
  position: relative;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-width: 0;
}
.card h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.muted { color: var(--text-2); }
.grid-charts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 18px; }

/* ── View switcher (segmented buttons) */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: 0.5px solid var(--border-strong);
  background: transparent;
  color: var(--text-2);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 400;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 500;
}
.tab .count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.tab[aria-pressed="true"] .count { background: var(--accent-soft); color: var(--accent); }
.tabs-main .tab { padding: 9px 18px; font-size: 14px; }

/* ── KPI / metric tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 12px; }
.kpi {
  position: relative;
  overflow: hidden;
  text-align: left;
  border: none;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: box-shadow 0.2s;
  min-width: 0;
}
.kpi:hover { box-shadow: inset 0 0 0 0.5px var(--border-strong); }
.kpi[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--kpi-color, var(--accent)); }
.kpi-label { font-size: 13px; font-weight: 400; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kpi-color); flex: none; }
.kpi-value { font-size: 22px; font-weight: 500; margin-top: 4px; color: var(--kpi-color, var(--text)); }
.kpi-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.kpi-bar { height: 4px; border-radius: 999px; background: var(--border); margin-top: 10px; overflow: hidden; }
.kpi-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--kpi-color, var(--accent)); transition: width 0.8s cubic-bezier(.2,.8,.2,1); }
.kpi-hero { grid-column: span 2; }

/* ── Module cards */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.module-card { text-align: left; cursor: pointer; width: 100%; font: inherit; color: inherit; padding: 16px; overflow: hidden; transition: background 0.2s, border-color 0.2s; }
.module-card:hover { background: var(--surface-2); border-color: var(--border-strong); }
.module-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.module-card-name { font-weight: 500; font-size: 14px; color: var(--text); }
.module-card-pct { font-weight: 500; font-size: 18px; color: var(--accent); }
.module-card-pct[data-tone="low"] { color: var(--warning); }
.module-card-pct[data-tone="full"] { color: var(--success); }
.progress { position: relative; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 10px 0 8px; }
.progress > span {
  position: relative;
  display: block; height: 100%; border-radius: 999px; overflow: hidden;
  background: var(--accent);
  transition: width 0.9s cubic-bezier(.2,.8,.2,1);
}
.module-card-pills { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Badges & pills: a light shade of the badge's own hue on a faint tint of it */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  color: color-mix(in srgb, var(--badge-color) 55%, var(--text));
  background: color-mix(in srgb, var(--badge-color) 15%, transparent);
  border: 0.5px solid color-mix(in srgb, var(--badge-color) 35%, transparent);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--badge-color); }
.pill-btn { cursor: pointer; }
.pill-btn:hover { background: color-mix(in srgb, var(--badge-color) 25%, transparent); }

/* ── Insights */
.insights {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.insights-head { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); margin-bottom: 8px; font-size: 15px; }
.insights-head svg { color: var(--warning); }
.insights ul { margin: 0; padding-left: 18px; display: grid; gap: 5px; color: var(--text-2); }
.insights li::marker { color: var(--muted); }

/* ── Filters */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input, .select {
  font: inherit;
  padding: 8px 12px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  min-width: 0;
}
.input::placeholder { color: var(--muted); }
.input { width: 240px; max-width: 100%; }
.input:hover, .select:hover { background: var(--surface-2); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select option { background: var(--surface); color: var(--text); }
.link-btn { border: none; background: none; color: var(--accent); font-weight: 500; cursor: pointer; padding: 0; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent); border: 0.5px solid transparent;
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 500; cursor: pointer;
}

/* ── Table */
.table-wrap { overflow: auto; max-height: 560px; border: 0.5px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left; font-weight: 500; color: var(--text-2);
  font-size: 12px;
  padding: 11px 12px; white-space: nowrap; border-bottom: 0.5px solid var(--border-strong);
}
tbody td { padding: 9px 12px; border-bottom: 0.5px solid var(--border); vertical-align: top; color: var(--text-2); }
tbody tr { transition: background 0.15s; }
tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
tbody tr:hover { background: rgba(255, 255, 255, 0.04); }
td.idx { color: var(--muted); }
td.strong { font-weight: 500; color: var(--text); }
td.wrap { min-width: 180px; max-width: 280px; }
.empty { text-align: center; padding: 32px; color: var(--muted); }

/* ── Description hover */
.desc { position: relative; display: inline-block; color: var(--text-2); font-size: 13px; }
.desc[data-truncated="true"] { cursor: help; }
.desc-pop {
  position: absolute; top: 100%; right: 0; margin-top: 6px;
  width: min(640px, 85vw); max-height: 50vh; overflow-y: auto;
  padding: 12px 14px; background: var(--surface-2); color: var(--text);
  border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm);
  white-space: pre-wrap; word-break: break-word; line-height: 1.6; z-index: 20;
}

/* ── Charts */
.chart-tooltip {
  background: var(--surface-2); color: var(--text); border-radius: var(--radius-sm);
  border: 0.5px solid var(--border-strong);
  padding: 10px 12px; font-size: 12px; min-width: 150px;
}
.chart-tooltip-title { font-weight: 500; margin-bottom: 6px; color: var(--text); }
.chart-tooltip-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.chart-tooltip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.chart-tooltip-total { margin-top: 4px; border-top: 0.5px solid var(--border); padding-top: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--text); font-weight: 500; }
.donut-wrap { position: relative; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center strong { font-size: 22px; font-weight: 500; color: var(--text); }
.donut-center small { color: var(--muted); font-weight: 400; font-size: 11px; }
.recharts-sector, .recharts-rectangle { transition: filter 0.2s; }
.recharts-sector:hover, .recharts-bar-rectangle:hover { filter: brightness(1.12); }

/* ── Admin & alerts */
.notice { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-top: 10px; border: 0.5px solid transparent; }
.notice-error { background: rgba(226, 75, 74, 0.15); border-color: rgba(226, 75, 74, 0.35); color: var(--danger); }
.notice-ok { background: rgba(99, 153, 34, 0.15); border-color: rgba(99, 153, 34, 0.40); color: var(--success); }
.notice-info { background: var(--accent-soft); border-color: rgba(57, 135, 229, 0.35); color: var(--text); }
.file-input { width: 100%; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: transparent; color: var(--text-2); }
.btn { border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 16px; font-weight: 500; cursor: pointer; background: transparent; color: var(--text); transition: background 0.2s; }
.btn:hover { background: var(--surface-2); }

/* Admin panel (Task 12 builds the markup) */
.admin-panel {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-width: 0;
}
.style-option {
  display: block; width: 100%; text-align: left; cursor: pointer; font: inherit;
  background: transparent; color: var(--text);
  border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: background 0.2s;
}
.style-option:hover { background: var(--surface-2); }
.style-option-title, .style-option strong { display: block; font-size: 13px; font-weight: 500; color: var(--text); }
.style-option-desc, .style-option small { display: block; font-size: 11px; color: var(--text-2); }
/* 2px border; padding shrinks by the extra 1.5px so the card keeps its size */
.style-option.is-live, .style-option.is-selected {
  border: 2px solid var(--accent); background: var(--accent-soft); padding: 8.5px 10.5px;
}
.style-option.is-live .style-option-title, .style-option.is-selected .style-option-title,
.style-option.is-live strong, .style-option.is-selected strong { color: var(--accent); }
.preview-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px 0 0; }

.to-top {
  position: fixed; right: 16px; bottom: 16px; z-index: 30;
  border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 14px;
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer;
  transition: background 0.2s;
}
.to-top:hover { background: var(--surface-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Phone width */
@media (max-width: 760px) {
  .header { padding: 14px 16px; }
  .page { padding: 16px; }
  .grid-charts { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-hero { grid-column: 1 / -1; }
  .card { padding: 16px; }
  .input { width: 100%; }
  .filter-row > * { flex: 1 1 100%; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .tab { flex: none; }
  .table-wrap { max-height: 70vh; }
}
