/* Planificateur GPX – feuille de style unique, responsive (mobile d'abord pour le contenu, grille desktop ≥ 900 px). */

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #1d4ed8;
  --primary-fg: #ffffff;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 8px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
  --topbar-h: 52px;
  --sidebar-w: 400px;
  --elev-h: 170px;
  --chart-fg: #334155;
  --chart-grid: #e2e8f0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111827;
    --fg: #e5e7eb;
    --muted: #94a3b8;
    --line: #1f2937;
    --primary: #3b82f6;
    --chart-fg: #cbd5e1;
    --chart-grid: #1f2937;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
a { color: var(--primary); }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
h4 { font-size: 13px; margin: 8px 0 4px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.hint.warn, .warn { color: var(--warn); }
.hint.error, .error { color: var(--danger); }
.empty { color: var(--muted); margin: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
input[type="text"], input[type="search"], input[type="url"], input[type="email"], input[type="number"], select {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="range"] { width: 100%; accent-color: var(--primary); }

/* Boutons */
.btn {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 2px; min-height: 32px;
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.active { background: color-mix(in srgb, var(--primary) 15%, var(--panel)); border-color: var(--primary); }
.btn.icon { padding: 4px 8px; justify-content: center; min-width: 32px; }
.btn.sm { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.btn.icon.sm { min-width: 28px; padding: 2px 4px; }
.btn.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--primary); text-align: left; white-space: normal; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.badge:empty { display: none; }

/* Barre du haut */
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: #1e3a8a; color: #fff; box-shadow: var(--shadow); z-index: 1000; position: relative;
}
.brand { font-weight: 700; white-space: nowrap; }
.doc-name { background: rgba(255, 255, 255, .12) !important; color: #fff !important; border-color: transparent !important; width: 220px; font-weight: 600; }
.doc-name:focus { background: rgba(255, 255, 255, .22) !important; }
.search { position: relative; display: flex; gap: 4px; flex: 1; max-width: 360px; }
.search input { flex: 1; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--panel); color: var(--fg); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto;
}
.search-results li { display: flex; align-items: center; gap: 4px; padding: 2px; }
.search-results .result { flex: 1; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 6px; cursor: pointer; border-radius: 4px; }
.search-results .result:hover { background: var(--bg); }
.toolbar { display: flex; gap: 6px; margin-left: auto; }
.topbar .btn:not(.primary) { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .25); }
.topbar .btn.primary { background: #fff; color: #1e3a8a; border-color: #fff; }

/* Mise en page */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
.sidebar { order: -1; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.map-area { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#map { flex: 1; min-height: 200px; z-index: 0; }

.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; white-space: nowrap; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 6px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.tab.active { color: var(--fg); border-bottom-color: var(--primary); font-weight: 600; }
.tab[data-tab="settings"] { flex: 0 0 48px; }
.tab-panels { flex: 1; overflow-y: auto; }
.panel { display: none; padding: 12px; }
.panel.active { display: block; }
.block { padding: 10px 0 14px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }

/* Profils */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; cursor: pointer; user-select: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip.active, .chip:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--panel)); font-weight: 600; }
.chip:has(input:focus-visible) { outline: 2px solid var(--primary); }
.custom-profile { margin-top: 8px; }
.custom-profile summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.custom-profile input { width: 100%; margin-top: 4px; }
.pref { margin: 8px 0; }
.pref-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.pref-head output { color: var(--primary); font-weight: 600; white-space: nowrap; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 12px 0 4px; }
.seg { flex: 1; border: 0; background: var(--panel); color: inherit; font: inherit; padding: 8px 4px; cursor: pointer; }
.seg + .seg { border-left: 1px solid var(--line); }
.seg.active { background: var(--primary); color: #fff; font-weight: 600; }

/* Points de passage */
.wp-list { list-style: none; margin: 0; padding: 0; }
.wp-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-top: 2px solid transparent; }
.wp-item.drop { border-top-color: var(--primary); }
.wp-item.dragging { opacity: .4; }
.handle { cursor: grab; color: var(--muted); user-select: none; letter-spacing: -2px; }
.wp-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wp-main small { color: var(--muted); font-size: 11px; }
.wp-name { width: 100%; padding: 3px 6px !important; }
.wp-actions { display: flex; gap: 2px; }
.wp {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font: 700 12px/1 system-ui, sans-serif; color: #fff; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.wp-btn { flex: none; cursor: pointer; padding: 0; }
.wp-start { background: #16a34a; }
.wp-end { background: #dc2626; }
.wp-via { background: #2563eb; }
.wp-poi { background: #7c3aed; }
.wp-icon { background: none; border: 0; }
.wp-popup { display: flex; flex-direction: column; gap: 6px; }

/* Statistiques */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; }
.stat-v { font-weight: 700; font-size: 15px; }
.stat-l { color: var(--muted); font-size: 11px; }
.status { color: var(--muted); display: flex; align-items: center; gap: 6px; margin: 0 0 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.breakdown { margin-bottom: 10px; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--line); }
.bar span { display: block; height: 100%; }
.legend { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; }
.legend i, .lg i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend small { color: var(--muted); }

.alerts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.alert { padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.alert-danger { background: color-mix(in srgb, var(--danger) 12%, var(--panel)); }
.alert-warning { background: color-mix(in srgb, #f59e0b 16%, var(--panel)); }
.alert-info { background: color-mix(in srgb, var(--primary) 8%, var(--panel)); }
.alert .btn.link { color: inherit; text-decoration: underline dotted; }

/* POI */
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; margin: 8px 0; }
.cat { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.cat input { accent-color: var(--c); }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list-head h3 { margin: 0; }
.list-head select { max-width: 60%; }
.poi-list { list-style: none; padding: 0; margin: 8px 0 0; }
.poi-row { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.poi-main { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 6px 2px; cursor: pointer; }
.poi-text { display: flex; flex-direction: column; min-width: 0; }
.poi-text b, .poi-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poi-text small { color: var(--muted); font-size: 12px; }
.poi-ico { flex: none; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--c) 18%, var(--panel)); }
.poi-actions { display: flex; gap: 2px; }
.poi-icon { background: none; border: 0; }
.poi {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px;
  background: #fff; border: 2px solid var(--c); box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.poi-selected { box-shadow: 0 0 0 3px #facc15, 0 1px 3px rgba(0, 0, 0, .35); }
.poi-card { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.poi-title { font-size: 14px; }
.hours { color: var(--ok); }
.osm-link { font-size: 11px; margin-top: 4px; }
progress { width: 100%; margin-top: 8px; }

/* Projets / réglages */
.project-list { list-style: none; padding: 0; margin: 0; }
.project { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.project.current .project-main b::after { content: " •"; color: var(--primary); }
.project-main { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; background: none; border: 0; color: inherit; font: inherit; padding: 8px 2px; cursor: pointer; }
.project-main small { color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; font-size: 13px; }

/* Carte : outils superposés */
.map-tools { position: absolute; top: 80px; left: 10px; z-index: 500; display: flex; flex-direction: column; gap: 6px; }
.map-btn { background: var(--panel); box-shadow: var(--shadow); width: 34px; height: 34px; }
.map-status {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 600; background: var(--panel);
  padding: 6px 12px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13px;
}
.color-legend {
  position: absolute; right: 10px; bottom: calc(var(--elev-h) + 44px); z-index: 500; background: var(--panel);
  padding: 6px 8px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 12px; max-width: 260px;
}
.legend-items { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; }
.lg { white-space: nowrap; }

/* Profil altimétrique */
.elevation { flex: none; background: var(--panel); border-top: 1px solid var(--line); z-index: 1; }
.elevation-head { display: flex; align-items: center; gap: 12px; padding: 4px 10px; font-size: 12px; }
.elevation-head .btn.link { color: var(--fg); font-weight: 600; white-space: nowrap; }
.range-info { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart { position: relative; height: var(--elev-h); }
.chart canvas { position: absolute; inset: 0; }
.chart canvas:last-of-type { touch-action: pan-y; cursor: crosshair; }
.elevation.collapsed .chart { display: none; }
.map-area:has(.elevation.collapsed) .color-legend { bottom: 44px; }
.chart-tip {
  position: absolute; display: none; pointer-events: none; background: rgba(15, 23, 42, .9); color: #fff;
  padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
}

/* Boîtes de dialogue */
.dialog { border: 0; border-radius: 12px; padding: 0; max-width: min(520px, 94vw); box-shadow: var(--shadow); background: var(--panel); color: var(--fg); }
.dialog form { padding: 16px 18px; }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.dialog fieldset label { display: flex; gap: 6px; align-items: flex-start; }
.dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
.dialog::backdrop { background: rgba(15, 23, 42, .45); }

/* Notifications */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 6px; width: min(460px, 92vw); pointer-events: none; }
.toast { pointer-events: auto; background: #1e293b; color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; animation: toast-in .2s ease-out; }
.toast-error { background: #991b1b; }
.toast-warning { background: #92400e; }
.toast-success { background: #166534; }
.toast.leaving { opacity: 0; transition: opacity .25s; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; }

/* ---------- Tablette / mobile ---------- */
@media (max-width: 900px) {
  :root { --sidebar-w: 340px; }
  .brand-name { display: none; }
  .doc-name { width: 140px; }
  .topbar .lbl { display: none; }
}

@media (max-width: 700px) {
  body { overflow: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 6px 8px; gap: 6px; }
  .doc-name { flex: 1; width: auto; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .toolbar { margin-left: 0; }
  .layout { display: flex; flex-direction: column; }
  .map-area { height: 62vh; height: 62svh; flex: none; }
  :root { --elev-h: 120px; }
  .sidebar { order: 0; border-right: 0; border-top: 1px solid var(--line); }
  .tab-panels { overflow: visible; }
  .tabs { position: sticky; top: 0; background: var(--panel); z-index: 5; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .color-legend { bottom: auto; top: 10px; right: 56px; max-width: 46vw; }
  .color-legend .legend-items { display: none; }
  .map-area:has(.elevation.collapsed) .color-legend { bottom: auto; }
  .map-tools { top: 80px; }
  .btn.icon.sm { min-width: 34px; min-height: 34px; }
}

.noscript { padding: 20px; }
