/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #2563eb;
  --green:   #16a34a;
  --orange:  #ea580c;
  --red:     #dc2626;
  --yellow:  #d97706;
  --purple:  #7c3aed;
  --gray-50: #f9fafb;
  --gray-100:#f3f4f6;
  --gray-200:#e5e7eb;
  --gray-400:#9ca3af;
  --gray-600:#4b5563;
  --gray-800:#1f2937;
  --radius:  12px;
  --shadow:  0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 80px; /* space for bottom nav */
}

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

/* ── Top Nav ──────────────────────────────────────────────────────── */
.topnav {
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; }
.nav-links { display: flex; gap: 14px; font-size: 0.8rem; }
.nav-links a { color: rgba(255,255,255,.85); }
.nav-logout { font-size: 1rem; opacity: .7; }

/* ── Bottom Nav (iPhone style) ────────────────────────────────────── */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}
.bn-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  color: var(--gray-400);
  padding: 4px 8px;
  border-radius: 8px;
  min-width: 52px;
}
.bn-icon { font-size: 1.3rem; }
.bn-primary .bn-icon {
  background: var(--blue);
  color: #fff;
  border-radius: 50%;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  margin-top: -18px;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
}
.bn-primary { color: var(--blue); }

/* ── Container ────────────────────────────────────────────────────── */
.container { max-width: 480px; margin: 0 auto; padding: 16px; }

/* ── Alerts ───────────────────────────────────────────────────────── */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-info    { background: #dbeafe; color: #1e40af; }

/* ── Page Header ──────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 1.3rem; flex: 1; }
.back-btn {
  font-size: 1.1rem;
  color: var(--blue);
  padding: 4px 8px 4px 2px;
}
.date-badge {
  font-size: 0.75rem;
  background: var(--gray-200);
  padding: 3px 8px;
  border-radius: 20px;
  color: var(--gray-600);
}

/* ── Stats Grid ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num  { font-size: 2rem; font-weight: 700; }
.stat-label{ font-size: 0.75rem; color: var(--gray-600); margin-top: 2px; }
.stat-blue   .stat-num { color: var(--blue); }
.stat-green  .stat-num { color: var(--green); }
.stat-orange .stat-num { color: var(--orange); }
.stat-red    .stat-num { color: var(--red); }

/* ── Due Banner ───────────────────────────────────────────────────── */
.due-banner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 1px solid #fbbf24;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.due-banner strong { font-size: 1.2rem; color: var(--orange); }

/* ── Quick Actions ────────────────────────────────────────────────── */
.quick-actions h2, .section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-400);
  margin-bottom: 10px;
}
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.btn-primary   { background: var(--blue);   color: #fff; }
.btn-success   { background: var(--green);  color: #fff; }
.btn-info      { background: #0891b2;       color: #fff; }
.btn-secondary { background: #fff; color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-danger    { background: var(--red);    color: #fff; }
.btn-whatsapp  { background: #25d366;       color: #fff; }

.btn-full {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn-sm {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.btn-xs {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
}

/* ── List Cards ───────────────────────────────────────────────────── */
.list-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.lc-left { display: flex; flex-direction: column; gap: 3px; }
.lc-left strong { font-size: 1rem; }
.lc-left small  { color: var(--gray-600); font-size: 0.8rem; }
.lc-right { display: flex; align-items: center; gap: 8px; }
.chevron { color: var(--gray-400); font-size: 1.3rem; }

.apt-card { align-items: flex-start; }
.apt-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.occupied { border-left: 3px solid var(--green); }
.vacant   { border-left: 3px solid var(--orange); }

/* ── Bill Rows ────────────────────────────────────────────────────── */
.bill-row {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}
.bill-row.unpaid { border-left: 3px solid var(--red); }
.bill-row.paid   { border-left: 3px solid var(--green); opacity: .85; }
.bill-row-left  { display: flex; flex-direction: column; gap: 3px; }
.bill-row-left strong { font-size: 0.95rem; }
.bill-row-left small  { color: var(--gray-600); font-size: 0.78rem; }
.bill-row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.bill-row-right strong { font-size: 1rem; }

/* ── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select,
.form-group textarea {
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 0.95rem;
  width: 100%;
  background: var(--gray-50);
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--blue); background: #fff; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-400);
  margin-bottom: 10px;
  padding-top: 4px;
}

/* ── Info Box ─────────────────────────────────────────────────────── */
.info-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.88rem;
  color: #1e40af;
  margin-bottom: 14px;
  line-height: 1.6;
}

/* ── Calc Preview (meter) ─────────────────────────────────────────── */
.calc-preview {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: #166534;
  margin-bottom: 14px;
}

/* ── OCR ──────────────────────────────────────────────────────────── */
.ocr-status { color: var(--gray-600); padding: 8px 0; font-size: 0.9rem; }
.ocr-result {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f0fdf4;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: #166534;
  margin-top: 8px;
}

/* ── Bill Preview (generate) ──────────────────────────────────────── */
.bill-preview {
  background: #f8fafc;
  border: 1.5px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  opacity: .5;
  transition: opacity .3s;
}
.bp-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--gray-400); margin-bottom: 8px; }
.bp-row   { display: flex; justify-content: space-between; font-size: 0.9rem; padding: 4px 0; }
.bp-total { border-top: 1px solid var(--gray-200); margin-top: 4px; padding-top: 8px; font-weight: 700; font-size: 1rem; }

/* ── Bill Card (view) ─────────────────────────────────────────────── */
.bill-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 14px;
}
.bill-card-header {
  background: var(--blue);
  color: #fff;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.bill-tenant { font-size: 1.1rem; font-weight: 700; }
.bill-room   { font-size: 0.82rem; opacity: .85; margin-top: 2px; }
.bill-month-badge {
  background: rgba(255,255,255,.2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}
.bill-breakdown { padding: 16px; }
.bb-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}
.bb-label  { font-weight: 600; color: var(--gray-800); }
.bb-calc   { color: var(--gray-600); font-size: 0.82rem; }
.bb-amount { font-weight: 600; text-align: right; }
.bb-total-row {
  border-top: 2px solid var(--gray-200);
  border-bottom: none;
  margin-top: 4px;
  padding-top: 12px;
}
.total-amt { font-size: 1.3rem; color: var(--green); }
.paid-stamp {
  text-align: center;
  background: #dcfce7;
  color: #166534;
  font-weight: 700;
  padding: 10px;
  font-size: 0.9rem;
}

/* ── Detail Card ──────────────────────────────────────────────────── */
.detail-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-row span { color: var(--gray-600); }
.detail-row strong { text-align: right; }
.detail-row a { color: var(--blue); }

/* ── Danger Zone ──────────────────────────────────────────────────── */
.danger-zone {
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 16px;
}
.danger-zone summary {
  background: #fee2e2;
  color: var(--red);
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.danger-zone details[open] summary { border-bottom: 1px solid #fecaca; }
.danger-zone form { padding: 14px; }

/* ── Empty State ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}
.empty-state p { margin-bottom: 16px; font-size: 1rem; }

.muted-text { color: var(--gray-600); font-size: 0.88rem; margin-bottom: 12px; }

/* ── Section ──────────────────────────────────────────────────────── */
.section { margin-top: 20px; }

/* ── Documents ────────────────────────────────────────────────────── */
.docs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.doc-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.doc-thumb-link { display: block; }
.doc-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
  background: var(--gray-100);
}
.doc-pdf-icon {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: #fef3c7;
}
.doc-info {
  padding: 8px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.doc-info strong { font-size: 0.78rem; color: var(--gray-800); }
.doc-info small  { font-size: 0.7rem; color: var(--gray-600); }
.doc-info .muted { color: var(--gray-400); }
.doc-del-btn {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(220,38,38,.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.upload-doc-box {
  background: #fff;
  border: 1.5px dashed var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}
.upload-doc-box summary {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--blue);
  cursor: pointer;
  list-style: none;
}
.upload-doc-box details[open] summary {
  border-bottom: 1px solid var(--gray-200);
}
.upload-doc-box form { padding: 0 14px; }

/* ── Spinner ──────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; animation: spin 1s linear infinite; }

/* ── Responsive tweaks ────────────────────────────────────────────── */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .action-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .bb-row { grid-template-columns: 80px 1fr auto; font-size: 0.82rem; }
}
