:root {
  color-scheme: light;
  --bg: #eef1f3;
  --surface: #ffffff;
  --border: #d9e0e3;
  --border-strong: #c3ccd0;
  --text: #1c2b33;
  --muted: #5b6b72;
  --brand: #176b5b;
  --brand-dark: #0f4f43;
  --ok-bg: #e3f4ea; --ok-fg: #17603a; --ok-bd: #9fd3b4;
  --warn-bg: #fff3dc; --warn-fg: #8a4b00; --warn-bd: #f0c77a;
  --bad-bg: #fde7e7; --bad-fg: #9b1c1c; --bad-bd: #eea9a9;
  --info-bg: #e6f0fb; --info-fg: #1d4f86; --info-bd: #a9c6ea;
  --neutral-bg: #eef1f3; --neutral-fg: #45555c; --neutral-bd: #cfd7da;
  --radius: 8px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h1, h2, h3 { color: #17323a; line-height: 1.2; }
h1 { font-size: 1.55rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
p { margin: 0 0 0.75rem; }
code { font-size: 0.85em; }

/* Header / navigation */
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem;
  padding: 0.7rem max(1rem, calc((100% - 1240px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { color: #173d37; font-weight: 700; text-decoration: none; }
.primary-nav, .account-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.primary-nav a {
  padding: 0.35rem 0.6rem; border-radius: 6px; color: var(--muted);
  font-size: 0.92rem; text-decoration: none;
}
.primary-nav a:hover { background: var(--bg); color: var(--text); }
.primary-nav a.active { background: #e2efec; color: var(--brand-dark); font-weight: 600; }
.account-nav { margin-left: auto; gap: 0.75rem; font-size: 0.88rem; color: var(--muted); }
.account-nav form { margin: 0; }
.role-tag { padding: 0.1rem 0.45rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.78rem; }

.page-content { width: min(100% - 2rem, 1240px); min-height: 70vh; margin: 1.5rem auto 2rem; }
.site-footer { padding: 1.25rem; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* Page heading */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.page-head .subtitle { color: var(--muted); margin: 0; }
.breadcrumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
.breadcrumbs a { color: var(--muted); }

/* Surfaces */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.15rem; margin-bottom: 1rem;
}
.panel > h2:first-child, .panel > .panel-head:first-child { margin-top: 0; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* Welcome (anonymous) */
.welcome-panel, .form-panel {
  padding: clamp(1.5rem, 4vw, 2.5rem); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.welcome-panel h1, .form-panel h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0.25rem 0 0.75rem; }
.eyebrow { margin: 0; color: var(--brand); font-weight: 700; letter-spacing: 0.04em; font-size: 0.85rem; text-transform: uppercase; }
.lead { color: var(--muted); font-size: 1.05rem; }
.form-panel { max-width: 30rem; margin: 0 auto; }

/* Key figures */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.5rem 1rem; margin: 0; }
.figures div { padding: 0.5rem 0; border-top: 1px solid var(--border); }
.figures dt { color: var(--muted); font-size: 0.8rem; }
.figures dd { margin: 0.1rem 0 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.recon-card { border-left: 4px solid var(--neutral-bd); }
.recon-card.ok { border-left-color: var(--ok-fg); }
.recon-card.warn { border-left-color: var(--warn-fg); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.55rem;
  border: 1px solid; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-bd); }
.badge-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-bd); }

/* Callouts */
.notice { padding: 0.65rem 0.85rem; border: 1px solid; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.92rem; }
.notice ul { margin: 0.25rem 0 0; padding-left: 1.2rem; }
.notice-warn { background: var(--warn-bg); border-color: var(--warn-bd); color: #5c3500; }
.notice-info { background: var(--info-bg); border-color: var(--info-bd); color: #173e69; }
.notice-ok { background: var(--ok-bg); border-color: var(--ok-bd); color: #134d2f; }
.notice-bad { background: var(--bad-bg); border-color: var(--bad-bd); color: #7a1515; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data thead th { background: #f6f8f9; color: var(--muted); font-weight: 600; font-size: 0.8rem; border-bottom-color: var(--border-strong); }
table.data tbody tr:hover { background: #fafbfb; }
table.data .num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; }
table.data tr.subtotal td { background: #f6f8f9; font-weight: 600; }
table.data tr.group td { background: #f1f5f4; font-weight: 700; color: #17323a; }
table.data input, table.data select { width: 100%; min-width: 6rem; }

details.explain summary { cursor: pointer; color: var(--brand); font-size: 0.85rem; }
details.explain[open] summary { margin-bottom: 0.35rem; }
details.explain .explain-body { font-size: 0.85rem; color: var(--muted); }

/* Workflow steps */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  display: grid; grid-template-columns: 2rem 1fr auto; gap: 0.75rem; align-items: start;
  padding: 0.75rem 0; border-top: 1px solid var(--border);
}
.steps li:first-child { border-top: 0; }
.steps li::before {
  counter-increment: step; content: counter(step);
  display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--neutral-bg); border: 1px solid var(--neutral-bd); font-weight: 700; font-size: 0.85rem;
}
.steps li.done::before { content: "✓"; background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd); }
.steps li.attention::before { content: "!"; background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.steps .step-title { font-weight: 600; }
.steps .step-detail { color: var(--muted); font-size: 0.87rem; }

/* Forms and buttons */
form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.75rem 1rem; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; color: #34454c; margin-bottom: 0.2rem; }
.field .help { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.field .errorlist, .errorlist { color: var(--bad-fg); font-size: 0.82rem; margin: 0.2rem 0 0; padding-left: 1rem; }
.field.wide { grid-column: 1 / -1; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 0.4rem 0.55rem; border: 1px solid var(--border-strong); border-radius: 6px;
  font: inherit; font-size: 0.92rem; background: #fff; color: var(--text);
}
textarea { min-height: 4.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc9bf; outline-offset: 0; border-color: var(--brand); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 0.35rem; color: #17323a; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1rem; }

.button, button.button {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.45rem 0.9rem;
  border: 1px solid var(--brand); border-radius: 6px; background: var(--brand); color: #fff;
  font: inherit; font-size: 0.9rem; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--brand-dark); }
.button.secondary { background: #fff; color: var(--brand); }
.button.secondary:hover { background: #eef6f4; }
.button.danger { background: #fff; color: var(--bad-fg); border-color: var(--bad-bd); }
.button.danger:hover { background: var(--bad-bg); }
.button.small { padding: 0.25rem 0.6rem; font-size: 0.82rem; }
.button[disabled] { opacity: 0.5; cursor: not-allowed; }
.text-button { padding: 0; color: var(--brand); background: none; border: 0; font: inherit; cursor: pointer; }
.form-panel button { padding: 0.6rem 1rem; color: #fff; background: var(--brand); border: 0; border-radius: 6px; cursor: pointer; }
.form-panel input { width: 100%; }
.form-error { color: var(--bad-fg); }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: 0.45rem 0.8rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }

.chart-box { position: relative; height: 260px; }
.statement-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; }
.totals { margin-left: auto; min-width: 280px; }
.totals table { width: 100%; }
.totals td { padding: 0.3rem 0.5rem; }
.totals tr.grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--border-strong); }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .account-nav { margin-left: 0; }
  .page-content { margin: 1rem auto; }
  .steps li { grid-template-columns: 2rem 1fr; }
  .steps li > :last-child { grid-column: 2; }
}

@media print {
  .site-header, .site-footer, .no-print, .form-actions { display: none !important; }
  body, :root { background: #fff; }
  .panel { border: 0; padding: 0; }
  .page-content { width: 100%; margin: 0; }
}

/* Demo-readiness additions */
.open-items { border-left: 4px solid var(--warn-fg); }
.open-list { margin: 0; padding-left: 1.3rem; }
.open-list li { margin: 0.35rem 0; }
.figures dd.diff-warn { color: var(--warn-fg); }
details.panel > summary { font-weight: 600; font-size: 0.92rem; }
@media (min-width: 1600px) {
  .site-header { padding-left: max(1.5rem, calc((100% - 1440px) / 2)); padding-right: max(1.5rem, calc((100% - 1440px) / 2)); }
  .page-content { width: min(100% - 3rem, 1440px); }
  .figures dd { font-size: 1.35rem; }
}

/* Monthly Billing Input worksheet */
.cta-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; border-left: 4px solid var(--brand); }
.button.large { padding: 0.7rem 1.3rem; font-size: 1rem; }
.ws-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
.ws-side { position: sticky; top: 1rem; }
.ws-section .panel-head h2 { display: flex; align-items: center; gap: 0.5rem; }
.section-num { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--brand); color: #fff; font-size: 0.85rem; flex: none; }
.ws-summary h2 { display: flex; align-items: center; gap: 0.5rem; }
.ws-table td { vertical-align: middle; }
.ws-table input[type=text], .ws-table input[type=number], .ws-table select { min-width: 7rem; }
.ws-table .unit { display: block; font-size: 0.75rem; color: var(--muted); }
.ws-details > summary { cursor: pointer; font-weight: 600; }
.total-box { padding: 0.4rem 0.55rem; border: 1px dashed var(--border-strong); border-radius: 6px; font-weight: 700; font-variant-numeric: tabular-nums; background: #f6f8f9; }
.override-row td { background: var(--warn-bg) !important; }
.override-box { display: grid; gap: 0.2rem; justify-items: end; }
.sub-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem 1rem; margin-bottom: 1rem; background: #fbfcfc; }
.quick-add { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.quick-add input[type=text] { width: 11rem; }
.quick-add select { width: auto; }
.dirty-flag { color: var(--warn-fg); font-weight: 600; font-size: 0.85rem; }
.calc-button { width: 100%; justify-content: center; }
.mini-recon { border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.5rem; }
.figures.compact dd { font-size: 1rem; }
input:disabled, select:disabled, textarea:disabled { background: #f3f5f6; color: var(--text); border-color: var(--border); }
@media (max-width: 1100px) { .ws-layout { grid-template-columns: 1fr; } .ws-side { position: static; } }
table.data input[type=checkbox] { width: auto; min-width: 0; margin-right: 0.3rem; vertical-align: middle; }
.ws-table .quick-add input[type=text] { width: 11rem; min-width: 0; }
.ws-table .quick-add select { width: auto; min-width: 0; max-width: 15rem; }
.quick-add label { white-space: nowrap; }

/* Live Energy */
.range-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 1rem; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); gap: 1rem; }
.live-card { margin-bottom: 0; }
.live-figures { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.live-figures dd { font-size: 1.35rem; }
.live-figures dd .small { display: block; font-weight: 400; font-size: 0.75rem; margin-top: 0.15rem; }
.collecting { color: var(--muted); font-size: 1rem; font-weight: 600; }
.live-chart { position: relative; height: 240px; margin-top: 0.75rem; }
@media (max-width: 700px) { .live-grid { grid-template-columns: 1fr; } .live-figures { grid-template-columns: repeat(2, 1fr); } }

/* Invoice-style statements */
.invoice-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.invoice {
  position: relative; background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.2rem 2.4rem; max-width: 1100px; margin: 0 auto 1.5rem; overflow: hidden;
}
.invoice h2 { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.45rem; }
.invoice .pre { white-space: pre-line; }
.invoice .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; white-space: nowrap; }
.invoice .placeholder {
  color: #8a969b; font-style: italic; border: 1px dashed #c9d2d6; border-radius: 4px;
  padding: 0.05rem 0.4rem; margin: 0.2rem 0; display: block; width: fit-content;
}
.invoice-watermark {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg);
  font-size: 6.5rem; font-weight: 800; letter-spacing: 0.12em; color: rgba(138, 75, 0, 0.06);
  pointer-events: none; white-space: nowrap; z-index: 0;
}
.invoice > :not(.invoice-watermark) { position: relative; z-index: 1; }
.invoice .print-only { display: none; }
.invoice-head { display: flex; justify-content: space-between; gap: 2rem; padding-bottom: 1.25rem; border-bottom: 3px solid var(--brand); }
.invoice-from { line-height: 1.5; font-size: 0.92rem; }
.invoice-sender { font-size: 1.25rem; font-weight: 700; color: var(--brand-dark); margin-bottom: 0.2rem; }
.invoice-meta { text-align: right; min-width: 18rem; }
.invoice-title { font-size: 1.45rem; letter-spacing: 0.04em; margin: 0 0 0.4rem; color: var(--text); }
.invoice-status.provisional {
  display: inline-block; padding: 0.15rem 0.6rem; border: 1.5px solid var(--warn-fg); color: var(--warn-fg);
  border-radius: 4px; font-weight: 700; letter-spacing: 0.1em; font-size: 0.8rem; margin-bottom: 0.5rem;
}
.invoice dl { display: grid; grid-template-columns: auto auto; gap: 0.2rem 1rem; margin: 0; font-size: 0.9rem; }
.invoice-meta dl { justify-content: end; }
.invoice dt { color: var(--muted); }
.invoice dd { margin: 0; font-weight: 600; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; padding: 1.25rem 0; line-height: 1.5; font-size: 0.92rem; }
.invoice-recipient { font-weight: 700; font-size: 1.05rem; }
.invoice-units { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.invoice-lines { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.invoice-lines th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  border-bottom: 2px solid var(--text); padding: 0.45rem 0.5rem; }
.invoice-lines td { padding: 0.4rem 0.5rem; border-bottom: 1px solid #e8ecee; vertical-align: top; }
.invoice-lines .num { text-align: right; white-space: nowrap; }
.invoice-lines tr.group td { background: #f3f6f7; font-weight: 700; font-size: 0.76rem; letter-spacing: 0.07em; color: var(--brand-dark); padding-top: 0.6rem; }
.invoice-lines tr.subtotal td { font-weight: 600; border-bottom: 1px solid var(--border-strong); }
.invoice-lines details.explain { margin-top: 0.2rem; }
.invoice-bottom { display: grid; grid-template-columns: 1fr 22rem; gap: 2rem; margin-top: 1.5rem; }
.invoice-payment { font-size: 0.9rem; }
.invoice-totals table { width: 100%; border-collapse: collapse; }
.invoice-totals td { padding: 0.35rem 0.25rem; }
.invoice-totals .num { text-align: right; white-space: nowrap; }
.invoice-totals tr.minor td { font-size: 0.82rem; color: var(--muted); }
.invoice-totals tr.due td { white-space: nowrap; border-top: 3px solid var(--brand); font-size: 1.35rem; font-weight: 800; padding-top: 0.6rem; color: var(--brand-dark); }
.invoice-foot { margin-top: 1.75rem; padding-top: 0.9rem; border-top: 1px solid var(--border); font-size: 0.88rem; }
@media screen and (max-width: 760px) {
  .invoice { padding: 1.2rem; }
  .invoice-head, .invoice-parties, .invoice-bottom { display: block; }
  .invoice-meta { text-align: left; margin-top: 1rem; }
  .invoice-meta dl { justify-content: start; }
}
@page { size: A4; margin: 14mm 12mm; }
@media print {
  .breadcrumbs, .messages { display: none !important; }
  .invoice { border: 0; border-radius: 0; padding: 0; max-width: none; margin: 0; font-size: 10pt; }
  .invoice .placeholder { display: none !important; }
  .invoice .print-only { display: block; }
  .invoice-meta dt, .invoice-meta dd { white-space: nowrap; }
  .invoice-head { padding-bottom: 0.8rem; }
  .invoice-parties { padding: 0.8rem 0; }
  .invoice-lines td { padding: 0.28rem 0.4rem; }
  .invoice-foot { margin-top: 1rem; }
  .invoice-watermark { color: rgba(0, 0, 0, 0.07); }
  .invoice-head, .invoice-parties, .invoice-bottom, .invoice-foot, .invoice-lines tr, .invoice-group { break-inside: avoid; page-break-inside: avoid; }
  .invoice-bottom { break-before: avoid; }
  .invoice-lines thead { display: table-header-group; }
  .invoice-lines tr.group td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .invoice-head { display: flex; }
  .invoice-meta { text-align: right; margin-top: 0; }
  .invoice-meta dl { justify-content: end; }
  .invoice-parties { display: grid; grid-template-columns: 1fr 1fr; }
  .invoice-bottom { display: grid; grid-template-columns: 1fr 19rem; }
  .table-wrap { overflow: visible !important; }
}
