/* ==========================================================================
   PDC-KAP — Executive Project Dashboard
   Light default, dark by preference or manual toggle. No framework, no deps.
   ========================================================================== */

:root {
  color-scheme: light;

  --plane:          #f5f6f8;
  --surface:        #ffffff;
  --surface-2:      #fafbfc;
  --sunken:         #eef1f5;

  --ink:            #0d1522;
  --ink-2:          #3d4a5c;
  --muted:          #6b7787;
  --faint:          #98a2b3;

  --border:         #e3e8ef;
  --border-strong:  #cfd7e3;
  --grid:           #eef1f5;

  /* series */
  --plan:           #2a78d6;
  --plan-soft:      #cfdff5;
  --act:            #128f7f;
  --act-soft:       #cdeae4;
  --cost:           #d9662b;
  --pv:             #9aa9bd;
  --ev:             #128f7f;
  --ac:             #d9662b;

  /* status */
  --good:           #12855a;
  --good-bg:        #e3f4ec;
  --warn:           #a86a00;
  --warn-bg:        #fdf0d7;
  --serious:        #b4541d;
  --serious-bg:     #fde8dc;
  --crit:           #b3261e;
  --crit-bg:        #fbe3e1;
  --neutral:        #5b6675;
  --neutral-bg:     #eceff4;

  --accent:         #1d4ed8;
  --radius:         14px;
  --radius-s:       9px;
  --shadow:         0 1px 2px rgba(13,21,34,.04), 0 10px 26px -18px rgba(13,21,34,.35);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0b1119;
  --surface:        #121a24;
  --surface-2:      #151e29;
  --sunken:         #1b2634;

  --ink:            #f2f5f9;
  --ink-2:          #c3ccd8;
  --muted:          #93a0b1;
  --faint:          #6c7a8c;

  --border:         #223041;
  --border-strong:  #2e3f53;
  --grid:           #1d2836;

  --plan:           #5a9bf0;
  --plan-soft:      #23405f;
  --act:            #2fb9a4;
  --act-soft:       #17473f;
  --cost:           #ef8a4c;

  --good:           #45c08b;  --good-bg:   #123528;
  --warn:           #e8b24a;  --warn-bg:   #362a10;
  --serious:        #f0975c;  --serious-bg:#3a2112;
  --crit:           #f07c73;  --crit-bg:   #3d1a18;
  --neutral:        #a3b0c2;  --neutral-bg:#1e2a38;

  --accent:         #7ba7ff;
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 14px 34px -22px rgba(0,0,0,.9);
}



* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1, "ss01" 1;
}

h1, h2, h3, p { margin: 0; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.mark {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(155deg, #16233b 0%, #0b1119 100%);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.brand-text { min-width: 0; }

.brand h1 {
  font-size: clamp(15px, 1.4vw, 18px);
  font-weight: 700;
  letter-spacing: -.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub b { font-weight: 600; color: var(--ink-2); font-family: var(--mono); font-size: 11.5px; }
.dot { opacity: .45; padding: 0 2px; }

.controls { display: flex; align-items: center; gap: 10px; flex: none; }

.health {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px 7px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  white-space: nowrap;
}
.health::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 22%, transparent);
}
.health.is-crit { color: var(--crit); background: var(--crit-bg); }
.health.is-risk { color: var(--serious); background: var(--serious-bg); }
.health.is-watch { color: var(--warn); background: var(--warn-bg); }
.health.is-good { color: var(--good); background: var(--good-bg); }

.btn, .icon-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}
.btn { padding: 8px 14px; font-size: 12.5px; font-weight: 600; text-decoration: none; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; }
.btn:hover, .icon-btn:hover { background: var(--sunken); color: var(--ink); }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--sunken); }

/* ---------------------------------------------------------------- layout */
.wrap {
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(16px, 2.2vw, 26px) clamp(14px, 3vw, 34px) 56px;
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -.005em;
}

.card-head p {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); font-weight: 500; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-plan { background: var(--plan); }
.sw-act { background: var(--act); }
.sw-pv { background: var(--pv); }
.sw-ev { background: var(--ev); }
.sw-ac { background: var(--ac); }

/* ---------------------------------------------------------------- KPI cards */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--bar, transparent);
}

.kpi-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .085em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-value {
  font-family: var(--mono);
  font-size: clamp(21px, 2.1vw, 27px);
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value .unit { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.kpi-meta { font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.kpi-meta b { color: var(--ink-2); font-weight: 600; }

.delta { font-weight: 700; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.delta.neg { color: var(--crit); background: var(--crit-bg); }
.delta.pos { color: var(--good); background: var(--good-bg); }
.delta.flat { color: var(--neutral); background: var(--neutral-bg); }

.kpi-bar { height: 7px; border-radius: 4px; background: var(--sunken); position: relative; margin-top: 2px; overflow: hidden; }
.kpi-bar .fill { position: absolute; inset: 0 auto 0 0; background: var(--act); border-radius: 4px; }
.kpi-bar .plan-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--plan); }

/* ---------------------------------------------------------------- bars */
.bars { display: flex; flex-direction: column; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.5fr) minmax(120px, 2.4fr) 104px;
  gap: 14px;
  align-items: center;
  padding: 9px 6px;
  margin: 0 -6px;
  border-radius: var(--radius-s);
  border-bottom: 1px solid var(--grid);
  cursor: pointer;
  transition: background .14s ease;
}
.bar-row:last-child { border-bottom: 0; }
.bar-row:hover { background: var(--surface-2); }
.bar-row.is-active { background: var(--sunken); }

.bar-name { font-size: 12.5px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

.bar-track { position: relative; height: 12px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.bar-track .b-plan { position: absolute; inset: 0 auto 0 0; background: var(--plan-soft); }
.bar-track .b-act { position: absolute; inset: 0 auto 0 0; background: var(--act); border-radius: 4px; }
.bar-track .b-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--plan); }

.bar-val { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink); }

.bars.compact .bar-row { grid-template-columns: minmax(96px, 1fr) minmax(90px, 1.6fr) 92px; padding: 8px 6px; }

/* ---------------------------------------------------------------- donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { flex: none; width: 150px; height: 150px; position: relative; }
.donut svg { display: block; width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center b { font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -.03em; }
.donut-center span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.legend-list li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; font-size: 12px; }
.legend-list .nm { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-list .vl { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.legend-list .dotc { width: 10px; height: 10px; border-radius: 3px; }

/* ---------------------------------------------------------------- rank list */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rank li {
  display: grid;
  grid-template-columns: 22px 1fr 74px;
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--grid);
}
.rank li:last-child { border-bottom: 0; }
.rank .n {
  font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--muted);
}
.rank .nm { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.rank .mt { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.rank .sl { text-align: right; font-family: var(--mono); font-weight: 600; font-size: 14px; color: var(--crit); }
.rank .sl small { display: block; font-family: var(--font); font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-height: 420px; }
.register .table-wrap { max-height: 560px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  position: sticky; top: 0; z-index: 2;
  text-align: left;
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl th.num, .tbl td.num { text-align: right; }
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort]:hover { color: var(--ink); }
.tbl th .arrow { opacity: .45; font-size: 9px; margin-left: 3px; }
.tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl td.nm { font-weight: 550; color: var(--ink); }
.tbl td.mono, .tbl td.num { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.tbl .muted { color: var(--muted); }
.tbl .w-id { width: 62px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.serious { color: var(--serious); background: var(--serious-bg); }
.pill.crit { color: var(--crit); background: var(--crit-bg); }
.pill.neutral { color: var(--neutral); background: var(--neutral-bg); }

.var-neg { color: var(--crit); font-weight: 600; }
.var-pos { color: var(--good); font-weight: 600; }

/* ---------------------------------------------------------------- register toolbar */
.register-head { align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; color: var(--faint); pointer-events: none; }
.search input {
  font: inherit; font-size: 12.5px;
  padding: 8px 12px 8px 32px;
  width: 260px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 11.5px; font-weight: 600;
  padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.chip .c { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.chip:hover { background: var(--sunken); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip[aria-pressed="true"] .c { color: color-mix(in srgb, var(--surface) 75%, transparent); }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-tall { min-height: 250px; }

.ax-line { stroke: var(--grid); stroke-width: 1; }
.ax-text { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.ax-text.mono { font-family: var(--mono); }

.chart-note { font-size: 11px; color: var(--muted); margin-top: 8px; }

/* tooltip */
.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity .12s ease;
  background: #0d1522;
  color: #f4f7fb;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.45;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.6);
  max-width: 260px;
}
.tooltip.on { opacity: 1; }
.tooltip b { font-family: var(--mono); font-weight: 600; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }

/* ---------------------------------------------------------------- footer */
.foot {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 20px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}
.foot .defs { max-width: 880px; }
.foot code { font-family: var(--mono); font-size: 11px; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }
.foot .stamp { text-align: right; white-space: nowrap; }

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

/* ---------------------------------------------------------------- print */
@page { size: A3 landscape; margin: 8mm; }

@media print {
  html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar { position: static; backdrop-filter: none; }
  .wrap { max-width: 1440px; margin: 0 auto; }
  .table-wrap, .register .table-wrap { max-height: none; overflow: visible; }
  .tbl th { position: static; }
  a { text-decoration: none; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px 12px; padding: 10px 14px; }
  .brand { flex: 1 1 100%; min-width: 0; }
  .mark { width: 34px; height: 34px; border-radius: 10px; font-size: 10px; }
  .brand h1 { font-size: 15px; }
  .sub { font-size: 11px; }
  .controls { flex: 1 1 100%; justify-content: space-between; gap: 8px; }
  .health { flex: 1 1 auto; justify-content: center; font-size: 11.5px; padding: 6px 10px; }
  .health .health-note { display: none; }
  .btn { padding: 8px 12px; }
  .wrap { padding-top: 12px; }
  .kpis { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr 88px; }
  .bar-row .bar-track { grid-column: 1 / -1; order: 3; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
  .search input { width: 100%; }
  .search { flex: 1; }
  .foot { flex-direction: column; }
  .foot .stamp { text-align: left; white-space: normal; }
}

/* ==========================================================================
   v2 — schedule-only rebuild (NCT Domestic Water Pump Station)
   ========================================================================== */

.span-12 { grid-column: span 12; }

/* project identification strip */
.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 26px;
  margin-bottom: 16px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.mi { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ml {
  font-size: 9.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.mv {
  font-size: 12.5px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.pill.plan { color: var(--plan); background: var(--plan-soft); }
.faint { color: var(--faint); }
.soon { color: var(--serious); font-weight: 600; }

.card-head p code {
  font-family: var(--mono); font-size: 10.5px;
  background: var(--sunken); padding: 1px 5px; border-radius: 4px;
}

/* register: workstream group rows */
.tbl tr.grp td {
  background: var(--sunken);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  padding: 7px 10px;
}
.tbl tr.grp:hover td { background: var(--sunken); }
.gw { font-weight: 700; font-size: 12px; color: var(--ink); }
.gm { font-size: 10.5px; color: var(--muted); margin-left: 10px; font-family: var(--mono); }

.lvl-task { padding-left: 16px; display: inline-block; color: var(--ink-2); font-weight: 500; }
.lvl-sum { font-weight: 650; }
.lvl-roll { font-weight: 600; color: var(--muted); }

/* not in the schedule */
.nslist {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column;
  max-height: 292px; overflow: auto;
}
.nslist li { padding: 8px 0; border-bottom: 1px solid var(--grid); }
.nslist li:last-child { border-bottom: 0; }
.nsw {
  font-size: 12.5px; font-weight: 600; color: var(--ink);
  display: flex; gap: 8px; align-items: baseline;
}
.nsw::before {
  content: ""; width: 6px; height: 6px; border-radius: 2px;
  background: var(--crit); flex: none; transform: translateY(-2px);
}
.nswy { font-size: 11.5px; color: var(--muted); margin: 2px 0 0 14px; line-height: 1.5; }

/* calculation basis + audit */
.tbl-basis td, .tbl-audit td { vertical-align: top; }
.tbl-basis td:first-child { font-weight: 600; white-space: nowrap; }
.tbl-audit td:first-child { font-weight: 600; }
.tbl-audit td:nth-child(2) { white-space: nowrap; }
.tbl-audit tbody tr:hover td, .tbl-basis tbody tr:hover td { background: var(--surface-2); }

/* data notes */
.notes { list-style: none; margin: 0; padding: 0; counter-reset: note; }
.notes li {
  display: grid; grid-template-columns: 28px 1fr; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--grid);
  counter-increment: note;
}
.notes li:last-child { border-bottom: 0; }
.notes li::before {
  content: counter(note, decimal-leading-zero);
  font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.nt { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }

@media print {
  .meta-strip { break-inside: avoid; }
  .tbl tr { break-inside: avoid; }
  .nslist { max-height: none; overflow: visible; }
}

@media (max-width: 720px) {
  .meta-strip { gap: 8px 18px; padding: 10px 12px; }
  .gm { display: block; margin-left: 0; }
}
