:root {
  --surface-0: #F7F6F2;
  --surface-1: #FFFFFF;
  --border: #E2E0D8;
  --text-primary: #1F2420;
  --text-secondary: #6B6F68;
  --teal: #0F6E56;
  --teal-bg: #E1F5EE;
  --amber: #854F0B;
  --amber-bg: #FAEEDA;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --gray-fill: #D3D1C7;
  --radius: 10px;
  --header-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: var(--safe-bottom);
}

/* ─── App header + hamburger ─── */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0 12px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.menu-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.menu-toggle:hover {
  background: var(--surface-0);
}

.menu-toggle:active {
  background: var(--border);
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger::before {
  top: -6px;
}

.hamburger::after {
  top: 6px;
}

.app-header .brand {
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-spacer {
  flex: 1;
}

/* Side drawer */
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.nav-overlay.open {
  opacity: 1;
  visibility: visible;
}

.side-nav {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: var(--surface-1);
  z-index: 60;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  padding-top: var(--safe-top);
}

.side-nav.open {
  transform: translateX(0);
}

.side-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
}

.side-nav-header .brand {
  font-weight: 600;
  font-size: 16px;
}

.menu-close {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-close:hover {
  background: var(--surface-0);
}

.side-nav-links {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.nav-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 16px 20px 6px;
}

.nav-link {
  display: block;
  padding: 14px 20px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.nav-link:hover,
.nav-link:active {
  background: var(--surface-0);
}

.nav-logout-form {
  margin: 0;
}

.nav-logout {
  color: var(--red);
}

/* ─── Layout ─── */
.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  width: 100%;
}

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

.card-flat {
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  margin: 2px 0 0;
}

.big-number {
  font-size: 28px;
  font-weight: 600;
  margin: 0;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 380px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18px, 1fr));
  gap: 4px;
  margin: 10px 0;
}

.unit-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  min-width: 14px;
}

.unit-cell.paid {
  background: #639922;
}

.unit-cell.pending {
  background: #EF9F27;
}

.unit-cell.unpaid {
  background: var(--gray-fill);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
}

.badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.valid {
  background: var(--teal-bg);
  color: var(--teal);
}

.badge.pending {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge.invalid,
.badge.clarify {
  background: var(--red-bg);
  color: var(--red);
}

.badge.credit {
  background: var(--teal-bg);
  color: var(--teal);
}

.badge.debit {
  background: var(--red-bg);
  color: var(--red);
}

/* ─── Buttons ─── */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 15px;
  font-weight: 500;
  background: var(--surface-1);
  border: 1px solid var(--text-primary);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  color: var(--text-primary);
  text-decoration: none;
  font-family: inherit;
  min-height: 44px;
  /* touch-friendly */
  transition: opacity 0.15s, background 0.15s;
}

button:hover,
.btn:hover {
  background: var(--surface-0);
}

button:active,
.btn:active {
  opacity: 0.85;
}

button.primary,
.btn.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

button.primary:hover,
.btn.primary:hover {
  background: #0d5c48;
  border-color: #0d5c48;
}

button.small,
.btn.small {
  width: auto;
  padding: 0.45rem 0.85rem;
  font-size: 13px;
  min-height: 36px;
}

button:disabled,
.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  pointer-events: none;
}

button.loading,
.btn.loading {
  opacity: 0.8;
  cursor: wait;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-row>* {
  flex: 1 1 0;
  min-width: 0;
}

.btn-row form {
  margin: 0;
}

.btn-row .btn.small,
.btn-row button.small {
  width: 100%;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

button:not(.primary) .spinner {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--text-primary);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Forms ─── */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 16px;
  /* prevents iOS zoom */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-family: inherit;
  background: var(--surface-1);
  color: var(--text-primary);
  -webkit-appearance: none;
  appearance: none;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-bg);
}

input[type="file"] {
  padding: 0.5rem;
  font-size: 14px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B6F68' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

label {
  font-size: 13px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  min-height: 40px;
  padding: 4px 0;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  border: 2px solid var(--text-secondary);
  background: var(--surface-1);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
}

.checkbox-row input[type="checkbox"] {
  border-radius: 5px;
}

.checkbox-row input[type="radio"] {
  border-radius: 50%;
}

.checkbox-row input[type="checkbox"]:checked,
.checkbox-row input[type="checkbox"]:checked:disabled {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
}

.checkbox-row input[type="radio"]:checked {
  background: var(--teal);
  border-color: var(--teal);
}

.checkbox-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.checkbox-row input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}

.checkbox-row input[type="checkbox"]:focus-visible,
.checkbox-row input[type="radio"]:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.checkbox-row label {
  margin: 0;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  flex: 1;
}

.error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 10px;
}

.muted {
  color: var(--text-secondary);
  font-size: 13px;
}

.tx-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.tx-row:last-child {
  border-bottom: none;
}

.tx-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.3;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px;
}

a.link {
  color: var(--teal);
  text-decoration: none;
}

a.link:hover {
  text-decoration: underline;
}

/* Action stack — consistent vertical buttons on mobile */
.action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.action-stack .btn,
.action-stack a.btn {
  width: 100%;
}

/* Page header spacing */
.page-intro {
  margin-bottom: 1rem;
}

/* Touch-friendly list items */
@media (max-width: 480px) {
  .container {
    padding: 0.85rem 0.85rem 2rem;
  }

  .card {
    padding: 0.9rem 1rem;
  }

  .btn-row {
    gap: 6px;
  }

  .btn-row button.small,
  .btn-row .btn.small {
    font-size: 12px;
    padding: 0.4rem 0.5rem;
  }
}

/* ─── Welcome / society document ─── */
.welcome-hero {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.welcome-eyebrow {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--teal);
  margin: 0 0 6px;
}

.welcome-card {
  padding: 0.5rem 1rem 0.75rem;
}

.welcome-points {
  list-style: none;
  margin: 0;
  padding: 0;
}

.welcome-points li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.welcome-points li:last-child {
  border-bottom: none;
}

.welcome-points strong {
  display: block;
  font-size: 14px;
  margin-bottom: 2px;
}

.welcome-points .muted {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.welcome-icon {
  font-size: 22px;
  line-height: 1.2;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.doc-list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 14px;
  line-height: 1.55;
}

.doc-list li {
  margin-bottom: 8px;
}

.doc-list li:last-child {
  margin-bottom: 0;
}

.notif-preview {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}


/* Locked maintenance category (e.g. Security guard) */
.checkbox-row--locked {
  opacity: 0.65;
  background: var(--surface-0, #f5f5f5);
  border-radius: 8px;
  padding: 6px 8px;
  margin: 4px 0;
}

.checkbox-row--locked input[type="checkbox"] {
  cursor: not-allowed;
  accent-color: #98a2b3;
}

.checkbox-row--locked label,
.cat-label-locked {
  color: #667085;
  cursor: default;
}

#notification-bar {
  align-items: center;
  margin: 6px 16px;
  padding: 4px 12px;
  background: #fff1d6;
  font-size: 13px;
  line-height: 1;
}

#notification-bar button {
  box-sizing: border-box;
  width: auto;
  height: 22px;
  min-height: 0;
  padding: 0 10px;
  align-content: center;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: #e85d5d;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.page-wait-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(255, 255, 255, 0.85);
  align-items: center;
  justify-content: center;
}

.page-wait-overlay.visible {
  display: flex;
}

.page-wait-box {
  width: min(90%, 380px);
  padding: 24px;
  text-align: center;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.page-wait-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 4px solid #ddd;
  border-top-color: #333;
  border-radius: 50%;
  animation: page-wait-spin 0.8s linear infinite;
}

.page-wait-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.page-wait-message {
  font-size: 14px;
  line-height: 1.5;
  color: #666;
}

@keyframes page-wait-spin {
  to {
    transform: rotate(360deg);
  }
}

#page-retry-button {
  margin-top: 18px;
  padding: 10px 22px;
  border: none;
  border-radius: 6px;
  background: #333;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

#page-retry-button:active {
  opacity: 0.8;
}