/* Modern CSS Reset & Variables */
:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #131b2e;
  --bg-card: #182238;
  --bg-card-hover: #1f2c49;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: #1e293b;
  --border-light: #334155;
  
  --brand-lukoil: #ef4444;
  --brand-tatneft: #10b981;
  --brand-gpn: #0284c7;
  --brand-opti: #06b6d4;
  --brand-default: #8b5cf6;
  
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-accent: #38bdf8;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  
  --header-height: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  font-size: 24px;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-group h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

.status-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-success);
  display: inline-block;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.status-dot.updating {
  background-color: var(--color-warning);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.1); }
}

/* Buttons */
.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
}

.btn-icon:active {
  transform: scale(0.97);
}

.btn-icon svg.icon {
  width: 16px;
  height: 16px;
}

.btn-secondary {
  padding: 10px;
}

/* Toolbar */
.toolbar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
  flex-shrink: 0;
}

.search-bar {
  display: flex;
  gap: 8px;
}

.input-wrapper {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-dim);
}

.input-wrapper input {
  width: 100%;
  height: 40px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0 36px 0 36px;
  font-size: 14px;
  color: #fff;
  transition: border-color 0.15s ease;
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
}

/* Fuel Pills Horizontal Scroll */
.pills-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.pills-scroll::-webkit-scrollbar {
  display: none;
}

.pill {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill:hover {
  color: #fff;
  border-color: var(--border-light);
}

.pill.active {
  background: var(--color-accent);
  color: #041226;
  border-color: var(--color-accent);
  font-weight: 700;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* Sub-toolbar */
.sub-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.select-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#brand-select {
  height: 34px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 0 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  accent-color: var(--color-accent);
  width: 16px;
  height: 16px;
}

/* View Mode Toggle */
.view-toggle {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
}

.toggle-btn {
  padding: 5px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toggle-btn.active {
  background: var(--bg-card);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* Default on Desktop: Show Map and Split, hide List */
#view-list-btn {
  display: none !important;
}

#view-split-btn {
  display: inline-flex !important;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Sidebar / Card List */
.sidebar-panel {
  width: 440px;
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 500;
  transition: width 0.2s ease;
}

.sidebar-panel.hidden-view {
  display: none !important;
}

.sidebar-panel.full-width {
  width: 100% !important;
  border-right: none !important;
}

.sidebar-panel.full-width .stations-list {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)) !important;
  gap: 16px !important;
  padding: 16px !important;
  align-content: start;
}

.sidebar-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-secondary);
}

.badge-accent {
  background: rgba(56, 189, 248, 0.15);
  color: var(--color-accent);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.stations-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Station Card */
.station-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  flex-shrink: 0; /* CRITICAL: Prevents cards from squishing in flex list */
}

.station-card:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.station-card.active-card {
  border-color: var(--color-accent);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.brand-lukoil { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.brand-tatneft { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.brand-gpn { background: rgba(2, 132, 199, 0.15); color: #38bdf8; border: 1px solid rgba(2, 132, 199, 0.3); }
.brand-other { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }

.distance-badge {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.card-address {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Fuel Price Grid */
.fuel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(65px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.fuel-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 4px;
  text-align: center;
}

.fuel-item.available {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.05);
}

.fuel-item.unavailable {
  opacity: 0.45;
  border-color: var(--border);
}

.fuel-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
}

.fuel-item.available .fuel-tag {
  color: var(--color-accent);
}

.fuel-price {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.fuel-price.in-stock {
  color: #34d399;
  font-size: 11px;
  font-weight: 700;
}

.fuel-limit {
  font-size: 10px;
  font-weight: 700;
  color: #f59e0b;
  margin-top: 2px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 1px 3px;
  display: block;
  text-align: center;
}

.badge-limit {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
}

/* Card Action Buttons (Navigators) */
.card-actions {
  display: flex;
  gap: 8px;
}

.nav-btn {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.nav-yandex {
  background: #fc3f1d;
  color: #fff;
}

.nav-yandex:hover {
  background: #e03212;
}

.nav-2gis {
  background: #2b9938;
  color: #fff;
}

.nav-2gis:hover {
  background: #23802e;
}

/* Card Metadata / Source Verification */
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
}

.source-tag {
  color: var(--text-dim);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.verify-link {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
}

.verify-link:hover {
  text-decoration: underline;
  color: #7dd3fc;
}

/* Map Wrapper */
.map-wrapper {
  flex: 1;
  position: relative;
  height: 100%;
}

.map-wrapper.hidden-view {
  display: none !important;
}

.map-wrapper.full-width {
  width: 100% !important;
  flex: 1 !important;
}

.map-view {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
}

/* Floating Reset Button on Map */
.floating-btn {
  position: absolute;
  bottom: 24px;
  right: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  cursor: pointer;
  transition: all 0.15s ease;
}

.floating-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
}

/* Leaflet Custom Marker Styling */
.custom-az-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px !important;
  height: 34px !important;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  border: 2px solid #fff;
  transition: transform 0.15s ease;
}

.custom-az-marker:hover {
  transform: scale(1.15);
  z-index: 10000 !important;
}

.marker-lukoil { background: var(--brand-lukoil); }
.marker-tatneft { background: var(--brand-tatneft); }
.marker-gpn { background: var(--brand-gpn); }
.marker-other { background: var(--brand-default); }
.marker-closed { background: var(--text-dim); opacity: 0.6; }

/* Custom Leaflet Popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-main) !important;
  border-radius: var(--radius-lg) !important;
  border: 1px solid var(--border-light) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 4px !important;
}

.leaflet-popup-tip {
  background: var(--bg-secondary) !important;
}

/* Responsive Styles */
@media (max-width: 900px) {
  /* On mobile: Hide Split button, show List button */
  #view-split-btn {
    display: none !important;
  }

  #view-list-btn {
    display: inline-flex !important;
  }

  .sidebar-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100%;
    border-right: none;
    display: none;
  }

  .sidebar-panel.mobile-visible {
    display: flex !important;
  }

  .map-wrapper.mobile-hidden {
    display: none !important;
  }

  .header-right .btn-text {
    display: none;
  }

  .app-header {
    padding: 0 12px;
  }

  .toolbar {
    padding: 8px 12px;
  }
}

/* Modal Overlay & Card (Lukoil API Verification) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 16px;
}

.modal-st-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.modal-st-addr {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.modal-info-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12px;
}

.info-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.info-val {
  color: var(--text-main);
  line-height: 1.4;
}

.info-val code {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-accent);
  font-family: monospace;
}

.modal-app-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 12px;
  line-height: 1.4;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-primary-modal {
  background: var(--color-accent);
  color: #041226;
  border: none;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.btn-primary-modal:hover {
  background: #7dd3fc;
}
