* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 0.6rem 1rem;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.header h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }
.link-driver { font-size: 0.85rem; color: #93c5fd; text-decoration: none; }
.link-driver:hover { text-decoration: underline; }
.badge { font-size: 0.75rem; padding: 0.2rem 0.5rem; border-radius: 4px; }
.badge-live { background: #166534; color: #86efac; }
.badge-waiting { color: #94a3b8; }
.badge-connected { color: #22c55e; }

.live-panel {
  padding: 0.75rem 1rem;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}
.panel-title {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem 1rem;
}
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat-label { font-size: 0.7rem; color: #64748b; }
.stat-value { font-size: 0.95rem; font-variant-numeric: tabular-nums; }

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 1fr;
  min-height: 0;
}
.map {
  min-height: 300px;
  background: #1e293b;
}
.leaflet-container { background: #1e293b; font: inherit; }
.leaflet-control-zoom a { background: #1e293b !important; color: #e2e8f0; }
.live-marker { background: #22c55e; border-radius: 50%; cursor: pointer; }
.leaflet-popup-content .live-click-popup { font-size: 0.85rem; line-height: 1.4; min-width: 140px; }

.sidebar {
  overflow-y: auto;
  padding: 0.75rem;
  background: #1e293b;
  border-left: 1px solid #334155;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.settings-section { flex-shrink: 0; }
.settings-content { margin-top: 0.25rem; }
.settings-hint { font-size: 0.7rem; color: #64748b; margin: 0 0 0.5rem; }
.toggler { cursor: pointer; user-select: none; }
.settings-content.collapsed { display: none; }
.speed-level-row { display: flex; gap: 0.35rem; align-items: center; margin-bottom: 0.35rem; font-size: 0.8rem; }
.speed-level-row input[type="number"] { width: 4rem; padding: 0.25rem; background: #334155; border: 1px solid #475569; color: #e2e8f0; border-radius: 4px; }
.speed-level-row input[type="text"] { width: 5rem; padding: 0.25rem; background: #334155; border: 1px solid #475569; color: #e2e8f0; border-radius: 4px; }
.speed-level-row input[type="color"] { width: 2rem; height: 1.5rem; padding: 0; border: none; cursor: pointer; }
.speed-level-row .btn-remove-level { padding: 0.2rem 0.4rem; font-size: 0.75rem; background: #450a0a; color: #fecaca; border: none; border-radius: 4px; cursor: pointer; }
.speed-level-row .btn-remove-level:hover { background: #7f1d1d; }
.btn-add-level, .btn-save-settings { padding: 0.35rem 0.6rem; font-size: 0.75rem; margin-right: 0.5rem; margin-top: 0.35rem; border-radius: 4px; cursor: pointer; border: none; }
.btn-add-level { background: #334155; color: #e2e8f0; }
.btn-save-settings { background: #22c55e; color: #fff; }

.trip-detail-panel { flex-shrink: 0; }
.trip-name-row { margin-bottom: 0.5rem; }
.trip-name-label { display: block; font-size: 0.7rem; color: #64748b; margin-bottom: 0.2rem; }
.trip-name-input { width: 100%; padding: 0.4rem; font-size: 0.9rem; background: #334155; border: 1px solid #475569; color: #e2e8f0; border-radius: 4px; box-sizing: border-box; }
.trip-detail-content { font-size: 0.9rem; margin-bottom: 0.5rem; }
.trip-detail-content .stat { margin-bottom: 0.35rem; }
.trip-detail-content .stat-value.warn { color: #eab308; }
.trip-detail-content .stat-value.critical { color: #ef4444; }
.trip-detail-content .stat-value.rep-good { color: #22c55e; }
.trip-detail-content .stat-value.rep-bad { color: #ef4444; }
.trip-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-clear, .btn-delete {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.btn-clear { background: #334155; color: #e2e8f0; }
.btn-clear:hover { background: #475569; }
.btn-delete { background: #7f1d1d; color: #fecaca; }
.btn-delete:hover { background: #991b1b; }

.points-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.points-table-wrap { overflow: auto; flex: 1; min-height: 120px; font-size: 0.75rem; }
.points-table { width: 100%; border-collapse: collapse; }
.points-table th, .points-table td { padding: 0.25rem 0.3rem; text-align: left; border-bottom: 1px solid #334155; }
.points-table th { color: #94a3b8; font-weight: 600; position: sticky; top: 0; background: #1e293b; }
.points-table tbody tr { cursor: pointer; }
.points-table tbody tr:hover { background: #334155; }
.points-table tbody tr.selected { background: #1e3a5f; }
.points-table .speed-warn { color: #eab308; }
.points-table .speed-critical { color: #ef4444; }

.trips-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.trips-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}
.trip-count { font-size: 0.75rem; color: #64748b; }
.btn-refresh {
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  background: transparent;
  color: #94a3b8;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}
.btn-refresh:hover { background: #334155; color: #e2e8f0; }

.trips-table-wrap { overflow: auto; flex: 1; min-height: 0; }
.trips-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.trips-table th,
.trips-table td { padding: 0.4rem 0.35rem; text-align: left; border-bottom: 1px solid #334155; }
.trips-table th { color: #94a3b8; font-weight: 600; }
.trips-table tbody tr { cursor: pointer; }
.trips-table tbody tr:hover { background: #334155; }
.trips-table tbody tr.selected { background: #1e3a5f; }
.trips-table .btn-view, .trips-table .btn-del {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.trips-table .btn-view:hover { background: #2563eb; }
.trips-table .btn-del { background: #450a0a; margin-left: 0.25rem; }
.trips-table .btn-del:hover { background: #7f1d1d; }
.trips-table .trip-name-cell { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { max-height: 280px; }
  .live-grid { grid-template-columns: repeat(4, 1fr); }
}
