:root {
  --navy: #14295A;
  --navy-2: #1F3C7A;
  --ink: #1B2333;
  --muted: #5B6578;
  --line: #D9DEE8;
  --paper: #FFFFFF;
  --ground: #EEF1F6;
  --green: #2E8B57;
  --red: #C0392B;
  --amber: #D4A017;
  font-family: "IBM Plex Sans", "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--ground); }
a { color: var(--navy-2); }
button, select, input { font: inherit; }
:focus-visible { outline: 3px solid #6EA8FF; outline-offset: 2px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%); }
.login-card { width: 100%; max-width: 380px; background: var(--paper); border-radius: 10px; padding: 32px 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; color: var(--navy); }
.login-card p.sub { margin: 0 0 24px; color: var(--muted); }
.login-card label { display: block; font-size: .9rem; margin: 14px 0 6px; color: var(--muted); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.btn { display: inline-block; border: 0; border-radius: 6px; padding: 10px 16px; cursor: pointer;
  background: var(--navy); color: #fff; }
.btn.full { width: 100%; margin-top: 22px; padding: 12px; }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }
.error { background: #FCEBEA; color: var(--red); padding: 10px 12px; border-radius: 6px; font-size: .9rem; }

/* Dashboard shell */
.topbar { background: var(--navy); color: #fff; padding: 14px 24px;
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand strong { font-size: 1.5rem; letter-spacing: .5px; }
.brand span { opacity: .8; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.controls select { padding: 8px 10px; border-radius: 6px; border: 0; min-width: 180px; }
main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.period { color: var(--muted); margin: 0 0 18px; }
.section { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 20px; }
.section > h2 { margin: 0; padding: 10px 16px; font-size: 1rem; color: #fff; background: var(--navy-2);
  border-radius: 8px 8px 0 0; }
.section .body { padding: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.kpi .v { font-size: 1.6rem; font-weight: 600; color: var(--navy); }
.kpi .l { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 0 0 8px; }
pre.raw { white-space: pre-wrap; font-size: .8rem; max-height: 420px; overflow: auto; background: var(--ground);
  padding: 12px; border-radius: 6px; }

@media print {
  @page { size: A3 landscape; margin: 10mm; }
  body { background: #fff; }
  .controls, .no-print { display: none !important; }
  .topbar, .section > h2 { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .section { break-inside: avoid; }
  main { max-width: none; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Phase 3 dashboard ---------- */
.lbl { opacity: .8; }
form.inline { margin: 0; }
.secnav { position: sticky; top: 0; z-index: 5; background: var(--paper); border-bottom: 1px solid var(--line);
  display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; }
.secnav a { padding: 12px 12px; white-space: nowrap; text-decoration: none; color: var(--muted);
  border-bottom: 3px solid transparent; font-size: .92rem; }
.secnav a:hover { color: var(--navy); }
.secnav a.on { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
section.section { scroll-margin-top: 56px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 20px; }
.grid2 > .section { margin-bottom: 0; }
.stack { display: grid; gap: 20px; margin-bottom: 20px; }
.kpi.good .v { color: var(--green); }
.kpi.bad .v { color: var(--red); }
.kpi.warn .v { color: #B07D00; }
.kpi .s { font-size: .8rem; color: var(--muted); }
.chartbox { position: relative; height: 280px; }
.chartbox.sm { height: 220px; }
.chartbox.tall { height: 520px; }
.hero { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: center; }
.timeline { margin-top: 14px; }
.timeline .bar { height: 12px; border-radius: 6px; background: var(--ground); overflow: hidden; }
.timeline .bar span { display: block; height: 100%; background: var(--navy-2); }
.timeline .ends { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.pkgs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.pkg { border: 1px solid var(--line); border-radius: 6px; padding: 14px; }
.pkg h3 { margin: 0 0 4px; font-size: 1rem; }
.pkg .meta { color: var(--muted); font-size: .85rem; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.Finished, .pill.Closed { background: #E3F3EA; color: var(--green); }
.pill.In-progress, .pill.Open { background: #E6EEFB; color: var(--navy-2); }
.pill.Upcoming { background: #F1F2F5; color: var(--muted); }
.pill.Low { background: #DFF0D8; color: #2D6A2D; }
.pill.Medium { background: #FFF4C2; color: #7A5C00; }
.pill.High { background: #FFE0C7; color: #9A4A00; }
.pill.Extreme { background: #F8D2CF; color: #9B1C12; }
.meter { height: 8px; background: var(--ground); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.meter span { display: block; height: 100%; background: var(--green); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: var(--ground); font-weight: 600; color: var(--ink); position: sticky; top: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 600; background: var(--ground); }
.scroll { overflow-x: auto; }
.scroll.y { max-height: 420px; overflow-y: auto; }
.zones { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.zone { border: 1px solid var(--line); border-radius: 6px; padding: 14px; background: var(--paper); cursor: pointer; text-align: left; }
.zone:hover { border-color: var(--navy-2); }
.zone[aria-expanded="true"] { border-color: var(--navy); box-shadow: inset 0 0 0 1px var(--navy); }
.zone h3 { margin: 0; font-size: 1rem; }
.zone .big { font-size: 1.5rem; font-weight: 600; color: var(--navy); margin: 6px 0 2px; }
.disc { display: grid; grid-template-columns: 48px 1fr 44px; gap: 6px; align-items: center; font-size: .8rem; margin-top: 5px; }
.disc .track { height: 6px; background: var(--ground); border-radius: 3px; overflow: hidden; }
.disc .track span { display: block; height: 100%; background: var(--navy-2); }
.zone .more { display: none; margin-top: 10px; font-size: .85rem; border-top: 1px solid var(--line); padding-top: 8px; }
.zone[aria-expanded="true"] .more { display: block; }
.zone .more p { margin: 4px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; align-items: center; }
.filters select, .filters input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; }
.filters .count { color: var(--muted); font-size: .88rem; margin-left: auto; }
.matrix { display: grid; grid-template-columns: 110px repeat(5, 1fr); gap: 3px; font-size: .8rem; }
.matrix .h { padding: 6px; color: var(--muted); text-align: center; }
.matrix .rowh { padding: 6px; color: var(--muted); display: flex; align-items: center; }
.matrix button { border: 0; border-radius: 4px; padding: 12px 4px; font-weight: 600; cursor: pointer; font-size: .95rem; }
.matrix button.sel { outline: 3px solid var(--navy); outline-offset: -3px; }
.m-Low { background: #CFE8C6; } .m-Medium { background: #FFE98F; } .m-High { background: #FFC48F; } .m-Extreme { background: #F2A39C; }
.note { font-size: .82rem; color: var(--muted); margin: 8px 0 0; }
@media (max-width: 720px) { .hero { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; } }
@media print {
  .secnav, .filters { display: none !important; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .scroll.y { max-height: none; overflow: visible; }
  .zone .more { display: block; }
  .pill, .matrix button, .meter span, .disc .track span, .timeline .bar span, .tbl th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.grid2 { scroll-margin-top: 56px; }

/* ---------- Site plan with live zone labels ---------- */
.siteplan { position: relative; width: 100%; max-width: 1100px; margin: 0 auto 8px; aspect-ratio: 1.495; background: #FAFCFE; border-radius: 6px; }
.siteplan img { position: absolute; left: 6%; top: 17%; width: 88%; height: 66%; object-fit: contain; }
.siteplan svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.siteplan line { stroke: #8B1E2D; stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.siteplan circle { fill: #8B1E2D; }
.pin { position: absolute; transform: translate(-50%, -50%); background: #fff; border: 1.5px solid #8B1E2D; border-radius: 6px;
  padding: .35em .8em; text-align: center; text-decoration: none; color: var(--ink); line-height: 1.15; white-space: nowrap;
  font-size: clamp(9px, 1.05vw, 14px); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.pin:hover { background: #FBF3F4; }
.pin-l { display: block; font-size: .78em; color: var(--muted); }
.pin-v { display: block; font-size: 1.55em; font-weight: 700; }
.siteplan-list { display: none; }
@media (max-width: 700px) {
  .siteplan { aspect-ratio: 2; }
  .siteplan img { left: 0; top: 0; width: 100%; height: 100%; }
  .siteplan svg, .pin { display: none; }
  .siteplan-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
  .siteplan-list a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid #8B1E2D;
    border-radius: 6px; text-decoration: none; color: var(--ink); font-size: .85rem; }
}

/* Zone cards: site progress only */
.zone { cursor: default; scroll-margin-top: 64px; }
.zone p { margin: 6px 0; font-size: .9rem; line-height: 1.4; }
.zone:target { border-color: #8B1E2D; box-shadow: inset 0 0 0 1px #8B1E2D; }

/* ---------- Shop drawings grid laid out like the site plan ---------- */
.sdgrid { display: grid; gap: 6px; grid-template-columns: 1fr 1fr 1fr .85fr;
  grid-template-areas: "z1 z3 z5 z7" "z1 z3 z5 z7" "z1 z3 z5 z8" "z2 z4 z6 z8" "z2 z4 z6 z9" "z2 z4 z6 z9"; }
.sd-Z1 { grid-area: z1; } .sd-Z2 { grid-area: z2; } .sd-Z3 { grid-area: z3; } .sd-Z4 { grid-area: z4; } .sd-Z5 { grid-area: z5; }
.sd-Z6 { grid-area: z6; } .sd-Z7 { grid-area: z7; } .sd-Z8 { grid-area: z8; } .sd-Z9 { grid-area: z9; }
.sd { background: #ECEEF2; border: 2px dashed #3D4E7A; border-radius: 3px; padding: 12px 10px; color: var(--zc, var(--navy));
  display: flex; flex-direction: column; justify-content: space-between; gap: 12px; text-align: center; min-height: 92px; }
.sd h3 { margin: 0; font-size: .95rem; color: var(--ink); letter-spacing: .2px; }
.sd-disc { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.sd-disc b { display: block; font-size: 1.05rem; font-weight: 500; }
.sd-disc span { font-size: .8rem; }
.sd-tot b { display: block; font-size: 1.9rem; font-weight: 500; }
.sd-tot span { font-size: .8rem; }
.sd-Z7, .sd-Z8, .sd-Z9 { gap: 6px; padding: 8px; }
.sd-Z7 .sd-disc, .sd-Z8 .sd-disc, .sd-Z9 .sd-disc { gap: 10px; }
.sd-Z7 .sd-disc b, .sd-Z8 .sd-disc b, .sd-Z9 .sd-disc b { font-size: .85rem; }
.sd-Z7 .sd-tot b, .sd-Z8 .sd-tot b, .sd-Z9 .sd-tot b { font-size: 1.3rem; }
@media (max-width: 760px) {
  .sdgrid { grid-template-columns: 1fr 1fr; grid-template-areas: none; }
  .sd { grid-area: auto !important; }
  .sd-Z1 { order: 1; } .sd-Z2 { order: 2; } .sd-Z3 { order: 3; } .sd-Z4 { order: 4; } .sd-Z5 { order: 5; }
  .sd-Z6 { order: 6; } .sd-Z7 { order: 7; } .sd-Z8 { order: 8; } .sd-Z9 { order: 9; }
  .sd-Z7 .sd-disc b, .sd-Z8 .sd-disc b, .sd-Z9 .sd-disc b { font-size: 1.05rem; }
  .sd-Z7 .sd-tot b, .sd-Z8 .sd-tot b, .sd-Z9 .sd-tot b { font-size: 1.9rem; }
}
@media print {
  .siteplan line, .siteplan circle, .pin, .sd { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sdgrid, .siteplan { break-inside: avoid; }
}
