/* ═══════════════════════════════════════════════════════════════
   HomeRent — Premium Mobile-First CSS
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  /* Color Palette */
  --bg-deep:       #0b0f1a;
  --bg-main:       #0f172a;
  --bg-card:       #1e293b;
  --bg-card-hover: #263349;
  --bg-input:      #1a2540;
  --bg-drawer:     #0d1627;

  --accent:        #6366f1;
  --accent-light:  #818cf8;
  --accent-dark:   #4f46e5;
  --accent-glow:   rgba(99,102,241,0.25);

  --green:         #10b981;
  --green-bg:      rgba(16,185,129,0.15);
  --red:           #ef4444;
  --red-bg:        rgba(239,68,68,0.15);
  --yellow:        #f59e0b;
  --yellow-bg:     rgba(245,158,11,0.15);
  --blue:          #3b82f6;
  --blue-bg:       rgba(59,130,246,0.15);

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #475569;
  --text-accent:   #818cf8;

  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,102,241,0.6);

  --shadow-sm:     0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg:     0 8px 40px rgba(0,0,0,0.5);
  --shadow-glow:   0 0 20px rgba(99,102,241,0.3);

  /* Layout */
  --topbar-h:      60px;
  --drawer-w:      260px;
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --radius-xl:     20px;

  /* Typography */
  --font-main: 'Sarabun', 'Inter', sans-serif;
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 2px; }

/* ══════════════════════════════════════════════════════════════
   TOP BAR
   ══════════════════════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(13,22,39,0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1.05rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.topbar-title:hover {
  opacity: 0.85;
}
.topbar-icon { font-size: 1.2rem; }

.menu-btn {
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; padding: 8px;
}
.menu-btn span {
  display: block;
  width: 18px; height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.3s;
}

.month-badge {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  color: var(--accent-light);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════
   DRAWER / SIDEBAR
   ══════════════════════════════════════════════════════════════ */
.drawer {
  position: fixed;
  top: 0; left: 0;
  width: var(--drawer-w);
  height: 100vh;
  background: var(--bg-drawer);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  z-index: 200;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 199;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.drawer-overlay.show { opacity: 1; pointer-events: all; }

.drawer-header {
  padding: 32px 20px 24px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(99,102,241,0.1) 0%, transparent 100%);
}
.drawer-logo { font-size: 2.5rem; margin-bottom: 8px; }
.drawer-title { font-size: 1.2rem; font-weight: 700; color: var(--text-primary); }
.drawer-sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }

.nav-list { list-style: none; padding: 12px 12px; flex: 1; }
.nav-list li { margin-bottom: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 0.95rem;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, var(--accent-glow), rgba(99,102,241,0.1));
  color: var(--accent-light);
  border: 1px solid rgba(99,102,241,0.3);
}
.nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }

.drawer-footer {
  padding: 16px 20px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ══════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════ */
.main-content {
  margin-top: var(--topbar-h);
  padding: 16px;
  min-height: calc(100vh - var(--topbar-h));
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Pages ──────────────────────────────────────────────────── */
.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Month Selector ──────────────────────────────────────────── */
.month-selector { display: flex; align-items: center; gap: 8px; }
.month-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  min-width: 100px;
  text-align: center;
}
.btn-icon {
  width: 32px; height: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--accent); border-color: var(--accent); }

/* ══════════════════════════════════════════════════════════════
   SUMMARY CARDS (Dashboard)
   ══════════════════════════════════════════════════════════════ */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 10px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.summary-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.card-total::before  { background: linear-gradient(90deg, var(--accent), var(--accent-light)); }
.card-paid::before   { background: linear-gradient(90deg, var(--green), #34d399); }
.card-unpaid::before { background: linear-gradient(90deg, var(--red), #f87171); }

.summary-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.summary-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.card-paid .summary-value   { color: var(--green); }
.card-unpaid .summary-value { color: var(--red); }

/* ══════════════════════════════════════════════════════════════
   ROOM CARDS GRID (Dashboard)
   ══════════════════════════════════════════════════════════════ */
.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.mt-4 { margin-top: 24px; }

.rooms-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.room-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.room-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 70% 20%, rgba(99,102,241,0.05), transparent 60%);
  pointer-events: none;
}
.room-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(99,102,241,0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.room-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.room-card-name { font-weight: 700; font-size: 0.95rem; }
.room-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 4px;
}
.status-paid    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-unpaid  { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.status-none    { background: var(--text-muted); }

.room-card-tenant {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-card-amount {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-light);
}
.room-card-actions {
  display: flex; gap: 6px;
  margin-top: 10px;
}
.room-action-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-sm);
  color: var(--accent-light);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.room-action-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.room-action-btn:active {
  transform: scale(0.96);
}

/* ══════════════════════════════════════════════════════════════
   FORMS
   ══════════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
.form-group.half { flex: 1; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-input, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-main);
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}
.form-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 d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input[readonly] { opacity: 0.6; cursor: not-allowed; }
.form-textarea { resize: vertical; min-height: 70px; }

/* ══════════════════════════════════════════════════════════════
   PREVIOUS READING BOX
   ══════════════════════════════════════════════════════════════ */
.prev-reading-box {
  background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(99,102,241,0.1));
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.prev-reading-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.prev-reading-grid { display: flex; gap: 20px; }
.prev-item { display: flex; align-items: center; gap: 10px; }
.prev-icon { font-size: 1.4rem; }
.prev-label { font-size: 0.75rem; color: var(--text-secondary); }
.prev-value { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }

/* ══════════════════════════════════════════════════════════════
   OCR TOGGLE
   ══════════════════════════════════════════════════════════════ */
.ocr-toggle-bar {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 16px;
  gap: 4px;
}
.ocr-toggle-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s;
  font-family: var(--font-main);
}
.ocr-toggle-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-glow);
}

/* ══════════════════════════════════════════════════════════════
   METER INPUT
   ══════════════════════════════════════════════════════════════ */
.meter-input-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.meter-icon-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  font-size: 0.95rem;
}
.meter-row { display: flex; align-items: flex-end; gap: 8px; }
.meter-arrow {
  color: var(--accent-light);
  font-size: 1.2rem;
  padding-bottom: 12px;
  flex-shrink: 0;
}
.meter-calc {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
  display: none;
}
.meter-calc.show { display: block; }

/* ── OCR Upload Area ─────────────────────────────────────────── */
.ocr-section { margin-bottom: 16px; }
.ocr-section-title { font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }

.ocr-upload-area {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.25s;
  overflow: hidden;
  position: relative;
  min-height: 120px;
}
.ocr-upload-area:hover { border-color: var(--accent); background: var(--bg-card-hover); }

.ocr-placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  text-align: center;
}
.ocr-camera-icon { font-size: 2rem; }

.ocr-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
}
.ocr-result { padding: 12px; border-top: 1px solid var(--border); }
.ocr-status {
  font-size: 0.82rem;
  color: var(--yellow);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}

/* ══════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  transition: all 0.25s;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  box-shadow: 0 4px 15px rgba(99,102,241,0.35);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99,102,241,0.5);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--accent); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: var(--red); color: white; }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(16,185,129,0.3);
}
.btn-success:hover { background: var(--green); color: white; }

.btn-line {
  background: rgba(6,199,85,0.15);
  color: #06c755;
  border: 1px solid rgba(6,199,85,0.3);
}
.btn-line:hover { background: #06c755; color: white; }

.btn-full { width: 100%; margin-top: 4px; }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }

/* ══════════════════════════════════════════════════════════════
   BILLING PAGE
   ══════════════════════════════════════════════════════════════ */
.bill-month-row { display: flex; gap: 12px; }

.bill-items-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 14px;
}
.bill-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.bill-item-row:last-child { border-bottom: none; }
.bill-item-label {
  font-size: 0.88rem;
  color: var(--text-secondary);
  flex: 1;
  display: flex; align-items: center; gap: 6px;
}
.bill-item-input {
  width: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-main);
  text-align: right;
  transition: border-color 0.2s;
}
.bill-item-input:focus { outline: none; border-color: var(--accent); }
.bill-other-label {
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--text-muted);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-family: var(--font-main);
  width: 120px;
  padding: 2px 4px;
}
.bill-other-label:focus { outline: none; border-color: var(--accent); color: var(--text-primary); }

.bill-divider { height: 1px; background: var(--border); margin: 0; }
.bill-total-row {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(99,102,241,0.03));
  padding: 14px 16px !important;
}
.bill-total-label { font-weight: 700; color: var(--text-primary); font-size: 1rem; }
.bill-total-value { font-size: 1.3rem; font-weight: 800; color: var(--accent-light); }

.bill-action-row { display: flex; gap: 10px; }
.bill-action-row .btn { flex: 1; }

.meter-action-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.meter-action-row .btn { flex: 1; }

/* ══════════════════════════════════════════════════════════════
   HISTORY PAGE
   ══════════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex; gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-select { flex: 1; min-width: 80px; padding: 10px 12px; font-size: 0.85rem; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  transition: all 0.2s;
}
.history-card:hover { border-color: rgba(99,102,241,0.4); }
.history-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.history-room-name { font-weight: 700; font-size: 1rem; }
.history-period { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.history-total { font-size: 1.1rem; font-weight: 700; color: var(--accent-light); }
.history-tenant { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 8px; }
.history-breakdown {
  display: flex; gap: 10px; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--text-muted);
  margin-bottom: 10px;
}
.history-breakdown span { 
  background: var(--bg-input); 
  padding: 3px 8px; 
  border-radius: 12px; 
}
.history-card-actions { display: flex; gap: 8px; margin-top: 4px; }

.paid-toggle-btn {
  flex: 2;
  padding: 14px 10px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid;
  font-family: var(--font-main);
  transition: all 0.25s;
  letter-spacing: 0.02em;
}
.partial-payment-btn {
  flex: 1.5;
  padding: 14px 10px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--yellow);
  border: 2px solid var(--yellow);
  font-family: var(--font-main);
  transition: all 0.25s;
  text-align: center;
}
.partial-payment-btn:hover {
  background: var(--yellow);
  color: white;
}
.paid-toggle-btn.paid {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green);
}
.paid-toggle-btn.paid:hover {
  background: var(--green);
  color: white;
}
.paid-toggle-btn.unpaid {
  background: var(--red-bg);
  color: var(--red);
  border-color: var(--red);
}
.paid-toggle-btn.unpaid:hover {
  background: var(--red);
  color: white;
}
.history-delete-btn {
  padding: 14px 16px;
  background: var(--red-bg);
  color: var(--red);
  border: 2px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.history-delete-btn:hover {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

/* ══════════════════════════════════════════════════════════════
   SETTINGS PAGE
   ══════════════════════════════════════════════════════════════ */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.settings-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.room-setting-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}
.room-setting-name {
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: var(--accent-light);
}
.room-setting-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.room-setting-grid .form-group { margin-bottom: 0; }

/* ══════════════════════════════════════════════════════════════
   METER HISTORY LIST
   ══════════════════════════════════════════════════════════════ */
.meter-history-list { display: flex; flex-direction: column; gap: 8px; }
.meter-history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.meter-history-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.meter-history-period { font-weight: 600; font-size: 0.9rem; color: var(--accent-light); }
.meter-history-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; font-size: 0.82rem;
}
.meter-history-item { color: var(--text-secondary); }
.meter-history-item strong { color: var(--text-primary); }

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.modal-close {
  width: 28px; height: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--red); color: white; border-color: var(--red); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px; }
.modal-footer {
  display: flex; gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.modal-footer .btn { flex: 1; }

/* ══════════════════════════════════════════════════════════════
   BILL PREVIEW (A5 receipt)
   ══════════════════════════════════════════════════════════════ */
.bill-preview {
  background: white;
  color: #1a1a1a;
  width: 420px;
  min-height: 560px;
  margin: 0 auto;
  padding: 24px 28px;
  font-family: 'Sarabun', sans-serif;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  line-height: 1.6;
}

.bill-preview .bp-header {
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 2px solid #2d3748;
  margin-bottom: 16px;
}
.bill-preview .bp-logo { font-size: 2rem; margin-bottom: 4px; }
.bill-preview .bp-bldname { font-size: 1.1rem; font-weight: 800; color: #1a202c; }
.bill-preview .bp-address { font-size: 0.78rem; color: #4a5568; margin-top: 2px; }
.bill-preview .bp-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 16px;
  background: #4f46e5;
  color: white;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.bill-preview .bp-meta {
  display: flex; justify-content: space-between;
  margin-bottom: 16px;
}
.bill-preview .bp-meta-item { font-size: 0.82rem; }
.bill-preview .bp-meta-label { color: #718096; }
.bill-preview .bp-meta-value { font-weight: 700; color: #1a202c; }

.bill-preview .bp-tenant-row {
  background: #f7f9fc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.bill-preview .bp-tenant-label { font-size: 0.72rem; color: #718096; }
.bill-preview .bp-tenant-name { font-size: 1rem; font-weight: 700; color: #1a202c; }

.bill-preview table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 0.85rem;
}
.bill-preview table th {
  background: #2d3748;
  color: white;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.78rem;
}
.bill-preview table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  color: #2d3748;
}
.bill-preview table tr:last-child td { border-bottom: none; }
.bill-preview table .td-right { text-align: right; font-weight: 600; }

.bill-preview .bp-total-row {
  background: #f0f0ff;
  border: 2px solid #4f46e5;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 0;
}
.bill-preview .bp-total-label { font-weight: 700; font-size: 1rem; color: #2d3748; }
.bill-preview .bp-total-value { font-size: 1.3rem; font-weight: 900; color: #4f46e5; }

.bill-preview .bp-notes {
  font-size: 0.78rem;
  color: #718096;
  border-top: 1px dashed #e2e8f0;
  padding-top: 10px;
  margin-top: 10px;
}
.bill-preview .bp-footer {
  text-align: center;
  font-size: 0.72rem;
  color: #a0aec0;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
  margin-top: 12px;
}

/* ══════════════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 400;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  opacity: 0;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.success { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.toast.error   { border-color: var(--red);   background: var(--red-bg);   color: var(--red); }

/* ══════════════════════════════════════════════════════════════
   LOADING
   ══════════════════════════════════════════════════════════════ */
.loading-spinner {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.9rem; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 640px) {
  .rooms-grid { grid-template-columns: 1fr 1fr 1fr; }
  .summary-grid { gap: 16px; }
  .main-content { padding: 24px; }
}

@media (min-width: 1024px) {
  .drawer { transform: translateX(0); }
  .main-content { margin-left: var(--drawer-w); }
  .menu-btn { display: none; }
  .drawer-overlay { display: none; }
  .topbar { left: var(--drawer-w); }
}

/* ══════════════════════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg-deep);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 500;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(99,102,241,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(16,185,129,0.08) 0%, transparent 50%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px 28px;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(99,102,241,0.15);
  animation: fadeIn 0.4s ease;
}
.login-logo {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 8px;
}
.login-title {
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 28px;
}
.login-pass-wrap {
  position: relative;
}
.login-pass-wrap .form-input {
  padding-right: 48px;
}
.login-eye {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.login-eye:hover { opacity: 1; }

.login-error {
  color: var(--red);
  font-size: 0.85rem;
  margin-bottom: 12px;
  min-height: 20px;
  text-align: center;
  font-weight: 500;
}

/* Logout button in topbar */
.logout-btn {
  width: 34px; height: 34px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.logout-btn:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }

/* Theme toggle button in topbar */
.theme-toggle-btn {
  width: 34px; height: 34px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.theme-toggle-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-light);
  border-color: var(--accent);
}

/* Carry over alert banner */
.carry-over-alert {
  display: flex;
  align-items: center;
  background: var(--yellow-bg);
  border: 1px solid var(--yellow);
  color: var(--yellow);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Partial paid status button */
.paid-toggle-btn.partial {
  background: var(--yellow-bg);
  color: var(--yellow);
  border-color: var(--yellow);
}
.paid-toggle-btn.partial:hover {
  background: var(--yellow);
  color: white;
}

/* Partial status dot in room card */
.status-partial {
  background: var(--yellow);
  box-shadow: 0 0 6px var(--yellow);
}

/* Bulk Room Checkbox UI */
.bulk-room-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
  font-size: 0.95rem;
  font-weight: 600;
}
.bulk-room-checkbox:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}
.bulk-room-checkbox.checked {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-light);
}
.bulk-room-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Bulk Print A4 Layout - Landscape */
.bulk-a4-sheet {
  width: 1123px;  /* A4 landscape width at 96 DPI */
  height: 794px;  /* A4 landscape height at 96 DPI */
  background: white;
  color: black;
  font-family: 'Sarabun', sans-serif;
  box-sizing: border-box;
  padding: 15px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr); /* 4x2 grid of portrait bills */
  gap: 0;
}

.bulk-mini-bill {
  box-sizing: border-box;
  padding: 12px 14px;
  font-size: 9.5px;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: white;
  color: black;
}

/* Inner vertical cutting lines (columns 1, 2, 3 only) */
.bulk-mini-bill:not(:nth-child(4n)) {
  border-right: 1px dashed #94a3b8;
}

/* Inner horizontal cutting line (row 1 only) */
.bulk-mini-bill:nth-child(-n+4) {
  border-bottom: 1px dashed #94a3b8;
}

.empty-bill-card {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa !important;
}

.bulk-mini-bill .bp-header {
  text-align: center;
  padding-bottom: 5px;
  border-bottom: 1.5px solid #2d3748;
  margin-bottom: 5px;
}
.bulk-mini-bill .bp-logo {
  font-size: 1.1rem;
  margin-bottom: 2px;
  line-height: 1;
}
.bulk-mini-bill .bp-bldname {
  font-size: 0.8rem;
  font-weight: 800;
  color: #1a202c;
  line-height: 1.2;
}
.bulk-mini-bill .bp-address {
  font-size: 0.62rem;
  color: #4a5568;
  margin-top: 1px;
  line-height: 1.2;
}
.bulk-mini-bill .bp-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 8px;
  background: #4f46e5;
  color: white;
  border-radius: 10px;
  font-size: 0.58rem;
  font-weight: 600;
  line-height: 1.1;
}

.bulk-mini-bill .bp-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  gap: 4px;
}
.bulk-mini-bill .bp-meta-item {
  text-align: center;
  flex: 1;
}
.bulk-mini-bill .bp-meta-label {
  font-size: 0.58rem;
  color: #718096;
  line-height: 1.1;
}
.bulk-mini-bill .bp-meta-value {
  font-weight: 700;
  color: #1a202c;
  font-size: 0.72rem;
  margin-top: 1px;
  line-height: 1.1;
}

.bulk-mini-bill .bp-tenant-row {
  background: #f7f9fc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 3px 6px;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bulk-mini-bill .bp-tenant-label {
  font-size: 0.58rem;
  color: #718096;
}
.bulk-mini-bill .bp-tenant-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: #1a202c;
}

.bulk-mini-bill table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
}
.bulk-mini-bill table th {
  background: #2d3748;
  color: white;
  padding: 2px 4px;
  text-align: left;
  font-size: 0.6rem;
}
.bulk-mini-bill table td {
  padding: 3px 4px;
  border-bottom: 1px solid #e2e8f0;
  color: #2d3748;
  font-size: 0.68rem;
}
.bulk-mini-bill table tr:last-child td {
  border-bottom: none;
}
.bulk-mini-bill table .td-right {
  text-align: right;
  font-weight: 600;
}

.bulk-mini-bill .bp-total-row {
  background: #f0f0ff;
  border: 1.5px solid #4f46e5;
  border-radius: 4px;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 3px 0 5px 0;
}
.bulk-mini-bill .bp-total-label {
  font-weight: 700;
  font-size: 0.72rem;
  color: #2d3748;
}
.bulk-mini-bill .bp-total-value {
  font-size: 0.88rem;
  font-weight: 900;
  color: #4f46e5;
}

.bulk-mini-bill .bp-footer {
  text-align: center;
  font-size: 0.58rem;
  color: #718096;
  padding-top: 3px;
  border-top: 1px solid #e2e8f0;
  line-height: 1.25;
}

/* ── App Logo Image Styling ────────────────────────────────────── */
.drawer-logo img, .login-logo img {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.25);
  margin: 0 auto 10px auto;
  display: block;
}
.drawer-logo, .login-logo {
  font-size: unset; /* Remove emoji size */
  display: flex;
  justify-content: center;
}

/* ── Bill Logo Image Styling ────────────────────────────────────── */
.bp-logo img {
  width: 55px;
  height: 55px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #4f46e5;
  margin: 0 auto;
  display: block;
}
.bulk-mini-bill .bp-logo img {
  width: 32px;
  height: 32px;
  border: 1px solid #4f46e5;
}

/* ── Light Theme Variable Overrides ────────────────────────────── */
:root.light-theme {
  --bg-deep:       #f1f5f9;
  --bg-main:       #f8fafc;
  --bg-card:       #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input:      #ffffff;
  --bg-drawer:     #ffffff;

  --text-primary:  #0f172a;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;
  --text-accent:   #4f46e5;

  --border:        rgba(15, 23, 42, 0.08);
  --border-focus:  rgba(99, 102, 241, 0.8);
}

:root.light-theme .topbar {
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--border);
}

:root.light-theme .drawer {
  border-right: 1px solid var(--border);
}

:root.light-theme .drawer-header {
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.05) 0%, transparent 100%);
}

:root.light-theme .drawer-footer {
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

:root.light-theme .login-title {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

:root.light-theme .login-pass-wrap .login-eye {
  color: var(--text-secondary);
}

:root.light-theme .rooms-group-title {
  border-bottom-color: rgba(15, 23, 42, 0.08) !important;
}
