:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e6ea;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-bg: #111827;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #111827);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  padding: 36px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card .muted { margin-top: 0; margin-bottom: 20px; }
.switch-mode { text-align: center; margin-top: 16px; font-size: 14px; }
.switch-mode a { color: var(--primary); text-decoration: none; }

.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #3c4043;
  border: 1px solid var(--border);
}
.btn-google:hover { background: #f8f9fa; }

/* ---------- App Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 18px 0;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 10px;
}
#nav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0 10px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { width: 18px; text-align: center; }

.sidebar-footer {
  padding: 14px 16px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 10px;
}
#user-info { display: flex; flex-direction: column; margin-bottom: 10px; font-size: 13px; }
#user-info strong { color: #fff; font-size: 14px; }
#user-info .muted { text-transform: capitalize; }

.main { flex: 1; padding: 28px 32px; overflow-x: hidden; min-width: 0; }

/* ---------- Common ---------- */
.page-title { margin: 0 0 18px; font-size: 22px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin-top: 0; font-size: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.negative { color: var(--danger); font-weight: 600; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-danger { color: var(--danger); }
.stat-success { color: var(--success); }
.stat-warning { color: var(--warning); }

.progress-row { margin-bottom: 14px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.progress-bar { background: #e5e7eb; border-radius: 6px; height: 8px; overflow: hidden; }
.progress-fill { background: var(--primary); height: 100%; }
.progress-fill.over { background: var(--danger); }

/* ---------- Table ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table thead th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.report-total-label { text-align: right; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
  font-size: 12px;
  text-transform: capitalize;
}
.badge-paid, .badge-completed, .badge-adjusted { background: #dcfce7; color: #166534; }
.badge-pending, .badge-planning { background: #fef3c7; color: #92400e; }
.badge-partial, .badge-ongoing, .badge-outstanding { background: #dbeafe; color: #1e40af; }
.badge-on_hold { background: #fee2e2; color: #991b1b; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: #f3f4f6; }
.icon-btn.danger { color: var(--danger); border-color: #fecaca; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Filters ---------- */
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-row select, .filter-row input, #filter-project {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

/* ---------- Forms / Modal ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}
.field textarea { resize: vertical; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Daily log ---------- */
.log-list { display: flex; flex-direction: column; gap: 12px; }
.log-entry-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.log-meta { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }

/* ---------- Misc ---------- */
.loading { padding: 60px; text-align: center; color: var(--muted); }
.error-box { background: #fee2e2; color: #991b1b; padding: 16px; border-radius: var(--radius); }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111827;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 2000;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-error { background: var(--danger); }
#toast.toast-success { background: var(--success); }

@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px; }
  .brand { border: none; margin: 0; padding: 0 12px; }
  #nav-links { flex-direction: row; padding: 0; }
  .sidebar-footer { display: flex; align-items: center; gap: 10px; border: none; padding: 0 10px; margin: 0; }
  #user-info { margin: 0; }
  .main { padding: 18px; }
}
