:root {
  /* couleurs du logo MadGD */
  --green: #01521c;
  --green-dark: #013a14;
  --green-light: #53a301;
  --bg: #f2f6ee;
  --card: #fff;
  --text: #1f2a1e;
  --muted: #6b7768;
  --line: #dde3d9;
  --c1: #d9534f; --c2: #f0ad4e; --c3: #5cb85c; --cS: #5b7fc7;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg);
       display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { margin: 0; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.grow { flex: 1; }

/* ---------- barre du haut ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 18px; background: #fff; color: var(--text);
          border-bottom: 3px solid var(--green-light); box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-logo { height: 36px; width: auto; display: block; }
.brand small { color: var(--green); font-weight: 600; font-size: 13px; padding-left: 12px; border-left: 2px solid var(--line); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar .btn.ghost { border-color: var(--line); }
.save-status { font-size: 12px; color: var(--muted); margin-right: 6px; }
.save-status.err { background: #c0392b; color: #fff; padding: 2px 8px; border-radius: 6px; }
.hero { text-align: center; padding: 8px 0 4px; }
.hero img { width: min(340px, 70vw); height: auto; }
@media (max-width: 700px) { .brand small { display: none; } }

/* ---------- boutons & champs ---------- */
.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: #fff; color: var(--text);
       padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--green); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.4); }
.preview-bar .btn.ghost, dialog .btn.ghost { border-color: var(--line); }
.btn.small { padding: 3px 9px; }
.btn small { opacity: .75; }
.btn.c1 { border-left: 4px solid var(--c1); } .btn.c2 { border-left: 4px solid var(--c2); }
.btn.c3 { border-left: 4px solid var(--c3); } .btn.cS { border-left: 4px solid var(--cS); }
label { display: block; font-weight: 600; font-size: 12px; color: #405040; margin-bottom: 10px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; color: var(--text);
       padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(83,163,1,.4); border-color: var(--green); }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }

/* ---------- accueil ---------- */
.home { max-width: 900px; width: 100%; margin: 24px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.plans-list { display: flex; flex-direction: column; gap: 6px; }
.plan-item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
             cursor: pointer; }
.plan-item:hover { border-color: var(--green); background: #fafcf9; }
.plan-item img { width: 36px; height: 40px; object-fit: contain; }
.plan-item .name { font-weight: 600; }

/* ---------- éditeur ---------- */
.editor { flex: 1; display: grid; grid-template-columns: minmax(380px, 44%) 1fr; min-height: 0; }
.form-pane { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.section { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.section > summary { padding: 12px 14px; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.section > summary::-webkit-details-marker { display: none; }
.step { background: var(--green-light); color: #fff; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; }
.count { color: var(--muted); font-weight: 400; }
.section-body { padding: 0 14px 14px; }
.commune-head { display: flex; gap: 12px; align-items: center; }
.blason { width: 52px; height: 58px; object-fit: contain; }
.cover-row { margin: 4px 0; }
.field-default { font-weight: 400; color: var(--muted); }

/* fiches */
.fiche { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 10px; background: #fcfdfb; }
.fiche > summary { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; list-style: none; }
.fiche > summary::-webkit-details-marker { display: none; }
.fiche-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.badge { color: #fff; font-weight: 700; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.badge.c1 { background: var(--c1); } .badge.c2 { background: var(--c2); } .badge.c3 { background: var(--c3); } .badge.cS { background: var(--cS); }
.fiche-body { padding: 4px 12px 12px; }
.icon { border: none; background: none; cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 5px; color: var(--muted); }
.icon:hover { background: #eef2ec; color: var(--text); }
.icon.danger:hover { background: #fde8e6; }
.add-fiche { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* emplacements photo */
.photo-slot { position: relative; border: 2px dashed var(--line); border-radius: 8px; aspect-ratio: 6/5; display: grid; place-items: center;
              text-align: center; color: var(--muted); font-size: 12px; cursor: pointer; background: #fff center/cover no-repeat;
              margin-bottom: 10px; overflow: hidden; }
.photo-slot.wide { aspect-ratio: 3/2; }
.photo-slot.planning { aspect-ratio: 6.7/1; }
.photo-slot:hover, .photo-slot.drag { border-color: var(--green); color: var(--green); }
.photo-slot.has { border-style: solid; color: transparent; }
.photo-slot .lbl { padding: 6px; pointer-events: none; }
.photo-slot.has .lbl { position: absolute; left: 0; bottom: 0; right: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 11px; padding: 3px; }
.photo-slot .rm { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; border: none; border-radius: 50%;
                  width: 22px; height: 22px; cursor: pointer; display: none; }
.photo-slot.has .rm { display: block; }
.photo-slot:focus { outline: 3px solid var(--green); outline-offset: 1px; border-color: var(--green); }
.photo-slot .paste-hint { display: none; position: absolute; top: 6px; left: 6px; background: var(--green); color: #fff;
                          font-size: 11px; padding: 2px 7px; border-radius: 5px; pointer-events: none; }
.photo-slot:focus .paste-hint, .photo-slot:hover .paste-hint { display: block; }
.photo-slot .browse { position: absolute; bottom: 4px; right: 4px; border: none; background: rgba(255,255,255,.9); border-radius: 6px;
                      cursor: pointer; padding: 2px 6px; font-size: 13px; z-index: 1; }
.photo-slot.has .browse { bottom: 22px; }
.photo-slot.busy::after { content: "Envoi…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.8); color: var(--green); }

/* aperçu */
.preview-pane { display: flex; flex-direction: column; min-height: 0; background: #5f6660; }
.preview-bar { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.preview-status { font-size: 12px; color: var(--muted); }
.preview-status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--green);
                               border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-scroll { flex: 1; overflow: auto; padding: 16px; position: relative; }
#preview-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#preview-pages canvas { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); max-width: 100%; }
.page-num { color: #dfe5de; font-size: 11px; margin-top: -10px; }

/* versions */
dialog { border: none; border-radius: 12px; width: min(640px, 94vw); padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.versions { list-style: none; padding: 0; margin: 14px 0 0; max-height: 55vh; overflow-y: auto; }
.versions li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.versions .when { font-variant-numeric: tabular-nums; min-width: 128px; }
.versions .lbl { flex: 1; }
.versions .lbl.named { font-weight: 600; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .preview-pane { min-height: 70vh; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

/* ---------- planning prévisionnel (éditeur façon carte gestion diff) ---------- */
.cal-editor { border: 1px solid var(--line); border-radius: 9px; padding: 10px; background: #fff; margin-bottom: 8px; }
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.cal-head .cal-modele { width: auto; flex: 1; margin: 0; padding: 5px 8px; }
.cal-chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-bottom: 8px; font-size: 12px; }
.cal-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: #fafbf8; border-radius: 14px;
            padding: 3px 9px; font: inherit; font-size: 12px; cursor: pointer; }
.cal-chip:hover { border-color: var(--green); background: #f1f6ef; }
.cal-chip i, .cal-name i { flex: none; width: 10px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); }
.cal-ed { width: 100%; border-collapse: separate; border-spacing: 2px; table-layout: fixed; user-select: none; }
.cal-ed thead th { font-size: 11px; font-weight: 600; color: #5b6a62; text-align: center; }
.cal-ed thead th:first-child { width: 38%; }
.cal-ed thead th:last-child { width: 62px; }
.cal-ed tbody th { text-align: left; font-weight: 400; padding: 2px 6px 2px 0; vertical-align: middle; }
.cal-name { display: flex; align-items: center; gap: 6px; }
.cal-nom { margin: 0; padding: 2px 4px; border: 1px solid transparent; font-weight: 600; background: transparent; }
.cal-nom:hover { border-color: var(--line); }
.cal-sub { color: #5b6a62; font-size: 11px; margin-left: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-cell { background: #efece3; border-radius: 4px; height: 28px; cursor: crosshair; }
.cal-cell:hover { outline: 2px solid rgba(83,163,1,.55); }
.cal-cell.on { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.cal-act { white-space: nowrap; text-align: right; }
.cal-act .icon { padding: 1px 3px; font-size: 12px; }
.cal-row.open th, .cal-row.open + .cal-detail td { background: #f6f9f4; }
.cal-detail td { padding: 8px; border-radius: 6px; }
.cal-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.cal-detail-grid label { margin-bottom: 6px; }
.cal-detail-grid .span2 { grid-column: span 2; }
.cal-date { display: flex; gap: 4px; }
.cal-date input { width: 64px; flex: none; }
.cal-detail input[type=color] { padding: 2px; height: 32px; }
.cal-capture { margin-bottom: 4px; }
.cal-capture summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 6px; }

/* ---------- connexion & comptes ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 24px 16px;
         background: radial-gradient(ellipse at top, #e7f2dc, var(--bg) 60%); }
.login-card { width: min(400px, 100%); padding: 26px 28px; }
.login-logo { display: block; width: 210px; max-width: 80%; margin: 0 auto 14px; }
.login-card h2 { text-align: center; margin-bottom: 4px; }
.login-card > .muted { text-align: center; margin: 0 0 16px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }
.login-error { background: #fdecea; color: #a12a1e; border-radius: 7px; padding: 7px 10px; font-size: 13px; margin: 4px 0 10px; }
.user-menu { position: relative; margin-left: auto; }
.user-menu + .topbar-right { margin-left: 8px; }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 9px;
                 box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 5px; min-width: 230px; z-index: 20; }
.user-dropdown button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px;
                        font: inherit; cursor: pointer; }
.user-dropdown button:hover { background: #f1f6ef; }
.new-user { display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; gap: 6px; align-items: center; margin: 10px 0; }
.new-user input { margin: 0; }
label.check { display: flex; align-items: center; gap: 5px; margin: 0; white-space: nowrap; }
label.check input { width: auto; margin: 0; }
table.users { width: 100%; border-collapse: collapse; font-size: 13px; }
table.users th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.users td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.users tr.inactive td { opacity: .55; }
table.users .acts { text-align: right; white-space: nowrap; }
.tag { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 8px; background: #e6f1dc; color: var(--green); margin-left: 3px; }
.tag.warn { background: #fff1d6; color: #8a5a00; }
.tag.off { background: #eee; color: #666; }
dialog#dlg-users { width: min(820px, 96vw); }
@media (max-width: 700px) { .new-user { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .brand small { display: none; } }
.photo-slot.optional:not(.has) { aspect-ratio: 5/1; border-style: dotted; }
.photo-hint { margin-top: -6px; }
.install-banner { display: flex; align-items: center; gap: 10px; background: #e6f1dc; border: 1px solid #c9e0b4; color: var(--green);
                  border-radius: var(--radius); padding: 9px 12px; font-size: 13px; }
.install-banner span { flex: 1; }

/* Fiches : numéro + choix du nombre de photos du site */
.fiche-num { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px;
  background: var(--green); color: #fff; font-weight: 700; font-size: 12px; }
.nb-photos { display: flex; white-space: nowrap; align-items: center; gap: 4px; margin: 4px 0 8px; font-size: 13px; font-weight: 600; }
.nb-photos button { width: 32px; height: 28px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 700; }
.nb-photos button:first-of-type { border-radius: 6px 0 0 6px; }
.nb-photos button:last-of-type { border-radius: 0 6px 6px 0; }
.nb-photos button.on { background: var(--green); border-color: var(--green); color: #fff; }
.nb-photos .hint { margin: 0 0 0 8px; white-space: normal; font-weight: 400; }
.photos[data-nb="1"] { grid-template-columns: 1fr; }
.photos[data-nb="1"] .photo-slot { aspect-ratio: 37/10; }
.photos[data-nb="2"] { grid-template-columns: 1fr 1fr; }
.photos[data-nb="2"] .photo-slot { aspect-ratio: 18/10; }

/* Vue aérienne depuis la carte IGN */
.photo-slot .map-btn { position: absolute; bottom: 4px; left: 4px; border: none; background: var(--green); color: #fff;
  border-radius: 6px; padding: 3px 7px; font-size: 11px; font-weight: 600; cursor: pointer; }
.photo-slot .map-btn:hover { background: var(--green-light); }
.photo-slot.has .map-btn { bottom: 22px; }
.dlg-aerial { width: min(960px, 96vw); }
.dlg-aerial .aerial-search input { flex: 1; }
.aerial-results { list-style: none; margin: 6px 0; padding: 0; max-height: 92px; overflow: auto; font-size: 13px; }
.aerial-results li { padding: 3px 8px; border-radius: 6px; cursor: pointer; }
.aerial-results li:hover { background: #eef5e8; }
.aerial-results li.on { background: var(--green); color: #fff; }
.aerial-results li.muted { cursor: default; color: var(--muted); }
.aerial-results li.err { color: #c62828; cursor: default; }
.aerial-map-wrap { position: relative; height: min(60vh, 520px); border-radius: 8px; overflow: hidden; background: #ddd; }
.aerial-map { position: absolute; inset: 0; }
.aerial-frame { position: absolute; z-index: 500; pointer-events: none; border: 3px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35); border-radius: 2px; }
.aerial-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.aerial-foot .hint { flex: 1; margin: 0; }

/* Espace disque */
#dlg-storage { width: min(560px, 94vw); }
table.storage { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
table.storage th, table.storage td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.storage tr:last-child th, table.storage tr:last-child td { font-weight: 700; border-bottom: none; }
.storage-rules { font-size: 13px; padding-left: 18px; margin: 4px 0 10px; }

/* Import d'un plan existant */
.drop-zone { display: block; border: 2px dashed var(--line); border-radius: 10px; padding: 22px 14px; text-align: center;
  color: var(--muted); cursor: pointer; background: #fafcf8; transition: background .15s, border-color .15s; }
.drop-zone:hover, .drop-zone.drag { border-color: var(--green-light); background: #eef5e8; color: var(--green); }
.drop-zone.busy { pointer-events: none; opacity: .7; }
