*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #667eea;
  --primary-dark: #5a6fd6;
  --secondary: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-light: #f5f6fa;
  --bg-sidebar: #1e1e2f;
  --text: #333;
  --text-light: #666;
  --text-white: #fff;
  --white: #fff;
  --danger: #e74c3c;
  --danger-bg: #fde8e8;
  --success: #27ae60;
  --success-bg: #d4edda;
  --warning: #f39c12;
  --warning-bg: #fff3cd;
  --info: #3498db;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.04);
  --border: #e0e3eb;
  --table-stripe: #f8f9fc;
  --pagination-bg: #f8f9fc;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-light);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Screens ──────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }
#authScreen {
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  background: var(--bg-gradient);
  padding: 20px;
}
#dashboardScreen {
  flex-direction: column;
  min-height: 100vh;
}

/* ── Auth ─────────────────────────────────── */
.auth-box {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
}
.auth-box h1 { margin-bottom: 4px; font-size: 1.6em; }
.auth-box > p { color: var(--text-light); margin-bottom: 24px; font-size: 0.9em; }

/* ── Forms ────────────────────────────────── */
label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.9em; text-align: left; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95em;
  margin-bottom: 12px;
  transition: border-color 0.2s;
  background: var(--white);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102,126,234,0.12);
}
small.hint { display: block; margin-top: -10px; margin-bottom: 12px; font-size: 0.8em; color: var(--text-light); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}
.btn-primary { background: var(--bg-gradient); color: var(--text-white); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(102,126,234,0.35); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary { background: #e8eaf0; color: var(--text); }
.btn-secondary:hover { background: #dde0e8; }
.btn-danger { background: var(--danger); color: var(--text-white); }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 7px 14px; font-size: 0.85em; }
.btn-sm.btn-primary { width: auto; }

.hint { margin-top: 8px; font-size: 0.85em; color: var(--text-light); }
.hint a { color: var(--primary); text-decoration: none; }
.info { font-size: 0.9em; color: var(--text-light); margin-bottom: 16px; }

/* ── Alerts ───────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 0.9em; margin-bottom: 12px; }
.alert-error { background: var(--danger-bg); color: #c0392b; border: 1px solid #f5c6cb; }
.alert-success { background: var(--success-bg); color: #155724; border: 1px solid #c3e6cb; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ── Dashboard Header ─────────────────────── */
header {
  background: var(--bg-gradient);
  color: var(--text-white);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 10;
}
header h1 { font-size: 1.2em; }
.user-info { display: flex; align-items: center; gap: 10px; font-size: 0.85em; }
.badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8em;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
}

/* ── Layout ───────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--bg-sidebar);
  color: rgba(255,255,255,0.7);
  padding: 16px 0;
  flex-shrink: 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: inherit;
  text-decoration: none;
  font-size: 0.9em;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-left-color: var(--primary);
}
.nav-item.disabled { opacity: 0.35; cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; color: inherit; }
.nav-item-laporan {
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 12px;
}
.nav-icon { font-size: 1.2em; }

/* ── Main Content ─────────────────────────── */
main {
  flex: 1;
  padding: 20px 24px;
  overflow: hidden;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.module { display: none; }
.module.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.placeholder-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.placeholder-msg h3 { margin-bottom: 8px; }

/* ── Stats Cards ──────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); }
.stat-label { font-size: 0.8em; color: var(--text-light); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.6em; font-weight: 700; }
.stat-total { border-left: 4px solid var(--primary); }
.stat-lunas { border-left: 4px solid var(--success); }
.stat-belum { border-left: 4px solid var(--warning); }
.stat-nominal { border-left: 4px solid var(--info); }

/* ── Toolbar ──────────────────────────────── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.filters select {
  width: auto;
  min-width: 100px;
  margin-bottom: 0;
  padding: 7px 10px;
  font-size: 0.85em;
}

/* ── Table ────────────────────────────────── */
.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
}
.data-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table thead::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--border);
  z-index: 3;
  pointer-events: none;
}
.data-table th {
  background: #f0f2f7;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.85em;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}
.data-table tr:nth-child(even) { background: var(--table-stripe); }
.data-table tr:hover { background: #eef1f8; }
.data-table tr.row-lunas td { opacity: 0.65; }
.data-table .empty { text-align: center; padding: 32px; color: var(--text-light); font-style: italic; }
.text-right { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Pagination ───────────────────────────── */
.pagination {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--pagination-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 6px rgba(0,0,0,0.03);
}
.pagination-info {
  font-size: 0.82em;
  color: var(--text-light);
  white-space: nowrap;
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}
.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  font-size: 0.82em;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  line-height: 1;
}
.pagination-btn:hover:not(:disabled):not(.active) {
  background: #eef1f8;
  border-color: #ccc;
}
.pagination-btn.active {
  background: var(--primary);
  color: var(--text-white);
  border-color: var(--primary);
}
.pagination-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.pagination-ellipsis {
  padding: 0 4px;
  color: var(--text-light);
  font-size: 0.85em;
}

/* ── Scrollbar Styling ────────────────────── */
.table-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ── Badges ───────────────────────────────── */
.badge-success { background: var(--success-bg); color: #155724; padding: 2px 10px; border-radius: 12px; font-size: 0.8em; font-weight: 600; white-space: nowrap; }
.badge-danger { background: var(--danger-bg); color: #c0392b; padding: 2px 10px; border-radius: 12px; font-size: 0.8em; font-weight: 600; white-space: nowrap; }

/* ── Action Buttons ───────────────────────── */
.actions { white-space: nowrap; }
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1em;
  transition: all 0.15s;
  background: transparent;
}
.btn-confirm { color: var(--success); }
.btn-confirm:hover { background: var(--success-bg); }
.btn-edit { color: var(--info); }
.btn-edit:hover { background: #d1ecf1; }
.btn-delete { color: var(--danger); }
.btn-delete:hover { background: var(--danger-bg); }
.btn-upload { color: var(--info); }
.btn-upload:hover { background: #d1ecf1; }
.btn-bukti { color: var(--success); text-decoration: none; }
.btn-bukti:hover { background: var(--success-bg); }

/* ── Sub-tabs + Sub-modules ────────────────── */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.sub-tab {
  padding: 8px 18px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  color: var(--text-light);
  transition: all 0.15s;
}
.sub-tab.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}
.sub-tab:hover:not(.active) { background: #eef1f8; }
.sub-module {
  display: none;
  min-height: 0;
  overflow: hidden;
}
.sub-module.sub-active {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── Modal ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: 12px;
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 1.1em; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.6em;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 24px 24px; }
.modal-body p { margin-bottom: 16px; color: var(--text-light); line-height: 1.6; }

/* ── Form Row ─────────────────────────────── */
.form-row {
  display: flex;
  gap: 12px;
}
.form-row .form-group { flex: 1; }
.form-group { margin-bottom: 4px; }
.form-group label { margin-bottom: 4px; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

/* ── Toast ────────────────────────────────── */
#toast {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9em;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: slideUp 0.3s ease-out;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--info); color: #fff; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Loading ──────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ───────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar .nav-item { justify-content: center; padding: 14px; }
  .sidebar .nav-icon { margin: 0; }
  .sidebar .nav-item span:not(.nav-icon) { display: none; }
  main { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; gap: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filters { flex-wrap: wrap; }
  .filters select { flex: 1; min-width: 80px; }
  .pagination { flex-direction: column; align-items: stretch; text-align: center; }
  .pagination-controls { justify-content: center; flex-wrap: wrap; }
}

@media (max-width: 480px) {
  header { padding: 10px 14px; flex-wrap: wrap; }
  header h1 { font-size: 1em; }
  .user-info { font-size: 0.8em; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px 16px; }
  .stat-value { font-size: 1.3em; }
  .auth-box { padding: 28px 20px; }
}


/* ── GAS-Style Form Classes ───────────── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; color: #333; font-weight: 500; font-size: 0.95em; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 5px;
  font-size: 1em; font-family: inherit; transition: border-color 0.3s;
  box-sizing: border-box; background: #fff; margin-bottom: 0;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: #667eea; box-shadow: 0 0 5px rgba(102,126,234,0.3);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-row { display: flex; gap: 15px; margin-bottom: 20px; }
.form-row .form-group.half { flex: 1; margin-bottom: 0; }
@media (max-width: 768px) { .form-row { flex-direction: column; gap: 0; } }
.form-actions { display: flex; gap: 10px; margin-top: 30px; flex-wrap: wrap; }
.form-actions .btn { flex: 1; min-width: 100px; }
@media (max-width: 480px) { .form-actions { gap: 8px; margin-top: 20px; } }

/* Month grid selector (GAS-style) */
.month-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; margin-top: 8px; }
@media (max-width: 768px) { .month-grid { grid-template-columns: repeat(4,1fr); gap: 8px; } }
@media (max-width: 480px) { .month-grid { grid-template-columns: repeat(3,1fr); gap: 6px; } }
.checkbox-month-item {
  display: flex; align-items: center; justify-content: center;
  background: #f7f7fb; border: 1px solid #eee; border-radius: 6px;
  padding: 10px; text-align: center; cursor: pointer; user-select: none;
  min-height: 50px; flex-direction: column;
}
.checkbox-month-item input[type="checkbox"] { display: none; }
.checkbox-month-item span { pointer-events: none; font-size: 14px; }
.checkbox-month-item.selected { background: #3b82f6; color: white; border-color: #2b6fd6; }
.checkbox-month-item.paid-disabled { background: #e6f4ea; color: #1e7a3a; border-color: #c3e6cf; opacity: 0.6; cursor: not-allowed; pointer-events: none; }
.checkbox-month-item.paid-disabled .paid-check { display: flex; }

/* Kasbon wrapper */
#kasbon_wrapper { margin-bottom: 0; }
#kasbon_info { margin-top: 10px; }

/* Alert inside forms */
.form-group .alert { margin-top: 10px; }

/* ── Searchable Select / Autocomplete ── */
.searchable-wrapper { position: relative; }
.searchable-wrapper input { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 5px; font-size: 1em; box-sizing: border-box; }
.searchable-wrapper input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 5px rgba(102,126,234,0.3); }
.searchable-wrapper .dropdown-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #999; pointer-events: none; }

/* Autocomplete suggestion list (for custom impl) */
.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid #ddd; border-top: none; border-radius: 0 0 5px 5px; max-height: 200px; overflow-y: auto; z-index: 1001; display: none; }
.autocomplete-list div { padding: 10px 12px; cursor: pointer; font-size: 0.95em; }
.autocomplete-list div:hover { background: #f0f0ff; }
.autocomplete-list div.active { background: #e8e8ff; }
