:root {
  --ink: #172033;
  --muted: #667085;
  --line: #e7eaf0;
  --paper: #ffffff;
  --canvas: #f5f6fa;
  --brand: #5147d9;
  --brand-dark: #3730a3;
  --brand-soft: #efefff;
  --green: #087c5b;
  --green-soft: #e9f8f2;
  --amber: #ad6500;
  --amber-soft: #fff5df;
  --red: #c33445;
  --red-soft: #fff0f2;
  --shadow: 0 14px 34px rgba(22, 31, 52, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.shell { min-height: 100vh; padding-bottom: 90px; }
.topbar { background: linear-gradient(135deg, #302987, var(--brand)); color: white; }
.topbar-inner, .page { width: min(1120px, calc(100% - 32px)); margin: auto; }
.topbar-inner { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,.15); font-size: 20px; }
.brand strong { display: block; font-size: 18px; letter-spacing: -.02em; }
.brand small { display: block; color: #dcd9ff; font-size: 11px; margin-top: 1px; }
.top-link { padding: 9px 13px; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; text-decoration: none; font-size: 13px; font-weight: 700; }

.page { padding-top: 30px; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 5vw, 40px); line-height: 1.1; letter-spacing: -.04em; }
h2 { margin-bottom: 6px; font-size: 20px; letter-spacing: -.02em; }
h3 { margin-bottom: 4px; font-size: 15px; }
.subtle { color: var(--muted); line-height: 1.55; }
.small { font-size: 12px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.auth-wrap { display: grid; grid-template-columns: 1.05fr .95fr; max-width: 900px; margin: 30px auto; overflow: hidden; }
.auth-aside { padding: 42px; color: white; background: linear-gradient(155deg, #2d277b 0%, var(--brand) 100%); }
.auth-aside h1 { font-size: 38px; margin-top: 50px; }
.auth-aside p { color: #dfddff; }
.auth-form { padding: 42px; background: white; }
.feature-list { display: grid; gap: 12px; margin-top: 30px; }
.feature { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #eeedff; }
.feature i { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; background: rgba(255,255,255,.14); font-style: normal; }

.field { margin-top: 18px; }
.field label { display: block; margin-bottom: 7px; color: #344054; font-size: 13px; font-weight: 700; }
.field-label { display: block; margin-bottom: 7px; color: #344054; font-size: 13px; font-weight: 700; }
.control { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid #d8dde7; border-radius: 11px; background: #fbfcfe; color: var(--ink); outline: none; }
.control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.hint { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.btn { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: 0; border-radius: 11px; font-weight: 800; font-size: 13px; text-decoration: none; transition: transform .15s, background .15s; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: white; background: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { color: white; background: var(--green); }
.btn-danger { color: var(--red); background: var(--red-soft); }
.btn-ghost { color: var(--brand); background: var(--brand-soft); }
.btn-wide { width: 100%; margin-top: 22px; }
.btn:disabled { cursor: not-allowed; opacity: .55; transform: none; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat { padding: 18px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-value { margin-top: 7px; font-size: 25px; font-weight: 850; letter-spacing: -.04em; }
.stat-note { margin-top: 5px; color: var(--muted); font-size: 11px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.section-head p { margin-bottom: 0; }
.units { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.unit { position: relative; min-height: 146px; padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: white; text-align: left; }
.unit.selectable:hover { border-color: var(--brand); box-shadow: 0 8px 20px rgba(81,71,217,.1); }
.unit.admin-unit { cursor: pointer; font: inherit; color: inherit; }
.unit.admin-unit:hover, .unit.admin-unit:focus-visible { border-color: var(--brand); box-shadow: 0 8px 20px rgba(81,71,217,.1); outline: none; }
.unit.selected { border: 2px solid var(--brand); background: #fafaff; }
.unit.disabled { cursor: not-allowed; opacity: .62; }
.unit-number { margin-bottom: 22px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.unit strong { display: block; margin-bottom: 4px; font-size: 16px; }
.unit-meta { color: var(--muted); font-size: 11px; }
.unit-action { display: block; margin-top: 12px; color: var(--brand); font-size: 11px; font-weight: 800; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; }
.unit .badge { position: absolute; top: 12px; right: 12px; }
.unit-with-photo { padding: 0; overflow: hidden; }
.unit-card-body { position: relative; padding: 14px; }
.unit-with-photo .unit-number { margin-bottom: 7px; }
.unit-photo { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #eef0f4; }
.unit-photo-empty { display: grid; place-items: center; align-content: center; gap: 4px; color: #858da0; }
.unit-photo-empty span { font-size: 32px; }
.unit-photo-empty small { font-size: 10px; font-weight: 700; }
.unit-description { margin: 10px 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.facility-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.facility-chips span { padding: 4px 7px; border-radius: 999px; color: var(--brand-dark); background: var(--brand-soft); font-size: 9px; font-weight: 750; }
.admin-unit-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 13px; }
.admin-unit-actions .btn { min-height: 36px; padding: 7px; font-size: 11px; }
.badge-available, .badge-paid { color: var(--green); background: var(--green-soft); }
.badge-pending { color: var(--amber); background: var(--amber-soft); }
.badge-occupied, .badge-overdue, .badge-rejected { color: var(--red); background: var(--red-soft); }
.badge-maintenance { color: #475467; background: #eef0f4; }

.booking { margin-top: 20px; padding: 22px; }
.booking-unit-summary { display: grid; grid-template-columns: 210px 1fr; align-items: center; gap: 18px; margin-bottom: 22px; }
.booking-unit-summary .unit-photo { border-radius: 13px; }
.upload { position: relative; padding: 24px; border: 1.5px dashed #cdd3df; border-radius: 13px; background: #fafbfc; text-align: center; }
.upload input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.upload-icon { font-size: 25px; }
.upload p { margin: 5px 0 0; font-size: 12px; font-weight: 700; }

.profile { display: flex; align-items: center; gap: 12px; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px; border-radius: 13px; background: var(--brand-soft); color: var(--brand); font-weight: 850; }
.due-countdown { display: grid; place-items: center; margin-top: 24px; padding: 34px 20px; border-radius: 16px; color: var(--brand-dark); background: var(--brand-soft); text-align: center; }
.due-countdown span { color: var(--muted); font-size: 13px; }
.due-countdown strong { margin: 4px 0 -5px; font-size: clamp(72px, 13vw, 118px); line-height: 1; letter-spacing: -.08em; }
.due-countdown b { font-size: 18px; }
.lease-start { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfc; }
.lease-start span { color: var(--muted); font-size: 12px; }
.lease-start strong { font-size: 14px; }
.money { color: var(--green); font-weight: 850; }

.payments { display: grid; gap: 10px; }
.payment { padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.payment-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.payment-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.payment-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }
.payment-proof { display: grid; gap: 6px; margin-top: 11px; padding: 10px; border-radius: 10px; background: #f7f7fb; font-size: 11px; }
.payment-proof > span:first-child { color: var(--muted); }
.proof-link { padding: 0; border: 0; color: var(--brand); background: transparent; text-align: left; font-size: 11px; font-weight: 800; text-decoration: underline; }
.proof-unavailable { color: var(--red); font-size: 10px; }
.period-options { display: grid; max-height: 285px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; }
.period-option { display: grid !important; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin: 0 !important; padding: 11px 12px; cursor: pointer; }
.period-option + .period-option { border-top: 1px solid var(--line); }
.period-option:has(input:checked) { background: var(--brand-soft); }
.period-option input { width: 17px; height: 17px; accent-color: var(--brand); }
.period-option span strong, .period-option span small { display: block; }
.period-option span strong { font-size: 12px; }
.period-option span small { margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 500; }
.period-option > b { font-size: 11px; }
.payment-total { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding: 12px; border-radius: 11px; background: #f6f7fa; font-size: 12px; }
.payment-total strong { color: var(--green); font-size: 15px; }
.empty { padding: 28px; color: var(--muted); border: 1px dashed #d5dae3; border-radius: 13px; text-align: center; font-size: 13px; }

.bottom-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; border-top: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(14px); }
.bottom-nav-inner { display: flex; width: min(520px, 100%); height: 67px; margin: auto; align-items: center; justify-content: space-around; }
.nav-item { display: grid; gap: 3px; min-width: 70px; color: var(--muted); text-align: center; text-decoration: none; font-size: 10px; font-weight: 700; }
.nav-item b { font-size: 18px; line-height: 1; }
.nav-item.active { color: var(--brand); }
.toast { position: fixed; z-index: 50; right: 20px; bottom: 88px; max-width: 330px; padding: 13px 16px; border-radius: 11px; color: white; background: #222936; box-shadow: var(--shadow); font-size: 13px; transform: translateY(16px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: translateY(0); opacity: 1; }
.otp-demo { margin-top: 15px; padding: 12px; border-radius: 10px; color: #5f4700; background: var(--amber-soft); font-size: 12px; text-align: center; }
.history-dialog { width: min(720px, calc(100% - 24px)); max-height: min(760px, calc(100vh - 32px)); padding: 22px; border: 0; border-radius: 18px; color: var(--ink); background: white; box-shadow: 0 24px 80px rgba(19, 25, 43, .24); }
.history-dialog::backdrop { background: rgba(20, 25, 40, .56); backdrop-filter: blur(3px); }
.proof-dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 22px; border: 0; border-radius: 18px; color: var(--ink); background: white; box-shadow: 0 24px 80px rgba(19, 25, 43, .24); }
.proof-dialog::backdrop { background: rgba(20, 25, 40, .65); backdrop-filter: blur(3px); }
.proof-content { display: grid; min-height: 280px; max-height: 62vh; place-items: center; overflow: auto; border: 1px solid var(--line); border-radius: 13px; background: #f4f5f8; }
.proof-content img { display: block; width: 100%; max-height: 62vh; object-fit: contain; }
.proof-content iframe { width: 100%; height: 60vh; border: 0; }
.proof-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 14px; }
.proof-actions form { margin: 0; }
.loading-card { max-width: 360px; margin: 18vh auto 0; text-align: center; }
.spinner { display: inline-block; width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.form-error { padding: 11px 13px; margin: 12px 0; color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dialog-close { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; color: var(--muted); background: #f1f2f6; font-size: 24px; line-height: 1; }
.tenant-histories { display: grid; gap: 10px; }
.tenant-history { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.tenant-history summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px; cursor: pointer; list-style-position: inside; background: #fafbfc; }
.tenant-history summary strong, .tenant-history summary small { display: block; }
.tenant-history summary small { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tenant-history[open] summary { border-bottom: 1px solid var(--line); }
.tenant-profile { display: grid; grid-template-columns: 180px 1fr; gap: 18px; padding: 16px; }
.ktp-photo img, .ktp-missing { display: block; width: 100%; aspect-ratio: 1.68; border-radius: 10px; object-fit: cover; background: #f1f2f6; }
.ktp-missing { display: grid; place-items: center; padding: 12px; color: var(--muted); font-size: 11px; text-align: center; }
.ktp-photo small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; overflow-wrap: anywhere; }
.tenant-profile dl { display: grid; gap: 10px; margin: 0; }
.tenant-profile dl div { display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.tenant-profile dt { color: var(--muted); font-size: 11px; }
.tenant-profile dd { margin: 0; font-size: 12px; font-weight: 700; }
.tenant-history > .payments { padding: 0 16px 16px; }
.auth-catalog-link { margin-top: 24px; color: white; border: 1px solid rgba(255,255,255,.28); background: rgba(255,255,255,.12); }
.public-catalog { margin: 34px 0 10px; }
.catalog-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.catalog-unit { overflow: hidden; }
.catalog-unit-body { padding: 16px; }
.catalog-unit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.catalog-unit-head h3 { margin: 2px 0 0; font-size: 20px; }
.catalog-unit-price { display: flex; align-items: baseline; gap: 7px; margin-top: 15px; }
.catalog-unit-price strong { color: var(--green); font-size: 17px; }
.catalog-unit-price span { color: var(--muted); font-size: 10px; }
.unit-dialog.gallery-dialog { width: min(900px, calc(100% - 24px)); }
.unit-gallery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 18px; }
.gallery-photo { position: relative; margin: 0; overflow: hidden; border-radius: 13px; background: #f1f2f6; }
.gallery-photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.gallery-photo-featured { grid-column: 1 / -1; }
.gallery-photo-featured img { aspect-ratio: 2 / 1; }
.gallery-photo figcaption { position: absolute; left: 10px; bottom: 10px; padding: 5px 8px; border-radius: 999px; color: white; background: rgba(33, 38, 56, .78); font-size: 10px; font-weight: 800; }
.unit-dialog { width: min(700px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 22px; overflow-y: auto; border: 0; border-radius: 18px; color: var(--ink); background: white; box-shadow: 0 24px 80px rgba(19, 25, 43, .24); }
.unit-dialog::backdrop { background: rgba(20, 25, 40, .65); backdrop-filter: blur(3px); }
.unit-form { display: grid; gap: 15px; }
.status-manager { margin-top: 22px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #f7f7fb; }
.status-manager h3 { margin: 3px 0 6px; }
.status-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 7px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 750; }
.unit-photo-manager { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 10px; }
.unit-photo-item { position: relative; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; }
.unit-photo-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.unit-photo-item figcaption { display: grid; gap: 4px; padding: 7px; overflow: hidden; color: var(--muted); font-size: 9px; }
.unit-photo-item figcaption > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.featured-choice { display: flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 800; }
.featured-choice input { accent-color: var(--brand); }
.unit-photo-item button { position: absolute; top: 6px; right: 6px; padding: 5px 7px; border: 0; border-radius: 7px; color: white; background: rgba(161, 26, 48, .88); font-size: 9px; font-weight: 800; }
.compact-upload { padding: 17px; }

@media (max-width: 820px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .layout, .auth-wrap { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .units { grid-template-columns: repeat(2, 1fr); }
  .catalog-grid { grid-template-columns: repeat(2, 1fr); }
  .unit-gallery-grid { grid-template-columns: 1fr; }
  .gallery-photo-featured { grid-column: auto; }
}

@media (max-width: 520px) {
  .topbar-inner, .page { width: min(100% - 24px, 1120px); }
  .topbar-inner { min-height: 64px; }
  .page { padding-top: 22px; }
  .hero { align-items: flex-start; flex-direction: column; }
  .top-link { padding: 8px 10px; }
  .auth-wrap { margin: 12px auto; border-radius: 16px; }
  .auth-form, .card-pad, .booking { padding: 18px; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 21px; }
  .units { gap: 9px; }
  .unit { min-height: 138px; padding: 13px; }
  .unit-with-photo { padding: 0; }
  .unit .badge { position: static; margin-bottom: 12px; }
  .unit-number { margin-bottom: 5px; }
  .tenant-profile { grid-template-columns: 1fr; }
  .ktp-photo { max-width: 240px; }
  .tenant-profile dl div { grid-template-columns: 115px 1fr; }
  .catalog-grid, .form-grid, .booking-unit-summary { grid-template-columns: 1fr; }
  .unit-photo-manager { grid-template-columns: repeat(2, 1fr); }
}
