:root {
  --bg: #f2f5f7;
  --panel: #ffffff;
  --ink: #1b2a36;
  --muted: #64748b;
  --line: #dde5ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #ccfbf1;
  --warn: #b91c1c;
  --warn-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --sidebar: #0e1f2b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 35, 50, .08), 0 4px 14px rgba(15, 35, 50, .05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; background: var(--bg); color: var(--ink);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 14px;
}
body.logged-out #sidebar { display: none; }
body.logged-out #main { min-height: 100vh; max-width: none; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(430px, calc(100vw - 32px)); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 60px rgba(15, 42, 52, .16); padding: 28px; }
.login-card h1 { margin: 0 0 6px; }
.login-card .brand-mark { margin-bottom: 16px; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 218px; min-width: 218px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0f766e); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; }
.brand-name { font-weight: 700; color: #fff; font-size: 14.5px; }
.brand-sub { font-size: 11px; color: #7da2b3; }
#sidebar nav { display: flex; flex-direction: column; padding: 12px 8px; gap: 2px; flex: 1; }
#sidebar nav a { color: #b9c8d2; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; font-size: 13.5px; }
#sidebar nav a .ico { width: 18px; text-align: center; }
#sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
#sidebar nav a.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-foot { padding: 14px 16px; font-size: 10.5px; color: #5f7a89; border-top: 1px solid rgba(255,255,255,.08); line-height: 1.7; }

/* ---------- main ---------- */
#main { flex: 1; padding: 26px 32px 60px; max-width: 1480px; min-width: 0; }
.loading { color: var(--muted); padding: 40px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: 13px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- components ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { margin: 0 0 12px; font-size: 14px; color: var(--ink); }
.grid { display: grid; gap: 16px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 750; letter-spacing: -0.5px; }
.stat .l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.stat.ok .v { color: var(--accent); }

button, .btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.ghost, .btn.ghost { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
button.ghost:hover { background: var(--accent-soft); }
button.subtle { background: #eef2f5; color: var(--ink); }
button.subtle:hover { background: #e2e8ed; }
button.sm { padding: 4px 10px; font-size: 12px; }
input, select, textarea {
  font-family: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
table.data th { background: #f7fafb; text-align: left; padding: 10px 12px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); border-bottom: 1px solid var(--line); }
table.data td { padding: 10px 12px; border-bottom: 1px solid #edf2f5; font-size: 13px; vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover { background: #f4fbfa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2.5px 9px; border-radius: 99px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.badge.LPST { background: #fde8e8; color: #9b1c1c; }
.badge.TRRP { background: #e1effe; color: #1e429f; }
.badge.OCP { background: #fdf6b2; color: #8e4b10; }
.badge.VCP { background: #e1fcef; color: #046c4e; }
.badge.DCRP { background: #edebfe; color: #5521b5; }
.badge.SPILL { background: #ffe4e6; color: #9f1239; }
.badge.status-Active { background: var(--ok-soft); color: var(--ok); }
.badge.status-Monitoring { background: var(--amber-soft); color: var(--amber); }
.badge.status-Closed { background: #e5e7eb; color: #4b5563; }
.badge.status-Inactive { background: #e5e7eb; color: #6b7280; }
.badge.cat { background: #eef2f5; color: #475569; }
.badge.overdue { background: var(--warn-soft); color: var(--warn); }

/* exceedance highlighting */
td.exceed { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
td.nd { color: #94a3b8; }

/* ---------- stage tracker ---------- */
.stages { display: flex; gap: 0; margin: 14px 0 4px; flex-wrap: wrap; row-gap: 8px; }
.stage-step { display: flex; align-items: center; font-size: 11px; color: var(--muted); }
.stage-step .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--muted); cursor: pointer; }
.stage-step.done .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.stage-step.current .dot { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px rgba(15,118,110,.15); }
.stage-step .bar { width: 26px; height: 2px; background: var(--line); margin: 0 2px; }
.stage-step.done .bar { background: var(--accent); }
.stage-step .lbl { display: none; }
.stage-label { font-size: 12.5px; color: var(--accent-dark); font-weight: 650; margin-top: 6px; }

/* ---------- site detail ---------- */
.site-head { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px; }
.site-head h1 { margin: 0 0 4px; font-size: 21px; }
.site-meta { color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 9px 16px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--accent-dark); }

/* dropzone */
.dropzone {
  border: 2px dashed #9fb8c4; border-radius: var(--radius); padding: 36px 20px; text-align: center;
  color: var(--muted); background: #fbfdfe; cursor: pointer; transition: all .15s; margin-bottom: 18px;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.dropzone .big { font-size: 15px; font-weight: 650; color: var(--ink); margin-bottom: 4px; }
.dropzone .types { font-size: 11.5px; margin-top: 8px; }

.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item::before { content: ''; position: absolute; left: -22.5px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--accent); }
.tl-item.src-artifact::before { background: #2563eb; box-shadow: 0 0 0 2px #2563eb; }
.tl-item.src-system::before { background: #64748b; box-shadow: 0 0 0 2px #64748b; }
.tl-date { font-size: 11.5px; color: var(--muted); }
.tl-title { font-weight: 650; font-size: 13.5px; margin: 1px 0; }
.tl-desc { font-size: 12.5px; color: var(--muted); }

/* report catalog */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.report-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.report-card h4 { margin: 0 0 6px; font-size: 13.5px; }
.report-card p { margin: 0 0 12px; font-size: 12px; color: var(--muted); flex: 1; line-height: 1.5; }
.report-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 6px; max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fbfdfe; }
.analyte-grid { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
.check { display: flex; align-items: center; gap: 7px; margin: 0; color: var(--ink); font-weight: 500; font-size: 12.5px; }
.check input { width: auto; }

/* map */
.map-box { height: 320px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.map-box-lg { height: calc(100vh - 170px); min-height: 420px; }

/* modal */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(10, 25, 35, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 1000; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 640px; max-width: 100%; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast { background: #0e1f2b; color: #fff; padding: 11px 16px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow); max-width: 420px; animation: slide .2s ease-out; }
.toast.err { background: var(--warn); }
@keyframes slide { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.empty { color: var(--muted); padding: 26px; text-align: center; font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.kv-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv-grid dt { color: var(--muted); font-weight: 600; }
.kv-grid dd { margin: 0; }
.chart-box { height: 280px; }

/* sortable table headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent-dark); }

/* screening bar */
.screening-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #f0fdfa; border: 1px solid #99f6e4; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }

/* recommendations */
.reco { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid #eef2f5; font-size: 13px; color: var(--ink); }
.reco:last-child { border-bottom: none; }
.badge.prio-High { background: var(--warn-soft); color: var(--warn); }
.badge.prio-Medium { background: var(--amber-soft); color: var(--amber); }
.badge.prio-Low { background: #e5e7eb; color: #4b5563; }

/* geology */
.pick { display: inline-flex; gap: 5px; align-items: center; background: #eef2f5; border-radius: 7px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; }
.pick input { width: auto; }
.pick-dim { opacity: .5; }
.uscs-chip { display: inline-block; padding: 1px 8px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); font-size: 11px; font-weight: 700; color: #2f2a20; }
