/* Project Solar Operations Portal — design tokens & components
   Brand: Project Solar green #245C48 / gold #F2B33D (PSUK pack jurisdictions.json theme; TODO(brand): confirm against the official logo pack). */

:root {
  --bg: #f6f5f3;
  --panel: #ffffff;
  --panel-2: #fbfaf9;
  --ink: #17181a;
  --ink-2: #3c3f42;
  --muted: #6a6e72;
  --faint: #9aa0a5;
  --line: #e7e5e1;
  --line-2: #f0eeea;
  --accent: #245C48;
  --accent-hover: #1C4A3A;
  --accent-soft: #e9f2ee;
  --sidebar: #131315;
  --sidebar-ink: #b9bcc0;
  --good: #1a7f37;      --good-bg: #e8f3ec;
  --warn: #9a6700;      --warn-bg: #fff4d5;
  --danger: #c62828;    --danger-bg: #fdecea;
  --info: #0b63ce;      --info-bg: #e9f1fc;
  --hold: #5f6368;      --hold-bg: #f1f3f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23,24,26,.05), 0 4px 16px rgba(23,24,26,.05);
  --shadow-lg: 0 8px 40px rgba(23,24,26,.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================= login ============================= */
#login {
  min-height: 100vh; display: none; align-items: stretch;
  background: var(--sidebar);
}
#login.show { display: flex; }
.login-brand {
  flex: 1.2; display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px 56px; color: #c8cbd0;
  background:
    radial-gradient(1200px 500px at -10% 110%, rgba(254,82,0,.16), transparent 60%),
    #131315;
}
.login-brand img { height: 40px; align-self: flex-start; }
.login-brand h2 { color: #fff; font-size: 28px; font-weight: 600; max-width: 420px; line-height: 1.3; }
.login-brand .foot { font-size: 12.5px; color: #83878c; }
.login-side {
  flex: 1; background: var(--bg); display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.login-card { width: 360px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); margin: 0 0 26px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 12px; }
@media (max-width: 860px) { .login-brand { display: none; } }

/* ============================= shell ============================= */
#app { display: none; min-height: 100vh; }
#app.show { display: block; }
.shell { display: flex; min-height: 100vh; }

nav.side {
  width: 224px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 20px 0 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
nav.side .logo { padding: 2px 22px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
nav.side .logo img { height: 26px; display: block; }
nav.side .logo img.mark { display: none; height: 30px; }
nav.side .sec {
  padding: 18px 22px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: #6c7075;
}
nav.side a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 22px; color: inherit; text-decoration: none; font-weight: 500; font-size: 13.5px;
  border-left: 3px solid transparent;
}
nav.side a:hover { color: #fff; text-decoration: none; }
nav.side a.active { color: #fff; background: rgba(255,255,255,.07); border-left-color: var(--accent); }
nav.side .badge-n {
  margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 700; padding: 1px 7px;
}
nav.side .spacer { flex: 1; }
nav.side .env { padding: 10px 22px; font-size: 11.5px; color: #6c7075; }

main { flex: 1; min-width: 0; padding: 26px 34px 60px; max-width: 1340px; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.topbar h1 { font-size: 21px; }
.topbar .crumb { color: var(--muted); font-size: 13px; margin-top: 3px; }
.userbox { position: relative; }
.userbtn {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 24px; padding: 6px 14px 6px 6px; cursor: pointer; font: inherit;
}
.userbtn .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--sidebar); color: #fff;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
}
.userbtn .who { text-align: left; line-height: 1.15; }
.userbtn .who b { display: block; font-size: 13px; }
.userbtn .who span { font-size: 11.5px; color: var(--muted); text-transform: capitalize; }
.usermenu {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 200px; z-index: 40; display: none;
  overflow: hidden;
}
.usermenu.open { display: block; }
.usermenu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 16px;
  font: inherit; cursor: pointer; color: var(--ink);
}
.usermenu button:hover { background: var(--panel-2); }

/* ============================= building blocks ============================= */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 14px; box-shadow: var(--shadow); cursor: default;
}
.tile.click { cursor: pointer; }
.tile.click:hover { border-color: var(--faint); }
.tile .k { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.tile .v { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.tile .d { font-size: 12px; color: var(--muted); margin-top: 7px; }
.tile .v .unit { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.tile.alert .v { color: var(--danger); }
.tile.ok .v { color: var(--good); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.card .card-h {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line-2);
}
.card .card-h h3 { font-size: 14.5px; }
.card .card-h .hint { font-size: 12.5px; color: var(--muted); }
.card .card-b { padding: 16px 18px; }

.toolrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolrow .grow { flex: 1; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel-2); white-space: nowrap;
}
table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr.rowlink { cursor: pointer; }
table.grid tbody tr.rowlink:hover { background: #fcf9f7; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 12.5px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 20px; padding: 3px 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.p-info   { background: var(--info-bg);   color: var(--info); }
.pill.p-warn   { background: var(--warn-bg);   color: var(--warn); }
.pill.p-danger { background: var(--danger-bg); color: var(--danger); }
.pill.p-good   { background: var(--good-bg);   color: var(--good); }
.pill.p-hold   { background: var(--hold-bg);   color: var(--hold); }
.pill.p-plain  { background: var(--line-2);    color: var(--ink-2); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 6px 14px;
  cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.chip:hover { border-color: var(--faint); }
.chip.active { background: var(--sidebar); color: #fff; border-color: var(--sidebar); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 0; border-radius: 8px;
  padding: 9px 16px; font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer;
  transition: background .12s ease;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-dark { background: var(--sidebar); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #2a2a2e; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--faint); }
.btn-good { background: var(--good); color: #fff; }
.btn-good:hover:not(:disabled) { background: #14642b; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a21f1f; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 7px; }

label.f { display: block; font-size: 11.5px; font-weight: 650; letter-spacing: .02em; color: var(--muted); margin: 14px 0 6px; }
input.f, select.f, textarea.f {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 13.5px; background: var(--panel); color: var(--ink);
}
textarea.f { height: auto; padding: 9px 12px; resize: vertical; }
select.f { cursor: pointer; }
input.f:focus, select.f:focus, textarea.f:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
/* One field = one grid cell: label and control always stay aligned. */
.fld { min-width: 0; }
.fld label.f { margin: 0 0 6px; }
.frow, .frow3 { display: grid; gap: 14px 16px; align-items: end; }
.frow  { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.frow3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.frow .actions, .frow3 .actions { grid-column: 1 / -1; }
/* Mini section heading inside a card body */
.subh {
  grid-column: 1 / -1; font-size: 11px; font-weight: 750; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint); padding-top: 8px;
  border-top: 1px solid var(--line-2); margin-top: 6px;
}
.subh:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
/* Compact numeric inputs inside tables (roof areas, price matrix) */
table.grid input.cell {
  width: 100%; max-width: 110px; height: 32px; padding: 0 9px; text-align: right;
  border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 13px;
  font-variant-numeric: tabular-nums; background: var(--panel);
}
table.grid input.cell:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.empty {
  padding: 46px 20px; text-align: center; color: var(--muted);
}
.empty .big { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.loading { padding: 40px; text-align: center; color: var(--faint); }

.bar { height: 7px; background: var(--line-2); border-radius: 4px; overflow: hidden; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.full i { background: var(--danger); }

/* ============================= drawer / modal / toast ============================= */
#overlay {
  position: fixed; inset: 0; background: rgba(19,19,21,.45); z-index: 50; display: none;
}
#overlay.show { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 94vw; background: var(--panel);
  z-index: 60; box-shadow: var(--shadow-lg); display: none; flex-direction: column;
}
.drawer.show { display: flex; }
.drawer > header {
  padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 10px;
}
.drawer > header h2 { font-size: 16px; }
.drawer .body { padding: 18px 22px; overflow-y: auto; flex: 1; }

.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 520px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border-radius: 12px; z-index: 60; box-shadow: var(--shadow-lg); display: none;
}
.modal.show { display: block; }
.modal > header {
  padding: 18px 24px 0; display: flex; align-items: center; justify-content: space-between;
}
.modal > header h2 { font-size: 17px; }
.modal .body { padding: 10px 24px 24px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.close-x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 12px; font-size: 13.5px; margin: 0 0 18px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar); color: #fff; border-radius: 9px; padding: 11px 20px; z-index: 100;
  display: none; font-size: 13.5px; box-shadow: var(--shadow-lg); max-width: 80vw;
}
#toast.err { background: var(--danger); }

.reveal {
  background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 8px;
  padding: 12px 14px; font-size: 14px; margin-top: 14px;
}
.reveal code { font-size: 16px; font-weight: 700; letter-spacing: .03em; }
.reveal .sub { display: block; margin-top: 4px; }

/* tools grid */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tool-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); display: block;
}
.tool-card:hover { border-color: var(--accent); text-decoration: none; }
.tool-card b { display: block; margin-bottom: 4px; }
.tool-card span { font-size: 12.5px; color: var(--muted); }

/* HR tabs */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
  background: none; border: 0; padding: 9px 16px; font: inherit; font-weight: 600; font-size: 13.5px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.statusbars { display: flex; flex-direction: column; gap: 9px; }
.statusbars .row { display: grid; grid-template-columns: 170px 1fr 44px; align-items: center; gap: 12px; font-size: 13px; }
.statusbars .row .lbl { color: var(--ink-2); font-weight: 500; text-transform: capitalize; }
.statusbars .row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

@media (max-width: 900px) {
  main { padding: 18px 16px 50px; }
  nav.side { width: 64px; }
  nav.side .logo { padding: 2px 0 14px; display: flex; justify-content: center; }
  nav.side .logo img.full { display: none; }
  nav.side .logo img.mark { display: block; }
  nav.side .sec, nav.side a span.t, nav.side .env { display: none; }
  nav.side a { justify-content: center; padding: 11px 0; }
  nav.side a::before { content: attr(data-ab); font-size: 12.5px; font-weight: 700; }
  .frow, .frow3 { grid-template-columns: 1fr; }
}

/* ============================ dark theme ============================ */
:root[data-theme="dark"] {
  --bg: #141416;
  --panel: #1d1d20;
  --panel-2: #19191c;
  --ink: #eceff1;
  --ink-2: #c3c7cb;
  --muted: #8b9095;
  --faint: #6a6f74;
  --line: #2b2b30;
  --line-2: #232327;
  --accent-soft: #14281f;
  --sidebar: #0e0e10;
  --good: #5ec26a;      --good-bg: #16301d;
  --warn: #e0a63f;      --warn-bg: #332910;
  --danger: #ef6a5f;    --danger-bg: #3a1a17;
  --info: #64a7f0;      --info-bg: #17293e;
  --hold: #9aa0a5;      --hold-bg: #232529;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.6);
}
:root[data-theme="dark"] .login-side { background: var(--bg); }

.themebtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 50%; width: 34px; height: 34px; cursor: pointer; font-size: 15px;
  line-height: 1; margin-right: 10px;
}
.themebtn:hover { color: var(--ink); border-color: var(--faint); }

/* ====================== job stage pipeline dots ===================== */
.stages { display: flex; gap: 2px; align-items: flex-start; }
.stg { width: 58px; text-align: center; position: relative; }
.stg::before {
  content: ''; position: absolute; top: 8px; left: -50%; width: 100%; height: 2px;
  background: var(--line);
}
.stg:first-child::before { display: none; }
.stg .d {
  position: relative; z-index: 1; display: block; width: 17px; height: 17px; margin: 0 auto;
  border-radius: 50%; border: 2px solid var(--line); background: var(--panel);
  font-size: 10px; line-height: 14px; color: #fff; text-align: center;
}
.stg.done .d { background: var(--good); border-color: var(--good); }
.stg.done .d::after { content: '✓'; }
.stg.active .d { border-color: var(--accent); background: var(--accent-soft); }
.stg.warn .d { background: var(--danger); border-color: var(--danger); }
.stg.warn .d::after { content: '!'; }
.stg .l { font-size: 9.5px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
  text-transform: uppercase; margin-top: 4px; }
.stg.done .l, .stg.active .l { color: var(--ink-2); }
.stg .s { font-size: 9.5px; color: var(--faint); line-height: 1.2; }
.stg.warn .s { color: var(--danger); }

/* ===================== funnel + trend (home KPIs) ==================== */
.funnel { display: flex; gap: 10px; align-items: flex-end; }
.funnel .fs { flex: 1; text-align: center; }
.funnel .fbar {
  background: var(--accent); border-radius: 6px 6px 2px 2px; margin: 0 auto;
  width: 100%; min-height: 4px; opacity: .92; transition: height .3s;
}
.funnel .fs:hover .fbar { opacity: 1; }
.funnel .fv { font-size: 19px; font-weight: 700; margin-top: 6px; }
.funnel .fk { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; color: var(--muted);
  text-transform: uppercase; }
.funnel .fp { font-size: 10.5px; color: var(--faint); }

.trend { display: flex; gap: 14px; align-items: flex-end; height: 120px; padding-top: 8px; }
.trend .tm { flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; height: 100%; gap: 0; }
.trend .bars { display: flex; gap: 4px; align-items: flex-end; width: 100%; height: 100%;
  justify-content: center; }
.trend .tb { width: 16px; border-radius: 4px 4px 1px 1px; min-height: 2px; }
.trend .tb.leads { background: var(--line); }
.trend .tb.jobs { background: var(--accent); }
.trend .tl { font-size: 10.5px; color: var(--muted); margin-top: 6px; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  margin-right: 5px; vertical-align: -1px; }

/* Testing & Rules — rendered markdown */
.md { max-width: 860px; line-height: 1.6; font-size: 13.5px; }
.md h2 { font-size: 19px; margin: 4px 0 10px; }
.md h3 { font-size: 14px; margin: 22px 0 8px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.md h3:first-child { border-top: 0; padding-top: 0; margin-top: 4px; }
.md h4 { font-size: 13px; margin: 16px 0 6px; }
.md p { margin: 0 0 10px; color: var(--ink); }
.md .md-ul { margin: 0 0 12px; padding-left: 20px; }
.md .md-ul li { margin: 4px 0; }
.md code { font-family: Consolas, 'SF Mono', monospace; font-size: 12px;
  background: var(--line-2); border-radius: 5px; padding: 1px 5px; }
.md .md-pre { font-family: Consolas, 'SF Mono', monospace; font-size: 12px;
  background: var(--line-2); border-radius: 9px; padding: 12px 14px; overflow: auto;
  margin: 0 0 12px; line-height: 1.5; }
.md table.md-t { margin: 0 0 14px; }
.md table.md-t td { vertical-align: top; }
.md .md-hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
