:root {
  color-scheme: light;
  --green-950: #102f29;
  --green-900: #173f35;
  --green-800: #205548;
  --green-700: #286b5a;
  --green-100: #e3f1ed;
  --green-50: #f1f8f6;
  --orange: #f2a51a;
  --orange-dark: #b96d00;
  --red: #c73c3c;
  --red-soft: #fff0ef;
  --amber: #b76e00;
  --amber-soft: #fff6dc;
  --blue: #176b9b;
  --blue-soft: #e9f5fb;
  --ink: #1d2a27;
  --muted: #65736f;
  --line: #dce4e1;
  --surface: #ffffff;
  --canvas: #f4f7f6;
  --shadow: 0 12px 32px rgba(16, 47, 41, 0.08);
  --radius: 16px;
  --header-height: 76px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(242, 165, 26, 0.48);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 1rem;
  z-index: 100;
  padding: .75rem 1rem;
  background: var(--ink);
  color: white;
  border-radius: 8px;
}
.skip-link:focus { top: 1rem; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem clamp(1rem, 3vw, 2rem);
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand, .header-actions { display: flex; align-items: center; gap: .8rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--green-900), var(--green-700));
  color: white;
  font-weight: 900;
  letter-spacing: -.05em;
  box-shadow: 0 8px 18px rgba(23, 63, 53, .22);
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1.1rem; }
.brand span { margin-top: .1rem; color: var(--muted); font-size: .78rem; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .42rem .72rem;
  border-radius: 999px;
  background: var(--green-100);
  color: var(--green-900);
  font-size: .78rem;
  font-weight: 800;
}
.status-pill.offline { background: var(--amber-soft); color: var(--amber); }

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  position: sticky;
  top: var(--header-height);
  align-self: start;
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: 1.5rem 1rem;
  background: var(--green-950);
}

.nav-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .85rem 1rem;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #dcece7;
  text-align: left;
  font-weight: 700;
}
.nav-item span { width: 1.2rem; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active {
  background: var(--orange);
  color: #2f260f;
  box-shadow: 0 7px 16px rgba(0,0,0,.12);
}

.main-content {
  width: min(100%, 1500px);
  padding: clamp(1.25rem, 3vw, 2.5rem);
  margin: 0 auto;
}

.view { display: none; animation: appear .2s ease-out; }
.view.active { display: block; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  margin-bottom: 1.6rem;
}
.page-heading h1 { margin: .15rem 0 .35rem; font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow {
  margin: 0 !important;
  color: var(--orange-dark) !important;
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.button {
  min-height: 42px;
  padding: .7rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 850;
  white-space: nowrap;
}
.button-primary { background: var(--green-800); color: white; }
.button-primary:hover { background: var(--green-950); }
.button-secondary { background: white; color: var(--green-900); border-color: var(--line); }
.button-secondary:hover { background: var(--green-50); }
.text-button { border: 0; background: transparent; color: var(--green-700); font-weight: 850; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; line-height: 1; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat-card, .panel, .record-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card {
  position: relative;
  overflow: hidden;
  min-height: 150px;
  padding: 1.15rem;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--green-700);
}
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card strong { display: block; margin: .5rem 0 .35rem; font-size: 2.35rem; }
.stat-danger::before { background: var(--red); }
.stat-warning::before { background: var(--orange); }
.stat-success::before { background: #299464; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 1rem;
}
.panel { min-width: 0; padding: 1.2rem; }
.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.panel-heading h2 { margin: 0 0 .25rem; font-size: 1.08rem; }
.panel-heading p { margin: 0; color: var(--muted); font-size: .86rem; }

.list-container { min-height: 180px; }
.empty-state {
  display: grid;
  place-items: center;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: .9rem 0;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row strong, .list-row small { display: block; }
.list-row small { margin-top: .2rem; color: var(--muted); }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.record-card { padding: 1.15rem; }
.record-card h3 { margin: 0 0 .35rem; }
.record-card p { color: var(--muted); }
.record-card footer {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: center;
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}

.badge {
  display: inline-flex;
  padding: .32rem .55rem;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: .73rem;
  font-weight: 900;
  text-transform: uppercase;
}
.badge-critique { background: var(--red-soft); color: var(--red); }
.badge-eleve { background: var(--amber-soft); color: var(--amber); }
.badge-modere { background: var(--blue-soft); color: var(--blue); }
.badge-faible, .badge-realisee { background: var(--green-100); color: var(--green-700); }

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}
.toolbar label { color: var(--muted); font-size: .85rem; font-weight: 750; }
.toolbar select { margin-left: .5rem; }

select, input, textarea {
  width: 100%;
  min-height: 44px;
  padding: .65rem .75rem;
  border: 1px solid #cbd7d3;
  border-radius: 9px;
  background: white;
  color: var(--ink);
}
textarea { min-height: 100px; resize: vertical; }
.table-wrap {
  overflow-x: auto;
  min-height: 200px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  background: var(--green-50);
  color: var(--green-900);
  font-size: .77rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.data-table tr:last-child td { border-bottom: 0; }
.actions-cell { display: flex; gap: .35rem; }
.small-button {
  padding: .38rem .55rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--green-800);
  font-size: .77rem;
  font-weight: 800;
}

dialog {
  width: min(680px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 0;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(12, 30, 26, .65); backdrop-filter: blur(3px); }
dialog form { padding: 1.4rem; }
.dialog-heading, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.dialog-heading { margin-bottom: 1.25rem; }
.dialog-heading h2 { margin: .15rem 0 0; }
.dialog-actions { justify-content: flex-end; margin-top: 1.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-field { display: grid; gap: .35rem; font-weight: 750; font-size: .85rem; }
.form-field.full { grid-column: 1 / -1; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  max-width: min(390px, calc(100% - 2rem));
  padding: .85rem 1rem;
  border-radius: 10px;
  background: var(--green-950);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --header-height: 68px; }
  .app-header { padding: .65rem .8rem; }
  .brand span, .status-pill { display: none; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: .45rem;
    border-top: 1px solid rgba(255,255,255,.15);
  }
  .nav-item {
    flex: 0 0 72px;
    min-height: 54px;
    justify-content: center;
    flex-direction: column;
    gap: .1rem;
    padding: .35rem;
    font-size: .62rem;
    text-align: center;
  }
  .nav-item span { font-size: 1.05rem; }
  .main-content { padding: 1rem 1rem 88px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading .button { width: 100%; }
  .stats-grid, .cards-grid { grid-template-columns: 1fr; }
  .stats-grid { gap: .7rem; }
  .stat-card { min-height: 118px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
  .data-table th:nth-child(3), .data-table td:nth-child(3) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

/* Accès propriétaire */
body.locked .app-header, body.locked .app-shell { display: none; }
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; background: #eef5f2; }
body:not(.locked) .login-screen { display: none; }
.login-card { width: min(100%, 430px); padding: 2rem; background: white; border-radius: 18px; box-shadow: 0 14px 48px rgba(16,47,41,.14); display: grid; gap: 1rem; }
.login-card h1 { margin: 0; font-size: 1.7rem; }
.login-card p { margin: 0; color: #52645f; }
.login-card label { font-weight: 700; }
.login-card input { font: inherit; padding: .8rem; border: 1px solid #82988e; border-radius: 8px; width: 100%; }
.login-card #loginError { color: #a82424; min-height: 1.4em; }

.module-heading-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
@media (max-width:760px) { .module-heading-actions { flex-direction: column; } }

[hidden] { display: none !important; }
.admin-form { display: grid; gap: .9rem; max-width: 620px; margin-bottom: 1.3rem; }
.admin-form h2 { margin: 0; }
.admin-form label { display: grid; gap: .3rem; font-weight: 700; }
.admin-form input, .admin-form select { width: 100%; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: white; }
.admin-form select[multiple] { min-height: 125px; }
#temporaryCredential { margin: 1rem 0; overflow-wrap: anywhere; border: 2px solid var(--orange); }

.indicators-panel { margin-bottom: 1.2rem; }
.indicators-panel .panel-heading { gap: 1rem; flex-wrap: wrap; }
.indicators-panel select { max-width: 260px; padding: .55rem; border: 1px solid var(--line); border-radius: 8px; }
.indicators-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 1.4rem; }
.indicators-grid h3 { font-size: 1rem; margin: .2rem 0 1rem; }
.indicator-row { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(60px, 1fr) 2rem; align-items: center; gap: .55rem; margin: .55rem 0; font-size: .85rem; }
.indicator-row strong { text-align: right; }
.indicator-track { height: .8rem; background: #e9f0ec; border-radius: 10px; overflow: hidden; }
.indicator-track span { display: block; height: 100%; background: #337869; border-radius: inherit; }
.indicator-trend { display: grid; grid-template-columns: repeat(12, minmax(22px, 1fr)); gap: .25rem; overflow-x: auto; }
.indicator-month { display: grid; grid-template-rows: 1.2rem 100px 2.4rem; text-align: center; align-items: end; min-width: 22px; font-size: .72rem; }
.indicator-column { height: 100px; display: flex; align-items: end; background: #f2f6f4; border-radius: 4px; }
.indicator-column span { width: 100%; background: #337869; border-radius: 4px 4px 0 0; }
.indicator-month small { align-self: start; overflow-wrap: anywhere; line-height: 1.1; }

.audit-point-row { display:grid; grid-template-columns: minmax(150px,2fr) minmax(110px,1fr) minmax(150px,2fr) auto; gap:.5rem; align-items:end; margin:.8rem 0; }
.audit-point-row label { display:grid; gap:.25rem; }
.audit-point-row input,.audit-point-row select { width:100%; padding:.6rem; border:1px solid var(--line); border-radius:8px; }
@media(max-width:760px) { .audit-point-row { grid-template-columns:1fr; padding:.8rem; border:1px solid var(--line); border-radius:10px; } }

.phase-tabs { display:flex; gap:.5rem; flex-wrap:wrap; margin-bottom:.8rem; }
.phase-tabs [aria-pressed="true"] { background:var(--green-900); color:white; }
.phase-count { color:#52645f; margin:0 0 1rem; }
.phase-checks { margin:.9rem 0; padding:.75rem; background:#f3f7f5; border-radius:9px; }
.phase-checks ul { margin:.5rem 0 0; padding-left:1.2rem; }
.phase-checks li { margin:.25rem 0; }
.phase-checks .missing { color:#9a4b18; }
.phase-checks .ready { color:#246251; }

.report-controls { margin-bottom:1rem; flex-wrap:wrap; }
.report-controls input,.report-controls select { padding:.55rem; border:1px solid var(--line); border-radius:8px; }
.report-print { overflow-x:auto; }
.report-footnote { margin-top:1.5rem; color:#52645f; font-size:.85rem; }
@media print { body { background:white !important; } .login-screen,.app-header,.sidebar,.report-controls,.skip-link { display:none !important; } .app-shell,.main-content { display:block !important; margin:0 !important; padding:0 !important; width:100% !important; } .view { display:none !important; } #view-rapport { display:block !important; } #view-rapport .page-heading { display:none; } .report-print { border:0; box-shadow:none; padding:0; overflow:visible; } .table-wrap { overflow:visible; } .data-table { font-size:10pt; } tr { break-inside:avoid; } }

.alert-count { display:inline-flex; justify-content:center; align-items:center; min-width:1.6rem; padding:.1rem .35rem; border-radius:1rem; background:#a82424; color:white; margin-left:auto; font-size:.75rem; }
.alert-row { border-left:4px solid #e2ad55; }
.alert-level-0 { border-left-color:#b54335; }
.alert-level-2 { border-left-color:#4d8e78; }
.alert-row small { display:block; margin-top:.25rem; }

.matrix-scroll { overflow-x: auto; margin: .8rem 0 1.4rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.matrix-scroll:empty { display: none; }
.matrix-scroll h2 { margin: 1rem; font-size: 1.05rem; }
.matrix-scroll .data-table { min-width: 680px; }
.matrix-scroll th small { display: block; font-weight: normal; text-transform: none; letter-spacing: 0; }

.contact-list { display:grid; gap:.75rem; padding-left:1.2rem; }
.contact-list li { line-height:1.5; overflow-wrap:anywhere; }
.contact-list li span { display:block; }
.contact-links { display:flex; flex-wrap:wrap; gap:.35rem .8rem; margin-top:.15rem; }
.contact-links a { font-weight:600; }

.site-instructions { margin:.8rem 0; padding:.75rem 1rem; border:1px solid #bed8cc; border-left:4px solid #2e7660; border-radius:.6rem; background:#f5faf7; }
.site-instructions summary { cursor:pointer; font-weight:700; }
.site-instructions p { white-space:pre-wrap; overflow-wrap:anywhere; margin:.7rem 0 0; }
.site-instructions-missing { border-left:4px solid #bc543e; padding:.55rem .75rem; background:#fff5f1; }

.form-error { margin: 1rem 0; padding: .75rem 1rem; border: 1px solid #c46a57; border-radius: .6rem; background: #fff1ed; color: #7d241a; font-weight: 600; }
.form-error[hidden] { display: none; }

.indicator-bars { display: grid; gap: .65rem; }
.indicator-row { display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(5rem, 2fr) 2rem; align-items: center; gap: .75rem; font-size: .9rem; }
.indicator-row progress { width: 100%; height: .85rem; accent-color: #2b7665; }
.indicator-row strong { text-align: right; }
@media (max-width: 520px) { .indicator-row { grid-template-columns: minmax(6rem, 1fr) minmax(4rem, 1fr) 2rem; gap: .4rem; } }

.dashboard-site-picker { display: grid; gap: .3rem; min-width: min(16rem, 100%); font-weight: 600; font-size: .85rem; }
.dashboard-site-picker select { width: 100%; padding: .65rem; border: 1px solid #b9c8c2; border-radius: .55rem; background: #fff; color: #173f35; }

/* Choix d'activation des paramètres de diffusion. */
.admin-form label.setting-toggle { flex-direction: row; align-items: center; gap: .65rem; }
.admin-form label.setting-toggle input[type="checkbox"] { width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; flex: 0 0 auto; }

/* Les commandes et l'historique de diffusion restent lisibles sur petits écrans. */
.report-controls { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr)); gap:1rem; align-items:end; }
.report-controls label { display:flex; flex-direction:column; gap:.35rem; min-width:0; }
.report-controls input,.report-controls select { box-sizing:border-box; width:100%; min-width:0; margin:0; }
.report-controls .button { min-width:0; white-space:normal; }
.email-history-list { margin-bottom:1rem; overflow-wrap:anywhere; }
.email-history-list li { margin-bottom:1rem; }
#communicationEmailDialog { width:min(640px,calc(100% - 2rem)); max-height:90dvh; overflow:auto; box-sizing:border-box; }
#communicationEmailForm { display:grid; gap:1rem; }
#communicationEmailForm textarea { box-sizing:border-box; width:100%; min-height:6rem; }
@media print { .email-history-list { display:none !important; } }

#offlineConstatsDialog { width:min(720px,calc(100% - 2rem)); max-height:90dvh; overflow:auto; box-sizing:border-box; }
#offlineConstatsDialog .setting-toggle { display:flex; flex-direction:row; gap:.6rem; align-items:flex-start; }
#offlineConstatsDialog .setting-toggle input { width:auto; flex:0 0 auto; }
#offlineConstatsDialog .panel { margin:1rem 0; }

.offline-editor-body { background:var(--green-50,#f4f7f6); }
.offline-editor-main { max-width:860px; padding:2rem 1rem; margin:0 auto; }
.offline-editor-main > select { width:100%; padding:.65rem; margin:.5rem 0; }
.offline-editor-main .admin-form { max-width:none; }
.offline-editor-main .panel { margin:1rem 0; }
.offline-editor-main textarea { min-height:5rem; }
#offlineConstatsDialog > .button { margin:.5rem .5rem .5rem 0; }
