/* ================================================================== tokens
   Light is the base; dark overrides the same tokens (system via media query,
   explicit via [data-theme]). Only tokens change between themes.            */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9ecf1;
  --border: #e2e5ea;
  --border-strong: #c9ced6;
  --text: #171a1f;
  --text-2: #4b5260;
  --text-3: #7d8593;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --on-primary: #ffffff;
  --accent: #ea580c;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --warn-line: #f59e0b;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info-soft: #e0e7ff;
  --calc-bg: #f4f6fa;
  --sheet-bg: #ffffff;
  --sheet-line: #b9bfc9;
  --sheet-text: #0f1115;
  --focus: rgba(37, 99, 235, .35);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px -12px rgba(16, 24, 40, .25);
  --radius: 10px;
  --radius-sm: 6px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-sheet: "Times New Roman", Tinos, Times, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --surface-3: #262c36;
    --border: #2a303a; --border-strong: #3a414d;
    --text: #e8ebf0; --text-2: #aeb5c0; --text-3: #7f8794;
    --primary: #4f83f1; --primary-hover: #6b97f5; --primary-soft: #1b2a4a; --on-primary: #ffffff;
    --accent: #fb923c;
    --ok: #4ade80; --ok-soft: #14351f; --warn: #fbbf24; --warn-soft: #3a2c0a; --warn-line: #d97706;
    --bad: #f87171; --bad-soft: #3b1515; --info-soft: #1e2440;
    --calc-bg: #1c2129; --sheet-bg: #1a1f26; --sheet-line: #414957; --sheet-text: #e8ebf0;
    --focus: rgba(79, 131, 241, .45);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --surface-3: #262c36;
  --border: #2a303a; --border-strong: #3a414d;
  --text: #e8ebf0; --text-2: #aeb5c0; --text-3: #7f8794;
  --primary: #4f83f1; --primary-hover: #6b97f5; --primary-soft: #1b2a4a; --on-primary: #ffffff;
  --accent: #fb923c;
  --ok: #4ade80; --ok-soft: #14351f; --warn: #fbbf24; --warn-soft: #3a2c0a; --warn-line: #d97706;
  --bad: #f87171; --bad-soft: #3b1515; --info-soft: #1e2440;
  --calc-bg: #1c2129; --sheet-bg: #1a1f26; --sheet-line: #414957; --sheet-text: #e8ebf0;
  --focus: rgba(79, 131, 241, .45);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ================================================================== base */
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* keep `hidden` authoritative even where a rule sets display */
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; min-height: 100vh; -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
h1, h2 { font-weight: 700; letter-spacing: -.01em; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 0 0 6px; }
.mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ================================================================== app bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  min-height: 60px; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.page-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 10px 24px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.ws-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ws-actions[hidden] { display: none; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 30; display: flex; flex-direction: column; }
.menu-list[hidden] { display: none; }
.menu-list button { text-align: left; font: 500 14px var(--font); color: var(--text); background: transparent; border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 12.5px; color: var(--text-3); }
.stepper { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 10px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 600; color: var(--text-3); }
.step-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; border: 1.5px solid var(--border-strong); color: var(--text-3); background: var(--surface); }
.step.is-active { color: var(--text); }
.step.is-active .step-num { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.step.is-done { color: var(--ok); }
.step.is-done .step-num { background: var(--ok-soft); border-color: transparent; color: var(--ok); font-size: 0; }
.step.is-done .step-num::after { content: "✓"; font-size: 12px; }
.step-line { width: 36px; height: 1.5px; background: var(--border-strong); }
.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.theme-toggle { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); margin-left: 6px; }
.theme-toggle button { border: 0; background: transparent; color: var(--text-3); width: 32px; height: 28px; border-radius: 5px; display: grid; place-items: center; cursor: pointer; }
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ================================================================== buttons */
.btn {
  font: 600 14.5px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 16px; line-height: 1.3; cursor: pointer; transition: background .12s, border-color .12s, color .12s, box-shadow .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; }
.btn-lg { font-size: 15.5px; padding: 11px 20px; }
.btn-sm { font-size: 13.5px; padding: 6px 12px; }
.btn[hidden] { display: none; }

.foot { padding: 28px 24px 40px; color: var(--text-3); font-size: 13px; text-align: center; }

/* ================================================================== step 1 */
#screen-1 { width: min(1400px, 100% - 48px); margin: 0 auto; padding: 40px 0 16px; }
.hero h1 { font-size: clamp(26px, 2.4vw, 34px); margin: 0 0 8px; }
.lede { max-width: 70ch; color: var(--text-2); margin: 0 0 28px; font-size: 16px; }
.lede strong { color: var(--text); font-weight: 600; }

.upload-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 16px; align-items: stretch; }
.dropzone {
  display: block; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; min-height: 200px;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dz-inner { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 28px; text-align: center; }
.dz-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); margin-bottom: 10px; }
.dz-title { font-size: 17px; font-weight: 600; }
.dz-sub { color: var(--text-3); font-size: 14px; }
.dz-sub em { font-style: normal; font-family: var(--mono); color: var(--text-2); }
.link { color: var(--primary); }
.sample-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; font-family: var(--font); color: var(--text);
  box-shadow: var(--shadow); transition: border-color .12s, transform .12s;
}
.sample-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.sample-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.sample-text { display: flex; flex-direction: column; gap: 2px; }
.sample-title { font-weight: 600; font-size: 15.5px; }
.sample-sub { font-size: 13px; color: var(--text-3); line-height: 1.4; }
.sample-arrow { color: var(--text-3); font-size: 18px; }

.error { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); border: 1px solid transparent; font-size: 14.5px; }

.summary { margin-top: 24px; padding: 20px 22px 18px; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }
.summary-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 16px; }
.summary-head h2 { font-family: var(--mono); font-size: 16px; margin: 0; font-weight: 500; }
.summary-grid { display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); gap: 28px; }
.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; font-size: 14px; align-content: start; }
.kv dt { color: var(--text-3); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding-top: 2px; }
.kv dd { margin: 0; color: var(--text); }
.summary-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.summary-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.summary-table th { text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 8px 10px; }
.summary-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.summary-table tr:last-child td { border-bottom: 0; }
.summary-table tbody tr:hover td { background: var(--surface-2); }
.summary-table td.mono { font-family: var(--mono); font-size: 13.5px; }
.summary-table small { color: var(--text-3); }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; margin-right: 6px; white-space: nowrap; }
.pill-labor { color: var(--primary); background: var(--primary-soft); }
.pill-equip { color: var(--accent); background: var(--warn-soft); }
.pill-ok { color: var(--ok); background: var(--ok-soft); }
.pill-warn { color: var(--warn); background: var(--warn-soft); }
.pill-bad { color: var(--bad); background: var(--bad-soft); }
.pill-idle { color: var(--text-2); background: var(--surface-3); }
.pill-misc { color: var(--primary); background: var(--info-soft); font-size: 11px; margin-left: 6px; }
.idle { color: var(--accent); }
.sources { margin: 14px 0 0; font-size: 13px; color: var(--text-3); font-family: var(--mono); }

.defaults { margin-top: 24px; padding: 20px 22px 22px; }
.defaults-top { margin: 0 0 18px; }
.gate-note { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 14.5px; }
.upload-grid.is-disabled .dropzone, .upload-grid.is-disabled .sample-card { opacity: .5; cursor: not-allowed; pointer-events: none; }
.field-county.is-required select { border-color: var(--warn-line); box-shadow: 0 0 0 3px var(--warn-soft); }
.defaults-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.defaults-title { font-size: 19px; margin: 0; }
.defaults-sub { margin: 4px 0 0; font-size: 14.5px; color: var(--text-2); max-width: 62ch; }
.defaults-actions { display: flex; align-items: center; gap: 10px; }
.saved { font-size: 13.5px; font-weight: 600; color: var(--ok); }
.saved[hidden] { display: none; }
.defaults-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.field-county { grid-column: 1 / -1; }
.field select, .field input {
  font: 500 15px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 11px; height: 40px;
}
.field select { max-width: 420px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.pctwrap { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 14px; color: var(--text-2); }
.pctwrap input { width: 100%; text-align: right; font-family: var(--mono); }
.field small { font-weight: 400; font-family: var(--mono); font-size: 13px; color: var(--text-3); line-height: 1.4; }


.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; margin: 36px 0 16px; padding-top: 24px; border-top: 1px solid var(--border); font-size: 14.5px; color: var(--text-2); }
.how-item { display: flex; gap: 12px; }
.how-n { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--surface-3); color: var(--text-2); }
.how strong { color: var(--text); }

/* ================================================================== step 2 */
#screen-2 { padding: 28px 24px 40px; width: min(1900px, 100%); margin: 0 auto; }
.ws-toolbar { margin: 0 0 16px; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.ws-h1 { font-size: 24px; margin: 0; }
.ws-hint { margin: 4px 0 0; color: var(--text-2); font-size: 15px; }

.sheet-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; padding-bottom: 12px; }
.sheet-scroll { overflow-x: auto; min-width: 0; }
.ws-side { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; padding: 14px 16px 16px; }
.ws-side-hint { margin: 0 0 10px; font-size: 13.5px; color: var(--text-3); }
.ws-flags { display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.4; }
.flag-group { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 8px 0 0; }
.flag { display: block; width: 100%; text-align: left; font: inherit; color: var(--text); cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius-sm); padding: 7px 9px; }
.flag.is-warn { background: var(--warn-soft); border-left-color: var(--warn-line); }
.flag:hover { border-color: var(--border-strong); }
.flag b { font-family: var(--mono); font-weight: 500; display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 2px; }
.flag-empty { color: var(--ok); font-size: 14px; }
.sheet tr.is-target td { background: var(--warn-soft); transition: background .3s; }
/* narrower than the sheet + panel: notes move above the sheet as a compact grid */
@media (max-width: 1600px) {
  .sheet-wrap { grid-template-columns: minmax(0, 1fr); }
  .ws-side { position: static; max-height: none; order: -1; }
  .ws-flags { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
  .flag-group { grid-column: 1 / -1; margin: 4px 0 0; }
}

/* ---- the Extra Work Bill form keeps its printed look, themed for dark */
.sheet {
  --cell-h: 22px;
  font-family: var(--font-sheet); font-size: 13px; line-height: 1.25; color: var(--sheet-text);
  background: var(--sheet-bg); width: 100%; min-width: 1180px; padding: 24px 28px 28px;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.sheet input, .sheet textarea, .sheet select { font: inherit; color: inherit; background: transparent; border: 0; width: 100%; padding: 2px 4px; outline: none; min-width: 0; }
.sheet input:focus, .sheet textarea:focus { background: var(--warn-soft); box-shadow: inset 0 0 0 1.5px var(--primary); }
.sheet input.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet input.ctr { text-align: center; }
.sheet .calc { text-align: right; background: var(--calc-bg); padding: 2px 5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet .warn { background: var(--warn-soft) !important; }
.sheet table { border-collapse: collapse; table-layout: fixed; width: 100%; }
.sheet td, .sheet th { border: 1px solid var(--sheet-line); padding: 0; height: var(--cell-h); vertical-align: middle; overflow: hidden; }
.sheet th { font-weight: normal; text-align: center; border-bottom: 2px solid var(--sheet-text); padding: 3px 3px; background: var(--calc-bg); line-height: 1.15; font-size: 12px; }
.sheet .nob td, .sheet td.nob { border: 0; }

.ws-title-row { display: grid; grid-template-columns: 1fr 300px; align-items: start; gap: 24px; }
.ws-title { font-weight: bold; font-size: 17px; letter-spacing: .01em; }
.ws-subtitle { font-style: italic; margin-top: 2px; }
.ws-ids { display: grid; grid-template-columns: 120px 1fr; gap: 4px 8px; font-size: 12px; align-items: center; }
.ws-ids .field { border-bottom: 1px solid var(--sheet-text); display: block; }
.ws-ids .field input { text-align: center; font-family: var(--mono); font-size: 12px; border: 0; border-radius: 0; padding: 2px 4px; background: transparent; height: auto; }
.ws-meta { display: grid; grid-template-columns: minmax(0, 1fr) 170px 320px; gap: 20px; margin: 14px 0 16px; align-items: start; }
.ws-fields { display: grid; grid-template-columns: 150px 1fr; gap: 6px 8px; align-items: start; }
.ws-fields .lbl { padding-top: 2px; }
.ws-fields .field { border-bottom: 1px solid var(--sheet-text); display: block; font-weight: normal; color: inherit; }
.ws-fields .field input { border: 0; border-radius: 0; padding: 2px 4px; background: transparent; font: inherit; height: auto; }
.ws-fields textarea { resize: vertical; min-height: 34px; line-height: 1.25; }
.ws-rates { display: grid; grid-template-columns: 64px 1fr; gap: 3px 8px; align-items: center; font-size: 12px; }
.ws-rates .pct { border: 1px solid var(--sheet-line); display: flex; align-items: center; }
.ws-rates .pct input { text-align: center; font-family: var(--mono); }
.ws-rates label { display: flex; gap: 6px; align-items: center; }
.ws-totals { display: grid; grid-template-columns: 1fr 130px; gap: 4px 10px; align-items: center; font-size: 12px; }
.ws-totals .lbl { text-align: right; }
.ws-totals .calc { border-bottom: 1px solid var(--sheet-text); font-size: 13px; }
.ws-totals .grand { font-weight: bold; font-size: 15px; border: 1.5px solid var(--sheet-text); background: var(--sheet-bg); font-family: var(--mono); }
.ws-totals .grand-lbl { font-weight: bold; }
.ws-two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.ws-block-title { font-family: var(--font); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 0 0 4px; display: flex; justify-content: space-between; align-items: center; }
.ws-block-title .btn { font-size: 12px; padding: 2px 9px; }
.ws-foot { display: grid; grid-template-columns: 1fr 150px; gap: 3px 8px; margin-top: 6px; justify-items: end; font-size: 12.5px; align-items: center; }
.ws-foot .calc { width: 100%; border-bottom: 1px solid var(--sheet-text); }
.ws-foot .pct { display: inline-flex; align-items: center; gap: 4px; }
.ws-foot .pct input { width: 52px; border: 1px solid var(--sheet-line); text-align: center; font-family: var(--mono); }
.ws-note { font-size: 11.5px; font-style: italic; margin-top: 6px; }
.ws-materials { margin-top: 16px; }
.ws-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; margin-top: 16px; align-items: end; }
.ws-checks { display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; font-size: 12.5px; }
.ws-checks .yn { display: inline-flex; gap: 12px; }
.ws-checks label { display: inline-flex; gap: 4px; align-items: center; }
.ws-sign { display: grid; grid-template-columns: 1fr 110px; gap: 30px; margin-top: 28px; font-size: 12.5px; }
.ws-sign .line { border-top: 1px solid var(--sheet-text); padding-top: 2px; }
.rowtag { color: var(--text-3); font-size: 9px; text-align: center; font-family: var(--mono); }
.pick-cell { width: 26px; text-align: center; }
.pick-btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--primary); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 5px; border-radius: 4px; }
.pick-btn:hover { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.pick-btn.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }

/* ================================================================== sign in */
.auth-screen { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(460px, 100%); padding: 28px 28px 30px; }
.auth-title { font-size: 24px; margin: 0 0 6px; word-break: break-all; }
.auth-sub { margin: 0 0 18px; color: var(--text-2); font-size: 15px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .btn { align-self: stretch; }
.auth-error { margin: 0 0 4px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.linkbtn { border: 0; background: none; color: var(--primary); font: 500 14px var(--font); cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }
.auth-dev { margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-family: var(--mono); font-size: 14px; }

/* ================================================================== app bar nav + user */
.topbar-nav { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); justify-self: start; }
.topbar-nav[hidden] { display: none; }
.navlink { border: 0; background: transparent; color: var(--text-2); font: 600 14px var(--font); padding: 5px 12px; border-radius: 5px; cursor: pointer; }
.navlink:hover { color: var(--text); }
.navlink.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.user-menu { display: inline-flex; align-items: center; gap: 8px; margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-menu[hidden] { display: none; }
.user-email { font-size: 13.5px; color: var(--text-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-save.is-saved { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

/* ================================================================== saved EWBs */
#screen-3 { padding: 28px 24px 40px; width: min(1500px, 100%); margin: 0 auto; }
.saved-head { margin-bottom: 16px; }
.saved-filters { display: grid; grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(140px, 1fr)) auto; gap: 14px; align-items: end; padding: 16px 18px; margin-bottom: 16px; }
.field-search { grid-column: span 1; }
.saved-actions { display: flex; align-items: flex-end; }
.saved-table-wrap { overflow-x: auto; }
.saved-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.saved-table th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 10px 14px; white-space: nowrap; }
.saved-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.saved-table tbody tr { cursor: pointer; }
.saved-table tbody tr:hover td { background: var(--surface-2); }
.saved-table td small { color: var(--text-3); font-size: 12.5px; }
.saved-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.saved-table td.mono { font-family: var(--mono); font-size: 13.5px; }
.saved-table .row-actions { text-align: right; white-space: nowrap; }
.saved-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text-3); font-size: 13.5px; }
@media (max-width: 1100px) { .saved-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .field-search, .saved-actions { grid-column: 1 / -1; } }

/* ================================================================== setup, projects, dashboard */
.setup { margin: 0 0 18px; padding: 20px 22px 20px; }
.setup-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.setup-grid { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr); gap: 16px; }
.project-summary { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 12px; font-size: 14px; color: var(--text-2); }
.project-summary b { color: var(--text); font-weight: 600; margin-right: 4px; }
.project-summary small { color: var(--text-3); }
.warn-text { color: var(--warn); }
.ws-tabs { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.ws-tabs[hidden] { display: none; }
.ws-tab { border: 0; background: transparent; color: var(--text-2); font: 600 14px var(--font); padding: 6px 12px; border-radius: 5px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.ws-tab.is-active { background: var(--primary-soft); color: var(--primary); }
.ws-tab .pill { margin: 0; }
.projects-head, .saved-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
#screen-projects, #screen-dash { padding: 28px 24px 40px; width: min(1500px, 100%); margin: 0 auto; }
.projects-table td.mono { font-size: 13px; }
.projects-table tr.is-inactive td { color: var(--text-3); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--text-2); cursor: pointer; text-transform: none; letter-spacing: 0; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }
.empty { color: var(--text-3); text-align: center; padding: 18px 12px !important; }
.pm-panel { width: min(900px, 100%); }
.pm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.pm-span2 { grid-column: span 2; }
.pm-pcts { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.pm-section { margin: 16px 0 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.pm-items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.pm-item { display: grid; grid-template-columns: 120px 120px 1fr auto; gap: 8px; }
.pm-item input { font: 500 14px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; }
.pm-share { margin-top: 16px; }
.pm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dash-filters { grid-template-columns: minmax(220px, 1fr) minmax(160px, 1fr) minmax(160px, 1fr) auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { padding: 16px 18px; }
.stat-k { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.stat-v { font-family: var(--mono); font-size: 24px; font-weight: 600; margin-top: 4px; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.dash-panel { padding: 16px 18px 18px; overflow-x: auto; }
.dash-panel h3 { margin: 0 0 10px; font-size: 15px; }
.dash-wide { grid-column: 1 / -1; }
.dash-table td, .dash-table th { padding: 8px 10px; }
.barcell { width: 26%; }
.bar { display: block; height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.months { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding: 8px 4px 0; overflow-x: auto; }
.month { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 64px; flex: 1; }
.month-bar { width: 60%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 4px; }
.month-l { font-size: 12px; color: var(--text-3); margin-top: 6px; white-space: nowrap; }
.month-v { font-size: 11.5px; color: var(--text-2); }
@media (max-width: 1000px) { .dash-grid, .setup-grid { grid-template-columns: 1fr; } .pm-grid, .pm-pcts { grid-template-columns: repeat(2, minmax(0, 1fr)); } .pm-item { grid-template-columns: 1fr 1fr; } }

/* ================================================================== picker */
.picker { position: fixed; inset: 0; z-index: 20; background: rgba(15, 18, 22, .55); display: grid; place-items: start center; padding: 6vh 16px; overflow: auto; backdrop-filter: blur(2px); }
.picker[hidden] { display: none; }
.picker-panel { width: min(960px, 100%); padding: 18px 20px 20px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.picker-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 10px; }
.picker-tools { display: flex; gap: 8px; align-items: center; }
.picker-area { font: 500 14px var(--font); color: var(--text); border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; padding: 5px 8px; }
.picker-area[hidden] { display: none; }
.picker-row-label { font-family: var(--mono); font-size: 14px; }
.picker-q { font: 500 16px var(--font); color: var(--text); padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); width: 100%; margin-bottom: 10px; }
.picker-q:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.picker-results { overflow: auto; border-top: 1px solid var(--border); }
.picker-cls { padding: 12px 8px 6px; font-size: 14.5px; }
.picker-cls small { color: var(--text-3); font-family: var(--mono); margin-left: 6px; }
.picker-cls-text { font-size: 13.5px; color: var(--text-2); margin-top: 3px; line-height: 1.35; }
.picker-row { display: grid; grid-template-columns: 140px 1fr 100px; gap: 12px; width: 100%; text-align: left; font: 14.5px var(--font); background: var(--surface); border: 1px solid var(--border); border-top: 0; padding: 7px 8px; cursor: pointer; color: var(--text); }
.picker-row:first-of-type { border-top: 1px solid var(--border); }
.picker-row:hover { background: var(--primary-soft); }
.picker-row .mono { font-family: var(--mono); }
.picker-row span:last-child { text-align: right; }
.picker-row small { color: var(--text-3); }
.picker-empty { color: var(--text-3); padding: 16px 8px; font-size: 14.5px; }

/* ================================================================== print */
@page { size: landscape; margin: 0.35in; }
@media print {
  :root, :root[data-theme="dark"] { --sheet-bg: #fff; --sheet-text: #000; --sheet-line: #999; --calc-bg: #fff; --warn-soft: #fff; }
  body { background: #fff; }
  .chrome, .topbar, .page-toolbar, .foot, .ws-toolbar, .ws-side, .picker, .pick-cell, .rowtag, .ws-block-title .btn, #screen-3, #screen-auth, #screen-dash, #screen-projects { display: none !important; }
  #screen-2 { padding: 0; }
  #screen-2[hidden] { display: none; }
  .sheet-wrap { display: block; overflow: visible; }
  .sheet-scroll { overflow: visible; }
  .sheet { box-shadow: none; border: 0; border-radius: 0; width: 100%; min-width: 0; padding: 0; font-size: 10px; color: #000; --cell-h: 18px; }
  .sheet input, .sheet textarea { background: transparent !important; box-shadow: none !important; }
  .ws-block-title { color: #000; }
}

@media (max-width: 1100px) {
  .topbar-actions { flex-wrap: wrap; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; padding: 10px 16px; }
  .topbar-actions { justify-content: flex-start; }
  #screen-1 { width: min(1400px, 100% - 32px); padding-top: 24px; }
  #screen-2 { padding: 20px 16px 32px; }
  .upload-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-head, .defaults-head { flex-direction: column; align-items: stretch; }
}
