/* =====================================================================
   PropertyLedger v2 — "Sidebar Command" design system
   =====================================================================
   Loaded AFTER style.css. It does not replace the older component CSS;
   it re-skins it and adds the new application shell:

     desktop  →  fixed 248px rail + scrolling work area
     phone    →  app bar + hamburger drawer + bottom tab bar

   Everything here is additive and namespaced to the shell (.rail,
   .appbar, .tabbar, .scrim) except where an existing component class is
   deliberately restyled (.card, .stat-grid, .btn, .costs-table, …).
   ===================================================================== */

:root {
  /* shell */
  --rail:        #16293f;
  --rail-2:      #1d3450;
  --rail-3:      #22405f;
  --rail-ink:    #a9bacd;
  --rail-muted:  #7f95ab;
  --rail-line:   #24405e;
  --rail-accent: #4ade80;

  /* surfaces */
  --line:        #e5e0d6;
  --line-2:      #d4cdbf;
  --line-soft:   #f1ece1;

  /* brand */
  --green:       #16a34a;
  --green-d:     #15803d;
  --green-bg:    #e8f5ec;
  --green-br:    #bfe3ca;
  --amber:       #b45309;
  --amber-bg:    #fdf6e7;
  --navy:        #1e3a5f;

  --radius:      10px;
  --radius-lg:   14px;
}

/* ---------------------------------------------------------------------
   1. Shell
   ------------------------------------------------------------------ */
body.has-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

body.has-shell #app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "rail main";
  height: 100%;
  min-height: 0;
}

/* The work area is the scroll container. Content height is never taken
   by chrome other than the rail, which sits beside it rather than above. */
body.has-shell .main {
  grid-area: main;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 22px 22px 28px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
body.has-shell .main::-webkit-scrollbar { width: 10px; }
body.has-shell .main::-webkit-scrollbar-thumb {
  background: #e0d9cc; border-radius: 10px; border: 3px solid var(--bg);
}

/* ---------------------------------------------------------------------
   2. Rail (desktop) — becomes the drawer on a phone
   ------------------------------------------------------------------ */
.rail {
  grid-area: rail;
  background: var(--rail);
  color: var(--rail-ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.rail-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 12px; color: #fff; flex: 0 0 auto;
}
.rail-brand svg { width: 22px; height: 22px; stroke: var(--rail-accent); flex: 0 0 22px; }
.rail-brand b { display: block; font-size: 15px; letter-spacing: -.2px; font-weight: 700; }
.rail-brand span {
  display: block; font-size: 9px; letter-spacing: .9px; text-transform: uppercase;
  color: var(--rail-muted); font-weight: 800; margin-top: 1px;
}

/* property switcher */
.rail-switch { margin: 2px 10px 8px; flex: 0 0 auto; }
.rail-switch .rs-label {
  font-size: 9px; letter-spacing: .9px; text-transform: uppercase;
  color: #5d7794; font-weight: 800; padding: 0 4px 5px;
}
.rail-switch a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; min-height: 46px;
  background: var(--rail-2); border: 1px solid #29456a; border-radius: 8px;
  color: inherit; text-decoration: none;
}
.rail-switch a:hover { background: var(--rail-3); text-decoration: none; }
.rail-switch .rs-av {
  width: 26px; height: 26px; border-radius: 6px; background: #0f2033;
  display: grid; place-items: center; color: var(--rail-accent);
  font-size: 10.5px; font-weight: 800; flex: 0 0 26px;
}
.rail-switch .rs-t { min-width: 0; flex: 1; }
.rail-switch .rs-t b {
  display: block; font-size: 12px; color: #e8eef6; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-switch .rs-t i {
  display: block; font-style: normal; font-size: 10px; color: var(--rail-muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-switch .rs-chev { color: #5d7794; font-size: 9px; }

/* nav */
.rail-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 8px 10px; }
.rail-nav::-webkit-scrollbar { width: 5px; }
.rail-nav::-webkit-scrollbar-thumb { background: #2b4664; border-radius: 5px; }

.rail-nav .grp {
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  color: #5d7794; font-weight: 800; padding: 12px 10px 4px;
}
.rail-nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; min-height: 34px; border-radius: 6px;
  color: var(--rail-ink); text-decoration: none; font-size: 13px; position: relative;
}
.rail-nav a:hover { background: #1e3550; color: #dbe6f2; text-decoration: none; }
.rail-nav a.on { background: #20395a; color: #fff; font-weight: 600; }
.rail-nav a.on::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: var(--rail-accent); border-radius: 2px;
}
.rail-nav a .dot {
  width: 6px; height: 6px; border-radius: 50%; background: #3f5b7a; flex: 0 0 6px;
}
.rail-nav a.on .dot { background: var(--rail-accent); }
.rail-nav a .cnt {
  margin-left: auto; font-size: 10.5px; color: var(--rail-muted);
  background: #0f2033; padding: 1px 6px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.rail-nav a.on .cnt { background: #2c4a70; color: #cfe0f0; }

/* footer */
.rail-me {
  flex: 0 0 auto; display: flex; align-items: center; gap: 9px;
  padding: 10px 12px; border-top: 1px solid var(--rail-line);
}
.rail-me .me-av {
  width: 28px; height: 28px; border-radius: 50%; background: #2c4a70; color: #cfe0f0;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: 0 0 28px;
}
.rail-me .me-t { min-width: 0; }
.rail-me .me-n {
  font-size: 12px; color: #dbe6f2; font-weight: 600; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 118px;
}
.rail-me .me-e {
  font-size: 10px; color: var(--rail-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 118px;
}
.rail-me .me-actions { margin-left: auto; display: flex; gap: 2px; }
.rail-me button {
  width: 32px; height: 32px; border: 0; background: transparent; border-radius: 7px;
  color: var(--rail-muted); cursor: pointer; font-size: 13px; line-height: 1;
  display: grid; place-items: center; box-shadow: none; padding: 0;
}
.rail-me button:hover { background: #24405e; color: #fff; }
.rail-version {
  flex: 0 0 auto; padding: 0 12px 10px; font-size: 10px; color: #5d7794; letter-spacing: .2px;
}

/* ---------------------------------------------------------------------
   3. Mobile chrome
   ------------------------------------------------------------------ */
.appbar, .tabbar, .scrim { display: none; }

/* ---------------------------------------------------------------------
   4. Page furniture
   ------------------------------------------------------------------ */
.property-head, .page-head {
  display: flex; align-items: flex-start; gap: 14px;
  padding-bottom: 13px; margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.property-head h1, .page-head h1 {
  font-size: 19px; line-height: 1.25; letter-spacing: -.35px;
  font-weight: 700; margin: 0 0 5px;
}
.property-head .muted, /* legacy meta line */
.page-meta {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-3); margin: 0;
}
.page-meta .sep { color: var(--line-2); }
.property-head > div:last-child,
.page-head .head-actions { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 20px;
  background: #efe9dd; border: 1px solid var(--line-2);
  color: #5b4a2e; font-size: 10.5px; font-weight: 700; white-space: nowrap;
}
.pill.ok { background: var(--green-bg); border-color: var(--green-br); color: var(--green-d); }
.pill.warn { background: var(--amber-bg); border-color: #f0d9a8; color: var(--amber); }

/* the old horizontal tab strip is superseded by the rail / drawer */
.tabs-nav { display: none !important; }

/* ---------------------------------------------------------------------
   5. Cards
   ------------------------------------------------------------------ */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 1px 2px rgba(31, 41, 55, .04), 0 4px 14px rgba(31, 41, 55, .05);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card > h2, .card > h3 {
  font-size: 11.5px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-2); font-weight: 800;
  margin: 0; padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.card > *:not(h2):not(h3) { padding-left: 14px; padding-right: 14px; }
.card > *:not(h2):not(h3):last-child { padding-bottom: 14px; }
.card > *:not(h2):not(h3):first-child { padding-top: 14px; }

/* ---------------------------------------------------------------------
   6. Stat strips / KPI cards
   ------------------------------------------------------------------ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(31, 41, 55, .04);
  margin-bottom: 12px;
}
.stat-card {
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 13px 16px 12px;
  box-shadow: none;
  min-width: 0;
}
.stat-card:last-child { border-right: 0; }
.stat-card .label {
  font-size: 9.5px; letter-spacing: .85px; text-transform: uppercase;
  color: #8a8272; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-card .value {
  font-size: 23px; font-weight: 700; letter-spacing: -.7px; line-height: 1;
  margin-top: 6px; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-card .value.pos { color: var(--green-d); }
.stat-card .value.neg { color: var(--amber); }
.stat-card .sub {
  font-size: 11px; color: var(--text-3); margin-top: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------------------------------------------------------------
   7. Tables
   ------------------------------------------------------------------ */
table { border-collapse: collapse; width: 100%; }
.costs-table, .card table, .sdlt-table { width: 100%; font-size: 12.5px; }
.costs-table th, .card table th, .sdlt-table th {
  text-align: left; font-size: 9.5px; letter-spacing: .75px; text-transform: uppercase;
  color: var(--text-3); font-weight: 800;
  padding: 8px 14px; background: #faf6ef; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.costs-table td, .card table td, .sdlt-table td {
  padding: 8px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle;
}
.costs-table tbody tr:last-child td, .card table tbody tr:last-child td { border-bottom: 0; }
.costs-table tbody tr:hover, .card table tbody tr:hover { background: #fdfbf7; }
.costs-table .amount, .costs-table td.amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.costs-table .actions { text-align: right; white-space: nowrap; }
tfoot td { border-top: 1px solid var(--line-2); background: #fdfbf7; font-weight: 700; }

/* ---------------------------------------------------------------------
   8. Badges — dot + word, matching the ledger statuses
   ------------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0; border: 0; background: none; border-radius: 0;
  font-size: 11px; font-weight: 700; letter-spacing: 0; text-transform: none;
  color: var(--text-2);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: #cbd5e1; flex: 0 0 6px;
}
.badge-paid { background: none; border: 0; color: var(--green-d); }
.badge-paid::before { background: var(--green); }
.badge-quote { background: none; border: 0; color: var(--amber); }
.badge-quote::before { background: #f59e0b; }
.badge-status { background: none; border: 0; color: var(--text-3); }

/* ---------------------------------------------------------------------
   9. Buttons
   ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line-2); background: #fff; color: var(--text-2);
  box-shadow: none; cursor: pointer; text-decoration: none; line-height: 1.4;
}
.btn:hover { background: #faf6ef; border-color: #c3bbab; color: var(--text); text-decoration: none; }
.btn:active { transform: none; }
.btn-secondary { background: #fff; border: 1px solid var(--line-2); color: var(--text-2); }
.btn-secondary:hover { background: #faf6ef; border-color: #c3bbab; }
.btn-primary, .btn:not(.btn-secondary):not(.btn-danger):not(.btn-danger-outline):not(.btn-sm) {
  /* default button stays the brand green, as before */
}
.btn.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.btn-primary:hover { background: var(--green-d); border-color: var(--green-d); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline { background: #fff; border: 1px solid #e6c9c9; color: var(--danger); }
.btn-danger-outline:hover { background: #fdf3f3; border-color: #d9a8a8; color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 11.5px; border-radius: 6px; min-height: 30px; }

/* the "+ Add cost" action is the page's primary button — make it green */
.property-head .btn-primary,
.head-actions .btn-primary { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------------------------------------------------------------------
   10. Sub-tabs → pill chips
   ------------------------------------------------------------------ */
.subtabs-nav {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin: 0 0 12px; padding: 0; border: 0;
}
.subtab-btn {
  border: 1px solid var(--line-2); background: #fff; border-radius: 20px;
  padding: 6px 12px; font-size: 11.5px; font-weight: 700; color: var(--text-2);
  cursor: pointer; box-shadow: none;
}
.subtab-btn:hover { background: #faf6ef; }
.subtab-btn.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.subtab-pane { display: none; }
.subtab-pane.active { display: block; }

/* ---------------------------------------------------------------------
   11. Forms
   ------------------------------------------------------------------ */
label { font-size: 12px; font-weight: 600; color: var(--text-2); }
input, select, textarea {
  background: #fff; border: 1px solid var(--line-2); border-radius: 7px;
  padding: 10px 12px; font-size: 16px; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 163, 74, .16); outline: none;
}
.form-section { border-top: 1px solid var(--line); }
.form-section h2 { color: var(--text); font-size: 11.5px; letter-spacing: .6px; text-transform: uppercase; font-weight: 800; }

/* ---------------------------------------------------------------------
   12. Dashboard
   ------------------------------------------------------------------ */
.property-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.property-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: 0 1px 2px rgba(31, 41, 55, .04);
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.property-card:hover { border-color: var(--green-br); box-shadow: 0 4px 16px rgba(31, 41, 55, .08); }
.property-card .address { font-size: 14px; font-weight: 700; letter-spacing: -.2px; }
.property-card .meta { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.property-card .role-badge {
  margin-left: 7px; font-size: 9.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase;
  padding: 1px 6px; border-radius: 4px; background: #f2ede3; color: #5b4a2e; vertical-align: 2px;
}

.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #faf6ef; border: 1px solid var(--line); border-radius: 20px;
  padding: 3px 10px; font-size: 11.5px; font-weight: 600; color: var(--text-2);
}
.status-chip-count { color: var(--text-3); font-variant-numeric: tabular-nums; }

.spend-bars { display: flex; flex-direction: column; gap: 9px; }
.spend-bar-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.5fr) auto; gap: 12px; align-items: center; }
.spend-bar-label { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spend-bar-pct { margin-left: 6px; font-size: 11.5px; font-weight: 700; color: var(--text-3); }
.spend-bar-track { height: 6px; background: #f0ebdf; border-radius: 4px; overflow: hidden; }
.spend-bar-fill { height: 100%; background: var(--green); border-radius: 4px; font-size: 0; }
.spend-bar-value { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   13. Modals
   ------------------------------------------------------------------ */
.modal { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 24px 60px rgba(15, 32, 51, .26); }
.modal h2 { font-size: 16px; letter-spacing: -.2px; }

/* ---------------------------------------------------------------------
  14. Touch layout — phones, and tablets / desktop-mode phones

  The breakpoint is 1024px, not 900px, because a phone browser in
  "Request desktop site" mode lays the page out at a 980px viewport.
  At a 900px breakpoint that device got the DESKTOP rail: a 248px
  sidebar, everything scaled to ~40%, and 70% of the screen left blank
  below the fold. 980 < 1024 so those devices now get the touch shell.
   ------------------------------------------------------------------ */
@media (max-width: 1024px) {
  body.has-shell #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 58px minmax(0, 1fr) calc(60px + env(safe-area-inset-bottom));
    grid-template-areas: "appbar" "main" "tabbar";
  }

  /* app bar */
  .appbar {
    grid-area: appbar;
    display: flex; align-items: center; gap: 8px;
    padding: 0 8px 0 6px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    z-index: 20;
  }
  .appbar .ico-btn {
    width: 44px; height: 44px; flex: 0 0 44px;
    border: 0; background: transparent; border-radius: 10px;
    display: grid; place-items: center; cursor: pointer; padding: 0;
    color: var(--text-2); box-shadow: none;
  }
  .appbar .ico-btn:active { background: #ece6da; }
  .appbar .bars { width: 18px; height: 2px; background: currentColor; border-radius: 2px; position: relative; display: block; }
  .appbar .bars::before, .appbar .bars::after {
    content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: currentColor; border-radius: 2px;
  }
  .appbar .bars::before { top: -6px; }
  .appbar .bars::after { top: 6px; }
  .appbar .ab-title { min-width: 0; flex: 1; padding: 0 2px; }
  .appbar .ab-title b {
    display: block; font-size: 14.5px; font-weight: 700; letter-spacing: -.2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .appbar .ab-title i {
    display: block; font-style: normal; font-size: 11px; color: var(--text-3); margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .appbar .ab-add {
    width: 44px; height: 44px; flex: 0 0 44px; border: 0; background: transparent;
    display: grid; place-items: center; cursor: pointer; padding: 0; box-shadow: none;
  }
  .appbar .ab-add span {
    width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: #fff;
    display: grid; place-items: center; font-size: 20px; line-height: 1;
    box-shadow: 0 2px 6px rgba(22, 163, 74, .30);
  }
  .appbar .ab-add[hidden] { display: none; }

  /* rail becomes a drawer */
  .rail {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; max-width: 84%;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.3, .7, .3, 1);
    box-shadow: 16px 0 44px rgba(15, 32, 51, .35);
  }
  .rail.open { transform: none; }

  .scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15, 32, 51, .42);
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
    z-index: 50;
  }
  .scrim.open { opacity: 1; pointer-events: auto; }

  /* bottom bar */
  .tabbar {
    grid-area: tabbar;
    display: flex; align-items: stretch;
    background: #fff;
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
  }
  .tabbar a, .tabbar button {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: 0; box-shadow: none; padding: 0;
    color: var(--text-3); font-size: 9.5px; font-weight: 700; letter-spacing: .2px;
    text-decoration: none; cursor: pointer; min-height: 44px;
  }
  .tabbar a.on { color: var(--green-d); }
  .tabbar .tb-ic { width: 20px; height: 20px; display: grid; place-items: center; color: #8a8272; }
  .tabbar .tb-ic svg { width: 20px; height: 20px; }
  .tabbar a.on .tb-ic { color: var(--green-d); }

  /* work area */
  body.has-shell .main { padding: 12px 16px 20px; }

  /* page head */
  .property-head, .page-head {
    gap: 10px; padding-bottom: 10px; margin-bottom: 12px;
  }
  .property-head h1, .page-head h1 { font-size: 18px; }
  .property-head .muted, .page-meta { font-size: 11.5px; }
  .property-head > div:last-child, .page-head .head-actions {
    margin-left: 0; width: 100%;
  }

  /* stat strip → 2 × 2 cards */
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px; background: transparent; border: 0; box-shadow: none; overflow: visible;
  }
  .stat-card {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
    padding: 12px 13px; min-height: 78px;
    display: flex; flex-direction: column; justify-content: space-between;
    box-shadow: 0 1px 2px rgba(31, 41, 55, .04);
  }
  .stat-card:nth-child(2n) { border-right: 1px solid var(--line); }
  /* An odd number of stat cards would leave a single orphan in the last row.
     The first card (the headline total) spans both columns instead. */
  .stat-grid > .stat-card:first-child:nth-last-child(odd) { grid-column: 1 / -1; border-right: 0; }
  .stat-card .label { font-size: 10px; white-space: normal; }
  .stat-card .value { font-size: 20px; white-space: normal; }
  .stat-card .sub { font-size: 11.5px; white-space: normal; }

  .card > h2, .card > h3 { font-size: 11.5px; padding: 11px 13px; }
  .card > *:not(h2):not(h3) { padding-left: 13px; padding-right: 13px; }

  /* wide tables stack into labelled rows */
  .costs-table thead { display: none; }
  .costs-table, .costs-table tbody, .costs-table tr, .costs-table td { display: block; width: 100%; }
  .costs-table tr {
    border: 1px solid var(--line); border-radius: var(--radius-lg);
    background: #fff; margin-bottom: 8px; padding: 4px 0;
    box-shadow: 0 1px 2px rgba(31, 41, 55, .04);
  }
  .costs-table td {
    display: flex; align-items: center; gap: 10px;
    border: 0; padding: 5px 12px; text-align: left !important;
  }
  .costs-table td::before {
    content: attr(data-label);
    flex: 0 0 88px;
    font-size: 10px; letter-spacing: .6px; text-transform: uppercase;
    color: #8a8272; font-weight: 800;
  }
  .costs-table td:last-child { padding-bottom: 8px; }
  .costs-table tr:hover { background: #fff; }

  /* A <summary> is a control: give it a thumb-sized target. The VAT/row menus
     already declare their own 44px rules and are left alone. */
  body.has-shell .main summary:not(.vat-summary) { min-height: 44px; }

  .property-list { grid-template-columns: minmax(0, 1fr); }
  .spend-bar-row { grid-template-columns: minmax(0, 1fr) auto; }
  .spend-bar-track { grid-column: 1 / -1; order: 3; }
}

/* Very small phones: keep the two-up stat grid but tighten the label */
@media (max-width: 380px) {
  body.has-shell .main { padding: 10px 12px 18px; }
  .stat-card { padding: 10px 11px; min-height: 72px; }
  .stat-card .value { font-size: 18px; }
}

/* ---------------------------------------------------------------------
   15. Dark mode
   ------------------------------------------------------------------ */
:root[data-theme="dark"] {
  --line: #334155;
  --line-2: #475569;
  --line-soft: #27364a;
  --green-bg: #14351f;
  --green-br: #1f5b34;
  --amber-bg: #3a2a10;
}
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .stat-grid,
:root[data-theme="dark"] .property-card,
:root[data-theme="dark"] .modal { background: var(--bg-2); }
:root[data-theme="dark"] .stat-card { background: transparent; }
:root[data-theme="dark"] .costs-table th,
:root[data-theme="dark"] .card table th { background: var(--bg-3); }
:root[data-theme="dark"] .costs-table tbody tr:hover,
:root[data-theme="dark"] .card table tbody tr:hover { background: var(--bg-3); }
:root[data-theme="dark"] .btn { background: var(--bg-3); border-color: var(--line-2); color: var(--text-2); }
:root[data-theme="dark"] .btn:hover { background: var(--line); }
:root[data-theme="dark"] .subtab-btn { background: var(--bg-3); border-color: var(--line-2); }
:root[data-theme="dark"] .pill { background: var(--bg-3); border-color: var(--line-2); color: var(--text-2); }
:root[data-theme="dark"] .tabbar { background: var(--bg-2); }
:root[data-theme="dark"] .appbar { background: var(--bg); }
