:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17212b;
  background: #f5f7fa;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: #f5f7fa; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 420px);
  background: white;
  padding: 32px;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(23, 33, 43, 0.12);
}

.auth-card h1 { margin-bottom: 4px; }
.auth-card form,
.resident-form,
.fee-form { display: grid; gap: 12px; }
.auth-card form { margin-top: 24px; }

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #cfd7df;
  border-radius: 10px;
  background: white;
  color: #17212b;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(31, 111, 235, 0.15);
  border-color: #1f6feb;
}

input[readonly] { background: #f2f4f7; }

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: #1f6feb;
  color: white;
  font-weight: 600;
}
button:hover { filter: brightness(0.96); }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.secondary-button { background: #384656; }
.text-button {
  background: transparent;
  color: #1f6feb;
  padding: 6px 0;
}

.muted { color: #66727d; }
.message { min-height: 1.25rem; margin: 6px 0; }
.message.error { color: #b42318; }
.message.success { color: #067647; }

.app-shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: #17212b;
  color: white;
}
.brand-block { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar .muted { color: #c7d0d9; }

.main-nav {
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  overflow-x: auto;
  background: white;
  border-bottom: 1px solid #e3e8ee;
}
.nav-button {
  flex: 0 0 auto;
  background: transparent;
  color: #52606d;
  padding: 9px 12px;
}
.nav-button.active { background: #e8eef8; color: #1f4f8a; }

.content { padding: 28px; max-width: 1200px; margin: 0 auto; }
.page-heading,
.detail-heading,
.form-heading,
.statement-heading,
.history-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}
.page-heading { margin-bottom: 18px; }
.page-heading h1,
.detail-heading h2,
.form-heading h3,
.statement-heading h2,
.history-heading h2 { margin: 0; }
.page-heading p,
.detail-heading p,
.history-heading p { margin: 4px 0 0; }

.pill {
  background: #e8eef8;
  color: #1f4f8a;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.toolbar,
.fees-selector-card,
.statement-card,
.payment-card,
.payment-preview-card,
.payment-history-card {
  background: white;
  border: 1px solid #e3e8ee;
  border-radius: 14px;
  padding: 16px;
}
.toolbar { margin-bottom: 16px; }
.search-field { display: grid; gap: 8px; max-width: 520px; }
.search-field span { font-weight: 600; }

.houses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
}

.house-card {
  width: 100%;
  text-align: left;
  background: white;
  color: #17212b;
  border: 1px solid #e3e8ee;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 4px 18px rgba(23, 33, 43, 0.05);
}
.house-card:hover { border-color: #a9bfd8; }
.house-card.selected { border-color: #1f6feb; box-shadow: 0 0 0 3px rgba(31,111,235,.1); }
.house-card strong { display: block; font-size: 1.15rem; margin-bottom: 6px; }
.house-card .resident-preview { display: block; margin-top: 8px; font-size: .9rem; color: #52606d; }

.detail-panel {
  margin-top: 24px;
  background: white;
  border: 1px solid #e3e8ee;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 8px 24px rgba(23, 33, 43, 0.06);
}
.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .75rem;
  font-weight: 700;
  color: #1f6feb;
}
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr);
  gap: 24px;
  margin-top: 22px;
}
.residents-list { display: grid; gap: 12px; }
.resident-card {
  border: 1px solid #e3e8ee;
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 8px;
}
.resident-card-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.resident-card h4 { margin: 0; }
.resident-meta { display: flex; gap: 8px; flex-wrap: wrap; color: #52606d; font-size: .92rem; }
.resident-actions { display: flex; gap: 8px; }
.resident-actions button { padding: 8px 10px; font-size: .9rem; }
.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: .78rem;
  font-weight: 700;
  background: #ecfdf3;
  color: #067647;
  white-space: nowrap;
}
.status-badge.inactive { background: #f2f4f7; color: #667085; }
.status-badge.pending { background: #fff7e6; color: #9a6700; }
.status-badge.partial { background: #eef4ff; color: #3538cd; }
.status-badge.overdue { background: #fef3f2; color: #b42318; }

.empty-state {
  border: 1px dashed #cfd7df;
  border-radius: 14px;
  padding: 22px;
  color: #66727d;
  text-align: center;
}

.resident-form {
  align-self: start;
  background: #f8fafc;
  border: 1px solid #e3e8ee;
  border-radius: 14px;
  padding: 18px;
}
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: auto; }

.fees-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.fees-selector-card { display: grid; gap: 14px; }
.fees-selector-card > label { font-weight: 600; }
.fee-form {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid #e3e8ee;
}
.fee-form h3 { margin: 0 0 4px; }
.form-grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-grid-two label,
.fee-form > label { display: grid; gap: 6px; }
.statement-card { min-height: 280px; }
.statement-heading { align-items: flex-start; margin-bottom: 14px; }
.statement-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 8px;
}
.statement-totals > div {
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}
.statement-totals strong { font-size: 1.05rem; }
.fees-list { display: grid; gap: 10px; }
.fee-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  border: 1px solid #e3e8ee;
  border-radius: 12px;
  padding: 14px;
}
.fee-row > div:first-child,
.fee-amounts { display: grid; gap: 4px; }
.fee-amounts { text-align: right; }

.payments-layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.payment-card { display: grid; gap: 12px; }
.payment-card > label { display: grid; gap: 6px; font-weight: 600; }
.payment-card .form-grid-two label { display: grid; gap: 6px; font-weight: 600; }
.payment-preview-card { min-height: 320px; }
.payment-summary-boxes {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 8px;
}
.payment-total-box {
  display: grid;
  gap: 4px;
  min-width: 140px;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 12px;
}
.applications-list { display: grid; gap: 10px; margin-top: 14px; }
.application-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  border: 1px solid #e3e8ee;
  border-radius: 12px;
  padding: 14px;
}
.application-row.selected {
  border-color: #9db9dd;
  background: #f7faff;
}
.application-row > div:first-child,
.application-amount { display: grid; gap: 4px; }
.application-amount { text-align: right; }
.payment-warning {
  border: 1px solid #f5c2c0;
  background: #fef3f2;
  color: #b42318;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
}
.payment-credit {
  border: 1px solid #a9d9bc;
  background: #ecfdf3;
  color: #067647;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
}
.payment-info {
  border: 1px solid #b8cce8;
  background: #f4f8ff;
  color: #1f4f8a;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
}

.payment-history-card { margin-top: 18px; }
.history-heading { align-items: flex-start; margin-bottom: 14px; }
.payment-history-list { display: grid; gap: 10px; }
.payment-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  border: 1px solid #e3e8ee;
  border-radius: 12px;
  padding: 14px;
}
.payment-history-main,
.payment-history-amounts { display: grid; gap: 3px; }
.payment-history-amounts { text-align: right; min-width: 125px; }
.payment-history-amounts > strong { font-size: 1.05rem; }
.payment-history-actions button { padding: 8px 11px; font-size: .9rem; }

.receipt-dialog {
  width: min(94vw, 720px);
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(23, 33, 43, .28);
}
.receipt-dialog::backdrop { background: rgba(23, 33, 43, .58); }
.receipt-sheet { padding: 26px; background: white; }
.receipt-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 2px solid #17212b;
}
.receipt-header h2 { margin: 0; }
.receipt-main {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.receipt-main > div,
.receipt-summary > div {
  display: grid;
  gap: 4px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
}
.receipt-main span,
.receipt-summary span { color: #66727d; font-size: .88rem; }
.receipt-section { margin-top: 20px; }
.receipt-section h3 { margin: 0 0 10px; }
.receipt-applications { display: grid; gap: 8px; }
.receipt-application-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid #e3e8ee;
}
.receipt-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.receipt-footnote { margin: 22px 0 16px; color: #66727d; font-size: .85rem; }

@media (max-width: 900px) {
  .fees-layout,
  .payments-layout { grid-template-columns: 1fr; }
  .statement-heading { flex-direction: column; }
  .statement-totals,
  .payment-summary-boxes { width: 100%; }
}

@media (max-width: 800px) {
  .detail-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar,
  .page-heading,
  .detail-heading,
  .history-heading { align-items: stretch; flex-direction: column; }
  .content { padding: 18px; }
  .topbar { padding: 14px 16px; }
  .main-nav { padding: 8px 12px; }
  .houses-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .house-card { padding: 14px; }
  .detail-panel { padding: 16px; }
  .detail-heading > button { width: 100%; }
  .form-grid-two,
  .payment-summary-boxes,
  .receipt-main,
  .receipt-summary { grid-template-columns: 1fr; }
  .statement-totals { grid-template-columns: 1fr; }
  .fee-row,
  .application-row,
  .payment-history-row { grid-template-columns: 1fr; gap: 8px; }
  .fee-amounts,
  .application-amount,
  .payment-history-amounts { text-align: left; }
  .payment-history-actions button { width: 100%; }
  .receipt-sheet { padding: 20px; }
}

@media (max-width: 400px) {
  .houses-grid { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden !important; }
  .receipt-dialog,
  .receipt-dialog * { visibility: visible !important; }
  .receipt-dialog {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .receipt-sheet { padding: 0; }
  .no-print { display: none !important; }
}