: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 */
#app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.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 button.on { background: #fff; color: var(--text); }
aside { background: #dde4eb; padding: 10px; border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; max-height: calc(100vh - 44px); position: sticky; top: 44px; }
main { padding: 12px 16px; min-width: 0; }
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 .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; }
.week .cell { min-height: 360px; }
.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; }
.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, #8aa); background: color-mix(in srgb, var(--c, #8aa) 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-top: 8px; font-size: 12px; color: 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.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; }

@media (max-width: 800px) {
    #app { grid-template-columns: 1fr; }
    aside { position: static; max-height: none; border-right: 0; }
    .grid { grid-template-columns: 24px repeat(7, minmax(0, 1fr)); }
    .cell { min-height: 64px; }
    .ev .t { display: none; }
    .cell .hname { display: none; }
}
@media print {
    aside, .topbar, .legend { display: none; }
    #app { display: block; }
}
