/* ============================================================================
   Utilitaria — styles
   Design language (see build brief §7–8):
     • Neutral ground: paper-white surfaces, near-black text, hairline borders.
     • The three STATUS COLOURS (green/amber/red) plus a quiet blue carry ALL
       meaning and are the only saturated colour anywhere.
     • One clean sans for UI; a monospaced face with tabular numerals for money,
       meter readings and account references — the ledger feel is the identity.
     • Sentence case; plain-verb buttons; visible keyboard focus; minimal motion.
     • Comfortable on a phone at 390px wide.
   ========================================================================== */

:root {
  /* Neutral ground */
  --bg:        #f5f6f7;
  --paper:     #ffffff;
  --ink:       #17191d;
  --ink-soft:  #40454d;
  --muted:     #6b7280;
  --line:      #e4e6e9;
  --line-strong:#d3d6da;
  --hover:     #f0f1f3;

  /* Status colours — the only saturated colour in the interface */
  --green:     #157f3c;
  --green-bg:  #e7f4ec;
  --amber:     #9a6a00;
  --amber-dot: #e0a800;
  --amber-bg:  #fbf1da;
  --red:       #c62828;
  --red-bg:    #fbe9e9;
  --blue:      #2f6fb0;   /* "neutral / to pay" — informational, not an alarm */
  --blue-bg:   #e8f0f8;
  --grey-dot:  #9aa0a6;   /* exempt */

  --focus:     #2f6fb0;

  --radius:    8px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(20,24,31,.06), 0 1px 1px rgba(20,24,31,.04);
  --shadow-lg: 0 10px 30px rgba(20,24,31,.16);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

/* Numbers, money, references and readings use the mono face with tabular figures. */
.mono, .num, code, .ref, .money, input[inputmode="decimal"], td.num, th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; margin: 0; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 .6em; }
a  { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ---- Focus: always visible ---- */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================================
   Buttons & controls
   ========================================================================== */
button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  padding: .5rem .8rem;
  border-radius: var(--radius-sm);
  line-height: 1.2;
  transition: background .08s ease, border-color .08s ease;
}
button:hover, .btn:hover { background: var(--hover); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn-primary:hover { background: #000; }

.btn-sm { padding: .3rem .55rem; font-size: .85rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { color: var(--red); border-color: #e8c9c9; }
.btn-danger:hover { background: var(--red-bg); }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

label { display: block; font-size: .82rem; color: var(--ink-soft); margin: 0 0 .25rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 2px rgba(47,111,176,.2); }
textarea { min-height: 4.5rem; resize: vertical; }
.field { margin-bottom: .8rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.hint { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.warn-flag { color: var(--red); font-weight: 600; }

/* ============================================================================
   Layout scaffold
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: .55rem 1rem;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 600; letter-spacing: -.01em; }
.brand .marque { display: grid; grid-template-columns: 7px 7px; grid-template-rows: 7px 7px; gap: 3px; }
.brand .marque i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.brand .marque i:nth-child(1){ background: var(--green); }
.brand .marque i:nth-child(2){ background: var(--amber-dot); }
.brand .marque i:nth-child(3){ background: var(--red); }
.brand .marque i:nth-child(4){ background: var(--blue); }

.nav { display: flex; gap: .25rem; margin-left: .5rem; flex-wrap: wrap; }
.nav a { color: var(--ink-soft); padding: .35rem .6rem; border-radius: var(--radius-sm); }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { background: var(--ink); color: #fff; }

.topbar .spacer { flex: 1; }
.user { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--muted); }
.user .email { font-family: var(--mono); color: var(--ink-soft); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .85rem; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 1rem; }
.section { margin-bottom: 1.5rem; }
.section > h2 { margin-bottom: .6rem; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.empty { color: var(--muted); padding: 1rem; text-align: center; font-size: .9rem; }
.sep { border: none; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ============================================================================
   Status dots & pills — shared vocabulary (see status engine)
   ========================================================================== */
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; background: var(--grey-dot); }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber-dot); }
.dot.red   { background: var(--red); }
.dot.blue  { background: var(--blue); }
.dot.grey  { background: var(--grey-dot); }
.dot.unanswered { background: transparent; border: 2px dashed var(--line-strong); box-sizing: border-box; }

.pill {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .75rem; font-weight: 600; letter-spacing: .01em;
  padding: .18rem .5rem; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.pill .dot { width: 8px; height: 8px; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red   { background: var(--red-bg);   color: var(--red); }
.pill.blue  { background: var(--blue-bg);  color: var(--blue); }
.pill.grey  { background: var(--hover);    color: var(--muted); }
.pill.unanswered { background: transparent; color: var(--ink-soft); border: 1px dashed var(--line-strong); }

/* ============================================================================
   Dashboard — metric tiles
   ========================================================================== */
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: .7rem; margin-bottom: 1.5rem; }
.tile {
  text-align: left; display: block;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; box-shadow: var(--shadow); color: inherit;
}
.tile:hover { background: var(--hover); text-decoration: none; }
.tile .n { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.6rem; font-weight: 600; line-height: 1; }
.tile .k { font-size: .74rem; color: var(--muted); margin-top: .4rem; }
.tile.is-red .n   { color: var(--red); }
.tile.is-amber .n { color: var(--amber); }
.tile.is-zero .n  { color: var(--ink); }

/* ============================================================================
   Portfolio dot grid — the signature element
   ========================================================================== */
.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.portfolio { border-collapse: collapse; width: 100%; min-width: 560px; }
table.portfolio th, table.portfolio td { padding: .5rem .4rem; text-align: center; }
table.portfolio thead th {
  font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: none;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper);
}
table.portfolio th.prop, table.portfolio td.prop { text-align: left; white-space: nowrap; }
table.portfolio td.prop { font-weight: 500; }
table.portfolio td.prop .code { font-family: var(--mono); color: var(--muted); font-size: .78rem; margin-right: .4rem; }
table.portfolio tbody tr { border-bottom: 1px solid var(--line); }
table.portfolio tbody tr:hover { background: var(--hover); }
.cell-btn {
  border: none; background: transparent; padding: .35rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.cell-btn:hover { background: var(--line); }
.cell-btn .dot { width: 14px; height: 14px; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: .8rem 1.1rem; font-size: .78rem; color: var(--ink-soft); margin-top: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }

/* ============================================================================
   Property view — sidebar + supply cards
   ========================================================================== */
.property-layout { display: grid; grid-template-columns: 250px 1fr; gap: 1rem; align-items: start; }
.prop-list { list-style: none; margin: 0; padding: 0; }
.prop-list li { margin: 0; }
.prop-list button {
  width: 100%; text-align: left; border: none; background: transparent;
  display: flex; align-items: center; gap: .55rem; padding: .55rem .6rem; border-radius: var(--radius-sm);
}
.prop-list button:hover { background: var(--hover); }
.prop-list button.active { background: var(--ink); color: #fff; }
.prop-list button.active .code { color: #c9ccd1; }
.prop-list .code { font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.prop-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.supply-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .8rem; }
.supply-card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
  padding: .8rem; box-shadow: var(--shadow); text-align: left; width: 100%; display: block;
}
.supply-card:hover { background: var(--hover); }
.supply-card .top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.supply-card .util { font-weight: 600; }
.supply-card .supplier { font-size: .85rem; color: var(--ink-soft); }
.supply-card .line { font-size: .82rem; color: var(--muted); margin-top: .3rem; min-height: 1.1em; }
.supply-card.exempt { background: var(--bg); color: var(--muted); box-shadow: none; }
.supply-card.exempt .util { color: var(--ink-soft); }
.supply-card.unanswered { border-style: dashed; background: repeating-linear-gradient(135deg, transparent, transparent 8px, #fafbfc 8px, #fafbfc 16px); }
.supply-card.unanswered .answer { display: flex; gap: .5rem; margin-top: .6rem; }

/* ============================================================================
   Tables (monthly checks, history)
   ========================================================================== */
.data-table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.data-table th, .data-table td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table thead th { font-size: .74rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.data-table td.num, .data-table th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--hover); }
.variance-amber { color: var(--amber); font-weight: 600; }

/* ============================================================================
   Timelines (notes, calls)
   ========================================================================== */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .meta { font-size: .76rem; color: var(--muted); display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .2rem; }
.timeline .meta .who { font-family: var(--mono); }
.timeline .body { font-size: .9rem; white-space: pre-wrap; }
.call-item .org { font-weight: 600; }
.call-item .followup { margin-top: .3rem; }

/* ============================================================================
   Login
   ========================================================================== */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { justify-content: center; margin-bottom: .3rem; font-size: 1.2rem; }
.login-card .tagline { text-align: center; color: var(--muted); font-size: .82rem; margin-bottom: 1.2rem; }
.form-error { background: var(--red-bg); color: var(--red); border: 1px solid #e8c9c9; border-radius: var(--radius-sm); padding: .55rem .7rem; font-size: .85rem; margin-bottom: .8rem; }

/* ============================================================================
   Modal / detail layer
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,31,.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2rem 1rem; z-index: 60; overflow-y: auto;
}
.modal {
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 680px; margin: auto;
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); border-radius: var(--radius) var(--radius) 0 0; }
.modal-body { padding: 1.1rem; }
.modal-close { border: none; background: transparent; font-size: 1.3rem; line-height: 1; padding: .2rem .5rem; border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--hover); }

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem 1.2rem; margin: 0 0 1rem; }
.facts .f { display: flex; flex-direction: column; }
.facts .f dt { font-size: .74rem; color: var(--muted); }
.facts .f dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.facts .f dd.text { font-family: var(--sans); }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 0 0 1rem; flex-wrap: wrap; }
.tabs button { border: none; background: transparent; padding: .5rem .7rem; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

/* Toast */
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: var(--radius);
  font-size: .85rem; z-index: 80; box-shadow: var(--shadow-lg); max-width: 90vw;
}
.toast.err { background: var(--red); }

/* ============================================================================
   Responsive — must be comfortable at 390px
   ========================================================================== */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .property-layout { grid-template-columns: 1fr; }
  .prop-list { display: flex; overflow-x: auto; gap: .3rem; padding-bottom: .3rem; }
  .prop-list button { white-space: nowrap; }
  .prop-list .nm { max-width: 40vw; }
}
@media (max-width: 620px) {
  body { font-size: 14px; }
  .wrap { padding: .75rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .supply-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .nav { display: none; }              /* replaced by the menu button on small screens */
  .nav.open { display: flex; position: absolute; top: 100%; left: 0; right: 0; background: var(--paper); border-bottom: 1px solid var(--line); flex-direction: column; padding: .5rem; }
  .topbar { position: relative; }
  .modal-backdrop { padding: 0; }
  .modal { border-radius: 0; min-height: 100dvh; max-width: none; }
}
@media (min-width: 621px) { .menu-btn { display: none; } }

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