/* ===== VARIABLES ===== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #3b82f6;
  --info-light: #dbeafe;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --sidebar-bg: #1e1b4b;
  --sidebar-text: #c7d2fe;
  --sidebar-active: rgba(99,102,241,0.35);
  --sidebar-hover: rgba(255,255,255,0.08);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --transition: all 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #1a2438;
  --surface-3: #334155;
  --border: #334155;
  --border-2: #475569;
  --text: #f1f5f9;
  --text-2: #e2e8f0;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --primary-light: #312e81;
  --success-light: #14532d;
  --warning-light: #78350f;
  --danger-light: #7f1d1d;
  --info-light: #1e3a5f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5), 0 4px 6px rgba(0,0,0,0.4);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  line-height: 1.6;
  overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
ul { list-style: none; }

/* ===== LAYOUT ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-header { padding: 20px 16px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { display: flex; flex-direction: column; }
.logo-title { font-size: 15px; font-weight: 700; color: #fff; }
.logo-subtitle { font-size: 11px; color: var(--sidebar-text); }

.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-label { flex: 1; }

.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,0.08); }
.theme-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-size: 13px;
  transition: var(--transition);
}
.theme-toggle:hover { background: var(--sidebar-hover); color: #fff; }

.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}
.main-wrapper.expanded { margin-left: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.menu-toggle { font-size: 18px; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); transition: var(--transition); }
.menu-toggle:hover { background: var(--surface-3); color: var(--text); }
.topbar-title { font-size: 17px; font-weight: 700; flex: 1; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.current-date { font-size: 12.5px; color: var(--text-muted); }

.content { flex: 1; padding: 28px 28px 48px; max-width: 1400px; width: 100%; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: var(--transition);
}
.card-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin-bottom: 18px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title span { color: var(--text-muted); font-weight: 400; font-size: 12px; }

/* ===== KPI GRID ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
}
.kpi-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.kpi-info { flex: 1; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.kpi-value { font-size: 20px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== DASHBOARD GRID ===== */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.dash-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.dash-full { grid-column: 1 / -1; }

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-2); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ===== FILTERS BAR ===== */
.filters-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 20px; align-items: center;
}
.search-input {
  padding: 8px 14px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  min-width: 220px;
  transition: var(--transition);
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.filter-select {
  padding: 8px 12px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: var(--transition);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--primary); }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface-2);
  padding: 11px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.td-actions { display: flex; gap: 6px; justify-content: flex-end; }
.action-btn {
  padding: 4px 8px; border-radius: var(--radius-sm);
  font-size: 12px; cursor: pointer;
  transition: var(--transition); display: inline-flex; align-items: center; gap: 3px;
}
.action-btn.edit { background: var(--info-light); color: var(--info); }
.action-btn.edit:hover { background: var(--info); color: #fff; }
.action-btn.delete { background: var(--danger-light); color: var(--danger); }
.action-btn.delete:hover { background: var(--danger); color: #fff; }
.action-btn.view { background: var(--primary-light); color: var(--primary); }
.action-btn.view:hover { background: var(--primary); color: #fff; }
.action-btn.pay { background: var(--success-light); color: var(--success); }
.action-btn.pay:hover { background: var(--success); color: #fff; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11.5px; font-weight: 600;
  white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: #16a34a; }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-danger { background: var(--danger-light); color: #dc2626; }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-gray { background: var(--surface-3); color: var(--text-muted); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: modalIn 0.2s ease;
}
.modal.modal-lg { max-width: 820px; }
.modal.modal-sm { max-width: 420px; }
@keyframes modalIn { from { opacity:0; transform: translateY(-16px) scale(0.97); } to { opacity:1; transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { padding: 4px 8px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 16px; transition: var(--transition); }
.modal-close:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-muted);
  padding: 10px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  grid-column: 1 / -1;
}
.form-hint { font-size: 11px; color: var(--text-muted); }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input { width: 16px; height: 16px; cursor: pointer; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 260px;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: none; } }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--primary); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 13px; }

/* ===== STAT ROW ===== */
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-chip {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; gap: 5px;
}
.stat-chip strong { color: var(--text); }

/* ===== PROGRESS BAR ===== */
.progress-bar { background: var(--surface-3); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }

/* ===== SECTION DIVIDER ===== */
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted);
  margin: 20px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ===== AVATAR ===== */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}

/* ===== TABS ===== */
.tabs { display: flex; gap: 2px; background: var(--surface-3); border-radius: var(--radius); padding: 4px; margin-bottom: 20px; }
.tab {
  flex: 1; padding: 8px 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; text-align: center; cursor: pointer;
  color: var(--text-muted); transition: var(--transition);
}
.tab.active { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow-sm); }
.tab:hover:not(.active) { color: var(--text); }

/* ===== BILLING CARD ===== */
.billing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.billing-header { display: flex; align-items: center; gap: 12px; }
.billing-name { font-size: 14px; font-weight: 700; }
.billing-prof { font-size: 12px; color: var(--text-muted); }
.billing-amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.billing-amount { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; }
.billing-amount-label { font-size: 11px; color: var(--text-muted); }
.billing-amount-value { font-size: 16px; font-weight: 700; color: var(--text); }
.billing-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .content { padding: 16px 14px 40px; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
}

/* ===== ATTENDANCE FORM ===== */
.atend-table { width: 100%; border-collapse: collapse; }
.atend-table th, .atend-table td { padding: 8px 10px; border: 1px solid var(--border); font-size: 12.5px; }
.atend-table th { background: var(--surface-2); font-weight: 700; font-size: 12px; }
.atend-table td input { border: none; background: transparent; width: 100%; color: var(--text); padding: 2px; }
.atend-table td input:focus { outline: none; }

/* ===== CHART CONTAINER ===== */
.chart-container { position: relative; height: 260px; }

/* ===== LIST ITEM ===== */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-size: 13.5px; font-weight: 600; }
.list-item-sub { font-size: 12px; color: var(--text-muted); }
.list-item-value { font-size: 14px; font-weight: 700; text-align: right; }

/* ===== TOGGLE ===== */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative;
  width: 40px; height: 22px;
  background: var(--border-2);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--success); }
.toggle::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on::after { transform: translateX(18px); }

/* ===== MONTH PICKER ===== */
.month-nav { display: flex; align-items: center; gap: 12px; }
.month-nav button { padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text); font-size: 18px; transition: var(--transition); }
.month-nav button:hover { background: var(--border); }
.month-nav .month-label { font-size: 16px; font-weight: 700; min-width: 140px; text-align: center; }

/* ===== OCCUPANCY GRID ===== */
.occ-grid td { transition: opacity 0.15s; }
.occ-grid td:hover { opacity: 0.85; }

/* ===== RECEIPT BADGE ===== */
.badge-rec { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .badge-rec { background: #065f46; color: #a7f3d0; }

/* ===== AUTH OVERLAY ===== */
.auth-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  display: none; align-items: center; justify-content: center; z-index: 9999;
}
.auth-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 40px 36px; width: 100%; max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.4); text-align: center;
}
.auth-logo { font-size: 48px; margin-bottom: 6px; }
.auth-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.auth-card > p { margin-bottom: 24px; }
.auth-card .form-group { text-align: left; margin-bottom: 14px; }

/* ===== APP LOADING ===== */
.app-loading {
  position: fixed; inset: 0; background: var(--bg);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px; z-index: 9998;
}
.app-loading-spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.app-loading p { color: var(--text-muted); font-size: 14px; }

/* ===== LOGOUT BUTTON ===== */
.logout-btn {
  display: none; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px; margin-top: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-text); font-size: 13.5px;
  border-radius: var(--radius-sm); transition: var(--transition);
}
.logout-btn:hover { background: rgba(239,68,68,0.18); color: #fca5a5; }

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .page-actions, .modal-overlay, .toast-container { display: none !important; }
  .main-wrapper { margin-left: 0; }
  .content { padding: 0; }
}
