:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #16202b;
  --muted: #5b6776;
  --faint: #8a95a3;
  --line: #e2e7ed;
  --accent: #1d64d8;
  --accent-ink: #ffffff;
  --accent-soft: #e7effc;
  --danger: #c2453d;
  --ok: #2f8f55;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --st-available: #3a9d5d;
  --st-hold: #e3a92b;
  --st-booked: #e07a3a;
  --st-sold: #c2453d;
  --st-unknown: #c9b98f;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 16px; height: 16px; }

.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); width: 100%; outline: none;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 72px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 550; }
label.field > span { color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--surface-2); border: 1px solid var(--line); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- toast & dialogs ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; pointer-events: none; }
.toast { background: #1d2733; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 550; animation: toast-in .2s ease-out; max-width: min(90vw, 520px); }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

dialog { border: 0; border-radius: 16px; padding: 0; box-shadow: var(--shadow); width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(15, 23, 32, .45); }
.dlg { padding: 20px; display: grid; gap: 14px; }
.dlg-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.dlg-head h3 { font-size: 18px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* =========================================================== showroom */
.showroom { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { min-width: 0; flex: 1; }
.brand h1 { font-size: 17px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.stage { position: relative; flex: 1; min-height: 0; background: #e6ebef; }
.view { position: absolute; inset: 0; }
.view canvas { display: block; touch-action: none; }
.view svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; }
.view svg.dragging { cursor: grabbing; }

.overlay-tl { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; pointer-events: none; z-index: 3; }
.overlay-tl > * { pointer-events: auto; }
.search { position: relative; width: 200px; }
.search input { padding-left: 32px; box-shadow: var(--shadow-sm); }
.search svg { position: absolute; left: 10px; top: 10px; width: 16px; height: 16px; color: var(--faint); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; box-shadow: var(--shadow-sm); }
.chip .n { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.off { opacity: .5; }
.chip.off .dot { background: transparent !important; box-shadow: inset 0 0 0 2px var(--faint); }

.overlay-br { position: absolute; right: 12px; bottom: 12px; display: grid; gap: 6px; z-index: 3; }
.overlay-br .btn { box-shadow: var(--shadow-sm); }
.stage.panel-open .overlay-br { right: 384px; }
.compass { position: absolute; left: 12px; bottom: 12px; z-index: 3; background: var(--surface); border: 1px solid var(--line); border-radius: 50%; width: 44px; height: 44px; display: grid; place-items: center; box-shadow: var(--shadow-sm); font-size: 9px; font-weight: 800; color: var(--muted); }
.compass .rose { position: relative; width: 40px; height: 40px; display: grid; place-items: center; transition: transform .15s linear; }
.compass .rose b { position: absolute; top: -1px; left: 50%; transform: translateX(-50%); line-height: 1; color: #d93a3a; }
.compass .rose svg { margin-top: 4px; }

#tooltip { position: absolute; z-index: 6; pointer-events: none; background: rgba(13, 17, 23, .96); color: #f2f6f7; padding: 12px 16px; border-radius: 12px; font-size: 14px; white-space: nowrap; transform: translate(14px, 14px); box-shadow: 0 8px 24px rgba(0, 0, 0, .3); min-width: 190px; border: 1px solid rgba(255, 255, 255, .06); }
#tooltip .tip-title { color: #a259ff; font: 700 15px ui-monospace, SFMono-Regular, Consolas, monospace; margin-bottom: 6px; }
#tooltip .tip-row { display: flex; justify-content: space-between; gap: 22px; line-height: 1.75; }
#tooltip .tip-row span { color: #aab4be; }
#tooltip .tip-row b { font-weight: 700; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 8; background: #e6ebef; }
.loading .box { text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #cfd8e0; border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* plot panel */
.panel { position: absolute; top: 12px; right: 12px; bottom: 12px; width: 360px; z-index: 7; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: panel-in .18s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateX(12px); } }
.panel-scroll { overflow-y: auto; padding: 18px; display: grid; gap: 16px; grid-auto-rows: max-content; align-content: start; flex: 1 1 auto; min-height: 0; }
.panel-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.eyebrow { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 700; }
.panel-head h2 { font-size: 26px; font-weight: 800; }
.btn.wa-share { background: #25d366; border-color: #25d366; color: #fff; }
.btn.wa-share:hover { background: #1ebe5b; border-color: #1ebe5b; color: #fff; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 0; }
.facts > div { background: var(--surface); padding: 10px 12px; }
.facts dt { font-size: 11.5px; color: var(--faint); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 2px 0 0; font-weight: 650; }
.facts .wide { grid-column: span 2; }
.price-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.price-box .big { font-size: 22px; font-weight: 800; }
.emi { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 10px; }
.emi h3 { font-size: 14px; }
.emi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.emi-grid label { font-size: 11.5px; color: var(--muted); font-weight: 600; display: grid; gap: 3px; }
.emi-grid input { height: 32px; }
.emi-out { display: flex; justify-content: space-between; align-items: baseline; }
.emi-out strong { font-size: 18px; }
.panel-actions { padding: 12px 18px 18px; display: grid; gap: 8px; border-top: 1px solid var(--line); }
.panel-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.partner-note { font-size: 12.5px; color: var(--muted); text-align: center; }

.notfound { display: grid; place-items: center; height: 100%; text-align: center; padding: 24px; }

@media (max-width: 720px) {
  .topbar { padding: 8px 12px; }
  .top-actions .label-lg { display: none; }
  .top-actions { gap: 6px; }
  .top-actions .btn { width: 36px; padding: 0; }
  #unitSel { padding: 0 4px; }
  .search { width: 100%; }
  .overlay-tl { top: 8px; left: 8px; right: 8px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; padding-bottom: 2px; }
  .chip { flex: none; }
  .overlay-br { bottom: 64px; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72dvh; border-radius: 18px 18px 0 0; animation: sheet-in .2s ease-out; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
}

/* =========================================================== index */
.page { max-width: 1040px; margin: 0 auto; padding: 32px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; font-weight: 800; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.proj-card { padding: 18px; display: grid; gap: 8px; color: inherit; transition: box-shadow .15s, transform .15s; }
.proj-card:hover { box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.proj-card h2 { font-size: 18px; }

/* =========================================================== admin */
.admin-bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.admin-bar .logo { font-weight: 800; font-size: 16px; }
.admin-main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 80px; display: grid; gap: 20px; }
.section { padding: 20px; display: grid; gap: 16px; }
.section h2 { font-size: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.form-grid .span-all { grid-column: 1 / -1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 650; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: 70vh; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 700; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td .input { height: 30px; min-width: 90px; }
.tbl td.r, .tbl th.r { text-align: right; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.stat { padding: 14px; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.report { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 6px; font-size: 13.5px; }
.report .warn { color: #a3591a; }
.report .bad { color: var(--danger); }
.report .good { color: var(--ok); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.login-box { max-width: 380px; margin: 12vh auto; padding: 28px; display: grid; gap: 16px; }
.copy { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; word-break: break-all; }
