:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #16a34a;
  --danger: #dc2626;
  --border: #e2e8f0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --accent: #22c55e;
  --danger: #ef4444;
  --border: #334155;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  min-height: 100vh;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* LOGIN SCREEN */
#login-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
  width: 100%;
  max-width: 340px;
}

.login-logo { width: 64px; height: 64px; margin-bottom: 12px; }
.login-box h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login-box p { color: var(--text-muted); margin-bottom: 20px; font-size: 0.9rem; }

.passcode-display {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}

.passcode-display .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.2s;
}

.passcode-display .dot.filled {
  background: var(--primary);
  border-color: var(--primary);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.num-btn {
  padding: 18px 0;
  font-size: 1.2rem;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.num-btn:active { transform: scale(0.94); background: var(--border); }
.clear-btn, .theme-toggle-btn { font-size: 1rem; }

.login-error {
  color: var(--danger);
  min-height: 20px;
  margin-top: 14px;
  font-size: 0.85rem;
}

/* DASHBOARD */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 { font-size: 1.2rem; }
.header-actions { display: flex; gap: 10px; }
.header-actions button {
  background: var(--bg);
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}

#main-content {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-box {
  text-align: center;
  padding: 14px 8px;
  border-radius: 10px;
  background: var(--bg);
}

.stat-box .value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.stat-box .label { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

/* CALENDAR MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.calendar-header button {
  background: var(--bg);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--text);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.calendar-grid .day-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 6px 0;
}

.calendar-grid .day-cell {
  padding: 10px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.calendar-grid .day-cell:hover { background: var(--bg); }
.calendar-grid .day-cell.selected { background: var(--primary); color: white; font-weight: 700; }
.calendar-grid .day-cell.empty { cursor: default; }

@media (min-width: 768px) {
  #main-content { padding: 24px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

.cal-select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}
