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

:root {
  --bg0:   #0a0f1e;
  --bg1:   #111827;
  --bg2:   #1f2937;
  --bg3:   #374151;
  --text:  #f1f5f9;
  --muted: #94a3b8;
  --dim:   #64748b;
  --border:#1f2937;
  --green: #22c55e;
  --orange:#f97316;
  --yellow:#eab308;
  --red:   #ef4444;
  --blue:  #3b82f6;
  --blue2: #2563eb;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg0);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at 50% 40%, #1a2744 0%, var(--bg0) 70%);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 16px;
  padding: 44px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 32px 64px rgba(0,0,0,.6);
}

.login-icon { font-size: 40px; margin-bottom: 12px; }
.login-card h1 { font-size: 26px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 28px; }

.login-card input {
  display: block; width: 100%;
  padding: 11px 14px;
  background: var(--bg1);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
  transition: border-color .15s;
}
.login-card input:focus { outline: none; border-color: var(--blue); }

.login-card button[type=submit] {
  width: 100%; padding: 11px;
  background: var(--blue);
  color: #fff;
  border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 4px;
  transition: background .15s;
}
.login-card button[type=submit]:hover { background: var(--blue2); }
.login-card button[type=submit]:disabled { opacity: .6; cursor: default; }

.login-error { color: #f87171; font-size: 13px; margin-top: 12px; min-height: 20px; }

/* ── Dashboard shell ────────────────────────────────── */
#dashboard { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ─────────────────────────────────────────── */
#header {
  display: flex; align-items: center; gap: 16px;
  height: 58px; padding: 0 16px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-brand {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.brand-icon { font-size: 20px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -.3px; }

#stats-bar {
  display: flex; gap: 6px;
  flex: 1; justify-content: center;
}

.stat-card {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 14px;
  min-width: 72px;
}
.stat-num  { font-size: 20px; font-weight: 700; line-height: 1.3; }
.stat-label{ font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }

.stat-card.available  .stat-num { color: var(--green); }
.stat-card.queue      .stat-num { color: var(--orange); }
.stat-card.low        .stat-num { color: var(--yellow); }
.stat-card.unavailable.stat-num { color: var(--red); }
.stat-card.unknown    .stat-num { color: #6b7280; }
.stat-card.total      .stat-num { color: var(--muted); }
.stat-card.pct        .stat-num { color: #a78bfa; }

.stat-card[data-modal] {
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.stat-card[data-modal]:hover {
  border-color: #475569;
  transform: translateY(-1px);
}

/* ── Card tooltip ───────────────────────────────────── */
.card-tooltip {
  position: fixed;
  z-index: 1500;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  padding: 10px 13px;
  min-width: 190px;
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
  pointer-events: none;
  font-size: 12px;
}

.tt-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dim);
  margin-bottom: 7px;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
  color: var(--text);
  line-height: 1.5;
}

.tt-cnt {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

.modal-box {
  background: var(--bg1);
  border: 1px solid var(--bg3);
  border-radius: 14px;
  width: min(880px, 100%);
  padding: 24px 28px 28px;
  box-shadow: 0 40px 80px rgba(0,0,0,.7);
  display: flex; flex-direction: column; gap: 20px;
}

.modal-hd {
  display: flex; align-items: center; gap: 16px;
}

.modal-title {
  font-size: 18px; font-weight: 700;
  flex: 1;
  color: var(--text);
}

.modal-chart-wrap {
  position: relative;
  height: 420px;
}

/* ── Station history modal ──────────────────────────── */
.st-head { flex: 1; min-width: 0; }
.st-addr { font-size: 12px; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.st-body { display: flex; flex-direction: column; gap: 20px; }

.st-loading, .st-empty {
  text-align: center; padding: 48px 0;
  color: var(--dim); font-size: 14px;
}

.st-section { display: flex; flex-direction: column; gap: 6px; }

.st-section-title {
  font-size: 11px; font-weight: 600;
  color: var(--dim); text-transform: uppercase; letter-spacing: .07em;
}

.st-canvas-wrap { position: relative; width: 100%; }

.st-axis {
  position: relative; height: 18px; margin-top: 2px;
}
.st-axis span {
  position: absolute; font-size: 10px; color: var(--dim);
  transform: translateX(-50%); white-space: nowrap;
}
.st-axis span:last-child { transform: translateX(-100%); }

.st-fuel-labels {
  display: flex; flex-direction: column;
  position: absolute; left: 0; top: 0;
  width: 32px;
}
.st-fuel-label {
  font-size: 11px; color: var(--dim);
  display: flex; align-items: center;
  justify-content: flex-end;
  padding-right: 5px;
}

/* Summary bar */
.st-bar {
  display: flex; height: 22px; border-radius: 4px;
  overflow: hidden; gap: 1px;
}
.st-bar-seg {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: #fff;
  min-width: 2px; overflow: hidden;
}

.st-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 6px;
}
.st-legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted);
}
.st-legend-dot {
  width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0;
}

/* Shared crosshair tooltip (inside station modal) */
.st-tip {
  position: absolute; z-index: 10;
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: 7px; padding: 8px 11px;
  font-size: 12px; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  white-space: nowrap;
}
.st-tip-time { font-size: 10px; color: var(--dim); margin-bottom: 4px; }
.st-tip-status { margin-bottom: 3px; }
.st-tip-fuels { font-size: 11px; color: var(--muted); }

/* popup button */
.popup-hist-btn {
  margin-top: 9px; width: 100%;
  padding: 6px 0;
  background: var(--blue); color: #fff;
  border: none; border-radius: 6px;
  font-size: 12px; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.popup-hist-btn:hover { background: var(--blue2); }

.header-right {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}

.update-time { font-size: 12px; color: var(--dim); }

.icon-btn {
  background: none; border: 1px solid var(--bg3);
  color: var(--muted); border-radius: 6px;
  width: 30px; height: 30px; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.icon-btn:hover { background: var(--bg2); color: var(--text); }

.outline-btn {
  padding: 5px 12px;
  background: none; border: 1px solid var(--bg3);
  color: var(--muted); border-radius: 6px;
  font-size: 13px; cursor: pointer; transition: .15s;
}
.outline-btn:hover { background: var(--bg2); color: var(--text); }

/* ── Workspace ──────────────────────────────────────── */
.workspace {
  display: flex; flex: 1; overflow: hidden;
}

/* ── Map ────────────────────────────────────────────── */
#map-wrap { position: relative; flex: 1; }

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

#map-legend {
  position: absolute; bottom: 28px; left: 10px; z-index: 1000;
  background: rgba(17,24,39,.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex; flex-direction: column; gap: 5px;
}
.legend-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Leaflet popup dark */
.leaflet-popup-content-wrapper {
  background: var(--bg2) !important;
  color: var(--text) !important;
  border: 1px solid var(--bg3) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.5) !important;
}
.leaflet-popup-tip-container .leaflet-popup-tip { background: var(--bg2) !important; }
.leaflet-popup-close-button { color: var(--muted) !important; }

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg0);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }

.panel {
  background: var(--bg1);
  padding: 14px 14px 16px;
  flex-shrink: 0;
}

.panel-hd {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-title {
  font-size: 11px; font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.panel-hint { font-size: 11px; color: var(--dim); }

.tab-group { display: flex; gap: 3px; }

.tab {
  padding: 2px 9px; font-size: 12px;
  background: none; border: 1px solid var(--bg3);
  color: var(--muted); border-radius: 4px;
  cursor: pointer; transition: .15s;
}
.tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.tab:not(.active):hover { border-color: var(--blue); color: var(--text); }

.chart-wrap {
  position: relative;
  width: 100%;
}

.chart-wrap canvas { display: block; }

/* ── Chips ──────────────────────────────────────────── */
.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  padding: 3px 10px; font-size: 12px;
  background: var(--bg0); border: 1px solid var(--bg3);
  color: var(--muted); border-radius: 20px;
  cursor: pointer; transition: .15s;
  white-space: nowrap;
}
.chip:hover { border-color: var(--blue); color: var(--text); }
.chip.active { background: #1d4ed8; border-color: var(--blue); color: #fff; }

.link-btn {
  background: none; border: none;
  color: var(--blue); font-size: 12px;
  cursor: pointer; padding: 0;
}
.link-btn:hover { text-decoration: underline; }
