/* ===================================================================
   Design system — CSS variables, light/dark themes.
   No frameworks. Flexbox + Grid. Mobile-first & responsive.
   =================================================================== */
:root {
  /* Warm cream palette */
  --color-bg: #faf5ec;
  --color-surface: #fffdf9;
  --color-surface-2: #f3ebdd;
  --color-text: #2b2620;
  --color-muted: #6f6657;
  --color-border: #e8dccb;
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success: #16a34a;
  --color-info: #0ea5e9;

  /* Sidebar is a standalone dark-indigo accent panel (theme-independent). */
  --color-sidebar: #312e81;
  --color-sidebar-2: #3730a3;
  --color-sidebar-text: #e0e7ff;
  --color-sidebar-muted: #a5b4fc;
  --color-sidebar-active: #6366f1;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);

  --space: 1rem;
  --header-h: 64px;
  --sidebar-w: 240px;
  --max-w: 1100px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: 160ms ease;
}

:root[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-surface: #171a23;
  --color-surface-2: #1f2330;
  --color-text: #e7e9f0;
  --color-muted: #9aa1b2;
  --color-border: #2a2f3d;
  --color-primary: #6366f1;
  --color-primary-hover: #818cf8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0f1117;
    --color-surface: #171a23;
    --color-surface-2: #1f2330;
    --color-text: #e7e9f0;
    --color-muted: #9aa1b2;
    --color-border: #2a2f3d;
    --color-primary: #6366f1;
    --color-primary-hover: #818cf8;
  }
}

/* ── Reset / base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--color-surface-2);
  padding: .1em .4em;
  border-radius: 6px;
  font-size: .9em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }

/* ── Header ───────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header__inner {
  max-width: var(--max-w);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space);
  display: flex;
  align-items: center;
  gap: var(--space);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--color-text); }
.brand:hover { text-decoration: none; }
.brand__logo { font-size: 1.25rem; }
.brand__sub {
  font-weight: 600; font-size: .85rem; color: var(--color-muted);
  padding-left: .55rem; margin-left: .25rem; border-left: 1px solid var(--color-border);
}
@media (max-width: 520px) { .brand__sub { display: none; } }
.header__nav { display: flex; gap: .25rem; margin-left: 1rem; flex-wrap: wrap; }
.header__right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.nav-link {
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-weight: 500;
}
.nav-link:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav-link.is-active { color: var(--color-primary); background: var(--color-surface-2); }

/* ── Language switcher ────────────────────────────────────────── */
.lang-switcher { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; }
.lang-switcher__item {
  padding: .4rem .6rem;
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  color: var(--color-muted);
  border-left: 1px solid var(--color-border);
}
.lang-switcher__item:first-child { border-left: 0; }
.lang-switcher__item:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.lang-switcher__item.is-active { background: var(--color-primary); color: #fff; }

/* ── Layout: sidebar + content ────────────────────────────────── */
.layout {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--space);
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: var(--space);
  align-items: start;
  align-content: start; /* pack rows to the top (mobile: sidebar above content) */
}
/* No sidebar (landing / onboarding): content spans the full width. */
.layout--full { grid-template-columns: 1fr; }
.sidebar {
  position: sticky;
  top: calc(var(--header-h) + var(--space));
  background: var(--color-sidebar);
  background-image: linear-gradient(160deg, var(--color-sidebar-2), var(--color-sidebar));
  border: 1px solid var(--color-sidebar);
  border-radius: var(--radius);
  padding: var(--space);
  display: flex;
  flex-direction: column;
  gap: var(--space);
  color: var(--color-sidebar-text);
  box-shadow: var(--shadow);
}
.sidebar__title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--color-sidebar-muted); }
.sidebar__nav { display: flex; flex-direction: column; gap: .25rem; }
.sidebar__link {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.sidebar__link:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: var(--color-sidebar-active); color: #fff; box-shadow: 0 4px 12px rgba(99, 102, 241, .4); }
.sidebar__footer { margin-top: auto; }
.content { min-width: 0; display: flex; flex-direction: column; gap: var(--space); }

/* ── Footer ───────────────────────────────────────────────────── */
.footer { border-top: 1px solid var(--color-border); background: var(--color-surface); }
.footer__inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--space);
  display: flex; justify-content: space-between; gap: var(--space); flex-wrap: wrap;
  color: var(--color-muted);
  font-size: .875rem;
}

/* ── Page head ────────────────────────────────────────────────── */
.page-head__sub { color: var(--color-muted); }
.page-head--row { display: flex; align-items: center; justify-content: space-between; gap: var(--space); flex-wrap: wrap; }
.page-head__actions { display: flex; gap: .5rem; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--color-surface-2);
  --btn-fg: var(--color-text);
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--primary { --btn-bg: var(--color-primary); --btn-fg: #fff; }
.btn--primary:hover { --btn-bg: var(--color-primary-hover); }
.btn--danger { --btn-bg: var(--color-danger); --btn-fg: #fff; }
.btn--danger:hover { --btn-bg: var(--color-danger-hover); }
.btn--outline { --btn-bg: transparent; --btn-fg: var(--color-text); border-color: var(--color-border); }
.btn--outline:hover { --btn-bg: var(--color-surface-2); }
.btn--ghost { --btn-bg: transparent; --btn-fg: var(--color-muted); }
.btn--ghost:hover { --btn-bg: var(--color-surface-2); --btn-fg: var(--color-text); }
.btn--sm { padding: .35rem .65rem; font-size: .85rem; }

/* ── Cards & grid ─────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: var(--space); }
.grid--cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card__icon { font-size: 1.6rem; }
.card__title { margin: .5rem 0 .25rem; font-size: 1.05rem; }
.card__text { color: var(--color-muted); font-size: .925rem; }

/* ── Dashboard cards (home) ───────────────────────────────────── */
.dash-card {
  display: flex; flex-direction: column; gap: .15rem;
  color: var(--color-text);
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.dash-card:hover { text-decoration: none; transform: translateY(-3px); border-color: var(--color-primary); box-shadow: var(--shadow-lg); }
.dash-card__icon { font-size: 1.7rem; }
.dash-card__title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); font-weight: 700; margin-top: .35rem; }
.dash-card__value { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.dash-card__note { font-size: .85rem; color: var(--color-muted); }

.cta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.cta__actions { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); background: var(--color-surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--color-surface-2); }
/* Keep the cell a real table-cell (so it centers to the row height); the inner
   wrapper lays out the buttons. Making the <td> itself flex broke row alignment. */
.table__actions { text-align: right; white-space: nowrap; vertical-align: middle; }
.row-actions { display: inline-flex; align-items: center; gap: .4rem; }
.inline-form { display: inline; }

/* ── Forms ────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1rem; max-width: 520px; }
.form__group { display: flex; flex-direction: column; gap: .35rem; }
.form__label { font-weight: 600; font-size: .9rem; }
.form__input {
  padding: .6rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.form__actions { display: flex; gap: .6rem; }
.password-field { position: relative; display: block; width: 100%; }
.password-field .form__input { width: 100%; padding-right: 2.6rem; }
.password-toggle {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer;
  font-size: 1.05rem; line-height: 1; padding: .25rem; border-radius: 6px;
}
.password-toggle:hover { background: var(--color-surface-2); }
.form__row { display: flex; gap: 1rem; }
.form__row .form__group { flex: 1; }
textarea.form__input { resize: vertical; min-height: 2.5rem; }
.checkbox { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--color-primary); }
@media (max-width: 520px) { .form__row { flex-direction: column; gap: 1rem; } }

/* ── Expenses: amounts, notes, category tags ──────────────────── */
.num { text-align: right; white-space: nowrap; }
.col-apt { width: 3rem; text-align: center; white-space: nowrap; }
.muted-note { display: block; color: var(--color-muted); font-size: .8rem; margin-top: .15rem; }
.tag {
  display: inline-block; padding: .15rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
  background: var(--color-surface-2); color: var(--color-muted);
}
.tag--cleaning    { background: color-mix(in srgb, #0ea5e9 16%, transparent); color: #0284c7; }
.tag--supplies    { background: color-mix(in srgb, #16a34a 16%, transparent); color: #15803d; }
.tag--maintenance { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #b45309; }
.tag--utilities   { background: color-mix(in srgb, #6366f1 16%, transparent); color: #4f46e5; }

/* ── Detail (show page) ───────────────────────────────────────── */
.detail__list { display: flex; flex-direction: column; }
.detail__row { display: grid; grid-template-columns: 140px 1fr; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--color-border); }
.detail__row:last-child { border-bottom: 0; }
.detail__row dt { color: var(--color-muted); font-weight: 600; }

/* ── Badges & alerts ──────────────────────────────────────────── */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge--info { background: color-mix(in srgb, var(--color-info) 18%, transparent); color: var(--color-info); }
.badge--danger { background: color-mix(in srgb, var(--color-danger) 18%, transparent); color: var(--color-danger); }

.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 500; }
.alert--success { background: color-mix(in srgb, var(--color-success) 14%, transparent); color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 35%, transparent); }
.alert--error { background: color-mix(in srgb, var(--color-danger) 14%, transparent); color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 35%, transparent); }
.alert--info { background: color-mix(in srgb, var(--color-info) 14%, transparent); color: var(--color-info); border-color: color-mix(in srgb, var(--color-info) 35%, transparent); }
.code-form { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.code-form__label { font-weight: 700; }
.code-form__input { width: 180px; max-width: 100%; padding: .4rem .6rem; }
.code-form__value { font-size: 1.05rem; font-weight: 800; letter-spacing: .08em; padding: .2rem .55rem; background: var(--color-surface); border-radius: 6px; }

/* ── Announcements (notice board) ─────────────────────────────── */
.notices { display: flex; flex-direction: column; gap: var(--space); }
.notice {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-muted);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.notice--info    { border-left-color: var(--color-info); }
.notice--warning { border-left-color: #f59e0b; }
.notice--urgent  { border-left-color: var(--color-danger); }
.notice__head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.notice__type { text-transform: uppercase; }
.notice--info .notice__type    { background: color-mix(in srgb, var(--color-info) 16%, transparent); color: #0284c7; }
.notice--warning .notice__type { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #b45309; }
.notice--urgent .notice__type  { background: color-mix(in srgb, var(--color-danger) 16%, transparent); color: var(--color-danger); }
.notice__pin { font-size: .75rem; font-weight: 700; color: var(--color-primary); }
.notice__date { margin-left: auto; color: var(--color-muted); font-size: .82rem; }
.notice__title { font-size: 1.15rem; margin-bottom: .35rem; }
.notice__body { color: var(--color-text); white-space: pre-line; line-height: 1.6; }
.notice__actions { display: flex; gap: .4rem; margin-top: .9rem; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--color-muted); display: flex; flex-direction: column; gap: 1rem; align-items: center; }

/* ── Error pages ──────────────────────────────────────────────── */
.error-page { text-align: center; padding: 3rem 1rem; display: flex; flex-direction: column; gap: .75rem; align-items: center; }
.error-page__code { font-size: 4rem; font-weight: 800; color: var(--color-primary); line-height: 1; }
.error-page__title { font-size: 1.5rem; }
.error-page__text { color: var(--color-muted); }
.error-page__details { list-style: none; padding: .75rem 1rem; background: var(--color-surface-2); border-radius: var(--radius-sm); text-align: left; }
.error-page__stack { text-align: left; overflow-x: auto; max-width: 100%; padding: 1rem; background: var(--color-surface-2); border-radius: var(--radius-sm); font-size: .8rem; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: var(--space); }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); backdrop-filter: blur(2px); }
.modal__dialog {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px; width: 100%;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 1rem;
  animation: modal-in var(--transition);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal__actions { display: flex; gap: .6rem; justify-content: flex-end; }

/* ── Payments page ────────────────────────────────────────────── */
.fee-badge {
  display: inline-flex; align-items: baseline; gap: .3rem;
  padding: .5rem .9rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 800; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
}
.fee-badge small { font-weight: 600; font-size: .72rem; opacity: .85; }
.year-form { display: inline-flex; gap: .4rem; }
.fee-form { display: inline-flex; align-items: center; gap: .4rem; }
.fee-form__label { font-weight: 700; font-size: .85rem; color: var(--color-muted); }
.fee-input { width: 90px; padding: .45rem .6rem; text-align: right; }
.fee-form__cur { font-weight: 700; color: var(--color-muted); }
.fee-form__cur small { font-weight: 600; font-size: .7rem; }
.year-form .form__input { padding: .45rem .6rem; }

.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
.stat__value { font-size: 1.4rem; font-weight: 800; }
.stat__value--danger { color: var(--color-danger); }
.progress { display: block; height: 8px; margin-top: .4rem; background: var(--color-surface-2); border-radius: 999px; overflow: hidden; }
.progress__bar { display: block; height: 100%; background: var(--color-primary); border-radius: 999px; transition: width var(--transition); }

/* Sized by intrinsic content (no forced min-width) so the full grid —
   including the last column — fits on desktop/tablet; phones still scroll. */
.table--grid { min-width: 0; }
/* Higher specificity than the card-view `display: grid`, so search-hidden rows
   stay hidden in both the desktop table and the mobile card layout. */
.table--grid tr[hidden] { display: none; }

.search-input { width: 200px; max-width: 100%; padding: .5rem .75rem; }
@media (max-width: 640px) { .search-input { width: 100%; } }
.table--grid th, .table--grid td { text-align: center; padding: .45rem .2rem; }
.table--grid .col-name { text-align: left; white-space: nowrap; font-weight: 600; }
.table--grid .col-no { width: 2.5rem; color: var(--color-muted); }
.table--grid .col-month { font-size: .72rem; }
.table--grid thead .col-month {
  writing-mode: vertical-rl; transform: rotate(180deg);
  white-space: nowrap; height: 78px; vertical-align: bottom; padding-bottom: .5rem;
}
.table--grid tfoot td { font-weight: 700; background: var(--color-surface-2); border-top: 2px solid var(--color-border); }
.table--grid .total { color: var(--color-primary); }

.pay-cell {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 1rem; font-weight: 800;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.pay-cell:hover { border-color: var(--color-primary); transform: scale(1.08); }
.pay-cell:disabled { opacity: .5; cursor: progress; }
.pay-cell.is-paid { background: color-mix(in srgb, var(--color-primary) 16%, transparent); border-color: var(--color-primary); }
.pay-cell__mark { line-height: 1; }
/* Read-only cells for non-admins: same look, no interaction. */
.pay-cell--readonly { cursor: default; }
.pay-cell--readonly:hover { transform: none; border-color: var(--color-border); }
.pay-cell--readonly.is-paid:hover { border-color: var(--color-primary); }

.auth-form { max-width: 360px; }
.access-admin-btn,
.landing-create-btn { margin-top: .9rem; }

/* Legal / privacy text */
.legal { max-width: 760px; line-height: 1.65; }
.legal h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }
.legal p { margin-bottom: .6rem; color: var(--color-text); }
.legal ul { margin: 0 0 .8rem 1.2rem; }
.legal li { margin-bottom: .35rem; }

/* Floating WhatsApp button — visible on every building screen. */
.wa-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #25d366; color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
  transition: transform var(--transition), box-shadow var(--transition);
}
.wa-fab:hover { transform: scale(1.08); text-decoration: none; box-shadow: var(--shadow-lg); }
.wa-fab:active { transform: scale(1); }
@media (max-width: 520px) { .wa-fab { right: 14px; bottom: 14px; width: 52px; height: 52px; } }

/* Per-cell month label and the "Paid:" label: only used in the mobile card view. */
.pay-cell__month, .paid-label { display: none; }

.count-pill { display: inline-block; padding: .15rem .5rem; border-radius: 999px; background: var(--color-surface-2); font-size: .8rem; font-weight: 700; }
.hint { color: var(--color-muted); font-style: italic; text-align: center; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__footer { margin-left: auto; }
}

/* Hide the header nav on tablets (the sidebar provides navigation). */
@media (max-width: 1024px) {
  .header__nav { display: none; }
}
@media (max-width: 520px) {
  .page-head--row { align-items: flex-start; }
}

/* Stack page-head controls (search / fee / year) full-width on small screens. */
@media (max-width: 640px) {
  .page-head--row { flex-direction: column; align-items: stretch; gap: .75rem; }
  .page-head__actions { width: 100%; flex-direction: column; align-items: stretch; gap: .6rem; }
  .page-head__actions > .btn { width: 100%; }

  .search-input { width: 100%; }
  .year-form, .fee-form { width: 100%; }
  .year-form .form__input { flex: 1; }

  .fee-form { flex-wrap: wrap; }
  .fee-form .fee-input { flex: 1 1 90px; width: auto; text-align: left; }
  .fee-form .btn { flex: 1 1 100%; }   /* Save button on its own full-width row */
}

/* Payments grid → one card per resident on small screens (no horizontal scroll). */
@media (max-width: 640px) {
  .table-wrap:has(.table--grid) { border: 0; background: transparent; overflow: visible; }
  .table--grid thead, .table--grid tfoot { display: none; }
  .table--grid, .table--grid tbody { display: block; }

  .table--grid tr {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .85rem;
    margin-bottom: .85rem;
  }
  .table--grid td { padding: 0; border: 0; }

  .table--grid .col-no,
  .table--grid .col-name,
  .table--grid .col-paid { grid-column: 1 / -1; text-align: left; }
  .table--grid .col-no { color: var(--color-muted); font-size: .78rem; font-weight: 700; }
  .table--grid .col-no::before { content: "#"; }
  .table--grid .col-name {
    font-size: 1.05rem; font-weight: 700;
    padding-bottom: .5rem; border-bottom: 1px solid var(--color-border);
  }

  .table--grid td.cell {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 4px 6px 4px 9px;
    background: var(--color-surface-2);
  }
  .table--grid td.cell:has(.is-paid) {
    background: color-mix(in srgb, var(--color-primary) 14%, transparent);
    border-color: var(--color-primary);
  }
  .pay-cell__month { display: inline; font-size: .72rem; font-weight: 700; color: var(--color-muted); }
  .table--grid td.cell:has(.is-paid) .pay-cell__month { color: var(--color-primary); }

  .table--grid .col-paid {
    display: flex; align-items: center; gap: .5rem;
    padding-top: .6rem; margin-top: .25rem; border-top: 1px solid var(--color-border);
  }
  .paid-label { display: inline; font-size: .82rem; font-weight: 600; color: var(--color-muted); }
}

/* Generic table → one card per row on tablet & mobile (e.g. expenses, users). */
@media (max-width: 820px) {
  .table-wrap:has(.table--cards) { border: 0; background: transparent; overflow: visible; }
  .table--cards { min-width: 0; }
  .table--cards thead { display: none; }
  .table--cards, .table--cards tbody { display: block; }
  .table--cards .col-apt { width: auto; text-align: right; }

  .table--cards tr {
    display: flex; flex-direction: column; gap: .4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .9rem;
    margin-bottom: .85rem;
  }
  .table--cards tr:hover { background: var(--color-surface); }

  .table--cards td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0; border: 0; text-align: right;
  }
  .table--cards td[data-label]::before {
    content: attr(data-label);
    color: var(--color-muted); font-weight: 600; font-size: .85rem; text-align: left;
  }

  .table--cards .col-title {
    order: -1; display: block; text-align: left;
    padding-bottom: .55rem; border-bottom: 1px solid var(--color-border);
  }
  .table--cards .col-title strong { font-size: 1.05rem; }
  .table--cards .num strong { font-size: 1.05rem; }

  .table--cards .table__actions {
    justify-content: flex-end; gap: .5rem;
    padding-top: .65rem; margin-top: .1rem;
    border-top: 1px solid var(--color-border);
  }

  /* Collapsible cards (users): show name + status, reveal the rest on tap. */
  .table--collapsible .col-title {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    cursor: pointer;
  }
  .table--collapsible .col-title::after {
    content: "▾"; color: var(--color-muted); font-size: .9rem; font-weight: 700;
    transition: transform var(--transition);
  }
  .table--collapsible tr.is-open .col-title::after { transform: rotate(180deg); }
  .table--collapsible .card-detail { display: none; }
  .table--collapsible tr.is-open .card-detail { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
