:root {
  --paper: #E9EDF2;
  --surface: #FFFFFF;
  --sunk: #F3F5F8;
  --ink: #17202C;
  --ink-2: #536173;
  --ink-3: #8592A3;
  --line: #D2D9E2;
  --accent: #3346C8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3E7FB;
  --danger: #B93A3A;
  --warn: #A86A12;
  --ok: #1D7A55;
  --shadow: 0 1px 0 rgba(23, 32, 44, .06), 0 8px 24px -12px rgba(23, 32, 44, .25);
  --radius: 10px;
  --font: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1319; --surface: #171D26; --sunk: #12171F; --ink: #E4E9F0; --ink-2: #9AA7B8; --ink-3: #6B7787;
    --line: #2A323E; --accent: #8E9CFF; --accent-ink: #0F1319; --accent-soft: #232A4A;
    --danger: #F07C7C; --warn: #E4A94C; --ok: #5CC99A; --shadow: 0 1px 0 rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0F1319; --surface: #171D26; --sunk: #12171F; --ink: #E4E9F0; --ink-2: #9AA7B8; --ink-3: #6B7787;
  --line: #2A323E; --accent: #8E9CFF; --accent-ink: #0F1319; --accent-soft: #232A4A;
  --danger: #F07C7C; --warn: #E4A94C; --ok: #5CC99A; --shadow: 0 1px 0 rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--font);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer;
  font-weight: 500; font-size: 14px; white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--sunk); color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: 7px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
.icon-btn svg, .btn svg { width: 16px; height: 16px; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=date],
input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { width: 34px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; flex: none; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
label.field > span { padding-left: 1px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stack { display: grid; gap: 12px; }
.spacer { flex: 1; }
.check {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--ink-3); background: transparent;
  cursor: pointer; flex: none; display: grid; place-items: center; padding: 0;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg button.on { background: var(--accent-soft); color: var(--ink); }

/* ---------- connexion ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth form { width: min(380px, 100%); display: grid; gap: 14px; }
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.wordmark i { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); display: inline-block; box-shadow: 0 0 0 4px var(--accent-soft); }
.auth h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.025em; margin: 18px 0 2px; font-weight: 700; }
.auth p { margin: 0 0 6px; color: var(--ink-2); }
.err { color: var(--danger); font-size: 14px; min-height: 1.2em; }

/* ---------- structure ---------- */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line);
}
.side .wordmark { font-size: 19px; padding: 2px 10px 18px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2);
  text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface); color: var(--ink); }
.nav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.nav a .count { margin-left: auto; font-size: 12px; background: var(--accent-soft); color: var(--ink); padding: 0 7px; border-radius: 99px; }
.side .foot { margin-top: auto; display: grid; gap: 6px; padding: 0 4px; }
.kbd { font-size: 12px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--ink-2); background: var(--surface); }
.main-wrap { min-width: 0; display: flex; flex-direction: column; }
main { padding: 26px clamp(16px, 3vw, 40px) 80px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 30px; letter-spacing: -.025em; line-height: 1.1; font-weight: 700; }
.page-head .sub { color: var(--ink-2); font-size: 15px; padding-bottom: 3px; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 650; letter-spacing: -.005em; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.section + .section { margin-top: 28px; }
.empty { color: var(--ink-3); padding: 14px 0; }

/* ---------- bandeau « en cours » ---------- */
.live {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px clamp(16px, 3vw, 40px); background: var(--accent); color: var(--accent-ink);
}
.live .what { min-width: 0; display: grid; }
.live .what b { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live .what span { font-size: 12px; opacity: .8; }
.live .clock { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1; margin-left: auto; }
.live .pulse { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; animation: pulse 2s ease-in-out infinite; }
.live.paused { background: var(--ink-2); }
.live.paused .pulse { animation: none; opacity: .5; }
.live .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, currentColor 40%, transparent); }
.live .btn:hover { border-color: currentColor; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live .pulse { animation: none; } }

/* ---------- Aujourd'hui ---------- */
.today { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.timeline { position: relative; display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 58px 1fr; gap: 14px; padding: 9px 0; border-top: 1px solid var(--line); align-items: start; }
.tl-item:first-child { border-top: 0; }
.tl-time { font-size: 13px; color: var(--ink-2); padding-top: 2px; font-weight: 500; }
.tl-body { border-left: 3px solid var(--c, var(--ink-3)); padding-left: 10px; min-width: 0; }
.tl-body b { font-weight: 600; display: block; }
.tl-body.block { border-left-style: dashed; }
.tl-body.done { opacity: .75; }
.tl-now { display: grid; grid-template-columns: 58px 1fr; gap: 14px; align-items: center; color: var(--danger); font-size: 12px; font-weight: 600; }
.tl-now hr { border: 0; border-top: 2px solid var(--danger); margin: 0; }
.allday { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.allday span { font-size: 13px; padding: 2px 9px; border-radius: 99px; background: var(--sunk); border-left: 3px solid var(--c); }

/* ---------- tâches ---------- */
.quick { display: flex; gap: 8px; margin-bottom: 18px; }
.quick input { font-size: 16px; padding: 11px 14px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.filters button { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.filters button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.group-title { font-size: 13px; font-weight: 650; color: var(--ink-2); margin: 18px 0 4px; display: flex; gap: 8px; }
.group-title.late { color: var(--danger); }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.task .check { margin-top: 2px; }
.task .t { flex: 1; min-width: 0; }
.task .t .title { font-weight: 500; cursor: pointer; overflow-wrap: anywhere; }
.task.done .title { text-decoration: line-through; color: var(--ink-3); }
.task .meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.task .meta .late { color: var(--danger); }
.task .acts { display: flex; gap: 2px; opacity: .55; }
.task:hover .acts, .task:focus-within .acts { opacity: 1; }
.prio { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; }
.prio i { width: 3px; background: var(--line); border-radius: 1px; }
.prio i:nth-child(1) { height: 5px; } .prio i:nth-child(2) { height: 8px; } .prio i:nth-child(3) { height: 11px; }
.prio[data-p="1"] i:nth-child(-n+1), .prio[data-p="2"] i:nth-child(-n+2) { background: var(--ink-2); }
.prio[data-p="3"] i { background: var(--danger); }

/* ---------- calendrier ---------- */
.cal-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.cal-bar .range { font-weight: 650; font-size: 17px; margin: 0 6px; min-width: 190px; }
.week { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.week-head, .week-allday { display: grid; grid-template-columns: 54px repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.week-head div { padding: 8px 8px 6px; font-size: 13px; color: var(--ink-2); border-left: 1px solid var(--line); }
.week-head div:first-child, .week-allday div:first-child { border-left: 0; }
.week-head b { display: block; font-size: 20px; color: var(--ink); font-weight: 650; line-height: 1.1; }
.week-head .is-today b { color: var(--accent); }
.week-allday div { border-left: 1px solid var(--line); padding: 3px; min-height: 26px; display: grid; gap: 2px; align-content: start; }
.week-allday .ev { position: static; }
.week-scroll { height: min(68vh, 760px); overflow-y: auto; position: relative; }
.week-grid { display: grid; grid-template-columns: 54px repeat(7, minmax(0, 1fr)); position: relative; }
.hours div { height: 48px; font-size: 11px; color: var(--ink-3); text-align: right; padding-right: 8px; transform: translateY(-7px); }
.daycol {
  position: relative; border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0 47px, var(--line) 47px 48px);
}
.daycol.is-today { background-color: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.daycol .nowline { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 3; pointer-events: none; }
.daycol .nowline::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.ev {
  position: absolute; border-radius: 6px; padding: 3px 6px; font-size: 12px; line-height: 1.25; overflow: hidden;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c); cursor: pointer; text-align: left;
  border-top: 0; border-right: 0; border-bottom: 0; color: var(--ink);
}
.ev:hover { z-index: 4; box-shadow: var(--shadow); }
.ev b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev span { color: var(--ink-2); }
.ev.block { background: transparent; border: 1.5px dashed var(--c); border-left-width: 3px; border-left-style: solid; }
.ev.session { background: var(--c); color: #fff; border-left-color: rgba(0,0,0,.25); }
.ev.session span { color: rgba(255,255,255,.85); }
.ev.session.live { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.15) 0 6px, transparent 6px 12px); }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.month .dow { padding: 8px; font-size: 12px; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.month .cell { min-height: 108px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); padding: 4px; display: grid; gap: 2px; align-content: start; cursor: pointer; }
.month .cell:nth-child(7n+1) { border-left: 0; }
.month .cell.out { background: var(--sunk); color: var(--ink-3); }
.month .cell .n { font-size: 13px; font-weight: 600; padding: 1px 4px; }
.month .cell.is-today .n { color: var(--accent-ink); background: var(--accent); border-radius: 6px; justify-self: start; }
.month .mi { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; border-left: 2px solid var(--c); border-radius: 2px; }
.cal-list { display: grid; gap: 2px; }
.cal-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cal-row .name { flex: 1; min-width: 0; }
.cal-row .name b { font-weight: 550; }
.cal-row .name div { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- étude ---------- */
.study-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: start; margin-bottom: 28px; }
.big-clock { font-size: clamp(48px, 7vw, 76px); font-weight: 750; letter-spacing: -.04em; line-height: 1; margin: 6px 0 10px; }
.bars svg { width: 100%; height: auto; display: block; overflow: visible; }
.bars text { fill: var(--ink-2); font-size: 11px; font-family: var(--font); }
.goal { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.goal .bar { grid-column: 1 / -1; height: 8px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.goal .bar i { display: block; height: 100%; background: var(--c); border-radius: 99px; }
.goal .bar.over i { background: repeating-linear-gradient(90deg, var(--c) 0 8px, color-mix(in srgb, var(--c) 70%, #fff) 8px 10px); }
.goal input { width: 74px; padding: 4px 8px; text-align: right; }
.sess { display: grid; grid-template-columns: 110px 1fr auto auto; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: center; }

/* ---------- habitudes ---------- */
.habit { display: grid; grid-template-columns: minmax(140px, 1fr) auto; gap: 8px 16px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.habit .days { display: grid; grid-template-columns: repeat(14, 26px); gap: 4px; }
.habit .day { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 10px; color: var(--ink-3); padding: 0; }
.habit .day.on { background: var(--c); border-color: var(--c); color: #fff; }
.habit .day.is-today { outline: 2px solid var(--ink-3); outline-offset: 1px; }
.habit .day.future { visibility: hidden; }
.dayhead { display: grid; grid-template-columns: repeat(14, 26px); gap: 4px; font-size: 10px; color: var(--ink-3); text-align: center; }

/* ---------- inbox ---------- */
.note { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.note .txt { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- revue ---------- */
.review-step { display: grid; grid-template-columns: 36px 1fr; gap: 14px; padding: 20px 0; border-top: 1px solid var(--line); }
.review-step .num { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--ink-3); display: grid; place-items: center; font-weight: 650; font-size: 14px; color: var(--ink-2); }
.review-step h2 { margin-top: 4px; }
.slip { display: flex; gap: 8px; align-items: center; padding: 6px 0; flex-wrap: wrap; }
.slip .name { flex: 1; min-width: 160px; }

/* ---------- modales, palette, toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 50; display: grid; place-items: start center; padding: 9vh 16px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); width: min(560px, 100%); padding: 22px; display: grid; gap: 14px; }
.modal.wide { width: min(760px, 100%); }
.modal h2 { font-size: 19px; margin: 0; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.palette { width: min(620px, 100%); background: var(--surface); border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); overflow: hidden; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 16px 18px; font-size: 17px; box-shadow: none !important; }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 52vh; overflow-y: auto; }
.palette li { padding: 9px 12px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.palette li .k { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.palette li.on { background: var(--accent-soft); }
.palette li svg { width: 16px; height: 16px; color: var(--ink-2); flex: none; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--danger); color: #fff; }
.plan-day { margin-top: 10px; }
.plan-day h3 { font-size: 13px; color: var(--ink-2); margin: 8px 0 4px; font-weight: 650; }
.plan-item { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.plan-item .time { width: 104px; font-size: 13px; color: var(--ink-2); flex: none; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .today, .study-top { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 30; flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
    background: var(--paper); overflow-x: auto;
  }
  .side .wordmark, .side .foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 10px; }
  .nav a .count { position: absolute; margin: -4px 0 0 14px; font-size: 10px; padding: 0 5px; }
  main { padding-bottom: 110px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .live .clock { font-size: 22px; }
  .live .hide-sm { display: none; }
  .week-scroll { height: 62vh; }
  .week-head div { padding: 6px 3px; font-size: 11px; }
  .week-head b { font-size: 16px; }
  .ev { padding: 2px 3px; font-size: 10.5px; }
  .habit { grid-template-columns: 1fr; }
  .habit .days, .dayhead { grid-template-columns: repeat(7, 26px); }
  .habit .day.old, .dayhead .old { display: none; }
  .sess { grid-template-columns: 1fr auto auto; }
  .sess .when { grid-column: 1 / -1; }
}
