/* Astoria Park water meter billing — mobile-first, single stylesheet. */

:root {
  --ink: #1b2a41;
  --ink-soft: #5b6b81;
  --line: #dfe5ec;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --brand: #0f4c75;
  --brand-dark: #0b3a5b;
  --accent: #e08e45;
  --ok: #1b7f5a;
  --ok-bg: #e3f4ec;
  --warn: #a8600b;
  --warn-bg: #fdf0dc;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(27, 42, 65, 0.06), 0 6px 20px rgba(27, 42, 65, 0.06);
  --tap: 44px;
}

* { box-sizing: border-box; }

/* Class-based display rules below would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--brand); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

p { margin: 0 0 0.75rem; }

code {
  background: #eef2f7;
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}

.muted { color: var(--ink-soft); font-size: 0.9rem; }
.center { text-align: center; }

.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;
}

/* --------------------------------------------------------------- header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* Photo banner: centred to the page width, cropped from the middle so the
   building stays in frame at any screen size. */
.banner { background: var(--brand-dark); overflow: hidden; }
.banner img {
  display: block;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  height: 120px;
  object-fit: cover;
  object-position: center 45%;
}

.header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
  margin-right: auto;
}

.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1rem; }
.brand-text small { color: var(--ink-soft); font-size: 0.75rem; }

.site-nav { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }

.site-nav a,
.link-button {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.7rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.site-nav a.active { background: #eaf1f7; color: var(--brand); }
.site-nav a:hover, .link-button:hover { background: #eef2f7; color: var(--brand); }

.link-button { background: none; border: 0; cursor: pointer; font-family: inherit; }
.site-nav form { margin: 0; }

/* ----------------------------------------------------------------- page */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.page-title { margin-top: 0.25rem; }
.breadcrumb { margin: 0 0 0.5rem; font-size: 0.9rem; }

.site-footer {
  text-align: center;
  padding: 1rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card > h2:first-child { margin-top: 0; }
.card summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }

.empty { text-align: center; color: var(--ink-soft); }
.center-card { max-width: 420px; margin: 3rem auto; text-align: center; }
.error-code { font-size: 3rem; margin-bottom: 0; color: var(--brand); }

.plain-list { margin: 0; padding-left: 1.1rem; color: var(--ink-soft); font-size: 0.9rem; }
.plain-list li { margin-bottom: 0.25rem; }

/* ----------------------------------------------------------------- flash */

.flash {
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  border: 1px solid transparent;
}

.flash-success { background: var(--ok-bg); border-color: #bfe4d3; color: var(--ok); }
.flash-error { background: var(--danger-bg); border-color: #f3c9c5; color: var(--danger); }

/* ----------------------------------------------------------------- forms */

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0.85rem 0 0.3rem;
}

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="month"],
input[type="date"],
input[type="email"],
select {
  width: 100%;
  min-height: var(--tap);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.45;
  resize: vertical;
}

.message-preview {
  margin: 0;
  padding: 0.75rem 0.9rem;
  background: #e7f7ec;
  border: 1px solid #c6e9d3;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.92rem;
}

.readonly-field {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  padding: 0.55rem 0.7rem;
  background: #eef2f7;
  border-radius: 10px;
  font-weight: 600;
  margin: 0;
}

.form-grid { display: grid; gap: 0.25rem; }
.form-actions { margin-top: 1rem; }

/* Block dropdown next to the flat number — they read as one address. */
.field-pair { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: 0.75rem; }
.field-pair label { margin-top: 0.85rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: #f2f5f9; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.btn-block { width: 100%; margin-top: 1rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; }
.btn-warning { background: var(--warn-bg); border-color: #f0d5ab; color: var(--warn); }
/* Share-on-WhatsApp action — deliberately in WhatsApp's green so it reads as
   "this leaves the app". */
.btn-wa { background: #25d366; border-color: #1fbe5a; color: #08331b; }
.btn-wa:hover { background: #1fbe5a; }
.data-table .btn-wa { min-height: 32px; padding: 0 0.7rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger-bg); border-color: #f3c9c5; color: var(--danger); }

.danger-zone h2 { margin-top: 1.25rem; }
.danger-zone form { margin-bottom: 0.5rem; }

.login-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}
.login-row form { margin: 0; }

/* ------------------------------------------------------------ auth pages */

.auth-page .site-nav { display: none; }
.auth-card { max-width: 420px; margin: 1.5rem auto; }
.auth-alt { text-align: center; font-size: 0.9rem; margin: 0.75rem 0 0; }

/* ------------------------------------------------------ association contact */

.contact-block {
  margin-top: 1rem;
  padding: 0.75rem 0.9rem;
  background: #eef2f7;
  border-radius: 10px;
}

.contact-title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-weight: 700;
}

.contact-list { list-style: none; margin: 0; padding: 0; }
.contact-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-height: var(--tap);
}
.contact-list a { font-weight: 600; word-break: break-word; }

.contact-wa {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 0.6rem;
  border-radius: 999px;
  background: #25d366;
  color: #08331b !important;
  font-size: 0.78rem;
  text-decoration: none;
}

/* ------------------------------------------------------------ stat cards */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.stat-label { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.stat-value { display: block; font-size: 1.25rem; margin-top: 0.2rem; }
.stat-note { display: block; font-size: 0.78rem; color: var(--ink-soft); }
.stat-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat-primary .stat-label, .stat-primary .stat-note { color: rgba(255, 255, 255, 0.82); }

/* ----------------------------------------------------------- filter bar */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.filter-fields { display: flex; gap: 0.5rem; flex: 1; min-width: 0; }
.filter-fields select { flex: 0 0 8.5rem; }
.filter-fields input { flex: 1; min-width: 0; }
.filter-bar .btn { flex: 0 0 auto; }

/* ------------------------------------------------- admin reading entry */

.entry-head { display: none; }

.entry-grid { display: grid; gap: 0.6rem; }

.entry-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.entry-row.is-entered { border-left-color: var(--ok); }
.entry-row.is-invalid { border-left-color: var(--danger); }

.entry-flat { grid-column: 1 / -1; display: flex; flex-direction: column; }
.entry-flat a { text-decoration: none; color: inherit; font-size: 1.05rem; }
.entry-flat small { font-size: 0.8rem; }

.entry-cell { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.entry-cell::before {
  content: attr(data-label);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 0.15rem;
}

.entry-input { grid-column: 1 / -1; }
.entry-amount .js-amount { font-weight: 700; }

.entry-actions { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 0.5rem; }
.entry-actions::before { display: none; }
.btn-save { flex: 1; }

.entry-message { grid-column: 1 / -1; margin: 0; font-size: 0.85rem; min-height: 0; }
.entry-message.is-error { color: var(--danger); }
.entry-message.is-success { color: var(--ok); }

/* --------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 0.85rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: default;
}

button.badge { cursor: pointer; }
.badge-paid { background: var(--ok-bg); border-color: #bfe4d3; color: var(--ok); }
.badge-unpaid { background: var(--warn-bg); border-color: #f0d5ab; color: var(--warn); }
.badge-muted { background: #eef2f7; border-color: var(--line); color: var(--ink-soft); }
.badge-lg { font-size: 1rem; padding: 0 1.25rem; }

/* Badges inside history tables are labels, not tap targets. */
.data-table .badge { min-height: 28px; padding: 0 0.6rem; font-size: 0.78rem; }

/* ----------------------------------------------------------- flat list */

.flat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.flat-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}

.flat-item-main { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: inherit; min-height: var(--tap); flex: 1; }
.flat-no {
  background: #eaf1f7;
  color: var(--brand);
  font-weight: 700;
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  min-width: 64px;
  text-align: center;
}
.flat-people { display: flex; flex-direction: column; line-height: 1.3; }
.flat-people small { font-size: 0.78rem; }

.flat-group-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 700;
  margin-top: 0.5rem;
}
.flat-group-heading:first-child { margin-top: 0; }

.flat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; }
.flat-outstanding { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.flat-outstanding.is-due { color: var(--danger); }

/* --------------------------------------------------------------- tables */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { padding: 0.55rem 0.5rem; text-align: left; white-space: nowrap; }
.data-table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
.data-table tbody tr + tr td { border-top: 1px solid var(--line); }
.data-table td:nth-child(n + 2) { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------- resident bill hero */

/* The bill and its status must be visible without scrolling on a phone. */
.bill-hero {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1rem 1.4rem;
  text-align: center;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.bill-hero.is-paid { background: linear-gradient(160deg, #12694c, #1b7f5a); }
.bill-hero.is-unpaid { background: linear-gradient(160deg, #0b3a5b, #0f4c75); }

.bill-flat { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.85; margin: 0; }
.bill-label { margin: 0.35rem 0 0; font-size: 0.95rem; opacity: 0.9; }
.bill-amount { font-size: 2.6rem; font-weight: 700; margin: 0.1rem 0 0.5rem; line-height: 1.1; letter-spacing: -0.02em; }
.bill-status { margin: 0 0 0.5rem; }
.bill-hero .badge { background: rgba(255, 255, 255, 0.95); border-color: transparent; }
.bill-note { margin: 0; font-size: 0.9rem; opacity: 0.9; }
.bill-note.muted { color: rgba(255, 255, 255, 0.75); }

.outstanding-note {
  background: var(--warn-bg);
  border: 1px solid #f0d5ab;
  color: var(--warn);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  font-size: 0.92rem;
}

.chart-wrap { position: relative; height: 240px; }
.chart-legend-note { margin: 0.5rem 0 0; }

/* ------------------------------------------------------ tablet/desktop */

@media (min-width: 768px) {
  h1 { font-size: 1.7rem; }

  .page { padding: 1.5rem 1.5rem 4rem; }

  .banner img { height: 200px; }

  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* Reading entry becomes a real table-like grid. */
  .entry-head,
  .entry-row {
    grid-template-columns: minmax(130px, 1.3fr) 80px minmax(110px, 1fr) 70px 105px minmax(250px, auto);
    gap: 0.75rem;
    align-items: center;
  }

  .entry-head {
    display: grid;
    padding: 0 0.85rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
  }

  .entry-row { padding: 0.6rem 0.85rem; }
  .entry-flat, .entry-input, .entry-actions { grid-column: auto; }
  .entry-flat { flex-direction: column; align-items: flex-start; }
  .entry-cell::before { display: none; }
  .entry-cell { flex-direction: row; align-items: center; }
  .entry-actions { justify-content: flex-end; }
  .btn-save { flex: 0 0 auto; }
  .entry-message:empty { display: none; }

  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.25rem 1rem; }
  .form-actions, .form-wide { grid-column: 1 / -1; }
  .form-actions .btn-block { width: auto; min-width: 200px; }

  .auth-card { margin-top: 3rem; }

  .bill-amount { font-size: 3.2rem; }
  .chart-wrap { height: 300px; }

  .data-table th, .data-table td { padding: 0.65rem 0.75rem; }
}

/* ------------------------------------------- maintenance & accounts module */

/* Small inline labels: a category, a closed collection, an inactive flat. */
.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f7;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tag-muted { background: transparent; }

/* Status words come straight from the data layer in lower case ('partial',
   'collected'), so capitalise in CSS rather than restating the list in every
   template and in the grid script. */
.badge { text-transform: capitalize; }
.badge-partial { background: var(--warn-bg); border-color: #f0d5ab; color: var(--warn); }
.badge-collected { background: var(--ok-bg); border-color: #bfe4d3; color: var(--ok); }
.badge-none { background: #eef2f7; border-color: var(--line); color: var(--ink-soft); }

.entry-row.is-inactive { opacity: 0.65; border-left-color: var(--line); }

/* Forms that sit inside a card: a stacked one for records, an inline one for
   a single action plus its explanation. */
.field { margin-bottom: 0.25rem; }
.field label { margin-top: 0; }
.stacked-form { display: grid; gap: 0.5rem; }
.field-row { display: grid; gap: 0.5rem; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.inline-form .field { flex: 1 1 12rem; margin-bottom: 0; }
.inline-form .muted { flex: 1 1 100%; margin: 0; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.checkbox input { width: auto; min-height: 0; margin: 0; }

.charge-all summary { font-size: 0.95rem; }
.charge-all[open] summary { margin-bottom: 0.5rem; }

/* Numeric table columns line up on the decimal point. */
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tfoot th {
  border-top: 2px solid var(--line);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.data-table tfoot .num { text-align: right; }
.data-table td small { display: block; font-size: 0.78rem; font-weight: 400; }
.is-negative { color: var(--danger); }

/* Share-of-total bars: expense split, and levy collection progress. */
.progress,
.category-bar {
  display: block;
  height: 8px;
  min-width: 60px;
  border-radius: 999px;
  background: #e7ecf3;
  overflow: hidden;
}
.progress-fill, .category-fill { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress { margin-bottom: 0.2rem; }

.category-list { list-style: none; padding-left: 0; color: var(--ink); font-size: 1rem; }
.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 0.75rem;
  align-items: center;
  padding: 0.4rem 0;
}
.category-row + .category-row { border-top: 1px solid var(--line); }
.category-name { font-weight: 600; font-size: 0.95rem; }
.category-bar { grid-column: 1 / -1; order: 3; }
.category-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.category-amount small { display: block; font-weight: 400; }

/* Resident dashboard: maintenance at a glance under the water bill. */
.summary-strip {
  display: grid;
  gap: 0.75rem;
}
.summary-item { display: flex; flex-direction: column; gap: 0.15rem; }
.summary-item .badge { align-self: flex-start; min-height: 28px; padding: 0 0.6rem; font-size: 0.78rem; }
.summary-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.summary-value { font-size: 1.3rem; font-variant-numeric: tabular-nums; }

.levy-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  color: var(--ink);
  font-size: 0.95rem;
}
.levy-line + .levy-line { border-top: 1px solid var(--line); }
.levy-line small { display: block; font-size: 0.8rem; }
.levy-line-amount {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.levy-line-amount .badge { min-height: 28px; padding: 0 0.6rem; font-size: 0.78rem; }

@media (min-width: 768px) {
  /* Five data columns rather than the water grid's six, plus the message row. */
  .entry-grid-maintenance .entry-head,
  .entry-grid-maintenance .entry-row {
    grid-template-columns: minmax(140px, 1.4fr) minmax(100px, 1fr) minmax(100px, 1fr) 110px minmax(200px, auto);
  }

  .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem 1rem; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: center; }
  .category-row { grid-template-columns: minmax(120px, 1fr) minmax(0, 3fr) auto; }
  .category-bar { grid-column: auto; order: 0; }
}
