/* ===========================================================================
   Educatex — feuille de style

   Direction : le cahier d'école romand. Papier légèrement chaud, encre
   bleu-noir, quadrillage discret sur le fond de l'application. Le rouge est
   réservé aux erreurs et aux corrections — jamais à la décoration, jamais à un
   bouton d'action. C'est la seule règle chromatique qui ne se négocie pas :
   dans une interface scolaire, le rouge veut dire quelque chose.

   Aucune police distante : l'isolation d'origine bloque les CDN, et un
   établissement n'a pas à voir ses requêtes partir chez un tiers.
   =========================================================================== */

:root {
  --paper:      #FBFAF6;
  --surface:    #FFFFFF;
  --ink:        #1E3A5C;
  --ink-deep:   #16233A;
  --text:       #23303F;
  --muted:      #6A7789;
  --muted-3:    #A3ADBB;
  --rule:       #E4E1D8;
  --rule-soft:  #EFEDE6;
  --grid:       #E7EDF3;
  --correct:    #B03A2E;
  --warn:       #A8781F;
  --ok:         #2E6B4F;
  --select:     #D9E4F0;
  --line-active:#F4F6F9;

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;

  --cm-command: #1E3A5C;
  --cm-env:     #6B3E8F;
  --cm-math:    #9A5B12;
  --cm-comment: #7A8494;
  --cm-punct:   #A3ADBB;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(22,35,58,.05), 0 8px 24px rgba(22,35,58,.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--paper);
  /* Le quadrillage : présent, jamais bruyant. */
  background-image:
    repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(to right,  var(--grid) 0 1px, transparent 1px 26px);
  background-position: 0 -1px;
  -webkit-text-size-adjust: 100%;
}

body.plain { background-image: none; }

/* --------------------------------------------------------------- structure */

.shell { max-width: 1080px; margin: 0 auto; padding: 0 24px 96px; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--ink-deep);
  text-decoration: none;
  display: inline-flex; align-items: baseline; gap: 9px;
}
/* La marge rouge du cahier, réduite à un trait. Signature discrète. */
.brand::before {
  content: ""; width: 3px; height: 19px; border-radius: 2px;
  background: var(--correct); opacity: .75; transform: translateY(2px);
}

.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 7px 13px; border-radius: 7px; text-decoration: none;
  color: var(--muted); font-size: 14.5px; font-weight: 500;
}
.nav a:hover { background: var(--rule-soft); color: var(--text); }
.nav a[aria-current] { background: var(--ink); color: #fff; }

.whoami { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.whoami .label { font-family: var(--font-mono); color: var(--text); }

/* ------------------------------------------------------------ typographie */

h1 {
  font-family: var(--font-display);
  font-size: 34px; line-height: 1.15; letter-spacing: -0.5px;
  margin: 0 0 6px; color: var(--ink-deep); font-weight: 600;
}
h2 {
  font-family: var(--font-display);
  font-size: 21px; margin: 40px 0 12px; color: var(--ink-deep); font-weight: 600;
}
h3 { font-size: 15px; margin: 0 0 6px; font-weight: 600; }
p { margin: 0 0 14px; }
a { color: var(--ink); }

.lede { font-size: 17px; color: var(--muted); margin-bottom: 32px; max-width: 62ch; }

.eyebrow {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px;
  font-weight: 700; color: var(--muted-3); margin-bottom: 8px;
}

/* ------------------------------------------------------------------ blocs */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.tile {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 18px 20px;
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--ink); transform: translateY(-1px); }
.tile .name { font-weight: 600; color: var(--ink-deep); margin-bottom: 3px; }
.tile .meta { font-size: 13.5px; color: var(--muted); }

.stat { font-family: var(--font-display); font-size: 30px; color: var(--ink-deep); line-height: 1.1; }
.stat + .meta { font-size: 13.5px; color: var(--muted); }

/* ----------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--muted); font-weight: 700; padding: 0 12px 8px; border-bottom: 1px solid var(--rule);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: var(--font-mono); font-size: 14px; }

/* ---------------------------------------------------------------- contrôles */

label { display: block; font-weight: 600; font-size: 14px; margin: 0 0 5px; }
.field { margin-bottom: 16px; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 5px; }

input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 15px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 8px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; min-height: 44px;
  font: inherit; font-size: 15px; font-weight: 600;
  color: #fff; background: var(--ink); border: 1px solid var(--ink);
  border-radius: 8px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--ink-deep); border-color: var(--ink-deep); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { background: var(--rule-soft); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

/* --------------------------------------------------------------- messages */

.notice {
  border-left: 3px solid var(--muted-3);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  padding: 13px 18px; margin: 0 0 24px; font-size: 15px;
}
.notice.success { border-left-color: var(--ok); }
.notice.error   { border-left-color: var(--correct); }
.notice.warn    { border-left-color: var(--warn); }
.notice strong { color: var(--ink-deep); }

.empty {
  border: 1px dashed var(--rule); border-radius: var(--radius);
  padding: 36px 28px; text-align: center; color: var(--muted); background: rgba(255,255,255,.6);
}
.empty h3 { font-family: var(--font-display); font-size: 19px; color: var(--ink-deep); margin-bottom: 6px; }

.tag {
  display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 2px 8px; border-radius: 20px;
  background: var(--rule-soft); color: var(--muted);
}
.tag.archived { background: #F3EAE8; color: var(--correct); }

/* ================================================================ éditeur */

body.editor { height: 100dvh; overflow: hidden; background-image: none; background: var(--surface); }

.ed-shell { display: flex; flex-direction: column; height: 100dvh; }

.ed-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-bottom: 1px solid var(--rule);
  background: var(--paper); flex-shrink: 0;
}
.ed-title {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  color: var(--ink-deep); margin-right: auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ed-state { font-size: 13px; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.ed-state.saving { color: var(--warn); }
.ed-state.error  { color: var(--correct); }

.ed-body { display: flex; flex: 1; min-height: 0; }

.ed-outline {
  width: 236px; flex-shrink: 0; overflow-y: auto;
  border-right: 1px solid var(--rule); background: var(--paper); padding: 12px 8px;
}
.ed-outline .eyebrow { padding: 0 10px 6px; }
.ed-outline button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  font: inherit; font-size: 14px; color: var(--text);
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ed-outline button:hover { background: var(--rule-soft); }
.ed-outline button .num { color: var(--muted-3); font-family: var(--font-mono); font-size: 12px; margin-right: 7px; }
.ed-outline .lvl-2 { padding-left: 22px; }
.ed-outline .lvl-3 { padding-left: 34px; font-size: 13.5px; }
.ed-outline .lvl-4 { padding-left: 46px; font-size: 13.5px; color: var(--muted); }

.ed-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ed-code { flex: 1; min-height: 0; overflow: hidden; }

.ed-preview {
  width: 46%; min-width: 320px; flex-shrink: 0;
  border-left: 1px solid var(--rule); background: var(--line-active);
  display: flex; flex-direction: column;
}
.ed-preview iframe { flex: 1; border: 0; width: 100%; background: var(--line-active); }
.ed-preview .placeholder { margin: auto; padding: 32px; text-align: center; color: var(--muted); max-width: 340px; }
.ed-preview .placeholder h3 { font-family: var(--font-display); font-size: 18px; color: var(--ink-deep); }

.ed-log {
  max-height: 34%; overflow: auto; border-top: 1px solid var(--rule);
  background: var(--surface); padding: 10px 14px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap;
  color: var(--muted);
}
.ed-log .err { color: var(--correct); }

/* Palette de symboles : sur iPad sans clavier physique, ce n'est pas un
   confort mais une condition d'usage — « \ », « { » et « $ » sont enfouis. */
.ed-palette {
  display: flex; gap: 5px; overflow-x: auto; flex-shrink: 0;
  padding: 7px 10px; border-top: 1px solid var(--rule); background: var(--paper);
  scrollbar-width: thin;
}
.ed-palette button {
  flex-shrink: 0; min-width: 44px; min-height: 38px;
  font-family: var(--font-mono); font-size: 14px;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: 7px; color: var(--ink-deep); cursor: pointer; padding: 0 10px;
}
.ed-palette button:active { background: var(--select); }
.ed-palette .sep { width: 1px; background: var(--rule); margin: 4px 4px; flex-shrink: 0; }

@media (max-width: 900px) {
  .ed-outline { display: none; }
  .ed-outline.open { display: block; position: absolute; z-index: 20; height: calc(100dvh - 53px); box-shadow: var(--shadow); }
  .ed-preview { display: none; }
  .ed-body.show-preview .ed-main { display: none; }
  .ed-body.show-preview .ed-preview { display: flex; width: 100%; min-width: 0; }
}

/* ====================================================== fiches à découper */

.sheet { font-family: var(--font-ui); color: var(--text); background: #fff; }
.sheet-head { max-width: 190mm; margin: 0 auto; padding: 20px 8mm 12px; }
.sheet-head h1 { font-size: 24px; margin-bottom: 2px; }
.sheet-head p { color: var(--muted); font-size: 14px; }

.tickets {
  max-width: 190mm; margin: 0 auto; padding: 0 8mm 24px;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0;
}
@supports not (display: grid) {
  .tickets { display: flex; flex-wrap: wrap; }
  .tickets .ticket { width: 50%; }
}
.ticket {
  border: 1px dashed var(--muted-3);
  padding: 12px 14px 13px;
  margin: -0.5px;                     /* les traits de coupe se superposent */
  min-height: 40mm;
  break-inside: avoid;
}
.ticket-body { display: flex; gap: 12px; align-items: stretch; }
.ticket-text { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; }
.ticket-qr {
  flex-shrink: 0; width: 104px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ticket-qr svg { display: block; width: 104px; height: 104px; }
.qr-caption {
  font-size: 9px; color: var(--muted); text-align: center;
  margin-top: 3px; letter-spacing: .2px;
}
.ticket .head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--muted); margin-bottom: 8px;
}
.ticket .site { font-weight: 700; color: var(--ink-deep); letter-spacing: .3px; }
.ticket .row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.ticket .k {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); width: 76px; flex-shrink: 0; white-space: nowrap;
}
.ticket .v { font-family: var(--font-mono); font-size: 16px; color: var(--ink-deep); font-weight: 600; letter-spacing: .2px; }
.ticket .name-line { margin-top: 10px; font-size: 10.5px; color: var(--muted); }
.ticket .name-line span { display: inline-block; border-bottom: 1px solid var(--rule); width: 62%; margin-left: 6px; }

.print-actions { max-width: 190mm; margin: 0 auto 20px; padding: 0 8mm; display: flex; gap: 10px; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .print-actions, .no-print { display: none !important; }
  .ticket { border-color: #999; }
}

/* --------------------------------------------------------- accessibilité */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 640px) {
  .shell { padding: 0 16px 64px; }
  h1 { font-size: 27px; }
  .topbar { gap: 12px; }
  .nav { width: 100%; order: 3; }
}
