:root {
  --brand: #1e3a5f; --brand-2: #2b5486; --bg: #f4f6f9; --card: #fff; --ink: #172033; --muted: #66718a;
  --line: #dde2ea; --ok: #15803d; --warn: #c2410c; --err: #b91c1c; --info: #2563eb;
  --r: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

header#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff; min-height: 56px; }
header .hlogo { width: 34px; height: 34px; border-radius: 7px; flex: none; }
header .title { flex: 1; min-width: 0; }
#title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle:empty { display: none; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn circle { fill: currentColor; stroke: none; }
.save-state { font-size: 12px; opacity: .85; white-space: nowrap; }
.save-state.err { color: #fecaca; opacity: 1; font-weight: 600; }

nav#tabs { position: sticky; top: 56px; z-index: 19; display: flex; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); scrollbar-width: none; }
nav#tabs::-webkit-scrollbar { display: none; }
nav#tabs button { flex: 1 0 auto; background: none; border: 0; padding: 12px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
nav#tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
nav#tabs .dot { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px; border-radius: 9px; background: var(--err); color: #fff; font-size: 11px; line-height: 18px; }

main { max-width: 860px; margin: 0 auto; padding: 14px 14px calc(90px + env(safe-area-inset-bottom)); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 2px 8px; }
h2:first-child { margin-top: 4px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=datetime-local], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 44px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
input.big { font-size: 20px; font-weight: 700; letter-spacing: .02em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.danger { color: var(--err); border-color: #f3c4c4; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn svg { width: 19px; height: 19px; }
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 15; border-radius: 28px; padding: 14px 20px; box-shadow: 0 6px 18px rgba(30,58,95,.35); }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--ok); }

.list-item { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.chip { flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #ffedd5; color: var(--warn); }
.badge.err { background: #fee2e2; color: var(--err); }
.badge.info { background: #dbeafe; color: var(--info); }
.place { font-size: 12px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 6px; }

/* voies Squid */
.voies { width: 100%; border-collapse: collapse; }
.voies td { padding: 4px 3px; vertical-align: middle; }
.voies td.n { width: 30px; font-weight: 700; color: var(--muted); text-align: center; }
.voies td.ph { width: 78px; }
.voies td.cat { width: 34%; }
.voies input, .voies select { min-height: 40px; padding: 8px; }
.voies tr.grp-start td { border-top: 2px solid #e6eaf0; }
@media (max-width: 560px) {
  .voies tr { display: grid; grid-template-columns: 30px 1fr 74px; grid-template-areas: "n lib ph" "n cat cat"; padding: 6px 0; border-top: 1px solid var(--line); }
  .voies td.n { grid-area: n; } .voies td.lib { grid-area: lib; } .voies td.ph { grid-area: ph; width: auto; } .voies td.cat { grid-area: cat; width: auto; }
  .voies tr.grp-start td { border-top: 0; }
}

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.ph-tile { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; position: relative; }
.ph-tile img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #e9edf3; cursor: zoom-in; }
.ph-tile input { border: 0; border-top: 1px solid var(--line); border-radius: 0; min-height: 36px; font-size: 13px; padding: 6px 8px; }
.ph-tile .ph-menu { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.55); color: #fff; border: 0; border-radius: 8px; padding: 4px; cursor: pointer; }
.ph-tile .ph-menu svg { width: 18px; height: 18px; }
.ph-tile .ph-menu circle { fill: currentColor; stroke: none; }
.ph-tile.loading { display: grid; place-items: center; aspect-ratio: 4/3; color: var(--muted); font-size: 13px; }
.ph-tile .cover { position: absolute; top: 6px; left: 6px; }
.ph-actions { display: flex; gap: 8px; margin: 10px 0 2px; flex-wrap: wrap; }
.ph-head { display: flex; align-items: baseline; justify-content: space-between; }
.ph-head b { font-size: 15px; }

/* sheet (bottom panel) */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.sheet-body h3 { margin: 0 0 12px; font-size: 18px; }
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-btn { display: flex; gap: 10px; align-items: center; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; }
.type-btn.on { border-color: var(--brand); background: #eef3fa; }
.type-btn small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.3; }
@media (max-width: 420px) { .types { grid-template-columns: 1fr; } }
.menu-list button { display: block; width: 100%; text-align: left; padding: 14px; background: #fff; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 600; }
.menu-list button:first-child { border-radius: 12px 12px 0 0; } .menu-list button:last-child { border-radius: 0 0 12px 12px; border-bottom: 0; }
.menu-list button.danger { color: var(--err); }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#toast.err { background: var(--err); }

.ctrl { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); }
.ctrl:first-child { border-top: 0; }
.ctrl.link { cursor: pointer; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 14px; display: block; }
.viewer { position: fixed; inset: 0; z-index: 70; background: #000; display: grid; place-items: center; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer button { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; background: rgba(255,255,255,.2); color: #fff; border: 0; border-radius: 20px; padding: 8px 14px; font-weight: 600; }
.mes { padding: 12px 0; border-top: 1px solid var(--line); }
.mes:first-child { border-top: 0; }
.annexe { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.annexe:first-child { border-top: 0; }
.annexe a { color: var(--brand); font-weight: 600; word-break: break-all; }

/* ---------- éditeur d'annexes ---------- */
.ed { position: fixed; inset: 0; z-index: 80; background: #2b313b; display: flex; flex-direction: column; }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--brand); color: #fff; }
.ed-title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-weight: 600; min-height: 40px; min-width: 40px; cursor: pointer; }
.ed-btn.primary { background: #22c55e; color: #fff; border-color: #22c55e; }
.ed-btn.danger { color: var(--err); }
.ed-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.ed-top .ed-btn:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.ed-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px; }
.ed-pages { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; width: max-content; min-width: 100%; }
.ed-page { position: relative; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); margin: 0 auto; }
.ed-page canvas { position: absolute; left: 0; top: 0; }
.ed-loading { color: #fff; padding: 40px; text-align: center; width: 100%; }
.ed-bar { background: #fff; border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.ed-tools { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.ed-tools button { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 0; border-radius: 9px; padding: 6px 8px; font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer; }
.ed-tools button.on { background: #e8eef7; color: var(--brand); }
.ed-opts { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.ed-opts .ed-btn { padding: 6px 10px; min-height: 36px; }
.ed-color { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); flex: none; cursor: pointer; }
.ed-color.on { box-shadow: 0 0 0 2px var(--ink); }
.ed-sep { width: 1px; height: 26px; background: var(--line); flex: none; }
.ed-dialog { position: absolute; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 5; }
.ed-dialog[hidden] { display: none; }
.ed-dlg { background: var(--bg); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.ed-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-chips button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.ed-row { display: flex; gap: 8px; align-items: center; }
.ed-bold { font-size: 14px; display: flex; gap: 6px; align-items: center; }
.tpl { display: flex; gap: 10px; align-items: center; }
