/* Design system — Flat Design (light default, dark via prefers-color-scheme) */
:root {
  color-scheme: light dark;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;

  --primary: #0284C7;
  --primary-hover: #0369A1;
  --on-primary: #FFFFFF;

  --accent: #059669;
  --accent-bg: #ECFDF5;
  --warning: #D97706;
  --warning-bg: #FFFBEB;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --info: #7C3AED;
  --info-bg: #F5F3FF;

  --ring: #0284C7;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: none;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1220;
    --surface: #131B2C;
    --surface-2: #1B2436;
    --border: #2A3648;
    --text: #F1F5F9;
    --text-muted: #94A3B8;

    --primary: #38BDF8;
    --primary-hover: #0EA5E9;
    --on-primary: #05202E;

    --accent: #34D399;
    --accent-bg: #0B2B22;
    --warning: #FBBF24;
    --warning-bg: #2E2408;
    --danger: #F87171;
    --danger-bg: #2E1414;
    --info: #A78BFA;
    --info-bg: #241B3D;

    --ring: #38BDF8;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 24px 0 8px; }

a { color: var(--primary); }

.app { display: flex; flex-direction: column; min-height: 100vh; }

.view { display: none; padding: 16px; padding-bottom: 96px; max-width: 720px; margin: 0 auto; width: 100%; }
.view.active { display: block; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .t { font-weight: 700; font-size: 17px; }
.topbar .s { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Auth screen */
.auth-card {
  max-width: 380px;
  margin: 8vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 24px; color: var(--primary); }
.auth-card h2 { font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 14px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.form.inline input, .form.inline select { flex: 1; min-width: 130px; }

.form input, .form select, .form textarea {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  min-height: 44px;
  transition: border-color 150ms ease;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 20%, transparent);
}
.form textarea { min-height: 72px; resize: vertical; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 500; }

/* Buttons */
.btn {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 11px 18px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}
.btn:hover { background: var(--border); }
.btn:active { opacity: 0.85; }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--on-primary); }
.btn.small { padding: 8px 12px; font-size: 13px; min-height: 36px; }

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

/* Dashboard */
.progress-track {
  height: 10px; border-radius: 20px; background: var(--surface-2);
  border: 1px solid var(--border); overflow: hidden; margin-top: 10px;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 300ms ease; }

.register-toggle { margin-top: 18px; color: var(--text-muted); font-size: 13px; }
.register-toggle summary { cursor: pointer; margin-bottom: 12px; font-weight: 600; }

.error { color: var(--danger); font-size: 13px; min-height: 16px; font-weight: 500; }

/* Calendar */
#calendar {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  border: 1px solid var(--border);
}
.fc { font-family: var(--font); }
.fc .fc-toolbar-title { font-size: 17px; font-weight: 700; }
.fc .fc-button {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text);
  box-shadow: none;
  text-transform: capitalize;
  font-weight: 600;
}
.fc .fc-button:hover { background: var(--border); }
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.fc-theme-standard td, .fc-theme-standard th, .fc-theme-standard .fc-scrollgrid { border-color: var(--border); }
.fc .fc-non-business { background: var(--surface-2); }
.fc .fc-timegrid-slot-label, .fc .fc-col-header-cell-cushion { color: var(--text-muted); }
.fc-daygrid-day-number, .fc-col-header-cell-cushion { color: var(--text); }

/* Modal */
.modal-bg, .modal { position: fixed; display: none; }
.modal-bg { inset: 0; background: rgba(15, 23, 42, .55); z-index: 20; }
.modal {
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; width: 90%; max-width: 420px; z-index: 21;
}
.modal.open, .modal-bg.open { display: block; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* Cards & lists */
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.badge {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.pending { background: var(--warning-bg); color: var(--warning); }
.badge.approved { background: var(--accent-bg); color: var(--accent); }
.badge.rejected { background: var(--danger-bg); color: var(--danger); }
.badge.suggested { background: var(--info-bg); color: var(--info); }

.total-due { font-size: 26px; font-weight: 700; margin-bottom: 14px; color: var(--primary); }

.cal-status { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.cal-status > div { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--text-muted);
  padding: 10px 4px 8px; font-size: 11px; font-family: var(--font); font-weight: 600;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 56px; transition: color 150ms ease;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.active { color: var(--primary); }
.tabbar button:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }

/* Toast */
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 200ms ease;
  z-index: 30; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

@media (min-width: 768px) {
  .view { padding: 24px; }
}

/* Desktop: left sidebar nav instead of bottom tabbar, wider content */
@media (min-width: 900px) {
  .view { max-width: 1000px; padding: 32px 40px; padding-bottom: 40px; }

  .topbar { padding-left: 260px; }

  main#main { padding-left: 220px; }

  .tabbar {
    top: 0; bottom: 0; right: auto; width: 220px;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    border-top: none; border-right: 1px solid var(--border);
    padding: 20px 0 0;
    gap: 2px;
  }
  .tabbar button {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 24px; font-size: 14px; min-height: 44px;
    border-radius: 0 20px 20px 0; margin-right: 12px;
  }
  .tabbar button.active { background: var(--surface-2); }
  .tabbar button svg { width: 20px; height: 20px; flex-shrink: 0; }
}

@media (min-width: 1200px) {
  .view { max-width: 1140px; }
}
