:root {
  --font-display: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Plus Jakarta Sans", "Inter", "Segoe UI", sans-serif;

  --bg: #0f172a;
  --bg-gradient-start: #020617;
  --bg-gradient-end: #0f172a;

  --motion-quick: 140ms;
  --motion-base: 280ms;
  --motion-slow: 520ms;

  --surface-1: #111827;
  --surface-2: #0b1220;

  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;

  --accent: #22c55e;
  --accent-strong: #16a34a;
  --accent-contrast: #06260f;

  --danger: #ef4444;
  --danger-strong: #991b1b;
  --danger-soft: #fee2e2;

  --stroke-1: #334155;
  --stroke-2: #1f2937;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 14px;
  --radius-pill: 999px;

  --space-1: 0.35rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;

  --input-py: 0.65rem;
  --input-px: 0.75rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: linear-gradient(120deg, var(--bg-gradient-start), var(--bg-gradient-end));
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  z-index: -1;
  pointer-events: none;
  filter: blur(2px);
}

body::before {
  width: 380px;
  height: 380px;
  top: -90px;
  right: -110px;
  background: radial-gradient(circle at 30% 30%, rgba(56, 189, 248, 0.28), transparent 70%);
  animation: floatAmbient 14s ease-in-out infinite;
}

body::after {
  width: 420px;
  height: 420px;
  bottom: -160px;
  left: -140px;
  background: radial-gradient(circle at 70% 40%, rgba(34, 197, 94, 0.2), transparent 72%);
  animation: floatAmbient 18s ease-in-out infinite reverse;
}

img {
  max-width: 100%;
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 1rem 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

.topbar p {
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.admin-mode-tag {
  display: inline-block;
  margin-top: 0.45rem;
  background: #b91c1c;
  color: var(--danger-soft);
  border: 1px solid #ef4444;
  border-radius: var(--radius-pill);
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.header-avatar-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
}

.header-avatar-wrap:focus-visible {
  outline: 2px solid #22c55e;
  outline-offset: 4px;
  border-radius: 12px;
}

.header-avatar {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--stroke-1);
  object-fit: cover;
  background: var(--surface-2);
}

.header-avatar-name {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.container {
  width: min(1080px, 92%);
  margin: 0 auto 2rem;
  display: grid;
  gap: 1rem;
  align-items: start;
}

#mainView:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.9fr);
  gap: 1rem;
}

#mainHeaderSection,
#mainStartCard,
#exploreSection {
  grid-column: 1 / -1;
}

#driverActionsSection,
#driverRequestsSection,
#reviewSection,
#chatSection,
#routeComposerCard {
  grid-column: 1;
}

#notificationsSection,
#activitySection,
#historySection {
  grid-column: 2;
}

.main-start-card {
  background:
    radial-gradient(1200px 180px at -8% -60%, rgba(56, 189, 248, 0.22), transparent 45%),
    radial-gradient(900px 200px at 110% 140%, rgba(34, 197, 94, 0.2), transparent 48%),
    color-mix(in srgb, var(--surface-1) 94%, transparent);
}

.quick-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.55rem;
}

.card {
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--stroke-2);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.28);
  transition: transform var(--motion-base) ease, border-color var(--motion-base) ease, box-shadow var(--motion-base) ease;
  transform: perspective(900px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
}

.card:hover {
  border-color: #2a3f57;
  box-shadow: 0 14px 30px rgba(2, 6, 23, 0.36);
}

[hidden] {
  display: none;
}

h2, h3 {
  margin-top: 0;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

.grid {
  display: grid;
  gap: 0.75rem;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.journey-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.journey-btn {
  margin-top: 0;
  text-align: left;
  min-height: 132px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-lg);
  background: linear-gradient(165deg, #082f49, #0f172a);
  color: var(--text);
  padding: 1rem;
  transition: transform var(--motion-base) ease, box-shadow var(--motion-base) ease, filter var(--motion-base) ease;
  transform: perspective(900px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
}

.journey-btn:hover {
  box-shadow: 0 18px 36px rgba(2, 6, 23, 0.45);
  transform: translateY(-3px) perspective(900px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
}

.journey-btn:last-child {
  background: linear-gradient(165deg, #14532d, #0f172a);
}

.journey-title {
  display: block;
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.journey-subtitle {
  display: block;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 0.95rem;
}

input, select, button {
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke-1);
  background: var(--surface-2);
  color: var(--text);
  padding: var(--input-py) var(--input-px);
  transition: border-color var(--motion-quick) ease, box-shadow var(--motion-quick) ease, transform var(--motion-quick) ease, background-color var(--motion-quick) ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.16);
}

button {
  margin-top: 0.75rem;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  border: none;
  position: relative;
  overflow: hidden;
}

button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  left: 50%;
  top: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), transparent 60%);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
}

.pulse-hit::after {
  animation: pulseRipple 420ms ease;
}

.upload-field {
  background: var(--surface-2);
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  padding: 0.6rem;
}

.register-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.step-pill {
  display: inline-block;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-pill);
  padding: 0.18rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text-soft);
  background: var(--surface-2);
}

.step-pill.active {
  border-color: #22c55e;
  color: #86efac;
  background: rgba(20, 83, 45, 0.35);
}

.register-step {
  margin-bottom: 0.8rem;
}

.form-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.link-btn {
  margin-top: 0;
  background: transparent;
  color: #86efac;
  border: 1px solid #14532d;
  padding: 0.3rem 0.55rem;
}

.empty {
  color: var(--text-muted);
  padding: 0.5rem 0;
}

.profile {
  background: var(--surface-2);
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  padding: 0.8rem;
}

.profile-avatar-large {
  width: 160px;
  height: 160px;
  border-radius: var(--radius-pill);
  object-fit: cover;
  border: 3px solid var(--stroke-1);
  display: block;
  margin: 0 auto 0.85rem;
  background: #0b1220;
}

.profile-name {
  text-align: center;
  font-size: 1.7rem;
  font-weight: 800;
  margin: 0;
}

.profile-username {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0.2rem 0 0.7rem;
}

.profile-role-row {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.role-pill {
  display: inline-block;
  background: var(--accent-strong);
  color: #052e16;
  border-radius: var(--radius-pill);
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.profile-meta {
  border-top: 1px solid var(--stroke-1);
  margin-top: 0.7rem;
  padding-top: 0.7rem;
}

.badge {
  display: inline-block;
  background: #14532d;
  color: #bbf7d0;
  border: 1px solid #22c55e;
  border-radius: var(--radius-pill);
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  margin: 0.3rem 0;
}

.route {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  padding: 0.7rem;
  margin-top: 0.5rem;
  background: var(--surface-2);
}

.explore-layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(520px, 1.45fr);
  gap: 0.9rem;
  align-items: stretch;
}

.explore-sidebar {
  display: grid;
  gap: 0.65rem;
  min-height: 560px;
  max-height: 700px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-lg);
  padding: 0.7rem;
  background: color-mix(in srgb, var(--surface-2) 95%, transparent);
}

.route-filters-grid {
  display: grid;
  gap: 0.6rem;
}

.route-filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.results {
  color: var(--text-soft);
  font-size: 0.88rem;
}

.ride-list {
  display: grid;
  gap: 0.55rem;
  overflow: auto;
  min-height: 300px;
  padding-right: 0.15rem;
}

.ride-card {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 0.65rem;
  transition: border-color var(--motion-base) ease, box-shadow var(--motion-base) ease, transform var(--motion-base) ease;
  transform: translateY(0) perspective(900px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
}

.ride-card:hover,
.ride-card-highlight {
  border-color: #22c55e;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.2);
  transform: translateY(-1px);
}

.ride-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.ride-card-meta {
  color: var(--text-soft);
  font-size: 0.83rem;
  margin-top: 0.3rem;
}

.ride-history-list {
  display: grid;
  gap: 0.45rem;
}

.engagement-list {
  display: grid;
  gap: 0.45rem;
  max-height: 280px;
  overflow: auto;
}

.engagement-item {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 0.55rem;
  transition: border-color var(--motion-base) ease, transform var(--motion-base) ease;
}

.engagement-item:hover {
  transform: translateX(3px);
  border-color: #22c55e;
}

.engagement-unread {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25) inset;
}

.engagement-detail {
  color: var(--text-soft);
  font-size: 0.83rem;
  margin-top: 0.2rem;
}

.engagement-meta {
  color: var(--text-muted);
  font-size: 0.76rem;
  margin-top: 0.18rem;
}

.ride-card-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.45rem;
}

.ride-verify-pill {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 0.12rem 0.5rem;
  font-size: 0.72rem;
  border: 1px solid var(--stroke-1);
}

.ride-verified {
  color: #86efac;
  border-color: #16a34a;
  background: rgba(20, 83, 45, 0.35);
}

.ride-unverified {
  color: #fbbf24;
  border-color: #f59e0b;
  background: rgba(120, 53, 15, 0.35);
}

.map-pane {
  min-width: 0;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-lg);
  padding: 0.6rem;
  background: color-mix(in srgb, var(--surface-2) 95%, transparent);
}

.chat-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0.7rem;
}

.chat-thread-list {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 0.35rem;
  max-height: 360px;
  overflow: auto;
}

.chat-thread-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: transparent;
  color: var(--text);
  margin-top: 0;
}

.chat-thread-item:hover,
.chat-thread-active {
  border-color: var(--stroke-1);
  background: rgba(15, 23, 42, 0.65);
}

.chat-thread-preview {
  display: block;
  margin-top: 0.22rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-window {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 0.6rem;
  display: grid;
  gap: 0.5rem;
  transition: border-color var(--motion-base) ease, box-shadow var(--motion-base) ease;
}

.chat-window:hover {
  border-color: #2a3f57;
  box-shadow: 0 10px 20px rgba(2, 6, 23, 0.32);
}

.chat-window h3 {
  margin-bottom: 0;
}

.chat-messages {
  min-height: 220px;
  max-height: 300px;
  overflow: auto;
  display: grid;
  gap: 0.45rem;
  padding-right: 0.2rem;
}

.chat-bubble {
  max-width: 78%;
  border-radius: 12px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--stroke-1);
  line-height: 1.35;
  font-size: 0.9rem;
}

.chat-bubble.mine {
  margin-left: auto;
  background: rgba(21, 128, 61, 0.35);
  border-color: #22c55e;
}

.chat-bubble.theirs {
  margin-right: auto;
  background: rgba(15, 23, 42, 0.8);
}

.chat-meta {
  margin-top: 0.18rem;
  font-size: 0.73rem;
  color: var(--text-muted);
}

.chat-form {
  display: flex;
  gap: 0.45rem;
}

.chat-form input {
  flex: 1;
}

.route-driver-popup {
  min-width: 210px;
  max-width: 250px;
}

.route-driver-popup-name {
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.route-driver-popup-meta {
  color: var(--text-soft);
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  line-height: 1.35;
  word-break: break-word;
}

.route-driver-popup-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.45rem;
}

.route-action-btn {
  margin-top: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.leaflet-container {
  font: inherit;
}

.leaflet-popup.route-popup .leaflet-popup-content-wrapper {
  background: var(--surface-2);
  color: #e5e7eb;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-lg);
}

.leaflet-popup.route-popup .leaflet-popup-tip {
  background: var(--surface-2);
}

.leaflet-popup.route-popup .leaflet-popup-content {
  margin: 0.75rem;
}

.leaflet-popup.route-popup .leaflet-popup-close-button {
  color: var(--text-soft);
}

.leaflet-popup.route-popup .leaflet-popup-close-button:hover {
  color: #ffffff;
}

.driver-request-card {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 0.7rem;
  margin-top: 0.5rem;
}

.driver-request-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.us-map {
  width: 100%;
  height: 620px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 0.45rem;
  background: #020617;
}

@media (max-width: 1080px) {
  .explore-layout {
    grid-template-columns: minmax(300px, 0.92fr) minmax(0, 1.25fr);
  }

  .us-map {
    height: 520px;
  }
}

.status-available { color: #4ade80; }
.status-on-route { color: #f59e0b; }
.status-do-not-disturb { color: #f87171; }

.admin-users-list {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.45rem;
}

.admin-user-row {
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-md);
  padding: 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  background: var(--surface-2);
}

.danger-btn {
  background: var(--danger-strong);
  color: var(--danger-soft);
}

.toast-root {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2500;
  display: grid;
  gap: 0.55rem;
  width: min(360px, calc(100vw - 2rem));
}

.toast {
  border: 1px solid #334155;
  border-left-width: 4px;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  background: rgba(2, 6, 23, 0.95);
  color: #e2e8f0;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.45);
  transform: translateY(10px);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast-visible {
  transform: translateY(0);
  opacity: 1;
}

.toast-info {
  border-left-color: #38bdf8;
}

.toast-success {
  border-left-color: #22c55e;
}

.toast-error {
  border-left-color: #ef4444;
}

[data-reveal] {
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity var(--motion-slow) ease, transform var(--motion-slow) cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: calc(var(--reveal-order, 0) * 35ms);
}

body.motion-ready [data-reveal].in-view {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.error-banner {
  position: fixed;
  top: 0.7rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2550;
  border: 1px solid #ef4444;
  border-radius: var(--radius-sm);
  background: rgba(127, 29, 29, 0.95);
  color: #fee2e2;
  padding: 0.5rem 0.75rem;
  max-width: min(720px, calc(100vw - 1.4rem));
}

@keyframes pulseRipple {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 0.35;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
  }
}

@keyframes floatAmbient {
  0% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, 18px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

#openSignup {
  margin-top: 0.5rem;
}

@media (max-width: 800px) {
  .grid.two, .grid.three, .journey-grid {
    grid-template-columns: 1fr;
  }

  .explore-layout {
    grid-template-columns: 1fr;
  }

  #mainView:not([hidden]) {
    grid-template-columns: 1fr;
  }

  #mainHeaderSection,
  #mainStartCard,
  #exploreSection,
  #driverActionsSection,
  #driverRequestsSection,
  #reviewSection,
  #chatSection,
  #routeComposerCard,
  #notificationsSection,
  #activitySection,
  #historySection {
    grid-column: 1;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .explore-sidebar {
    max-height: none;
  }

  .us-map {
    height: 360px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-user-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .toast-root {
    left: 1rem;
    right: 1rem;
    width: auto;
  }
}

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

  [data-reveal] {
    opacity: 1;
    transform: none;
  }
}
