:root {
  color-scheme: dark;
  --bg: #06111f;
  --bg-soft: #0c1b2d;
  --ink: #f7fbff;
  --muted: #9fb0c4;
  --gold: #f4c85a;
  --gold-2: #ffe5a3;
  --line: rgba(255, 255, 255, .12);
  --glass: rgba(10, 25, 43, .62);
  --glass-strong: rgba(13, 27, 45, .82);
  --green: #42d39b;
  --red: #ff6b7a;
  --blue: #75b7ff;
  --shadow: 0 28px 80px rgba(0, 0, 0, .38);
}

[data-theme="day"] {
  color-scheme: light;
  --bg: #edf3fb;
  --bg-soft: #f7f1df;
  --ink: #071424;
  --muted: #506174;
  --line: rgba(8, 24, 42, .12);
  --glass: rgba(255, 255, 255, .68);
  --glass-strong: rgba(255, 255, 255, .86);
  --shadow: 0 24px 70px rgba(31, 49, 76, .18);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(244, 200, 90, .18), transparent 30rem),
    radial-gradient(circle at 80% 20%, rgba(117, 183, 255, .15), transparent 26rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  color: var(--ink);
  overflow-x: hidden;
  min-width: 320px;
}

#skyCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -3;
  opacity: .72;
}

.ambient {
  position: fixed;
  width: 38vw;
  height: 38vw;
  border-radius: 999px;
  filter: blur(40px);
  opacity: .28;
  z-index: -2;
  pointer-events: none;
}
.ambient-one { left: -10vw; top: 8vh; background: var(--gold); }
.ambient-two { right: -12vw; bottom: 0; background: var(--blue); }

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
  touch-action: manipulation;
}

.app-shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 0 max(42px, env(safe-area-inset-bottom));
}

.glass {
  background: linear-gradient(145deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.35);
  border-radius: 30px;
}

.login-grid {
  min-height: calc(100vh - 44px);
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: 22px;
  align-items: stretch;
}
.auth-card {
  align-self: center;
}

.static-landing {
  padding: clamp(20px, 4vw, 38px);
  display: grid;
  gap: 28px;
}

.static-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.static-nav nav {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.static-nav a,
.hero-actions a {
  color: inherit;
  text-decoration: none;
}
.static-nav a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.static-hero {
  max-width: 760px;
  padding: clamp(24px, 6vw, 70px) 0;
}

.static-section {
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.hero, .panel, .auth-card {
  padding: clamp(20px, 4vw, 38px);
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #0a1421;
  box-shadow: 0 14px 34px rgba(244, 200, 90, .28);
}

h1, h2, h3, p { margin-top: 0; overflow-wrap: anywhere; }
h1 {
  font-size: clamp(42px, 7vw, 78px);
  line-height: .92;
  letter-spacing: -.07em;
  margin: 52px 0 20px;
}
h1 span, .gold { color: var(--gold); }
.hero p, .muted { color: var(--muted); line-height: 1.7; }

.metric-row, .stats-grid, .dashboard-grid, .role-grid {
  display: grid;
  gap: 14px;
}
.metric-row { grid-template-columns: repeat(3, 1fr); margin-top: 30px; }
.role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric, .stat, .mini-card {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.055);
  border-radius: 22px;
  padding: 16px;
}
.metric b, .stat b { display: block; font-size: 1.45rem; }
.metric span, .stat span, small { color: var(--muted); }

.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field span { color: var(--muted); font-size: .88rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 17px;
  min-height: 48px;
  padding: 14px 15px;
  background: rgba(4, 13, 24, .55);
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(244, 200, 90, .7);
  box-shadow: 0 0 0 4px rgba(244, 200, 90, .12);
}
button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(244, 200, 90, .72);
  outline-offset: 3px;
}
[data-theme="day"] input, [data-theme="day"] select, [data-theme="day"] textarea {
  background: rgba(255,255,255,.78);
}
textarea { min-height: 96px; resize: vertical; }
.code-input {
  font-size: clamp(1.25rem, 6vw, 1.9rem);
  font-weight: 900;
  letter-spacing: .22em;
  text-align: center;
}

.primary, .secondary, .danger, .ghost {
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .18s ease, opacity .18s ease, border-color .18s ease;
}
.primary {
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #071424;
}
.secondary, .ghost {
  background: rgba(255,255,255,.07);
  border: 1px solid var(--line);
}
.danger {
  background: rgba(255, 107, 122, .18);
  color: var(--red);
  border: 1px solid rgba(255, 107, 122, .35);
}
button:hover { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.auth-tabs, .topbar, .nav, .actions, .toolbar, .card-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.auth-tabs button { flex: 1 1 135px; }
.auth-tabs button.active, .nav button.active {
  background: var(--gold);
  color: #071424;
}
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.inline-actions > button { flex: 1 1 180px; }
.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}
.google-button {
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, .95);
  color: #111827;
  border: 1px solid rgba(255, 255, 255, .55);
  font-weight: 900;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .16);
}
.google-mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(from -45deg, #4285f4, #34a853, #fbbc05, #ea4335, #4285f4);
  color: #fff;
  font-size: .78rem;
  font-weight: 900;
}
.auth-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.55;
}
.auth-help {
  border: 1px solid rgba(244, 200, 90, .28);
  background: rgba(244, 200, 90, .08);
  border-radius: 22px;
  padding: 14px;
  margin: 14px 0;
}
.auth-help b {
  color: var(--gold);
  letter-spacing: .04em;
}
.auth-help p { color: var(--muted); margin: 7px 0 0; line-height: 1.6; }

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
}
.backend-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 900;
}
.backend-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.backend-pill.online::before { background: var(--green); box-shadow: 0 0 0 6px rgba(66, 211, 155, .12); }
.backend-pill.offline::before { background: var(--red); box-shadow: 0 0 0 6px rgba(255, 107, 122, .12); }
.backend-pill.checking::before { background: var(--gold); box-shadow: 0 0 0 6px rgba(244, 200, 90, .12); }
.identity { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: #071424;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  font-weight: 900;
}
.nav { margin: 14px 0 22px; }
.nav button { flex: 1 1 128px; }

.dashboard-grid { grid-template-columns: 1.05fr .95fr; }
.stats-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 14px; }

.delivery-list { display: grid; gap: 12px; }
.delivery-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  background: rgba(255,255,255,.055);
  min-width: 0;
}
.delivery-head, .delivery-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.status {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 900;
  text-transform: uppercase;
  background: rgba(117,183,255,.16);
  color: var(--blue);
}
.status.delivered { color: var(--green); background: rgba(66,211,155,.15); }
.status.pending { color: var(--gold); background: rgba(244,200,90,.14); }
.status.cancelled { color: var(--red); background: rgba(255,107,122,.14); }

.progress {
  height: 10px;
  background: rgba(255,255,255,.1);
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0;
}
.progress i {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--green));
}

.map-card {
  min-height: 340px;
  position: relative;
  overflow: hidden;
}
.estate-map {
  position: absolute;
  inset: 18px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    radial-gradient(circle at 30% 40%, rgba(244,200,90,.18), transparent 20%),
    rgba(2, 11, 21, .35);
  background-size: 44px 44px, 44px 44px, auto, auto;
}
.pin {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 8px rgba(244,200,90,.16);
}
.pin.rider { background: var(--green); box-shadow: 0 0 0 8px rgba(66,211,155,.18); }
.pin.drop { background: var(--blue); box-shadow: 0 0 0 8px rgba(117,183,255,.18); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.55);
  z-index: 20;
  padding: 18px;
}
.modal {
  width: min(680px, 100%);
  max-height: min(780px, calc(100vh - 30px));
  overflow: auto;
}
.hidden { display: none !important; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 860px) {
  .login-grid, .dashboard-grid, .stats-grid, .metric-row {
    grid-template-columns: 1fr;
  }
  .hero { min-height: auto; }
  h1 { margin-top: 30px; }
  .delivery-head, .delivery-meta { flex-direction: column; }
  .map-card {
    min-height: 300px;
  }
}

@media (max-width: 700px) {
  .topbar, .actions, .toolbar, .card-foot {
    align-items: stretch;
  }
  .actions, .toolbar, .card-foot {
    width: 100%;
  }
  .actions > button, .toolbar > button, .card-foot > button {
    flex: 1 1 170px;
  }
  .backend-pill {
    width: 100%;
    justify-content: center;
  }
  .role-grid {
    grid-template-columns: 1fr;
  }
  .modal-backdrop {
    align-items: end;
    padding: 10px;
  }
  .modal {
    max-height: calc(100dvh - 20px);
    border-radius: 24px;
  }
}

@media (max-width: 520px) {
  .app-shell { width: min(100% - 18px, 1200px); padding-top: 10px; }
  .hero, .panel, .auth-card { padding: 18px; border-radius: 24px; }
  .topbar { align-items: flex-start; }
  .primary, .secondary, .danger, .ghost { width: 100%; }
  .auth-tabs button { flex-basis: 100%; }
  .login-grid {
    min-height: calc(100dvh - 20px);
    gap: 12px;
  }
  .brand {
    letter-spacing: .08em;
    font-size: .82rem;
  }
  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 14px;
  }
  h1 {
    font-size: clamp(36px, 13vw, 54px);
    letter-spacing: -.055em;
  }
  .metric, .stat, .mini-card, .delivery-card {
    border-radius: 18px;
    padding: 14px;
  }
  .toast {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
  }
}

@media (max-width: 380px) {
  .app-shell { width: min(100% - 12px, 1200px); }
  .hero, .panel, .auth-card { padding: 14px; }
  .static-nav nav { width: 100%; }
  .static-nav a { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
  #skyCanvas { display: none; }
}
