:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #646b78;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --danger: #c53030;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);

  --s-open: #b45309;        --s-open-bg: #fef3c7;
  --s-progress: #1d4ed8;    --s-progress-bg: #dbeafe;
  --s-scheduled: #6d28d9;   --s-scheduled-bg: #ede9fe;
  --s-resolved: #047857;    --s-resolved-bg: #d1fae5;
  --s-closed: #4b5563;      --s-closed-bg: #e5e7eb;
  --p-emergency: #b91c1c;   --p-emergency-bg: #fee2e2;
  --p-high: #c2410c;        --p-high-bg: #ffedd5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --border: #2e333e;
    --text: #e8eaef;
    --muted: #9aa1ae;
    --accent: #6b8cff;
    --accent-text: #0b1020;
    --danger: #f87171;
    --shadow: none;

    --s-open: #fbbf24;      --s-open-bg: #3a2c0a;
    --s-progress: #93c5fd;  --s-progress-bg: #172a4d;
    --s-scheduled: #c4b5fd; --s-scheduled-bg: #2a2150;
    --s-resolved: #6ee7b7;  --s-resolved-bg: #0f3327;
    --s-closed: #cbd5e1;    --s-closed-bg: #2b2f38;
    --p-emergency: #fca5a5; --p-emergency-bg: #451414;
    --p-high: #fdba74;      --p-high-bg: #43260d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: .9rem;
}
.topbar .who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem;
}
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* forms */
label, .label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: .9rem; }
.hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; font-size: .95rem; }
.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; }

.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: .25rem 0 .5rem; }

/* auth page */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-head { text-align: center; margin-bottom: 1.25rem; }
.auth-head .brand-mark { width: 44px; height: 44px; font-size: 1.3rem; margin: 0 auto .75rem; border-radius: 11px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; margin-bottom: 1.25rem; }
.tabs button {
  flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; font-size: .9rem;
  color: var(--muted); padding: .45rem; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* badges */
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: .12rem .5rem;
  border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.status-open { color: var(--s-open); background: var(--s-open-bg); }
.status-in_progress { color: var(--s-progress); background: var(--s-progress-bg); }
.status-scheduled { color: var(--s-scheduled); background: var(--s-scheduled-bg); }
.status-resolved { color: var(--s-resolved); background: var(--s-resolved-bg); }
.status-closed { color: var(--s-closed); background: var(--s-closed-bg); }
.prio-emergency { color: var(--p-emergency); background: var(--p-emergency-bg); }
.prio-high { color: var(--p-high); background: var(--p-high-bg); }

/* request list */
.req-list { list-style: none; margin: 0; padding: 0; }
.req-item {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; margin-bottom: .6rem; box-shadow: var(--shadow);
}
.req-item:hover { border-color: var(--accent); }
.req-item[aria-current="true"] { border-color: var(--accent); outline: 1px solid var(--accent); }
.req-item .title { font-weight: 600; }
.req-item .meta { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { padding: .9rem 1rem; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--p-emergency); }

/* split view */
.split { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 1.25rem; align-items: start; }
.detail { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .detail { position: static; max-height: none; }
}

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { flex: 1 1 180px; }
.filters select { flex: 0 1 160px; width: auto; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; font-size: .9rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.desc { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: .75rem .9rem; margin-bottom: 1rem; }

.manage { background: var(--surface-2); border-radius: 8px; padding: .9rem; margin-bottom: 1rem; }

/* timeline */
.timeline { list-style: none; margin: 0 0 1rem; padding: 0; }
.timeline li { padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .event { color: var(--muted); }
.timeline .bubble { white-space: pre-wrap; margin-top: .2rem; }
.timeline .from-manager .author { color: var(--accent); }
.timeline .author { font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; font-size: .9rem;
  z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

.nav-tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.nav-tabs button {
  border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: .6rem .9rem; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.nav-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* photos */
.photos { margin-bottom: 1rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.photo { position: relative; aspect-ratio: 1; }
.photo-thumb { display: block; width: 100%; height: 100%; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: zoom-in; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 1.1rem; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.photo-add { cursor: pointer; }
.photo-add.disabled { opacity: .6; pointer-events: none; }
.picker-previews { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.picker-previews .photo { width: 72px; }
.picker-previews img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }

.lightbox {
  position: fixed; inset: 0; z-index: 100; background: #000;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: zoom-in; overscroll-behavior: contain;
}
.lightbox.zoomed { cursor: grab; }
.lightbox.zoomed:active { cursor: grabbing; }
.lightbox-img {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none;
  opacity: 0; transition: opacity .15s; -webkit-user-drag: none; pointer-events: auto;
}
.lightbox-img.ready { opacity: 1; }
.lightbox-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .18); color: #fff;
  font-size: 1.6rem; line-height: 1; cursor: pointer; z-index: 1;
}
.lightbox-hint {
  position: absolute; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(0, 0, 0, .6); color: #fff; font-size: .85rem; padding: .4rem .8rem; border-radius: 999px;
  pointer-events: none; transition: opacity .4s; white-space: nowrap;
}
.lightbox-hint.hide { opacity: 0; }

/* vendors */
.spec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.spec-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; text-align: left;
  font: inherit; color: inherit; cursor: pointer; padding: .6rem .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.spec-tile:hover { border-color: var(--accent); }
.spec-tile.active { border-color: var(--accent); outline: 1px solid var(--accent); background: var(--surface-2); }
.spec-tile .spec-name { font-weight: 600; font-size: .9rem; }
.spec-tile .spec-count { color: var(--muted); font-size: .8rem; }
.spec-tile.gap .spec-count { color: var(--p-high); }

.vendor-list { list-style: none; margin: .75rem 0 0; padding: 0; }
.vendor { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .6rem; background: var(--surface); }
.vendor.far { opacity: .65; }
.vendor-head { align-items: flex-start; flex-wrap: nowrap; }
.vendor-name { font-weight: 600; }
.vendor .star { color: #e0a100; }
.vendor .tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }
.vendor-contact { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .45rem; }
.vendor-list.compact .vendor { padding: .6rem .75rem; margin-bottom: .5rem; }
.suggested { margin-bottom: 1rem; }
.filter-check { flex: 0 0 auto; margin: 0; align-self: center; white-space: nowrap; }
.notice { background: var(--s-open-bg); color: var(--s-open); border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; }

.spec-pick { border: 0; padding: 0; margin: 0 0 .9rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .35rem .75rem; }
.spec-pick legend { font-size: .85rem; font-weight: 600; margin-bottom: .4rem; padding: 0; }
.coords { margin-bottom: .9rem; }
.coords summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin-bottom: .5rem; }

.prop-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.prop-list li { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.prop-list li:last-child { border-bottom: 0; }
.prop-form { margin-top: .5rem; flex-wrap: nowrap; }
.prop-form input { flex: 1; min-width: 0; }

/* vendor map */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; font: inherit; font-weight: 600; font-size: .85rem; color: var(--muted);
  padding: .35rem .8rem; border-radius: 6px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.vendor-map {
  height: 520px; margin-top: .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2); z-index: 0; position: relative;
}
.map-loading { padding: 1rem; }
.map-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .6rem; color: var(--muted); }
.map-legend span { display: inline-flex; align-items: center; gap: .35rem; }

.map-pin { display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; line-height: 1; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.map-pin.pin-vendor { background: #2f5bea; border: 2px solid #fff; font-size: 11px; }
.map-pin.pin-vendor.pin-preferred { background: #d97706; }
.map-pin.pin-vendor.pin-out { background: #8b93a1; opacity: .85; }
.map-pin.pin-property { background: #0f766e; border: 3px solid #fff; font-size: 17px; }
.map-pin.pin-property.selected { background: #b91c1c; }
.range-circle { stroke: #2f5bea; stroke-width: 1.5; stroke-dasharray: 6 6; fill: #2f5bea; fill-opacity: .04; }
.range-circle.selected { stroke: #b91c1c; stroke-dasharray: none; fill: #b91c1c; fill-opacity: .06; }

.swatch { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; font-style: normal; font-size: 9px; color: #fff; }
.swatch.sw-vendor { background: #2f5bea; }
.swatch.sw-vendor.sw-preferred { background: #d97706; }
.swatch.sw-vendor.sw-out { background: #8b93a1; }
.swatch.sw-property { background: #0f766e; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.swatch.sw-circle { border: 1.5px dashed #2f5bea; background: transparent; }

.map-popup { display: grid; gap: .2rem; min-width: 180px; font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.map-popup .btn { margin-top: .4rem; min-height: 0; padding: .35rem .7rem; justify-self: start; }
.map-popup .star { color: #d97706; }
/* Leaflet popups are always light, so keep their text dark in dark mode too. */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { color: #1a1d23; }
.leaflet-popup-content .muted { color: #646b78; }
.leaflet-popup-content .btn { background: #fff; color: #1a1d23; border-color: #e2e5ea; }
.leaflet-container a { color: #2f5bea; }

@media (prefers-color-scheme: dark) {
  /* Darken the light OpenStreetMap tiles to sit comfortably in the dark theme. */
  .vendor-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.85); }
  .vendor-map .leaflet-control-attribution { background: rgba(26, 29, 36, .8); color: #9aa1ae; }
  .vendor-map .leaflet-control-attribution a { color: #9db3ff; }
}

@media (max-width: 640px) {
  .vendor-map { height: 60vh; min-height: 340px; }
}

/* routine maintenance */
.stat-btn { font: inherit; color: inherit; text-align: left; cursor: pointer; }
.stat-btn:hover { border-color: var(--accent); }
.stat-btn.active { border-color: var(--accent); outline: 1px solid var(--accent); }
.task-group h3 { margin-top: .5rem; }
.group-overdue h3 { color: var(--p-emergency); }
.task-list { list-style: none; margin: 0; padding: 0; }
.task {
  border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: var(--radius);
  padding: .8rem .9rem; margin-bottom: .6rem; background: var(--surface);
}
.task.due-overdue { border-left-color: var(--p-emergency); }
.task.due-soon { border-left-color: var(--p-high); }
.task-head { align-items: flex-start; flex-wrap: nowrap; }
.task-main { min-width: 0; }
.task-title { font-weight: 600; }
.task-meta { display: flex; flex-wrap: wrap; gap: .1rem 1rem; margin-top: .2rem; color: var(--muted); }
.task-actions { margin-top: .6rem; gap: .4rem; }
.task-actions .btn { padding: .4rem .8rem; }
.task-panel { margin-top: .75rem; }
.task-history .timeline { margin: 0; }
.checklist { margin: .5rem 0 0; padding-left: 1.2rem; columns: 2; column-gap: 2rem; }
.checklist li { break-inside: avoid; margin-bottom: .2rem; }
@media (max-width: 640px) {
  .checklist { columns: 1; }
  .task-head .badge { white-space: normal; text-align: right; }
}

/* billing & invoices */
.icon-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.generate-card { margin-bottom: 1.25rem; }
.generate-card.needs-action { border-color: var(--p-high); }
.attention { color: var(--p-high); }
.balance-due { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .75rem; margin-bottom: .5rem; }
.balance-due strong { font-size: 1.6rem; }
.invoice-summary { margin-bottom: 1rem; }
.charge-rows { display: grid; gap: .5rem; margin-bottom: .5rem; }
.charge-row { flex-wrap: nowrap; }
.charge-row input[name=description] { flex: 2; min-width: 0; }
.charge-row input[name=amount] { flex: 1; min-width: 0; }
.invoice-actions { display: grid; gap: 1rem; margin-top: 1rem; }
.invoice-actions .manage { margin: 0; }

.invoice-doc { background: var(--surface); }
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.invoice-brand { font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.invoice-brand .brand-mark { width: 24px; height: 24px; font-size: .8rem; }
.invoice-id { text-align: right; display: grid; gap: .2rem; justify-items: end; }
.invoice-word { font-size: 1.3rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.invoice-meta { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: .75rem; margin-bottom: 1.25rem; font-size: .92rem; }
.invoice-meta .label { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .15rem; }
.invoice-lines { margin-bottom: 1rem; }
.invoice-lines .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.invoice-lines th:last-child, .invoice-lines td:last-child { width: 1%; }
.invoice-lines tfoot td { border-bottom: 0; }
.invoice-lines tr.total td { font-weight: 600; border-top: 2px solid var(--border); }
.invoice-lines tr.payment td { color: var(--muted); font-size: .9rem; padding-top: .3rem; padding-bottom: .3rem; }
.invoice-lines tr.balance td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--text); }
.invoice-instructions { background: var(--surface-2); border-radius: 8px; padding: .75rem .9rem; font-size: .9rem; }
.invoice-instructions p { margin: .25rem 0 0; }
@media (max-width: 640px) {
  .invoice-meta { grid-template-columns: 1fr 1fr; }
  .invoice-meta > :first-child { grid-column: 1 / -1; }
  .generate-card form { align-items: stretch; }
  .generate-card form > .row { width: 100%; }
  .generate-card select { flex: 1; min-width: 0; }
}

#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { background: #fff; }
  #print-root { display: block; color: #000; padding: 0; }
  #print-root .invoice-doc { background: #fff; color: #000; }
  #print-root .muted, #print-root .invoice-meta .label { color: #555; }
  #print-root .badge { border: 1px solid #999; background: none; color: #000; }
  #print-root .invoice-instructions { background: #f3f3f3; }
  #print-root .no-print { display: none !important; }
  #print-root th, #print-root td { border-color: #ccc; }
  #print-root .brand-mark { background: #2f5bea; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* account dialog */
.account-dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 1.25rem; width: min(420px, calc(100vw - 2rem)); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.account-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.account-dialog hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0 1rem; }
.account-dialog label input { margin-top: .3rem; font-weight: 400; }
#pending-note { align-items: center; margin-bottom: 1rem; }
#mfa-note { align-items: center; margin-bottom: 1rem; }
.mfa-section h3 .badge { vertical-align: middle; margin-left: .25rem; }
.mfa-step { margin: .5rem 0; }
.mfa-step .btn-primary { margin-right: .5rem; }
.mfa-qr { display: grid; place-items: center; margin: .75rem 0; }
.mfa-qr img { width: 220px; height: 220px; image-rendering: pixelated; border-radius: 8px; background: #fff; }
.mfa-secret { display: block; margin: .5rem 0; padding: .5rem .7rem; background: var(--surface-2); border-radius: 6px; font-size: 1rem; letter-spacing: .05em; word-break: break-all; user-select: all; }
.recovery-codes { columns: 2; column-gap: 1.5rem; margin: .75rem 0; padding-left: 1.5rem; font-size: .95rem; }
.recovery-codes code { font-size: 1rem; user-select: all; }
.account-dialog { max-height: calc(100dvh - 2rem); overflow: auto; }

/* tenant accounts, work orders, reconciliation */
.list-head { margin-bottom: .5rem; }
.manage-sub { margin: 1rem 0 .5rem; font-size: .95rem; }
.account-list, .people-list { list-style: none; margin: 0; padding: 0; }
.account { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .6rem; background: var(--surface); }
.account.open { border-color: var(--accent); }
.account-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; width: 100%; text-align: left;
  font: inherit; color: inherit; background: none; border: 0; padding: .85rem 1rem; cursor: pointer;
}
.account-name { font-weight: 600; }
.account-panel { padding: 0 1rem 1rem; border-top: 1px solid var(--border); }
.people-list li { padding: .55rem 0; border-bottom: 1px solid var(--border); align-items: center; }
.people-list li:last-child { border-bottom: 0; }
.invite-form { margin: .75rem 0 .25rem; flex-wrap: wrap; }
.invite-form input { flex: 1 1 160px; min-width: 0; }
.invite-form select { flex: 0 0 auto; width: auto; }
.invite-link input { flex: 1; min-width: 0; font-size: .85rem; }
.recon-table td, .recon-table th { white-space: nowrap; }
.recon-table td:first-child { white-space: normal; }
.recon-table tr.highlight td { background: var(--surface-2); }
.recon-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.charge-row select { flex: 0 0 auto; width: auto; }
@media (max-width: 640px) {
  .charge-row { flex-wrap: wrap; }
  .charge-row select { flex: 1 1 100%; }
  .account-head { flex-direction: column; gap: .25rem; }
}

/* back button: only shown in the phone detail view */
.back-btn { display: none; margin: -.25rem 0 .75rem -.5rem; padding-left: .5rem; color: var(--accent); }

/* --- phones (iPhone and similar) ---------------------------------------- */
@media (max-width: 860px) {
  /* Detail opens as its own screen instead of below the whole list. */
  body.show-detail .split > section:first-child,
  body.show-detail [data-hide-in-detail] { display: none !important; }
  body.show-detail .detail { border: 0; box-shadow: none; background: transparent; padding: 0; }
  body.show-detail .back-btn { display: inline-flex; }
  body:not(.show-detail) .detail { display: none; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  /* iOS Safari zooms into any focused field under 16px. */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; }
  .check input { min-height: 0; width: 22px; height: 22px; flex-shrink: 0; }
  .card { scroll-margin-top: calc(64px + env(safe-area-inset-top)); }

  .topbar {
    padding: .5rem 1rem;
    padding-top: max(.5rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .brand { white-space: nowrap; }
  .topbar .who-name { display: none; }
  .topbar .btn-ghost { padding: .5rem .25rem; }

  main {
    padding: 1rem 1rem calc(3rem + env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  h1 { font-size: 1.3rem; }
  .card { padding: 1rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn { width: 100%; }

  /* Stats become a compact row you can swipe sideways. */
  .stats {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: .5rem;
    margin: 0 -1rem 1rem; padding: 0 1rem .25rem; scroll-padding: 0 1rem; scrollbar-width: none;
  }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 0 0 auto; min-width: 104px; padding: .6rem .8rem; scroll-snap-align: start; }
  .stat .n { font-size: 1.3rem; }
  .stat .l { font-size: .78rem; white-space: nowrap; }

  .filters input { flex: 1 1 100%; }
  .filters select { flex: 1 1 0; min-width: 0; padding-left: .55rem; padding-right: .3rem; }

  /* Five tabs don't fit on a phone: let the bar scroll sideways. */
  .nav-tabs { margin: 0 -1rem 1rem; padding: 0 .5rem; overflow-x: auto; scrollbar-width: none; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs button { flex: 0 0 auto; padding: .7rem .75rem; white-space: nowrap; }

  .req-item { padding: .85rem .9rem; }
  .req-item .row.spread { align-items: flex-start; flex-wrap: nowrap; }
  .req-item .row.spread > :last-child { flex-shrink: 0; }

  dl.facts { grid-template-columns: 6.5rem 1fr; gap: .3rem .75rem; font-size: .92rem; }
  .manage .grid-2 { grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
  .manage .field { margin-bottom: .7rem; min-width: 0; }
  .manage .btn { width: 100%; }

  .toast { bottom: calc(1rem + env(safe-area-inset-bottom)); max-width: calc(100% - 2rem); }

  /* Tenants table turns into cards. */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .6rem; }
  table.cards td { border: 0; padding: .15rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; overflow-wrap: anywhere; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex-shrink: 0; }
  table.cards td:first-child { font-weight: 600; font-size: 1rem; }
  table.cards td:first-child::before { content: none; }
}

/* --- documents ------------------------------------------------------------- */
.doc-list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.doc { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.doc:last-child { border-bottom: 0; }
.doc-main { display: flex; gap: .65rem; align-items: flex-start; min-width: 0; }
.doc-main > div { min-width: 0; }
.doc-icon { flex-shrink: 0; width: 38px; height: 44px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .7rem; font-weight: 700; display: grid; place-items: center; border: 1px solid var(--border); }
.doc-title { font-weight: 600; overflow-wrap: anywhere; }
.doc-badges { gap: .3rem; margin: .2rem 0; }
.doc-actions { gap: .2rem; flex-shrink: 0; }
.doc-upload { margin-top: .5rem; }
.internal-badge { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }

/* --- vendor work orders ---------------------------------------------------- */
.workorder { margin-bottom: 1rem; }
.card-inset { border: 1px solid var(--border); border-radius: 8px; padding: .8rem .9rem; }
.card-inset > * + * { margin-top: .5rem; }
.card-inset .desc { margin-bottom: 0; }
.msg-vendor textarea { flex: 1; min-width: 0; }
.past-jobs { margin-top: .5rem; }
.past-jobs summary { cursor: pointer; color: var(--muted); }
.timeline .from-vendor .author { color: var(--s-scheduled, var(--accent)); }
.timeline li.internal .bubble { border-left: 3px solid var(--border); padding-left: .5rem; }
.job-page { max-width: 760px; margin: 0 auto; }
.job-page > .card { margin-bottom: 1rem; }
.job-page h1 { font-size: 1.35rem; }
.job-page .notice .bubble { white-space: pre-wrap; margin-top: .25rem; color: var(--text); }
.job-page hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.job-page details summary { cursor: pointer; color: var(--muted); margin-bottom: .5rem; }
.job-page textarea { margin-bottom: .5rem; }

/* --- reports ---------------------------------------------------------------- */
.report-nav-wrap { overflow-x: auto; margin-bottom: 1rem; -webkit-overflow-scrolling: touch; }
.report-nav button { white-space: nowrap; }
.report-head { align-items: flex-start; }
.report-group h3 { margin-bottom: .4rem; }
.report-table tfoot th, .report-table tfoot td { border-top: 2px solid var(--border); font-weight: 600; }
.report-table td { vertical-align: top; }
.report-kinds { gap: .4rem 1.2rem; margin-top: .4rem; }
.aging-stats .n { font-size: 1.1rem; }
ul.plain { list-style: none; margin: .25rem 0 0; padding: 0; }
.nowrap, .report-table td.nowrap { white-space: nowrap; }
/* Narrow phones: the role badge doesn't fit beside Account and Log out. */
@media (max-width: 400px) { .topbar:has(#logout) .brand .badge { display: none; } }
.recon-table .recon-notes { white-space: normal; max-width: 28rem; font-size: .8rem; }
.recon-table .recon-notes li + li { margin-top: .15rem; }

/* --- properties, suites, lease dates, quotes ----------------------------------- */
.suites-table input { width: 100%; }
.report-table tr.vacant-row td { background: var(--surface-2); }
.report-table tr.muted td { color: var(--muted); }
.vendor-docs { margin-top: .5rem; }
.vendor-docs summary { cursor: pointer; color: var(--muted); }
.vendor-docs[open] summary { margin-bottom: .4rem; }
.quote-pending .bubble { white-space: pre-wrap; margin-top: .3rem; color: var(--text); }
.quote-pending input { flex: 1; min-width: 0; }
.notice.warn { border-left: 3px solid var(--p-high); }

/* --- security deposits ---------------------------------------------------------- */
.deposit-summary { display: flex; flex-wrap: wrap; gap: .5rem 1.75rem; margin-bottom: .4rem; }
.deposit-summary > div { display: flex; flex-direction: column; }
.deposit-summary strong { font-size: 1.15rem; }
.deduction-row { flex-wrap: nowrap; gap: .4rem; margin-bottom: .4rem; }
.deduction-row input[name=description] { flex: 1; min-width: 0; }
.deduction-row select { max-width: 11rem; }
.statement { margin-top: .6rem; }
.statement summary { cursor: pointer; font-weight: 600; }
.statement .statement-doc { margin: .6rem 0; }
@media (max-width: 600px) { .deduction-row { flex-wrap: wrap; } .deduction-row select { max-width: none; flex: 1 1 100%; } }

/* --- leasing, listings, signatures, system ------------------------------------- */
.public-page { max-width: 960px; margin: 0 auto; }
.listing-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.listing-card { display: block; padding: 0; overflow: hidden; color: inherit; text-decoration: none; height: 100%; }
.listing-card:hover { border-color: var(--accent); }
.listing-card img, .listing-noimg { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--surface-2); }
.listing-noimg { display: grid; place-items: center; font-size: 2.5rem; color: var(--muted); }
.listing-body { padding: .75rem .9rem; }
.listing-body > * + * { margin-top: .2rem; }
.listing-title { font-weight: 600; font-size: 1.05rem; }
.listing-rent { font-weight: 600; color: var(--accent); }
.listing-photos { margin: .25rem 0; }
.listing-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; flex-shrink: 0; border: 1px solid var(--border); }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.consent { align-items: flex-start; line-height: 1.4; }
.signature-preview { font-family: "Snell Roundhand", "Brush Script MT", "Segoe Script", cursive; font-size: 1.8rem; margin: .2rem 0 .8rem; min-height: 2.4rem; border-bottom: 1px solid var(--border); }
.system-checks li { margin: .35rem 0; }
pre.stack { white-space: pre-wrap; font-size: .75rem; max-height: 16rem; overflow: auto; background: var(--surface-2); padding: .5rem; border-radius: 6px; }

/* --- import ------------------------------------------------------------------------ */
.import-panel { margin-top: .75rem; }
.import-steps { padding-left: 1.2rem; }
.import-steps li { margin: .25rem 0; }
.import-table tr.error-row td { background: var(--p-emergency-bg, var(--surface-2)); }

/* --- inspections, statement, rent schedule ---------------------------------------- */
.inspection-editor .insp-area { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; }
.inspection-editor .insp-area summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.insp-item { padding: .6rem 0; border-top: 1px solid var(--border); }
.cond-buttons { display: flex; flex-wrap: wrap; gap: .3rem; margin: .35rem 0; }
.cond-buttons .cond { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: .4rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; min-height: 36px; }
.cond-buttons .cond[aria-pressed="true"] { color: #fff; border-color: transparent; }
.cond-buttons .cond-good[aria-pressed="true"] { background: #15803d; }
.cond-buttons .cond-fair[aria-pressed="true"] { background: #a16207; }
.cond-buttons .cond-poor[aria-pressed="true"] { background: #c2410c; }
.cond-buttons .cond-damaged[aria-pressed="true"] { background: #b91c1c; }
.cond-buttons .cond-na[aria-pressed="true"] { background: #6b7280; }
.badge.cond-good { background: var(--s-resolved-bg, #dcfce7); color: var(--s-resolved, #15803d); }
.badge.cond-fair { background: var(--p-high-bg); color: var(--p-high); }
.badge.cond-poor, .badge.cond-damaged { background: var(--p-emergency-bg, #fee2e2); color: var(--p-emergency, #b91c1c); }
.insp-extra { gap: .4rem; flex-wrap: nowrap; }
.insp-extra input { flex: 1; min-width: 0; }
.insp-extra input.estimate { max-width: 7rem; flex: 0 0 7rem; }
.photo-grid.small-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); margin-top: .4rem; }
.insp-thumbs { display: flex; gap: .3rem; margin-top: .3rem; flex-wrap: wrap; }
.insp-thumbs .photo-thumb { width: 56px; height: 56px; }
.insp-report-area h3 { margin: .9rem 0 .2rem; }
.saved-status { min-width: 3rem; text-align: right; }
.statement-view { margin-top: .75rem; }
.statement-lines td, .statement-lines th { white-space: nowrap; }
.statement-lines td:nth-child(2) { white-space: normal; }
@media (max-width: 600px) { .insp-extra { flex-wrap: wrap; } .insp-extra input.estimate { max-width: none; flex: 1 1 40%; } }
