/* ─── Reset / base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f111a;
  --panel-bg: #161b27;
  --panel-border: #1e2535;
  --surface: #1c2235;
  --surface-hover: #232a3e;
  --text: #dde3f0;
  --text-muted: #7a8499;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --info: #60a5fa;
  --radius: 8px;
  --radius-sm: 5px;
  --transition-fast: 0.15s ease;
  --transition-med: 0.25s ease;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
}

html, body, #root {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Layout ────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.map-container {
  width: 100%;
  height: 100%;
}

/* ─── Control panel ─────────────────────────────────────────────────── */
.control-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

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

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

.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.api-section {
  margin-top: auto;
  border-top: 1px solid var(--panel-border);
  border-bottom: none;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

/* ─── Search ────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
}

.input-text {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.input-text:focus {
  border-color: var(--accent);
}

.input-text::placeholder {
  color: var(--text-muted);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  list-style: none;
  z-index: 1000;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.search-dropdown li {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
  border-bottom: 1px solid var(--panel-border);
  transition: background 0.1s;
}

.search-dropdown li:last-child { border-bottom: none; }
.search-dropdown li:hover { background: var(--surface-hover); }

.coord-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.coord-text {
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
}

.btn-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
}

.btn-clear:hover { color: var(--danger); }

.hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* ─── Mode selector ─────────────────────────────────────────────────── */
.mode-selector {
  display: flex;
  gap: 6px;
}

.btn-mode {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-mode:hover { background: var(--surface-hover); color: var(--text); }

.btn-mode.active { background: rgba(59,130,246,0.15); border-color: var(--accent); color: var(--accent); }
.btn-mode.active[data-mode="auto"]       { background: rgba(251,191,36,.14); border-color: #fbbf24; color: #fbbf24; }
.btn-mode.active[data-mode="bicycle"]    { background: rgba(34,211,238,.14); border-color: #22d3ee; color: #22d3ee; }
.btn-mode.active[data-mode="pedestrian"] { background: rgba(74,222,128,.14); border-color: #4ade80; color: #4ade80; }

.mode-icon { font-size: 18px; }
.mode-label { font-size: 11px; font-weight: 600; }

/* ─── Time ranges ───────────────────────────────────────────────────── */
.time-ranges {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.time-range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.range-input {
  width: 60px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 5px 6px;
  font-size: 13px;
  text-align: center;
  outline: none;
}

.range-input:focus { border-color: var(--accent); }

.range-preview {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}

.btn-icon {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-add {
  background: none;
  border: 1px dashed var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  font-size: 12px;
  text-align: center;
  transition: all 0.15s;
  width: 100%;
}

.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  flex: 1;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover { background: var(--surface-hover); border-color: var(--accent); }

.export-row {
  display: flex;
  gap: 8px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-align: left;
  transition: color 0.15s;
}

.btn-link:hover { color: var(--text); }

.key-ok { color: var(--success); }

/* ─── Error ─────────────────────────────────────────────────────────── */
.error-msg {
  font-size: 12px;
  color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  line-height: 1.4;
}

/* ─── Legend ────────────────────────────────────────────────────────── */
.legend {
  position: absolute;
  bottom: 32px;
  left: 16px;
  background: rgba(15, 17, 26, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: all;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
  border-radius: var(--radius-sm);
  padding: 1px 2px;
}
.legend-item:hover { opacity: 0.8; }
.legend-item.hidden { opacity: 0.35; }

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  opacity: 0.85;
  flex-shrink: 0;
}

.legend-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* ─── Splash screen ─────────────────────────────────────────────────── */
.splash {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.splash-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--panel-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Splash amélioré - anneaux concentriques */
.splash-rings {
  width: 72px;
  height: 72px;
  position: relative;
  margin: 0 auto;
}
.splash-ring {
  border-radius: 50%;
  border: 2px solid var(--accent);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: splash-radiate 2.2s ease-out infinite;
  opacity: 0;
}
.splash-ring:nth-child(1) { animation-delay: 0s; }
.splash-ring:nth-child(2) { animation-delay: 0.55s; }
.splash-ring:nth-child(3) { animation-delay: 1.1s; }
@keyframes splash-radiate {
  0%   { width: 10px; height: 10px; opacity: 0.9; }
  80%  { opacity: 0.2; }
  100% { width: 72px; height: 72px; opacity: 0; }
}

.splash-error .splash-content { color: var(--danger); }

.splash-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── MapLibre overrides ────────────────────────────────────────────── */
.maplibregl-ctrl-group {
  background: rgba(15, 17, 26, 0.9) !important;
  border: 1px solid var(--panel-border) !important;
}

.maplibregl-ctrl-group button {
  background: transparent !important;
}

.maplibregl-ctrl-group button:hover {
  background: var(--surface) !important;
}

.maplibregl-ctrl-attrib {
  background: rgba(15, 17, 26, 0.7) !important;
  color: var(--text-muted) !important;
}

.maplibregl-ctrl-attrib a { color: var(--text-muted) !important; }

/* ─── Status dot ────────────────────────────────────────────────────── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot--ready { background: #4ade80; box-shadow: 0 0 6px rgba(74,222,128,.6); }
.status-dot--starting { background: #fbbf24; animation: pulse-dot 1.2s ease-in-out infinite; }
.status-dot--error { background: #f87171; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ─── Toast system ──────────────────────────────────────────────────── */
.toast-container { position: absolute; bottom: 48px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 10px 14px; border-radius: var(--radius); font-size: 12px; font-weight: 500; backdrop-filter: blur(8px); border: 1px solid; animation: toast-enter .25s ease forwards; pointer-events: all; display: flex; align-items: center; gap: 8px; min-width: 180px; }
.toast--success { background: rgba(74,222,128,.12); border-color: rgba(74,222,128,.3); color: #4ade80; }
.toast--error   { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.3); color: #f87171; }
.toast--info    { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.3); color: #60a5fa; }
.toast-msg { flex: 1; }
.toast-close { background: none; border: none; color: inherit; cursor: pointer; opacity: 0.6; font-size: 14px; line-height: 1; padding: 0; }
.toast-close:hover { opacity: 1; }
@keyframes toast-enter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Map loading bar ───────────────────────────────────────────────── */
.map-loading-overlay { position: absolute; top: 0; left: 0; right: 0; z-index: 500; pointer-events: none; }
.map-loading-bar { height: 3px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 200% 100%; animation: loading-sweep 1.2s ease-in-out infinite; }
@keyframes loading-sweep { 0% { background-position: -100% 0; } 100% { background-position: 200% 0; } }

/* ─── Map context menu ──────────────────────────────────────────────── */
.map-context-menu { position: absolute; z-index: 1500; background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.5); min-width: 210px; overflow: hidden; }
.map-context-menu button { display: block; width: 100%; padding: 9px 14px; background: none; border: none; color: var(--text); font-size: 12px; text-align: left; cursor: pointer; transition: background .1s; }
.map-context-menu button:hover { background: var(--surface-hover); }

/* ─── Isochrone hover popup ─────────────────────────────────────────── */
.iso-popup .maplibregl-popup-content { background: rgba(15,17,26,.92); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius-sm); color: var(--text); font-size: 12px; font-weight: 600; padding: 5px 10px; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.iso-popup .maplibregl-popup-tip { display: none; }

/* ─── Isochrone map labels ──────────────────────────────────────────── */
.iso-map-label { background: rgba(0,0,0,.58); backdrop-filter: blur(4px); border-radius: 4px; color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; pointer-events: none; white-space: nowrap; letter-spacing: .3px; font-family: 'Inter', system-ui, sans-serif; }

/* ─── Preset chips ──────────────────────────────────────────────────── */
.preset-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.preset-chips::-webkit-scrollbar { display: none; }
.preset-chip { flex-shrink: 0; padding: 3px 8px; background: var(--surface); border: 1px solid var(--panel-border); border-radius: 100px; color: var(--text-muted); font-size: 11px; cursor: pointer; white-space: nowrap; transition: all var(--transition-fast); }
.preset-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ─── History ───────────────────────────────────────────────────────── */
.history-toggle { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; padding: 0; width: 100%; text-align: left; display: flex; align-items: center; justify-content: space-between; }
.history-toggle:hover { color: var(--text); }
.history-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--surface); border: 1px solid var(--panel-border); border-radius: var(--radius-sm); cursor: pointer; text-align: left; width: 100%; transition: background .1s; }
.history-item:hover { background: var(--surface-hover); border-color: var(--accent); }
.history-icon { font-size: 14px; flex-shrink: 0; }
.history-label { flex: 1; font-size: 11px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.collapsible-body { max-height: 0; overflow: hidden; transition: max-height var(--transition-med), opacity var(--transition-med); opacity: 0; }
.collapsible-body.open { max-height: 500px; opacity: 1; }

/* ─── Coord copy / auto-recalc ──────────────────────────────────────── */
.btn-copy { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 0 3px; transition: color var(--transition-fast); line-height: 1; }
.btn-copy:hover { color: var(--accent); }
.auto-recalc-toggle { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none; }
.auto-recalc-toggle input { accent-color: var(--accent); }

/* ─── Error card ────────────────────────────────────────────────────── */
.error-card { display: flex; align-items: flex-start; gap: 10px; background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.2); border-radius: var(--radius); padding: 10px 12px; }
.error-icon { font-size: 16px; color: var(--danger); flex-shrink: 0; margin-top: 1px; }
.error-body { flex: 1; }
.error-title { font-size: 12px; font-weight: 600; color: var(--danger); }
.error-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; word-break: break-word; }
.btn-retry { background: none; border: 1px solid rgba(248,113,113,.3); border-radius: var(--radius-sm); color: var(--danger); font-size: 11px; padding: 4px 8px; cursor: pointer; flex-shrink: 0; transition: all var(--transition-fast); white-space: nowrap; }
.btn-retry:hover { background: rgba(248,113,113,.1); }

/* ─── Legend eye toggle ─────────────────────────────────────────────── */
.legend-eye { background: none; border: none; color: var(--text-muted); font-size: 11px; cursor: pointer; margin-left: auto; padding: 0 2px; line-height: 1; opacity: 0; transition: opacity var(--transition-fast); }
.legend:hover .legend-eye { opacity: 0.5; }
.legend-item:hover .legend-eye { opacity: 1; }
.legend-item.hidden .legend-eye { opacity: 1; color: var(--danger); }
