:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2430; --muted: #64707d; --line: #dde3ea;
  --brand: #0f4c81; --brand-2: #e8f0f8; --ok: #1d7a46; --warn: #b4540b; --bad: #b42318;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--brand); color: #fff; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: .3px; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { padding: 6px 12px; border-radius: 6px; opacity: .85; }
#nav a.active, #nav a:hover { background: rgba(255,255,255,.15); opacity: 1; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Home */
.home { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px; }
.home h1 { font-size: 34px; margin: 0; }
.big-buttons { display: flex; gap: 32px; flex-wrap: wrap; justify-content: center; }
.big-btn { width: 260px; height: 200px; border-radius: 18px; background: var(--card); border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-decoration: none; color: var(--ink); font-size: 28px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.06); transition: .15s; }
.big-btn:hover { border-color: var(--brand); transform: translateY(-2px); }
.big-btn .icon { font-size: 56px; }
.big-btn .sub { font-size: 14px; font-weight: 400; color: var(--muted); }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; }
textarea { min-height: 80px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-content: start; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; }
.check input { width: auto; }
button, .btn { padding: 8px 16px; border-radius: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: #fff; color: var(--brand); }
button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* Inventory */
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.inv-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.inv-card:hover { border-color: var(--brand); }
.inv-card .ph { aspect-ratio: 4/3; background: #e9edf1 center/cover; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 40px; }
.inv-card .body { padding: 12px; }
.inv-card .title { font-weight: 700; }
.inv-card .price { font-size: 20px; font-weight: 700; color: var(--brand); }
.photos { display: flex; flex-wrap: wrap; gap: 10px; }
.photos .p { position: relative; width: 150px; height: 112px; border-radius: 6px; background: center/cover; border: 1px solid var(--line); }
.photos .p button { position: absolute; top: 4px; right: 4px; padding: 0 7px; font-size: 13px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-2); color: var(--brand); }
.badge.available, .badge.active, .badge.current { background: #e3f4ea; color: var(--ok); }
.badge.pending { background: #fff1e0; color: var(--warn); }
.badge.sold, .badge.paid_off { background: #eceff3; color: var(--muted); }
.badge.late, .badge.repossessed, .badge.charged_off { background: #fde8e6; color: var(--bad); }

/* Quote / TILA */
.quote-lines div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.quote-lines div.total { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px; }
.payment-hero { text-align: center; padding: 12px 0 18px; }
.payment-hero .amt { font-size: 44px; font-weight: 800; color: var(--brand); }
.tila { border: 2px solid var(--ink); border-radius: 4px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 16px; background: #fff; overflow: hidden; }
.tila > div { padding: 10px; outline: 1px solid var(--ink); }
.tila .h { font-weight: 800; text-transform: uppercase; font-size: 12px; }
.tila .d { font-size: 11px; color: var(--muted); min-height: 42px; }
td { overflow-wrap: anywhere; }
td:first-child { white-space: nowrap; }
.tila .v { font-size: 18px; font-weight: 700; margin-top: 6px; }

.notice { background: #fff8e6; border: 1px solid #f0d28a; border-radius: 8px; padding: 10px 12px; font-size: 13px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

@media print {
  .topbar, button, .no-print { display: none !important; }
  main { padding: 0; }
  .card { border: 0; }
}

/* Additions */
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin: -8px 0 18px; border-bottom: 1px solid var(--line); }
.subnav a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.narrow { max-width: 420px; margin: 40px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.bad { color: var(--bad); }
.filter { margin-bottom: 16px; }
.filter input { max-width: 320px; }
.filter select { width: auto; }
.small-btn { padding: 3px 10px; font-size: 13px; }
.logo { max-width: min(560px, 90vw); max-height: 220px; }
.logo-text { font-size: 44px; font-weight: 800; color: var(--brand); letter-spacing: .5px; }
.photos .p .cover { position: absolute; left: 4px; bottom: 4px; background: var(--brand); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.photos .p button[data-cover] { right: auto; left: 4px; }
.qr { margin: 10px 0; }
.tenant-block { margin-bottom: 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
code { background: var(--brand-2); padding: 1px 5px; border-radius: 4px; }
.print-only { display: none; }
.letter { max-width: 680px; margin: 0 auto; font-size: 15px; }
.quote-lines div span:first-child { padding-right: 12px; }
details summary { cursor: pointer; color: var(--muted); }
@media print {
  body:has(#noticeDoc:not(:empty)) main > *:not(#noticeDoc) { display: none !important; }
  .print-only { display: block; }
  .subnav { display: none; }
}
@media (max-width: 600px) { .topbar { padding: 10px 16px; gap: 8px; } .big-btn { width: 100%; height: auto; padding: 18px; } }

/* Invite pop-up */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.overlay .card { max-width: 520px; width: 100%; }
details summary { cursor: pointer; }
/* Logo in the top bar: shown on a white chip so it reads on the blue bar; falls back to text. */
.brand-logo { height: 46px; width: auto; background: #fff; padding: 4px 10px; border-radius: 6px; display: block; }
.brand.has-logo .brand-text { display: none; }
.fixed-val { padding: 9px 0; font-weight: 600; }

/* ---------- Phones and small tablets ---------- */
.menu-btn { display: none; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
details.schedule > summary { cursor: pointer; margin: 18px 0 10px; }
@media (max-width: 760px) {
  .topbar { position: sticky; top: 0; z-index: 40; padding: 10px 16px; gap: 8px; padding-top: max(10px, env(safe-area-inset-top)); }
  .brand { flex: 1; font-size: 18px; }
  .brand-logo { height: 36px; }
  .menu-btn { display: inline-flex; flex-direction: column; justify-content: center; gap: 5px; width: 44px; height: 44px; padding: 10px; background: transparent; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; }
  .menu-btn span { display: block; height: 2px; background: #fff; border-radius: 2px; }
  #nav { display: none; width: 100%; flex-direction: column; gap: 2px; padding: 6px 0 4px; }
  #nav.open { display: flex; }
  #nav a { padding: 12px 12px; font-size: 16px; }
  main { padding: 16px 12px 72px; padding-bottom: max(72px, env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  .card { padding: 14px; }
  /* sub-menus scroll sideways in one line instead of stacking */
  .subnav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: -4px -12px 14px; padding: 0 8px; }
  .subnav::-webkit-scrollbar { display: none; }
  .subnav a { white-space: nowrap; padding: 10px 12px; }
  /* number tiles two across */
  .cols-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .num { font-size: 20px; }
  .card.stat { padding: 12px; }
  /* bigger touch targets; 16px text stops iPhones zooming into fields */
  button, .btn { min-height: 44px; }
  .small-btn { min-height: 38px; padding: 6px 12px; font-size: 14px; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 22px; height: 22px; }
  .form-grid { grid-template-columns: 1fr !important; }
  .row > div { flex: 1 1 140px; }
  /* tables become a stack of small cards */
  .table-wrap { border: 0; overflow: visible; }
  #app table { background: transparent; }
  #app table, #app table tbody, #app table tr, #app table td { display: block; width: 100%; box-sizing: border-box; }
  #app table tr.head-row { display: none; }
  #app table tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 12px; }
  #app table td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  #app table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto; max-width: 45%; }
  #app table td:not([data-label])::before, #app table td[data-label=""]::before { content: none; }
  #app table td:not([data-label]) { justify-content: flex-end; }
  #app table td[colspan] { justify-content: center; text-align: center; }
  .tila { grid-template-columns: 1fr 1fr !important; }
  .tila .d { min-height: 0; }
  .payment-hero .amt { font-size: 40px; }
  .overlay .card { max-height: 90vh; overflow: auto; }
  .row.spread > h1, .row.spread > h2 { flex: 1 1 100%; }
}
@media (max-width: 760px) { #app table td { background: transparent !important; } }

/* ---------- Print / Save as PDF sheets ---------- */
@media screen { #printDoc { display: none; } }
@media print {
  body.print-doc-mode > *:not(#printDoc) { display: none !important; }
  body.print-doc-mode { background: #fff; }
  @page { margin: 14mm; }
}
#printDoc { color: #111; font-size: 12.5px; }
#printDoc h1 { font-size: 22px; margin: 10px 0 8px; }
#printDoc h2 { font-size: 15px; margin: 16px 0 6px; border-bottom: 1px solid #ccc; padding-bottom: 3px; }
.pd-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #0f4c81; padding-bottom: 8px; }
.pd-head img { height: 54px; }
.pd-co { text-align: right; font-size: 12px; }
.pd-foot { margin-top: 18px; font-size: 11px; color: #666; }
.pd-veh { display: flex; gap: 16px; align-items: flex-start; }
.pd-cover { width: 58%; max-height: 330px; object-fit: cover; border-radius: 6px; }
.pd-facts { flex: 1; }
.pd-price { font-size: 28px; font-weight: 800; color: #0f4c81; margin-bottom: 8px; }
.pd-row { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dotted #ccc; padding: 4px 0; }
.pd-row span, .pd-stats span { color: #555; }
.pd-gallery { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.pd-gallery img { width: 100%; height: 110px; object-fit: cover; border-radius: 4px; }
.pd-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 14px; }
.pd-stats div { display: flex; flex-direction: column; }
#printDoc table.pd-table { width: 100%; border-collapse: collapse; }
#printDoc .pd-table th, #printDoc .pd-table td { border-bottom: 1px solid #ddd; padding: 4px 6px; text-align: left; }
#printDoc .pd-table .num { text-align: right; }
#printDoc .pd-table tr { page-break-inside: avoid; }
.pd-small { font-size: 11px; }
.pd-thumb img { width: 90px; height: 60px; object-fit: cover; border-radius: 4px; }
#printDoc .tila { break-inside: avoid; }
.quote-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; }
