@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@700&family=Syne:wght@400;600;700;800&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #07090f;
  --s1: #0d1117;
  --s2: #121a27;
  --border: #1c2a3a;
  --acc: #e8ff47;
  --blue: #38bdf8;
  --green: #4ade80;
  --red: #f87171;
  --orange: #fb923c;
  --purple: #a78bfa;
  --pink: #f472b6;
  --txt: #dde6f0;
  --muted: #4a6278;
  --font: 'Syne', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --radius: 8px;
  --sidebar: 340px;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --s1: #ffffff;
  --s2: #edf2f7;
  --border: #e2e8f0;
  --acc: #8a7400;
  --blue: #0284c7;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --purple: #7c3aed;
  --pink: #db2777;
  --txt: #1e293b;
  --muted: #64748b;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--txt); display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }

header {
  height: 54px;
  flex-shrink: 0;
  background: var(--s1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 900;
  position: relative;
}

.logo {
  display: flex;
  align-items: center;
  font-family: 'Space Grotesk', var(--font);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.04em;
  user-select: none;
}
.logo-accent { color: var(--acc); }

nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  border: none; background: transparent;
  transition: color 0.15s, background 0.15s;
  display: flex; align-items: center; gap: 6px;
}
.nav-link:hover { color: var(--txt); background: var(--s2); }
.nav-link.active { color: var(--acc); background: rgba(232,255,71,0.08); }

.status-pill {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.dot.loading { background: var(--orange); animation: pulse 1.5s infinite; }
.dot.error { background: var(--red); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.app-body { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--s1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sb-block { padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); }
.sb-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; margin-bottom: 0.6rem; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 11px;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--acc); }
.stat-val { font-family: var(--mono); font-size: 1.2rem; font-weight: 500; line-height: 1; }
.stat-lbl { font-size: 0.65rem; color: var(--muted); margin-top: 3px; }

.fuel-tabs { display: flex; gap: 3px; background: var(--bg); border-radius: 9px; padding: 3px; }
.fuel-tab {
  padding: 4px 11px; border-radius: 6px; font-size: 0.72rem; font-weight: 700;
  border: none; color: var(--muted); background: transparent;
  transition: all 0.15s; letter-spacing: 0.02em;
}
.fuel-tab:hover { color: var(--txt); }
.fuel-tab.active { background: var(--acc); color: #000; }

.filter-row { display: flex; gap: 6px; }
.filter-select {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--txt);
  border-radius: var(--radius); padding: 5px 9px; font-size: 0.72rem;
  font-family: var(--font); outline: none; cursor: pointer;
}
.filter-select:focus { border-color: var(--acc); }

.chart-zone {
  flex: 1; padding: 0.9rem 1.1rem;
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-canvas-wrap { flex: 1; position: relative; min-height: 0; }

.range-nav { display: flex; gap: 3px; }
.range-btn {
  padding: 3px 9px; border-radius: 5px; font-size: 0.67rem; font-weight: 700;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font-family: var(--font); transition: all 0.15s;
}
.range-btn:hover, .range-btn.active { background: var(--acc); border-color: var(--acc); color: #000; }

.station-list { height: 200px; overflow-y: auto; padding: 0 1.1rem 0.9rem; }
.station-list::-webkit-scrollbar { width: 3px; }
.station-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.station-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
  transition: background 0.12s; margin-bottom: 2px;
}
.station-item:hover { background: var(--bg); }
.station-item.active { background: var(--s2); }
.station-name { font-size: 0.75rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 185px; }
.station-sub { font-size: 0.65rem; color: var(--muted); }
.station-price { font-family: var(--mono); font-size: 0.82rem; color: var(--acc); white-space: nowrap; }

#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

.map-search-wrap {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 500; width: 280px;
}
.map-search {
  width: 100%; background: var(--s1); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 18px;
  font-size: 0.8rem; color: var(--txt); font-family: var(--font);
  outline: none; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: border-color 0.2s;
}
.map-search:focus { border-color: var(--acc); }
.map-search::placeholder { color: var(--muted); }

.map-legend {
  position: absolute; bottom: 26px; right: 12px; z-index: 500;
  background: var(--s1); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 13px; font-size: 0.7rem;
}
.legend-title { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em; margin-bottom: 6px; font-size: 0.6rem; }
.legend-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

#toast {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  z-index: 600; border-radius: 9px; padding: 9px 16px;
  font-size: 0.75rem; text-align: center; max-width: 400px;
  display: none; pointer-events: none;
}
#toast.info { background: #1e3a1e; border: 1px solid #166534; color: var(--green); }
#toast.error { background: #3b0f0f; border: 1px solid #7f1d1d; color: var(--red); }

#loader {
  position: fixed; inset: 0; background: var(--bg); z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  transition: opacity 0.5s;
}
#loader.out { opacity: 0; pointer-events: none; }
.loader-ring {
  width: 48px; height: 48px; border: 3px solid var(--border);
  border-top-color: var(--acc); border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 0.78rem; color: var(--muted); }
.loader-prog { width: 200px; height: 2px; background: var(--border); border-radius: 999px; overflow: hidden; }
.loader-bar { height: 100%; background: var(--acc); width: 0%; transition: width 0.3s; }

.leaflet-tile { filter: brightness(0.65) saturate(0.4) invert(1) hue-rotate(200deg); }
[data-theme="light"] .leaflet-tile { filter: none; }
[data-theme="light"] .leaflet-popup-content-wrapper {
  background: #fff !important; color: var(--txt) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12) !important;
}
[data-theme="light"] .leaflet-popup-tip { background: #fff !important; }
[data-theme="light"] .leaflet-popup-close-button { color: var(--muted) !important; }
.leaflet-popup-content-wrapper {
  background: var(--s2) !important; color: var(--txt) !important;
  border: 1px solid var(--border) !important; border-radius: 12px !important;
  box-shadow: 0 20px 50px rgba(0,0,0,0.7) !important;
  font-family: var(--font) !important;
}
.leaflet-popup-tip { background: var(--s2) !important; }
.leaflet-popup-close-button { color: var(--muted) !important; font-size: 18px !important; top: 8px !important; right: 10px !important; }

.popup-inner { padding: 2px; min-width: 220px; }
.popup-title { font-weight: 800; font-size: 0.92rem; margin-bottom: 2px; }
.popup-addr { font-size: 0.68rem; color: var(--muted); margin-bottom: 10px; line-height: 1.4; }
.popup-badge {
  display: inline-block; font-size: 0.6rem; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; margin-left: 6px;
  background: var(--s1); color: var(--blue); vertical-align: middle;
}
.popup-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.popup-price { background: var(--bg); border-radius: 7px; padding: 7px 9px; text-align: center; border: 1px solid var(--border); }
.popup-fuel { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.06em; }
.popup-val { font-family: var(--mono); font-size: 0.88rem; margin-top: 2px; }

.predict-page {
  flex: 1; overflow-y: auto; padding: 1.5rem;
  display: none; background: var(--bg);
}
.predict-page.visible { display: block; }

.predict-header { margin-bottom: 1.5rem; }
.predict-header h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 4px; }
.predict-header p { font-size: 0.78rem; color: var(--muted); }

.predict-controls {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-bottom: 1.5rem;
}

.predict-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 900px) { .predict-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--s1); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.1rem;
}
.card-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; margin-bottom: 0.8rem; }

.model-stats { display: flex; flex-direction: column; gap: 8px; }
.model-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.model-row:last-child { border-bottom: none; }
.model-key { font-size: 0.75rem; color: var(--muted); }
.model-val { font-family: var(--mono); font-size: 0.78rem; }

.trend-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  margin-top: 0.5rem;
}
.trend-badge.up   { background: rgba(248,113,113,0.15); color: var(--red);    border: 1px solid rgba(248,113,113,0.3); }
.trend-badge.down { background: rgba(74,222,128,0.15);  color: var(--green);  border: 1px solid rgba(74,222,128,0.3); }
.trend-badge.flat { background: rgba(232,255,71,0.10);  color: var(--acc);    border: 1px solid rgba(232,255,71,0.2); }

.predict-table { width: 100%; border-collapse: collapse; }
.predict-table th, .predict-table td {
  padding: 7px 10px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 0.75rem;
}
.predict-table th { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.62rem; }
.predict-table td:last-child { font-family: var(--mono); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius); border: none;
  font-size: 0.78rem; font-weight: 700; font-family: var(--font);
  transition: all 0.15s; cursor: pointer;
}
.btn-primary { background: var(--acc); color: #000; }
.btn-primary:hover { background: #d4eb30; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--txt); border-color: var(--txt); }

.feat-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.feat-name { font-size: 0.68rem; color: var(--muted); min-width: 90px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feat-bar-wrap { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.feat-bar { height: 100%; background: var(--acc); border-radius: 3px; transition: width 0.4s ease; }
.feat-val { font-size: 0.65rem; font-family: var(--mono); color: var(--txt); min-width: 42px; text-align: right; }

.theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--muted);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; transition: all 0.2s; margin-left: 4px;
}
.theme-toggle:hover { color: var(--acc); border-color: var(--acc); }

.geo-btn {
  position: absolute; bottom: 26px; left: 12px; z-index: 500;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--s1); border: 1px solid var(--border); color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: all 0.2s;
}
.geo-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.geo-btn.loading { animation: pulse 1s infinite; }

.compare-btn {
  padding: 3px 9px; border-radius: 5px; font-size: 0.67rem; font-weight: 700;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font-family: var(--font); transition: all 0.15s; cursor: pointer;
}
.compare-btn:hover { color: var(--txt); border-color: var(--txt); }
.compare-btn.active { background: var(--purple); border-color: var(--purple); color: #fff; }

.burger {
  display: none; background: none; border: none; color: var(--txt);
  font-size: 1.4rem; padding: 4px; cursor: pointer;
}

@media (max-width: 768px) {
  header { padding: 0 0.75rem; gap: 6px; }
  .status-pill { display: none; }
  .burger { display: flex; }

  .app-body { flex-direction: column; }

  .sidebar {
    position: fixed; top: 54px; left: 0; bottom: 0; z-index: 800;
    width: 100%; max-width: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  #map-container { flex: 1; width: 100%; min-height: 0; }

  .map-search-wrap { width: calc(100% - 24px); max-width: 340px; }
  .map-legend { bottom: 12px; right: 8px; font-size: 0.65rem; padding: 7px 10px; }

  .station-list { height: 160px; }
  .chart-zone { min-height: 180px; max-height: 220px; }

  .predict-layout { padding: 1rem; }
  .predict-header h2 { font-size: 1.1rem; }

  .predict-controls {
    flex-direction: column; align-items: stretch; gap: 8px;
  }
  .predict-controls .fuel-tabs { overflow-x: auto; flex-shrink: 0; }
  .predict-controls .filter-select { max-width: 100% !important; }
  .predict-controls .btn { width: 100%; justify-content: center; }

  .predict-grid { grid-template-columns: 1fr; }

  .fuel-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .fuel-tab { flex-shrink: 0; }

  .popup-inner { min-width: 180px; }
  .popup-prices { grid-template-columns: 1fr 1fr; gap: 4px; }

  .filter-row { flex-direction: column; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 5px; }
  .stat-val { font-size: 1rem; }
}

@media (max-width: 480px) {
  header { height: 48px; }
  .logo { font-size: 0.92rem; }
  .nav-link { padding: 5px 10px; font-size: 0.72rem; }

  .sidebar { top: 48px; }

  .predict-layout { padding: 0.75rem; }
  .predict-header h2 { font-size: 1rem; }
  .card { padding: 0.85rem; }

  .feat-name { min-width: 70px; font-size: 0.62rem; }
}
