*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: #fafaf8;
  color: #1a1a1a;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Map Panel */
#map-panel {
  flex: 0 0 40vh;
  background: #fff;
  border-bottom: 2px solid #e0e0d8;
  overflow: hidden;
  position: relative;
  transition: flex 0.3s ease;
}

#map-panel.fullscreen {
  flex: 1;
}

#map-panel.dragging {
  transition: none;
}

.resize-handle {
  display: none;
  height: 20px;
  background: #f5f5f3;
  border-top: 1px solid #e0e0d8;
  border-bottom: 1px solid #e0e0d8;
  cursor: ns-resize;
  position: relative;
  z-index: 1001;
  touch-action: none;
  user-select: none;
}

.resize-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  background: #ccc;
  border-radius: 2px;
}

.resize-handle:active {
  background: #ebebe8;
}

@media (max-width: 767px) {
  .resize-handle {
    display: block;
  }

  .resize-handle.hidden {
    display: none;
  }
}

#map-container {
  width: 100%;
  height: 100%;
  z-index: 1;
}

.auto-scale-control {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 1000;
  background: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #e0e0d8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  user-select: none;
  cursor: pointer;
}

.auto-scale-control:hover {
  background: #fafaf8;
}

.auto-scale-control input[type="checkbox"] {
  cursor: pointer;
}

.auto-scale-control label {
  cursor: pointer;
  margin: 0;
}

.leaflet-overlay-pane svg {
  z-index: 400 !important;
}

.leaflet-overlay-pane path {
  pointer-events: auto !important;
}

svg#map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.leaflet-container svg {
  position: relative;
  z-index: 1000;
}

.segment-line {
  fill: none;
  stroke: #ccc;
  stroke-width: 3;
  cursor: pointer;
  transition: stroke 0.2s;
}

.segment-hit-area {
  fill: none;
  stroke: transparent;
  stroke-width: 20;
  cursor: pointer;
}

.segment-line.selected {
  stroke: #f59e0b;
  stroke-width: 4;
}

.town-dot {
  fill: #2563eb;
  stroke: #fff;
  stroke-width: 2;
}

.town-label {
  fill: #1a1a1a;
  font-size: 12px;
  font-weight: 500;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.town-label-leaflet {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 12px;
  font-weight: 500;
  color: #1a1a1a;
  text-shadow: 0 0 3px white, 0 0 3px white, 0 0 3px white;
}

.restaurant-dot {
  fill: #e0e0e0;
  stroke: #fff;
  stroke-width: 2.5;
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(224, 224, 224, 0.9));
  cursor: pointer;
  transition: all 0.2s;
}

.restaurant-dot.silver {
  fill: #bbb;
  stroke: #fff;
  stroke-width: 1.5;
  opacity: 0.7;
}

.restaurant-dot.gold {
  fill: #fcd34d;
  stroke: #fff;
  stroke-width: 2.5;
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(252, 211, 77, 0.9));
}

.restaurant-dot.highlighted {
  stroke: #1a1a1a;
  stroke-width: 3;
  r: 7;
}

.restaurant-dot.highlighted.silver {
  stroke: #1a1a1a;
  stroke-width: 3;
}

.restaurant-dot.highlighted.gold {
  stroke: #1a1a1a;
  stroke-width: 3;
}

/* Restaurant List Panel */
#list-panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  transition: all 0.3s ease;
}

#list-panel.hidden {
  display: none;
}

.list-header {
  margin-bottom: 1.5rem;
}

.list-header.collapsible {
  user-select: none;
  margin-bottom: 0.5rem;
  padding: 0.75rem;
  background: #f5f5f3;
  border-radius: 8px;
  transition: background 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.collapse-arrow {
  font-size: 12px;
  color: #1a1a1a;
  flex-shrink: 0;
  line-height: 1.4;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
}

.collapse-arrow:hover {
  background: #ddddd8;
}

.segment-names {
  cursor: pointer;
}

.segment-names:hover {
  color: #2563eb;
}

.segment-header-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.segment-names-text {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.reverse-button,
.filter-button {
  background: #f5f5f3;
  border: 1px solid #e0e0d8;
  border-radius: 4px;
  padding: 4px 8px;
  margin-left: 0.5rem;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  position: relative;
  z-index: 10;
}

.reverse-button:hover,
.filter-button:hover {
  background: #ebebe8;
  color: #1a1a1a;
}

.reverse-button:active,
.filter-button:active {
  background: #ddddd8;
}

.filter-button.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #f59e0b;
  font-weight: 600;
}

.route-panel {
  background: #fff;
  border: 1px solid #e0e0d8;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.route-panel-title {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 0.75rem;
}

.route-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.route-input-wrapper {
  position: relative;
}

.route-input-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #666;
  margin-bottom: 0.25rem;
}

.route-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #e0e0d8;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fafaf8;
  transition: border-color 0.2s, background 0.2s;
}

.route-input:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e0e0d8;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: none;
}

.autocomplete-dropdown.active {
  display: block;
}

.autocomplete-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: #f5f5f3;
}

.autocomplete-item.highlighted {
  background: #ebebe8;
}

.route-buttons {
  display: flex;
  gap: 0.5rem;
}

.route-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

#reverse-route-btn {
  flex: 0 0 auto;
  padding: 8px 12px;
}

.route-btn-secondary:disabled {
  background: #f5f5f3;
  color: #ccc;
  cursor: not-allowed;
}

.route-btn-primary {
  background: #2563eb;
  color: #fff;
}

.route-btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.route-btn-primary:disabled {
  background: #e0e0d8;
  color: #999;
  cursor: not-allowed;
}

.route-btn-secondary {
  background: #f5f5f3;
  border: 1px solid #e0e0d8;
  color: #666;
}

.route-btn-secondary:hover {
  background: #ebebe8;
  color: #1a1a1a;
}

.route-info {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  font-size: 13px;
  color: #92400e;
  display: none;
}

.route-info.active {
  display: block;
}

@media (max-width: 767px) {
  .route-inputs {
    grid-template-columns: 1fr;
  }
}

.global-filter {
  background: #fff;
  border: 1px solid #e0e0d8;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.global-filter-label {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
}

.global-filter-button {
  background: #f5f5f3;
  border: 1px solid #e0e0d8;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

.global-filter-button:hover {
  background: #ebebe8;
}

.global-filter-button.active {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #fff;
  font-weight: 500;
}

.collapse-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.collapse-control-button {
  background: #f5f5f3;
  border: 1px solid #e0e0d8;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
}

.collapse-control-button:hover {
  background: #ebebe8;
  color: #1a1a1a;
}

.restaurant-item.filtered-out {
  display: none;
}

.segment-meta {
  font-size: 13px;
  color: #888;
  margin-top: 0.25rem;
}

.segment-restaurants {
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.segment-restaurants.collapsed {
  max-height: 0;
}

.placeholder {
  text-align: center;
  color: #bbb;
  font-size: 14px;
  padding: 1.5rem 1rem;
  font-style: italic;
}

.restaurant-item {
  background: #fff;
  border: 1px solid #e0e0d8;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  transition: all 0.2s;
}

.restaurant-item.highlighted {
  border-color: #ef4444;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
  transform: translateX(4px);
}

.restaurant-item.silver {
  background: linear-gradient(135deg, #e0e7ef 0%, #f5f7fa 50%, #e0e7ef 100%);
  border: 2px solid #94a3b8;
  box-shadow: 0 2px 6px rgba(100, 116, 139, 0.25);
}

.restaurant-item.gold {
  background: linear-gradient(135deg, #fffbf0 0%, #ffffff 100%);
  border: 2px solid #fbbf24;
  box-shadow: 0 2px 6px rgba(251, 191, 36, 0.2);
}

.restaurant-info {
  flex: 1;
  min-width: 0;
}

.restaurant-name {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 0.25rem;
}

.restaurant-address {
  font-size: 13px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.restaurant-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.restaurant-km {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.restaurant-km-value {
  font-size: 13px;
  font-weight: 500;
  color: #888;
}

.restaurant-km-from {
  font-size: 11px;
  color: #aaa;
}

.maps-button {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}

.maps-button:active {
  background: #1d4ed8;
}

@media (min-width: 768px) {
  body { flex-direction: row; }
  #map-panel {
    flex: 0 0 50%;
    border-bottom: none;
    border-right: 2px solid #e0e0d8;
  }
  #list-panel { padding: 2rem; }
}
