* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; height: 100vh; display: flex; overflow: hidden; }

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

#sidebar {
  width: 380px;
  min-width: 380px;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  border-right: 1px solid #dee2e6;
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 14px;
  background: rgb(0, 128, 123);
  border-bottom: 3px solid #004d4a;
  font-size: 0.85em;
  color: #fff;
}

#fleet-title { font-size: 1em; font-weight: 800; color: #fff; letter-spacing: 0.3px; }
#last-refreshed { color: #eaf7f6; font-weight: 700; }

#summary-strip {
  display: flex;
  padding: 8px 12px;
  gap: 4px;
  border-bottom: 3px solid #c4cbd3;
  background: #fff;
}

.sum-stat { flex: 1; text-align: center; }
.sv { display: block; font-size: 1.1em; font-weight: 700; color: #212529; }
.sl { display: block; font-size: 10px; color: #6c757d; }

#truck-list { flex: 1; overflow-y: auto; background: #eef1f4; }

.truck-card {
  margin: 7px 8px;
  padding: 8px 9px 7px;
  border: 2px solid rgba(0, 128, 123, 0.38);
  border-left: 15px solid rgb(0, 128, 123);
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 77, 74, 0.08);
}

.truck-card:hover { background: #f1f3f5; }

.truck-card.status-driving { border-left-color: #006b3f; }
.truck-card.status-stopped-long { border-left-color: #7a5a00; }
.truck-card.status-stopped-recent { border-left-color: #6c757d; }

.truck-card.map-hidden {
  background: #f8f9fa;
  border-color: #ced4da;
  border-left-color: #adb5bd;
  box-shadow: none;
}

.truck-card.map-hidden .tc-id {
  background: #6c757d;
  box-shadow: none;
}

.truck-card.map-hidden .tc-metrics,
.truck-card.map-hidden .tc-chips,
.truck-card.map-hidden .tc-loads {
  opacity: 0.58;
}

.truck-card.active {
  background: #d8f3f1;
  border-color: rgb(0, 128, 123);
  box-shadow: inset 0 0 0 2px rgba(0, 128, 123, 0.22), 0 2px 8px rgba(0, 77, 74, 0.18);
}

.tc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 3px;
}

.tc-identity {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}

.tc-id {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 20px;
  padding: 3px 8px;
  border-radius: 5px;
  background: #004d4a;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 77, 74, 0.28);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1;
}

.truck-card.active .tc-id { background: rgb(0, 128, 123); }

.tc-driver-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 118px;
  min-height: 20px;
  padding: 3px 7px;
  border: 1px solid rgba(0, 128, 123, 0.22);
  border-radius: 999px;
  background: #eef7f6;
  color: #004d4a;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-driver-chip,
a.tc-driver-chip {
  text-decoration: none;
}

a.tc-driver-chip { cursor: pointer; }
.tc-driver-chip i { flex: 0 0 auto; font-size: 9px; }

.tc-header-right {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 0;
}

.tc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 20px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.tc-badge i { font-size: 8px; line-height: 1; }
.tc-badge .status-sep { opacity: 0.72; }
.tc-badge.status-driving {
  background: #006b3f;
  color: #fff;
}
.tc-badge.status-stopped-long {
  background: #7a5a00;
  color: #ffe08a;
}
.tc-badge.status-stopped-recent {
  background: #e2e3e5;
  color: #383d41;
}

.tc-alert-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffec99;
}

.badge-driving { background: #d4edda; color: #155724; }
.badge-stopped { background: #e2e3e5; color: #383d41; }

.tc-location-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin: -1px 0 4px;
  color: #495057;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
}

.tc-location-line i {
  flex: 0 0 auto;
  color: rgb(0, 128, 123);
  font-size: 9px;
}

.tc-location-line span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.tc-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  margin-bottom: 4px;
}

.tc-metric { text-align: center; min-width: 0; }
.tc-metric .mv { font-size: 12px; font-weight: 700; color: #212529; overflow-wrap: anywhere; }
.tc-metric .ml { font-size: 10px; color: #6c757d; line-height: 1.05; }

.tc-fuel-link,
.fuel-box-link,
.chip-fuel-left {
  color: inherit;
  text-decoration: none;
}

.tc-fuel-link { display: block; border-radius: 6px; }
.tc-fuel-link:hover,
.fuel-box-link:hover,
.chip-fuel-left:hover { filter: brightness(0.96); }

.tc-fuel-metric,
.fuel-mini-box {
  display: flex;
  align-items: center;
  justify-content: center;
}

.fuel-display {
  display: inline-grid;
  grid-template-columns: 9px minmax(0, auto);
  grid-template-rows: auto auto;
  align-items: center;
  justify-content: center;
  column-gap: 6px;
  color: #212529;
  min-height: 22px;
}

.fuel-battery {
  position: relative;
  grid-row: 1 / span 2;
  display: flex;
  align-items: flex-end;
  width: 9px;
  height: 20px;
  padding: 1px;
  border: 1px solid currentColor;
  border-radius: 2px;
  color: #198754;
  background: #fff;
}

.fuel-battery::after {
  content: '';
  position: absolute;
  top: -3px;
  left: 2px;
  width: 3px;
  height: 2px;
  border-radius: 1px 1px 0 0;
  background: currentColor;
}

.fuel-battery-fill {
  display: block;
  width: 100%;
  min-height: 1px;
  border-radius: 1px;
  background: #198754;
}

.fuel-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.05;
}

.fuel-text { font-weight: 800; font-size: 12px; }
.fuel-label { font-size: 10px; color: #6c757d; white-space: nowrap; }

.fuel-display.fuel-low,
.fuel-display.fuel-low .fuel-label,
.fuel-low-box,
.fuel-critical,
.fuel-critical-box,
.fuel-critical-chip { color: #dc3545; }

.fuel-display.fuel-low .fuel-battery,
.fuel-low-box .fuel-battery { color: #dc3545; }

.fuel-display.fuel-low .fuel-battery-fill,
.fuel-low-box .fuel-battery-fill { background: #dc3545; }

.fuel-mini-box,
.est-fuel-box { text-decoration: none; }
.est-fuel-box .fa-gas-pump { font-size: 12px; margin-left: 3px; }

.tc-chips {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.tc-chips .chip { flex: 0 0 auto; min-width: 0; }
.truck-card .tc-chips .chip-trip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 1 auto !important;
  max-width: 49%;
}

.trip-drive {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.drive-wheel-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}

.tc-chips .chip-arrival,
.tc-chips .chip-trip,
.tc-chips .chip-fuel-left { font-weight: 800; }
.truck-card .tc-chips .chip-dest {
  flex: 0 1 auto !important;
  max-width: 38%;
  width: auto;
  text-overflow: ellipsis;
  overflow: hidden;
}

.chip {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  background: #e9ecef;
  color: #495057;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-warn { background: #fff3cd; color: #856404; }
.chip-danger { background: #f8d7da; color: #721c24; }
.chip-info,
.chip-dest,
.chip-fuel-left:not(.chip-danger) { background: #d1ecf1; color: #0c5460; }
.chip-fuel-left .fa-gas-pump,
.chip-arrival .fa-clock { margin-right: 3px; }
.fuel-critical-chip { background: #f8d7da; border: 1px solid #f1aeb5; }

.tc-loads { display: grid; gap: 3px; }

.tc-load {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  background: #fbfcfd;
}

.compact-load {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px;
  align-items: center;
  min-height: 20px;
  padding: 2px 5px;
  border-color: rgba(0, 128, 123, 0.22);
  border-radius: 4px;
  background: #fff;
}

.tc-load-main { min-width: 0; }
.compact-load-main { display: flex; align-items: center; gap: 4px; min-width: 0; }

.load-kind-icon {
  flex: 0 0 auto;
  color: rgb(0, 128, 123);
  font-size: 9px;
  line-height: 1;
}

.next-load .load-kind-icon { color: #6c757d; }

.load-kind {
  display: block;
  font-size: 9px;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 2px;
}

.load-route {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #212529;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-load .load-route {
  min-width: 0;
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.load-actions { display: flex; gap: 4px; }
.compact-load-actions { gap: 2px; }

.load-actions button,
.detail-actions button,
#detail-dest-set {
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #007bff;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 7px;
}

.compact-load-actions button {
  width: 17px;
  height: 17px;
  padding: 0;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  line-height: 1;
}

.load-actions button:nth-child(2),
.detail-actions button:nth-child(2) { background: #20c997; }

.compact-load-actions .load-home-btn,
.detail-actions .load-home-btn {
  background: rgb(0, 128, 123);
}

.compact-load-actions .load-home-btn:disabled,
.detail-actions .load-home-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#sidebar-footer {
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #dee2e6;
  background: #fff;
  font-size: 12px;
}

#refreshSelect {
  height: 32px;
  min-width: 130px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  color: #243039;
  background: #fff;
}

#auth-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

#signed-in-email {
  min-width: 0;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #495057;
  font-size: 11px;
  font-weight: 800;
}

#signout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #004d4a;
  border-radius: 6px;
  background: #004d4a;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 2px 5px rgba(0, 77, 74, 0.2);
}

#signout-btn:hover {
  background: rgb(0, 128, 123);
  border-color: rgb(0, 128, 123);
}

#signout-btn:active { transform: translateY(1px); }

#map-wrap { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

#refresh-alert {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  background: #dc3545;
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: 13px;
}

.map-truck-icon { background: transparent; border: 0; }
.map-truck-marker { position: relative; width: 38px; height: 38px; }

.map-truck-marker.driving .map-truck-arrow-shape {
  position: absolute;
  inset: 2px 5px;
  background: #198754;
  clip-path: polygon(50% 0%, 88% 68%, 62% 61%, 62% 100%, 38% 100%, 38% 61%, 12% 68%);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.32));
  transform-origin: 50% 50%;
}

.map-truck-marker.stopped {
  border-radius: 50%;
  background: #ffc107;
  border: 3px solid #fff;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.32);
}

.map-truck-stop-square {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #fff;
  transform: translate(-50%, -50%);
}

.map-truck-num {
  position: absolute;
  left: 50%;
  top: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #fff;
  color: #004d4a;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
}

.map-truck-marker.stopped .map-truck-num { color: #5f4300; }
.map-truck-marker.selected .map-truck-num {
  border-color: #111827;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92), 0 2px 6px rgba(0, 0, 0, 0.36);
}

#detail-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1001;
  width: 360px;
  max-height: calc(100% - 20px);
  background: #fff;
  border-radius: 8px;
  border: 1px solid #dee2e6;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

#detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  color: #fff;
}

#detail-title {
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

#detail-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #fff;
  font-weight: 700;
}

#detail-body { padding: 12px 14px; font-size: 13px; }

.detail-section { margin-bottom: 14px; }
.detail-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  border-bottom: none;
  padding: 6px 8px;
  border-radius: 4px;
  background: #e8f0fe;
  color: #0b5ed7;
  border-left: 4px solid #0b5ed7;
}

.detail-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.detail-row .dk { color: #6c757d; flex: 0 0 auto; }
.detail-row .dv { font-weight: 600; text-align: right; max-width: 210px; overflow-wrap: anywhere; }
.detail-row a { color: #007bff; text-decoration: none; }

.detail-input-row { display: flex; gap: 6px; margin-bottom: 6px; }
.detail-input-row input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #ced4da;
  border-radius: 4px;
}
.detail-note { font-size: 11px; color: #6c757d; padding-top: 3px; }

.condition-box {
  border: 2px solid #198754;
  background: #f0fff6;
  box-shadow: 0 2px 8px rgba(25, 135, 84, 0.15);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}

.condition-box .detail-section:last-child,
.route-box .detail-section:last-child,
.loads-box .detail-section { margin-bottom: 0; }

.condition-box .detail-section h4 {
  background: #d1e7dd;
  color: #0f5132;
  border-left: 4px solid #198754;
}

.condition-box .detail-row .dv {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  max-width: 230px;
}

.route-box {
  border: 2px solid #ffc107;
  background: #fffdf2;
  box-shadow: 0 2px 8px rgba(255, 193, 7, 0.18);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}

.route-box .detail-section h4,
.route-box .eta-header {
  background: #fff3cd;
  color: #664d03;
  border-left: 4px solid #ffc107;
}

.eta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gmaps-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  vertical-align: middle;
  font-size: 16px;
  text-decoration: none;
  color: #664d03;
}

.condition-box .gmaps-link { color: #0f5132; flex: 0 0 auto; }

.eta-line,
.status-grid {
  display: grid;
  gap: 6px;
}

.eta-line { grid-template-columns: repeat(3, 1fr); }
.eta-line-four,
.status-grid { grid-template-columns: repeat(4, 1fr); }

.mini-box {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 6px;
  text-align: center;
  min-width: 0;
}

.condition-box .mini-box { border-color: #badbcc; background: #ffffff; }
.route-box .mini-box { border-color: #ffecb5; background: #ffffff; }

.mini-box .mini-value {
  display: block;
  font-weight: 700;
  font-size: 12px;
  color: #212529;
  overflow-wrap: anywhere;
}

.mini-box .mini-label { display: block; font-size: 10px; color: #6c757d; }
.fuel-mini-link { display: inline-block; margin-left: 4px; text-decoration: none; font-size: 13px; }

.loads-box {
  border: 2px solid #495057;
  background: #f8f9fa;
  box-shadow: 0 2px 8px rgba(33, 37, 41, 0.12);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}

.loads-box .detail-section h4 {
  background: #e9ecef;
  color: #212529;
  border-left: 4px solid #495057;
}

.load-detail {
  border: 1px solid #adb5bd;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(33, 37, 41, 0.08);
}

.load-detail:last-child { margin-bottom: 0; }
.load-detail-head { display: grid; gap: 2px; margin-bottom: 6px; border-bottom: 1px solid #e9ecef; padding-bottom: 6px; }
.load-detail-head span { color: #343a40; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; font-weight: 800; }
.load-detail-head strong { font-size: 12px; color: #111827; }
.loads-box .detail-row { border-bottom: 1px solid #f1f3f5; }
.loads-box .detail-actions button { background: #343a40; }
.loads-box .detail-actions button:nth-child(2) { background: #6c757d; }
.detail-actions { display: flex; gap: 6px; margin-top: 8px; }
.detail-actions button { flex: 1; padding: 6px 8px; }

.fault-row { padding: 3px 0; border-bottom: 1px solid #f1f1f1; font-size: 12px; }
.fault-row .fc { color: #6c757d; font-size: 10px; }
.stop-row { padding: 4px 0; border-bottom: 1px solid #f1f1f1; font-size: 12px; }
.stop-row .sa { color: #212529; font-weight: 500; }
.stop-row .sm { color: #6c757d; font-size: 11px; }

.tc-identity {
  flex-wrap: wrap !important;
  align-items: center !important;
}

.tc-location-chip {
  display: flex !important;
  flex: 1 0 100% !important;
  max-width: 100% !important;
  min-height: 12px !important;
  padding: 0 0 0 2px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #495057 !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  line-height: 1.1 !important;
  justify-content: flex-start !important;
  gap: 4px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
}

.tc-location-chip i {
  flex: 0 0 auto;
  color: rgb(0, 128, 123) !important;
  font-size: 9px !important;
}

.tc-location-chip span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 767px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; min-width: unset; height: 48%; }
  #map-wrap { height: 52%; }
  #detail-panel { top: unset; bottom: 10px; right: 5px; left: 5px; width: auto; max-height: 62%; }
  .eta-line-four,
  .status-grid { grid-template-columns: repeat(2, 1fr); }
}
