html, body, #map { 
  height: 100%; 
  margin: 0; 
}

body { 
  font-family: 'Quicksand', 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif; 
}

.status-bar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(32, 32, 32, 0.85);
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 1000;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2ecc71; /* green by default */
}

.status-bar.error .status-dot { 
  background: #e74c3c; /* red on error */
}

.status-bar.stale .status-dot { 
  background: #f1c40f; /* yellow on stale */
}

/* DivIcon styling for a circle with a tiny bearing arrow (CSS transform) */
.bus-marker {
  position: relative;
  width: 16px;
  height: 16px;
  background: #1976d2;           /* blue circle */
  border: 2px solid white;       /* white edge for contrast */
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}

.bus-marker .bearing-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 10px;
  background: #111;
  transform-origin: 50% 90%;
  border-radius: 1px;
  /* default rotation is 0; we set inline style transform to rotate(deg) at runtime */
}

.bus-marker .bearing-tip {
  position: absolute;
  left: 50%;
  top: 2px;
  width: 0;
  height: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 5px solid #111;
  transform: translateX(-50%);
}

/* Popup table */
.popup-table {
  border-collapse: collapse;
  font-size: 12px;
}

.popup-table td {
  padding: 2px 4px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

.popup-table td:first-child {
  color: #555;
  white-space: nowrap;
}

.vehicle-count {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(32, 32, 32, 0.82);
  color: #fff;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 500;
  pointer-events: none;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ── Filter panel ───────────────────────────────────────────────── */
#filterPanel {
  display: block;
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 10px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
  padding: 12px 14px 14px;
  z-index: 1001;
  font-size: 18px;
  font-family: inherit;
  width:350px;
  min-width: 230px;
  max-width: 290px;
}
#filterPanel.open { display: block; /* already block by default */ }

.filter-title {
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 10px;
}

.filter-section { margin-bottom: 10px; }

.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.filter-row label {
  font-weight: 600;
}

.filter-select-all {
  font-size: 15px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #bbb;
  background: #f5f5f5;
  cursor: pointer;
  font-family: inherit;
}
.filter-select-all:hover { background: #e0e0e0; }

select.filter-select {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 3px 4px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  box-sizing: border-box;
}

.filter-apply {
  width: 100%;
  margin-top: 4px;
  padding: 7px 0;
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.filter-apply:hover { background: #1565c0; }

/* ── RT Data Recorder panel ─────────────────────────────────────── */
#recorderPanel {
  position: absolute;
  bottom: 48px;
  left: 12px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 10px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
  padding: 12px 14px 14px;
  z-index: 1001;
  font-size: 12px;
  font-family: inherit;
  width: 700px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
}

.recorder-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
}

.recorder-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.recorder-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #f5f5f5;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
}

.recorder-btn:hover:not(:disabled) {
  background: #e0e0e0;
}

.recorder-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#startRecordBtn {
  background: #2ecc71;
  color: white;
  border-color: #27ae60;
}

#startRecordBtn:hover:not(:disabled) {
  background: #27ae60;
}

#stopRecordBtn {
  background: #e74c3c;
  color: white;
  border-color: #c0392b;
}

#stopRecordBtn:hover:not(:disabled) {
  background: #c0392b;
}

.recorder-status {
  font-size: 11px;
  color: #666;
  margin-bottom: 10px;
  padding: 4px 8px;
  background: #f0f0f0;
  border-radius: 4px;
}

.recorder-content {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.recorder-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.recorder-details {
  flex: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.recorder-list-title,
.recorder-details-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.trip-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px;
  background: #fafafa;
  min-height: 0;
}

.trip-item {
  padding: 6px 8px;
  margin-bottom: 2px;
  background: white;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  border: 1px solid transparent;
}

.trip-item:hover {
  background: #e3f2fd;
}

.trip-item.selected {
  background: #1976d2;
  color: white;
  border-color: #1565c0;
}

.trip-details {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  background: #fafafa;
  font-size: 11px;
  min-height: 0;
}

.trip-details-empty {
  color: #999;
  text-align: center;
  padding: 20px;
}

.stop-record {
  padding: 4px 0;
  border-bottom: 1px solid #eee;
}

.stop-record:last-child {
  border-bottom: none;
}

/* Hide recorder panel when hidden class is applied */
#recorderPanel.hidden {
  display: none;
}

/* Agency Selector Row (within filter panel) */
.agency-selector-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.agency-btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 6px;
  font-size: 26px;
  font-weight: 900;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.agency-ttc {
  background: #f5f5f5;
  color: #c41e3a;
  border: 2px solid #c41e3a;
}

.agency-ttc:hover:not(.active) {
  background: #fee;
}

.agency-ttc.active {
  background: #c41e3a;
  color: white;
  box-shadow: 0 3px 8px rgba(196, 30, 58, 0.25);
}

.agency-translink {
  background: #f5f5f5;
  color: #0066cc;
  border: 2px solid #0066cc;
}

.agency-translink:hover:not(.active) {
  background: #eef;
}

.agency-translink.active {
  background: #0066cc;
  color: white;
  box-shadow: 0 3px 8px rgba(0, 102, 204, 0.25);
}

/* View Recordings button */
.view-recordings-btn {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(67, 160, 71, 0.9);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 24px;
  width: 325px;
  font-size: 25px;
  font-weight: 600;
  cursor: pointer;
  z-index: 500;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.2s;
}

.view-recordings-btn:hover {
  background: rgba(56, 142, 60, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
}

/* Close button for recorder panel */
.close-recorder-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 18px;
  color: #666;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.close-recorder-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  #recorderPanel {
    left: 8px;
    right: 8px;
    bottom: 56px;
    width: auto;
    max-height: 60vh;
    padding: 10px 12px 12px;
    font-size: 11px;
  }
  
  .recorder-title {
    font-size: 12px;
    padding-right: 30px; /* Make room for close button */
  }
  
  .recorder-controls {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .recorder-btn {
    font-size: 10px;
    padding: 5px 10px;
  }
  
  .recorder-content {
    flex-direction: column;
    gap: 10px;
  }
  
  .recorder-list,
  .recorder-details {
    flex: none;
    min-height: 120px;
  }
  
  .trip-item {
    font-size: 10px;
    padding: 5px 6px;
  }
  
  .trip-details {
    font-size: 10px;
  }
  
  .toggle-recorder-btn {
    bottom: 8px;
    left: 8px;
    font-size: 11px;
    padding: 5px 10px;
  }

  .vehicle-count {
    bottom: 8px;
    right: 8px;
    font-size: 11px;
  }
}
