:root {
  --bg: #040713;
  --bg-accent: #120b2a;
  --panel-bg: rgba(13, 19, 45, 0.92);
  --panel-border: rgba(116, 61, 253, 0.45);
  --shadow: 0 32px 80px rgba(3, 6, 18, 0.75);

  --text-primary: #f5f8ff;
  --text-muted: #91a2d9;

  --green: #55ff55;
  --pink: #f626af;
  --purple: #713dfd;
  --blue: #1e4fff;

  --code-key: #55ff55;
  --code-operator: #94a4ff;
  --code-string: #ffc36d;
  --code-comment: #6f7ba8;

  --danger: #ff6b6b;
  --divider: rgba(255, 255, 255, 0.12);

  --font-sans: 'Space Grotesk', 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --font-mono: 'Fira Code', 'SFMono-Regular', ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

  /* Legacy aliases for existing components */
  --text: var(--text-primary);
  --muted: var(--text-muted);
  --primary: var(--purple);
  --primary-hover: #8a5fff;
}

* {
  box-sizing: border-box;
  font-family: var(--font-sans);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 20%, rgba(246, 38, 175, 0.18), transparent 55%),
    radial-gradient(circle at 85% 10%, rgba(30, 79, 255, 0.22), transparent 60%),
    radial-gradient(circle at 12% 85%, rgba(85, 255, 85, 0.18), transparent 45%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
  color: var(--text-primary);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: transparent;
  box-shadow: none;
}

.leaflet-popup-content {
  margin: 0;
  width: auto !important;
}

a {
  color: var(--blue);
}

/* Hard gating: only one panel visible at a time */
body:not(.authed) #map-section { display: none !important; }
body.authed #login-section { display: none !important; }

.layout {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.layout.map-active {
  align-items: flex-start;
  justify-content: center;
  padding-top: 2rem;
}

.layout.map-active #map-section {
  margin: 0 auto;
}

.panel {
  background: var(--panel-bg);
  border-radius: 1.1rem;
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--panel-border);
  width: min(520px, 92vw);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  backdrop-filter: blur(18px);
}

.panel:not(.hidden):hover {
  transform: translateY(-4px);
  box-shadow: 0 30px 60px rgba(3, 6, 18, 0.65);
}

.hidden {
  display: none;
}

#map-section {
  display: flex;
  flex-direction: column;
  width: min(1080px, 94vw);
  height: min(92vh, 960px);
  padding: 1.25rem;
  gap: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--text-muted);
}

.toolbar h2 {
  margin: 0;
  color: var(--text-primary);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

select,
input,
button {
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid rgba(113, 61, 253, 0.3);
  background: rgba(20, 27, 55, 0.85);
  color: var(--text-primary);
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

select:focus,
input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(113, 61, 253, 0.35);
}

button {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1;
}

button:hover {
  box-shadow: 0 12px 26px rgba(113, 61, 253, 0.45);
}

#favorites-toggle {
  background: rgba(20, 27, 55, 0.9);
  border: 1px solid rgba(113, 61, 253, 0.4);
  color: var(--text-muted);
  padding-inline: 0.85rem;
}

#favorites-toggle:hover {
  color: var(--text-primary);
  box-shadow: 0 12px 24px rgba(113, 61, 253, 0.35);
}

#favorites-toggle.active {
  color: var(--pink);
  border-color: rgba(246, 38, 175, 0.65);
  background: rgba(246, 38, 175, 0.22);
  box-shadow: 0 12px 26px rgba(246, 38, 175, 0.28);
}

#login-error {
  color: var(--danger);
  min-height: 1.2rem;
}

.map-wrapper {
  position: relative;
  flex: 1;
  min-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(113, 61, 253, 0.25);
}

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

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 26, 0.6);
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.04em;
  z-index: 20;
  backdrop-filter: blur(2px);
}

.map-loading.hidden {
  display: none;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.85rem 1.4rem;
  border-radius: 0.85rem;
  background: rgba(6, 78, 59, 0.9);
  color: #e7f8f2;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 18px 48px rgba(3, 9, 20, 0.55);
  transform: translateY(25px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 50;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast[data-type='error'] {
  background: rgba(220, 38, 38, 0.92);
  color: #fff3f3;
}

.fuel-marker {
  background: none;
  border: none;
}

.marker-wrapper {
  position: relative;
  display: inline-block;
}

.marker-wrapper img {
  display: block;
  width: 50px;
  height: 70px;
}

.dual-fuel-marker {
  position: absolute;
  top: -12px;
  right: -10px;
  color: #ffd43b;
  font-size: 22px;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
}

.favorite-marker {
  position: absolute;
  top: -12px;
  left: -10px;
  color: var(--pink);
  font-size: 22px;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
}

#stations-list {
  background: rgba(11, 18, 38, 0.65);
  border-radius: 12px;
  border: 1px solid rgba(113, 61, 253, 0.35);
  padding: 0.75rem 0.75rem 0;
  max-height: 240px;
  overflow-y: auto;
}

.station-item {
  padding: 0;
  border: none;
  background: transparent;
}

.station-item:focus {
  outline: 2px solid rgba(246, 38, 175, 0.65);
  outline-offset: 2px;
}

.station-item h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.station-item p {
  margin: 0.15rem 0;
  color: var(--text-muted);
}

.station-item p.alt-fuel {
  color: #94f1c6;
}

.station-item .price-line {
  color: var(--text-primary);
  font-weight: 600;
}

.station-item .distance-line {
  color: var(--text-muted);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-header h3 {
  flex: 1;
}

.favorite-toggle {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(113, 61, 253, 0.28);
  color: var(--text-muted);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.favorite-toggle i {
  pointer-events: none;
  font-size: 1rem;
}

.favorite-toggle:hover {
  color: var(--pink);
  border-color: rgba(246, 38, 175, 0.45);
  background: rgba(246, 38, 175, 0.12);
}

.favorite-toggle.active {
  color: var(--pink);
  border-color: rgba(246, 38, 175, 0.65);
  background: rgba(246, 38, 175, 0.18);
}

.station-item.favorite.card {
  border-color: rgba(246, 38, 175, 0.45);
  box-shadow: 0 0 12px rgba(246, 38, 175, 0.2);
}

.opening-hours {
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: pre-line;
}

.opening-label {
  display: block;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.alt-star {
  color: #ffd43b;
  margin-right: 0.25rem;
  display: inline-block;
  font-size: 1.05rem;
}

#stations-list.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
}

#stations-list.row .station-item {
  flex: 1 1 calc(50% - 0.75rem);
  box-sizing: border-box;
}

#stations-list.row .station-item p {
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.field span {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.password-wrapper {
  display: flex;
  gap: 0.5rem;
}

.password-wrapper input {
  flex: 1;
}

.password-wrapper button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(113, 61, 253, 0.3);
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.password-wrapper button:hover {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: none;
}

.password-wrapper button svg {
  width: 20px;
  height: 20px;
  fill: var(--text-muted);
}

#login-form .login-submit {
  margin-top: 1rem;
}

.code-panel {
  background: linear-gradient(140deg, rgba(19, 25, 58, 0.95), rgba(9, 13, 32, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 1.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(15, 20, 44, 0.9);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.code-title {
  margin-left: 0.4rem;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
}

.popup-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: color 0.2s ease;
}

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

.card {
  position: relative;
  display: grid;
  gap: 0.55rem;
  align-items: center;
  padding: 1.25rem 1.4rem;
  border-radius: 1.2rem;
  background: rgba(11, 18, 38, 0.75);
  border: 1px solid rgba(113, 61, 253, 0.28);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border 0.25s ease;
  color: var(--text-primary);
  cursor: pointer;
}

.card::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  background: radial-gradient(circle at 20% -20%, rgba(246, 38, 175, 0.2), transparent 55%),
              radial-gradient(circle at 120% 50%, rgba(85, 255, 85, 0.2), transparent 65%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(5, 10, 30, 0.65), 0 0 30px rgba(246, 38, 175, 0.2);
  border-color: rgba(85, 255, 85, 0.52);
}

.card:hover::after,
.card:focus-visible::after {
  opacity: 1;
}

.leaflet-popup.ironfuel-popup .leaflet-popup-content-wrapper,
.leaflet-popup.ironfuel-popup .leaflet-popup-tip {
  background: transparent;
  box-shadow: none;
  border: none;
}

.leaflet-popup.ironfuel-popup .leaflet-popup-tip {
  display: none;
}

.leaflet-popup.ironfuel-popup .leaflet-popup-content {
  margin: 0;
  padding: 0;
}

.leaflet-popup.ironfuel-popup .leaflet-popup-close-button {
  display: none;
}

.code-body {
  padding: 1rem 1.4rem 1.2rem;
  display: grid;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: radial-gradient(circle at 20% -20%, rgba(246, 38, 175, 0.18), transparent 55%),
              radial-gradient(circle at 120% 50%, rgba(85, 255, 85, 0.16), transparent 65%),
              linear-gradient(140deg, rgba(13, 18, 42, 0.93), rgba(8, 11, 28, 0.95));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.code-body p {
  margin: 0;
}

.code-body .price-line {
  color: var(--text-primary);
  font-weight: 600;
}

.code-body .alt-line {
  color: #94f1c6;
}

.code-body .distance-line {
  color: var(--text-muted);
}

.code-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(113, 61, 253, 0.28);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 768px) {
  .panel {
    padding: 1.5rem;
  }

  #map-section {
    height: auto;
  }

  #map {
    min-height: 360px;
  }

  #stations-list.row .station-item {
    flex: 1 1 100%;
  }
}
