:root {
  --navy: #16355f;
  --blue: #1d6fb8;
  --blue-soft: #e7f0fa;
  --bg: #f2f5f9;
  --card: #ffffff;
  --ink: #1d2633;
  --muted: #6b7686;
  --line: #e2e7ee;
  --ok: #1f8a4c;
  --ok-soft: #e4f4ea;
  --warn: #9a6200;
  --warn-soft: #fff3dc;
  --bad: #c0392b;
  --dep: #1d6fb8;
  --arr: #e0682b;
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* 16 px : Safari ne zoome pas au toucher */
a { color: var(--blue); }
[hidden] { display: none !important; }

.splash { min-height: 100vh; display: grid; place-items: center; }
.splash img { width: 140px; opacity: .9; }

/* ---------- Barres ---------- */
.top {
  position: sticky; top: 0; z-index: 500;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(var(--top) + 8px) 12px 8px; min-height: 52px;
  background: rgba(255,255,255,.92); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 17px; font-weight: 700; text-align: center; white-space: nowrap; }
.top .left { justify-self: start; }
.top .right { justify-self: end; }
.top .logo { height: 34px; }
.back { color: var(--blue); text-decoration: none; font-size: 17px; padding: 6px 4px; background: none; border: 0; }
.saved { font-size: 13px; color: var(--muted); justify-self: end; }

main { padding: 14px 14px calc(110px + var(--bottom)); max-width: 720px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 0 calc(6px + var(--bottom));
  background: rgba(255,255,255,.95); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
.tabs a.on { color: var(--blue); }
.tabs svg { width: 26px; height: 26px; }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  display: flex; gap: 10px; padding: 10px 14px calc(10px + var(--bottom));
  background: rgba(255,255,255,.95); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.bar > * { flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--blue-soft); color: var(--blue); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); opacity: .9; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.navy { background: var(--navy); color: #fff; }
.btn.danger { background: #fdecea; color: var(--bad); }
.btn.big { min-height: 56px; font-size: 17px; border-radius: 14px; width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--blue); font-weight: 600; padding: 6px; cursor: pointer; }

/* ---------- Cartes et champs ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; box-shadow: 0 1px 2px rgba(20,40,70,.06); }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.sec { margin: 22px 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.field { display: block; margin: 0 0 12px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfe;
  -webkit-appearance: none; appearance: none;
}
.field textarea { min-height: 80px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; background: #fff; }
.euro { position: relative; }
.euro input { padding-right: 64px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.euro::after { content: "€ TTC"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; }
.switch input { width: 51px; height: 31px; -webkit-appearance: none; appearance: none; background: #d6dbe2; border-radius: 99px; position: relative; transition: background .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- Accueil ---------- */
.hero { display: flex; align-items: center; gap: 12px; margin: 4px 2px 14px; }
.hero img { width: 54px; height: 54px; object-fit: contain; background: #fff; border-radius: 14px; padding: 4px; }
.hero h1 { margin: 0; font-size: 24px; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }
.search-input { width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 0; background: #e6ebf1; margin: 14px 0 10px; -webkit-appearance: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 99px; padding: 7px 13px; background: #fff; color: var(--ink); font-size: 14px; box-shadow: 0 1px 2px rgba(20,40,70,.08); }
.chip.on { background: var(--navy); color: #fff; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(20,40,70,.06); }
.item { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.item:last-child { border-bottom: 0; }
.item:active { background: #f5f8fc; }
.item .num { font-weight: 700; color: var(--navy); min-width: 58px; font-variant-numeric: tabular-nums; }
.item .mid { flex: 1; min-width: 0; }
.item .mid b, .item .mid span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .mid span { font-size: 13px; color: var(--muted); }
.item .end { text-align: right; font-size: 14px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge.envoyé { background: var(--blue-soft); color: var(--blue); }
.badge.accepté, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.refusé, .badge.annulé, .badge.échec { background: #fdecea; color: var(--bad); }
.badge.warn, .badge.test { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; padding: 34px 18px; color: var(--muted); }

/* ---------- Carte ---------- */
.mapwrap { position: relative; margin: 0 -14px 14px; background: #dfe7ef; }
.map { height: 46vh; min-height: 280px; max-height: 480px; }
.map.tall { height: 52vh; }
.mapctl { position: absolute; z-index: 450; left: 10px; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.mapctl > * { pointer-events: auto; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: rgba(255,255,255,.95); border-radius: 12px; padding: 3px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.seg button { border: 0; background: none; border-radius: 9px; min-height: 38px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--navy); color: #fff; }
.seg button.on.dep { background: var(--dep); }
.seg button.on.arr { background: var(--arr); }
.citysearch { position: relative; }
.citysearch input { width: 100%; min-height: 44px; border: 0; border-radius: 12px; padding: 10px 14px; box-shadow: 0 2px 10px rgba(0,0,0,.15); -webkit-appearance: none; }
.results { position: absolute; left: 0; right: 0; top: 48px; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); overflow: hidden; max-height: 50vh; overflow-y: auto; }
.results button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.results button:last-child { border-bottom: 0; }
.results button:active { background: var(--blue-soft); }
.results small { color: var(--muted); white-space: nowrap; }
.maphint { position: absolute; z-index: 450; left: 50%; bottom: 10px; transform: translateX(-50%); background: rgba(22,53,95,.88); color: #fff; font-size: 13px; padding: 6px 12px; border-radius: 99px; white-space: nowrap; pointer-events: none; }
.pin { width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.pin.dep { background: var(--dep); }
.pin.arr { background: var(--arr); }
.pin.asked { background: #8a96a6; width: 16px; height: 16px; }
.leaflet-container { font: inherit; }

/* ---------- Villes du devis ---------- */
.leg-h { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.leg-h b { font-size: 17px; }
.leg-h .dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.dep { background: var(--dep); }
.dot.arr { background: var(--arr); }
.leg-h .link { margin-left: auto; }
.asked { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 0 0 10px; }
.asked select { min-height: 34px; padding: 4px 10px; border-radius: 9px; border: 1px solid var(--line); background: #fbfcfe; }
.props { display: grid; gap: 8px; margin: 6px 0 10px; }
.prop { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; min-height: 52px; }
.prop .grow { flex: 1; min-width: 0; }
.prop small { display: block; color: var(--muted); font-size: 13px; }
.prop.on { border-color: var(--blue); background: var(--blue-soft); }
.prop .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; color: #fff; font-size: 13px; }
.prop.on .tick { background: var(--blue); border-color: var(--blue); }
.preview-line { background: #f6f8fb; border-radius: 10px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; }
.route { display: flex; gap: 18px; align-items: baseline; }
.route b { font-size: 20px; color: var(--navy); }

.cityrow { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 8px; transition: border-color .15s, box-shadow .15s; }
.cityrow.on { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.cityrow .lbl { font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.cityrow .val { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 4px; min-height: 28px; }
.cityrow .val select { min-height: 34px; padding: 4px 10px; border-radius: 9px; border: 1px solid var(--line); background: #fbfcfe; }
.cityrow .acts { display: flex; gap: 8px; margin-top: 8px; }
#kindSeg button { font-size: 14px; }

/* ---------- Aperçu ---------- */
.paper { background: #fff; border-radius: var(--radius); box-shadow: 0 2px 12px rgba(20,40,70,.1); overflow: hidden; margin: 0 -4px 14px; }
.paper img { max-width: 100%; }
.sendbox { display: grid; gap: 8px; }

/* ---------- Tournées ---------- */
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--blue-soft); color: var(--navy); border-radius: 99px; padding: 5px 6px 5px 11px; font-size: 14px; margin: 0 6px 6px 0; }
.tag button { border: 0; background: rgba(22,53,95,.12); color: var(--navy); width: 22px; height: 22px; border-radius: 50%; font-size: 13px; line-height: 1; }
.axis { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 10px; }
.axis.on { border-color: var(--blue); }
.axis .row input { min-height: 40px; }
.ol { counter-reset: n; }
.ol .tag::before { counter-increment: n; content: counter(n) "."; font-weight: 700; margin-right: 2px; }

.photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.photo { position: relative; aspect-ratio: 4/3; border-radius: 12px; background: #eef2f7 center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 14px; border: 1.5px dashed #c9d3df; overflow: hidden; }
.photo.has { border: 0; }
.photo .act { position: absolute; left: 6px; right: 6px; bottom: 6px; display: flex; gap: 6px; }
.photo .act .btn { flex: 1; min-height: 34px; font-size: 13px; background: rgba(255,255,255,.92); }
.logo-prev { width: 110px; height: 110px; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; }

/* ---------- Fenêtre du bas, message ---------- */
.sheet { position: fixed; inset: 0; z-index: 2000; background: rgba(10,20,35,.45); display: flex; align-items: flex-end; animation: fade .15s; }
.sheet .panel { width: 100%; max-width: 720px; margin: 0 auto; background: #fff; border-radius: 20px 20px 0 0; padding: 20px 18px calc(18px + var(--bottom)); animation: up .2s ease-out; max-height: 90vh; overflow-y: auto; }
.sheet h2 { margin: 0 0 6px; font-size: 20px; }
.sheet .kv { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin: 14px 0; font-size: 15px; display: grid; gap: 6px; }
.sheet .kv div { display: flex; gap: 10px; }
.sheet .kv div span { color: var(--muted); min-width: 62px; }
.sheet .kv div b { word-break: break-all; }
.sheet .stack { display: grid; gap: 10px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; z-index: 3000; left: 50%; top: calc(var(--top) + 12px); transform: translate(-50%, -200%); opacity: 0; background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 99px; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: transform .25s, opacity .25s; max-width: calc(100% - 28px); text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.err { background: var(--bad); }
.spin { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 22px calc(24px + var(--bottom)); max-width: 420px; margin: 0 auto; }
.login img { width: 150px; margin: 0 auto 18px; display: block; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 22px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 8px 0; text-align: center; }

table.sends { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sends td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.sends tr:last-child td { border-bottom: 0; }
