:root {
  /* Light theme (default). Dark theme overrides below via [data-theme="dark"]. */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --warn: #b54708;
  --warn-bg: #fff7ed;
  --warn-border: #fed7aa;
  --warn-soft: #fff3e0;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;
  --good: #1f7a3a;
  --thead-bg: #f9fafb;
  --row-border: #f1f3f5;
  --row-hover: #fafbfc;
  --neutral-soft: #f1f3f5;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --warn: #fdba74;
  --warn-bg: #2d1b00;
  --warn-border: #78350f;
  --warn-soft: #3a2208;
  --error-bg: #2a0f0f;
  --error-border: #7f1d1d;
  --error-text: #fca5a5;
  --good: #4ade80;
  --thead-bg: #1a2436;
  --row-border: #283549;
  --row-hover: #283549;
  --neutral-soft: #2a3548;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar-left { display: flex; align-items: baseline; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

select, button {
  font: inherit;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
button.ghost:hover { background: var(--row-hover); filter: none; }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

.status {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
}
.status.error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.warning {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}
.warning::before {
  content: "⚠";
  font-size: 18px;
  line-height: 1;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 28px; font-weight: 600; margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.table-wrap { overflow-x: auto; max-height: 420px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--thead-bg);
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--row-border);
  vertical-align: top;
}

tbody tr:hover { background: var(--row-hover); }

/* Indent rows nested under a parent (e.g. Tasks under their User Story). */
tbody tr.child-row td:nth-child(3) { padding-left: 32px; }
.tree-glyph {
  display: inline-block;
  width: 16px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 13px;
}

td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }

.state-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.state-pill.state-stale {
  background: var(--warn-soft);
  color: var(--warn);
}

.state-pill.state-new {
  background: var(--neutral-soft);
  color: var(--muted);
}

.progress-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.progress-percent {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.progress-bar-track {
  height: 10px;
  background: var(--neutral-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  border-radius: 999px;
  transition: width 300ms ease;
}
.progress-detail {
  font-size: 13px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 18px;
}

.chart-cell {
  height: 320px;
  position: relative;
}

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

/* Print-only header that surfaces the project name + date in the exported PDF. */
.print-only { display: none; }

@media print {
  /* Force light colors regardless of active theme so the PDF stays readable. */
  :root, [data-theme="dark"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --border: #d0d7de;
    --text: #1c2024;
    --muted: #57606a;
    --accent: #0969da;
    --accent-soft: #ddf4ff;
    --warn: #b54708;
    --warn-bg: #fff7ed;
    --warn-border: #fed7aa;
    --warn-soft: #fff3e0;
    --good: #1f7a3a;
    --thead-bg: #f6f8fa;
    --row-border: #eaeef2;
    --row-hover: transparent;
    --neutral-soft: #f6f8fa;
    --shadow: none;
  }

  body { background: white; }
  .topbar, #status, button, select, label[for="project-select"] { display: none !important; }
  main { max-width: none; padding: 12px 16px; gap: 14px; }
  .print-only { display: block; }
  #print-header { padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  #print-header h1 { margin: 0 0 4px 0; font-size: 18px; }
  #print-header .muted { font-size: 12px; }

  /* Don't split a card across pages when avoidable. */
  .card { break-inside: avoid; page-break-inside: avoid; box-shadow: none; }
  .card-head h2 { font-size: 14px; }

  /* Tables: drop sticky headers and the row-cap so all rows print. */
  .table-wrap { overflow: visible; max-height: none; }
  thead th { position: static; }
  tbody tr:hover { background: transparent; }

  /* Charts: cap height so they fit on a page; canvases scale to container. */
  .charts-row { padding: 8px; }
  .chart-cell { height: 240px; }

  /* Hide the hidden warning fully even with !important rules elsewhere. */
  .hidden { display: none !important; }
}
