/* ============================================================
   Routes4Me — Modern app shell with sidebar
   ============================================================ */
:root {
  --sidebar-w: 264px;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;

  --accent: #10b981;
  --accent-50: #ecfdf5;
  --danger: #ef4444;
  --danger-50: #fef2f2;
  --warn: #f59e0b;
  --warn-50: #fffbeb;
  --info: #0ea5e9;
  --info-50: #f0f9ff;

  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e6eaf2;

  --side-bg: #0f172a;
  --side-bg-2: #111c33;
  --side-text: #cbd5e1;
  --side-muted: #64748b;
  --side-active: #4f46e5;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 6px 20px -8px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px -12px rgba(15, 23, 42, 0.18);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

html { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
  z-index: 200;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 22px 18px;
  color: #fff;
}
.brand-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center;
  box-shadow: 0 6px 16px -4px rgba(99, 102, 241, 0.6);
  flex-shrink: 0;
}
.brand-text { font-weight: 800; font-size: 1.25rem; letter-spacing: -0.4px; }
.brand-text span { color: #a5b4fc; }
.nav-close { display: none; margin-left: auto; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--side-muted); }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px 14px;
}
.nav-section {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--side-muted);
  padding: 18px 12px 8px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 10px;
  color: var(--side-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.93rem;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active {
  background: var(--side-active);
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(79, 70, 229, 0.7);
}
.nav a .ic {
  width: 22px;
  text-align: center;
  font-style: normal;
  font-size: 1.05rem;
  opacity: 0.85;
}
.nav a.active .ic { opacity: 1; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
  background: rgba(0,0,0,0.18);
}
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.who { flex: 1; min-width: 0; }
.who-name { color: #fff; font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { color: var(--side-muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout {
  color: var(--side-muted);
  padding: 8px;
  border-radius: 8px;
  display: grid; place-items: center;
  transition: background 0.15s, color 0.15s;
}
.logout:hover { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* ---------- Main content ---------- */
main {
  padding: 34px 40px 60px;
  min-width: 0;
  position: relative;
}
.nav-open { display: none; }
.nav-toggle, .nav-backdrop { display: none; }

h1, h2, h3, h4 { margin: 0 0 18px; color: var(--text); font-weight: 700; letter-spacing: -0.4px; }
h1 { font-size: 1.75rem; margin-bottom: 22px; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 0.95rem; }
p { margin: 0 0 14px; }
p.muted, .muted { color: var(--muted); }
.small { font-size: 0.85rem; }
h1 + p.muted, h1 + .muted { margin-top: -14px; margin-bottom: 22px; }

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

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 22px;
}
.card > h3:first-child, .card > h2:first-child { margin-top: 0; }

/* ---------- Grid / layout ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: #a0aec0; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-100);
}
input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px;
  margin: 0 8px 0 0;
  vertical-align: -3px;
  accent-color: var(--primary);
}
label input[type="checkbox"] + span, label > input[type="checkbox"] { font-weight: 500; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
input[type="date"], input[type="time"] { min-height: 44px; }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25), 0 4px 12px -4px rgba(79, 70, 229, 0.45);
}
button:hover, .btn:hover { background: var(--primary-600); transform: translateY(-1px); }
button:active, .btn:active { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

button.secondary, .btn.secondary {
  background: #fff;
  color: var(--text-2);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
button.secondary:hover, .btn.secondary:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--text); }

button.danger, .btn.danger {
  background: var(--danger);
  box-shadow: 0 4px 12px -4px rgba(239, 68, 68, 0.5);
}
button.danger:hover, .btn.danger:hover { background: #dc2626; }

button.success, .btn.success { background: var(--accent); box-shadow: 0 4px 12px -4px rgba(16,185,129,0.5); }
button.success:hover, .btn.success:hover { background: #059669; }

button.small, .btn.small {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}
button.small.danger, .btn.small.danger {
  background: var(--danger-50);
  color: #b91c1c;
  border-color: #fecaca;
  box-shadow: none;
}
button.small.danger:hover, .btn.small.danger:hover { background: #fee2e2; }

/* ---------- Messages / badges ---------- */
.msg {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-weight: 500;
  border: 1px solid transparent;
}
.msg.ok  { background: var(--accent-50); color: #065f46; border-color: #a7f3d0; }
.msg.err { background: var(--danger-50); color: #991b1b; border-color: #fecaca; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-50);
  color: var(--primary-600);
}
.badge.ok { background: var(--accent-50); color: #047857; }
.badge.warn { background: var(--warn-50); color: #b45309; }
.badge.err { background: var(--danger-50); color: #b91c1c; }
.badge.muted { background: #f1f5f9; color: var(--muted); }

/* ---------- Metrics ---------- */
.metric {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  position: relative;
  overflow: hidden;
}
.metric::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary), #8b5cf6);
}
.metric .number {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
  line-height: 1.1;
}
.metric .label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 6px;
}

/* ---------- Tables ---------- */
.card > table:only-child { margin: -24px; width: calc(100% + 48px); border: none; box-shadow: none; border-radius: var(--radius); }
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: #f8fafc;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: #fafbff; }
td strong { color: var(--text); font-weight: 600; }
td img { display: block; }
td .muted { font-size: 0.82rem; }
code { background: #f1f5f9; padding: 2px 7px; border-radius: 6px; font-size: 0.85em; color: var(--primary-600); }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.cal-header { text-align: center; font-weight: 700; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.8px; text-transform: uppercase; padding: 8px 0; }
.cal-day {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 100px;
  padding: 10px 12px;
  cursor: pointer;
  background: #fff;
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
}
.cal-day:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #c7d2fe; }
.cal-dnum { font-weight: 700; font-size: 1rem; }
.cal-type { font-size: 0.72rem; color: var(--muted); text-transform: capitalize; margin-top: 4px; font-weight: 500; }
.cal-note { font-size: 0.72rem; color: var(--muted); margin-top: 6px; line-height: 1.3; }
.cal-day.shabbat, .cal-day.noschool, .cal-day.yom_tov { background: #fff1f2; color: #9f1239; border-color: #fecdd3; }
.cal-day.shabbat .cal-type, .cal-day.noschool .cal-type, .cal-day.yom_tov .cal-type { color: #be123c; }
.cal-day.erev { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.cal-day.erev .cal-type { color: #b45309; }
.cal-day.custom { background: var(--info-50); color: #075985; border-color: #bae6fd; }
.cal-day.custom .cal-type { color: #0369a1; }
.cal-day.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 6px 0 14px; vertical-align: middle; }
.dot.noschool { background: #fb7185; }
.dot.erev { background: #fbbf24; }
.dot.custom { background: #38bdf8; }

/* ---------- Planner / stop cards ---------- */
.stop-list { min-height: 90px; }
.stop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.stop-card:hover { box-shadow: var(--shadow); border-color: #c7d2fe; }
.stop-card:active { cursor: grabbing; }
.stop-thumb { height: 56px; width: 76px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.stop-body { flex: 1; min-width: 0; }
.stop-name { font-weight: 600; display: flex; align-items: center; gap: 10px; color: var(--text); }
.stop-addr { font-size: 0.85rem; color: var(--muted); }
.eta {
  background: var(--primary-50);
  color: var(--primary-600);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}
.van-col {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 14px;
  min-height: 160px;
}
.sortable-ghost { opacity: 0.4; }
.sortable-drag { box-shadow: var(--shadow-lg); }

/* ---------- Login (standalone pages) ---------- */
body.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #c7d2fe 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #a5f3fc 0%, transparent 55%),
              var(--bg);
}
.auth-card {
  background: #fff;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; }
.auth-brand .brand-icon { width: 44px; height: 44px; }
.auth-brand .brand-text { color: var(--text); font-size: 1.4rem; }
.auth-brand .brand-text span { color: var(--primary); }
.auth-card h1 { text-align: center; font-size: 1.3rem; margin: 14px 0 4px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin-bottom: 26px; font-size: 0.92rem; }
.auth-card .field { margin-bottom: 14px; }
.auth-card button { width: 100%; padding: 13px; font-size: 0.98rem; margin-top: 6px; }
.auth-card .error { background: var(--danger-50); color: #991b1b; border: 1px solid #fecaca; border-radius: 10px; padding: 10px 14px; font-size: 0.88rem; margin-bottom: 14px; }
.auth-links { margin-top: 22px; text-align: center; font-size: 0.88rem; color: var(--muted); }
.auth-links a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-links a:hover { text-decoration: underline; }

/* ---------- Utilities ---------- */
.text-right { text-align: right; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --sidebar-w: 232px; }
  main { padding: 28px 28px 50px; }
}

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  .nav-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
    z-index: 150;
  }
  .nav-toggle:checked ~ .nav-backdrop { opacity: 1; pointer-events: auto; }
  .nav-close { display: block; }
  .nav-open {
    display: inline-grid;
    place-items: center;
    width: 42px; height: 42px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    cursor: pointer;
    margin-bottom: 16px;
  }
  main { padding: 18px 16px 40px; }
  h1 { font-size: 1.45rem; }
  .card { padding: 18px; }
  .card > table:only-child { margin: -18px; width: calc(100% + 36px); }
  .card > table { display: block; overflow-x: auto; }
  th, td { padding: 12px 14px; }
  .grid { grid-template-columns: 1fr; }
  .cal-grid { gap: 4px; }
  .cal-day { min-height: 64px; padding: 6px; }
  .cal-type { display: none; }
}
