:root {
  --primary: #0057b8;
  --primary-dark: #003f86;
  --accent: #ffd500;
  --accent2:#0057b8;
  --bg: #f4f7fb;
  --panel: rgba(255, 255, 255, 0.96);
  --text: #172033;
  --muted: #667085;
  --border: #d9e2ef;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  width: 100%;
  min-height: 100%;
}

.sidebar {
  width: 390px;
  max-width: 94vw;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  z-index: 1000;
  overflow-y: auto;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
  margin-bottom: 18px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 25px;
  box-shadow: 0 10px 25px rgba(0, 87, 184, 0.28);
}

h1 {
  font-size: 19px;
  line-height: 1.2;
  margin: 0 0 5px;
  color: var(--primary-dark);
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 11px;
  margin-bottom: 18px;
}

.stats div {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 13px 10px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.stats span {
  display: block;
  font-size: 23px;
  font-weight: 850;
  color: var(--primary-dark);
}

.stats small {
  color: var(--muted);
  font-size: 12px;
}

.field-label,
.panel-title {
  display: block;
  font-weight: 800;
  font-size: 14px;
  margin: 15px 0 8px;
  color: var(--text);
}

select {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 15px;
  background: white;
  color: var(--text);
  font-weight: 650;
  outline: none;
}

select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0, 87, 184, 0.12);
}

.online-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 0 4px;
  padding: 11px 13px;
  border-radius: 15px;
  background: #ffffff;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 800;
  color: var(--primary-dark);
  cursor: pointer;
  user-select: none;
}

.online-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.route-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.route-buttons button {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--primary-dark);
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
  transition: 0.18s ease;
}

.route-buttons button:hover {
  transform: translateY(-1px);
  background: #eef5ff;
  border-color: #b8d4f5;
}

.route-buttons button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(0, 87, 184, 0.22);
}

.bus-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.bus-card {
  padding: 13px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 17px;
  cursor: pointer;
  transition: 0.18s ease;
  box-shadow: 0 7px 18px rgba(15, 23, 42, 0.05);
}

.bus-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.11);
}

.bus-card strong {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  font-size: 15px;
  color: var(--text);
}

.bus-card span {
  color: var(--muted);
  font-size: 13px;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.11);
}

.dot.online {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.13);
}

.footer-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
}

.status {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 1000;
  background: rgba(23, 32, 51, 0.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.25);
  backdrop-filter: blur(10px);
}

.bus-marker-wrapper {
  position: relative;
  width: 64px;
  height: 64px;
}

.direction-ring {
  position: absolute;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  transform-origin: 50% 50%;
  transition: transform 0.35s ease;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.direction-circle {
  fill: none;
  stroke: var(--accent2);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.95;
}

.direction-head {
  fill: var(--accent2);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
}

.bus-marker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 42px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  border: 3px solid #fff;
  box-shadow: 0 8px 18px rgba(0, 87, 184, 0.35);
  z-index: 2;
}

.marker-status-dot {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid #fff;
  z-index: 3;
}

.bus-marker-wrapper.online .marker-status-dot {
  background: var(--success);
}

.bus-marker-wrapper.offline .bus-marker {
  filter: grayscale(0.35);
  opacity: 0.82;
}

.leaflet-popup-content-wrapper {
  border-radius: 16px;
}

.leaflet-popup-content {
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
}

@media (max-width: 900px) {
  .sidebar {
    width: 340px;
    padding: 16px;
  }

  .stats {
    gap: 8px;
  }

  .stats span {
    font-size: 20px;
  }
}

@media (max-width: 760px) {
  #app {
    flex-direction: column;
    height: 100dvh;
  }

  .sidebar {
    width: 100%;
    max-width: 100%;
    height: 44dvh;
    min-height: 300px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
  }

  .map-wrap {
    height: 56dvh;
    min-height: 360px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .logo {
    width: 44px;
    height: 44px;
    border-radius: 15px;
    font-size: 21px;
  }

  h1 {
    font-size: 16px;
  }

  p {
    font-size: 12px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 12px;
  }

  .stats div {
    padding: 10px 8px;
    border-radius: 14px;
  }

  .stats span {
    font-size: 19px;
  }

  .stats small {
    font-size: 11px;
  }

  .field-label,
  .panel-title {
    margin: 11px 0 7px;
    font-size: 13px;
  }

  select {
    padding: 10px 11px;
    font-size: 14px;
  }

  .online-toggle {
    padding: 9px 11px;
    font-size: 13px;
  }

  .route-buttons {
    gap: 7px;
    margin: 10px 0;
  }

  .route-buttons button {
    padding: 8px 11px;
    font-size: 13px;
  }

  .bus-list {
    gap: 7px;
  }

  .bus-card {
    padding: 10px 11px;
    border-radius: 14px;
  }

  .bus-card strong {
    font-size: 14px;
  }

  .bus-card span {
    font-size: 12px;
  }

  .status {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    text-align: center;
    font-size: 12px;
    padding: 9px 12px;
  }

  .leaflet-control-zoom {
    margin-top: 12px !important;
    margin-right: 12px !important;
  }
}

@media (max-width: 420px) {
  .sidebar {
    height: 46dvh;
    min-height: 290px;
    padding: 12px;
  }

  .map-wrap {
    height: 54dvh;
    min-height: 330px;
  }

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

  .stats div {
    padding: 9px 6px;
  }

  .stats span {
    font-size: 17px;
  }

  .stats small {
    font-size: 10px;
  }

  .route-buttons button {
    padding: 7px 10px;
    font-size: 12px;
  }
}

.leaflet-popup-content-wrapper {
  border-radius: 22px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.22);
}

.leaflet-popup-content {
  margin: 0;
  width: 285px !important;
  font-family: Inter, system-ui, sans-serif;
}

.leaflet-popup-tip {
  background: #ffffff;
}

.pastrans-popup {
  background: #ffffff;
  color: var(--text);
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 15px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
}

.popup-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.32);
  font-size: 22px;
}

.popup-title {
  font-size: 16px;
  font-weight: 850;
  line-height: 1.1;
}

.popup-subtitle {
  margin-top: 3px;
  font-size: 12px;
  opacity: 0.86;
}

.popup-route {
  padding: 11px 15px;
  background: #fff7cc;
  color: #6b5400;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
  border-bottom: 1px solid #f3e5a0;
}

.popup-info {
  padding: 12px 15px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.popup-info div {
  min-width: 0;
}

.popup-info span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.popup-info strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  word-break: break-word;
}

.popup-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 15px 13px;
  font-size: 13px;
  font-weight: 800;
}

.popup-status span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.popup-status.online {
  color: var(--success);
}

.popup-status.online span {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.14);
}

.popup-status.offline {
  color: var(--danger);
}

.popup-status.offline span {
  background: var(--danger);
}

.leaflet-popup-close-button {
  width: 34px !important;
  height: 34px !important;

  top: 12px !important;
  right: 12px !important;

  border-radius: 50% !important;

  background: rgba(255,255,255,.15) !important;

  color: transparent !important;

  backdrop-filter: blur(10px);
}

.leaflet-popup-close-button::before {
  content: "✕";

  position: absolute;

  left: 50%;
  top: 50%;

  transform: translate(-50%, -50%);

  color: white;

  font-size: 14px;
  font-weight: 700;
}

.leaflet-popup-close-button:hover {
  background: rgba(255,255,255,.25) !important;
}

.map-modes {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 1000;

  display: flex;
  gap: 6px;

  padding: 7px;

  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 18px;

  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(14px);
}

.map-mode-btn {
  border: none;
  border-radius: 13px;
  padding: 9px 12px;
  background: transparent;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: 0.18s ease;
  white-space: nowrap;
}

.map-mode-btn:hover {
  background: #eef5ff;
}

.map-mode-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 6px 14px rgba(0, 87, 184, 0.22);
}

@media (max-width: 760px) {
  .map-modes {
    left: 10px;
    right: 10px;
    bottom: 58px;

    overflow-x: auto;
    justify-content: flex-start;

    padding: 6px;
    border-radius: 16px;
  }

  .map-mode-btn {
    flex: 0 0 auto;
    padding: 8px 10px;
    font-size: 12px;
  }
}

@media (max-width: 760px) {
  .status {
    bottom: 10px;
  }
}
