:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f4; --surface-3: #e4e7ed;
  --border: #dfe3ea; --text: #151920; --muted: #5d6573; --faint: #8a919d;
  --accent: #4d57d1; --accent-text: #ffffff; --accent-weak: #e7e9fb;
  --ok: #1f8a58; --ok-weak: #e1f3ea; --warn: #b7791f; --warn-weak: #fbf0dc; --danger: #c93c3c; --danger-weak: #fbe5e5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px; --radius-sm: 8px;
  --hour: 52px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1015; --surface: #151920; --surface-2: #1c212a; --surface-3: #252b36;
    --border: #2a303b; --text: #e7e9ee; --muted: #a1a9b6; --faint: #6f7785;
    --accent: #8d95ff; --accent-text: #0d1015; --accent-weak: #262b4d;
    --ok: #4cc58d; --ok-weak: #15302a; --warn: #e5ad4f; --warn-weak: #33291a; --danger: #f07474; --danger-weak: #3a1d20;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1015; --surface: #151920; --surface-2: #1c212a; --surface-3: #252b36;
  --border: #2a303b; --text: #e7e9ee; --muted: #a1a9b6; --faint: #6f7785;
  --accent: #8d95ff; --accent-text: #0d1015; --accent-weak: #262b4d;
  --ok: #4cc58d; --ok-weak: #15302a; --warn: #e5ad4f; --warn-weak: #33291a; --danger: #f07474; --danger-weak: #3a1d20;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side { position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; border-right: 1px solid var(--border); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 520; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-weak); color: var(--accent); }
.nav svg, .tabbar svg { width: 20px; height: 20px; flex: none; }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.side-foot { margin-top: auto; padding: 8px 10px; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.sync[data-etat="ok"] i { background: var(--ok); }
.sync[data-etat="encours"] i { background: var(--accent); animation: pulse 1s infinite; }
.sync[data-etat="erreur"] i { background: var(--danger); }
.sync[data-etat="horsligne"] i { background: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

main { min-width: 0; padding: 22px 28px 40px; }
.top { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.top h1 { flex: 1 1 auto; }
.capture { position: relative; flex: 0 1 460px; display: flex; gap: 6px; }
.capture input { flex: 1; }
.preview { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px; }

.tabbar { display: none; }
.fab { display: none; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 560; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 38px; padding: 0; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 560; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

input[type="text"], input[type="search"], input[type="date"], input[type="time"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
textarea { min-height: 72px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
label.field > span { padding-left: 2px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.f-6 { grid-column: span 6; } .f-4 { grid-column: span 4; } .f-3 { grid-column: span 3; } .f-2 { grid-column: span 2; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 520; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer; user-select: none; }
.chip[aria-pressed="true"] { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--c, var(--faint)); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.pill.warn { background: var(--warn-weak); color: var(--warn); }
.pill.danger { background: var(--danger-weak); color: var(--danger); }
.pill.accent { background: var(--accent-weak); color: var(--accent); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--c, var(--accent)); flex: none; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.alert.warn { background: var(--warn-weak); color: var(--warn); }
.alert.danger { background: var(--danger-weak); color: var(--danger); }
.alert.info { background: var(--accent-weak); color: var(--accent); }
.empty { padding: 22px 10px; text-align: center; color: var(--muted); font-size: 14px; }

/* Listes de tâches */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--border); cursor: pointer; min-width: 0; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); border-radius: var(--radius-sm); }
.item .when { width: 92px; flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.item .what { flex: 1; min-width: 0; }
.item .title { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.done .title { text-decoration: line-through; color: var(--faint); }
.item .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tick { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--c, var(--border)); background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; }
.tick[aria-pressed="true"] { background: var(--c, var(--ok)); }
.tick[aria-pressed="true"]::after { content: ""; width: 9px; height: 5px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.group-title { margin: 14px 0 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 4px; }
.stat { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* ---------- Planning ---------- */
.plan-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.plan-bar h2 { font-size: 18px; min-width: 0; }
.week { --cols: 7; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.week-head, .week-allday, .week-body { display: grid; grid-template-columns: 54px repeat(var(--cols), minmax(0, 1fr)); }
.week-head > div { padding: 8px 8px 6px; border-left: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.week-head > div:first-child, .week-allday > div:first-child { border-left: 0; }
.week-head .num { font-size: 18px; font-weight: 650; color: var(--text); margin-left: 4px; }
.week-head .today .num { background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 0 6px; }
.week-head .ferie { color: var(--danger); font-size: 11px; display: block; }
.week-allday { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.week-allday > div { border-left: 1px solid var(--border); padding: 4px; display: flex; flex-direction: column; gap: 3px; min-height: 30px; min-width: 0; }
.abs-line { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.abs-line.low { color: var(--danger); font-weight: 600; }
.week-body { position: relative; max-height: calc(100dvh - 250px); overflow-y: auto; }
.hours > div { height: var(--hour); font-size: 11px; color: var(--faint); text-align: right; padding: 0 6px; transform: translateY(-7px); }
.hours > div:first-child { transform: none; padding-top: 2px; }
.daycol { position: relative; border-left: 1px solid var(--border); background-image: linear-gradient(var(--border) 1px, transparent 1px); background-size: 100% var(--hour); cursor: copy; }
.daycol.weekend, .daycol.ferie { background-color: var(--surface-2); }
.daycol.today { background-color: color-mix(in srgb, var(--accent-weak) 45%, transparent); }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 4; pointer-events: none; }
.ev { position: absolute; z-index: 2; border-radius: 7px; padding: 3px 6px; overflow: hidden; cursor: pointer; font-size: 12px; line-height: 1.25;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c); color: var(--text); }
.ev:hover { z-index: 3; box-shadow: var(--shadow); }
.ev b { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev small { color: var(--muted); }
.ev.done { opacity: .55; } .ev.done b { text-decoration: line-through; }
.ev.conflict { outline: 2px solid var(--danger); outline-offset: -2px; }
/* Rendez-vous importés de l'agenda iPhone : grisés et hachurés, en lecture seule */
.ev.ext, .ev-allday.ext { --c: var(--faint); background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface) 6px 12px); border-left-style: dashed; }
.item.ext .title { color: var(--muted); }
.tick-ext { width: 22px; flex: none; text-align: center; font-size: 15px; }
.ev-allday { font-size: 12px; padding: 2px 6px; border-radius: 6px; background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daystrip { display: none; }

/* ---------- Équipe ---------- */
.presence { overflow-x: auto; }
.presence table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; }
.presence th, .presence td { padding: 4px; text-align: center; border-bottom: 1px solid var(--border); min-width: 34px; }
.presence th:first-child, .presence td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); min-width: 130px; z-index: 1; }
.presence th { color: var(--muted); font-weight: 600; }
.presence .we { background: var(--surface-2); }
.cell-abs { display: block; height: 22px; border-radius: 5px; background: var(--c); opacity: .85; cursor: pointer; }
.cell-abs.half-matin { background: linear-gradient(to right, var(--c) 50%, transparent 50%); border: 1px solid var(--c); }
.cell-abs.half-apresmidi { background: linear-gradient(to left, var(--c) 50%, transparent 50%); border: 1px solid var(--c); }
.cell-abs.demande { opacity: .45; background-image: repeating-linear-gradient(45deg, transparent 0 4px, rgba(255,255,255,.5) 4px 8px); }
.tot.low { color: var(--danger); font-weight: 700; }

/* ---------- Dialogues ---------- */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); width: min(620px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); }
dialog::backdrop { background: rgba(10, 12, 18, .45); backdrop-filter: blur(2px); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 16px 18px 10px; }
.dlg-head h2 { flex: 1; font-size: 18px; }
.dlg-body { padding: 4px 18px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: var(--accent-weak); font-weight: 700; cursor: pointer; }

pre.code { background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
ol.steps { padding-left: 20px; margin: 6px 0; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Tablette / mobile ---------- */
@media (max-width: 1100px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  main { padding: calc(14px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
  .top { margin-bottom: 14px; }
  .top .capture { display: none; }
  h1 { font-size: 22px; }
  .cols-3, .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; min-height: 44px; justify-content: center; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar .badge { position: absolute; top: 0; left: 55%; margin: 0; min-width: 18px; height: 18px; font-size: 11px; }
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 41; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 24px rgba(0,0,0,.25); cursor: pointer; }
  .fab svg { width: 26px; height: 26px; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f-6, .f-4 { grid-column: span 2; } .f-3, .f-2 { grid-column: span 1; }
  .week { --cols: 1 !important; }
  .week-head, .week-allday { display: none; }
  .daystrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
  .daystrip button { border: 0; background: var(--surface); border-radius: 10px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; cursor: pointer; font-size: 11px; color: var(--muted); position: relative; }
  .daystrip button b { font-size: 17px; color: var(--text); }
  .daystrip button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
  .daystrip button[aria-pressed="true"] b { color: var(--accent-text); }
  .daystrip button.has::after { content: ""; position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
  .mobile-day { display: block !important; margin-bottom: 8px; }
  .week-body { max-height: none; }
  .item .when { width: 74px; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh; }
  .dlg { max-height: 92dvh; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
.mobile-day { display: none; }
@media (min-width: 861px) { .only-mobile { display: none !important; } }
@media (max-width: 860px) { .only-desktop { display: none !important; } }
