:root {
  --fond: #f3f5f8;
  --surface: #ffffff;
  --texte: #14181f;
  --texte2: #5a6372;
  --bord: #d5dbe3;
  --accent: #1f4e79;
  --accent-txt: #ffffff;
  --ar: #1f6f43;
  --av: #a3361f;
  --int: #6a4c93;
  --ok: #1e7a34;
  --att: #b35c00;
  --err: #c0262d;
  --alerte-fond: #fde8e8;
  --inter-fond: #f5f1fb;
  --rayon: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #11151b; --surface: #1b2129; --texte: #e8edf3; --texte2: #9aa5b4; --bord: #323b47;
    --accent: #5a9fd8; --accent-txt: #0b1520; --ar: #5cc28a; --av: #f08a6c; --int: #b79cf0;
    --ok: #5cc27a; --att: #f0a64a; --err: #ff6b6b; --alerte-fond: #3a1d20; --inter-fond: #241f30;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #11151b; --surface: #1b2129; --texte: #e8edf3; --texte2: #9aa5b4; --bord: #323b47;
  --accent: #5a9fd8; --accent-txt: #0b1520; --ar: #5cc28a; --av: #f08a6c; --int: #b79cf0;
  --ok: #5cc27a; --att: #f0a64a; --err: #ff6b6b; --alerte-fond: #3a1d20; --inter-fond: #241f30;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h2 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1rem; margin: 0; }

.barre {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-txt);
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
}
.barre h1 { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barre .retour, .barre .icone {
  color: inherit; text-decoration: none; font-size: 1.8rem; line-height: 1; padding: 0 8px;
  background: none; border: 0; cursor: pointer;
}
.barre .icone { font-size: 1.4rem; }

main { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
main.large { max-width: 1200px; }
main.avec-pied { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
main.plein { max-width: none; padding: 8px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.actions.bas { margin-top: 24px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 8px 16px;
  border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--surface); color: var(--texte);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primaire { background: var(--accent); color: var(--accent-txt); border-color: var(--accent); }
.btn.danger { color: var(--err); }
.btn-mini {
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte); border-radius: 8px;
  min-width: 40px; min-height: 36px; font: inherit; cursor: pointer;
}

.carte {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--bord);
  border-radius: var(--rayon); margin: 8px 0; padding: 10px 12px; color: var(--texte); text-decoration: none;
}
.carte > a { flex: 1; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.carte.station { flex-direction: column; align-items: stretch; gap: 2px; border-left: 4px solid var(--accent); }
.carte.alerte { border-left-color: var(--err); }
.carte span { color: var(--texte2); font-size: .9rem; }
.carte i { font-style: normal; font-weight: 600; }
.badge { font-size: .75rem; padding: 1px 6px; border-radius: 6px; color: #fff; background: var(--err); vertical-align: middle; }

.encart { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 10px 12px; margin: 12px 0; }
.encart h2 { margin-top: 0; }
.resume div { padding: 2px 0; }
.vide { color: var(--texte2); text-align: center; margin: 32px 0; }
.note { color: var(--texte2); font-size: .88rem; }
.version { color: var(--texte2); font-size: .8rem; text-align: center; }
.ok { color: var(--ok); } .att { color: var(--att); } .err { color: var(--err); }
.gros { font-size: 1.4rem; font-weight: 700; }

.pied {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--bord);
}
.pied .btn { flex: 1; padding: 8px 6px; }

/* Formulaires */
.form h2 { color: var(--accent); }
.champ { display: block; margin: 10px 0; }
.champ > span { display: block; font-size: .88rem; color: var(--texte2); margin-bottom: 3px; }
.champ small { display: block; color: var(--texte2); font-size: .8rem; margin-top: 3px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; padding: 10px; border: 1px solid var(--bord); border-radius: 8px;
  background: var(--surface); color: var(--texte);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chk { display: inline-flex; align-items: center; gap: 8px; margin: 6px 0; }
.chk input { width: 22px; height: 22px; }

/* Saisie des visées */
.visee { background: var(--surface); border: 1px solid var(--bord); border-left: 5px solid var(--accent); border-radius: var(--rayon); padding: 10px 12px; margin: 10px 0; }
.visee.ar { border-left-color: var(--ar); } .visee.ar h3 { color: var(--ar); }
.visee.av { border-left-color: var(--av); } .visee.av h3 { color: var(--av); }
.visee.int { border-left-color: var(--int); } .visee.int h3 { color: var(--int); }
.visee-tete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.lbl { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--texte2); }
.lbl input { flex: 1; font-weight: 700; }
.fils { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.fils label, .fils input { min-width: 0; }
.fils label span { display: block; font-size: .8rem; color: var(--texte2); text-align: center; }
.fils input { font-size: 22px; font-weight: 600; text-align: center; padding: 10px 4px; font-variant-numeric: tabular-nums; }
.info { font-size: .88rem; margin-top: 6px; min-height: 1.3em; color: var(--texte2); }
.info.ok { color: var(--ok); } .info.err { color: var(--err); font-weight: 600; }
.ligne-opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.ligne-opt .cap { margin-left: auto; font-size: .9rem; color: var(--texte2); }
.ligne-opt .chk { font-size: .88rem; color: var(--texte2); }
.saisie > .btn { width: 100%; }
.proc { padding-left: 20px; } .proc li { margin: 6px 0; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

/* Boussole */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.boite { background: var(--surface); border-radius: 14px; padding: 16px; width: 100%; max-width: 420px; max-height: 92vh; overflow: auto; }
.boite h2 { margin-top: 0; }
.rose { position: relative; width: 150px; height: 150px; margin: 4px auto; border: 3px solid var(--bord); border-radius: 50%; }
.rose::after { content: ""; position: absolute; left: 50%; top: -10px; margin-left: -7px; border: 7px solid transparent; border-bottom: 10px solid var(--accent); }
.aiguille { position: absolute; inset: 0; transition: transform .15s linear; }
.aiguille::before, .aiguille::after { content: ""; position: absolute; left: 50%; margin-left: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; }
.aiguille::before { top: 12px; border-bottom: 63px solid var(--err); }
.aiguille::after { bottom: 12px; border-top: 63px solid var(--texte2); }
.rose .n { position: absolute; left: 50%; top: 50%; width: 20px; margin: -10px 0 0 -10px; text-align: center; font-weight: 700; color: var(--err); }
.cap-val { text-align: center; font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Tableaux */
.tab-defil { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--bord); border-radius: 8px; background: var(--surface); }
.tab { border-collapse: collapse; width: 100%; font-size: .85rem; font-variant-numeric: tabular-nums; }
.tab th, .tab td { border: 1px solid var(--bord); padding: 4px 6px; text-align: right; white-space: nowrap; }
.tab th { background: var(--fond); font-weight: 600; text-align: center; font-size: .78rem; }
.tab td.g { text-align: left; font-weight: 600; }
.tab td.fort { font-weight: 700; }
.tab tr.inter td { background: var(--inter-fond); font-style: italic; }
.tab tr.alerte td { background: var(--alerte-fond); }
.tab tr.sep td { border-top: 2px solid var(--texte2); }
.tab tfoot td { font-weight: 700; background: var(--fond); }
.bilan { padding-left: 18px; margin: 8px 0; } .bilan li { margin: 3px 0; }

/* Croquis */
.cadre-croquis { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); height: calc(100vh - 150px); overflow: hidden; }
.cadre-croquis svg { width: 100%; height: 100%; touch-action: none; display: block; }
.cq-visee { stroke: var(--texte2); opacity: .6; }
.cq-chemin { stroke: var(--accent); }
.cq-station { fill: var(--att); }
.cq-point { fill: var(--accent); }
.cq-inter { fill: var(--int); }
.cq-txt { fill: var(--texte); } .cq-txt2 { fill: var(--texte2); }
.cq-nord { fill: var(--err); }
.cq-echelle { stroke: var(--texte); fill: var(--texte); }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* Impression */
.barre-impr { display: flex; gap: 8px; padding: 12px 16px; flex-wrap: wrap; }
.impression { padding: 0 16px 24px; }
.impression h1 { font-size: 1.3rem; }
.impression .entete { width: 100%; font-size: .85rem; margin-bottom: 10px; border-collapse: collapse; }
.impression .entete td { padding: 2px 8px 2px 0; }
.croquis-impr svg { width: 100%; height: 150mm; }
.saut { break-after: page; }
@page { size: A4 landscape; margin: 10mm; }
@media print {
  :root { --fond: #eeeeee; --surface: #fff; --texte: #000; --texte2: #444; --bord: #999; --alerte-fond: #fde0e0; --inter-fond: #f3f0f8; color-scheme: light; }
  body { background: #fff; font-size: 11px; }
  .ecran-seul { display: none !important; }
  .tab-defil { overflow: visible; border: 0; }
  .tab { font-size: 9px; } .tab th { font-size: 8px; }
  .tab th, .tab td { padding: 2px 4px; }
  .tab tr { break-inside: avoid; }
  .impression { padding: 0; }
  .bilan { font-size: 10px; }
}
