/* Layout: left rail nav on desktop, bottom tab bar on phones; content as dense ledger-style tables and status chips. */
:root {
  --bg: #F2F5F3;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --ink: #15201C;
  --muted: #5D6B66;
  --line: #DCE3E0;
  --accent: #0E6E55;
  --accent-ink: #FFFFFF;
  --accent-soft: #E0EFE9;
  --ok: #1E7A3E;      --ok-soft: #E1F2E5;
  --warn: #A86300;    --warn-soft: #FBEED6;
  --bad: #B3261E;     --bad-soft: #FBE2DF;
  --info: #2F5E9E;    --info-soft: #E3ECF8;
  --shadow: 0 1px 2px rgba(16, 32, 28, .06), 0 4px 16px rgba(16, 32, 28, .06);
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-head: "Space Grotesk", "Inter", system-ui, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1412; --surface: #161F1C; --surface-2: #1B2522; --ink: #E4ECE8; --muted: #93A39D; --line: #2A3632;
    --accent: #3FB58E; --accent-ink: #06140F; --accent-soft: #173A2F;
    --ok: #6CCB8B; --ok-soft: #173220; --warn: #E6A847; --warn-soft: #3A2B12; --bad: #F2847C; --bad-soft: #3D1B19;
    --info: #8DB4EA; --info-soft: #1B2A40;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-family: var(--font-head); font-weight: 700; font-size: 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 15px; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link .badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.rail-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.who { display: flex; gap: 8px; align-items: center; min-width: 0; }
.who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; }

.main { min-width: 0; padding-block: 24px 48px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.demo-bar {
  background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
}
.demo-bar b { color: var(--ink); }

/* Bottom tab bar on phones */
.tabbar { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); padding-top: 16px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px max(4px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px));
  }
  .tabbar a { text-align: center; text-decoration: none; color: var(--muted); font-size: 11px; padding: 4px 0; border-radius: 8px; position: relative; }
  .tabbar a .ico { display: block; font-size: 18px; line-height: 1.2; }
  .tabbar a.active { color: var(--accent); background: var(--accent-soft); }
  .tabbar .dot { position: absolute; top: 2px; right: 22%; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
  .mobile-top { display: flex !important; }
}
.mobile-top { display: none; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* ---------- Building blocks ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn:focus-visible, .nav-link:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .55; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.section { margin-top: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-family: var(--font-head); font-size: 24px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.card.table-wrap > table { min-width: 820px; }
.modal .card.table-wrap > table { min-width: 520px; }
td .t-main { white-space: nowrap; }
.kpi .value { white-space: nowrap; font-size: clamp(18px, 2.2vw, 24px); }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.right, th.right { text-align: right; }
td .t-main { font-weight: 600; }
td .t-sub { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.list { display: grid; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .li-main { min-width: 0; }
.list-item .li-title { font-weight: 600; }
.list-item .li-sub { font-size: 12px; color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 15px; }

.prop-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.prop-card { padding: 16px; display: grid; gap: 10px; }
.prop-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.prop-card .stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.prop-card .stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.prop-card .stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Rent month ledger */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 6px; }
.month { border-radius: 8px; padding: 6px 8px; font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.month b { display: block; font-size: 13px; }
.month.paid { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.month.pending { background: var(--info-soft); border-color: transparent; color: var(--info); }
.month.due { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.month.future { opacity: .6; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

.receipt-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); display: block; }

/* ---------- Forms & modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 12, .45); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
@media (max-width: 600px) {
  .modal-wrap { padding: 0; place-items: end stretch; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; }
  .modal-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink) !important; font-size: 14px !important; }
.form-error { grid-column: 1 / -1; background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
@media (max-width: 820px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth-card { width: min(400px, 100%); padding: 28px; display: grid; gap: 16px; }
.auth-card .brand { padding: 0; }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 500; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: none; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .modal { animation: pop .14s ease-out; }
  @keyframes pop { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* Brand lockup: short name over full name */
.brand-text { display: grid; line-height: 1.1; min-width: 0; }
.brand-sub { font-family: var(--font-body); font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .01em; }
