@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --text: #e8eaf0;
  --muted: #7b7f96;
  --green: #1baf7a;
  --green-dim: rgba(27,175,122,0.15);
  --red: #e34948;
  --red-dim: rgba(227,73,72,0.15);
  --accent: #4f6ef7;
  --orange: #f7994f;
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f0f2f8;
    --surface: #ffffff;
    --surface2: #f5f6fa;
    --border: #dde0ed;
    --text: #1a1d27;
    --muted: #7b7f96;
    --green-dim: rgba(27,175,122,0.12);
    --red-dim: rgba(227,73,72,0.12);
  }
}

html, body { height: 100%; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }

.app { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; gap: 12px;
}
header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
header .subtitle { color: var(--muted); font-size: 13px; }

.icon-toll {
  width: 36px; height: 36px;
  background: var(--accent); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}

main { display: grid; grid-template-columns: 380px 1fr; overflow: hidden; height: calc(100vh - 63px); }

@media (max-width: 768px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 320px; height: auto; overflow: visible; }
}

/* Sidebar */
.sidebar {
  overflow-y: auto; padding: 16px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
}

.card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}

.card-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted); margin-bottom: 10px;
}

/* Inputs */
.input-group { display: flex; flex-direction: column; gap: 8px; }
.input-wrap { position: relative; }
.input-wrap .input-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  font-size: 13px; pointer-events: none;
}

input[type="text"] {
  width: 100%; padding: 9px 11px 9px 34px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: inherit; font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--muted); }

.autocomplete-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); z-index: 100;
  max-height: 200px; overflow-y: auto; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 9px 13px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--surface2); }

/* Vehicle */
.vehicle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.vehicle-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text); font-family: inherit;
  font-size: 11px; font-weight: 500; transition: border-color 0.15s, background 0.15s;
}
.vehicle-btn:hover { border-color: var(--accent); }
.vehicle-btn.active { border-color: var(--accent); background: rgba(79,110,247,0.1); color: var(--accent); }
.vehicle-btn .veh-icon { font-size: 19px; }

/* Slider */
.slider-wrap { display: flex; flex-direction: column; gap: 8px; }
.slider-header { display: flex; justify-content: space-between; align-items: baseline; }
.slider-label { font-size: 12px; color: var(--muted); }
.slider-value { font-family: 'DM Mono', monospace; font-size: 16px; font-weight: 500; color: var(--accent); }

.slider-track-wrap { position: relative; }

input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 4px;
  background: var(--border); border-radius: 2px; outline: none; cursor: pointer;
  position: relative; z-index: 2;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  background: var(--accent); border-radius: 50%;
  border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--accent);
}

/* Break-even marker on slider */
.be-marker-wrap { position: absolute; top: 0; left: 0; right: 0; height: 4px; pointer-events: none; z-index: 1; }
.be-marker {
  position: absolute; top: -3px;
  width: 2px; height: 10px; background: var(--orange);
  transform: translateX(-50%);
  transition: left 0.4s ease;
}
.be-marker-tip {
  position: absolute; top: 13px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--orange); white-space: nowrap; font-weight: 600;
  letter-spacing: 0.3px;
}

.slider-limits { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* CTA */
.btn-calc {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm); font-family: inherit;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn-calc:hover { opacity: 0.88; }
.btn-calc:disabled { opacity: 0.5; cursor: not-allowed; }

/* Error */
.error-msg {
  padding: 9px 13px; background: var(--red-dim); border: 1px solid var(--red);
  border-radius: var(--radius-sm); color: var(--red); font-size: 13px;
}

/* Break-even card */
.be-good  { background: var(--green-dim) !important; border-color: var(--green) !important; }
.be-bad   { background: var(--red-dim)   !important; border-color: var(--red)   !important; }
.be-neutral { background: var(--surface2); border-color: var(--border); }

.be-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.be-value { font-family: 'DM Mono', monospace; font-size: 22px; font-weight: 500; margin-top: 2px; }
.be-icon { font-size: 22px; opacity: 0.7; }
.be-verdict { font-size: 13px; line-height: 1.4; }

.net-savings { margin-top: 6px; font-size: 13px; font-family: 'DM Mono', monospace; font-weight: 500; }
.net-savings.positive { color: var(--green); }
.net-savings.negative { color: var(--red); }

/* Route cards */
.route-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.route-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px;
}
.route-card-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted); margin-bottom: 9px;
  display: flex; align-items: center; gap: 5px;
}
.route-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-toll { background: var(--accent); }
.dot-free { background: var(--orange); }

.metric { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; font-size: 13px; }
.metric:last-child { margin-bottom: 0; }
.metric-label { color: var(--muted); }
.metric-val { font-family: 'DM Mono', monospace; font-size: 13px; font-weight: 500; }

.time-badge { font-family: 'DM Mono', monospace; font-size: 12px; font-weight: 600; }
.time-badge.faster { color: var(--green); }
.time-badge.slower { color: var(--red); }

/* Toll segments */
.segment-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.segment-row:last-child { border-bottom: none; padding-bottom: 0; }
.segment-name { color: var(--text); }
.seg-country {
  font-size: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 3px; padding: 0 4px; color: var(--muted); margin-left: 4px;
  vertical-align: middle;
}
.segment-cost { font-family: 'DM Mono', monospace; font-weight: 500; color: var(--accent); }

/* Map */
#map { height: 100%; min-height: 320px; background: var(--surface2); }

/* Spinner */
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
  vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results { display: flex; flex-direction: column; gap: 10px; }
.hidden { display: none !important; }
