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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --accent: #4f8ef7;
  --accent-dark: #3a6fd8;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --text: #e8eaf0;
  --muted: #6b7280;
  --border: #2d3142;
  --nav-h: 56px;
  --tabs-h: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* NAV */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  gap: 0.5rem;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}
.nav-icon { font-size: 1.25rem; }
.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex-shrink: 0;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
}
.user-name {
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-btn {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: nowrap;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--text); }

/* TABS */
.tabs-bar {
  position: fixed;
  top: var(--nav-h);
  left: 0; right: 0;
  height: var(--tabs-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  z-index: 99;
  padding: 0 0.25rem;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
  position: relative;
  padding: 0 0.25rem;
  min-height: 44px;
}
.tab.active { color: var(--accent); }
.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 10%; right: 10%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}
.tab.hidden { display: none; }

/* MAIN */
.main {
  margin-top: calc(var(--nav-h) + var(--tabs-h));
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  min-height: calc(100dvh - var(--nav-h) - var(--tabs-h));
}

/* TAB CONTENT */
.tab-content { display: none; }
.tab-content.active { display: block; }

.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* TOURS GRID */
.tours-grid {
  display: grid;
  gap: 0.75rem;
}

.tour-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
  overflow: hidden;
  min-height: 44px;
}
.tour-card:active { transform: scale(0.98); }
.tour-card.has-reservation { border-color: var(--accent); }
.tour-card-accent {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}
.tour-card.has-reservation .tour-card-accent { opacity: 1; }

.tour-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
  gap: 0.5rem;
}
.tour-name {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tour-time {
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 7px;
  flex-shrink: 0;
}

.tour-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.seats-text {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.my-res-badge {
  font-size: 0.72rem;
  background: rgba(79,142,247,0.15);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,0.3);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
}

/* MAP */
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.map-tour-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  outline: none;
  flex-shrink: 0;
}
.map-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.status-dot.offline { background: var(--muted); }

#map {
  height: calc(100dvh - var(--nav-h) - var(--tabs-h) - 130px);
  min-height: 300px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
}

/* MESSAGES */
.messages-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  height: calc(100dvh - var(--nav-h) - var(--tabs-h) - 160px);
  min-height: 250px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  scroll-behavior: smooth;
}
.msg-empty {
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  margin: auto;
}
.msg-item {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  max-width: 85%;
}
.msg-item.mine {
  align-self: flex-end;
  background: rgba(79,142,247,0.2);
  border: 1px solid rgba(79,142,247,0.3);
}
.msg-sender {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.15rem;
}
.msg-text { font-size: 0.875rem; }
.msg-time { font-size: 0.65rem; color: var(--muted); margin-top: 0.2rem; }

.message-input-row {
  display: flex;
  gap: 0.5rem;
}
.msg-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.msg-input:focus { border-color: var(--accent); }
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  width: 46px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.send-btn:active { background: var(--accent-dark); }

/* DRIVER SPLIT LAYOUT */
.driver-split {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.driver-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.driver-panel-messages .messages-box {
  height: 240px;
  flex: none;
}

@media (min-width: 700px) {
  .driver-split {
    flex-direction: row;
    height: calc(100dvh - var(--nav-h) - var(--tabs-h) - 2rem);
  }
  .driver-panel-tours {
    flex: 1;
    overflow-y: auto;
  }
  .driver-panel-messages {
    flex: 1;
  }
  .driver-panel-messages .messages-box {
    flex: 1;
    height: auto;
  }
}

/* DRIVER PANEL */
.driver-tour-pick {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.driver-tour-pick label { font-size: 0.85rem; color: var(--muted); }

.driver-location-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.loc-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.loc-btn {
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.loc-btn:active { transform: scale(0.97); }
.loc-btn.start { background: var(--green); color: #fff; }
.loc-btn.stop { background: var(--red); color: #fff; }
.loc-btn.hidden { display: none; }

.passenger-stop {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.875rem 1rem;
  margin-bottom: 0.625rem;
}
.passenger-stop-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.passenger-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}
.passenger-row:last-child { border-bottom: none; }
.seat-badge {
  background: var(--surface2);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  min-width: 28px;
  text-align: center;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding-bottom: calc(1.5rem + var(--safe-bottom));
  animation: slideUp 0.25s cubic-bezier(0.16,1,0.3,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem 0.75rem;
  font-weight: 700;
  font-size: 1rem;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.modal-close {
  background: var(--surface2);
  border: none;
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.modal-body { padding: 1.25rem 1.5rem; }

/* BUS LAYOUT */
.bus-layout {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 16px;
  width: fit-content;
  margin: 0 auto 1.25rem;
}

.bus-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.bus-aisle {
  width: 18px;
  height: 40px;
  flex-shrink: 0;
  position: relative;
}
.bus-aisle::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  opacity: 0.5;
}

.bus-left-pair {
  display: flex;
  gap: 5px;
}

.seat-empty {
  width: 44px;
  height: 40px;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
}

/* SEAT */
.seat {
  width: 44px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  border: 2px solid transparent;
  user-select: none;
  -webkit-user-select: none;
}
.seat:active { transform: scale(0.92); }
.seat.driver {
  background: var(--surface);
  border-color: var(--muted);
  color: var(--muted);
  cursor: default;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
  text-align: center;
}
.seat.free { background: rgba(34,197,94,0.15); color: var(--green); border-color: rgba(34,197,94,0.3); }
.seat.mine { background: rgba(59,130,246,0.2); color: #60a5fa; border-color: rgba(59,130,246,0.5); }
.seat.taken { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.25); cursor: not-allowed; opacity: 0.6; }
.seat.free.selected { border-color: #fff; background: rgba(34,197,94,0.3); transform: scale(1.05); }

/* STOP SELECTOR */
.stop-selector {
  margin-bottom: 1rem;
}
.stop-selector.hidden { display: none; }
.stop-selector label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}
.stop-selector select {
  width: 100%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.625rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
  margin-bottom: 0.75rem;
}
.reserve-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.875rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.reserve-btn:active { transform: scale(0.98); background: var(--accent-dark); }
.reserve-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* MY RESERVATION */
.my-reservation.hidden { display: none; }
.my-res-info {
  background: rgba(79,142,247,0.1);
  border: 1px solid rgba(79,142,247,0.25);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
.cancel-btn {
  width: 100%;
  background: rgba(239,68,68,0.12);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 12px;
  padding: 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.cancel-btn:active { background: rgba(239,68,68,0.22); }

/* SEAT LEGEND */
.seat-legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}
.dot.green { background: var(--green); }
.dot.blue { background: var(--blue); }
.dot.red { background: var(--red); }
.dot.gray { background: var(--muted); }

/* PUSH NOTIFY BANNER */
.notify-banner {
  position: fixed;
  bottom: calc(0.75rem + var(--safe-bottom));
  left: 0.75rem; right: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  z-index: 150;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  animation: slideUp 0.3s cubic-bezier(0.16,1,0.3,1);
}
.notify-banner.hidden { display: none; }
.notify-banner span { flex: 1; }
.notify-banner button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#dismissNotify {
  background: transparent;
  color: var(--muted);
  padding: 0.35rem;
}

/* LEAFLET DARK */
.leaflet-container { background: #1a1d27; }
.leaflet-tile { filter: brightness(0.8) contrast(1.1) hue-rotate(180deg) invert(1); }
