:root {
  --green-950: #052d13;
  --green-900: #064319;
  --green-800: #075d20;
  --green-700: #087d22;
  --green-600: #0a9b2b;
  --green-500: #18bd3c;
  --mint-100: #e6f6e7;
  --mint-50: #f3fbf2;
  --cyan-50: #edfafa;
  --gold-100: #fff2cc;
  --rose-100: #ffe4e6;
  --ink: #102016;
  --muted: #637267;
  --line: #dce8dd;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --shadow: 0 24px 70px rgba(8, 65, 24, 0.15);
  --radius: 8px;
  color-scheme: light;
  font-family: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #f7fbf6; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(247, 251, 246, 0.82), rgba(241, 249, 238, 0.96)),
    url("/assets/background.png") center top / cover fixed;
  font-family: "DM Sans", system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; }

a { color: inherit; text-decoration: none; }

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  border-right: 1px solid rgba(220, 232, 221, 0.8);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; line-height: 1.1; }
.brand small { color: var(--muted); font-weight: 600; }

.nav {
  display: grid;
  gap: 6px;
}

.nav a, .nav-section a {
  border-radius: var(--radius);
  padding: 11px 12px;
  color: #2d3f33;
  font-weight: 600;
}

.nav a[aria-current="page"], .nav a:hover, .nav-section a[aria-current="page"], .nav-section a:hover {
  background: var(--mint-100);
  color: var(--green-800);
}

.nav-section {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.nav-section > span {
  padding: 10px 12px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-section[data-active="true"] > span {
  color: var(--green-700);
}

.nav-section a {
  padding-left: 22px;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 24px;
  max-width: 1120px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-700);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.user-chip {
  min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.view {
  margin: 0 auto;
  max-width: 1120px;
}

.panel {
  border: 1px solid rgba(220, 232, 221, 0.88);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 240px;
  gap: 24px;
  align-items: center;
  padding: 28px;
}

.hero h2, .auth-panel h2 {
  margin: 0 0 12px;
  font-size: clamp(26px, 5vw, 46px);
  line-height: 1.04;
}

.hero p, .muted {
  color: var(--muted);
  line-height: 1.55;
}

.hero-logo {
  width: min(100%, 220px);
  justify-self: center;
}

.role-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.82);
  color: #314438;
  font-size: 12px;
  font-weight: 900;
}

.role-badge span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #7dd3fc;
  box-shadow: 0 0 0 4px rgba(125, 211, 252, 0.2);
}

.role-badge.resident span {
  background: #86efac;
  box-shadow: 0 0 0 4px rgba(134, 239, 172, 0.24);
}

.role-badge.admin span {
  background: #facc15;
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.24);
}

.role-badge.super-admin span {
  background: #fda4af;
  box-shadow: 0 0 0 4px rgba(253, 164, 175, 0.26);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  padding: 18px;
}

.stat strong {
  display: block;
  font-family: "DM Mono", monospace;
  font-size: 28px;
}

.stat span { color: var(--muted); font-weight: 700; }

.chart-panel {
  padding: 22px;
}

.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
  background: transparent;
}

.chart-tab {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  min-width: 92px;
  padding: 10px 18px;
  text-align: center;
}

.chart-tab[aria-selected="true"] {
  background: rgba(235, 247, 230, 0.96);
  border-color: #bcd8b7;
  color: var(--ink);
  box-shadow: none;
}

.arrears-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 18px;
}

.arrears-toolbar .chart-tabs {
  margin: 0;
}

.compact-select {
  display: grid;
  gap: 5px;
  min-width: min(320px, 100%);
  color: #496052;
  font-size: 12px;
  font-weight: 800;
}

.compact-select select {
  min-height: 40px;
  border-radius: 8px;
}

.chart-empty {
  color: var(--muted);
  font-weight: 700;
}

.chart-wrap {
  display: grid;
  gap: 12px;
}

.line-chart {
  display: block;
  width: 100%;
  min-height: 260px;
}

.chart-grid {
  stroke: rgba(99, 114, 103, 0.18);
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-value {
  fill: #496052;
  font-size: 11px;
  font-weight: 500;
}

.chart-line {
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  stroke: white;
  stroke-width: 2;
}

.bar-chart-bar {
  fill: #2f7d2c;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #314438;
  font-size: 13px;
  font-weight: 800;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 22px;
  align-content: start;
}

.compact-form {
  gap: 12px 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #314438;
  font-size: 13px;
  font-weight: 800;
}

fieldset {
  margin: 0;
  border: 1px solid #cadccb;
  border-radius: var(--radius);
  padding: 12px;
}

legend {
  padding: 0 6px;
  color: #314438;
  font-size: 13px;
  font-weight: 800;
}

.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.check-option {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.72);
}

.check-option input {
  width: auto;
  min-height: auto;
}

.inline-check {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cadccb;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  outline: none;
}

input[type="checkbox"], input[type="radio"] {
  width: 16px;
  min-height: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green-700);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(10, 155, 43, 0.14);
}

.full { grid-column: 1 / -1; }

.primary-btn, .secondary-btn, .danger-btn, .ghost-btn {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn { background: var(--green-700); color: white; }
.primary-btn:hover { background: var(--green-800); }
.secondary-btn { background: var(--mint-100); color: var(--green-800); }
.danger-btn { background: var(--rose-100); color: #9f1239; }
.ghost-btn { background: transparent; color: var(--green-800); border: 1px solid var(--line); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-bar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.date-filter-bar {
  gap: 12px;
}

.date-filter-bar label {
  display: grid;
  gap: 5px;
  color: #496052;
  font-size: 12px;
  font-weight: 800;
}

.date-filter-bar input {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255,255,255,0.82);
  font: inherit;
}

.date-filter-bar select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255,255,255,0.82);
  font: inherit;
}

.filter-btn {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.78);
  color: #314438;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.filter-btn[aria-pressed="true"] {
  border-color: var(--green-700);
  background: var(--green-700);
  color: white;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: #637067;
  font-size: 13px;
  font-weight: 700;
}

.pagination-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pagination-actions .small-btn {
  min-height: 34px;
  padding: 7px 10px;
}

.pagination-actions button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.form-actions {
  align-items: center;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.small-btn {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.table-actions {
  flex-wrap: nowrap;
}

.arrears-summary-table {
  min-width: 820px;
}

.arrears-summary-table th:nth-child(1),
.arrears-summary-table td:nth-child(1) {
  width: 26%;
}

.arrears-summary-table th:nth-child(2),
.arrears-summary-table td:nth-child(2) {
  width: 18%;
}

.arrears-detail-list {
  display: grid;
  gap: 8px;
}

.arrears-detail-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) 72px minmax(150px, 1fr) 118px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(198, 217, 199, 0.72);
}

.arrears-detail-row:last-child {
  border-bottom: 0;
}

.arrears-detail-row span {
  color: #314438;
}

.arrears-detail-row strong {
  text-align: right;
}

.settings-hero {
  padding: 26px;
}

.settings-hero h2, .about-section h2 {
  margin: 0 0 10px;
}

.settings-card {
  padding: 18px;
}

.settings-card h3 {
  margin: 0 0 8px;
}

.about-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 28px;
  align-items: center;
  border-radius: var(--radius);
  padding: 34px;
  background: linear-gradient(135deg, rgba(5, 67, 25, 0.96), rgba(8, 125, 34, 0.82));
  color: white;
  box-shadow: var(--shadow);
}

.about-hero .eyebrow, .about-hero p {
  color: rgba(255, 255, 255, 0.82);
}

.about-hero h2 {
  max-width: 760px;
  margin: 0 0 16px;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.04;
}

.about-mark {
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: var(--radius);
  padding: 22px;
  background: rgba(255,255,255,0.12);
}

.about-mark img {
  width: 120px;
  height: 120px;
  object-fit: contain;
}

.about-mark strong {
  font-size: 42px;
  line-height: 1;
}

.about-points {
  margin-top: 16px;
}

.mini-card {
  display: grid;
  gap: 6px;
  padding: 18px;
}

.mini-card span, .about-copy {
  color: var(--muted);
  line-height: 1.55;
}

.about-section {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.about-copy {
  padding: 22px;
}

.about-footer {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 18px;
  overflow: hidden;
}

.about-footer div {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-right: 1px solid var(--line);
}

.about-footer div:last-child {
  border-right: 0;
}

.about-footer span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: auto;
  padding: 28px 16px;
  background: rgba(16, 32, 22, 0.44);
  backdrop-filter: blur(8px);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

body.modal-open {
  overflow: hidden;
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 420px);
  min-height: calc(100vh - 132px);
  gap: 22px;
  align-items: center;
}

.login-visual {
  display: grid;
  place-items: center;
}

.login-logo {
  width: min(72vw, 360px);
  filter: drop-shadow(0 28px 48px rgba(5, 67, 25, 0.18));
}

.auth-panel {
  padding: 24px;
}

.auth-panel .primary-btn {
  margin-top: 12px;
  align-self: start;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.78);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #496052;
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--mint-100);
  color: var(--green-800);
  font-size: 12px;
  font-weight: 800;
}

.badge.pending { background: var(--gold-100); color: #8a5a00; }
.badge.confirming { background: var(--cyan-50); color: #075985; }
.badge.rejected { background: var(--rose-100); color: #9f1239; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--green-900);
  color: white;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.icon-btn {
  display: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.84);
}

.icon-btn span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: var(--green-800);
}

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 15;
    width: min(320px, 86vw);
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .main { padding: 16px; }
  .icon-btn { display: block; }
  .topbar { align-items: flex-start; }
  .hero, .login-layout { grid-template-columns: 1fr; }
  .about-hero, .about-footer { grid-template-columns: 1fr; }
  .about-mark { justify-items: start; }
  .hero-logo { display: none; }
  .grid.two, .grid.three, .form-grid, .stats-grid { grid-template-columns: 1fr; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .arrears-toolbar { flex-direction: column; }
  .compact-select { width: 100%; }
  .user-chip { display: none; }
}

@media (max-width: 560px) {
  body { background-attachment: scroll; }
  .main { padding: 12px; }
  .topbar h1 { font-size: 25px; }
  .hero, .auth-panel, .form-grid { padding: 18px; }
  .login-layout { min-height: auto; }
  .login-logo { width: 180px; }
}
