/* HomeVault — steel vault palette.
   Meaning colors are PROTECTED (Kenzie's rule): red = overdue/urgent,
   yellow/amber = due soon / warnings, metallic gold = calendar follow-ups,
   green = Save buttons and handled checkmarks, dedicated orange = the back
   button, blue = Notes. Palette changes must never recolor those. */
:root {
  --bg: #e8eaec;
  --surface: #f7f8f9;
  --surface-muted: #dfe3e6;
  --text: #16181a;
  --muted: #5a6167;
  --border: #c3c9cd;
  --accent: #4c565e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --amber: #a87400;
  --amber-bg: #fdf3d7;
  --gold: #b8912a;
  --save: #5f7a4c;
  --back: #c05a2e;
  --blue: #2f6db3;
  --shadow: 0 2px 10px rgba(20, 24, 28, .14);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --surface: #1b1e21;
    --surface-muted: #26292d;
    --text: #e8eaec;
    --muted: #a7adb3;
    --border: #3a3f44;
    --accent: #c8ced3;
    --accent-text: #16181a;
    --danger: #e0655c;
    --amber: #e0aa3e;
    --amber-bg: #3a2f14;
    --gold: #d4af37;
    --save: #7f9c68;
    --back: #e07f45;
    --blue: #6ea8e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: var(--danger); }
h1, h2, h3 { line-height: 1.2; }
a { color: var(--blue); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 10px; padding: 9px 14px; font-size: 15px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.save { background: var(--save); color: #fff; border-color: var(--save); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  appearance: none; border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-muted); }

/* ---------- forms ---------- */
label { display: block; margin: 10px 0; font-weight: 600; font-size: 14.5px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 11px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  color: var(--text); font: inherit; font-weight: 400;
}
textarea { min-height: 74px; resize: vertical; }
input[type="checkbox"] { display: inline-block; width: auto; margin: 0 7px 0 0; }
.check-row { display: flex; align-items: center; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

/* ---------- auth ---------- */
#authView { max-width: 520px; margin: 0 auto; padding: 26px 16px 60px; }
.auth-hero { text-align: center; margin-bottom: 18px; }
.auth-hero h1 { margin: 8px 0 2px; font-size: 34px; letter-spacing: .5px; }
.tagline { font-weight: 700; color: var(--accent); margin: 2px 0 8px; }
@media (prefers-color-scheme: dark) { .tagline { color: var(--text); } }
.auth-sub { color: var(--muted); font-size: 14.5px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; margin: 14px 0; box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; }

/* ---------- app chrome ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 14px;
}
#householdName { font-weight: 800; font-size: 18px; }
.topbar-title { flex: 1; min-width: 0; }
.back-btn {
  appearance: none; border: none; cursor: pointer; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--back); color: #fff; font-size: 19px; line-height: 1;
}
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px 2px;
  scrollbar-width: thin;
}
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 999px; padding: 6px 13px; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: #f6d9c8; border-color: var(--back); }
@media (prefers-color-scheme: dark) { .chip.active { background: #4a3125; } }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.red { background: var(--danger); }
.dot.blue { background: var(--blue); }
.dot.gold { background: var(--gold); }

#appLayout { display: grid; grid-template-columns: 248px 1fr; gap: 0; align-items: start; }
#sidebarNav {
  position: sticky; top: 60px; padding: 12px 10px 30px; display: flex; flex-direction: column; gap: 2px;
}
#sidebarNav button {
  appearance: none; border: none; background: transparent; color: var(--text);
  text-align: left; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: 15px;
  display: flex; gap: 8px; align-items: baseline;
}
#sidebarNav button .num { color: var(--muted); font-size: 12.5px; min-width: 18px; }
#sidebarNav button.active { background: var(--surface-muted); font-weight: 700; }
#mainView { padding: 14px 16px 90px; min-width: 0; }
@media (max-width: 820px) {
  #appLayout { grid-template-columns: 1fr; }
  /* Single column: the main content leads and the numbered section menu
     follows it. Without this, the grid stacked #sidebarNav above #mainView
     in DOM order and the 1–14 menu filled the first phone screen. */
  #mainView { order: 1; }
  #sidebarNav { position: static; flex-direction: row; flex-wrap: wrap; padding-bottom: 4px; order: 2; }
  #sidebarNav button { border: 1px solid var(--border); background: var(--surface); }
}

/* ---------- content ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin: 0 0 16px;
}
.panel > h2, .panel > h3 { margin-top: 0; }
.section-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-head h2 { flex: 1; margin: 0; }
.prop-switch { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.prop-switch .chip.active { background: var(--surface-muted); border-color: var(--accent); }
.record {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 10px 0;
  background: var(--surface);
}
.record .r-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.record .r-title { font-weight: 700; font-size: 16.5px; }
.record .r-actions { margin-left: auto; display: flex; gap: 2px; }
.kv { color: var(--muted); font-size: 14px; }
.kv b { color: var(--text); font-weight: 600; }
.money { font-weight: 700; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.badge.red { background: var(--danger); color: #fff; }
.badge.yellow { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber); }
.badge.green { background: var(--save); color: #fff; }
.badge.gray { background: var(--surface-muted); color: var(--muted); }
.badge.gold { background: var(--gold); color: #fff; }
.rate-band {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  background: var(--amber-bg); border: 1px solid var(--amber); border-radius: 10px;
  padding: 8px 12px; margin: 8px 0;
}
.rate-band-label {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--amber);
}
.rate-band-value { font-size: 24px; font-weight: 800; line-height: 1.1; }
.rate-band-value.small { font-size: 16.5px; }
.clearable { display: flex; gap: 6px; align-items: center; }
.clearable input { flex: 1; }
.total-card {
  border: 1.5px dashed var(--accent); border-radius: 12px; padding: 12px 14px; margin: 12px 0;
  background: var(--surface-muted); cursor: pointer; width: 100%; text-align: left; font: inherit; color: var(--text);
}
.scrollbox { max-height: 340px; overflow-y: auto; padding-right: 4px; }
.scroll-hint { color: var(--muted); font-size: 13px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { flex: 1; margin-top: 0; }

/* home */
.attn h2 { color: var(--danger); }
.attn .place { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 10px; }
.attn .place h3 { margin: 4px 0 8px; }
.expiring-title { color: var(--amber); }
.notes-panel h2 { color: var(--blue); }
.note-row { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.note-row .txt { flex: 1; }
.home-card { cursor: pointer; }
.home-card .details-link { float: right; font-style: italic; color: var(--blue); }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quick-tile {
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 13px; cursor: pointer; text-align: left; font: inherit; color: var(--text);
}
.quick-tile .num { display: block; color: var(--muted); font-size: 12.5px; }
.quick-tile .lbl { font-weight: 700; }
.due-strip {
  border: 1.5px solid var(--gold); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px;
  background: var(--surface); cursor: pointer; width: 100%; text-align: left; font: inherit; color: var(--text);
}
.due-strip .gold { color: var(--gold); font-weight: 800; }
.guard-bar {
  border: 1.5px solid var(--amber); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px;
  background: var(--amber-bg); color: var(--text);
}
.guard-bar p { margin: 0 0 8px; }
.check-circle {
  appearance: none; flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer;
  color: #fff; font-size: 14px; line-height: 1; padding: 0;
}
.check-circle.done { background: var(--save); border-color: var(--save); }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-head h3 { flex: 1; text-align: center; margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 12.5px; font-weight: 700; padding: 4px 0; }
.cal-day {
  min-height: 58px; border: 1px solid var(--border); border-radius: 9px; padding: 4px 6px;
  cursor: pointer; background: var(--surface); font-size: 13.5px; position: relative; text-align: left; color: var(--text);
}
.cal-day.dim { opacity: .42; }
.cal-day .dnum { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center; font-weight: 700; }
.cal-day.today .dnum { background: var(--danger); color: #fff; }
.cal-day .star { color: var(--gold); font-size: 15px; }
.cal-day.today .star { color: var(--gold); }
.cal-day .dots { color: var(--muted); letter-spacing: 2px; font-size: 11px; }
.cal-day.selected { outline: 2px solid var(--accent); }

/* contacts */
.az-rail { display: flex; flex-wrap: wrap; gap: 3px; margin: 8px 0; }
.az-rail button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 13px; }
.letter-head { margin: 16px 0 4px; color: var(--muted); }
.stars { font-size: 19px; letter-spacing: 2px; }
.stars button { appearance: none; border: none; background: none; cursor: pointer; font-size: 19px; padding: 0 1px; color: var(--border); }
.stars button.on { color: var(--gold); }
.emerg-pill { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber); }

/* shutoffs */
.shutoff { border-radius: 12px; padding: 12px 14px; margin: 10px 0; border: 1px solid var(--border); }
.shutoff.blue { background: rgba(47, 109, 179, .12); }
.shutoff.amber { background: var(--amber-bg); }
.shutoff.red { background: rgba(179, 38, 30, .10); }
.shutoff.terra { background: rgba(192, 90, 46, .12); }
.shutoff .s-name { font-weight: 800; font-size: 16.5px; }

/* sheet (modal form) */
.sheet-back {
  position: fixed; inset: 0; background: rgba(10, 12, 14, .5); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); color: var(--text); width: min(680px, 100%);
  max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 16px 16px 150px; box-shadow: var(--shadow);
}
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; padding-bottom: 20px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h3 { flex: 1; margin: 0; }

/* toast */
#toastRoot { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90; }
.toast {
  background: var(--save); color: #fff; border-radius: 10px; padding: 10px 16px;
  box-shadow: var(--shadow); font-weight: 600; margin-top: 8px;
}
.toast.err { background: var(--danger); }

/* print */
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; color: #000; background: #fff; }
  #printArea table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
}
.warranty-none { color: var(--danger); font-weight: 800; text-transform: uppercase; }
table.plain { border-collapse: collapse; width: 100%; }
table.plain th, table.plain td { border-bottom: 1px solid var(--border); padding: 7px 6px; text-align: left; font-size: 14.5px; }
