:root {
  --bg: #f4f5f7; --surface: #ffffff; --text: #1d2330; --muted: #5f6878; --border: #dde1e7;
  --brand-navy: #0f1b26; --brand-red: #c8102e; --heading: #0f1b26;
  --accent: #23638a; --accent-soft: #e5eef4; --bad: #c62828; --good: #2e7d32; --warn: #ef8f00;
  --c1: #1f5fa8; --c2: #2a9d8f; --c3: #e9a23b; --c4: #8a6fbf; --c5: #d1495b; --c6: #6c8a9b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1b2029; --text: #e6e9ef; --muted: #9aa3b2; --border: #2c3340;
    --brand-red: #f0506e; --heading: #e6e9ef;
    --accent: #6fb3dd; --accent-soft: #1d2b38; --bad: #ef5350; --good: #66bb6a; --warn: #ffb74d;
    --c1: #6ea8ff; --c2: #4fc3b4; --c3: #f2b65a; --c4: #a991db; --c5: #ef6f80; --c6: #8fa9b8;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1b2029; --text: #e6e9ef; --muted: #9aa3b2; --border: #2c3340;
  --brand-red: #f0506e; --heading: #e6e9ef;
  --accent: #6fb3dd; --accent-soft: #1d2b38; --bad: #ef5350; --good: #66bb6a; --warn: #ffb74d;
  --c1: #6ea8ff; --c2: #4fc3b4; --c3: #f2b65a; --c4: #a991db; --c5: #ef6f80; --c6: #8fa9b8;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); }
h2 small, .card small { font-weight: 400; opacity: .8; }

.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.slicers { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 24px; align-items: center; }
.slicer { position: relative; }
.slicer > button {
  min-width: 190px; text-align: left; padding: 6px 28px 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface) ; color: var(--text); font: inherit; cursor: pointer; position: relative;
}
.slicer > button::after { content: "▾"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.slicer > button .lbl { display: block; font-size: 11px; color: var(--muted); }
.slicer > button .val { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.slicer .menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 320px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.slicer .menu label { display: flex; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.slicer .menu label:hover { background: var(--accent-soft); }
.slicer .menu .all { border-bottom: 1px solid var(--border); margin-bottom: 4px; padding-bottom: 6px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 6px; }

.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.page { padding: 12px 24px 0; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; }
.c7 { grid-column: span 7; } .c9 { grid-column: span 9; } .c12 { grid-column: span 12; }
@media (max-width: 1100px) { .c3 { grid-column: span 6; } .c4, .c5, .c6, .c7, .c9 { grid-column: span 12; } }
@media (max-width: 640px) {
  .page-head, .slicers, .tabs, .page, .placeholder { padding-left: 16px; padding-right: 16px; }
  .grid > * { grid-column: span 12; }
  .slicer, .slicer > button { width: 100%; }
}

.card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.card { align-self: start; padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; min-height: 92px; }
.card span { color: var(--muted); font-size: 13px; }
.card b { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.panel { padding: 12px 14px; min-width: 0; }
.chart { height: 300px; }
.chart.tall { height: 380px; }
.loading .chart, .loading .card b, .loading .table-wrap { opacity: .45; transition: opacity .2s; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.table-wrap { max-height: 520px; overflow: auto; }
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.table-tools input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; min-width: 220px; }
.table-tools select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.due-overdue { color: var(--bad); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }
.table-tools .count { color: var(--muted); font-size: 12px; margin-left: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; white-space: nowrap; font-weight: 600; }
th.sorted::after { content: attr(data-dir); color: var(--muted); padding-left: 4px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.notes { min-width: 220px; }
td.nowrap { white-space: nowrap; }
tr.lvl-Category td { font-weight: 600; background: var(--accent-soft); }
tr.lvl-Total td { font-weight: 700; border-top: 2px solid var(--text); }
a.asset { color: var(--accent); cursor: pointer; text-decoration: underline; }

.asset-head { display: flex; align-items: center; gap: 12px; }
.asset-head h2 { margin: 0; font-size: 18px; color: var(--text); }

/* Jobs / Invoices (live.js): plain filter fields next to the slicer-style buttons, job facts, job notes */
.live-filters .field { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); }
.live-filters .field select, .live-filters .field input[type="date"] {
  margin-top: 2px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; max-width: 320px; color-scheme: light dark;
}
.live-filters .field.check { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--text); align-self: flex-end; padding-bottom: 6px; }
#live.loading .table-wrap, #live.loading .facts { opacity: .45; transition: opacity .2s; }

/* Job bookings list (live.js) and form (booking.js) */
.head-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
a.button { display: inline-block; padding: 8px 18px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
a.button:hover { filter: brightness(1.08); }
.page-head .sub a.link { color: var(--accent); }
form.booking { display: flex; flex-direction: column; gap: 12px; }
form.booking .field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
form.booking input, form.booking select, form.booking textarea {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; color-scheme: light dark;
}
form.booking input[readonly] { background: var(--surface); color: var(--muted); }
form.booking textarea { resize: vertical; min-height: 110px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .field-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-actions button.primary { width: auto; padding: 9px 22px; margin: 0; }
.form-msg, .hint { color: var(--muted); font-size: 13px; margin: 0; }
#bookingView.loading form, #bookingView.loading .facts { opacity: .45; transition: opacity .2s; }
dl.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; font-size: 13px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.job-notes { white-space: pre-wrap; font-size: 13px; overflow-wrap: anywhere; }
/* sign-in pages and user bar */
.auth-page { display: flex; justify-content: center; padding: 48px 16px; }
.auth-box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; box-shadow: var(--shadow); }
.auth-box h1 { margin-bottom: 16px; }
.auth-box h2 { font-size: 16px; color: var(--text); margin-bottom: 12px; }
.auth-box p { color: var(--muted); margin: 0 0 12px; }
.auth-box label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.auth-box label.check { display: flex; gap: 8px; align-items: center; }
.auth-box input[type="email"], .auth-box input[type="password"], .auth-box input[type="text"], .auth-box input[type="tel"] {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 15px;
}
.auth-box .hint { font-size: 12px; }
.auth-box .msg { margin: 0 0 12px; padding: 8px 10px; border-radius: 6px; background: var(--bad); color: #fff; }
.auth-box .msg.good { background: var(--good); }
.auth-box a.link { display: inline-block; padding: 6px; color: var(--accent); }
.auth-box button.primary.secondary { background: none; color: var(--accent); border: 1px solid var(--accent); }
.auth-box img.qr { display: block; margin: 0 auto 12px; background: #fff; padding: 4px; border-radius: 6px; image-rendering: pixelated; }
.auth-box code.key { font-size: 13px; overflow-wrap: anywhere; }
.auth-box pre.recovery-codes { columns: 2; margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
button.primary { width: 100%; padding: 9px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; margin-bottom: 8px; }
button:disabled { opacity: .6; cursor: default; }
.notice { margin: 24px; padding: 16px 20px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-size: 15px; }
.slicer.account > button { border-color: var(--accent); }
.slicer .menu { min-width: 280px; }
.slicer .menu .menu-search { position: sticky; top: -6px; width: 100%; margin: -6px 0 6px; padding: 8px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.error { margin: 16px 24px 0; padding: 12px; border-radius: 6px; background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- portal shell (Pages/Shared/_Layout.cshtml)
   Jofson brand: navy panel + crimson accents, as on jofson.com; controls use the calmer steel blue (--accent)
   so the portal reads as a distinct, functional site rather than the sales site. */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; flex: none; }
.logo-chip { display: inline-flex; background: #fff; border-radius: 6px; padding: 3px 6px; }
.logo-chip img { display: block; height: 30px; width: auto; }
.brand-sub {
  color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  padding-left: 14px; border-left: 2px solid var(--brand-red); line-height: 1.6;
}
.topbar-tools { flex: 1; display: flex; justify-content: flex-end; min-width: 0; }
.topbar .slicer > button { padding-top: 4px; padding-bottom: 4px; }
.topbar .slicer .menu { left: auto; right: 0; }
.userbar { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.user-email { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.nav-toggle { display: none; background: none; border: 0; color: var(--text); padding: 6px; cursor: pointer; }

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.sidenav {
  position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; padding: 18px 0;
  background: var(--brand-navy); border-right: 3px solid var(--brand-red);
}
.sidenav ul { list-style: none; margin: 0; padding: 0; }
.sidenav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 20px; color: #c3cdd7; text-decoration: none;
  border-left: 3px solid transparent; font-size: 14px;
}
.sidenav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidenav a.active { color: #fff; background: rgba(255, 255, 255, .09); border-left-color: var(--brand-red); font-weight: 600; }
.sidenav .icon { flex: none; }
.sidenav .tag {
  margin-left: auto; font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 7px; border-radius: 10px; background: #5f7581; color: #fff;
}
.content { min-width: 0; padding-bottom: 32px; }
.page-head { padding: 20px 24px 4px; }
.page-head h1 { font-size: 22px; color: var(--heading); }
.brand-accent { color: var(--brand-red); }
.placeholder { padding: 16px 24px; max-width: 760px; }
.placeholder .panel { padding: 20px 24px; }
.placeholder h2 { font-size: 16px; color: var(--heading); }
.placeholder p { color: var(--muted); margin: 0 0 10px; }

/* phones / narrow windows: the menu slides in over the page */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-flex; }
  .sidenav {
    position: fixed; z-index: 40; top: 60px; bottom: 0; left: 0; width: 264px; height: auto;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  body.nav-open .sidenav { transform: none; }
  .nav-backdrop { position: fixed; inset: 60px 0 0 0; z-index: 35; background: rgba(0, 0, 0, .35); }
  .brand-sub, .user-email { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar .slicer { width: auto; }
  .topbar .slicer > button { min-width: 0; width: auto; max-width: 46vw; }
}

/* sign-in pages: logo above the form */
.auth-box { border-top: 3px solid var(--brand-red); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-brand .brand-sub { font-size: 11px; }

/* ---------------------------------------------------------------- inspect data (app.js: inspect pane)
   The pane covers the bottom of the window beside the menu; the page gets room below so every widget can still
   be scrolled into view above it. Phones: the pane takes the whole height under the top bar. */
.card, .panel { position: relative; }
.inspect-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2; display: inline-flex; padding: 4px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer; opacity: .7;
}
.inspect-btn:hover, .inspect-btn:focus-visible { opacity: 1; color: var(--accent); background: var(--accent-soft); }
.inspect-btn.active { opacity: 1; color: var(--accent); background: var(--accent-soft); }
.panel:has(> .inspect-btn) > h2, .card:has(> .inspect-btn) > span { padding-right: 28px; }
.inspect-row { display: inline-flex; padding: 2px; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; vertical-align: middle; }
.inspect-row:hover, .inspect-row:focus-visible { color: var(--accent); background: var(--accent-soft); }
td:has(> .inspect-row) { width: 1%; padding: 4px 0 4px 4px; }
.inspect-pane {
  position: fixed; z-index: 25; left: 236px; right: 0; bottom: 0; height: 45vh; display: flex; flex-direction: column;
  background: var(--surface); border-top: 3px solid var(--accent); box-shadow: 0 -6px 18px rgba(16, 24, 40, .14); padding: 10px 24px 8px;
}
body.inspecting .content { padding-bottom: calc(45vh + 24px); }
.inspect-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.inspect-text { flex: 1; min-width: 0; }
.inspect-head h2 { font-size: 15px; color: var(--heading); margin: 0; }
.inspect-close { border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1; padding: 2px 8px; cursor: pointer; border-radius: 6px; }
.inspect-close:hover { background: var(--accent-soft); color: var(--text); }
.inspect-pane .table-wrap { flex: 1; min-height: 0; max-height: none; }
.inspect-pane.loading .table-wrap { opacity: .45; transition: opacity .2s; }
@media (max-width: 900px) { .inspect-pane { left: 0; padding: 10px 12px 8px; } }
@media (max-width: 640px) {
  .inspect-pane { top: 60px; height: auto; }
  body.inspecting .content { padding-bottom: 32px; }
}
body.print-mode .inspect-pane, body.print-mode .inspect-btn, body.print-mode .inspect-row { display: none; }
body.print-mode.inspecting .content { padding-bottom: 32px; }

/* ---------------------------------------------------------------- exports (app.js: exportPdf / exportExcel) */
.export { position: relative; margin-left: auto; }
.export-btn {
  padding: 8px 30px 8px 14px; border: 1px solid var(--accent); border-radius: 6px; background: var(--surface);
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; position: relative;
}
.export-btn::after { content: "▾"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
.export-list {
  position: absolute; z-index: 25; right: 0; top: calc(100% + 4px); min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.export-list .export-group { padding: 6px 8px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.export-list .export-group small { text-transform: none; letter-spacing: 0; }
.export-list button {
  display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 4px;
  background: none; color: var(--text); font: inherit; cursor: pointer;
}
.export-list button:hover { background: var(--accent-soft); }
.export-list small { color: var(--muted); font-size: 11px; margin-left: 4px; }
.busy-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(15, 27, 38, .55); }
.busy-box { padding: 18px 26px; border-radius: 8px; background: var(--surface); color: var(--text); font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

/* print layout: only shown while printing (and prepared behind the overlay at A4-landscape width) */
.print-only { display: none; }
body.print-mode .content { width: 1047px; }   /* A4 landscape (297 mm) minus 2 x 10 mm margins, at 96 px per inch */
/* Desktop columns while preparing AND printing, whatever the window size: the charts are drawn for this
   layout, so the narrow-screen rules must not reflow it (that would clip or overlap the drawn charts). */
body.print-mode .grid > .c3 { grid-column: span 3; } body.print-mode .grid > .c4 { grid-column: span 4; }
body.print-mode .grid > .c5 { grid-column: span 5; } body.print-mode .grid > .c6 { grid-column: span 6; }
body.print-mode .grid > .c7 { grid-column: span 7; } body.print-mode .grid > .c9 { grid-column: span 9; }
body.print-mode .grid > .c12 { grid-column: span 12; }
/* tables cannot scroll on paper: give them the full width */
body.print-mode .grid > .panel:has(.table-wrap) { grid-column: span 12; }
body.print-mode table { font-size: 12px; }
.print-head { display: none; }
.print-cover h1 { font-size: 30px; color: #0f1b26; margin: 36px 0 6px; }
.print-cover .cover-customer { font-size: 20px; margin-bottom: 28px; }
.print-cover .cover-facts td { border: 0; padding: 3px 18px 3px 0; font-size: 13px; }
.print-cover .cover-facts td:first-child { color: #5f6878; }
.print-cover h2 { font-size: 15px; color: #0f1b26; margin: 28px 0 6px; }
.print-cover .cover-contents { font-size: 14px; line-height: 1.9; }
.print-note { color: #5f6878; font-size: 11px; margin-top: 6px; }

@page { size: A4 landscape; margin: 10mm 10mm 14mm; }
@page {
  @bottom-left { content: "Jofson Customer Portal"; font: 9px "Segoe UI", sans-serif; color: #5f6878; }
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 9px "Segoe UI", sans-serif; color: #5f6878; }
}
@media print {
  .topbar, .sidenav, .nav-backdrop, .slicers, .tabs, .busy-overlay, #notice, #error, .inspect-pane, .inspect-btn, .inspect-row,
  .table-tools input, .table-tools select, .table-tools button { display: none !important; }
  html, body { background: #fff; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .shell { display: block; min-height: 0; }
  .content { width: auto; padding: 0; }
  .page { padding: 0; }
  .print-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 0 0 6px; margin-bottom: 10px;
    border-bottom: 2px solid #c8102e; font-size: 11px; color: #5f6878;
  }
  .print-head b { font-size: 16px; color: #0f1b26; }
  .page-head { padding: 0 0 8px; }
  body.print-pack .page-head { display: none; }
  body.print-pack .print-cover { display: block; }
  body.print-pack .page { break-before: page; }
  .card, .panel { box-shadow: none; break-inside: avoid; }
  .panel:has(.table-wrap) { break-inside: auto; }
  .table-wrap { max-height: none; overflow: visible; }
  th { position: static; }
  .table-tools .count { margin-left: 0; }
}
