:root {
    --blue: #1f5a8b;
    --green: #0a8a4a;
    --gray: #8a97a3;
    --orange: #e36b3f;
    --line: #d5d9de;
    font-family: system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: #f4f4f4; color: #222; font-size: 14px; }
main { padding: 16px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { padding: 5px 12px; border: 1px solid #bbb; border-radius: 4px; background: #fff; cursor: pointer; }
button.danger { color: #b00020; }
.flash { background: #dff3e4; padding: 8px 12px; margin: 0 0 12px; }
.errors { color: #b00020; }

/* Menu bar, like the desktop app */
.menu { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.menu ul { list-style: none; margin: 0; padding: 0; }
.menu > ul { display: flex; flex-wrap: wrap; }
.menu li { position: relative; }
.menu span, .menu a, .menu button, .menu label {
    display: block; width: 100%; padding: 8px 14px; border: 0; border-radius: 0;
    background: none; text-align: left; white-space: nowrap; cursor: pointer;
}
.menu li:hover > span, .menu li:focus-within > span, .menu a:hover, .menu button:hover, .menu label:hover { background: #0a84c6; color: #fff; }
.menu li ul { display: none; position: absolute; top: 100%; left: 0; min-width: 180px; background: #fff; box-shadow: 0 2px 8px #0003; }
.menu li li ul { top: 0; left: 100%; }
.menu li:hover > ul, .menu li:focus-within > ul { display: block; }
.menu .long { max-height: 70vh; overflow-y: auto; }

.bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin: 0 0 16px; padding: 10px 16px; background: var(--blue); color: #fff; font-size: 22px; }
.bar.formateurs { background: var(--green); }
.bar.espaces { background: var(--gray); }

/* Dashboard */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { padding: 18px; border-radius: 6px; color: #fff; text-align: center; font-weight: 600; font-size: 16px; }
.card b { display: block; font-size: 44px; }
.card.formateurs { background: var(--green); }
.card.groupes { background: var(--blue); }
.card.espaces { background: var(--gray); }
.card.seances { background: var(--orange); }
h2 { font-weight: 400; text-align: center; }
.chart { display: flex; gap: 6px; height: 340px; overflow-x: auto; background: #fff; padding: 16px 8px 4px; }
.chart a { flex: 1 0 36px; display: flex; flex-direction: column; justify-content: flex-end; text-align: center; font-size: 12px; }
.chart span { background: #f05a28; color: #fff; min-height: 1px; }

/* Timetable grid: see grid.blade.php */
.scroll { overflow-x: auto; background: #fff; }
.grid {
    display: grid;
    grid-template-columns: 120px repeat(var(--n), minmax(0, 1fr));
    grid-template-rows: repeat(var(--h), auto);
    grid-auto-rows: 64px;
    min-width: 900px;
    font-size: 12px;
}
.matrice .grid { width: calc(120px + var(--n) * var(--slot, 40px)); grid-auto-rows: 56px; }
.head { padding: 2px; border: 1px solid var(--line); background: #eee; text-align: center; white-space: nowrap; overflow: hidden; }
.head.day { font-size: 16px; }
.label { grid-column: 1; display: flex; align-items: center; padding: 0 8px; border: 1px solid var(--line); background: #e8e8e8; font-size: 15px; }
.lane {
    grid-column: 2 / -1;
    border-bottom: 1px solid var(--line);
    cursor: cell;
    /* day, hour and half-hour lines */
    background-image: linear-gradient(to right, #666 1px, transparent 1px), linear-gradient(to right, #bbb 1px, transparent 1px), linear-gradient(to right, #eee 1px, transparent 1px);
    background-size: calc(100% * var(--slots) / var(--n)) 100%, calc(200% / var(--n)) 100%, calc(100% / var(--n)) 100%;
}
.seance {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    margin: 1px; border-radius: 4px; overflow: hidden;
    background: var(--blue); color: #fff; font-weight: 600; line-height: 1.4; text-align: center; cursor: pointer;
}
.formateurs .seance { background: var(--green); }
.espaces .seance { background: var(--gray); }
.seance span { max-width: 100%; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon { width: 1.1em; height: 1.1em; margin-right: .5em; vertical-align: -0.15em; }

/* Timetable page (groupe / formateur / espace), like the desktop app */
.planning { display: flex; gap: 16px; align-items: flex-start; }
.principal { flex: 1; min-width: 0; }
.semaine { padding: 0 6%; background: none; }
.semaine .grid { grid-auto-rows: 68px; font-size: 14px; container-type: inline-size; }
/* "08:30 - 09:30" is ~7em wide: shrink it to fit one hour column (2 of the --n slot columns) */
.semaine .head { margin-bottom: 3px; padding: 2px 0; border: 2px solid #111; border-left-width: 0; background: #fff; font-size: min(17px, (100cqi - 120px) / var(--n) / 3.75); }
.semaine .head:first-child { border-left-width: 2px; }
.semaine .label { border: 3px solid #111; border-top-width: 0; background: #fff; font-size: 24px; }
.semaine .lane {
    border: solid #111;
    border-width: 0 3px 3px 0;
    background-color: #fff;
    /* midday separator, solid hour lines, dashed half-hour lines (white gaps over a solid line) */
    background-image:
        linear-gradient(to right, transparent calc(100% * var(--midi) / var(--n) - 1.5px), #111 0 calc(100% * var(--midi) / var(--n) + 1.5px), transparent 0),
        linear-gradient(to right, #111 1px, transparent 1px),
        repeating-linear-gradient(to bottom, transparent 0 7px, #fff 7px 12px),
        linear-gradient(to right, #111 1px, transparent 1px);
    background-size: 100% 100%, calc(200% / var(--n)) 100%, 100% 100%, calc(100% / var(--n)) 100%;
}
.semaine .head + .label, .semaine .head + .label + .lane { border-top: 3px solid #111; }
.semaine .seance { margin: 0 1px 3px; font-size: 14px; text-transform: uppercase; }

.panneaux { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); gap: 24px; margin-top: 24px; }
.panneaux .bar { margin-bottom: 20px; padding: 8px 16px; font-size: 18px; }
.mini .grid { grid-auto-rows: 46px; min-width: 520px; font-size: 11px; }
.mini .head { margin-bottom: 2px; padding: 1px 0; border-width: 1px; border-left-width: 0; font-size: min(11px, (100cqi - 120px) / var(--n) / 3.75); }
.mini .head:first-child { border-left-width: 1px; }
.mini .label { padding: 0 4px; border-width: 0 2px 2px; font-size: 12px; }
.mini .lane { border-width: 0 2px 2px 0; }
.mini .head + .label, .mini .head + .label + .lane { border-top-width: 2px; }
.mini .seance { margin-bottom: 2px; font-size: 11px; line-height: 1.3; }

.planning aside { position: sticky; top: 52px; flex: none; width: 250px; background: #fff; border: 1px solid var(--line); }
aside summary { padding: 6px 10px; border-bottom: 1px solid var(--line); background: linear-gradient(#fafafa, #e4e4e4); cursor: pointer; }
aside .liste { display: grid; gap: 7px; max-height: calc(50vh - 60px); padding: 10px; overflow-y: auto; }
aside .liste a { padding: 7px 10px; background: var(--gray); color: #fff; font-size: 15px; }
aside .liste a.formateurs { background: var(--green); }
aside .liste a.groupes { background: var(--blue); }
aside .liste a.actif { outline: 3px solid #0a84c6; outline-offset: -3px; }

@media (max-width: 1000px) {
    .planning { flex-direction: column; align-items: stretch; }
    .planning aside { position: static; width: auto; }
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }

.horaires { display: grid; gap: 12px; max-width: 560px; padding: 16px; background: #fff; }
.horaires p { margin: 0; }
.horaires label { display: flex; align-items: center; gap: 8px; }
.horaires button { justify-self: start; }

/* Séance dialog */
dialog { width: min(480px, 100vw - 32px); border: 0; border-radius: 8px; padding: 20px; }
dialog h2 { margin-top: 0; text-align: left; }
dialog label { display: grid; gap: 4px; margin-bottom: 10px; }
dialog .row { display: flex; flex-wrap: wrap; gap: 0 10px; }
menu { display: flex; gap: 8px; margin: 12px 0 0; padding: 0; }
[hidden] { display: none !important; }

/* Paramètres */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 3px; border: 1px solid var(--line); text-align: left; }
td input, td select { width: 100%; min-width: 90px; padding: 4px; border: 1px solid transparent; background: none; }
td input:focus, td select:focus, tr.new input { border-color: #ccc; }
td.actions { width: 1%; white-space: nowrap; }
td.actions form { display: inline; }

/* PDF page (impression.blade.php): checklist on screen, sheets only in print */
button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
.choix fieldset { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0 0 12px; border: 1px solid var(--line); background: #fff; }
.choix legend { font-weight: 600; }
.choix label { white-space: nowrap; cursor: pointer; }
.feuilles { display: none; }

.impression { display: none; }

@media print {
    @page { size: A4 landscape; margin: 10mm; }
    /* No browser header/footer on a timetable sheet. The whole body is the named page:
       naming only .planning makes Firefox add a blank page after it. */
    @page emploi { margin: 0; }
    body:has(.planning, .feuilles) { page: emploi; }
    body { background: #fff; }
    .menu, .toolbar, dialog, .flash, .errors, aside, .panneaux, .planning .bar, .choix { display: none !important; }
    main { padding: 0; }
    .scroll { overflow: visible; }

    /* Timetable sheet (printdemo.jpeg) */
    .planning, .feuille { display: block; padding: 8mm 14mm 0; color: #000; font-family: Calibri, Carlito, "Segoe UI", sans-serif; }
    .feuilles { display: block; }
    /* one sheet per page; unchecked sheets are [hidden] and must not add a break */
    .feuille:not([hidden]) ~ .feuille:not([hidden]) { break-before: page; }
    .impression { display: block; }
    .entete { position: relative; min-height: 20mm; padding-top: 2mm; font-size: 13px; line-height: 1.6; text-align: center; }
    .entete p { margin: 0; }
    .entete img { position: absolute; top: -3mm; left: 0; height: 30mm; } /* the PNG has a wide white margin */
    .impression h1 { margin: 4mm 0 1mm; font-size: 24px; text-align: center; }
    .impression h2 { margin: 0 0 5mm; font-size: 16px; font-weight: 700; text-align: center; }
    .infos { display: flex; justify-content: space-between; margin-bottom: 5mm; padding: 0 12%; font-size: 12px; }
    .infos dl { display: grid; grid-template-columns: auto auto; align-content: start; gap: 0 4px; margin: 0; }
    .infos dd { margin: 0; }
    .infos dd::before { content: ": "; }

    .semaine { padding: 0; }
    .semaine .grid {
        grid-template-columns: 22mm repeat(var(--n), minmax(0, 1fr));
        grid-auto-rows: 15mm;
        min-width: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .semaine .head { margin-bottom: 1.5mm; padding: 1px 2px; border-width: 1.5px; border-left-width: 0; font-size: 11.5px; text-align: center; }
    .semaine .head:first-child { border-left-width: 1.5px; }
    .semaine .label { padding: 0 6px; border-width: 0 1.5px 1.5px; font-size: 14px; }
    .semaine .lane {
        border-width: 0 1.5px 1.5px 0;
        /* solid hour lines, dashed quarter-hour lines */
        background-image:
            linear-gradient(to right, #000 1.5px, transparent 1.5px),
            repeating-linear-gradient(to bottom, transparent 0 8px, #fff 8px 11px),
            linear-gradient(to right, #000 1px, transparent 1px);
        background-size: calc(200% / var(--n)) 100%, 100% 100%, calc(50% / var(--n)) 100%;
    }
    .semaine .head + .label, .semaine .head + .label + .lane { border-top-width: 1.5px; }
    .semaine .seance { margin: 0.8mm 1px; border: 1.5px solid #000; border-radius: 3mm; background: #fff; color: #000; font-size: 14px; text-transform: none; }
}
