:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e7ec;
  --primary: #1f6f5c;
  --primary-hover: #185a4a;
  --primary-soft: #e4f2ee;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --ok: #1e8e4e;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.1rem; margin: 0 0 .9rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0 .9rem; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.cap { text-transform: capitalize; }
.prewrap { white-space: pre-wrap; }
.ok { color: var(--ok); }
.bad { color: var(--danger); }

/* ---- top bar ---- */
.topbar { background: #14352d; color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: #cfe3dc; padding: .4rem .7rem; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.15); color: #fff; }
.userbox { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.userbox a { color: #fff; }
.userbox form { margin: 0; }
.linkbtn { background: none; border: 0; color: #cfe3dc; cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: #fff; text-decoration: underline; }
.role-chip { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 999px; font-weight: 600; }
.role-manager { background: #dbeafe; color: #1e40af; }
.role-cashier { background: #fef3c7; color: #92400e; }

/* ---- layout ---- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin: 0 0 .2rem !important; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 520px; }
.card.info { background: var(--primary-soft); border-color: #c7e3da; font-size: .9rem; }
.card.empty { text-align: center; padding: 3rem 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.two-col > .card { margin-bottom: 0; }
.two-col.wide-left { grid-template-columns: 3fr 2fr; }
.two-col + * { margin-top: 1.25rem; }
section { margin-bottom: 1.25rem; }
.row-between { display: flex; justify-content: space-between; }

/* ---- flash ---- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: #e8f6ee; border-color: #b9e2c9; color: #14532d; }
.flash-error { background: var(--danger-soft); border-color: #f5c2bd; color: #7f1d1d; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; list-style: none;
}
.btn:hover { background: #f1f3f5; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-danger-outline { color: var(--danger); border-color: #f0b8b1; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-lg { padding: .75rem 1.4rem; font-size: 1.05rem; }
summary.btn::-webkit-details-marker { display: none; }

/* ---- forms ---- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; }
label > span, .field-label { font-weight: 500; color: #344054; font-size: .88rem; display: block; margin-bottom: .3rem; }
label > span { margin-bottom: 0; }
input, select, textarea {
  font: inherit; padding: .55rem .7rem; border: 1px solid #cfd5dc; border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd4c5; border-color: var(--primary); }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.inline-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin: 1rem 0 0; }
.inline-form label { flex-direction: column; }
.inline-form input, .inline-form select { width: auto; }
.page-head .inline-form { margin: 0; }
.toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }
.toolbar select { width: auto; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; align-items: end; }
label.check { flex-direction: row; align-items: center; gap: .4rem; padding-bottom: .6rem; }
label.check input { width: auto; }
.amount-input { font-size: 1.25rem; font-weight: 600; }

.dropzone {
  border: 2px dashed #c3ccd5; border-radius: 10px; padding: 1.2rem; text-align: center;
  cursor: pointer; background: #fafbfc; color: var(--muted);
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone input { border: 0; padding: 0; background: transparent; }
.upload-form { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.upload-form .btn { align-self: flex-start; }
.preview-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.preview-row img { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.file-chip { padding: .3rem .6rem; background: #f1f3f5; border-radius: 6px; font-size: .85rem; }

/* ---- badges ---- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; text-transform: capitalize; }
.status-available { background: #dcfce7; color: #166534; }
.status-occupied { background: #dbeafe; color: #1e40af; }
.status-reserved { background: #fef3c7; color: #92400e; }
.status-maintenance { background: #e5e7eb; color: #374151; }
.standing-overdue { background: var(--danger-soft); color: #991b1b; }
.standing-current { background: #dcfce7; color: #166534; }
.standing-advance { background: #e0f2fe; color: #075985; }
.tag { display: inline-block; background: #f1f3f5; border-radius: 6px; padding: .1rem .5rem; margin: 0 .3rem .3rem 0; font-size: .82rem; }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; color: var(--text); box-shadow: var(--shadow);
}
a.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat.compact { padding: .6rem 1rem; text-align: right; }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.stat-value { font-size: 1.55rem; font-weight: 700; }
.small-value { font-size: 1.1rem; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .6rem .75rem; border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap; }
.table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tr.voided td { opacity: .5; }
.table tr.voided td.num { text-decoration: line-through; }
.card:not(.flush) .table th { background: transparent; }
.card:not(.flush) .table td:first-child, .card:not(.flush) .table th:first-child { padding-left: 0; }
.row-actions { display: flex; gap: .4rem; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.row-actions details form { margin-top: .4rem; }
.summary-bar { display: flex; gap: 1.5rem; margin: 0 0 .75rem; font-size: .95rem; }

/* ---- details lists ---- */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); font-size: .88rem; }
.details dd { margin: 0; }
.details.cols { grid-template-columns: repeat(4, max-content 1fr); }

/* ---- properties & rooms ---- */
.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.prop-card { color: var(--text); margin: 0; }
.prop-card:hover { border-color: var(--primary); text-decoration: none; }
.prop-card h2 { margin-bottom: .2rem; }
.prop-counts { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .9rem; }
.filter-tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-tabs a { padding: .4rem .85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .9rem; }
.filter-tabs a:hover { text-decoration: none; border-color: var(--primary); }
.filter-tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.filter-row { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-row .filter-tabs { margin-bottom: 0; }
.filter-row > p { margin: .45rem 0 0; }
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.view-toggle a { padding: .4rem .8rem; color: var(--text); font-size: .9rem; white-space: nowrap; }
.view-toggle a + a { border-left: 1px solid var(--border); }
.view-toggle a:hover { background: #f1f3f5; text-decoration: none; }
.view-toggle a.active { background: var(--primary); color: #fff; }
.room-table td { vertical-align: middle; }
.room-table tr.clickable { cursor: pointer; }
.room-table tr.clickable:hover td { background: #f7faf9; }
.thumb-cell { width: 64px; padding-right: 0 !important; }
.thumb-cell img, .thumb-empty { display: block; width: 56px; height: 42px; object-fit: cover; border-radius: 6px; background: #eef1f4; }

.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.room-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.room-card:hover { border-color: var(--primary); text-decoration: none; }
.room-thumb { position: relative; aspect-ratio: 4 / 3; background: #eef1f4; display: flex; align-items: center; justify-content: center; }
.room-thumb img { width: 100%; height: 100%; object-fit: cover; }
.room-thumb .badge { position: absolute; top: .5rem; left: .5rem; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.no-photo { color: #9aa4b0; font-size: .85rem; }
.room-body { padding: .75rem .9rem; display: flex; flex-direction: column; gap: .15rem; }
.room-title { font-weight: 600; font-size: 1.02rem; }
.room-rent { font-weight: 600; margin-top: .25rem; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.photo { position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: #eef1f4; }
.photo img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.photo form { position: absolute; top: .35rem; right: .35rem; margin: 0; }
.photo-del { border: 0; background: rgba(0,0,0,.55); color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: .8rem; }
.photo-del:hover { background: var(--danger); }
.cover-tag { position: absolute; left: .35rem; bottom: .35rem; background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; padding: .1rem .45rem; border-radius: 4px; }

.lease { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.lease-head { display: flex; justify-content: space-between; align-items: center; }
.lease-head h3 { margin: 0 0 .75rem; }
.lease-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-start; }
.lease-actions details[open] { flex-basis: 100%; border-top: 1px solid var(--border); padding-top: .75rem; }
.lease-actions details form { margin-top: .75rem; }
.danger-zone { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.danger-zone summary { color: var(--danger); cursor: pointer; font-size: .9rem; }
.danger-zone form { margin-top: .75rem; }

/* ---- payments ---- */
.amount-big { font-size: 2.2rem; font-weight: 700; margin-bottom: 1rem; color: var(--primary); }
.amount-big.struck { text-decoration: line-through; color: var(--muted); }
.proof-img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.proof-frame { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 8px; }

/* ---- cashier ---- */
.search-bar { display: flex; gap: .5rem; margin-bottom: .75rem; }
.search-bar .btn { padding-left: 1.2rem; padding-right: 1.2rem; }
.compact-search { margin: 0; min-width: 260px; }
.big-search { font-size: 1.1rem; padding: .8rem 1rem; flex: 1; min-width: 0; }
.tenant-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; }
.pick-card { display: flex; justify-content: space-between; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; color: var(--text); box-shadow: var(--shadow); }
.pick-card:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }
.pick-name { font-weight: 600; font-size: 1.05rem; }
.pick-right { text-align: right; display: flex; flex-direction: column; gap: .3rem; align-items: flex-end; }
.mini-list { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.mini-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: 0; }

/* ---- contract edit ---- */
.rent-mode { border: 1px solid var(--border); background: #fafbfc; border-radius: 8px; padding: .75rem 1rem; margin-top: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.rent-mode p { margin: 0; }
.radio-row { flex-direction: row; align-items: flex-start; gap: .6rem; font-size: .9rem; cursor: pointer; }
.radio-row input { width: auto; margin-top: .25rem; accent-color: var(--primary); }
.rent-mode .effective { margin-left: 1.6rem; max-width: 240px; }
.danger-link { color: var(--danger) !important; font-size: .85rem; }
.mini-list .row-actions { align-items: center; }

/* ---- users & access ---- */
.access-chip { background: var(--primary-soft); color: var(--primary); }
.acl-table th.acl-col { font-size: .68rem; text-align: center; white-space: normal; min-width: 64px; line-height: 1.2; }
.acl-table td.acl-col { text-align: center; }
.lvl { font-size: .78rem; font-weight: 600; }
.lvl-none { color: #b0b8c1; }
.lvl-view { color: #1e40af; }
.lvl-edit { color: var(--ok); }
.perm-matrix .lvl-head, .perm-matrix .lvl-cell { text-align: center; width: 90px; }
.perm-matrix input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.perm-matrix td { vertical-align: middle; }
.preset-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.static-field { padding: .55rem 0; }

/* ---- auth ---- */
.auth-card { max-width: 400px; margin: 8vh auto 0; padding: 2rem; }
.auth-card h1 { font-size: 1.4rem; }

/* ---- lightbox ---- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out; padding: 1rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* ---- responsive ---- */
@media (max-width: 860px) {
  .two-col, .two-col.wide-left { grid-template-columns: 1fr; }
  .two-col > .card { margin-bottom: 0; }
  .details.cols { grid-template-columns: max-content 1fr; }
  .topbar { position: static; }
  .userbox { width: 100%; justify-content: flex-end; }
}

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}
