/* =====================================================================
   Colloscope — styles (limités à .cs / .cs-*), variables --ot-* d'Otoolia
   ===================================================================== */
.cs { --cs-accent: var(--ot-brand); --cs-warn: #b45309; --cs-danger: #c81e1e; --cs-ok: #15803d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cs { --cs-warn: #fbbf24; --cs-danger: #f87171; --cs-ok: #4ade80; }
}
:root[data-theme="dark"] .cs { --cs-warn: #fbbf24; --cs-danger: #f87171; --cs-ok: #4ade80; }

.cs-head h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
.cs-grid { display: grid; gap: var(--ot-space); grid-template-columns: 1fr; margin-bottom: var(--ot-space); }
@media (min-width: 900px) { .cs-grid { grid-template-columns: 1fr 1fr; } }
.cs-full { grid-column: 1 / -1; }
.cs-panel h2 { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.cs-panel h2 .cs-num { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--cs-accent); color: var(--ot-brand-ink); font-size: .8rem; flex: none; }
.cs-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cs-bar h2 { margin: 0; }
.cs-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cs-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cs-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cs-field label { font-size: .82rem; font-weight: 600; }
.cs-wide { grid-column: 1 / -1; }
.cs .ot-input, .cs .ot-select { padding: 7px 10px; min-height: 38px; width: 100%; font-size: .92rem; }
.cs-hint { font-size: .8rem; color: var(--ot-text-soft); margin: 0; }
.cs-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: .9rem; cursor: pointer; }
.cs-check input { width: 17px; height: 17px; accent-color: var(--cs-accent); flex: none; }
.cs-sub { margin-top: 10px; padding-left: 14px; border-left: 3px solid var(--cs-accent); display: flex; flex-direction: column; gap: 8px; }
.cs-btn-s { min-height: 34px; padding: 5px 14px; font-size: .88rem; }

/* Matières */
.cs-subjects { display: flex; flex-direction: column; gap: 6px; max-height: 430px; overflow-y: auto; padding-right: 4px; }
.cs-subj { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: var(--ot-radius-s);
  background: var(--ot-surface-2); border: 1px solid var(--ot-border); }
.cs-subj.is-on { border-color: var(--cs-accent); }
.cs-subj .cs-check { flex: 1; font-weight: 500; }
.cs-subj .cs-color { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--ot-border); border-radius: 6px; background: var(--ot-surface); cursor: pointer; flex: none; }
.cs-subj .cs-per { width: 64px; min-height: 32px; padding: 3px 6px; text-align: center; }
.cs-per-unit { font-size: .78rem; color: var(--ot-text-soft); }
.cs-x { background: none; border: 0; color: var(--cs-danger); cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 6px; }
.cs-x:hover { background: var(--ot-surface-2); }
.cs-custom { margin-top: 10px; display: flex; gap: 6px; }

/* Lignes de colles */
.cs-lines { display: flex; flex-direction: column; gap: 12px; }
.cs-line { background: var(--ot-surface-2); border: 1px solid var(--ot-border); border-radius: var(--ot-radius-s); padding: 12px;
  display: flex; flex-direction: column; gap: 8px; }
.cs-line__top { display: grid; grid-template-columns: auto minmax(120px, 1fr) minmax(140px, 220px) 110px auto; gap: 8px; align-items: center; }
@media (max-width: 640px) { .cs-line__top { grid-template-columns: auto 1fr 1fr; } .cs-line__top .cs-name { grid-column: 2 / -1; } }
.cs-ab-pref { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.cs-ab-pref .ot-select { width: auto; }
.cs-days { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.cs-day { background: var(--ot-surface); border: 1px solid var(--ot-border); border-radius: var(--ot-radius-s); padding: 8px;
  display: flex; flex-direction: column; gap: 6px; }
.cs-day .ot-input { min-height: 32px; padding: 4px 8px; font-size: .85rem; }

/* Barre d'actions et messages */
.cs-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cs-messages { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--ot-radius-s); font-size: .9rem;
  background: var(--ot-surface-2); border-left: 4px solid var(--cs-accent); }
.cs-messages p { margin: 2px 0; }
.cs-messages[data-level="ok"] { border-left-color: var(--cs-ok); }
.cs-messages[data-level="warn"] { border-left-color: var(--cs-warn); }
.cs-messages[data-level="danger"] { border-left-color: var(--cs-danger); }
.cs-messages[data-level="danger"] p:first-child { color: var(--cs-danger); font-weight: 700; }

/* Tableau */
.cs-scroll { overflow-x: auto; width: 100%; }
.cs-table { border-collapse: collapse; white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.cs-table th, .cs-table td { border: 1px solid var(--ot-border); padding: 4px 6px; text-align: center; }
.cs-table thead th { background: var(--ot-surface-2); position: sticky; top: 0; z-index: 1; }
.cs-table .cs-years th { font-weight: 700; color: var(--ot-text-soft); }
.cs-table .cs-blank { background: transparent; border: 0; }
.cs-letter { display: block; font-size: .7rem; color: var(--cs-accent); font-weight: 800; }
/* Matière : la cellule reste « horizontale » et centrée ; seul le texte pivote (centrage identique dans Firefox et Chrome) */
.cs-subj-cell { background: var(--ot-surface-2); color: var(--cs-accent); text-transform: uppercase; font-size: 11px;
  vertical-align: middle; text-align: center; padding: 6px 3px; width: 28px; min-width: 28px; }
.cs-subj-cell span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg);
  white-space: normal; max-height: 16em; line-height: 1.1; vertical-align: middle; }
.cs-name-cell, .cs-slot-cell { text-align: left !important; }
.cs-room-cell { color: var(--cs-ok); font-weight: 700; }
/* Couleur de la matière : cellule de matière pleine, colonnes colleur / créneau / salle teintées, groupes légèrement teintés */
.cs-colored > td { background: color-mix(in srgb, var(--cs-c) 9%, transparent); }
.cs-colored > td.cs-name-cell, .cs-colored > td.cs-slot-cell, .cs-colored > td.cs-room-cell { background: color-mix(in srgb, var(--cs-c) 24%, transparent); }
.cs-subj-cell { font-weight: 800; }
.cs-first-row td, .cs-first-row th { border-top: 2px solid var(--ot-text-soft); }
.cs-table td.cs-off, .cs-table th.cs-off { background: repeating-linear-gradient(45deg, var(--ot-surface-2), var(--ot-surface-2) 4px, var(--ot-border) 4px, var(--ot-border) 6px); }
.cs-table td.cs-na { background: var(--ot-surface-2); }
.cs-table td.cs-free { color: var(--ot-text-soft); }
.cs-table td.cs-clash { background: color-mix(in srgb, var(--cs-danger) 25%, transparent); color: var(--cs-danger); font-weight: 800; }

/* Fenêtre LaTeX */
.cs-modal { position: fixed; inset: 0; z-index: 90; background: rgba(2,6,23,.6); display: grid; place-items: center; padding: var(--ot-space); }
.cs-modal[hidden] { display: none; }
.cs-modal__box { width: 100%; max-width: 820px; max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.cs-modal__box h2 { margin: 0; font-size: 1.1rem; display: flex; justify-content: space-between; align-items: center; }
.cs-modal textarea { font-family: var(--ot-mono); font-size: .75rem; min-height: 260px; }
.cs-toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 99; padding: 10px 18px;
  background: var(--ot-text); color: var(--ot-bg); border-radius: var(--ot-radius-s); font-size: .9rem; box-shadow: var(--ot-shadow-h); }

.cs-help { margin-top: calc(var(--ot-space) * 2.5); }
.cs-help code { font-family: var(--ot-mono); font-size: .88em; background: var(--ot-surface-2); padding: 1px 5px; border-radius: 4px; }

/* Impression : seul le tableau, en paysage, en couleurs claires */
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff !important; }
  #ot-header, #ot-footer, .ot-skip, .cs-head, .cs-grid, .cs-help, .cs-actions, .cs-messages, .cs-modal, .cs-toast, .cs-print-hide { display: none !important; }
  .cs-result { border: 0 !important; box-shadow: none !important; padding: 0 !important; background: #fff !important; }
  .cs-scroll { overflow: visible; }
  .cs-table { font-size: 8px; color: #000; }
  .cs-table th, .cs-table td { border-color: #888 !important; padding: 2px 3px; }
  .cs-table td { color: #000 !important; }
  .cs-table { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .cs-table thead th, .cs-table td.cs-na { background: #eee !important; }
  .cs-table td.cs-off, .cs-table th.cs-off { background: #ddd !important; }
}
.cs-add-bottom { width: 100%; margin-top: 12px; border-style: dashed; }

/* ---------- Panneaux et colleurs repliables ---------- */
.cs-grid { align-items: start; }
.cs-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; }
.cs-fold > summary::-webkit-details-marker { display: none; }
.cs-fold > summary h2 { margin: 0; }
.cs-fold > summary::after { content: "▾"; margin-left: auto; color: var(--ot-text-soft); transition: transform .15s; }
.cs-fold:not([open]) > summary::after { transform: rotate(-90deg); }
.cs-fold[open] > summary { margin-bottom: 12px; }
.cs-fold-sum { font-size: .85rem; color: var(--ot-text-soft); }
.cs-fold[open] .cs-fold-sum { display: none; }
.cs-fold > summary:hover h2 { color: var(--cs-accent); }
.cs-lines-tools { margin-bottom: 12px; }
.cs-fold-btn { background: none; border: 0; cursor: pointer; color: var(--ot-text-soft); font-size: 1rem; padding: 4px 6px;
  border-radius: 6px; transition: transform .15s; }
.cs-fold-btn:hover { background: var(--ot-surface); color: var(--cs-accent); }
.cs-line.is-folded .cs-fold-btn { transform: rotate(-90deg); }
.cs-line-sum { display: none; margin: 0; font-size: .85rem; color: var(--ot-text-soft); padding-left: 36px; }
.cs-line.is-folded .cs-line-sum { display: block; }
.cs-line.is-folded .cs-days, .cs-line.is-folded .cs-hint, .cs-line.is-folded .cs-ab-pref { display: none !important; }
.cs-line.is-folded { padding: 8px 12px; gap: 4px; }

/* ---------- Titre du tableau ---------- */
.cs-title-field { margin-bottom: 12px; max-width: 520px; }
.cs-caption { caption-side: top; text-align: left; font-size: 1.25rem; font-weight: 800; padding: 0 0 10px; color: var(--ot-text); }
@media print { .cs-caption { font-size: 14pt; color: #000; padding-bottom: 6px; } }
