/* ============================================================================
   Utility Ledger — stylesheet
   Written as a token layer on top of Bootstrap, not a fight with it.

   Direction: an instrument panel, not a marketing dashboard. The subject is a
   meter reading, so figures are set in a monospace face with tabular figures
   and are always the largest thing in any block. Colour is spent on exactly
   two things — water (teal) and electricity (amber) — and nowhere else.
   ========================================================================= */

:root {
  --water: #0f8b9e;
  --water-soft: rgba(15, 139, 158, .14);
  --elec: #c0711d;
  --elec-soft: rgba(192, 113, 29, .14);
  --alarm: #b32d43;
  --calm: #2c7a58;

  --radius: 10px;
  --rail-w: 232px;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-num: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;
}

[data-theme="light"] {
  --bg: #eaeef1;
  --surface: #ffffff;
  --surface-2: #f4f7f9;
  --ink: #101a21;
  --ink-2: #55656f;
  --ink-3: #8695a0;
  --line: #d6dee4;
  --line-strong: #b9c5ce;
  --shadow: 0 1px 2px rgba(16, 26, 33, .06), 0 8px 24px -18px rgba(16, 26, 33, .5);
}

[data-theme="dark"] {
  --bg: #090f13;
  --surface: #111a20;
  --surface-2: #16212a;
  --ink: #e4edf3;
  --ink-2: #93a5b1;
  --ink-3: #6b7d89;
  --line: #1f2c36;
  --line-strong: #2c3d49;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -20px rgba(0, 0, 0, .9);
  --water: #2aa6ba;
  --elec: #dd8b31;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .display { font-family: var(--font-display); letter-spacing: -.015em; }

a { color: inherit; }
:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; border-radius: 4px; }

/* Every figure on the site. Tabular so columns of numbers line up. */
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  letter-spacing: -.02em;
}

/* ── Shell ─────────────────────────────────────────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line);
}
.mark {
  width: 22px; height: 22px; flex: none; border-radius: 5px;
  background: linear-gradient(150deg, var(--water) 0 50%, var(--elec) 50% 100%);
}
.mark-text { font-family: var(--font-display); font-weight: 700; font-size: 14px; letter-spacing: -.02em; }

.rail-nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.rail-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-3); margin: 16px 0 6px; padding-left: 10px; font-weight: 600;
}
.rail-label:first-child { margin-top: 0; }

.rail-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.rail-link:hover { background: var(--surface-2); color: var(--ink); }
.rail-link.is-active { background: var(--surface-2); color: var(--ink); box-shadow: inset 2px 0 0 var(--ink); }
.glyph { font-size: 11px; color: var(--ink-3); width: 14px; text-align: center; }
.rail-link.is-active .glyph { color: var(--ink); }
.glyph-water { color: var(--water) !important; }
.glyph-elec { color: var(--elec) !important; }

.rail-foot {
  padding: 12px 18px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 1px;
}
.who { font-weight: 600; font-size: 13px; }
.role { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px; flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}

.icon-btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); border-radius: 7px; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 15px;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }

.omnibox { position: relative; flex: 1; max-width: 420px; }
.omnibox input {
  width: 100%; height: 34px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 7px; color: var(--ink); font-size: 13px;
}
.omnibox input::placeholder { color: var(--ink-3); }
.omnibox-results {
  position: absolute; top: 40px; left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.omnibox-results a {
  display: block; padding: 9px 12px; text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.omnibox-results a:last-child { border-bottom: 0; }
.omnibox-results a:hover { background: var(--surface-2); }
.omnibox-results .r-type {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3);
}
.omnibox-results .r-meta { font-size: 12px; color: var(--ink-2); }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.page { padding: 22px 20px 60px; max-width: 1500px; width: 100%; }

/* ── Page heading ──────────────────────────────────────────────────────── */

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--ink-2); font-size: 13px; margin: 3px 0 0; }
.page-head .spacer { flex: 1; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card-x {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-x + .card-x { margin-top: 16px; }
.card-x .hd {
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.card-x .hd h2 { font-size: 13px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.card-x .hd .hint { font-size: 11px; color: var(--ink-3); margin-left: auto; }
.card-x .bd { padding: 16px; }

/* ── KPI tiles + the meter strip (signature) ───────────────────────────── */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 12px; }

.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 15px 10px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .k-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .13em;
  color: var(--ink-3); font-weight: 600;
}
.kpi .k-value {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-size: 26px; font-weight: 700; letter-spacing: -.035em;
  margin: 6px 0 2px; line-height: 1.05;
}
.kpi .k-foot { font-size: 11px; color: var(--ink-2); min-height: 16px; }
.kpi.water .k-value { color: var(--water); }
.kpi.elec .k-value { color: var(--elec); }

.delta { font-family: var(--font-num); font-weight: 500; }
.delta.up { color: var(--alarm); }
.delta.down { color: var(--calm); }

/* The meter strip: one bar per month, read like the consumption histogram
   printed on the back of a utility bill. */
.meter { display: flex; align-items: flex-end; gap: 1.5px; height: 26px; margin-top: 10px; }
.meter i {
  flex: 1; min-width: 2px; display: block;
  background: var(--line-strong); border-radius: 1px 1px 0 0;
  transition: background .15s ease;
}
.kpi.water .meter i { background: var(--water); opacity: .35; }
.kpi.elec .meter i { background: var(--elec); opacity: .35; }
.meter i.peak { opacity: 1; }
.meter i:hover { opacity: 1; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--ink-3);
  font-size: 10px; text-transform: uppercase; letter-spacing: .11em; font-weight: 600;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl thead th a { text-decoration: none; }
table.tbl thead th a:hover { color: var(--ink); }
table.tbl tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tfoot td {
  padding: 11px 12px; font-weight: 600; border-top: 2px solid var(--line-strong);
  background: var(--surface-2);
}
/* Right-alignment for numeric columns.
   These selectors are qualified with `table.tbl` on purpose. The base rule
   `table.tbl thead th { text-align: left }` scores 0-1-3; a bare `th.t-right`
   scores 0-1-1 and loses, which is why the numeric headers sat left of their
   own figures. Matching the base specificity fixes it without !important. */
.t-right { text-align: right; }
table.tbl thead th.t-right,
table.tbl tbody td.t-right,
table.tbl tfoot td.t-right { text-align: right; }
/* A sort link fills its header cell so the arrow tracks the column edge. */
table.tbl thead th.t-right a { display: block; }

.tag {
  display: inline-block; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  padding: 2px 7px; border-radius: 4px;
}
.tag-water { background: var(--water-soft); color: var(--water); }
.tag-elec { background: var(--elec-soft); color: var(--elec); }
.tag-off { background: var(--surface-2); color: var(--ink-3); }

/* ── Alerts / ledger ───────────────────────────────────────────────────── */

.ledger { display: flex; flex-direction: column; }
.ledger-row {
  display: flex; gap: 12px; align-items: baseline;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}
.ledger-row:last-child { border-bottom: 0; }
.ledger-row.high { border-left-color: var(--alarm); }
.ledger-row.medium { border-left-color: var(--line-strong); }
.ledger-row .l-month {
  font-family: var(--font-num); font-size: 11px; color: var(--ink-3);
  width: 54px; flex: none; text-transform: uppercase;
}
.ledger-row .l-text { flex: 1; font-size: 13px; }
.ledger-empty { padding: 26px 16px; color: var(--ink-3); text-align: center; font-size: 13px; }

.callout {
  border: 1px solid var(--line); border-left: 3px solid var(--alarm);
  background: var(--surface); border-radius: var(--radius);
  padding: 13px 16px; margin-bottom: 16px;
}
.callout h3 { font-size: 13px; margin: 0 0 4px; font-weight: 700; }
.callout p { margin: 0; font-size: 13px; color: var(--ink-2); }

/* ── Notices ───────────────────────────────────────────────────────────── */

.notice {
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
  font-size: 13px; border: 1px solid var(--line); background: var(--surface);
}
.notice-success { border-left: 3px solid var(--calm); }
.notice-warning { border-left: 3px solid var(--elec); }
.notice-danger { border-left: 3px solid var(--alarm); }
.notice-float { position: fixed; top: 16px; right: 16px; z-index: 100; box-shadow: var(--shadow); }

/* ── Forms & filters ───────────────────────────────────────────────────── */

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label,
.form-lbl {
  font-size: 10px; text-transform: uppercase; letter-spacing: .11em;
  color: var(--ink-3); font-weight: 600;
}
.field input, .field select, .form-ctl {
  height: 34px; padding: 0 10px; font-size: 13px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
}
textarea.form-ctl { height: auto; padding: 8px 10px; }
.field input:focus, .field select:focus, .form-ctl:focus {
  border-color: var(--water); outline: none; box-shadow: 0 0 0 3px var(--water-soft);
}
.field-err { color: var(--alarm); font-size: 11px; margin-top: 3px; display: none; }
.has-err .form-ctl { border-color: var(--alarm); }
.has-err .field-err { display: block; }

.btn-x {
  height: 34px; padding: 0 14px; border-radius: 7px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn-x:hover { border-color: var(--line-strong); }
.btn-primary-x { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary-x:hover { opacity: .9; color: var(--bg); }
.btn-sm-x { height: 28px; padding: 0 9px; font-size: 12px; }
.btn-danger-x { color: var(--alarm); }

/* Live calculation readout in the bill form */
.calc-out {
  background: var(--surface-2); border: 1px dashed var(--line-strong);
  border-radius: var(--radius); padding: 12px 14px; margin-top: 4px;
}
.calc-out .c-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); }
.calc-out .c-value {
  font-family: var(--font-num); font-size: 24px; font-weight: 700; letter-spacing: -.03em;
}
.calc-out .c-note { font-size: 11px; color: var(--ink-2); }

/* ── Charts ────────────────────────────────────────────────────────────── */

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }

/* ── Auth ──────────────────────────────────────────────────────────────── */

body.plain { background: var(--bg); }
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 390px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 30px 28px;
}
.auth-card .mark { width: 30px; height: 30px; border-radius: 7px; margin-bottom: 16px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 20px; }
.auth-card .field { margin-bottom: 13px; }
.auth-card .field input { width: 100%; }
.auth-card .btn-x { width: 100%; justify-content: center; height: 38px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 12px; }
.auth-links a { color: var(--ink-2); }
.seed-hint {
  margin-top: 18px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); font-size: 11px; color: var(--ink-2);
  font-family: var(--font-num);
}

/* ── Pagination ────────────────────────────────────────────────────────── */

.pager { display: flex; gap: 5px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.pager a, .pager span {
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-num); font-size: 12px; text-decoration: none;
  border: 1px solid var(--line); color: var(--ink-2);
}
.pager .is-current { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pager .count { border: 0; color: var(--ink-3); margin-left: auto; }

/* ── Modal tweaks ──────────────────────────────────────────────────────── */

.modal-content {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px;
}
.modal-header, .modal-footer { border-color: var(--line); }
.modal-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; }

/* ── Responsive ────────────────────────────────────────────────────────── */

.rail-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 49; }

@media (max-width: 991.98px) {
  .rail {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .rail.is-open { transform: none; }
  .page { padding: 16px 14px 60px; }
  .kpi .k-value { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── Print ─────────────────────────────────────────────────────────────── */

@media print {
  .rail, .topbar, .filters, .btn-x, .pager { display: none !important; }
  body { background: #fff; color: #000; }
  .card-x { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
  .page { padding: 0; }
}

/* ── Bill attachments ──────────────────────────────────────────────────── */

.doc-link {
  display: inline-flex; align-items: baseline; gap: 5px;
  text-decoration: none; color: var(--ink-2); font-size: 12px; font-weight: 500;
}
.doc-link:hover { color: var(--water); text-decoration: underline; }
.doc-size { color: var(--ink-3); font-family: var(--font-num); font-size: 10px; }

.file-hint { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

.file-current {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 8px; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px;
}
.file-current a { font-size: 12px; font-weight: 500; text-decoration: none; }
.file-current a:hover { text-decoration: underline; }
.file-remove {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-2); margin-left: auto; cursor: pointer;
}

/* File inputs need a little help to match the other controls. */
input[type="file"].form-ctl { height: auto; padding: 6px 8px; font-size: 12px; }
