:root {
  --bg: #f6f7f9;
  --card: #fff;
  --ink: #1c2330;
  --muted: #6b7688;
  --line: #e3e7ee;
  --good: #0f7b4f;
  --bad: #b3261e;
  --accent: #1f5fd0;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

/* ---- layout ---- */
.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); margin-right: auto; }

/* The nav is one scrollable strip instead of wrapping into three rows. */
.top nav {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 0.6rem 0.5rem;
}
.top nav::-webkit-scrollbar { display: none; }
.top nav a {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
}
.top nav a:hover { background: var(--bg); color: var(--ink); }

.out { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.who { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
a { color: var(--accent); }

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card.narrow, .card.login { max-width: 26rem; }
.login h1 { margin-top: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.card.stat { display: flex; flex-direction: column; gap: 0.25rem; margin: 0; }
.card.stat .label { color: var(--muted); font-size: 0.85rem; }
.card.stat strong { font-size: 1.25rem; }

.split { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .split { grid-template-columns: 1fr 1fr; } }

/* ---- bits ---- */
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.strong { font-weight: 700; }

.flash {
  background: #e7f4ec;
  border: 1px solid #b8dfc9;
  color: #0f5133;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  margin: 0 0 1rem;
}
.flash--error { background: #fdeceb; border-color: #f2c2bf; color: #8c1d18; }
.flash-card { border-color: var(--good); border-width: 2px; }

.password {
  display: inline-block;
  font: 600 1.2rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  background: var(--bg);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  user-select: all;
}

.tag {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  text-transform: capitalize;
}
.tag-paid { background: #e7f4ec; color: var(--good); border-color: #b8dfc9; }
.tag-partial { background: #fdf3e2; color: #8a5a08; border-color: #edd3a8; }
.tag-pending { background: #fdeceb; color: var(--bad); border-color: #f2c2bf; }

.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--good); }

.list, .pending { list-style: none; margin: 0; padding: 0; }
.list li, .pending li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: baseline;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}
.list li:last-child, .pending li:last-child { border-bottom: 0; }
.list li span:first-child { flex: 1; }

ul.plain { padding-left: 1.1rem; }

/* ---- forms ---- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.6rem; }
input, select, button {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  max-width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.stack label input, .stack label select { display: block; width: 100%; }
.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}
/* Label above its control, not beside it. */
.row-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0;
  flex: 0 1 auto;
}
.row-form label input, .row-form label select { width: 100%; }
.row-form .grow { flex: 1 1 12rem; }
.stack > label { max-width: 22rem; }

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { filter: brightness(1.07); }
button.danger { background: var(--bad); border-color: var(--bad); }
.out button { background: transparent; color: var(--muted); border-color: var(--line); }

.inline { display: inline-flex; gap: 0.3rem; align-items: center; margin: 0; }
.inline input, .inline select { padding: 0.25rem 0.4rem; font-size: 0.9rem; }
.inline button { padding: 0.25rem 0.5rem; font-size: 0.9rem; }

.actions { display: flex; gap: 0.3rem; }

.monthbar { margin: -0.5rem 0 1rem; }
.monthbar select { min-width: 9rem; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
th, td { padding: 0.5rem 0.35rem; text-align: left; border-bottom: 1px solid var(--line); }
thead th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody th { font-weight: 600; }
tfoot th, tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* The flats table is editable, so its columns are pinned to percentages and the
   inputs fill them. The row then always fits the card without scrolling. */
.flats-table { table-layout: fixed; }
.flats-table td, .flats-table th { overflow-wrap: anywhere; }
.flats-table .w-flat,
.flats-table .w-owner,
.flats-table .w-phone { width: 100%; }
.flats-table .act { display: flex; flex-direction: column; gap: 0.3rem; }
.flats-table .act button { width: 100%; padding: 0.3rem 0.3rem; font-size: 0.8rem; }
.flats-table select { width: 100%; }

/* Per-row password reset: collapsed by default so the table stays scannable. */
details.pw summary {
  cursor: pointer;
  text-align: center;
  padding: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.8rem;
  list-style: none;
}
details.pw summary::-webkit-details-marker { display: none; }
details.pw summary:hover { background: var(--bg); }
details.pw form { display: flex; flex-direction: column; gap: 0.25rem; }
details.pw input { width: 100%; font-size: 0.8rem; padding: 0.25rem 0.35rem; }

.tag-superadmin { background: #ece7fb; color: #4a2fa8; border-color: #cfc2f2; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Tables scroll rather than overflow on a phone. */
.card { overflow-x: auto; }

/* The Settle dialog. <dialog> centres itself and dims the page; ::backdrop is
   the dim. Width is capped so it reads as a small popup, not a second page. */
.settle {
  width: min(24rem, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
  color: var(--ink);
}
.settle::backdrop { background: rgb(15 23 42 / 45%); }
.settle h2 { margin-top: 0; }
.settle__total { display: flex; justify-content: space-between; margin: 0 0 1rem; }
.settle__total strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.settle .actions { justify-content: flex-end; }
.settle .ghost { background: transparent; color: var(--muted); }
.settle label:last-of-type { margin-bottom: 0.75rem; }

@media print {
  .top nav, .top .out, .monthbar, .actions, .inline button { display: none; }
  body { background: #fff; }
  .card { border: 0; }
  .settle { display: none; }
}