/* General Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f5f5f5;
  color: #333;
}

:root {
  --sidebar-width: 350px;
}

.container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

header h1 {
  font-size: 2.5em;
  margin-bottom: 5px;
}

header p {
  font-size: 0.95em;
  opacity: 0.9;
}

.content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  min-width: 260px;
  max-width: 65vw;
  background-color: white;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

.sidebar-resizer {
  width: 8px;
  cursor: col-resize;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.03));
  flex: 0 0 8px;
}

.sidebar-resizer:hover {
  background: linear-gradient(to right, rgba(102, 126, 234, 0.12), rgba(102, 126, 234, 0.35), rgba(102, 126, 234, 0.12));
}

body.resizing-sidebar {
  cursor: col-resize;
  user-select: none;
}

.upload-section,
.rides-section,
.hover-data-section {
  padding: 20px;
  border-bottom: 1px solid #eee;
}

.upload-section h3,
.rides-section h3,
.hover-data-section h3 {
  margin-bottom: 15px;
  color: #667eea;
  font-size: 1.1em;
}

.upload-section form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-section input[type="file"] {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.upload-section button,
.rides-section button {
  padding: 10px 15px;
  background-color: #667eea;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-weight: 500;
}

.upload-section button:hover {
  background-color: #5568d3;
}

.upload-section button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.upload-results {
  margin-top: 10px;
  font-size: 0.85em;
}

.upload-results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.upload-results h4 {
  margin: 10px 0 5px 0;
  color: #333;
}

.upload-result-item {
  padding: 8px;
  margin: 5px 0;
  border-radius: 4px;
  border-left: 3px solid #ddd;
}

.upload-result-item.success {
  background-color: #d4edda;
  border-left-color: #28a745;
  color: #155724;
}

.upload-result-item.error {
  background-color: #f8d7da;
  border-left-color: #dc3545;
  color: #721c24;
}

.upload-result-item strong {
  display: block;
  margin-bottom: 3px;
}

.upload-result-item p {
  margin: 0;
}

.message {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 4px;
  font-size: 0.9em;
  margin-top: 10px;
}

.dismiss-message {
  flex: 0 0 auto;
  min-width: 24px;
  padding: 0 4px !important;
  border: 0 !important;
  background: transparent !important;
  color: inherit !important;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.dismiss-message:hover { opacity: 0.7; }

.message.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.message.error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* Rides List */
.rides-list {
  max-height: 250px;
  overflow-y: auto;
}

.rides-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.toggle-list-btn,
.clear-all-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 600;
}

.toggle-list-btn {
  background-color: #e6ecff;
  color: #27408b;
}

.clear-all-btn {
  background-color: #8f1d2c;
  color: #fff;
}

.clear-all-btn:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.rides-actions {
  margin-bottom: 8px;
}

.rides-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid #dde3f7;
  border-radius: 6px;
}

.rides-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82em;
}

.rides-table thead th {
  position: sticky;
  top: 0;
  background: #f3f6ff;
  color: #2b3f7a;
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #d8def2;
  z-index: 1;
}

.rides-table tbody td {
  padding: 8px;
  border-bottom: 1px solid #eef1fb;
}

.ride-toggle-cell {
  width: 44px;
  text-align: center;
}

.ride-toggle-checkbox {
  cursor: pointer;
  transform: scale(1.05);
}

.rides-table tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.rides-table tbody tr:hover {
  background-color: #f7f9ff;
}

.nearby-hint {
  color: #55608a;
  font-size: 0.88em;
}

.overlay-controls {
  padding: 10px;
  background-color: #f0f0f0;
  border-radius: 4px;
  margin-bottom: 10px;
  font-size: 0.9em;
}

.overlay-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

.overlay-controls input[type="checkbox"] {
  cursor: pointer;
}

.ride-item {
  padding: 12px;
  margin-bottom: 8px;
  background-color: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.ride-item:hover {
  background-color: #f0f0f0;
  border-color: #667eea;
}

.ride-item.active {
  background-color: #e8ebf5;
  border-color: #667eea;
  border-left: 4px solid #667eea;
}

.ride-header {
  flex: 1;
  cursor: pointer;
}

.ride-header h4 {
  margin-bottom: 5px;
  color: #333;
  font-size: 0.95em;
}

.ride-header .ride-date {
  font-size: 0.8em;
  color: #999;
  margin-bottom: 5px;
}

.ride-header .ride-desc {
  font-size: 0.8em;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-btn {
  background-color: #dc3545;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.9em;
  min-width: 32px;
  transition: background-color 0.3s;
  margin-left: 10px;
  flex-shrink: 0;
}

.delete-btn:hover {
  background-color: #c82333;
}

.ride-item h4 {
  margin-bottom: 5px;
  color: #333;
  font-size: 0.95em;
}

.motoheat-hover-tooltip {
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.4;
}

.motoheat-hover-tooltip:before {
  border-top-color: rgba(20, 20, 20, 0.9);
}

.motoheat-hover-tooltip .lean-angle-indicator {
  position: relative;
  width: 80px;
  height: 50px;
  margin: 2px auto 4px;
}

.motoheat-hover-tooltip .lean-angle-indicator::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  border-left: 1px dashed rgba(255, 255, 255, 0.5);
}

.motoheat-hover-tooltip .lean-angle-indicator-bar {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 4px;
  height: 38px;
  border-radius: 2px;
  background: #78b8ff;
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotate(var(--lean-angle));
}

.ride-item .ride-date {
  font-size: 0.8em;
  color: #999;
  margin-bottom: 5px;
}

.ride-item .ride-desc {
  font-size: 0.8em;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Statistics */
.stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  font-size: 0.9em;
}

.stat .label {
  font-weight: 500;
  color: #666;
}

.stat .value {
  color: #667eea;
  font-weight: 600;
}

/* Hover Data */
.hover-info {
  background-color: #f9f9f9;
  padding: 10px;
  border-radius: 4px;
  font-size: 0.85em;
  margin-bottom: 15px;
}

.hover-info p {
  margin: 5px 0;
}

.distribution-info {
  background-color: #e8f4f8;
  padding: 10px;
  border-radius: 4px;
  border-left: 3px solid #0f5f8f;
  font-size: 0.85em;
  margin-bottom: 15px;
}

.distribution-info .stat {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 0.9em;
}

.distribution-info .label {
  font-weight: 500;
  color: #333;
}

.distribution-info .value {
  color: #0f5f8f;
  font-weight: 600;
}

/* Ride distribution markers */
.ride-distribution-marker {
  transition: all 0.2s ease;
}

.ride-distribution-marker:hover {
  z-index: 1000;
}

/* Map Container */
.map-container {
  flex: 1;
  position: relative;
  background-color: #fff;
}

#map {
  width: 100%;
  height: 100%;
}

/* Legend */
.legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background-color: white;
  padding: 15px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  font-size: 0.85em;
}

.legend h4 {
  margin-bottom: 10px;
  font-size: 0.9em;
  color: #333;
}

.legend-item {
  display: flex;
  align-items: center;
  margin: 5px 0;
  gap: 8px;
}

.legend-item .color {
  width: 20px;
  height: 12px;
  border-radius: 2px;
}

/* Scrollbar Styling */
.sidebar::-webkit-scrollbar,
.rides-list::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.rides-list::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.sidebar::-webkit-scrollbar-thumb,
.rides-list::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.rides-list::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Responsive Design */
@media (max-width: 768px) {
  .content {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 300px;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }

  header h1 {
    font-size: 1.8em;
  }

  .legend {
    bottom: 10px;
    right: 10px;
    font-size: 0.75em;
    padding: 10px;
  }

}

/* Compact, theme-aware ride workspace */
:root {
  color-scheme: light;
  --page: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --text: #182230;
  --muted: #738094;
  --line: #e3e8ef;
  --accent: #147efb;
  --accent-soft: #eaf3ff;
  --danger: #d94c57;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #11151b;
  --surface: #191f28;
  --surface-muted: #202833;
  --text: #eef3fa;
  --muted: #9ba8ba;
  --line: #303a48;
  --accent: #59a7ff;
  --accent-soft: #1c324a;
  --danger: #ff737d;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text);
  transition: background-color 160ms ease, color 160ms ease;
}

.container { height: 100dvh; }

header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: none;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 13px;
  background: var(--accent);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
}

header h1 { margin: 0; font-size: 16px; letter-spacing: 0.09em; }
header p { margin-top: 2px; color: var(--muted); font-size: 12px; }
.theme-picker { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.theme-picker select {
  padding: 8px 30px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.content { min-height: 0; }
.sidebar {
  padding: 4px 0 24px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: none;
}

.upload-section, .rides-section, .hover-data-section {
  padding: 18px 18px;
  border-bottom: 1px solid var(--line);
}

.upload-section h3, .rides-section h3, .hover-data-section h3 {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.015em;
}

.upload-section input[type="file"] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-muted);
  color: var(--muted);
}

.upload-section button, .rides-section button {
  border-radius: 9px;
  background: var(--accent);
  transition: filter 140ms ease, transform 140ms ease;
}
.upload-section button:hover, .rides-section button:hover { filter: brightness(0.94); }
.upload-section button:active, .rides-section button:active { transform: translateY(1px); }
.upload-results h4, .upload-result-item strong { color: var(--text); }
.upload-result-item.success { background: #e9f8ef; color: #176c3b; }
:root[data-theme="dark"] .upload-result-item.success { background: #173527; color: #9be0b4; }
.upload-result-item.error { background: #fff0f0; color: #8e2931; }
:root[data-theme="dark"] .upload-result-item.error { background: #3a2226; color: #ffb3b8; }
.message.success { background: #e9f8ef; color: #176c3b; border-color: #c8eed5; }
.message.error { background: #fff0f0; color: #8e2931; border-color: #f3cdd0; }

.rides-header-row { margin-bottom: 10px; }
.toggle-list-btn { background: var(--accent-soft) !important; color: var(--accent) !important; }
.clear-all-btn { background: var(--surface-muted) !important; color: var(--danger) !important; }
.rides-table-wrap { border-color: var(--line); border-radius: 10px; }
.rides-table thead th { background: var(--surface-muted); color: var(--muted); border-color: var(--line); }
.rides-table tbody td { border-color: var(--line); color: var(--text); }
.rides-table tbody tr:hover { background: var(--surface-muted); }
.delete-btn { min-width: 28px; padding: 4px 7px; background: transparent; color: var(--danger); }
.stat { border-color: var(--line); }
.stat .label, .nearby-hint, .profile-caption { color: var(--muted); }
.stat .value { color: var(--accent); }

.hover-info {
  margin: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.profile-caption { margin: 0 0 12px; font-size: 12px; }
.profile-chart {
  overflow: hidden;
  margin-top: 10px;
  padding: 10px 9px 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-muted);
}
.profile-tabs { display: flex; gap: 5px; margin-bottom: 5px; }
.profile-tabs button {
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.profile-tabs button.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}
.profile-tabs button span { margin-left: 3px; opacity: 0.75; font-size: 10px; }
.profile-canvas { display: block; width: 100% !important; height: 238px !important; cursor: crosshair; }
.profile-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.profile-cursor-hint { margin-top: 3px; color: var(--muted); font-size: 10px; text-align: right; }
.profile-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 11px;
}
.profile-legend-item { display: flex; min-width: 0; align-items: center; gap: 7px; }
.profile-legend-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-legend-swatch { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; }
.profile-line-key { display: flex; flex-wrap: wrap; gap: 8px 15px; margin-top: 9px; color: var(--muted); font-size: 10px; }
.profile-line-key span { display: inline-flex; align-items: center; gap: 6px; }
.estimated-line-swatch, .measured-line-swatch { width: 19px; height: 0; border-top: 2px solid var(--accent); }
.estimated-line-swatch { border-top-style: dashed; }

.sidebar-resizer { width: 5px; flex-basis: 5px; background: transparent; }
.sidebar-resizer:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.map-container { background: var(--page); }
#map { background: var(--page); }
.leaflet-container { background: var(--page); }
.map-theme-dark .leaflet-tile-pane {
  filter: brightness(0.68) invert(1) hue-rotate(180deg) saturate(0.75);
}
.leaflet-control-zoom a, .leaflet-bar a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 82%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--accent); }

.motoheat-hover-tooltip {
  background: rgba(24, 34, 48, 0.94);
  color: #f7faff;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
:root[data-theme="dark"] .sidebar::-webkit-scrollbar-track { background: var(--surface); }
:root[data-theme="dark"] .sidebar::-webkit-scrollbar-thumb { background: #465365; }

@media (max-width: 768px) {
  header { min-height: 60px; padding: 8px 14px; }
  .brand-mark { width: 34px; height: 34px; }
  .theme-picker { gap: 6px; }
  .theme-picker span { display: none; }
  .content { flex-direction: column; }
  .sidebar { width: 100%; max-width: none; max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-resizer { display: none; }
  .map-container { min-height: 0; }
}
