:root {
    --bg: #eef2f6; --panel: #fff; --line: #cfd8e1; --text: #1d2733; --muted: #6a7a8a;
    --head: #3b4350; --accent: #2b6cb0; --today: #fff4c2; --off: #f1f3f5; --holiday: #ffd9a8; --danger: #c53030;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 system-ui, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 4px; padding: 5px 10px; }
button:hover { background: #f3f6f9; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #245a94; }
button.danger { color: var(--danger); }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* connexion */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box { background: var(--panel); padding: 28px 32px; border-radius: 8px; width: min(340px, 92vw); display: grid; gap: 12px; box-shadow: 0 2px 12px #0002; }
.login-box h1 { margin: 0; }
.login-box p { margin: 0; }
label { display: grid; gap: 3px; font-weight: 600; font-size: 13px; }
input:not([type=checkbox]), select, textarea { padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; width: 100%; font-weight: 400; }

/* mise en page */
/* l'appli occupe exactement l'écran : seules la colonne de gauche et la zone principale défilent */
#app { display: grid; grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / -1; background: var(--head); color: #fff; display: flex; align-items: center; gap: 12px; padding: 6px 12px; flex-wrap: wrap; }
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar button { background: #4a5361; color: #fff; border-color: #5b6573; }
.topbar button:hover { background: #596373; }
.topbar .seg { display: inline-flex; }
.topbar .seg button { border-radius: 0; margin-left: -1px; }
.topbar .seg button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.topbar .seg button:last-child { border-radius: 0 4px 4px 0; }
.topbar .seg button.on { background: #fff; color: var(--text); }
.topbar .menu, .fab, .scrim, .side-tools { display: none; }
aside { background: #dde4eb; padding: 10px; border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; }
main { padding: 12px 16px; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
main > * { flex: none; }
main h2 { margin: 0 0 10px; font-size: 20px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
main h2 small { font-size: 13px; font-weight: 400; color: var(--muted); }

.mini { margin-bottom: 14px; }
.mhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: 13px; }
.mhead button { padding: 0 6px; line-height: 1.4; }
.mgrid { display: grid; grid-template-columns: 24px repeat(7, 1fr); gap: 1px; text-align: center; font-size: 12px; }
.mgrid .mh { font-weight: 700; color: var(--muted); padding: 2px 0; }
.mgrid button { border: 0; background: none; padding: 3px 0; border-radius: 3px; min-width: 0; }
.mgrid button:hover { background: #fff9; }
.mgrid .md.other { color: #8d99a6; }
.mgrid .md.cur, .mgrid .mw.cur { background: #fff; }
.mgrid .md.today { background: var(--today); font-weight: 700; outline: 1px solid #d9b800; }
.mgrid .md.sel, .mgrid .md.sel:hover { background: var(--accent); color: #fff; font-weight: 700; } /* jour sélectionné */
.mgrid .mw { color: var(--muted); font-size: 10px; border-right: 1px solid var(--line); border-radius: 0; }
.mgrid .mw:hover { background: var(--accent); color: #fff; }
.userlist h3 { margin: 6px 0; font-size: 13px; }
.userlist input { margin-bottom: 6px; }
.userlist ul { list-style: none; margin: 0; padding: 0; }
.userlist li { padding: 3px 6px; border-radius: 3px; cursor: pointer; }
.userlist li:hover { background: #fff8; }
.userlist li.on { background: var(--accent); color: #fff; }
.userlist li.me::after { content: " (moi)"; opacity: .7; }
.userlist li.off { opacity: .5; }

/* vue mensuelle / hebdomadaire */
.grid { display: grid; grid-template-columns: 34px repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px; border: 1px solid var(--line); }
.grid > div { background: var(--panel); }
.grid .hd { background: #c9d4df; text-align: center; font-weight: 700; padding: 4px; }
.grid .wk { background: #c9d4df; text-align: center; font-weight: 700; padding: 4px 0; color: #3b4350; }
.cell { min-height: 96px; padding: 2px 3px 4px; }
.cell.other { background: var(--off) !important; }
.cell.we { background: #fafbfc; }
.cell.today { background: var(--today); }
.cell.holiday .num { background: var(--holiday); }
.cell .top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.cell .num { padding: 0 4px; border-radius: 3px; border: 0; background: none; font-weight: 700; }
.cell .num:hover { background: var(--accent); color: #fff; }
.cell .hname { font-size: 11px; font-weight: 400; color: #8a5a1c; margin-left: 4px; }
.cell .add { opacity: 0; border: 0; background: none; color: var(--accent); font-size: 16px; line-height: 1; padding: 0 4px; }
.cell:hover .add, .cell .add:focus { opacity: 1; }
.ev { display: flex; align-items: baseline; gap: 4px; padding: 1px 4px; margin-top: 2px; border-radius: 3px; border-left: 4px solid var(--c, #5b8fd0); background: color-mix(in srgb, var(--c, #5b8fd0) 22%, #fff); cursor: pointer; font-size: 12px; overflow: hidden; }
.ev:hover { filter: brightness(.95); }
.ev .t { white-space: nowrap; font-variant-numeric: tabular-nums; color: #333; }
.ev .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.masked { --c: #999; font-style: italic; cursor: default; }
.ev .ico { font-size: 10px; }
.legend { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* grille horaire jour / semaine (inspirée d'Outlook) ; --hh = hauteur d'une heure */
.tg { --hh: 48px; --gut: 52px; flex: 1 1 auto; min-height: 260px; overflow: auto; position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; overscroll-behavior: contain; }
.tg-head, .tg-body { display: grid; grid-template-columns: var(--gut) repeat(var(--cols), minmax(0, 1fr)); }
.tg-head { position: sticky; top: 0; z-index: 4; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 2px 4px #0000000d; }
.tg-corner { font-size: 11px; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.tg-day { border: 0; border-left: 1px solid var(--line); border-radius: 0; background: none; padding: 6px 4px; display: flex; gap: 6px; align-items: center; justify-content: center; min-width: 0; }
.tg-day:hover { background: #f3f6f9; }
.tg-day .dn { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.tg-day .dd { font-size: 20px; font-weight: 300; min-width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 50%; }
.tg-day.today .dd { background: var(--accent); color: #fff; font-weight: 600; }
.tg-day.today .dn { color: var(--accent); font-weight: 700; }
.tg-adl { grid-column: 1; font-size: 11px; line-height: 1.2; color: var(--muted); padding: 4px 4px; text-align: right; border-top: 1px solid var(--line); }
.tg-ad { border-left: 1px solid var(--line); border-top: 1px solid var(--line); padding: 1px 2px 3px; min-height: 28px; max-height: 92px; overflow-y: auto; cursor: cell; min-width: 0; }
.tg-ad .hol { font-size: 11px; color: #8a5a1c; background: var(--holiday); border-radius: 3px; padding: 1px 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-hours { position: relative; height: calc(24 * var(--hh)); }
.tg-hours span { position: absolute; right: 6px; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tg-col { position: relative; height: calc(24 * var(--hh)); border-left: 1px solid var(--line); cursor: cell; min-width: 0;
    background: linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% var(--hh),
                linear-gradient(#edf1f5 1px, transparent 1px) 0 calc(var(--hh) / 2) / 100% var(--hh); }
.tg-col.we, .tg-ad.we { background-color: #f7f9fb; }
.tg-col.today, .tg-ad.today { background-color: #f3f8ff; }
.tev { position: absolute; z-index: 1; overflow: hidden; display: flex; flex-direction: column; padding: 2px 5px; border-radius: 4px; cursor: pointer;
    font-size: 12px; line-height: 1.3; color: color-mix(in srgb, var(--c, #5b8fd0) 50%, #000);
    background: color-mix(in srgb, var(--c, #5b8fd0) 16%, #fff);
    border: 1px solid color-mix(in srgb, var(--c, #5b8fd0) 45%, #fff); border-left: 4px solid var(--c, #5b8fd0); }
.tev:hover { z-index: 2; box-shadow: 0 2px 8px #0003; }
.tev > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.tev .tt { font-weight: 600; white-space: normal; flex: 0 1 auto; }
.tev .tm, .tev .tl { font-size: 11px; opacity: .9; }
.tev.short { flex-direction: row; gap: 6px; align-items: baseline; padding-top: 0; padding-bottom: 0; }
.tev.short .tt { white-space: nowrap; }
.tev.short .tm { display: none; }
.tev.masked { --c: #999; font-style: italic; cursor: default; border-style: dashed; border-left-style: solid; background: #f6f6f6; }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 3; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* bandeau des jours de la semaine (petit écran) */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; margin-bottom: 6px; }
.strip .sd { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 4px 0 8px; position: relative; border-radius: 0; }
.strip .sl { font-size: 12px; color: var(--muted); font-weight: 600; }
.strip .sn { font-size: 17px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; }
.strip .we .sn { color: var(--muted); }
.strip .today .sn { color: var(--accent); font-weight: 700; }
.strip .holiday .sn { background: var(--holiday); }
.strip .on .sn { background: var(--accent); color: #fff; font-weight: 600; }
.strip .has::after { content: ""; position: absolute; bottom: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }

/* fenêtre modale */
dialog { border: 0; border-radius: 8px; padding: 0; width: min(560px, 96vw); box-shadow: 0 8px 40px #0005; }
dialog::backdrop { background: #0006; }
dialog form { display: grid; gap: 10px; padding: 18px 20px; max-height: 92vh; overflow: auto; }
dialog h3 { margin: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; align-items: end; }
.check { display: flex; gap: 6px; align-items: center; font-weight: 400; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches label { width: 24px; height: 24px; border-radius: 50%; background: var(--c); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; position: relative; }
.swatches input { position: absolute; opacity: 0; }
.swatches label:has(input:checked) { box-shadow: 0 0 0 2px var(--text); }
.people { max-height: 130px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 10px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.actions .left { margin-right: auto; }
.readonly dl { margin: 0; display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; }
.readonly dt { color: var(--muted); }
.readonly dd { margin: 0; white-space: pre-wrap; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
table.users td, table.users th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 8px 16px; border-radius: 6px; z-index: 10; }
.toast.ok { background: #2f855a; }

/* tablette : colonne de gauche plus étroite */
@media (max-width: 1000px) {
    #app { grid-template-columns: 190px minmax(0, 1fr); }
    .topbar { gap: 8px; }
}

/* téléphone (même seuil que matchMedia dans app.js) : tiroir, bandeau des jours, bouton flottant */
@media (max-width: 720px) {
    #app { grid-template-columns: minmax(0, 1fr); }
    .topbar { gap: 6px; padding: 6px 8px; flex-wrap: nowrap; }
    .topbar .brand { display: none; }
    .topbar button { padding: 6px 9px; min-height: 36px; }
    .topbar .menu { display: inline-block; font-size: 18px; line-height: 1; }
    .topbar .seg { margin-left: auto; }
    aside { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 20px #0003; padding: 14px; }
    #app.drawer aside { transform: none; }
    #app.drawer .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: #0005; }
    .mgrid { font-size: 14px; }
    .mgrid button { padding: 6px 0; }
    .userlist li { padding: 8px 6px; }
    .side-tools { display: grid; gap: 6px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
    .side-tools button { padding: 8px; text-align: left; }
    main { padding: 6px 6px 0; }
    main h2 { font-size: 16px; gap: 6px; margin-bottom: 6px; }
    main h2 small { font-size: 12px; }
    main h2 .other-agenda, .legend { display: none; }
    .tg { --hh: 56px; --gut: 50px; border-radius: 4px 4px 0 0; }
    .tg-adl { text-align: left; padding: 4px 3px; }
    .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 10;
        width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 4px 14px #0004; }
    .fab:hover { background: #245a94; }
    .grid { grid-template-columns: 22px repeat(7, minmax(0, 1fr)); }
    .grid .wk { font-size: 10px; padding: 4px 0; }
    .cell { min-height: 72px; padding: 1px; }
    .cell .add, .cell .hname { display: none; }
    .ev { font-size: 10px; padding: 0 2px; border-left-width: 3px; }
    .ev .t, .ev .ico { display: none; }
    dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0; margin: auto 0 0; }
    dialog form { max-height: 100dvh; padding: 14px; }
    input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; } /* évite le zoom auto d'iOS */
}
@media print {
    aside, .topbar, .legend, .fab, .strip { display: none; }
    #app, main { display: block; height: auto; overflow: visible; }
    .tg { overflow: visible; }
    .tg-head { position: static; }
}
