:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --border: #ddd7cc;
  --text: #1f2328;
  --muted: #5f6670;
  --accent: #d9822b;
  --accent-ink: #9c5714;
  --water: #215f8c;
  --ok: #2f8a4c;
  --warn: #d38b12;
  --alert: #c8372d;
  --none: #9aa0a6;
  --shadow: 0 6px 22px rgba(30, 30, 30, .14);
  --radius: 10px;
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --surface: #1d2126; --surface-2: #252a31; --border: #343b44;
    --text: #e8e6e3; --muted: #9aa3ad; --accent: #e8954a; --accent-ink: #f0b37c; --water: #5aa6dc;
    --ok: #4cb46d; --warn: #e6a53a; --alert: #ec5b50; --none: #6c737b; --shadow: 0 6px 22px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --surface: #1d2126; --surface-2: #252a31; --border: #343b44;
  --text: #e8e6e3; --muted: #9aa3ad; --accent: #e8954a; --accent-ink: #f0b37c; --water: #5aa6dc;
  --ok: #4cb46d; --warn: #e6a53a; --alert: #ec5b50; --none: #6c737b; --shadow: 0 6px 22px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- barre supérieure */
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: .01em; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-fictif { margin-left: auto; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); border: 1px dashed var(--accent); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); flex: none; }
.icon-btn:hover { border-color: var(--accent); }

/* --- disposition */
.layout { flex: 1; display: flex; min-height: 0; }
.panel { width: 400px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); min-height: 0; }
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }

/* --- onglets métiers */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 10px; border-bottom: 1px solid var(--border); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px; border: 1px solid transparent; border-radius: 8px; background: none; font-size: 11.5px; color: var(--muted); }
.tab .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface-2); border-color: var(--c); color: var(--text); font-weight: 600; }
.tab .cnt { font-size: 10px; font-weight: 700; color: #fff; background: var(--alert); border-radius: 999px; padding: 0 5px; line-height: 15px; }

.panel-body { overflow-y: auto; padding: 14px 14px 24px; flex: 1; }
.panel-body h2 { font-size: 15px; margin: 0 0 2px; display: flex; align-items: center; gap: 8px; }
.panel-body h2 .dot { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.panel-body .lead { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.panel-body h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 9px 10px; min-width: 0; }
.kpi .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v small { font-size: 12px; font-weight: 500; color: var(--muted); }
.kpi .l { font-size: 11.5px; color: var(--muted); }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); } .kpi.alert .v { color: var(--alert); }
.bar { height: 6px; border-radius: 3px; background: var(--border); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.chart { width: 100%; display: block; }
.chart text { fill: var(--muted); font: 10px var(--font); }
.chart .axis { stroke: var(--border); }
.chart-cap { font-size: 11px; color: var(--muted); margin: 4px 0 0; }

/* couches */
.layers { display: flex; flex-direction: column; gap: 2px; }
.layer { display: flex; align-items: center; gap: 9px; padding: 5px 6px; border-radius: 6px; cursor: pointer; user-select: none; }
.layer:hover { background: var(--surface-2); }
.layer input { accent-color: var(--accent); margin: 0; }
.layer .sw { width: 18px; height: 12px; flex: none; border-radius: 3px; }
.layer .sw.pt { width: 11px; height: 11px; border-radius: 50%; margin: 0 3.5px; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.layer .sw.ln { height: 3px; border-radius: 2px; }
.layer .name { flex: 1; min-width: 0; }
.layer .n { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.layer a.dl { font-size: 11px; color: var(--muted); text-decoration: none; opacity: 0; }
.layer:hover a.dl { opacity: 1; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted); margin: 4px 0 0 6px; }
.legend-inline span::before { content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 5px; vertical-align: -1px; }

/* listes */
.list { display: flex; flex-direction: column; gap: 4px; }
.item { display: grid; grid-template-columns: 8px 1fr auto; gap: 9px; align-items: center; text-align: left; border: 1px solid var(--border); background: none; border-radius: 7px; padding: 6px 9px; }
.item:hover { border-color: var(--accent); }
.item .g { width: 8px; height: 26px; border-radius: 3px; background: var(--c); }
.item .t { font-weight: 600; font-size: 12.5px; }
.item .s { font-size: 11.5px; color: var(--muted); }
.item .d { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.empty { color: var(--muted); font-size: 12.5px; font-style: italic; }

/* --- outils carte */
.map-tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 8px; flex-wrap: wrap; z-index: 2; }
.tool-group { display: flex; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.tool-group button { border: 0; background: none; padding: 7px 11px; font-size: 12.5px; border-right: 1px solid var(--border); }
.tool-group button:last-child { border-right: 0; }
.tool-group button.on { background: var(--accent); color: #fff; }
.coords { position: absolute; left: 10px; bottom: 96px; background: var(--surface); padding: 4px 9px; border-radius: 6px; font: 11.5px var(--mono); box-shadow: var(--shadow); color: var(--muted); z-index: 2; }
.coords b { color: var(--text); font-weight: 500; }

/* --- frise temporelle */
.timeline { position: absolute; left: 10px; right: 10px; bottom: 26px; display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 12px; z-index: 2; }
.tl-main { flex: 1; min-width: 0; }
.tl-head { display: flex; align-items: baseline; gap: 10px; }
.tl-head strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.tl-mode { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 1px 8px; border-radius: 999px; background: var(--ok); color: #fff; }
.tl-mode.prev { background: var(--water); }
.timeline input[type=range] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
.tl-scale { position: relative; height: 14px; font-size: 10.5px; color: var(--muted); }
.tl-scale span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.tl-today { border: 1px solid var(--accent); background: none; color: var(--accent-ink); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; font-weight: 600; }

/* --- popups */
.maplibregl-popup-content { background: var(--surface); color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 10px; font: 12.5px/1.4 var(--font); max-height: 60vh; overflow: auto; }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { font-size: 18px; color: var(--muted); padding: 0 6px; }
.pop h4 { margin: 0 22px 2px 0; font-size: 14px; }
.pop .sub { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #fff; padding: 1px 7px; border-radius: 999px; background: var(--c, var(--none)); }
.pop table { border-collapse: collapse; width: 100%; }
.pop td { padding: 2px 0; vertical-align: top; border-bottom: 1px solid var(--border); }
.pop td:first-child { color: var(--muted); padding-right: 10px; white-space: nowrap; }
.pop td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.maplibregl-ctrl-scale { background: var(--surface); color: var(--text); border-color: var(--muted); }
.maplibregl-ctrl-bottom-right { bottom: 92px; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* --- responsive */
@media (max-width: 860px) {
  body { overflow: auto; }
  .layout { flex-direction: column-reverse; }
  .map-wrap { height: 62vh; flex: none; }
  .panel { width: 100%; border-right: 0; border-top: 1px solid var(--border); }
  .panel-body { overflow: visible; }
  .brand p, .badge-fictif { display: none; }
  .timeline { left: 6px; right: 6px; bottom: 22px; padding: 6px 8px; gap: 8px; }
  .tl-today { padding: 5px 7px; font-size: 11.5px; }
  .coords { display: none; }
  .map-tools { left: 6px; top: 6px; gap: 5px; }
  .tool-group button { padding: 6px 8px; font-size: 11.5px; }
}

/* --- saisie terrain */
.tool-group button.saisie-btn { background: #ff00aa; color: #fff; font-weight: 700; }
.tool-group button.saisie-btn.on { background: #b30077; }
.sheet { position: absolute; top: 54px; right: 54px; width: 350px; max-height: calc(100% - 160px); overflow-y: auto; z-index: 4;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border-top: 4px solid #ff00aa; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 0 14px; }
.sheet h2 { font-size: 15px; margin: 0; }
.sheet form { display: flex; flex-direction: column; gap: 10px; padding: 10px 14px 14px; }
.sheet label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.sheet input, .sheet select, .sheet textarea { font: 14px var(--font); color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; width: 100%; }
.sheet input:focus, .sheet select:focus, .sheet textarea:focus { outline: 2px solid #ff00aa; outline-offset: 0; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .hint { font-weight: 400; }
.sheet fieldset.grav { border: 0; padding: 0; margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sheet fieldset.grav legend { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 3px; }
.sheet fieldset.grav label { flex-direction: row; }
.sheet fieldset.grav input { position: absolute; opacity: 0; width: 1px; }
.sheet fieldset.grav span { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); font-size: 14px; cursor: pointer; }
.sheet fieldset.grav input:checked + span { background: #ff00aa; border-color: #ff00aa; color: #fff; }
.sheet fieldset.grav input:focus-visible + span { outline: 2px solid var(--accent); }
.sheet fieldset.grav small { color: var(--muted); font-size: 11px; margin-left: 4px; }
.sheet .loc { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.sheet .loc span { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.sheet .loc small { color: var(--muted); font-size: 11px; }
.sheet .loc-btns { display: flex; gap: 6px; }
.sheet .loc-btns button, .sheet .actions button, .btn-row button, .btn-row .btn { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 6px 10px; font-size: 12.5px; color: var(--text); cursor: pointer; }
.sheet img[data-preview] { max-width: 100%; border-radius: 8px; }
.sheet .verdict { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sheet .verdict.normal { color: var(--ok); } .sheet .verdict.vigilance { color: var(--warn); } .sheet .verdict.alerte { color: var(--alert); }
.sheet .err { margin: 0; font-size: 12px; color: var(--alert); }
.sheet .actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet .actions .primary { background: #ff00aa; border-color: #ff00aa; color: #fff; font-weight: 700; padding: 8px 16px; }
.saisie-marker { width: 26px; height: 36px; cursor: grab; background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26 36'%3E%3Cpath d='M13 35C13 35 25 21 25 13A12 12 0 0 0 1 13C1 21 13 35 13 35Z' fill='%23ff00aa' stroke='white' stroke-width='2'/%3E%3Ccircle cx='13' cy='13' r='4.5' fill='white'/%3E%3C/svg%3E"); }
.toast { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 6; box-shadow: var(--shadow); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn-row button:disabled { opacity: .45; cursor: default; }
.btn-row .danger { color: var(--alert); border-color: var(--alert); }
.item .s b.new { color: #ff00aa; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }
.pop-photo { width: 100%; border-radius: 8px; margin-bottom: 6px; display: block; }
.pop-desc { margin: 0 0 8px; font-size: 12.5px; }
.pop-del { margin-top: 8px; width: 100%; border: 1px solid var(--alert); color: var(--alert); background: none; border-radius: 7px; padding: 5px; font-size: 12px; }
@media (max-width: 860px) {
  .sheet { position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 78vh; border-radius: 14px 14px 0 0; }
  .sheet input, .sheet select, .sheet textarea { font-size: 16px; }
}
.sheet [hidden] { display: none !important; }
.sheet { overflow-x: hidden; }
.sheet .row > label, .sheet input, .sheet select { min-width: 0; }
@media (max-width: 860px) { .sheet { max-height: 60vh; } }

/* --- onglets à pictogrammes */
.tab { position: relative; gap: 4px; padding: 8px 2px 7px; }
.tab .ico { color: var(--c); transition: transform .15s; }
.tab:hover .ico { transform: translateY(-1px); }
.tab[aria-selected="true"] { background: color-mix(in srgb, var(--c) 16%, var(--surface-2)); }
.tab .lbl { line-height: 1.15; }
.tab .cnt { position: absolute; top: 3px; right: 6px; }
.panel-body h2 .ico { color: var(--c); }

/* --- profil utilisateur */
.profile { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 3px 12px 3px 3px; max-width: 230px; }
.profile-btn:hover, .profile-btn[aria-expanded="true"] { border-color: var(--accent); }
.profile-btn .who { display: flex; flex-direction: column; text-align: left; line-height: 1.15; min-width: 0; }
.profile-btn .who b { font-size: 12.5px; }
.profile-btn .who small { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { position: relative; display: inline-grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #fff; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; }
.profile-btn .avatar::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface-2); }
.avatar.lg { width: 42px; height: 42px; font-size: 14px; }
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.profile-menu { position: absolute; right: 0; top: calc(100% + 8px); width: 290px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; z-index: 20; }
.profile-menu .me { display: flex; gap: 10px; align-items: center; padding: 6px 6px 10px; border-bottom: 1px solid var(--border); }
.profile-menu b { display: block; font-size: 13px; }
.profile-menu small { display: block; font-size: 11.5px; color: var(--muted); }
.profile-menu small.online { color: var(--ok); }
.profile-menu .menu-h { margin: 8px 6px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.profile-menu button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; border: 0; background: none; border-radius: 7px; padding: 5px 6px; }
.profile-menu button:hover { background: var(--surface-2); }
.profile-menu button[aria-checked="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
@media (max-width: 860px) {
  .profile-btn { padding: 2px; }
  .profile-btn .who { display: none; }
}

/* --- mode intégré (iframe) et mode métier unique */
.full-link { margin-left: 8px; font-size: 12.5px; font-weight: 600; color: var(--accent-ink); text-decoration: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; white-space: nowrap; }
.full-link:hover { border-color: var(--accent); }
.embed .profile { display: none; }
.embed .topbar { padding: 6px 12px; }
.embed .brand h1 { font-size: 15px; }
.embed .panel { width: 360px; }
.locked .tabs { display: none; }
@media (max-width: 860px) { .embed .full-link { padding: 5px 8px; } .embed .badge-fictif { display: none; } }

/* --- charte Altis QHSE (?brand=qhse) */
:root[data-brand="qhse"] { --font: 'Manrope', system-ui, sans-serif; --accent: #1B7F4C; --accent-ink: #146B3F; }
:root[data-brand="qhse"][data-theme="dark"] {
  --bg: #072a42; --surface: #0B3B5C; --surface-2: #124b72; --border: #22597f; --text: #ffffff; --muted: #b9cad4;
  --accent: #F2C94C; --accent-ink: #F2C94C;
}
:root[data-brand="qhse"] .tool-group button.saisie-btn { background: #F2B705; color: #14212B; }
.locked #btnFocus { display: none; }

/* --- correctif mobile : la colonne inversée débordait vers le haut (carte inaccessible) */
@media (max-width: 860px) {
  html, body { height: auto; min-height: 100%; }
  .layout { flex: none; }
}
