:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --muted: #6f6a60;
  --line: #e2ddd2;
  --gold: #a87a22;
  --gold-soft: #f5ecd9;
  --ok: #2f7a4b;
  --ok-soft: #e3f1e8;
  --warn: #9a5b00;
  --warn-soft: #fbeed8;
  --bad: #b23b32;
  --bad-soft: #f8e3e1;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Sarabun", "Leelawadee UI", Tahoma, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--gold); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px; background: #1f1d1a; color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.top .logo { width: 40px; height: 40px; object-fit: contain; }
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand span { color: #cbbd9c; font-size: 13px; }
.top nav { margin-left: auto; display: flex; gap: 4px; }
.top nav button {
  background: none; border: 0; color: #d9d2c3; padding: 8px 16px; border-radius: 6px; cursor: pointer;
}
.top nav button:hover { background: #34312b; }
.top nav button.on { background: var(--gold); color: #fff; }

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.on { display: block; }
.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.bar.end { justify-content: flex-end; margin-top: 14px; }
.bar.sticky { position: sticky; top: 0; background: var(--bg); padding: 12px 0; z-index: 2; border-bottom: 1px solid var(--line); }

.btn {
  background: var(--gold); color: #fff; border: 1px solid var(--gold);
  padding: 7px 16px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--gold); }
.btn.sm { padding: 3px 10px; font-size: 14px; }
.btn.link { background: none; border: 0; color: var(--gold); padding: 2px 6px; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
input[type=search] { width: 280px; }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.stats { display: flex; gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; min-width: 180px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.grid th { background: #efebe2; text-align: left; font-weight: 600; font-size: 14px; padding: 8px 12px; }
table.grid td { padding: 7px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
table.grid tr:hover td { background: #fbf9f4; }
table.grid tr.void td { color: #aaa; text-decoration: line-through; }
table.grid tr.void td:last-child, table.grid tr.void td:nth-last-child(2) { text-decoration: none; }
table.grid tr.skipped td { color: #999; }
table.grid td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

.badge { display: inline-block; font-size: 13px; padding: 1px 9px; border-radius: 99px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.mute { background: #eee; color: #777; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 0 0 14px; }
fieldset.card legend { font-weight: 600; color: var(--gold); padding: 0 6px; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 14px; }
.form2 label, .form3 label { display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; color: var(--muted); }
.form2 label input, .form2 label select, .form2 label textarea, .form3 label input { color: var(--ink); font-size: 15px; }
.form2 label.chk { flex-direction: row; color: var(--ink); font-size: 15px; }
.form2 small, .form3 small { color: var(--muted); font-size: 12px; }
.span2 { grid-column: span 2; }
.inline { display: flex; gap: 6px; }
.inline select { flex: 1; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.err { color: var(--bad); }

/* editors */
.sheet-wrap { position: fixed; inset: 0; background: rgba(30,28,25,.45); z-index: 20; overflow: auto; }
.editor { background: var(--bg); min-height: 100%; display: grid; grid-template-columns: 560px 1fr; }
.editor.single { display: block; padding: 0 28px 40px; max-width: 1400px; margin: 0 auto; }
.ed-form { padding: 18px 22px 40px; border-right: 1px solid var(--line); background: var(--panel); }
.ed-preview { padding: 24px; overflow: auto; }
.paper-scale { transform-origin: top left; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 500; padding: 2px 4px; }
table.items td { padding: 3px 4px; }
table.items input { width: 100%; }
table.items input.num { text-align: right; }
.x { background: none; border: 0; color: #b0a89a; cursor: pointer; font-size: 18px; }
.x:hover { color: var(--bad); }

.totals-box { margin-top: 14px; background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.totals-box div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals-box div.big { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.totals-box .words { color: var(--muted); justify-content: flex-end; }
.deposit-link { margin-top: 12px; font-size: 14px; }
.deposit-link .box { background: var(--gold-soft); border-radius: 8px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; }

.sched { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 30px; }
.sched .row { display: grid; grid-template-columns: 40px 1fr 140px; gap: 8px; align-items: center; }
.sched .row span { color: var(--muted); text-align: right; }
.furn { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 30px; }
.furn label { display: grid; grid-template-columns: 1fr 90px; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.furn input { text-align: center; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f1d1a; color: #fff; padding: 10px 20px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; }

/* ---------- receipt paper (A4, original on top, copy below) ---------- */
.paper {
  width: 210mm; height: 297mm; background: #fff; color: #000;
  box-shadow: 0 2px 14px rgba(0,0,0,.15);
  padding: 7mm 10mm; display: flex; flex-direction: column;
  font-family: "Sarabun", "TH Sarabun New", Tahoma, sans-serif; font-size: 10.5pt; line-height: 1.3;
}
.rc { height: 137mm; display: flex; flex-direction: column; overflow: hidden; }
.rc + .cut { border-top: 1px dashed #999; margin: 3.5mm 0; position: relative; }
.rc-head { display: flex; gap: 4mm; align-items: flex-start; }
.rc-head img { width: 19mm; height: 19mm; object-fit: contain; }
.rc-co { flex: 1; font-size: 8.5pt; line-height: 1.25; }
.rc-co b { font-size: 12.5pt; display: block; line-height: 1.3; }
.rc-co .en { font-weight: 600; font-size: 10pt; }
.rc-title { border: 1.2px solid #000; border-radius: 2mm; padding: 1.5mm 4mm; text-align: center; font-weight: 700; font-size: 12pt; white-space: nowrap; }
.rc-title small { display: block; font-weight: 500; font-size: 8.5pt; }
.rc-info { display: grid; grid-template-columns: 1fr 52mm; border: 1px solid #000; margin-top: 2mm; }
.rc-info > div { padding: 1mm 2.5mm; }
.rc-info > div + div { border-left: 1px solid #000; }
.rc-info .l { display: grid; grid-template-columns: 47mm 1fr; gap: .3mm 2mm; }
.rc-info .l span:nth-child(odd), .rc-info .r span:nth-child(odd) { color: #333; font-size: 9pt; }
.rc-info .r { display: grid; grid-template-columns: 17mm 1fr; gap: .3mm 2mm; align-content: start; }
.rc-info .v { font-weight: 600; }
.box-chk { display: inline-block; width: 3.2mm; height: 3.2mm; border: 1px solid #000; vertical-align: -.4mm; text-align: center; line-height: 3mm; font-size: 8pt; font-weight: 700; margin-right: 1mm; }
table.rc-items { width: 100%; border-collapse: collapse; margin-top: 2mm; }
table.rc-items th { border: 1px solid #000; font-size: 8.5pt; font-weight: 600; padding: .6mm 1mm; line-height: 1.15; background: #f3f3f3; }
table.rc-items td { border-left: 1px solid #000; border-right: 1px solid #000; padding: 0 2mm; height: 5mm; line-height: 1.15; }
table.rc-items tr:last-child td { border-bottom: 1px solid #000; }
.rc-foot { display: grid; grid-template-columns: 1fr 84mm; margin-top: -1px; }
.rc-foot .words { border: 1px solid #000; border-right: 0; padding: 1.2mm 2.5mm; }
.rc-foot .words b { font-weight: 700; }
.rc-sum { border: 1px solid #000; }
.rc-sum div { display: grid; grid-template-columns: 1fr 28mm; border-top: 1px solid #000; }
.rc-sum div:first-child { border-top: 0; }
.rc-sum span { padding: 0 2mm; height: 5.6mm; font-size: 8.5pt; line-height: 5.6mm; white-space: nowrap; }
.rc-sum span:last-child { border-left: 1px solid #000; text-align: right; font-size: 10.5pt; font-weight: 600; align-self: stretch; display: flex; align-items: center; justify-content: flex-end; }
.rc-sum div.total span { font-weight: 700; }
.rc-pay { padding: 1mm 2.5mm; border-left: 1px solid #000; border-bottom: 1px solid #000; margin-top: -1px; font-size: 9.5pt; display: grid; gap: .3mm; flex: 1; }
.rc-pay .line { border-bottom: 1px dotted #000; display: inline-block; min-width: 22mm; text-align: center; padding: 0 1mm; }
.rc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20mm; margin-top: auto; padding: 0 14mm; text-align: center; font-size: 9.5pt; line-height: 1.25; }
.rc-sign .sig { border-bottom: 1px solid #000; height: 7mm; margin-bottom: .3mm; }
.rc-left { display: flex; flex-direction: column; }
.rc-void { position: absolute; font-size: 60pt; color: rgba(200,0,0,.18); transform: rotate(-20deg); font-weight: 700; left: 60mm; top: 40mm; pointer-events: none; }
.rc { position: relative; }

#print-area { display: none; }
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; min-width: 0; }
  .no-print { display: none !important; }
  #print-area { display: block; }
  #print-area .paper { box-shadow: none; page-break-after: always; }
}

/* ---------- invoice paper (A4, one copy) ---------- */
.paper.inv { padding: 14mm 15mm 12mm; font-size: 11.5pt; line-height: 1.4; position: relative; }
.inv-head { display: flex; gap: 5mm; align-items: center; }
.inv-head img { width: 26mm; height: 26mm; object-fit: contain; }
.inv-head b { font-size: 15pt; display: block; line-height: 1.3; }
.inv-head div { font-size: 10.5pt; }
.inv-title { text-align: center; font-size: 17pt; font-weight: 700; margin: 6mm 0 4mm; letter-spacing: .3px; }
.inv-info { display: grid; grid-template-columns: 1fr 62mm; gap: 4mm; }
.inv-info .l { display: grid; grid-template-columns: 50mm 1fr; gap: 1mm 2mm; border: 1px solid #000; border-radius: 1.5mm; padding: 2.5mm 3.5mm; align-content: start; }
.inv-info .r { display: grid; grid-template-columns: 20mm 1fr; gap: 1mm 2mm; border: 1px solid #000; border-radius: 1.5mm; padding: 2.5mm 3.5mm; align-content: start; }
.inv-info span { color: #333; }
table.inv-items { width: 100%; border-collapse: collapse; margin-top: 5mm; }
table.inv-items th { border: 1px solid #000; background: #f1ede4; font-weight: 600; padding: 1.2mm 1mm; font-size: 10.5pt; }
table.inv-items td { border-left: 1px solid #000; border-right: 1px solid #000; padding: 0 2mm; height: 7.2mm; }
table.inv-items tr:last-child td { border-bottom: 1px solid #000; }
table.inv-items td.c { text-align: center; }
.inv-foot { display: grid; grid-template-columns: 1fr 70mm; }
.inv-foot .words { border: 1px solid #000; border-top: 0; border-right: 0; padding: 2mm 3mm; align-self: stretch; display: flex; align-items: flex-end; }
.inv-sum { border: 1px solid #000; border-top: 0; }
.inv-sum div { display: grid; grid-template-columns: 1fr 28mm; }
.inv-sum div + div { border-top: 1px solid #000; }
.inv-sum span { padding: 1mm 2mm; }
.inv-sum span:last-child { border-left: 1px solid #000; text-align: right; font-variant-numeric: tabular-nums; }
.inv-sum div.total { font-weight: 700; background: #f1ede4; }
.inv-note { display: grid; grid-template-columns: 20mm 1fr; margin-top: 5mm; font-size: 11pt; }
.inv-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20mm; margin-top: auto; padding: 0 8mm; text-align: center; font-size: 11pt; line-height: 1.7; }
.inv-sign .sig { border-bottom: 1px solid #000; height: 14mm; margin: 0 6mm 1mm; }

/* ---------- login ---------- */
.gate { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.gate-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 26px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.gate-card img { width: 72px; height: 72px; object-fit: contain; align-self: center; }
.gate-card h1 { text-align: center; }
.gate-card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.gate-card input { font-size: 16px; padding: 9px 11px; }
.gate-card .btn { padding: 10px; font-size: 16px; }

/* ---------- header / user menu ---------- */
.top { flex-wrap: nowrap; }
.top nav { overflow-x: auto; scrollbar-width: none; flex: 1; justify-content: flex-end; }
.top nav::-webkit-scrollbar { display: none; }
.top nav button { white-space: nowrap; }
.me { position: relative; }
.me-btn { background: #34312b; color: #fff; border: 0; border-radius: 99px; padding: 6px 14px; cursor: pointer; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.me-menu { position: absolute; right: 0; top: 40px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 8px; min-width: 200px; z-index: 30; display: flex; flex-direction: column; }
.me-menu > div { padding: 4px 10px 8px; }
.me-menu button { background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.me-menu button:hover { background: var(--bg); }
.me-menu[hidden] { display: none; }
body:not(.is-admin) [data-admin] { display: none !important; }
body.no-tenants_any [data-cap="tenants_any"] { display: none !important; }
body.no-contracts_any [data-cap="contracts_any"] { display: none !important; }
body.no-props [data-cap="props"] { display: none !important; }
body.no-contacts [data-cap="contacts"] { display: none !important; }
body.no-contracts [data-cap="contracts"] { display: none !important; }
body.no-finance [data-cap="finance"] { display: none !important; }
body.no-jobs [data-cap="jobs"] { display: none !important; }
body.no-jobs_admin [data-cap="jobs_admin"] { display: none !important; }
body.no-settings [data-cap="settings"] { display: none !important; }
body.no-users [data-cap="users"] { display: none !important; }
body.no-delete [data-cap="delete"] { display: none !important; }
.role-picks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; }
.role-picks label { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.role-picks input { width: auto; }
.lbl { font-size: 13px; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.badge.info { background: #e3ecf8; color: #2c5a92; }
.badge.vacant { background: #fde9d0; color: #9a5b00; font-weight: 600; }
tr.click { cursor: pointer; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
.table-wrap table.grid { min-width: 720px; }
h3.first { margin-top: 0; }
h4 { margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
.form3 .span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.picker { display: flex; gap: 6px; }
.picker input { flex: 1; min-width: 0; }
.tel-links { padding: 7px 0; color: var(--ink); font-size: 15px; }
.tel-links a, a[href^="tel:"] { color: var(--gold); text-decoration: none; font-weight: 600; }
label.pick input { background: var(--gold-soft); border-color: #e5d3a8; }

/* ---------- dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-grid .stat { text-align: left; cursor: pointer; font: inherit; min-width: 0; }
.stat-grid .stat:hover { border-color: var(--gold); }
.stat.st-vacant b { color: var(--warn); }
.stat.st-ok b { color: var(--ok); }
.stat.st-warn b { color: #b86e00; }
.stat.st-info b { color: #2c5a92; }
.dash-cols { align-items: start; }
.list { display: flex; flex-direction: column; }
.list .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; color: inherit; text-decoration: none; }
.list .row:last-child { border-bottom: 0; }
.list .row:hover { background: #fbf9f4; }
.list .row > div { display: flex; flex-direction: column; min-width: 0; }

/* ---------- units ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.bar.filters select, .bar.filters input { max-width: 100%; }
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.unit-grid > p { grid-column: 1 / -1; text-align: center; padding: 40px 0; }
.unit-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.unit-card:hover { border-color: var(--gold); box-shadow: 0 4px 14px rgba(0,0,0,.07); }
.unit-card .thumb { position: relative; aspect-ratio: 4 / 3; background: #ece7dc; display: grid; place-items: center; color: #aaa; font-size: 13px; }
.unit-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.unit-card .thumb .badge { position: absolute; top: 8px; left: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.unit-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.unit-card .price { color: var(--gold); font-weight: 700; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; }
.editor.single.narrow { max-width: 820px; }
.back { font-size: 18px; padding: 4px 12px; }
.bar.sticky h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.ph { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: #ece7dc; border: 2px solid transparent; }
.ph.cover { border-color: var(--gold); }
.ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.ph-tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: flex-end; gap: 2px; padding: 4px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.ph-tools button { background: rgba(255,255,255,.9); border: 0; border-radius: 5px; width: 26px; height: 24px; cursor: pointer; font-size: 13px; line-height: 1; }
.ph.cover .ph-tools button[data-cover] { background: var(--gold); color: #fff; }
.ph.doc a.pdf { display: grid; place-items: center; height: 100%; text-align: center; color: var(--ink); text-decoration: none; font-weight: 700; padding: 8px; }
.upload-bar { margin: 10px 0 0; }
.furn.one { grid-template-columns: 1fr; }
.dialog { background: var(--panel); max-width: 520px; margin: 8vh auto; border-radius: 12px; padding: 20px 22px; }
.dialog h2 { margin-bottom: 14px; }

/* ---------- photo viewer ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 70; display: grid; place-items: center; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 96vw; max-height: 88vh; object-fit: contain; }
.lightbox button { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 99px; width: 44px; height: 44px; font-size: 26px; cursor: pointer; }
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 12px; top: 50%; }
.lb-next { right: 12px; top: 50%; }
.lb-cap { position: absolute; bottom: 14px; color: #ccc; font-size: 14px; }
.gate[hidden], .sheet-wrap[hidden] { display: none; }

/* ---------- phones and small tablets ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .top { padding: 8px 12px; gap: 8px; }
  .top .brand { display: none; }
  .top nav { justify-content: flex-start; }
  .top nav button { padding: 7px 11px; }
  .me-btn { max-width: 88px; padding: 6px 10px; font-size: 13px; }
  .top .logo { width: 32px; height: 32px; }
  main { padding: 14px 12px 60px; }
  h1 { font-size: 18px; }
  .bar { gap: 8px; }
  input[type=search] { width: 100%; }
  .bar.filters > * { flex: 1 1 45%; }
  .form2, .form3, .cols, .unit-layout { grid-template-columns: 1fr; }
  .form3 .span2, .span2 { grid-column: auto; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .stat { min-width: 0; padding: 8px 10px; }
  .stat b { font-size: 18px; }
  .stats { flex-wrap: wrap; }
  .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .unit-card .body { padding: 8px 9px 10px; font-size: 14px; }
  .editor { grid-template-columns: 1fr; }
  .editor.single { padding: 0 12px 40px; }
  .ed-preview { display: none; }
  .ed-form { border-right: 0; padding: 12px; }
  .bar.sticky { flex-wrap: wrap; padding: 8px 0; }
  .bar.sticky h2 { flex: 1 1 calc(100% - 140px); font-size: 17px; }
  .bar.sticky .btn { flex: 1 1 auto; }
  .bar.sticky .btn.back { flex: 0 0 auto; }
  .bar.sticky .grow { display: none; }
  .bar.sticky .err { order: 10; flex-basis: 100%; }
  .gallery { grid-template-columns: repeat(3, 1fr); }
  .sched, .furn { grid-template-columns: 1fr; }
  .dialog { margin: 0; border-radius: 0; min-height: 100%; }
  input, select, textarea { font-size: 16px; } /* stops iOS zooming into fields */
}
@media (max-width: 420px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .gallery { grid-template-columns: repeat(2, 1fr); }
}

/* contract photo picker */
.pick-gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ph.pick { aspect-ratio: auto; display: flex; flex-direction: column; background: var(--panel); border: 2px solid var(--line); }
.ph.pick img { aspect-ratio: 4 / 3; cursor: pointer; opacity: .55; }
.ph.pick.on { border-color: var(--gold); }
.ph.pick.on img { opacity: 1; }
.pick-no { position: absolute; top: 6px; left: 6px; background: var(--gold); color: #fff; border-radius: 99px; min-width: 24px; height: 24px; display: grid; place-items: center; font-weight: 700; font-size: 13px; padding: 0 6px; }
.ph-cap { border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 13px; padding: 4px 6px; }
fieldset { min-width: 0; }
.cols > * { min-width: 0; }
.form2 input, .form3 input, .form2 select, .form3 select { min-width: 0; width: 100%; }

/* ---------- landlord / tenant cards ---------- */
.person-head { font-size: 16px; margin-bottom: 4px; }
.person dl { display: grid; grid-template-columns: 110px 1fr; gap: 2px 10px; margin: 8px 0; font-size: 14px; }
.person dt { color: var(--muted); }
.person dd { margin: 0; overflow-wrap: anywhere; }
.mini-docs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.mini { width: 92px; font-size: 12px; color: var(--muted); text-align: center; }
.mini img, .mini a.pdf { width: 92px; height: 62px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: grid; place-items: center; background: #f1ede4; color: var(--ink); text-decoration: none; font-weight: 700; }
.mini a.pdf .small { display: none; }
.person-tools { margin: 6px 0 0; }

/* document tiles (contact editor and contract pickers) */
.gallery.docs { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.ph.doc { aspect-ratio: auto; display: flex; flex-direction: column; background: var(--panel); border: 2px solid var(--line); }
.ph.doc > a, .ph.doc > img, .ph.doc > span.pdf { aspect-ratio: 1.58; display: grid; place-items: center; overflow: hidden; }
.ph.doc img { width: 100%; height: 100%; object-fit: cover; }
.ph.doc span.pdf { font-weight: 700; text-align: center; background: #f1ede4; cursor: pointer; }
.ph.doc .ph-tools { inset: 0 0 auto auto; background: none; }
.doc-type { border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 13px; padding: 4px 6px; width: 100%; }
.ph.doc.pick > img, .ph.doc.pick > span.pdf { opacity: .5; cursor: pointer; }
.ph.doc.pick.on { border-color: var(--gold); }
.ph.doc.pick.on > img, .ph.doc.pick.on > span.pdf { opacity: 1; }

/* ---------- contract preview ---------- */
.pv-pages { padding: 16px 0 40px; }
.pv-pages figure { margin: 0 auto 18px; max-width: 820px; }
.pv-pages img { width: 100%; display: block; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.15); }
.pv-pages figcaption { text-align: center; color: var(--muted); font-size: 13px; margin-top: 4px; }

/* signed contract */
.signed-box { border-color: #e5d3a8; }
.signed-pages { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.signed-pages .ph.doc > img, .signed-pages .ph.doc > a { aspect-ratio: .71; }
.signed-note { background: #fdf3dc; border: 1px solid #e8cf94; color: #7a5200; border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }
.inline-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.signed-pages .ph.doc .ph-tools { inset: 0 0 auto 0; padding: 5px; background: linear-gradient(rgba(0,0,0,.5), transparent); }
.signed-pages .pick-no { z-index: 1; }

/* locked contract */
#ct-form.locked .signed-pages .ph-tools { display: none; }
#ct-form.locked .pick-gallery img, #ct-form.locked .pick-gallery .pdf { cursor: default; }
#ct-form.locked .ph-cap, #ct-form.locked .doc-type { pointer-events: none; background: transparent; }
#ct-form.locked label.btn:not(.signed-box label.btn) { display: none; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea, input:disabled { background: #f3f1ec; color: #555; border-color: #e8e4da; }

/* furniture editor */
.furn-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.furn-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.furn-row { display: grid; grid-template-columns: 40px 1fr 72px 28px; gap: 6px; align-items: center; opacity: .55; }
.furn-row.on { opacity: 1; }
.furn-row .fqty { text-align: center; }
.switch { position: relative; width: 36px; height: 20px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d6d0c3; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::before { transform: translateX(16px); }
fieldset:disabled .switch span { cursor: default; }
#ct-furn, #un-furn { display: block; }
#ct-furn .furn-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
@media (max-width: 900px) { #ct-furn .furn-list { grid-template-columns: 1fr; } }
.furn-row .fname { text-align: left; min-width: 0; }
.furn-bar .chk { white-space: nowrap; }

/* ---------- repair jobs ---------- */
.rates-warn { background: #fdf3dc; border: 1px solid #e8cf94; color: #7a5200; border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; font-size: 14px; }
[data-jpanel][hidden] { display: none; }
.qt-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 12px; }
.qt-steps span { color: var(--muted); }
.step { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 12px; font-size: 13px; cursor: pointer; }
.step.past { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.step.now { background: var(--gold); color: #fff; border-color: var(--gold); font-weight: 600; }
.step:disabled { cursor: default; opacity: .6; }
.qline { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; background: #fff; }
.qline.custom { border-color: #e8cf94; background: #fffbf2; }
.qrow { display: grid; grid-template-columns: 1fr 56px 62px 74px 86px 84px 24px; gap: 4px; align-items: center; }
.qrow input, .qrow select { min-width: 0; width: 100%; padding: 5px 6px; font-size: 14px; }
.qamt { font-weight: 600; font-size: 14px; }
.qinfo { font-size: 12px; color: var(--muted); margin-top: 3px; }
.qinfo b.bad, .qt-analysis b.bad { color: var(--bad); }
.qreason { width: 100%; margin-top: 4px; font-size: 13px; padding: 4px 6px; }
.qreason.missing { border-color: var(--bad); background: var(--bad-soft); }
.qt-analysis { margin-top: 12px; background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 14px; }
.qt-analysis div { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.qt-analysis div.big { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.check { border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 8px 0; }
.check.ok { background: var(--ok-soft); color: #1f5a36; }
.check.warn { background: var(--warn-soft); color: #7a4700; }
.check.bad { background: var(--bad-soft); color: #8a2a23; }
.ph-tag { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 4px; padding: 0 6px; }
.rt-trades { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; max-width: 520px; }
.rt-row { display: grid; grid-template-columns: 1fr 110px 60px 24px; gap: 6px; align-items: center; }
@media (max-width: 900px) {
  .qrow { grid-template-columns: 1fr 1fr 1fr; }
  .qrow .qdesc { grid-column: 1 / -1; }
  .qrow .qamt { text-align: right; }
}
.qrow { grid-template-columns: 64px 70px 84px 1fr 96px 24px; }
.qrow .qdesc { grid-column: 1 / -1; font-weight: 600; }
.form2 input[type=checkbox], .form3 input[type=checkbox], .form2 input[type=radio] { width: auto; flex: none; }

.qscope { margin: 2px 0 0; padding-left: 18px; font-size: 12px; color: #444; }
.qscope li { margin: 0; }

/* contracts made before the system */
#ct-editor.legacy .ct-full { display: none !important; }
.bar.wrap { flex-wrap: wrap; gap: 8px 18px; }
.badge.legacy { background: #ece6f7; color: #5a3f8f; }
#lg-table tr.off td { color: var(--muted); }
#lg-table .note { font-size: 12px; }
