:root {
  --bg: #f6f8fb; --panel: #ffffff; --line: #e3e8ef; --text: #1b2430; --muted: #66758a; --hover: #f0f4fa;
  --accent: #1f6feb; --accent-soft: #e7f0ff; --selected: #e9f1ff;
  --urgent: #d93025; --urgent-soft: #fde8e6; --high: #e8710a; --high-soft: #fff0e0;
  --normal: #1f6feb; --low: #9aa6b6;
  --ok: #1a7f37; --ok-soft: #e3f5e8; --wait: #9a6700; --wait-soft: #fff4d6; --bad: #c62828; --bad-soft: #fdeaea;
  --ai: #6d4aff; --ai-soft: #f3f0ff; --ai-line: #ddd5ff;
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --panel: #161c25; --line: #263040; --text: #e6ebf2; --muted: #8b98ab; --hover: #1c2431;
    --accent: #4c8dff; --accent-soft: #1a2a44; --selected: #1b2a42;
    --urgent: #ff6b5e; --urgent-soft: #3a1d1b; --high: #ffa24c; --high-soft: #3a2a16;
    --normal: #4c8dff; --low: #5d6a7c;
    --ok: #4ac26b; --ok-soft: #16301f; --wait: #e3b341; --wait-soft: #332a12; --bad: #ff7b72; --bad-soft: #3a1b1b;
    --ai: #a48bff; --ai-soft: #1f1a36; --ai-line: #3a3160;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); font-weight: 500; padding: 6px 10px; }
button.ghost:hover { background: var(--hover); color: var(--text); }

/* top bar */
.top { height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 19px; letter-spacing: -.01em; width: 216px; }
.brand b, .login h1 b { color: var(--accent); }
.logo { width: 26px; height: 26px; color: var(--accent); }
.account { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--low); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.logout { margin: 0; }
.bell { display: inline-flex; align-items: center; padding: 6px 8px; }
.bell svg { width: 18px; height: 18px; }
.bell.on { color: var(--accent); }
.bell[hidden], .push-buttons [hidden] { display: none; }
.push-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13.5px; }
.push-panel[hidden] { display: none; }
.push-state { margin: 0; flex: 1 1 280px; }
.push-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(320px, 420px) 1fr; height: calc(100vh - 56px); }
.side { padding: 12px 8px; overflow-y: auto; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item span { flex: 1; }
.nav-item em { font-style: normal; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item.v-urgent svg { color: var(--urgent); }
.nav-item.v-suspect svg { color: var(--bad); }
.nav-item.v-todo svg { color: var(--ok); }
.nav-label { display: flex; align-items: center; gap: 6px; margin: 18px 10px 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ai); }
.nav-label svg { width: 14px; height: 14px; }
.nav-label.plain { color: var(--muted); }
.nav-foot { margin-top: auto; padding: 12px 10px 4px; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.nav-foot b.on { color: var(--ok); }

/* list */
.list { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); }
.list-head { position: sticky; top: 0; background: var(--panel); padding: 14px 16px 10px; border-bottom: 1px solid var(--line); z-index: 1; }
.list-head h1 { margin: 0; font-size: 17px; }
.items { list-style: none; margin: 0; padding: 0; }
.item { border-bottom: 1px solid var(--line); }
.item a { position: relative; display: grid; gap: 2px; padding: 10px 14px 10px 24px; }
.item a:hover { background: var(--hover); }
.item.selected a { background: var(--selected); }
.item.new a { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--ai-soft); } }
.prio { position: absolute; left: 10px; top: 16px; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.prio.p-urgent { background: var(--urgent); } .prio.p-haute { background: var(--high); }
.prio.p-normale { background: var(--normal); opacity: .5; } .prio.p-suspect { background: var(--bad); }
.row1 { display: flex; gap: 8px; align-items: baseline; }
.from { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .from, .unread .subject { font-weight: 700; }
.unread .time { color: var(--accent); font-weight: 600; }
.summary { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 13px; }
.summary svg { width: 12px; height: 12px; color: var(--ai); vertical-align: -1px; margin-right: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; align-items: center; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--hover); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip svg { width: 12px; height: 12px; }
.chip.p-urgent { background: var(--urgent-soft); color: var(--urgent); border-color: transparent; font-weight: 600; }
.chip.p-haute { background: var(--high-soft); color: var(--high); border-color: transparent; font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.wait { background: var(--wait-soft); color: var(--wait); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; font-weight: 600; }
.chip.draft { background: var(--ai-soft); color: var(--ai); border-color: transparent; }
.clip { width: 14px; height: 14px; color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.more { display: block; text-align: center; padding: 14px; color: var(--accent); }

/* reading pane */
.pane { overflow-y: auto; }
.mail { max-width: 860px; margin: 0 auto; padding: 22px 28px 48px; }
.back { display: none; color: var(--accent); margin-bottom: 8px; }
.mail-subject { margin: 0 0 14px; font-size: 21px; line-height: 1.3; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.toolbar form { margin: 0; display: flex; align-items: center; gap: 6px; }
.tool { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); color: var(--text); border: 1px solid var(--line); font-weight: 500; padding: 6px 11px; }
.tool:hover { background: var(--hover); border-color: var(--muted); }
.tool:disabled { opacity: .5; cursor: progress; }
.tool svg { width: 16px; height: 16px; color: var(--muted); }
.toolbar .move { margin-left: auto; }
.toolbar .move > svg { color: var(--muted); }
.toolbar select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); max-width: 180px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; display: flex; align-items: center; gap: 14px;
  background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100vw - 32px); }
.toast[hidden] { display: none; }
.toast button { background: transparent; color: var(--accent-soft); padding: 2px 6px; text-decoration: underline; }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--bad-soft); color: var(--bad); margin-bottom: 14px; }
.alert svg { margin-top: 1px; }
.ai { border: 1px solid var(--ai-line); background: var(--ai-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; }
.ai-suspect { border-color: var(--bad-soft); }
.ai-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--ai); font-weight: 700; font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; }
.ai-head span:first-of-type { margin-right: 6px; }
.ai-head .chip { text-transform: none; letter-spacing: 0; }
.ai-summary { margin: 10px 0 0; font-size: 15px; }
.ai h3 { margin: 14px 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.actions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.actions li { display: flex; align-items: flex-start; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--low); }
.dot.ok { background: var(--ok); } .dot.wait { background: var(--wait); } .dot.bad { background: var(--bad); }
.a-text { flex: 1; }
.due { color: var(--urgent); font-weight: 600; white-space: nowrap; }
.warn { color: var(--wait); font-size: 12px; }
.a-status { font-size: 12px; white-space: nowrap; color: var(--muted); }
.a-status.ok { color: var(--ok); } .a-status.wait { color: var(--wait); } .a-status.bad { color: var(--bad); }
.ai-reason { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }
.meta { display: flex; align-items: center; gap: 12px; padding: 4px 0 14px; border-bottom: 1px solid var(--line); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.who { flex: 1; min-width: 0; }
.date { white-space: nowrap; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; }
.att { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; background: var(--panel); }
.att svg { width: 14px; height: 14px; color: var(--muted); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; padding-top: 16px; font-size: 14.5px; line-height: 1.6; }
.thread { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
.thread h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.thread ul { list-style: none; margin: 0; padding: 0; }
.thread a { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 8px; border-radius: 8px; }
.thread a:hover { background: var(--hover); }
.thread .summary { grid-column: 1 / -1; }
.thread .current a { background: var(--selected); }
.placeholder { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); gap: 6px; }
.placeholder svg { width: 54px; height: 54px; color: var(--line); }

/* replies */
.compose { position: relative; margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 14px 16px; display: grid; gap: 10px; }
.compose-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.compose-head h3 { white-space: nowrap; }
.compose-head h3 { margin: 0; font-size: 15px; }
.compose-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.compose-row form { margin: 0; }
.compose button svg { width: 16px; height: 16px; vertical-align: -3px; }
.compose label { display: inline-flex; align-items: center; gap: 6px; }
.rcpt { display: grid; gap: 2px; overflow-wrap: anywhere; }
.compose textarea, .compose input[type=text] { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.compose textarea { resize: vertical; min-height: 140px; line-height: 1.55; }
.compose textarea:focus, .compose input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.editor { display: grid; gap: 8px; margin: 0; }
.regen { display: flex; gap: 8px; margin: 0; }
.regen input { flex: 1; }
.send-row { justify-content: space-between; }
button:disabled { opacity: .55; cursor: not-allowed; }
.write summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; }
.write[open] summary { margin-bottom: 8px; }
.compose.busy > * { opacity: .35; pointer-events: none; }
.compose.busy::after { content: attr(data-busy-text); position: absolute; inset: 0; display: grid; place-items: center; font-weight: 600; color: var(--ai); }
.a-decide { display: flex; gap: 4px; margin-left: 6px; }
.a-decide form { margin: 0; }
.small-btn { padding: 3px 8px; font-size: 12.5px; }
.confirm-dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 22px 24px; }
.confirm-dialog::backdrop { background: rgba(10, 16, 24, .45); }
.confirm-dialog h2 { margin: 0 0 12px; font-size: 19px; }
.confirm-close { position: absolute; right: 12px; top: 10px; margin: 0; }
.confirm-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; }
.confirm-meta dt { color: var(--muted); }
.confirm-meta dd { margin: 0; overflow-wrap: anywhere; font-weight: 600; }
.confirm-body { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 40vh; overflow-y: auto; }
.confirm-dialog.busy > * { opacity: .4; pointer-events: none; }

.new-mail { display: flex; align-items: center; gap: 10px; margin: 0 2px 12px; padding: 10px 12px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; }
.new-mail svg { width: 17px; height: 17px; }
.new-mail:hover { filter: brightness(1.06); }
a.tool { text-decoration: none; }
.field { display: grid !important; grid-template-columns: 56px 1fr; align-items: center; gap: 8px; }
.field span { color: var(--muted); font-size: 13px; }
.composer-page .compose { margin-top: 0; }
.forwarded { margin-top: 20px; border-left: 3px solid var(--line); padding: 4px 0 4px 14px; }
.forwarded h3 { margin: 0 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.forwarded .body { padding-top: 8px; font-size: 13.5px; }

/* search, « Demander à ta boîte » */
.search { flex: 1; min-width: 0; max-width: 560px; display: flex; align-items: center; gap: 8px; margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 16px; height: 16px; color: var(--muted); }
.search input { flex: 1; min-width: 0; font: inherit; color: var(--text); background: transparent; border: 0; padding: 9px 0; outline: none; }
.search-head p { margin: 4px 0 0; }
.search-head code { font-size: 12px; background: var(--hover); border-radius: 4px; padding: 0 4px; }
.ask { display: grid; gap: 6px; margin: 12px 0 2px; padding: 12px; border: 1px solid var(--ai-line); background: var(--ai-soft); border-radius: var(--radius); }
.ask button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--ai); }
.ask button svg { width: 16px; height: 16px; }
.chip.where { background: var(--panel); }
.ask-label { margin: 0 0 4px; }
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.sources { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sources a { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.sources a:hover { border-color: var(--ai); }
.sources .ref { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ai); color: #fff; font-size: 12px; font-weight: 700; }
.sources .src { flex: 1; min-width: 0; display: grid; gap: 1px; }
.asking { height: 100%; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--ai); font-weight: 600; padding: 24px; text-align: center; }
.asking i { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ai-line); border-top-color: var(--ai); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* « Aujourd'hui » */
body.wide .shell { grid-template-columns: 232px 1fr; }
body.wide .list { display: none; }
.nav-item.v-today svg { color: var(--high); }
.today { max-width: 920px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 4px 0 22px; }
.tile { display: grid; gap: 2px; padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.tile:hover { border-color: var(--accent); }
.tile b { font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.tile.urgent b { color: var(--urgent); } .tile.reply b { color: var(--accent); } .tile.todo b { color: var(--wait); }
.day-sec { margin-bottom: 22px; }
.day-sec h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.day-sec h3 svg { width: 16px; height: 16px; }
.day-sec .items { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day-sec .item:last-child { border-bottom: 0; }
.due.later { color: var(--muted); font-weight: 500; }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 10px; text-align: center; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0 0 8px; }
.login label { text-align: left; font-weight: 600; font-size: 13px; }
.login input { font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.logo.big { width: 48px; height: 48px; justify-self: center; }
.error { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px; }

/* narrow screens: list, or the mail, one at a time */
@media (max-width: 1100px) { .shell { grid-template-columns: 200px minmax(300px, 380px) 1fr; } .brand { width: auto; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 56px); }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; gap: 4px; background: var(--panel); }
  .nav-group { flex-direction: row; gap: 4px; }
  .nav-label, .nav-foot { display: none; }
  .nav-item { white-space: nowrap; padding: 6px 10px; }
  .new-mail { margin: 0; padding: 6px 12px; white-space: nowrap; }
  .list { border-right: 0; }
  .pane, body.has-pane .list, body.has-pane .side { display: none; }
  body.has-pane .pane { display: block; }
  .mail { padding: 16px 16px 40px; }
  .back { display: inline-block; }
  .account, .live span { display: none; }
  .top { gap: 10px; padding: 0 12px; }
  .brand span { display: none; }
  .logout button { padding: 6px 4px; font-size: 13px; }
  body.wide .shell { grid-template-columns: 1fr; }
  body.wide.has-pane .side { display: flex; }
  .meta { flex-wrap: wrap; }
  .who { overflow-wrap: anywhere; }
  .meta .date { flex-basis: 100%; padding-left: 50px; }
  .toolbar .tool span { display: none; }
  .actions li { flex-wrap: wrap; }
  .toolbar .move { margin-left: 0; }
  .toast { left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
}
.ai-compose { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ai-compose .field { flex: 1 1 260px; }
.ai-compose svg { width: 12px; height: 12px; vertical-align: -1px; }
