/*
 * Redesign intent: use flush operational surfaces, asymmetric emphasis,
 * and distinct status/metric treatments instead of uniform generic cards.
 */
#status-bar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(190px, auto) 1fr auto auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: 6px var(--space-4);
  border-bottom: 0;
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.product { display: flex; align-items: center; gap: 12px; }
.product__copy { display: flex; flex-direction: column; }
.product__copy strong { font: 700 17px/1.15 var(--font-display); letter-spacing: -0.01em; }
.product__copy span { color: var(--text-secondary); font-size: 12px; }
#fleet-health { justify-self: end; }
#last-update { color: var(--text-secondary); font: 400 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.health-popover { position: relative; }
.health-summary { display: flex; min-height: 36px; align-items: center; gap: 8px; border: 0; border-radius: var(--radius-control); background: var(--surface-secondary); padding: 0 10px; color: var(--text-secondary); cursor: pointer; list-style: none; }
.health-summary::-webkit-details-marker { display: none; }
.health-summary strong { color: var(--text-primary); font-size: 13px; }
.health-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); }
.health-dot--degraded { background: var(--stale); }
.health-popover__panel { position: absolute; top: calc(100% + 8px); right: 0; z-index: var(--z-notice); width: 330px; border: 0; border-radius: var(--radius-panel); background: var(--surface-overlay); padding: var(--space-4); box-shadow: var(--shadow-overlay); }
.health-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding-bottom: var(--space-3); border-bottom: 1px solid var(--border); }
.health-stat { color: var(--text-secondary); font: 500 12px/1.4 var(--font-mono); }
.feed-health-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding-top: var(--space-3); font-size: 12px; }
.feed-health-list dt { color: var(--text-secondary); }
.feed-health-list dd { font-family: var(--font-mono); }
.feed-health--success { color: var(--live); }
.feed-health--error { color: var(--error); }
#refresh-button.is-refreshing svg { animation: refresh-spin 900ms linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.language-control select { min-height: 36px; border: 0; border-radius: var(--radius-control); background: var(--surface-secondary); padding: 0 8px; color: var(--accent-strong); font-weight: 700; }
#mobile-view-switch { overflow: hidden; min-width: 142px; border: 0; border-radius: var(--radius-control); background: var(--surface-secondary); }
#mobile-view-switch button { min-height: 36px; background: transparent; color: var(--text-primary); }
#mobile-view-switch button[aria-pressed='true'] { background: var(--accent); color: var(--surface-primary); }

#vehicle-explorer, #vehicle-detail { border-color: var(--border); background: var(--surface-primary); }
#vehicle-explorer { display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.explorer-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); border-bottom: 1px solid var(--border); background: var(--surface-primary); padding: var(--space-4); }
.search-control { position: relative; display: flex; align-items: center; }
.search-control > span { position: absolute; left: 12px; width: 18px; color: var(--text-dim); }
.search-control svg { width: 18px; }
#vehicle-search { width: 100%; min-height: var(--touch-target); border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-secondary); padding: 0 12px 0 38px; color: var(--text-primary); outline: 0; }
#vehicle-search::placeholder { color: var(--text-secondary); }
#vehicle-search:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: none; }
#filter-trigger { display: inline-flex; align-items: center; gap: 8px; }
#filter-trigger svg { width: 18px; }
#active-filter-chips { display: flex; grid-column: 1 / -1; flex-wrap: wrap; gap: 6px; }
.filter-chip { display: inline-flex; min-height: 30px; align-items: center; gap: 6px; border: 1px solid var(--action); border-radius: 999px; background: var(--action-soft); padding: 0 10px; color: var(--action); font-size: 12px; }
.explorer-summary { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--space-2); padding: 12px var(--space-4); border-bottom: 1px solid var(--border); }
.explorer-summary__label { color: var(--text-secondary); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
#vehicle-count { color: var(--text-secondary); font-family: var(--font-mono); font-size: 13px; }
.explorer-summary__actions { display: flex; grid-column: 1 / -1; gap: 12px; }
.explorer-summary__actions button { min-height: var(--touch-target); background: transparent; color: var(--accent); font-size: 12px; font-weight: 700; }
.explorer-summary__actions button:hover { color: var(--accent); }
#vehicle-list { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-color: var(--border-strong) transparent; }
.feed-group { border-bottom: 1px solid var(--border); }
.feed-group__bar, .operator-group__bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; background: var(--surface-secondary); }
.operator-group__bar { background: var(--surface-primary); }
.group-heading { display: grid; grid-template-columns: auto 1fr auto; width: 100%; min-height: var(--touch-target); align-items: center; gap: 8px; background: transparent; padding: 0 var(--space-3); color: var(--text-primary); text-align: left; }
.operator-heading { background: transparent; padding-left: var(--space-6); color: var(--text-primary); }
.group-heading__chevron { display: grid; width: 16px; place-items: center; transition: transform var(--motion-fast); }
.group-heading__chevron svg { width: 15px; height: 15px; }
.group-heading[aria-expanded='false'] .group-heading__chevron { transform: rotate(-90deg); }
.group-heading__count { color: var(--text-secondary); font-size: 12px; }
.visibility-toggle { display: grid; width: var(--touch-target); height: var(--touch-target); place-items: center; background: transparent; color: var(--text-secondary); }
.visibility-toggle:hover { color: var(--accent); }
.visibility-toggle svg { width: 18px; height: 18px; }
.vehicle-row-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; border-top: 1px solid var(--border); }
.vehicle-row { position: relative; display: grid; grid-template-columns: auto minmax(0,1fr) auto; width: 100%; min-height: 68px; align-items: center; gap: 10px; background: transparent; padding: 6px var(--space-3) 6px var(--space-6); color: var(--text-primary); text-align: left; }
.vehicle-visibility { align-self: stretch; height: auto; min-height: var(--touch-target); }
.vehicle-row::before { position: absolute; inset: 8px auto 8px 0; width: 3px; border-radius: 0 3px 3px 0; background: transparent; content: ''; }
.vehicle-row:hover { background: var(--surface-hover); }
.vehicle-row[aria-current='true'] { background: var(--accent-soft); }
.vehicle-row[aria-current='true']::before { background: var(--accent); }
.vehicle-row__identity { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.vehicle-row__line { width: fit-content; max-width: 100%; align-self: flex-start; overflow: hidden; border-radius: 999px; background: var(--accent); padding: 2px 9px; color: var(--surface-primary); font: 700 14px/1.4 var(--font-body); text-overflow: ellipsis; white-space: nowrap; }
.vehicle-row__destination { overflow: hidden; color: var(--text-primary); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.vehicle-row__meta, .vehicle-row__age { color: var(--text-secondary); font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.status-dot--live { background: var(--live); }
.status-dot--stale { background: var(--stale); }
.status-dot--inactive { background: var(--text-dim); }

#loading-state { display: grid; gap: 10px; padding: var(--space-4); }
#loading-state span { height: 44px; border-radius: var(--radius-control); background: linear-gradient(90deg, var(--surface-secondary), var(--accent-soft), var(--surface-secondary)); background-size: 200% 100%; animation: loading-shimmer 1.5s linear infinite; }
@keyframes loading-shimmer { to { background-position: -200% 0; } }
.empty-state, .failure-state { display: grid; place-items: center; gap: var(--space-3); padding: var(--space-8); color: var(--text-secondary); text-align: center; }
.empty-state__symbol, .failure-state__symbol { display: grid; width: 52px; height: 52px; place-items: center; border: 1px solid var(--border-strong); color: var(--accent); font: 600 26px/1 var(--font-display); transform: rotate(45deg); }
.empty-state__symbol { line-height: 0; }

#map-region { position: relative; z-index: var(--z-map); overflow: hidden; background: var(--surface-map); isolation: isolate; }
#map { position: absolute; inset: 0; z-index: var(--z-map); }
.leaflet-container { background: var(--surface-map); font-family: var(--font-body); }
.leaflet-tile-pane { filter: saturate(.82) brightness(1.03) contrast(.96); }
.leaflet-control-attribution { border: 1px solid var(--border); background: rgba(255,255,255,.92) !important; color: var(--text-secondary); }
.leaflet-control-attribution a { color: var(--accent); }
#map-controls { position: absolute; top: var(--space-3); right: var(--space-3); z-index: var(--z-map-controls); display: grid; gap: 6px; }
.map-button { border-color: transparent; background: var(--surface-primary); color: var(--accent); box-shadow: var(--shadow-sm); }
.notice { position: absolute; top: var(--space-3); left: 50%; z-index: var(--z-notice); max-width: min(620px, calc(100% - 32px)); transform: translateX(-50%); border: 0; border-left: 5px solid; border-radius: var(--radius-control); background: var(--surface-overlay); padding: 10px 14px; color: var(--text-primary); box-shadow: var(--shadow-sm); }
.notice--warning { border-left-color: var(--stale); }
.notice--error { border-left-color: var(--error); }
.failure-state { position: absolute; inset: 0; z-index: var(--z-notice); background: rgba(255,255,255,.94); color: var(--text-secondary); }

.vehicle-marker-host { background: transparent; border: 0; }
.vehicle-marker { position: relative; display: grid; width: 30px; height: 30px; place-items: center; color: var(--text-on-accent); transition: transform var(--motion-marker), opacity var(--motion-standard); }
.vehicle-marker__body { position: relative; z-index: 2; display: grid; width: 26px; height: 26px; place-items: center; border: 2px solid var(--text-on-accent); border-radius: 50%; background: var(--accent); color: var(--text-on-accent); box-shadow: 0 2px 8px rgba(0,0,0,.28), inset 0 -3px 0 var(--operator-color); }
.vehicle-marker__body svg { width: 16px; height: 16px; }
.vehicle-marker__status { position: absolute; right: 0; bottom: 0; z-index: 3; width: 8px; height: 8px; border: 2px solid var(--surface-primary); border-radius: 50%; background: var(--text-dim); }
.vehicle-marker.freshness-live .vehicle-marker__status { background: var(--live); }
.vehicle-marker.freshness-stale .vehicle-marker__status { background: var(--stale); }
.vehicle-marker.freshness-inactive { opacity: 0.45; }
.vehicle-marker.is-selected { transform: scale(1.12); }
.vehicle-marker.is-selected .vehicle-marker__body { box-shadow: 0 0 0 3px var(--surface-primary), 0 0 0 6px var(--accent), 0 4px 14px rgba(0,0,0,.30), inset 0 -3px 0 var(--operator-color); }
.vehicle-cluster { display: grid; place-items: center; border: 2px solid var(--surface-primary); border-radius: 50%; background: var(--accent-strong); color: var(--text-on-accent); font: 600 12px/1 var(--font-body); box-shadow: var(--shadow-sm); }
.vehicle-cluster--medium { transform: none; }
.vehicle-cluster--large { transform: none; }

#vehicle-detail { display: flex; flex-direction: column; gap: var(--space-4); overflow: auto; overscroll-behavior: contain; border-left: 1px solid var(--border); background: var(--surface-primary); padding: var(--space-4); }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
#detail-identity h2 { font: 600 24px/1.2 var(--font-display); }
#detail-direction { padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); color: var(--text-secondary); }
#detail-direction { display: grid; gap: 4px; }
.detail-progress { color: var(--live); font-size: 13px; }
#detail-metrics { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-2); }
.metric { min-height: 92px; border-left: 3px solid var(--border-strong); background: var(--surface-secondary); padding: var(--space-3); }
.metric:first-child { grid-row: span 2; min-height: 192px; border-left-color: var(--accent); }
.metric dt { color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; }
.metric dd { margin-top: 8px; font: 600 22px/1.2 var(--font-body); font-variant-numeric: tabular-nums; }
.metric--live { border-left-color: var(--live); }
.metric--stale { border-left-color: var(--stale); }
.metric--inactive { border-left-color: var(--text-dim); }
#bearing-display { color: var(--accent); font: 600 18px/1 var(--font-body); font-variant-numeric: tabular-nums; }
#detail-actions { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--space-2); }
#detail-follow { border: 1px solid var(--action); background: var(--action); color: var(--text-on-accent); }
#detail-follow:hover { background: var(--action); box-shadow: inset 0 0 0 2px var(--action-hover); }
#detail-follow[aria-pressed='true'] { display: inline-flex; align-items: center; justify-content: center; border-color: var(--action); background: var(--action); color: var(--text-on-accent); }
#detail-follow[aria-pressed='true']::before { display: inline-block; width: 8px; height: 4px; margin-right: 6px; border-bottom: 2px solid currentColor; border-left: 2px solid currentColor; content: ''; transform: rotate(-45deg) translateY(-1px); }
#follow-button[aria-pressed='true'] { border-color: var(--action); background: var(--action); color: var(--text-on-accent); box-shadow: inset 0 0 0 3px var(--text-on-accent), var(--shadow-sm); }
#detail-center.is-confirmed { border-color: var(--live); background: rgba(52,211,153,.18); color: var(--live); }
.action-feedback { min-height: 20px; color: var(--live); font-size: 13px; line-height: 20px; }
.share-fallback { display: grid; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.share-fallback input { width: 100%; min-height: var(--touch-target); border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-secondary); padding: 0 10px; color: var(--text-primary); }
.technical-data { border-top: 1px solid var(--border); padding-top: var(--space-3); }
.technical-data summary { min-height: var(--touch-target); color: var(--text-secondary); cursor: pointer; }
#detail-technical { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-family: var(--font-mono); font-size: 12px; }
.sheet-handle { display: none; }

#filter-drawer { width: min(520px, calc(100vw - 24px)); max-height: min(720px, calc(100dvh - 24px)); border: 1px solid var(--border); border-radius: 10px; background: var(--surface-primary); padding: 0; box-shadow: var(--shadow-overlay); }
#filter-drawer form { display: flex; max-height: inherit; flex-direction: column; }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4); }
.dialog-header { border-bottom: 1px solid var(--border); }
.dialog-header h2 { font-size: 24px; }
.dialog-footer { border-top: 1px solid var(--border); }
#filter-fields { display: grid; gap: var(--space-6); overflow: auto; padding: var(--space-6); }
.filter-fieldset { display: grid; gap: 8px; border: 0; padding: 0; }
.filter-option { display: flex; min-height: var(--touch-target); align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }

@media (max-width: 767px) {
  #status-bar { grid-template-columns: minmax(0, 1fr) auto auto auto; height: 52px; padding: 4px 8px; }
  .product__copy span { display: none; }
  .product__copy strong { font-size: 14px; }
  #refresh-button { width: var(--touch-target); height: var(--touch-target); }
  .language-control select { min-height: var(--touch-target); }
  #mobile-view-switch button { min-height: var(--touch-target); }
  #vehicle-explorer { border-right: 0; }
  .sheet-handle { position: relative; display: block; width: 72px; min-height: var(--touch-target); flex: 0 0 auto; align-self: center; border-radius: 22px; background: transparent; touch-action: none; }
  .sheet-handle::after { position: absolute; top: 20px; left: 15px; width: 42px; height: 4px; border-radius: 2px; background: var(--border-strong); content: ''; }
  #detail-metrics { grid-template-columns: 1fr 1fr; }
  .metric:first-child { grid-row: auto; min-height: 92px; }
  #detail-actions { grid-template-columns: 1fr 1fr; }
  #detail-follow { grid-column: 1 / -1; }
  #vehicle-detail[data-snap='compact'] #detail-metrics,
  #vehicle-detail[data-snap='compact'] #bearing-display,
  #vehicle-detail[data-snap='compact'] .technical-data { display: none; }
  #vehicle-detail[data-snap='compact'] { gap: var(--space-2); }
  #vehicle-detail[data-snap='compact'] #detail-direction { padding-bottom: var(--space-2); }
  #vehicle-detail[data-snap='compact'] #detail-actions { display: grid; grid-template-columns: 1fr; }
  #vehicle-detail[data-snap='compact'] .action-feedback:empty { display: none; }
  #vehicle-detail[data-snap='compact'] #detail-center,
  #vehicle-detail[data-snap='compact'] #detail-share { display: none; }
  #vehicle-detail[data-snap='half'] .technical-data { display: none; }
  #vehicle-detail { background: var(--surface-primary); }
  #map-controls { top: auto; right: 52px; bottom: calc(32px + env(safe-area-inset-bottom)); }
  body.has-selection #map-controls { right: 52px; bottom: calc(308px + env(safe-area-inset-bottom)); }
  #filter-drawer { max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .product, .product__copy { min-width: 0; }
  .product__copy { display: none; }
}

@media (max-width: 359px) {
  #status-bar { gap: 4px; padding: 4px; }
  .language-control select { padding: 0 4px; }
  #mobile-view-switch { width: 104px; min-width: 104px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #mobile-view-switch button { min-width: 0; padding: 0 2px; }
}
