:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #EEF1F5;
  --ink: #0F1B2D;
  --ink-2: #4A5668;
  --ink-3: #7B8698;
  --line: #DDE2EA;
  --navy: #12263F;
  --navy-2: #1C3857;
  --red: #D42A2A;
  --red-dark: #A91E1E;
  --red-soft: #FDECEC;
  --green: #138A54;
  --green-soft: #E4F5EC;
  --amber: #B45F06;
  --amber-soft: #FFF3E0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { display: block; font-size: 12.5px; font-weight: 500; opacity: .72; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--red);
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { width: 20px; height: 20px; }
.icon-btn {
  appearance: none; border: 0; background: rgba(255,255,255,.1); color: #fff;
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.icon-btn svg { width: 22px; height: 22px; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; min-height: 48px; border-radius: 12px;
  font-weight: 650; font-size: 15.5px; text-decoration: none; text-align: center;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-ghost { background: var(--surface); border-color: #F2C4C4; color: var(--red); }
.btn-block { width: 100%; }
.btn-lg { min-height: 58px; font-size: 17px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 160px; }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card p.muted { margin: 0 0 14px; }
.muted { color: var(--ink-2); font-size: 14.5px; }
.tiny { color: var(--ink-3); font-size: 13px; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin: 22px 4px 10px;
}

.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  border: 1px solid transparent; text-align: left; width: 100%;
  appearance: none;
}
.row:hover { border-color: var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--ink-2); font-size: 13.5px; }
.chev { color: var(--ink-3); width: 20px; height: 20px; flex: none; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: var(--surface-2); color: var(--navy);
}
.class-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; flex: none; font-weight: 700; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.badge-red { background: var(--red-soft); color: var(--red-dark); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-gray { background: var(--surface-2); color: var(--ink-2); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.quick-call {
  appearance: none; border: 0; cursor: pointer; flex: none;
  width: 48px; height: 48px; border-radius: 50%; background: var(--green); color: #fff;
  display: grid; place-items: center; text-decoration: none;
}
.quick-call svg { width: 22px; height: 22px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat b { display: block; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--ink-2); }

.empty {
  text-align: center; padding: 38px 20px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px dashed var(--line);
}
.empty > svg { width: 46px; height: 46px; color: var(--ink-3); }
.empty h3 { margin: 10px 0 6px; font-size: 17px; }
.empty p { margin: 0 auto 18px; max-width: 380px; color: var(--ink-2); font-size: 14.5px; }

/* ---------- Search ---------- */
.search {
  position: relative; margin-bottom: 14px;
}
.search input {
  width: 100%; min-height: 52px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--surface); padding: 12px 14px 12px 46px; font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(18,38,63,.12); }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--ink-3); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 650; font-size: 14.5px; margin-bottom: 6px; }
.field label .opt { font-weight: 500; color: var(--ink-3); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 50px; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; background: var(--surface); font-size: 16px; outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(18,38,63,.12); }
.field .hint { font-size: 13px; color: var(--ink-3); margin-top: 5px; }
.field.invalid input, .field.invalid select { border-color: var(--red); }
.field .err { color: var(--red); font-size: 13px; margin-top: 5px; display: none; }
.field.invalid .err { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

.fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 4px; margin: 0 0 16px;
  background: var(--surface);
}
.fieldset legend { font-weight: 750; padding: 0 6px; font-size: 15px; }

.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 12px;
  background: var(--surface-2); cursor: pointer; font-size: 14.5px; line-height: 1.4;
}
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--navy); }

/* ---------- Emergency sheet ---------- */
.sos-head {
  background: var(--red); color: #fff; border-radius: var(--radius); padding: 18px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.sos-head .who { font-size: 24px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; }
.sos-head .cls { opacity: .85; font-size: 14px; margin-top: 2px; }
.med { display: grid; gap: 8px; margin-top: 14px; }
.med div { background: rgba(255,255,255,.14); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.med b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity: .8; font-weight: 700; }

.contact-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.contact-card .rank { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.contact-card .name { font-size: 19px; font-weight: 750; margin: 2px 0 0; }
.contact-card .rel { color: var(--ink-2); font-size: 14.5px; }
.contact-card .num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; margin: 8px 0 12px; }
.call-big {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 64px; border-radius: 14px; background: var(--green); color: #fff; font-weight: 800; font-size: 18px;
  text-decoration: none; width: 100%;
}
.call-big svg { width: 24px; height: 24px; }
.call-big:active { transform: scale(.985); }
.wa-link {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px;
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line); text-decoration: none; font-weight: 650; color: var(--ink);
}
.wa-link svg { width: 20px; height: 20px; color: #1DA851; }

.services { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.service {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 78px; border-radius: 14px; background: var(--navy); color: #fff; text-decoration: none; padding: 8px;
}
.service b { font-size: 22px; font-variant-numeric: tabular-nums; }
.service span { font-size: 12.5px; opacity: .85; text-align: center; }

/* ---------- FAB ---------- */
.fab-sos {
  position: fixed; right: 16px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 30;
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--red); color: #fff; border: 0; border-radius: 999px;
  padding: 0 22px 0 18px; height: 60px; font-weight: 800; font-size: 17px; letter-spacing: .02em;
  box-shadow: 0 8px 24px rgba(212, 42, 42, .38); cursor: pointer;
}
.fab-sos svg { width: 24px; height: 24px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 27, 45, .55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-back { align-items: center; } }
.modal {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 94vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px max(20px, env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: 20px; padding: 24px; } }
.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal .close-x { float: right; appearance: none; border: 0; background: var(--surface-2); width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1; }

/* ---------- Scanner ---------- */
.scanner {
  position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column;
}
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame {
  position: absolute; left: 50%; top: 42%; width: min(72vw, 320px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.9); border-radius: 22px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
  pointer-events: none;
}
.scanner .bar {
  background: #0B1626; color: #fff; padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.scanner .count { font-size: 15px; text-align: center; opacity: .9; }
.scanner .top-msg {
  position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; right: 16px; text-align: center;
  color: #fff; font-weight: 650; font-size: 16px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.flash-ok { animation: flashok .6s ease; }
@keyframes flashok { 0% { box-shadow: 0 0 0 9999px rgba(19,138,84,.55); } 100% { box-shadow: 0 0 0 9999px rgba(0,0,0,.45); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 80;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); text-align: center;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ---------- QR display ---------- */
.qr-box {
  background: #fff; border-radius: 18px; padding: 18px; display: grid; place-items: center; box-shadow: var(--shadow);
}
.qr-box img, .qr-box canvas { width: 100%; max-width: 340px; height: auto; image-rendering: pixelated; }

.notice {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4; margin-bottom: 14px;
  background: #EAF1FB; color: #1C3857;
}
.notice svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.notice.warn { background: var(--amber-soft); color: #7A3F00; }

.divider { height: 1px; background: var(--line); margin: 16px 0; }
.kbd-code {
  width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; min-height: 110px; word-break: break-all;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface);
}

/* ---------- Print ---------- */
.print-sheet { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body > *:not(.print-sheet) { display: none !important; }
  .print-sheet { display: block !important; color: #000; font-size: 11pt; }
  .print-sheet h1 { font-size: 16pt; margin: 0 0 2mm; }
  .print-sheet .p-sub { font-size: 10pt; margin-bottom: 4mm; }
  .print-sheet table { width: 100%; border-collapse: collapse; }
  .print-sheet th, .print-sheet td { border: 1px solid #555; padding: 1.6mm 2mm; text-align: left; vertical-align: top; font-size: 9.5pt; }
  .print-sheet th { background: #eee; }
  .print-sheet .p-foot { margin-top: 4mm; font-size: 9pt; }
  .print-sheet tr { break-inside: avoid; }
}

/* ---------- Formulaires vierges (impression) ---------- */
@media print {
  .print-sheet .b-slip { border: 1.2px dashed #555; border-radius: 3mm; padding: 4mm 5mm; margin-bottom: 4mm; break-inside: avoid; height: 88mm; display: flex; flex-direction: column; gap: 2.2mm; }
  .print-sheet .b-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4mm; border-bottom: 1px solid #999; padding-bottom: 1.5mm; }
  .print-sheet .b-head b { font-size: 12pt; white-space: nowrap; }
  .print-sheet .b-head span { font-size: 9pt; color: #333; text-align: right; }
  .print-sheet .b-sub { font-size: 9pt; font-weight: 700; margin-top: 1mm; }
  .print-sheet .b-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4mm; }
  .print-sheet .b-grid3 { display: grid; grid-template-columns: 1.4fr .8fr 1fr; gap: 4mm; }
  .print-sheet .b-line { display: flex; align-items: flex-end; gap: 2mm; font-size: 8.5pt; min-height: 7mm; }
  .print-sheet .b-line span { white-space: nowrap; color: #333; }
  .print-sheet .b-line i { flex: 1; border-bottom: 1px solid #777; height: 5mm; }
  .print-sheet .b-consent { font-size: 8pt; line-height: 1.35; margin-top: auto; display: flex; flex-direction: column; gap: 2mm; }
  .print-sheet .b-consent span { align-self: flex-end; font-size: 9pt; }
}

/* ---------- Actions de classe ---------- */
.class-actions { margin: 10px 0 18px; }
.class-actions > .btn { flex: 1 1 90px; padding: 10px 8px; font-size: 14.5px; }
.icon-act {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-act svg { width: 19px; height: 19px; }
.icon-act:hover { background: var(--surface-2); }
.icon-act.danger { color: var(--red); border-color: #F2C4C4; }
#createBig { margin-bottom: 4px; }

/* ---------- Répertoire d'urgence étudiant ---------- */
.rep-filter { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; margin: -4px 0 4px; scrollbar-width: none; }
.rep-filter::-webkit-scrollbar { display: none; }
.chip-f {
  appearance: none; flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 38px;
}
.chip-f[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.rep-letter { font-size: 13px; font-weight: 800; color: var(--ink-3); letter-spacing: .06em; margin: 16px 6px 8px; }
.acc { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.acc-head {
  appearance: none; border: 0; background: none; width: 100%; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; color: inherit;
}
.acc-head .grow { flex: 1; min-width: 0; }
.acc-head .title { font-weight: 650; font-size: 16px; }
.acc-head .meta { color: var(--ink-2); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-chev { width: 22px; height: 22px; color: var(--ink-3); flex: none; transition: transform .2s ease; }
.acc-head[aria-expanded="true"] .acc-chev { transform: rotate(180deg); }
.acc-head[aria-expanded="true"] { background: var(--surface-2); }
.acc-body { padding: 4px 16px 14px; border-top: 1px solid var(--line); }
.rep-med { display: grid; gap: 6px; margin: 12px 0 4px; }
.rep-med div { background: var(--red-soft); color: var(--red-dark); border-radius: 10px; padding: 9px 12px; font-size: 14.5px; }
.rep-med b { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.rep-contact { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rep-contact .grow { flex: 1; min-width: 0; }
.rep-cname { font-weight: 700; font-size: 16px; }
.rep-num { font-size: 15.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.rep-call { min-height: 44px; padding: 8px 14px; flex: none; }
.rep-wa { text-decoration: none; color: #1DA851; }
.rep-more { display: inline-block; margin-top: 12px; font-size: 14px; font-weight: 650; color: var(--navy); text-decoration: none; }
@media (prefers-reduced-motion: reduce) { .acc-chev { transition: none; } }
.rep-med .rep-sang { background: var(--surface-2); color: var(--ink); }

/* ---------- Accueil : accès principaux ---------- */
.home-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 4px; }
.tile {
  appearance: none; border: 1px solid transparent; background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius);
  padding: 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; color: var(--ink); min-height: 118px;
}
.tile:hover { border-color: var(--line); }
.tile b { font-size: 15px; line-height: 1.25; }
.tile > span:last-child { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.tile-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--navy); margin-bottom: 4px; }
.tile-ic svg { width: 21px; height: 21px; }
.tile-ic.tile-red { background: var(--red-soft); color: var(--red-dark); }

/* ---------- Console admin v2 ---------- */
.net-bar { position: sticky; top: 60px; z-index: 15; background: #7A3F00; color: #fff; font-size: 13.5px; padding: 8px 16px; text-align: center; }
.url-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 6px 6px 6px 12px; }
.url-box code { flex: 1; min-width: 0; font: 13px/1.35 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }
.url-box .btn { min-height: 40px; padding: 6px 14px; flex: none; }
.qr-more { margin-top: 12px; }
.qr-more summary { cursor: pointer; font-weight: 650; font-size: 14.5px; color: var(--navy); padding: 6px 2px; }
.badges .badge-green { background: var(--green-soft); color: var(--green); }

.more-opts { margin-top: 20px; }
.more-opts .btn { margin-top: 10px; }

/* ---------- Code de connexion ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 5px; border-radius: 14px; margin-bottom: 14px; }
.seg button { appearance: none; border: 0; background: transparent; border-radius: 10px; min-height: 44px; font-weight: 650; font-size: 15px; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.code-big { font: 700 26px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .12em; text-align: center; padding: 16px 10px; border: 2px dashed var(--navy); border-radius: 14px; background: var(--surface); user-select: all; overflow-wrap: anywhere; }
