:root {
  --bg: #0f1420;
  --panel-bg: #161d2e;
  --panel-border: #263049;
  --text: #e8ecf4;
  --text-dim: #9aa5bd;
  --accent: #e82127;
  --accent-2: #3ecf8e;
  --input-bg: #1d2537;
  --input-border: #2e3a56;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

#panel {
  width: 400px;
  min-width: 400px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#panel-header h1 {
  margin: 0;
  font-size: 22px;
}

.icon-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 16px;
  opacity: 0.5;
  flex-shrink: 0;
}

.icon-link:hover,
.icon-link:active {
  opacity: 1;
  background: var(--input-bg);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

#map {
  flex: 1;
  height: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

input[type="text"], input[type="number"] {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}

input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

.autocomplete-wrap {
  position: relative;
}

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}

.suggestions.open { display: block; }

.suggestion-item {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--panel-border);
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.highlighted { background: #232d45; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  padding: 2px 0;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-row input[type="range"] {
  flex: 1;
}

.slider-value {
  font-size: 13px;
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}

details#vehicle-settings {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

details#vehicle-settings summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

details#vehicle-settings[open] summary {
  margin-bottom: 10px;
}

#plan-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

#plan-btn:hover { background: #c81b20; }
#plan-btn:disabled { background: #5a2224; cursor: wait; }

.error {
  color: #ff7676;
  font-size: 13px;
  margin: 0;
}

.hidden { display: none !important; }

#return-options-field #return-soc-field {
  margin-left: 26px;
  margin-top: 10px;
  margin-bottom: 0;
}

.hint {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.leg-title {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.leg-title b { color: var(--text); }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.leg-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  padding: 10px;
}

.summary-card .value {
  font-size: 18px;
  font-weight: 700;
}

.summary-card .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.speak-plan-btn {
  display: block;
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 14px;
}

.speak-plan-btn:hover { border-color: var(--accent-2); }

.warning-box {
  background: #3a2418;
  border: 1px solid #7a4a1f;
  color: #ffc48a;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.stops-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stop-card {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
}

.stop-card:hover { border-color: var(--accent-2); }

.stop-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.stop-card-header .stop-number {
  background: var(--accent-2);
  color: #0b1a12;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  margin-right: 6px;
}

.stop-card-header .stop-name {
  font-weight: 700;
  font-size: 14px;
}

.stop-card-header .stop-dist {
  font-size: 12px;
  color: var(--text-dim);
}

.stop-address {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.stop-timing {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.stop-timing b { color: var(--text); }

.stop-details {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}

.stop-details b { color: var(--text); }

.bookend-card {
  cursor: default;
  background: transparent;
  border-style: dashed;
}

.bookend-card:hover { border-color: var(--input-border); }

.stop-number.start, .stop-number.end {
  background: transparent;
  width: auto;
  height: auto;
  font-size: 14px;
}

.leaflet-popup-content-wrapper {
  background: var(--panel-bg);
  color: var(--text);
}

.leaflet-popup-tip { background: var(--panel-bg); }

.marker-badge {
  background: var(--accent-2);
  color: #0b1a12;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.marker-endpoint {
  background: var(--accent);
  color: white;
  border-radius: 50% 50% 50% 0;
  width: 28px;
  height: 28px;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.marker-endpoint span {
  transform: rotate(45deg);
  font-size: 13px;
}

.directions-highlight, .directions-highlight-return {
  animation: directions-flow 0.6s linear infinite;
}

@keyframes directions-flow {
  to { stroke-dashoffset: -24; }
}

.marker-tesla-live {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border: 3px solid white;
  box-shadow: 0 0 0 4px rgba(232, 33, 39, 0.35), 0 2px 6px rgba(0,0,0,0.5);
  animation: tesla-pulse 2s ease-in-out infinite;
}

@keyframes tesla-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(232, 33, 39, 0.35), 0 2px 6px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(232, 33, 39, 0.15), 0 2px 6px rgba(0,0,0,0.5); }
}

.marker-alt {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #9b8cf2;
  border: 2.5px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}

.marker-corridor {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #5b8def;
  border: 2px solid white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
}

.alt-details {
  margin-top: 8px;
  border-top: 1px dashed var(--input-border);
  padding-top: 8px;
}

.alt-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent-2);
  font-weight: 600;
}

.alt-item {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--input-border);
}

.alt-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.alt-dist {
  font-weight: 400;
  color: var(--text-dim);
}

.alt-address, .alt-specs {
  font-size: 11px;
  color: var(--text-dim);
}

.alt-battery {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.alt-battery b { color: var(--text); }

.alt-unreachable {
  font-size: 11px;
  color: #ffc48a;
  margin-top: 4px;
}

.alt-choose-btn {
  margin-top: 6px;
  background: transparent;
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.alt-choose-btn:hover { background: var(--accent-2); color: #0b1a12; }
.alt-choose-btn:disabled { opacity: 0.6; cursor: wait; }

.send-tesla-btn {
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.send-tesla-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.route-info {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-left: 4px solid #ff2fb0;
  border-radius: var(--radius);
  padding: 12px 32px 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  box-shadow: 0 4px 18px rgba(0,0,0,0.55);
  max-width: 280px;
  z-index: 1000;
}

.route-info.route-info-error {
  border-left-color: #ff7676;
  color: #ffc4c4;
}

.route-info b { color: var(--text); }

.route-info-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

.route-info-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.route-info-close:hover { color: var(--text); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 24px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.modal-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
  text-align: left;
  margin: 0 0 16px;
}

.modal-hint b { color: var(--text); }

.modal-qr {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  background: white;
  border-radius: 8px;
  padding: 10px;
}

.modal-share-btn {
  display: block;
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 11px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 10px;
}

.modal-share-btn:hover { background: #c81b20; }

.modal-link {
  display: block;
  color: var(--accent-2);
  font-size: 13px;
  text-decoration: none;
}

.modal-link:hover { text-decoration: underline; }

.modal-divider {
  height: 1px;
  background: var(--panel-border);
  margin: 18px 0 14px;
}

.modal-copy-btn {
  display: block;
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}

.modal-copy-btn:hover { border-color: var(--accent-2); }
.modal-copy-btn.copied { border-color: var(--accent-2); color: var(--accent-2); }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  #panel {
    width: 100%;
    min-width: 0;
    height: 55vh;
  }
  #map { height: 45vh; }
}
