/* src/muni-speed/style.css */
*, *:before, *:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-panel: #f4f2eff0;
  --bg-input: #0000000a;
  --bg-input-hover: #00000012;
  --border: #0000001a;
  --border-focus: #00000038;
  --text-primary: #1c1b19;
  --text-secondary: #6b6862;
  --text-dim: #9e9a93;
  --accent: #c0362c;
  --speed-fast: #2dd4a8;
  --speed-mid: #f0c040;
  --speed-slow: #ef4444;
  --font-mono: "IBM Plex Mono", "SF Mono", monospace;
  --font-serif: "EB Garamond", "Georgia", serif;
}

html, body {
  overflow: hidden;
  background: #111315;
  height: 100%;
  margin: 0 !important;
  padding: 0 !important;
}

#map {
  position: fixed;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  height: 100dvh;
  top: 0;
  left: 0;
}

#panel {
  position: absolute;
  z-index: 1000;
  background: var(--bg-panel);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-serif);
  border-radius: 12px;
  width: 300px;
  padding: 20px;
  top: 16px;
  left: 16px;
  box-shadow: 0 8px 32px #0000001f, inset 0 0 0 1px #0000000a;
}

.back-link {
  display: inline-block;
  font-family: var(--font-mono);
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: .02em;
  margin-bottom: 14px;
  transition: color .2s;
  font-size: .6875rem;
  font-weight: 400;
}

.back-link:hover {
  color: var(--accent);
}

#panel-header {
  display: flex;
  align-items:  center;
  gap: 10px;
  margin-bottom: 20px;
}

#panel-header .logo-mark {
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  box-shadow: 0 0 8px #c0362c66;
}

#panel-header h1 {
  font-family: var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
}

#panel-header .subtitle {
  color: var(--text-dim);
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: .05em;
  flex-shrink: 0;
  margin-left: auto;
}

.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: block;
  font-family: var(--font-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-size: 9px;
  font-weight: 500;
}

select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-serif);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  border-radius: 6px;
  width: 100%;
  padding: 8px 12px;
  transition: border-color .15s, background .15s;
  font-size: 14px;
  font-weight: 500;
}

select:hover {
  background: var(--bg-input-hover);
}

select:focus {
  outline: none;
  border-color: var(--border-focus);
}

#direction-group {
  display: none;
}

#direction-group.visible {
  display: block;
}

.direction-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  gap: 2px;
  padding: 2px;
}

.direction-toggle button {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  letter-spacing: .06em;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 4px;
  flex: 1;
  padding: 7px 0;
  transition: all .15s;
  font-size: 11px;
  font-weight: 500;
}

.direction-toggle button.active {
  color: var(--text-primary);
  background: #00000014;
  font-weight: 700;
}

.direction-toggle button:hover:not(.active) {
  color: var(--text-primary);
}

#mode-filter-group {
  display: none;
}

#mode-filter-group.visible {
  display: block;
}

.mode-filter {
  display: flex;
  gap: 6px;
}

.mode-toggle {
  cursor: pointer;
}

.mode-toggle input {
  display: none;
}

.mode-chip {
  display: inline-block;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 5px 10px;
  transition: all .15s;
  font-size: 10px;
  font-weight: 500;
}

.mode-toggle input:checked + .mode-chip {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background: #00000014;
  font-weight: 700;
}

.mode-toggle input:not(:checked) + .mode-chip {
  opacity: .4;
}

.toggle-row {
  display: flex;
  cursor: pointer;
  align-items:  center;
  gap: 8px;
}

.toggle-row input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  border-radius: 9px;
  flex-shrink: 0;
  width: 32px;
  height: 18px;
  transition: background .2s, border-color .2s;
}

.toggle-row input[type="checkbox"]:after {
  content: "";
  position: absolute;
  background: var(--text-dim);
  border-radius: 50%;
  width: 12px;
  height: 12px;
  transition: transform .15s, background .15s;
  top: 2px;
  left: 2px;
}

.toggle-row input[type="checkbox"]:checked {
  background: #c0362c1f;
  border-color: #c0362c4d;
}

.toggle-row input[type="checkbox"]:checked:after {
  background: var(--accent);
  transform: translateX(14px);
}

.toggle-label {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  letter-spacing: .02em;
  font-size: 10px;
}

#hour-section {
  margin-top: 18px;
  padding-top: 0;
}

#hour-display {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

#hour-time {
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -.02em;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

#hour-period {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin-left: 4px;
  font-size: 11px;
  font-weight: 400;
}

#hour-label-right {
  font-family: var(--font-mono);
  color: var(--text-dim);
  letter-spacing: .08em;
  font-size: 9px;
}

#play-btn {
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  border-radius: 50%;
  flex-shrink: 0;
  justify-content: center;
  align-items:  center;
  width: 28px;
  height: 28px;
  transition: background .15s, color .15s, border-color .15s;
}

#play-btn:hover {
  background: var(--bg-input-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

#play-btn.playing {
  color: var(--accent);
  background: #c0362c1a;
  border-color: #c0362c40;
}

#play-btn svg {
  fill: currentColor;
  width: 12px;
  height: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background: none;
  width: 100%;
  height: 28px;
}

input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--text-dim) 0%, var(--accent) var(--progress, 0%), var(--text-dim) var(--progress, 0%));
  border-radius: 2px;
  height: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  background: var(--text-primary);
  border: 2px solid #f4f2ef;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  transition: transform .1s;
  box-shadow: 0 1px 4px #00000026;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-track {
  background: var(--text-dim);
  border-radius: 2px;
  height: 4px;
}

input[type="range"]::-moz-range-progress {
  background: var(--accent);
  border-radius: 2px;
  height: 4px;
}

input[type="range"]::-moz-range-thumb {
  background: var(--text-primary);
  border: 2px solid #f4f2ef;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  box-shadow: 0 1px 4px #00000026;
}

.hour-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  padding: 0 2px;
}

.hour-ticks span {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 8px;
}

#route-badge {
  display: none;
  position: absolute;
  z-index: 1000;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  border: 1px solid #00000014;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  top: 16px;
  right: 16px;
  box-shadow: 0 4px 16px #00000026;
}

#route-badge.visible {
  display: block;
}

#legend {
  position: absolute;
  z-index: 1000;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  display: flex;
  border-radius: 8px;
  align-items:  center;
  gap: 16px;
  width: 300px;
  padding: 12px 16px;
  font-size: 9px;
  bottom: 24px;
  left: 16px;
  box-shadow: 0 4px 16px #00000014;
}

.legend-gradient {
  background: linear-gradient(to right, #ef4444, #f59e0b, #f0c040, #84cc16, #2dd4a8);
  border-radius: 3px;
  width: 100%;
  height: 6px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 3px;
}

.legend-labels span {
  color: var(--text-dim);
  font-size: 8px;
}

#legend .legend-item {
  display: flex;
  flex-direction: column;
  flex: 1;
  align-items:  flex-start;
}

.legend-avg {
  display: flex;
  flex-direction: column;
  align-items:  center;
}

.legend-avg-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.legend-avg-label {
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 2px;
  font-size: 8px;
}

#loading {
  display: none;
  position: absolute;
  z-index: 2000;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 16px 24px;
  font-size: 11px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 32px #0000001f;
}

#loading.visible {
  display: block;
}

#loading:before {
  content: "";
  display: inline-block;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
  border-radius: 50%;
  width: 8px;
  height: 8px;
  margin-right: 10px;
}

@keyframes pulse {
  0%, 100% {
    opacity: .3;
  }

  50% {
    opacity: 1;
  }
}

#data-attribution {
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 14px;
  font-size: 8px;
}

#data-attribution a {
  color: var(--text-secondary);
  text-decoration: none;
}

#data-attribution a:hover {
  color: var(--accent);
}

.leaflet-control-attribution {
  color: var(--text-dim) !important;
  font-family: var(--font-mono) !important;
  background: #f4f2efcc !important;
  font-size: 8px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

.leaflet-control-zoom {
  overflow: hidden;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 8px #00000014 !important;
}

.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border) !important;
  font-family: var(--font-mono) !important;
  width: 32px !important;
  height: 32px !important;
  font-size: 14px !important;
  line-height: 32px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-input-hover) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-serif) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px #0000001f !important;
}

.leaflet-popup-content {
  margin: 12px 14px !important;
  font-size: 13px !important;
  line-height: 1.5 !important;
}

.leaflet-popup-tip {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
}

.leaflet-popup-close-button {
  color: var(--text-secondary) !important;
}

.leaflet-tooltip {
  white-space: nowrap;
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-mono) !important;
  border-radius: 6px !important;
  padding: 6px 10px !important;
  font-size: 11px !important;
  box-shadow: 0 4px 12px #0000001a !important;
}

.leaflet-tooltip:before {
  border-top-color: var(--bg-panel) !important;
}

.tooltip-route {
  color: var(--accent);
  font-weight: 700;
}

.tooltip-speed {
  font-weight: 700;
}

.tooltip-count {
  color: var(--text-dim);
  font-size: 9px;
}

.popup-route-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  justify-content: space-between;
  align-items:  center;
  padding: 4px 0;
  font-size: 11px;
}

.popup-route-row:last-child {
  border-bottom: none;
}

.popup-route-name {
  min-width: 40px;
  font-weight: 700;
}

.popup-route-speed {
  margin-left: 12px;
  font-weight: 700;
}

#mobile-sheet {
  display: none;
}

@media (max-width: 768px) {
  #panel {
    display: none;
  }

  #mobile-sheet {
    display: block;
    z-index: 1001;
    --sheet-max-height: calc(100dvh - 24px);
    --sheet-background: #f4f2ef;
    --sheet-border-radius: 16px;
    scrollbar-width: none;
  }

  #mobile-sheet::-webkit-scrollbar {
    display: none;
  }

  #mobile-sheet::part(sheet) {
    backdrop-filter: blur(10px) saturate(1.2);
    -webkit-backdrop-filter: blur(10px) saturate(1.2);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px #0000001f;
  }

  #mobile-sheet::part(content) {
    padding: 0 20px 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    overflow-y: hidden;
  }

  #mobile-sheet::part(header) {
    background: #f4f2ef;
  }

  #mobile-sheet::part(handle) {
    background: var(--text-dim);
    opacity: .5;
  }

  #panel-content {
    display: flex;
    font-family: var(--font-serif);
    color: var(--text-primary);
    flex-direction: column;
  }

  #hour-section {
    border-top: none;
    order: -9;
    margin-top: 4px;
    margin-bottom: 10px;
    padding-top: 0;
    padding-bottom: 0;
  }

  #legend.legend-inline {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    background: none;
    border: none;
    border-radius: 0;
    flex-direction: row;
    order: -8;
    align-items:  center;
    gap: 10px;
    margin-top: 2px;
    margin-bottom: 6px;
    padding: 0;
    position: static !important;
    width: 100% !important;
    bottom: auto !important;
    left: auto !important;
  }

  #legend.legend-inline .legend-avg {
    flex-direction: row;
    flex-shrink: 0;
    align-items: baseline;
    gap: 4px;
  }

  #legend.legend-inline .legend-avg-value {
    font-size: 13px;
  }

  #legend.legend-inline .legend-avg-label {
    margin-top: 0;
    font-size: 8px;
  }

  #legend.legend-inline .legend-item {
    flex: 1;
    min-width: 0;
    padding-left: 6px;
  }

  #legend.legend-inline .legend-gradient {
    height: 4px;
  }

  #legend.legend-inline .legend-labels span {
    font-size: 7px;
  }

  .control-group:has(#year-select) {
    order: 0;
  }

  .control-group:has(#daytype-select) {
    order: 0;
  }

  .control-group:has(#route-select) {
    order: 0;
  }

  #mode-filter-group, #direction-group {
    order: 1;
  }

  #data-attribution {
    order: 10;
  }

  .back-link {
    order: 10;
    margin-bottom: 0;
  }

  #panel-header {
    order: 10;
    margin-bottom: 0;
    display: none !important;
  }

  select {
    min-height: 44px;
    padding: 12px;
    font-size: 16px;
  }

  .direction-toggle button {
    min-height: 44px;
    padding: 12px 0;
  }

  .mode-chip {
    padding: 10px 14px;
  }

  #play-btn {
    width: 40px;
    height: 40px;
  }

  #play-btn svg {
    width: 14px;
    height: 14px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -10px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  #route-badge {
    top: calc(12px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
    right: unset !important;
  }

  .leaflet-control-zoom {
    margin-top: calc(10px + env(safe-area-inset-top)) !important;
    margin-right: env(safe-area-inset-right) !important;
  }
}
