/* Driving School Scheduler — mobile-first, light/dark aware. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #16202e;
  --muted: #6b7688;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --free: #0ea5a4;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --appbar-h: 52px;
  --nav-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1a2334;
    --surface-2: #222c40;
    --border: #2c3852;
    --text: #e6ebf3;
    --muted: #93a0b5;
    --primary: #3b82f6;
    --danger: #f05252;
    --success: #34d399;
    --warn: #f59e0b;
    --free: #2dd4bf;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout scaffold ---------- */

.appbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.appbar__brand { font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.appbar__logo { width: 28px; height: 28px; object-fit: contain; }

.main {
  position: fixed;
  top: calc(var(--appbar-h) + var(--safe-top));
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { padding: 12px 14px 28px; max-width: 720px; margin: 0 auto; }

.view__header { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.view__title { font-size: 1.35rem; margin: 6px 2px 12px; }
.view__header .view__title { margin: 0; }

/* ---------- Bottom nav ---------- */

.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.nav__btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: inherit;
  font-size: .68rem;
  cursor: pointer;
  padding: 6px 2px;
}
.nav__btn.is-active { color: var(--primary); }
.nav__icon { font-size: 1.25rem; line-height: 1; filter: grayscale(.2); }
.nav__btn.is-active .nav__icon { filter: none; }

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s ease, background .12s ease;
}
.btn:active { filter: brightness(.94); }
.btn--primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn--danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn--ghost { background: transparent; }
.btn--block { width: 100%; margin-top: 14px; }
.btn--add { padding: 8px 14px; }

/* ---------- Schedule: instructor tabs ---------- */

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.segmented--empty { padding: 12px; font-size: .9rem; }
.segmented__btn {
  flex: 1 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.segmented__btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Schedule: date bar ---------- */

.datebar { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.datebar__nav {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  font-size: 1.4rem; line-height: 1;
  color: var(--text);
  cursor: pointer;
}
.datebar__center { flex: 1; position: relative; display: flex; justify-content: center; }
.datebar__label {
  border: none; background: none; color: var(--text);
  font: inherit; font-weight: 700; font-size: 1.05rem;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.datebar__picker {
  position: absolute; inset: 0;
  opacity: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.datebar__today {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: 12px; padding: 0 12px; height: 40px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.pill { font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.pill--today { background: var(--primary); color: #fff; }

/* ---------- Schedule: timeline ---------- */

.timeline { display: flex; flex-direction: column; gap: 8px; }
.timeline__section { margin: 18px 2px 8px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.row:active { filter: brightness(.97); }
.row__time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 92px; font-size: .95rem; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; }
.row__title--free { color: var(--free); font-weight: 600; }
.row__sub { margin-top: 3px; }
.row__chev { color: var(--muted); font-size: 1.3rem; line-height: 1; }

.row--slot {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
  border-color: color-mix(in srgb, var(--free) 45%, var(--border));
}
.row--slot .row__chev { color: var(--free); font-weight: 700; }
.row--done { opacity: .78; }
.row--done .row__title { text-decoration: line-through; text-decoration-color: var(--muted); }
.row--cancelled { opacity: .55; }
.row--session.row--cancelled { border-style: dashed; }

.badge {
  display: inline-block; font-size: .68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; text-transform: capitalize;
  background: var(--surface-2); color: var(--muted);
}
.badge--scheduled { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.badge--done { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge--cancelled { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ---------- Cards (students / instructors) ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card:active { filter: brightness(.97); }
.card__main { flex: 1; min-width: 0; }
.card__title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card--done { opacity: .72; }
.progress__bar--done { background: var(--success); }

.group { margin-bottom: 8px; }
.section-head {
  margin: 18px 2px 8px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}
.group:first-child .section-head { margin-top: 4px; }
.card__sub { font-size: .85rem; margin-top: 2px; }
.card__right { text-align: right; min-width: 84px; }
.card__chev { color: var(--muted); font-size: 1.3rem; }
.count { font-weight: 700; font-variant-numeric: tabular-nums; }
.calid { word-break: break-all; }
.calid--missing { color: var(--warn); }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; margin-top: 6px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); border-radius: 999px; }

/* ---------- Panels (settings) ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel__title { margin: 0 0 4px; font-size: 1.05rem; }
.panel__intro { margin: 0 0 12px; font-size: .85rem; }

/* ---------- Forms ---------- */

.field { display: block; margin-bottom: 12px; }
.field__label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field__hint { display: block; font-size: .76rem; color: var(--muted); margin-top: 4px; }
.field__hint--err { color: var(--danger); font-weight: 600; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.control {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
}
.control:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
select.control { appearance: none; }

.summary {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  font-size: .92rem;
  display: grid;
  gap: 4px;
}

/* ---------- Reschedule slot chips ---------- */

.slots { margin-top: 6px; }
.slots__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.slotchip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 6px;
  font: inherit; font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.slotchip.is-active { background: var(--primary); color: #fff; border-color: transparent; }

/* ---------- Help disclosure ---------- */

.help {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: .9rem;
}
.help summary { cursor: pointer; font-weight: 600; }
.help__body { margin-top: 8px; font-size: .85rem; }
.help__body p { margin: 6px 0; }

/* ---------- Empty / skeleton states ---------- */

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty p { margin: 6px 0; }
.skeleton { padding: 24px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- Modal & sheet ---------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 15, 25, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 40;
  animation: fade .15s ease;
}
.overlay--bottom { align-items: flex-end; padding: 0; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.modal__title { margin: 0; font-size: 1.1rem; }
.modal__x, .toast__close {
  border: none; background: none; color: var(--muted);
  font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal__body { padding: 4px 16px 8px; overflow-y: auto; }
.modal__footer { display: flex; gap: 8px; padding: 12px 16px calc(16px + var(--safe-bottom)); }
.modal__footer .btn { flex: 1; }

.sheet {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  width: 100%;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet__title { text-align: center; color: var(--muted); font-size: .85rem; font-weight: 600; padding: 10px; }
.sheet__item {
  display: block; width: 100%;
  border: none; background: var(--surface-2);
  color: var(--text);
  padding: 15px; margin-bottom: 6px;
  border-radius: 12px;
  font: inherit; font-weight: 600; font-size: 1rem;
  cursor: pointer;
}
.sheet__item--danger { color: var(--danger); }
.sheet__cancel { background: transparent; color: var(--muted); margin-top: 4px; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 10px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 12px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  background: #1f2937; color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  max-width: 460px; width: 100%;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  font-size: .9rem;
  animation: pop .16s ease;
}
.toast--error { background: var(--danger); }
.toast--success { background: var(--success); }
.toast--out { opacity: 0; transform: translateY(6px); transition: all .2s ease; }
.toast span { flex: 1; }
.toast__close { color: rgba(255, 255, 255, .8); }

/* ---------- Loading overlay ---------- */

.loading {
  position: fixed; inset: 0;
  background: rgba(10, 15, 25, .18);
  display: none; align-items: center; justify-content: center;
  z-index: 80;
}
.loading.is-visible { display: flex; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(255, 255, 255, .4);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 640px) {
  .view__title { margin-top: 10px; }
}
