:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #18211d; --muted: #66706b; --line: #e3e7e4;
  --accent: #0f6b4f; --accent-ink: #ffffff; --accent-soft: #e5f2ec;
  --client: #2f5d8a; --client-soft: #e8f0f8; --equipe: #8a5a12; --equipe-soft: #fbf1df;
  --danger: #b3261e; --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111513; --panel: #1a201d; --ink: #e8ece9; --muted: #9aa49f; --line: #2c3430;
    --accent: #3fae84; --accent-ink: #08130e; --accent-soft: #1d3329; --client: #8fb7e0; --client-soft: #1d2a37;
    --equipe: #e0b46a; --equipe-soft: #33291a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 7px 6px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; padding: 4px 8px; color: var(--ink); }
.muted { color: var(--muted); }

.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; color: var(--muted); font-size: 13px; }
.brand strong { font-size: 18px; letter-spacing: -.01em; }
.brand.small strong { font-size: 16px; }
.mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.login-card form { display: grid; gap: 10px; margin-top: 22px; }
.login-card label { font-weight: 600; font-size: 14px; }
.login-card input { border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: var(--bg); font-size: 17px; }
.login-msg { min-height: 20px; color: var(--muted); font-size: 14px; margin: 14px 0 0; }

/* layout */
.app { display: grid; height: 100vh; height: 100dvh; grid-template-columns: 230px minmax(300px, 400px) 1fr; grid-template-rows: auto 1fr; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.sync { color: var(--muted); font-size: 13px; }
.nav { border-right: 1px solid var(--line); padding: 12px 8px; overflow: auto; background: var(--panel); }
.nav-item { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { color: var(--muted); font-size: 13px; font-weight: 400; }
.nav-title { margin: 16px 10px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.nav-help { margin: 18px 10px 0; font-size: 12.5px; color: var(--muted); }
.nav-help p { margin: 0 0 8px; }
.list { min-width: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.search { padding: 10px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--bg); }
.threads { overflow: auto; flex: 1; }
.thread { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 11px 14px; cursor: pointer; }
.thread:hover { background: var(--bg); }
.thread.active { background: var(--accent-soft); }
.thread .row1 { display: flex; gap: 8px; align-items: baseline; }
.thread .people { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread.unread .people, .thread.unread .subj { font-weight: 700; }
.thread .when { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.thread .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.thread .snip { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.olivier { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.equipe { background: var(--equipe-soft); color: var(--equipe); border-color: transparent; }
.badge.client { background: var(--client-soft); color: var(--client); border-color: transparent; }
.badge.wait { background: #fde8e6; color: var(--danger); border-color: transparent; }
.chip { font-size: 11.5px; color: var(--muted); }

.view { min-width: 0; overflow: auto; min-height: 0; padding: 18px 22px 40px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.view h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.01em; }
.thread-head { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.thread-head .grow { flex: 1; min-width: 220px; }
.back { margin-bottom: 8px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.msg.olivier { border-left: 4px solid var(--accent); }
.msg.equipe { border-left: 4px solid var(--equipe); }
.msg.client { border-left: 4px solid var(--client); }
.msg.pending { opacity: .75; }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-head .from { font-weight: 600; }
.msg-head .date { margin-left: auto; color: var(--muted); font-size: 13px; }
.msg-to { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; margin-top: 10px; }
.msg-quoted { white-space: pre-wrap; color: var(--muted); font-size: 13.5px; border-left: 2px solid var(--line); padding-left: 10px; margin-top: 8px; }
.msg-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.msg-tools .btn { font-size: 13px; padding: 4px 9px; }
.att { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; text-decoration: none; color: var(--ink); }
iframe.html-mail { width: 100%; height: 480px; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-top: 10px; }

.composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 18px; display: grid; gap: 8px; }
.composer h2 { font-size: 15px; margin: 0; }
.composer .field { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 8px; }
.composer label { color: var(--muted); font-size: 13.5px; }
.composer input, .composer textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.composer textarea { min-height: 170px; resize: vertical; }
.composer .from-line { font-size: 13px; color: var(--muted); }
.composer .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.composer .actions .spacer { flex: 1; }
.files { font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }
.ok { color: var(--accent); font-size: 14px; }

/* topo + markdown */
.md h1 { font-size: 21px; } .md h2 { font-size: 17px; margin-top: 22px; } .md h3 { font-size: 15.5px; margin-top: 16px; }
.md p, .md li { max-width: 760px; } .md ul { padding-left: 20px; } .md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.md code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.table-wrap { overflow-x: auto; margin: 8px 0; }
.table-wrap table { border-collapse: collapse; font-size: 13.5px; }
.table-wrap th, .table-wrap td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.table-wrap th { background: var(--panel); }

/* assistant */
.assistant { position: fixed; right: 0; top: 0; bottom: 0; width: min(460px, 100%); background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; box-shadow: -8px 0 24px rgba(0,0,0,.08); }
.assistant-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.assistant-head #assistant-context { flex: 1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assistant-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.assistant-log .hint { color: var(--muted); font-size: 14px; }
.bubble { padding: 10px 12px; border-radius: 10px; max-width: 92%; word-wrap: break-word; }
.bubble.user { background: var(--accent); color: var(--accent-ink); align-self: flex-end; white-space: pre-wrap; }
.bubble.assistant { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }
.bubble.assistant p:first-child { margin-top: 0; } .bubble.assistant p:last-child { margin-bottom: 0; }
.bubble .use { margin-top: 8px; }
.assistant-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.assistant-form textarea { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); resize: none; }

/* archive / bin */
.btn.mini { font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.btn.danger { color: var(--danger); }
.btn.mini[data-file="trash"]:hover, .btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.row-actions { margin-left: auto; display: flex; gap: 4px; opacity: 0; }
.thread:hover .row-actions, .thread:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }
.file-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 40; display: flex; gap: 10px; align-items: center;
  background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px); }
.toast .btn.link { color: var(--bg); font-weight: 700; text-decoration: underline; padding: 0 2px; }

.only-mobile { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .top-actions { gap: 4px; }
  .top .brand strong { display: none; }
  .only-mobile { display: inline-block; }
  .top { padding: 8px 12px; gap: 8px; }
  .top .sync { display: none; }
  .top-actions .btn#btn-new { display: none; }
  .nav { position: fixed; top: 0; left: 0; bottom: 0; width: 270px; z-index: 30; box-shadow: 8px 0 24px rgba(0,0,0,.15); transform: translateX(-105%); transition: transform .18s; }
  .nav.open { transform: none; }
  .list, .view { grid-column: 1; grid-row: 2; border-right: 0; }
  .app.show-view .list { display: none; }
  .app:not(.show-view) .view { display: none; }
  .view { padding: 14px 16px 40px; }
  .composer .field { grid-template-columns: 1fr; gap: 2px; }
}
