*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f1f5f9;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────── */
#sidebar {
  width: 400px;
  flex-shrink: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 2px 0 8px rgba(0,0,0,.08);
  z-index: 10;
}

header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #e2e8f0;
}

header h1 { font-size: 1.15rem; color: #1e293b; }
header p  { margin-top: 4px; font-size: .8rem; color: #64748b; }
header em { font-style: normal; font-weight: 600; }

/* ── Mode toggle ─────────────────────────── */
.mode-toggle {
  display: flex;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.mode-toggle label { flex: 1; }
.mode-toggle input[type=radio] { display: none; }
.mode-toggle span {
  display: block;
  padding: 7px;
  border-radius: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
}
.mode-toggle input:checked + span {
  background: #fff;
  color: #1e293b;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ── Form ────────────────────────────────── */
form {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.field { display: flex; flex-direction: column; gap: 4px; }

label { font-size: .75rem; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .04em; }

input, select {
  padding: 8px 10px;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  font-size: .9rem;
  color: #1e293b;
  background: #f8fafc;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: #3b82f6;
  background: #fff;
}

button {
  padding: 10px;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
button:hover  { background: #2563eb; }
button:active { background: #1d4ed8; }
button:disabled { background: #93c5fd; cursor: default; }

/* ── Status ──────────────────────────────── */
#status {
  padding: 8px 20px;
  font-size: .8rem;
  color: #64748b;
  min-height: 28px;
}
#status.error { color: #dc2626; }

/* ── Results list ────────────────────────── */
#results {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
}

.results-header {
  padding: 8px 8px 4px;
  font-size: .75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.station-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
  border: 1.5px solid transparent;
}
.station-card:hover    { background: #f1f5f9; }
.station-card.active   { background: #eff6ff; border-color: #3b82f6; }

.rank-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 1px;
}
.rank-best   { background: #16a34a; }
.rank-good   { background: #65a30d; }
.rank-mid    { background: #d97706; }
.rank-bad    { background: #dc2626; }

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

.station-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.station-name { font-weight: 600; font-size: .88rem; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.star-btn {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  color: #cbd5e1;
  flex-shrink: 0;
  transition: color .15s, transform .12s;
}
.star-btn:hover  { color: #f59e0b; transform: scale(1.25); }
.star-btn.active { color: #f59e0b; }

.station-addr { font-size: .75rem; color: #64748b; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  margin-top: 8px;
}
.stat-item { display: flex; flex-direction: column; gap: 1px; }
.stat-label {
  font-size: .67rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.stat-val { font-size: .84rem; font-weight: 700; color: #1e293b; }
.stat-val.price        { color: #1d4ed8; }
.stat-val.effective    { color: #92400e; }
.stat-val.savings-pos  { color: #166534; }
.stat-val.savings-neg  { color: #991b1b; }
.stat-val.savings-neutral { color: #64748b; font-weight: 500; font-size: .78rem; }

/* ── Map ─────────────────────────────────── */
#map { flex: 1; }

.price-marker span {
  display: block;
  width: 60px;
  height: 22px;
  border-radius: 7px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 22px;
  text-align: center;
  border: 2px solid rgba(0,0,0,.15);
  box-shadow: 0 2px 5px rgba(0,0,0,.35);
}

/* Leaflet popup tweaks */
.leaflet-popup-content { font-family: inherit; font-size: .85rem; line-height: 1.5; }
.popup-title { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.popup-row   { display: flex; justify-content: space-between; gap: 16px; }
.popup-label { color: #64748b; }
.popup-val   { font-weight: 600; }
.popup-best  { color: #16a34a; font-weight: 700; }

.popup-ref-btn {
  width: 100%;
  padding: 6px 10px;
  background: #fef9c3;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.popup-ref-btn:hover  { background: #fef08a; }
.popup-ref-btn.active { background: #f59e0b; color: #fff; border-color: #f59e0b; }

/* ── Sheet handle (desktop: verborgen) ───── */
.sheet-handle { display: none; }

/* ── Mobile bottom sheet ─────────────────── */
@media (max-width: 768px) {
  body { overflow: hidden; }

  #app { position: relative; }

  #map {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 88vh;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,.18);
    transform: translateY(calc(100% - 80px));
    transition: transform .35s cubic-bezier(.32,.72,0,1);
    z-index: 200;
    overflow: hidden;
  }

  #sidebar.sheet-open {
    transform: translateY(0);
  }

  .sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
  }

  .sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #cbd5e1;
  }
}
