:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --brand: #1f4fd8; --brand-ink: #fff; --ok: #0f8a4f; --ok-bg: #e6f6ee; --warn: #a15c00; --warn-bg: #fff4e0;
  --bad: #c4291c; --bad-bg: #fdecea; --info: #5b3fd6; --info-bg: #efebff; --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; }
.hidden { display: none !important; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.error { color: var(--bad); margin: 6px 0 0; font-size: 14px; }
.error:empty { display: none; }
h1 { font-size: 22px; margin: 0; } h3 { margin: 22px 0 6px; font-size: 15px; }

input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus, .editor:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #1f4fd81f; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; padding: 9px 16px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: #f1f3f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.link:hover { color: var(--ink); text-decoration: underline; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 8l7 5 7-5M5 8v8h14V8' stroke='white' stroke-width='1.8' fill='none' stroke-linejoin='round'/%3E%3C/svg%3E") center/80% no-repeat; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--panel); padding: 36px; border-radius: 16px; width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; box-shadow: 0 10px 40px #0000000f; }
.login-card p { margin: 0; }

/* Mise en page */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.compose-btn { width: 100%; }
nav { display: grid; gap: 2px; }
nav a { padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--ink); text-decoration: none; }
nav a:hover { background: #f1f3f6; }
nav a.active { background: #e8eefc; color: var(--brand); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.live { font-size: 12px; } .live.on { color: var(--ok); } .live.off { color: var(--muted); }
main { padding: 28px 32px 60px; max-width: 1100px; width: 100%; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.view-head input { max-width: 340px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.info { background: #f8f9fb; font-size: 14px; }

/* Statistiques */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { font-size: 24px; display: block; }
.stat span { color: var(--muted); font-size: 13px; }

/* Liste des messages */
.list { display: grid; gap: 10px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; }
.msg:hover { border-color: #c9cfd9; }
.msg-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.msg-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-from { color: var(--muted); font-size: 13px; margin-top: 2px; }
.rcpts { margin-top: 10px; display: grid; gap: 6px; }
.rcpt { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; }
.rcpt .who { min-width: 180px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: #f0f1f4; color: var(--muted); }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Rédaction */
.compose { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; }
.row label { color: var(--muted); font-size: 14px; }
.row textarea { resize: vertical; min-height: 40px; }
.preview-inbox { background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.inbox-line { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.inbox-line > div { min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.pv-subject { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; padding: 6px; background: #fafbfc; margin-bottom: -10px; }
.toolbar button { font: inherit; font-size: 13px; border: 0; background: none; padding: 5px 9px; border-radius: 6px; cursor: pointer; }
.toolbar button:hover, .toolbar button.on { background: #e8eaee; }
.toolbar .spacer { flex: 1; }
.editor { min-height: 260px; border: 1px solid var(--line); border-radius: 0 0 8px 8px; padding: 14px; background: #fff; outline: none; overflow: auto; line-height: 1.5; }
.editor.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical; }
.filelist { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #eef0f4; border-radius: 99px; padding: 3px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; }
.compose-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; margin: 6px 0; }
.check input { width: auto; }

/* Alias / domaines */
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-form textarea, .grid-form .error { grid-column: 1 / -1; }
.grid-form button { grid-column: 1 / -1; justify-self: start; }
.addr-input { display: flex; align-items: center; gap: 6px; }
.addr-input input { flex: 1; } .addr-input select { flex: 1.2; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; }
.inline-form .error { flex-basis: 100%; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.item .actions { display: flex; gap: 6px; }
.domain-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.domain-head h2 { font-size: 18px; margin: 0; }
.dns-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13.5px; table-layout: fixed; }
.dns-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.dns-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.dns-table td.val code { display: block; max-height: 70px; overflow: auto; }
.dns-table .why { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.domain-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.domain-settings label { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.domain-settings .full { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--brand); font-size: 14px; margin-top: 12px; }

.settings { max-width: 680px; }
.settings input { margin-top: 6px; }

/* Fenêtre détail */
.modal { position: fixed; inset: 0; background: #0f172a66; display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal-card { background: var(--panel); border-radius: 14px; width: 100%; max-width: 780px; max-height: 90vh; overflow: auto; padding: 24px; position: relative; }
.modal-close { position: absolute; top: 14px; right: 14px; border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; border-left: 2px solid var(--line); }
.timeline li { padding: 4px 0 8px 14px; position: relative; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.t-delivered::before { background: var(--ok); }
.timeline li.t-opened::before { background: var(--info); }
.timeline li.t-failed::before { background: var(--bad); }
.timeline li.t-deferred::before { background: #e3a008; }
.timeline .detail { color: var(--muted); word-break: break-word; }
.rcpt-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.mail-preview { width: 100%; height: 320px; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; background: #fff; }

/* Notifications */
.toasts { position: fixed; right: 18px; top: 18px; display: grid; gap: 8px; z-index: 30; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 10px; max-width: 360px; box-shadow: 0 8px 30px #0003; animation: pop .25s ease-out; font-size: 14px; }
.toast b { display: block; margin-bottom: 2px; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  main, .sidebar, nav { min-width: 0; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; }
  .sidebar .brand { order: 1; } .sidebar-foot { order: 2; }
  .sidebar .compose-btn { width: 100%; order: 3; }
  nav { grid-auto-flow: column; overflow-x: auto; width: 100%; order: 4; }
  .rcpt .who { min-width: 0; flex-basis: 100%; font-weight: 500; }
  nav a { white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; gap: 12px; }
  main { padding: 18px 14px 50px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 1fr; gap: 4px; }
  .grid-form { grid-template-columns: 1fr; }
  .view-head { flex-wrap: wrap; }
  .view-head input { max-width: none; }
  .dns-table { table-layout: auto; }
}

/* ---------- Boîte de réception ---------- */
.count { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11.5px; padding: 1px 7px; margin-left: 4px; font-weight: 650; }
nav a.active .count { background: var(--brand); }
main:has(.inbox-view:not(.hidden)) { max-width: none; padding: 0; }
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
.thread-pane { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.thread-tools { padding: 14px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.filters { display: flex; gap: 4px; }
.filters button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 11px; cursor: pointer; }
.filters button.on { background: #e8eefc; border-color: #c9d6fa; color: var(--brand); font-weight: 600; }
.threads { overflow-y: auto; flex: 1; }
.thread { padding: 12px 14px; border-bottom: 1px solid #f0f1f4; cursor: pointer; display: grid; gap: 2px; }
.thread:hover { background: #f8f9fb; }
.thread.active { background: #eef3ff; }
.thread .t-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.thread .t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .t-date { font-size: 12px; color: var(--muted); flex: none; }
.thread .t-subject { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .t-snippet { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .t-to { font-size: 11.5px; color: var(--muted); }
.thread.unread .t-name, .thread.unread .t-subject { font-weight: 700; }
.thread.unread .t-name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-right: 6px; vertical-align: middle; }
.conv-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.conv-empty { margin: auto; text-align: center; color: var(--ink); }
.big-icon { font-size: 44px; }
.conv-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 14px 20px; display: flex; gap: 12px; align-items: center; }
.conv-head .grow { flex: 1; min-width: 0; }
.conv-head h2 { font-size: 17px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-head .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.conv-items { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; max-width: 760px; width: 92%; }
.bubble.in { align-self: flex-start; border-top-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: #f1f5ff; border-color: #d8e2fb; border-top-right-radius: 4px; }
.bubble.new { animation: pop .35s ease-out; box-shadow: 0 0 0 3px #1f4fd833; }
.b-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.b-head .muted { font-size: 12.5px; }
.b-body iframe { width: 100%; border: 0; display: block; min-height: 40px; background: transparent; }
.b-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; }
.b-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.b-foot a.chip { text-decoration: none; color: inherit; }
.quote-toggle { font: inherit; font-size: 12px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 0 8px; cursor: pointer; color: var(--muted); }
.reply-box { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 20px 14px; }
.reply-box .editor { min-height: 90px; max-height: 40vh; border-radius: 8px; }
.reply-from { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.reply-from input { width: auto; padding: 3px 8px; font-size: 13px; }
.reply-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.reply-actions .grow { flex: 1; }
.reply-actions .check { margin: 0; font-size: 13px; }
.icon-btn { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.icon-btn:hover { background: #f1f3f6; }

@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  .inbox.open .thread-pane { display: none; }
  .inbox:not(.open) .conv-pane { display: none; }
  .back { display: inline-block; }
  .conv-items { padding: 12px; }
  .bubble { width: 100%; }
  .reply-box { padding: 10px 12px; }
}

/* Expéditeur modifiable dans la rédaction */
.from-edit { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px; }
.from-addr { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px 0 0; background: #fff; }
.from-addr:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px #1f4fd81f; }
.from-addr input { border: 0; box-shadow: none !important; text-align: right; flex: 1; min-width: 60px; }
.from-addr select { border: 0; box-shadow: none !important; width: auto; max-width: 60%; padding-left: 0; background: transparent; }
.from-addr .at { color: var(--muted); }
.from-hint { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: -4px; }
.from-hint select { width: auto; font-size: 13px; padding: 4px 8px; color: var(--muted); }
.from-hint .check { margin: 0; }
.hint-new { color: var(--info); } .hint-ok { color: var(--ok); }
@media (max-width: 760px) { .from-edit { grid-template-columns: 1fr; } }
.editor:empty::before { content: attr(data-ph); color: var(--muted); }
.icon-btn.on { background: #e8eefc; border-color: #c9d6fa; color: var(--brand); }

/* Modèles */
.tpl-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tpl-bar select { flex: 1; min-width: 200px; }
.vars-hint { margin-top: -4px; line-height: 1.9; }
.var { font: inherit; font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; border: 1px dashed #c9d6fa; background: #f4f7ff; color: var(--brand); border-radius: 6px; padding: 0 6px; margin: 0 3px; cursor: pointer; }
.var:hover { background: #e8eefc; }
.reply-actions select { width: auto; font-size: 13px; padding: 5px 8px; }

/* Cc / Cci / options */
.to-wrap { position: relative; }
.to-wrap textarea { padding-right: 190px; }
.to-links { position: absolute; right: 8px; top: 8px; display: flex; gap: 2px; }
.link-btn { font: inherit; font-size: 13px; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--brand); background: #eef3ff; }
.link-btn.on { color: var(--brand); font-weight: 600; }
.field-x { display: flex; gap: 6px; align-items: flex-start; }
.field-x textarea { resize: vertical; min-height: 40px; }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 10px 6px; }
.x:hover { color: var(--bad); }
.more-panel { display: grid; gap: 10px; background: #f8f9fb; border: 1px dashed var(--line); border-radius: 10px; padding: 12px; }
.sched { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sched input { width: auto; }
.opts { display: grid; gap: 2px; }
.kind { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
@media (max-width: 760px) { .to-wrap textarea { padding-right: 11px; } .to-links { position: static; margin-top: 4px; } }

.reply-to-edit { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
@media (max-width: 760px) { .reply-to-edit { grid-template-columns: 1fr; } }
