/* rent.michaelchen.co.nz — app shell: sidebar on desktop, bottom tabs on phone. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --fg: #0f172a;
  --muted: #5b6678;
  --border: #e2e8f0;
  --primary: #1e40af;
  --primary-soft: #e8eefc;
  --on-primary: #ffffff;
  --accent: #047857;
  --accent-soft: #e3f4ee;
  --warn: #a15c00;
  --warn-soft: #fdf1dd;
  --danger: #c0262d;
  --danger-soft: #fde8e8;
  --scrim: rgba(15, 23, 42, .42);
  --sh-1: 0 1px 2px rgba(15, 23, 42, .05), 0 2px 8px rgba(15, 23, 42, .04);
  --sh-2: 0 12px 32px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .06);
  --head: "Lexend", system-ui, -apple-system, "Segoe UI", sans-serif;
  --body: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a; --surface: #16213b; --surface-2: #101a34; --fg: #f1f5f9; --muted: #9aa8bf; --border: rgba(255,255,255,.08);
    --primary: #6b8cf5; --primary-soft: rgba(107,140,245,.14); --on-primary: #0b1226;
    --accent: #34d399; --accent-soft: rgba(52,211,153,.13); --warn: #f5b553; --warn-soft: rgba(245,181,83,.13); --danger: #f87171; --danger-soft: rgba(248,113,113,.13);
    --scrim: rgba(2, 6, 23, .6); --sh-1: 0 1px 2px rgba(0,0,0,.3); --sh-2: 0 16px 40px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --surface: #16213b; --surface-2: #101a34; --fg: #f1f5f9; --muted: #9aa8bf; --border: rgba(255,255,255,.08);
  --primary: #6b8cf5; --primary-soft: rgba(107,140,245,.14); --on-primary: #0b1226;
  --accent: #34d399; --accent-soft: rgba(52,211,153,.13); --warn: #f5b553; --warn-soft: rgba(245,181,83,.13); --danger: #f87171; --danger-soft: rgba(248,113,113,.13);
  --scrim: rgba(2, 6, 23, .6); --sh-1: 0 1px 2px rgba(0,0,0,.3); --sh-2: 0 16px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--head); font-weight: 600; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
.num { font-variant-numeric: tabular-nums; }
button, a { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button { background: none; border: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 20px; height: 20px; flex: none; }

.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px; border-radius: 10px; font-weight: 600; font-size: .95rem; border: 1px solid var(--border); background: var(--surface); transition: background-color 200ms var(--ease), border-color 200ms var(--ease), transform 150ms var(--ease); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { border-color: var(--primary); }
  .btn-primary:hover { filter: brightness(1.08); }
  .side a:hover { background: var(--surface-2); }
  .trow:hover { background: var(--surface-2); }
  .pcard:hover { border-color: var(--primary); box-shadow: var(--sh-2); }
}

/* ---------- Sign in ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding-block: 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--sh-2); padding: 32px; display: flex; flex-direction: column; gap: 18px; }
.auth-card .brand { margin-bottom: 4px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-card p { margin: 4px 0 0; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.field input, .field select { font: inherit; font-weight: 400; font-size: 1rem; color: var(--fg); min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); width: 100%; transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease); }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.help { font-weight: 400; font-size: .85rem; color: var(--muted); }
.err { color: var(--danger); font-weight: 500; font-size: .85rem; min-height: 1.2em; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: rot 600ms linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.side { position: sticky; top: 0; height: 100dvh; padding: 24px 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand svg { width: 34px; height: 34px; }
.brand b { font-family: var(--head); font-weight: 600; display: block; }
.brand small { color: var(--muted); font-size: .8rem; }
.side a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; transition: background-color 200ms var(--ease), color 200ms var(--ease); }
.side a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.side .grow { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--border); }
.me .av { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-family: var(--head); font-weight: 600; font-size: .85rem; display: grid; place-items: center; }
.me div { flex: 1; min-width: 0; font-size: .9rem; } .me small { display: block; color: var(--muted); }
main { min-width: 0; padding: 32px 40px 56px; padding-right: max(40px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 28px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.page-head h1 { font-size: 1.75rem; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: .92rem; text-decoration: none; min-height: 44px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--sh-1); min-width: 0; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi .lab { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: .88rem; }
.kpi .ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi .ico.g { background: var(--accent-soft); color: var(--accent); }
.kpi .ico.w { background: var(--warn-soft); color: var(--warn); }
.kpi .val { font-family: var(--head); font-weight: 600; font-size: 1.75rem; line-height: 1.15; }
.kpi .sub { color: var(--muted); font-size: .88rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transform-origin: left; transition: transform 700ms var(--ease); }

.cols { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 1.05rem; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { text-align: left; font-weight: 600; font-size: .8rem; color: var(--muted); padding: 10px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.trow { cursor: pointer; transition: background-color 200ms var(--ease); }
.r { text-align: right; white-space: nowrap; }
.m { color: var(--muted); }
.pname { font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: var(--accent-soft); color: var(--accent); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.Due, .badge.Part { background: var(--warn-soft); color: var(--warn); }
.badge.Overdue, .badge.Unpaid { background: var(--danger-soft); color: var(--danger); }
.badge.Upcoming { background: var(--primary-soft); color: var(--primary); }

.hbars { padding: 14px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.hb { display: grid; grid-template-columns: 7.5rem 1fr auto; gap: 12px; align-items: center; font-size: .9rem; }
.hb .t { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.hb .t i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transform-origin: left; transition: transform 700ms var(--ease); }
.hb .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 16px; }
.pcard { text-decoration: none; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease), transform 150ms var(--ease); }
.pcard:active { transform: scale(0.985); }
.pcard .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pcard h3 { font-size: 1.1rem; }
.pcard .who { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.pcard dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.pcard dt { color: var(--muted); font-size: .8rem; font-weight: 600; }
.pcard dd { margin: 0; font-weight: 600; }

/* Property page */
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.span2 { grid-column: 1 / -1; }
.fold-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; min-height: 44px; }
.fold-btn svg { transition: transform 200ms var(--ease); color: var(--muted); }
.fold-btn[aria-expanded="false"] svg { transform: rotate(-90deg); }
.more { width: 100%; min-height: 44px; padding: 0 20px; text-align: left; color: var(--primary); font-weight: 600; font-size: .92rem; border-top: 1px solid var(--border); }
.empty { padding: 20px; color: var(--muted); }
.total td { font-weight: 600; background: var(--surface-2); }

/* Bottom tabs (phone) */
.tabs { display: none; }

/* Modal */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease); z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.modal { position: fixed; left: 50%; top: 50%; z-index: 41; width: min(480px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--surface); border-radius: 18px; box-shadow: var(--sh-2); padding: 24px; display: flex; flex-direction: column; gap: 16px; opacity: 0; transform: translate(-50%, -48%) scale(0.97); pointer-events: none; transition: opacity 150ms var(--ease), transform 150ms var(--ease); }
.modal.open { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; transition: opacity 220ms var(--ease), transform 250ms var(--ease); }
.modal h2 { font-size: 1.25rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--muted); transition: background-color 200ms var(--ease), color 200ms var(--ease); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--sh-1); }
.g2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 14px; }
.mfoot { display: flex; justify-content: flex-end; gap: 10px; }

/* Toast */
.toasts { position: fixed; right: max(20px, env(safe-area-inset-right, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100% - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); box-shadow: var(--sh-2); transition: opacity 250ms var(--ease), transform 250ms var(--ease); }
@starting-style { .toast { opacity: 0; transform: translateY(12px); } }
.toast.out { opacity: 0; transform: translateY(12px); transition-duration: 150ms; }
.toast b { display: block; } .toast span { color: var(--muted); font-size: .88rem; }

/* Load stagger, visible at rest if motion is reduced */
.stg > * { animation: up 400ms var(--ease) both; }
.stg > *:nth-child(2) { animation-delay: 60ms; } .stg > *:nth-child(3) { animation-delay: 120ms; } .stg > *:nth-child(4) { animation-delay: 180ms; } .stg > *:nth-child(n+5) { animation-delay: 240ms; }
@keyframes up { from { opacity: 0; transform: translateY(12px); } }

@media (max-width: 1060px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols, .dgrid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 20px 16px calc(96px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); gap: 20px; }
  .tabs { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
  .tabs a, .tabs button { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .75rem; font-weight: 600; color: var(--muted); text-decoration: none; border-radius: 10px; }
  .tabs [aria-current="page"] { color: var(--primary); }
  .kpis { gap: 12px; }
  .kpi .val { font-size: 1.4rem; }
  .hide-sm { display: none; }
  td, th { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .stg > * { animation: none; }
  .bar i, .hb .t i { transition: none; }
  .modal, .modal.open { transition: opacity 150ms linear; }
  .btn:active, .pcard:active { transform: none; }
}

/* ---------- Production additions ---------- */
.card-head .fold-btn { flex: 1; min-width: 0; }
.card-head .fold-btn p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; font-weight: 400; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: .88rem; }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); margin-right: auto; }
.btn[disabled] { opacity: .6; cursor: default; }
.badge.No { background: var(--surface-2); color: var(--muted); }
.badge.Short, .badge.Ends { background: var(--warn-soft); color: var(--warn); }
.badge.Rent { background: var(--primary-soft); color: var(--primary); }
.badge.Water { background: var(--accent-soft); color: var(--accent); }
.badge.Expense { background: var(--danger-soft); color: var(--danger); }
.badge.Other { background: var(--surface-2); color: var(--muted); }
.sm { font-size: .85rem; }
.warn-t { color: var(--warn); }
.seg { grid-template-columns: repeat(var(--n, 3), 1fr); }
.seg.sub { padding: 3px; }
.seg.sub button { min-height: 36px; font-size: .9rem; }
.field textarea { font: inherit; font-weight: 400; font-size: 1rem; color: var(--fg); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); width: 100%; min-height: 72px; resize: vertical; }
.field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.mfoot { flex-wrap: wrap; }
.linkish { color: var(--primary); font-weight: 600; font-size: .92rem; min-height: 44px; padding: 0; align-self: flex-start; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.filters .field { font-size: .82rem; }
.details { margin: 0; padding: 16px 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px 20px; }
.details dt { color: var(--muted); font-size: .8rem; font-weight: 600; }
.details dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.banner { padding: 14px 18px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 40px 0; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn { justify-content: flex-start; width: 100%; }
.ok { color: var(--accent); font-weight: 600; font-size: .88rem; min-height: 1.2em; }
.page-head .acts { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
@media (max-width: 760px) {
  .page-head .acts { width: 100%; }
  .page-head .acts .btn { flex: 1; }
  .desk { display: none; }
}
.me div span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num { white-space: nowrap; }
