:root {
    --bg: #f3f6f4;
    --panel: #ffffff;
    --ink: #1b2a22;
    --muted: #66766d;
    --line: #dde5e0;
    --soft: #f1f5f3;
    --accent: #0f6b47;
    --accent-dk: #0f3d2e;
    --danger: #c62828;
    --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink); background: var(--bg);
    display: flex; flex-direction: column;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-weight: 600; margin: 6px 0 0; min-height: 0; }
.err:empty { display: none; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0c5a3b; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { width: 100%; padding: 12px; font-size: 16px; }
.btn.ghost-w { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); padding: 6px 10px; font-size: 13px; }
.btn.ghost-w:hover { background: rgba(255,255,255,.12); }

/* ---------- Mise en page ---------- */
.top {
    height: 50px; flex: none; display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; background: var(--accent-dk); color: #fff;
}
.brand { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { opacity: .7; font-size: 13px; margin-left: 4px; }
.top-a { display: flex; gap: 6px; }
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
#map { flex: 1; min-width: 0; background: #e8ece9; }

#panel {
    width: 400px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0;
}
.handle { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tabs button {
    flex: 1; padding: 11px 2px; border: 0; background: none; font: inherit; font-size: 13px;
    font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer;
}
.tabs button.on { color: var(--accent); border-color: var(--accent); }
.tab { flex: 1; overflow: auto; padding: 12px; display: none; -webkit-overflow-scrolling: touch; }
.tab.on { display: block; }

@media (max-width: 800px) {
    .hide-sm { display: none; }
    #panel {
        position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 58%;
        border-left: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18);
        z-index: 1100; transition: transform .25s ease;
        padding-bottom: env(safe-area-inset-bottom);
    }
    #panel.min { transform: translateY(calc(100% - 78px)); }
    .handle { display: block; width: 100%; border: 0; background: none; padding: 8px 0 2px; cursor: pointer; }
    .handle span { display: block; width: 46px; height: 5px; border-radius: 3px; background: #c4cec8; margin: 0 auto; }
}

/* ---------- Listes ---------- */
.row-btn { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.empty { padding: 16px; text-align: center; color: var(--muted); background: var(--soft); border-radius: var(--radius); margin: 8px 0 12px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; flex: none; vertical-align: -2px; margin-right: 6px; }
.sw.big { width: 22px; height: 22px; border-radius: 6px; margin: 0; }
.sw.line { width: 22px; height: 6px; border-radius: 3px; margin: 0 6px 0 0; vertical-align: 3px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line); }
.item {
    width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
    padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius);
    background: #fff; font: inherit; color: inherit; cursor: pointer;
}
.item:hover { border-color: #b9c7bf; background: #fafcfb; }
.item-b { flex: 1; min-width: 0; }
.item-b b { display: block; }
.item-b small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; display: flex; align-items: center; }
.age { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.age.g { background: #e1f3e4; color: #1b5e20; }
.age.o { background: #fff0d9; color: #a35a00; }
.age.r { background: #fde3e3; color: #b71c1c; }
.age.n { background: #eceff1; color: #607d8b; }

/* ---------- Planning ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; text-align: center; margin-bottom: 10px; }
.weeknav .btn { font-size: 18px; padding: 4px 14px; }
.day { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; background: #fff; }
.day.we .day-h { background: #f6f6f6; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day.today .day-h { background: #e3f1ea; }
.day-h { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 7px 10px; background: var(--soft); font-weight: 700; }
.ent { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-top: 1px solid var(--line); }
.ent .sw { margin: 0; }
.ent-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.ent-main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ent-main small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ent.st-annule .ent-main b { text-decoration: line-through; color: var(--muted); }
.stat { border: 0; border-radius: 12px; padding: 4px 10px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.stat-prevu { background: #e3eefc; color: #0d47a1; }
.stat-fait { background: #dff2e2; color: #1b5e20; }
.stat-annule { background: #eceff1; color: #78909c; }

/* ---------- Photos (panneau) ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 4px; }
.filters select { grid-column: 1 / -1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.thumb { position: relative; padding: 0; border: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: #ddd; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 4px; }

/* ---------- Champs ---------- */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
input, select, textarea {
    display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; font-weight: 400;
    border: 1px solid #c9d4ce; border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.filters input, .filters select { margin: 0; padding: 7px 8px; font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; }
label.check input { width: auto; margin: 3px 0 0; }
label.check small { display: block; font-weight: 400; }
.field { margin-bottom: 12px; }
.field .lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.colors { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cchip { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #c9d4ce; cursor: pointer; padding: 0; }
.cchip.on { box-shadow: 0 0 0 3px var(--ink); }
.cpick { width: 40px; height: 32px; padding: 2px; margin: 0; cursor: pointer; }

/* ---------- Dialogue ---------- */
dialog {
    width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); border: 0; border-radius: 14px;
    padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink);
}
dialog::backdrop { background: rgba(15, 30, 22, .45); }
#dlg-form { padding: 18px; }
dialog h2 { margin: 0 0 14px; font-size: 19px; }
.dlg-a { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; position: sticky; bottom: -18px; background: #fff; padding: 10px 0 0; }
.up-prev { text-align: center; margin-bottom: 10px; }
.up-prev img { max-width: 100%; max-height: 200px; border-radius: 8px; }
.pos { padding: 9px 10px; border-radius: 8px; font-size: 14px; margin-bottom: 8px; }
.pos.ok { background: #e3f4e5; }
.pos.warn { background: #fff3e0; }

/* ---------- Carte : éléments ---------- */
.lbl-secteur {
    background: rgba(255,255,255,.88); border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.2);
    font-weight: 700; font-size: 12px; padding: 1px 7px; border-radius: 6px; color: var(--ink);
}
.lbl-secteur::before { display: none; }
.far .lbl-secteur { display: none; }
.ph-icon { background: none; border: 0; }
.ph-mk {
    width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; overflow: hidden; position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,.4); background: #ccc;
}
.ph-mk img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-mk b {
    position: absolute; right: -1px; top: -1px; min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: 9px; background: #ff6f00; color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.locate-btn {
    display: block; width: 34px; height: 34px; line-height: 32px; text-align: center; background: #fff;
    font-size: 20px; color: #333; text-decoration: none; border-radius: 4px;
}
.locate-btn.on { color: #1e88e5; }

.leaflet-popup-content { margin: 12px 14px; font: inherit; }
.pop-t { font-weight: 700; font-size: 15px; margin-bottom: 6px; display: flex; align-items: center; }
.pop-m { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.pop-n { font-size: 13px; background: var(--soft); padding: 6px 8px; border-radius: 6px; margin: 6px 0; white-space: pre-line; }
.pop-a { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.ph-hist { max-height: 240px; overflow: auto; margin-top: 6px; }
.ph-row {
    display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; padding: 5px; margin-bottom: 4px;
    border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; font-size: 13px; cursor: pointer;
}
.ph-row img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; flex: none; }

#banner, #editbar {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1050;
    background: #fff; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.2);
    padding: 8px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
    max-width: calc(100% - 120px); font-size: 14px;
}
#banner[hidden], #editbar[hidden] { display: none; }
@media (max-width: 800px) { #banner, #editbar { top: auto; bottom: 90px; max-width: calc(100% - 20px); } }

/* ---------- Visionneuse ---------- */
#lightbox {
    position: fixed; inset: 0; z-index: 3000; background: rgba(8,12,10,.94);
    display: flex; align-items: center; justify-content: center;
}
#lightbox[hidden] { display: none; }
#lb-img { max-width: 100%; max-height: calc(100% - 130px); object-fit: contain; }
.lb-x { position: absolute; top: 10px; right: 12px; font-size: 24px; background: none; border: 0; color: #fff; cursor: pointer; padding: 8px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 46px; background: rgba(0,0,0,.3); border: 0; color: #fff; cursor: pointer; padding: 4px 14px; border-radius: 8px; }
.lb-prev { left: 8px; } .lb-next { right: 8px; }
.lb-nav[hidden] { display: none; }
.lb-info { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.8)); }
.lb-info .muted { color: #aab; }
.lb-a { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Toast ---------- */
#toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
    background: #1b2a22; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 4000;
    transition: all .25s; font-weight: 600; max-width: calc(100% - 24px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); }

/* ---------- Connexion ---------- */
.login-page { align-items: center; justify-content: center; background: linear-gradient(160deg, #0f3d2e, #1d6b4d); padding: 16px; }
.login-card { background: #fff; width: min(380px, 100%); padding: 28px 24px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { margin: 6px 0 2px; font-size: 22px; }
.login-card .muted { margin: 0 0 18px; }
.login-logo { font-size: 40px; }
.login-card .info { background: #e3f1ea; padding: 10px; border-radius: 8px; }
