:root {
  --green: #0B5D3B; --green2: #12804F; --gold: #F2B705; --bg: #F4F6F5; --card: #fff; --text: #1d2521; --muted: #6b7570;
  --line: #e2e7e4; --ok: #1e8e3e; --bad: #c0392b; --warn: #d68910; --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .nowrap { white-space: nowrap; }
.error { color: var(--bad); min-height: 1em; }
h2 { margin: 0 0 8px; } h3 { margin: 18px 0 10px; font-size: 16px; }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; margin: 6px 0; }
label.check input { width: auto; margin: 0; }

.btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 14px; border-radius: 10px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { border-color: var(--green2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.ok { background: #e7f5ec; color: var(--ok); border-color: #bfe3cb; }
.btn.danger { background: #fdecea; color: var(--bad); border-color: #f5c6c0; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 13px; border-radius: 8px; }
.btn.wide { width: 100%; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo { background: var(--green); color: var(--gold); font-weight: 800; border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; }
.brand.big .logo { width: 54px; height: 54px; font-size: 22px; }

.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--green), #073d27); padding: 16px; }
.login-card { background: #fff; padding: 28px; border-radius: 16px; width: min(400px, 100%); box-shadow: 0 20px 50px #0004; }
.login-card .brand { margin-bottom: 14px; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: #fff; border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav button { text-align: left; background: none; border: 0; padding: 11px 12px; border-radius: 10px; font: inherit; cursor: pointer; color: var(--text); }
.side nav button:hover { background: var(--bg); }
.side nav button.active { background: #e6f2ec; color: var(--green); font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 500; background: #fff; border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.menu-btn { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.chip i { font-style: normal; color: var(--muted); margin-left: 2px; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.chip.on i { color: #cfe; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 260px; }
.filters select, .filters input { width: auto; min-width: 150px; flex: 1; padding: 7px 9px; font-size: 13px; }
.live { color: var(--ok); font-size: 13px; font-weight: 600; white-space: nowrap; }
.live.off { color: var(--bad); }
.banner { background: #fff8e1; border-bottom: 1px solid #f3e2a6; padding: 8px 16px; font-size: 13px; color: #6d5a12; }

.view { padding: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi small { color: var(--muted); display: block; } .kpi b { font-size: 28px; display: block; margin: 4px 0; } .kpi span { font-size: 12px; color: var(--muted); }
.kpi.accent { border-left: 5px solid var(--green2); } .kpi.gold { border-left: 5px solid var(--gold); } .kpi.warnk { border-left: 5px solid var(--bad); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: left; cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 2px; }
.tile:hover { border-color: var(--green2); } .tile .ti { font-size: 26px; } .tile small { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; overflow-x: auto; }
.card h3 { margin-top: 0; }
.card.note { background: #f0f7f3; font-size: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--line); padding: 6px; }
td { border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover { background: var(--bg); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-bottom: 18px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; }
.bar i { background: var(--green2); border-radius: 4px 4px 0 0; min-height: 2px; display: block; }
.bar.now i { background: var(--gold); }
.bar span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars.week .bar i { background: var(--green); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef1ef; color: var(--muted); }
.badge.ok { background: #e7f5ec; color: var(--ok); } .badge.bad { background: #fdecea; color: var(--bad); } .badge.warn { background: #fef4e2; color: var(--warn); }
.badge.gold { background: #fff6d6; color: #8a6d00; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar input { max-width: 380px; }
.toolbar h3 { margin: 0; flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
.lcard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.lcard.suspendue { border-left: 5px solid var(--bad); background: #fffafa; } .lcard.deviee { border-left: 5px solid var(--warn); }
.lhead { display: flex; gap: 10px; align-items: center; }
.lhead > div { flex: 1; min-width: 0; } .lhead small { display: block; color: var(--muted); font-size: 12px; }
.lcode { color: #fff; font-weight: 700; border-radius: 8px; padding: 6px 9px; min-width: 44px; text-align: center; font-size: 14px; }
.lcode.sm { padding: 2px 6px; font-size: 12px; min-width: 0; }
.lmeta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin: 10px 0; }
.lnote { font-size: 13px; background: var(--bg); padding: 6px 8px; border-radius: 8px; margin-bottom: 8px; }
.lnote.warn { background: #fef4e2; }
.lbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.lbtns .btn { padding: 7px 10px; font-size: 13px; }

#view-map { padding: 0; position: relative; }
#map { height: calc(100vh - 100px); min-height: 420px; }
.map-side { position: absolute; left: 12px; bottom: 12px; z-index: 400; background: #fff; padding: 10px 12px; border-radius: 10px; box-shadow: 0 4px 16px #0002; font-size: 13px; max-width: 420px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 6px 0; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.legend i.ring { border: 2px solid var(--bad); background: #fff; }
.pop { font-size: 13px; line-height: 1.5; } .pop-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

.meter { width: 80px; height: 6px; background: #eef1ef; border-radius: 4px; overflow: hidden; display: inline-block; margin-right: 6px; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--green2); }

.msg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; position: relative; }
.msg.alerte { border-left: 4px solid var(--warn); } .msg.urgent { border-left: 4px solid var(--bad); } .msg.old { opacity: .55; }
.msg p { margin: 6px 0; } .msg .btn { position: absolute; top: 8px; right: 8px; }

.modal { position: fixed; inset: 0; background: #0006; z-index: 2000; display: grid; place-items: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 16px; padding: 22px; width: min(720px, 100%); max-height: 90vh; overflow: auto; position: relative; }
.modal-x { position: absolute; right: 12px; top: 12px; border: 0; background: var(--bg); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; }
.mbtns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.row2, .row3 { display: grid; gap: 10px; } .row2 { grid-template-columns: 1fr 1fr; } .row3 { grid-template-columns: 1fr 1fr 1fr; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.stopchecks { columns: 2; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.stoplist { columns: 2; font-size: 14px; } .stoplist li.skip { color: var(--bad); text-decoration: line-through; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2521; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 3000; max-width: 90vw; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 240px; z-index: 1500; transition: left .2s; box-shadow: 0 0 30px #0003; }
  body.menu-open .side { left: 0; }
  .menu-btn { display: inline-flex; }
  .filters select, .filters input { min-width: 0; flex: 1 1 45%; }
  .cards { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .stopchecks, .stoplist { columns: 1; }
  #map { height: calc(100vh - 170px); }
}
/* dossiers */
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.stoplist { padding-left: 22px; max-height: 240px; overflow: auto; }
.stoplist li { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.perms { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: normal; }
.chk input { width: auto; }
.toolbar select { width: auto; }
.stoplist { display: flex !important; flex-direction: column; gap: 0; margin: 6px 0; }
.stoplist li { width: 100%; }
input[type=color] { height: 38px; padding: 2px; }

.agentid{font-family:ui-monospace,Menlo,Consolas,monospace;background:#eef6f1;color:#1E7B4F;border-radius:6px;padding:1px 6px;font-weight:600;letter-spacing:.3px}
.agentid.big{display:block;font-size:22px;padding:4px 10px;margin:4px 0;width:max-content}
.agentcard{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:0;border-left:4px solid #1E7B4F}
.agentcard small{display:block;color:var(--muted,#667)}
/* Relevés terrain */
.rel-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
.rel-map { height: 380px; border-radius: 10px; overflow: hidden; }
.rel-pin { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: #0b6e52; color: #fff; font-size: 11px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.rel-pin.new { background: #E65100; }
tr.click.sel { background: rgba(11,110,82,.08); }
@media (max-width: 900px) { .rel-grid { grid-template-columns: 1fr; } }
.logout-top { white-space: nowrap; flex: none; }
@media (max-width: 860px) { .logout-top { padding: 6px 10px; font-size: 13px; } }
/* Menu plus compact pour que tout tienne sur un écran de PC portable */
.side { gap: 10px; padding: 12px 10px; }
.side nav button { padding: 8px 12px; }
.side-foot { gap: 6px; }
.side-foot .btn { padding: 7px 10px; font-size: 13px; }
@media (max-height: 640px) and (min-width: 861px) { .side nav button { padding: 6px 10px; font-size: 14px; } .side .brand small { display: none; } }
/* Menu déroulant du compte (haut à gauche) : mot de passe, déconnexion */
.brand.acct { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 6px 8px; cursor: pointer; font: inherit; color: inherit; text-align: left; }
.brand.acct:hover { background: var(--bg); }
.brand.acct > div { flex: 1; min-width: 0; }
.acct-caret { color: var(--muted); font-size: 14px; }
.acct-menu { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 6px 18px #0002; }
.acct-menu.hidden { display: none; }
.acct-menu .btn { padding: 7px 10px; font-size: 13px; }
.live-ev { display: flex; flex-direction: column; gap: 3px; max-height: 150px; overflow-y: auto; font-size: 13px; border-left: 3px solid #E65100; padding-left: 8px; }
