/* =========================================================================
   AKR WebMail — design system
   Palette "signal nocturne" : fond quasi-noir bleuté, deux accents
   (violet / cyan) plutôt qu'un seul, typo Sora (titres) + Inter (UI).
   ========================================================================= */

:root {
  --bg: #101019;
  --bg-elevated: #15151f;
  --surface: #191a25;
  --surface-2: #20212e;
  --surface-hover: #292a3a;
  --border: #2b2c3b;
  --border-soft: #212230;

  --text: #edeef5;
  --text-muted: #9297ac;
  --text-faint: #62667c;

  --accent: #7c6cff;
  --accent-dim: #5d4fd1;
  --accent-soft: rgba(124, 108, 255, .16);
  --accent-2: #22d3ee;
  --accent-2-soft: rgba(34, 211, 238, .14);

  --danger: #f5576c;
  --danger-soft: rgba(245, 87, 108, .14);
  --success: #34d399;
  --warning: #f5a623;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --ease: cubic-bezier(.2, .7, .3, 1);
  --fast: .13s;
  --normal: .2s;

  --rail-w: 64px;
  --side-w: 268px;
  --list-w: 360px;
  --topbar-h: 58px;
  --tabbar-h: 64px;

  color-scheme: dark;
}

/* ---------- Thème clair (bascule via bouton, mémorisée en localStorage) --- */
html[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f2f9;
  --surface-hover: #eaebf7;
  --border: #e2e3f0;
  --border-soft: #ebecf6;

  --text: #1b1c29;
  --text-muted: #5c5f74;
  --text-faint: #8b8ea3;

  --accent-soft: rgba(124, 108, 255, .12);
  --accent-2-soft: rgba(34, 211, 238, .16);
  --danger-soft: rgba(245, 87, 108, .1);

  color-scheme: light;
}

html {
  transition: background-color var(--normal) var(--ease);
}
html[data-theme], html[data-theme] body,
html[data-theme] #topbar, html[data-theme] #rail, html[data-theme] #side-panel,
html[data-theme] #list-panel, html[data-theme] #detail-panel,
html[data-theme] .modal-content, html[data-theme] .toast, html[data-theme] .notif-panel {
  transition: background-color var(--normal) var(--ease), color var(--normal) var(--ease), border-color var(--normal) var(--ease), box-shadow var(--normal) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Le contenu des mails / adresses / champs reste sélectionnable normalement. */
.selectable, input, textarea, [contenteditable],
#reading-pane .body, #reading-pane .reading-header,
.contact-detail .contact-email, .message-item .from, .message-item .subject,
.contact-card .c-email, .contact-card .c-name {
  -webkit-user-select: text;
  user-select: text;
}

img, svg { -webkit-user-drag: none; }

/* =========================================================================
   Système d'icônes — Lucide, colorées par famille + micro-animations.
   La couleur est posée directement sur .ic-xxx (donc sur le <svg>, pas sur
   son parent) : elle est donc toujours plus spécifique que `currentColor`
   hérité, mais toujours BATTUE par les règles d'état existantes du type
   `.rail-btn.active svg` ou `.folder-row.active .f-icon` (2 classes + tag
   > 1 classe), qui continuent donc à piloter la couleur "active/hover".
   ========================================================================= */
:root {
  --ic-blue: #5b9dff;
  --ic-teal: #22d3ee;
  --ic-violet: #7c6cff;
  --ic-pink: #f472b6;
  --ic-amber: #f5a623;
  --ic-green: #34d399;
  --ic-red: #f5576c;
  --ic-slate: #9297ac;
}

.ic {
  flex: none;
  transition: transform .22s cubic-bezier(.34, 1.56, .64, 1), color var(--fast) var(--ease), opacity var(--fast) var(--ease);
}

.ic-mail, .ic-inbox { color: var(--ic-blue); }
.ic-sent { color: var(--ic-violet); }
.ic-drafts { color: var(--ic-amber); }
.ic-spam { color: var(--ic-red); }
.ic-folder, .ic-folder-plus { color: var(--ic-amber); }
.ic-users, .ic-user-plus { color: var(--ic-teal); }
.ic-search { color: var(--ic-slate); }
.ic-plus { color: var(--ic-green); }
.ic-close { color: var(--ic-red); }
.ic-filter { color: var(--ic-violet); }
.ic-trash { color: var(--ic-red); }
.ic-archive { color: var(--ic-amber); }
.ic-tag { color: var(--ic-pink); }
.ic-reply, .ic-back { color: var(--ic-blue); }
.ic-clip { color: var(--ic-slate); }
.ic-compose, .ic-edit { color: var(--ic-violet); }
.ic-refresh { color: var(--ic-teal); }
.ic-bell { color: var(--ic-amber); }
.ic-download { color: var(--ic-green); }
.ic-eye { color: var(--ic-blue); }
.ic-image { color: var(--ic-pink); }
.ic-file { color: var(--ic-slate); }
.ic-moon { color: var(--ic-violet); }
.ic-sun { color: var(--ic-amber); }

/* Micro-animations au survol du bouton/élément parent */
button:hover > .ic-plus, .side-action-btn:hover .ic-plus { transform: rotate(90deg); }
button:hover > .ic-refresh, .side-action-btn:hover .ic-refresh { transform: rotate(75deg); }
button:hover > .ic-close { transform: rotate(90deg) scale(1.1); }
button:hover > .ic-trash { animation: icShake .35s ease; }
button:hover > .ic-archive { transform: translateY(2px); }
button:hover > .ic-reply, button:hover > .ic-back { transform: translateX(-2px); }
button:hover > .ic-download { animation: icBounceDown .5s ease; }
button:hover > .ic-bell { animation: icRing .5s ease; }
button:hover > .ic-compose, button:hover > .ic-edit { transform: rotate(-8deg); }
button:hover > .ic-mail, button:hover > .ic-inbox { transform: scale(1.12); }
button:hover > .ic-users, button:hover > .ic-user-plus { transform: scale(1.12); }
.icon-refresh.loading, .side-action-btn.loading .icon-refresh { animation: spin .9s linear infinite !important; }

@keyframes icShake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}
@keyframes icBounceDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}
@keyframes icRing {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(11deg); }
  60% { transform: rotate(-7deg); }
  80% { transform: rotate(4deg); }
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

h1, h2, h3 { font-family: "Sora", "Inter", sans-serif; margin: 0; }

/* ---------- fond décoratif (léger mouvement, désactivé si reduced-motion) - */
#bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(700px 500px at 8% -6%, var(--accent-soft), transparent 60%),
    radial-gradient(600px 520px at 106% 18%, var(--accent-2-soft), transparent 55%),
    radial-gradient(900px 700px at 50% 120%, rgba(124,108,255,.06), transparent 60%);
  background-size: 130% 130%;
  animation: meshDrift 26s ease-in-out infinite alternate;
  transition: opacity var(--normal) var(--ease);
}
html[data-theme="light"] #bg-mesh { opacity: .7; }
@keyframes meshDrift {
  0%   { background-position: 0% 0%, 100% 0%, 50% 100%; }
  100% { background-position: 4% 3%, 96% 8%, 54% 96%; }
}

/* =========================================================================
   Layout global
   ========================================================================= */

#topbar {
  position: relative;
  z-index: 20;
  order: -1;
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-soft);
}
#topbar h1 { font-size: 16px; font-weight: 700; letter-spacing: .01em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

body { display: flex; flex-direction: column; }
#app {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: var(--rail-w) var(--side-w) var(--list-w) 1fr;
  overflow: hidden;
  min-height: 0;
}

/* ---------- Rail ---------- */
#rail {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 6px;
}
#rail-brand {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  margin-bottom: 10px;
}
#rail-brand svg { width: 22px; height: 22px; }
#rail-brand img { width: 30px; height: 30px; object-fit: contain; border-radius: 8px; }
.rail-btn {
  position: relative;
  width: 42px; height: 42px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.rail-btn svg { width: 20px; height: 20px; transition: transform var(--fast) var(--ease); }
.rail-btn:hover { background: var(--surface-hover); color: var(--text); }
.rail-btn:hover svg { transform: scale(1.08); }
.rail-btn:active svg { transform: scale(.94); }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(124,108,255,.35); }
.rail-spacer { flex: 1; }
.rail-add { color: var(--accent-2); }
.rail-add:hover { background: var(--accent-2-soft); color: var(--accent-2); }
/* ---------- Side panel ---------- */
#side-panel {
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
  padding: 14px 10px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-view { display: flex; flex-direction: column; min-height: 0; }
.side-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 8px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: .02em;
}
.side-section-head:first-child { padding-top: 4px; }

.sortable-list { display: flex; flex-direction: column; gap: 2px; }
.sortable-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px 8px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.sortable-item:hover { background: var(--surface-hover); }
.sortable-item.active { background: var(--accent-soft); color: var(--accent); }
.sortable-item.dragging { opacity: .35; }
.sortable-item .grip {
  width: 12px; height: 16px; flex: none;
  opacity: 0;
  color: var(--text-faint);
  cursor: grab;
  transition: opacity var(--fast) var(--ease);
  display: flex; align-items: center; justify-content: center;
}
.sortable-item:hover .grip { opacity: 1; }
.sortable-item .grip svg { width: 12px; height: 12px; }

.avatar {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  color: #10111a;
  background: var(--accent);
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; animation: fadeIn var(--normal) var(--ease); }

.item-main { min-width: 0; flex: 1; }
.item-title {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-sub {
  font-size: 11px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-actions { display: flex; gap: 2px; opacity: .55; flex: none; transition: opacity var(--fast) var(--ease); }
.sortable-item:hover .item-actions, .sortable-item.active .item-actions { opacity: 1; }

.item-menu {
  position: fixed; z-index: 60; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 20px 44px rgba(0,0,0,.4); padding: 4px;
  display: flex; flex-direction: column; gap: 1px;
}
.item-menu-entry {
  display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; color: var(--text);
  font: inherit; font-size: 13px; text-align: left;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.item-menu-entry svg { width: 14px; height: 14px; flex: none; color: var(--text-muted); }
.item-menu-entry:hover { background: var(--surface-hover); }
.item-menu-entry.danger { color: var(--danger); }
.item-menu-entry.danger svg { color: var(--danger); }
.item-menu-entry.danger:hover { background: var(--danger-soft); }

.icon-btn {
  border: none; background: transparent; color: var(--text-muted);
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); transform: scale(1.06); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.ghost { background: transparent; }

/* ---------- Indicateur de chargement générique (boutons async) ---------- */
.is-loading { position: relative; pointer-events: none; }
.is-loading > *:not(.btn-spinner) { visibility: hidden; }
.btn-spinner {
  position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn-primary.is-loading .btn-spinner, .btn-ghost.is-loading .btn-spinner { width: 15px; height: 15px; }
.row-loading { opacity: .5; pointer-events: none; }

.folder-row .item-title { display: flex; align-items: center; gap: 8px; }
.folder-row .f-icon { width: 15px; height: 15px; color: var(--text-muted); flex: none; }
.folder-row.active .f-icon { color: var(--accent); }

.side-action-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-top: 8px;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.side-action-btn svg { width: 15px; height: 15px; flex: none; }
.side-action-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--accent-dim); }
.side-action-btn.loading .icon-refresh { animation: spin 0.9s linear infinite; }
.side-action-btn:disabled { opacity: .55; cursor: default; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  margin: 4px 2px 2px;
  color: var(--text-faint);
}
.search-box svg { width: 15px; height: 15px; flex: none; }
.search-box input {
  border: none; background: transparent; outline: none;
  width: 100%; font-size: 13px; color: var(--text);
}
.search-box input::placeholder { color: var(--text-faint); }

.hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
#contacts-count {
  margin-top: 10px;
  padding: 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: .01em;
}

/* ---------- List panel ---------- */
#list-panel {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.list-view { display: flex; flex-direction: column; min-height: 0; flex: 1; }

#sent-filter-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--text-muted);
  flex: none;
}
#sent-filter-bar svg { width: 14px; height: 14px; flex: none; }
#sent-filter-bar.hidden { display: none; }
#sent-filter-bar select {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12.5px;
}

/* ---------- Recherche + filtres mails ---------- */
#mail-search-bar {
  flex: none;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elevated);
}
#mail-search-bar .search-box { margin: 0; }
#mail-search-clear { flex: none; width: 22px; height: 22px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.filter-chip svg { width: 8px; height: 8px; color: var(--text-faint); transition: color var(--fast) var(--ease); }
.filter-chip:hover { transform: translateY(-1px); border-color: var(--accent-dim); }
.filter-chip[data-active="true"] {
  background: var(--accent-soft); border-color: rgba(124,108,255,.4); color: var(--accent);
}
.filter-chip[data-active="true"] svg { color: var(--accent-2); }

#message-list, #contact-list {
  flex: 1;
  overflow-y: auto;
  animation: fadeIn var(--normal) var(--ease);
}

.message-item {
  position: relative;
  display: flex;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.message-item:hover { background: var(--surface); }
.message-item.selected {
  background: linear-gradient(90deg, var(--accent-soft), transparent 130%);
  box-shadow: inset 3px 0 0 var(--accent), inset 0 0 0 1px rgba(124,108,255,.18);
  transform: translateX(2px);
}
.message-item.unread::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent-2);
}
.message-item.selected.unread::before { background: var(--accent); }
.message-item .m-body { min-width: 0; flex: 1; }
.message-item .subject {
  font-size: 13.5px; color: var(--text-muted);
  display: flex; align-items: center; min-width: 0;
}
.message-item .subject-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.message-item.unread .subject { color: var(--text); font-weight: 700; }
.m-clip { display: inline-flex; flex: none; margin-left: 5px; vertical-align: -2px; }
.m-clip svg { width: 12px; height: 12px; }
.message-item .from {
  font-size: 12px; color: var(--text-faint); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-item .date { font-size: 11px; color: var(--text-faint); flex: none; }

/* ---------- Sélection multiple + actions groupées ---------- */
.msg-check {
  display: flex; align-items: center; justify-content: center;
  flex: none; width: 20px; align-self: stretch;
  cursor: pointer; opacity: 0;
  transition: opacity var(--fast) var(--ease);
}
.message-item:hover .msg-check,
.message-item.checked .msg-check,
#message-list.select-mode .msg-check { opacity: 1; }
.msg-check-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.msg-check-box {
  width: 17px; height: 17px; border-radius: 5px; flex: none;
  border: 1.5px solid var(--border); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: transparent;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.msg-check-box svg { width: 11px; height: 11px; }
.msg-check:hover .msg-check-box { border-color: var(--accent-dim); }
.msg-check-input:checked + .msg-check-box {
  background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.05);
}
.message-item.checked {
  background: linear-gradient(90deg, var(--accent-soft), transparent 130%);
}
#select-mode-btn svg { width: 13px; height: 13px; }

#bulk-action-bar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--accent-soft);
  animation: fadeIn var(--fast) var(--ease);
}
#bulk-action-bar.hidden { display: none; }
#bulk-action-bar .icon-btn.ghost {
  width: 22px; height: 22px; flex: none; color: var(--text-muted);
}
#bulk-action-bar .icon-btn.ghost svg { width: 13px; height: 13px; }
#bulk-action-bar .icon-btn.ghost:hover { color: var(--text); background: var(--surface-hover); }

.bulk-select-all {
  display: flex; align-items: center; gap: 6px; cursor: pointer; flex: none;
}
.bulk-select-all input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.bulk-select-label { font-size: 11px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

.bulk-count-badge {
  flex: none;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.bulk-actions {
  display: flex; gap: 6px; flex: none;
  margin-left: auto;
}
.bulk-actions .btn-chip {
  padding: 6px 9px; font-size: 12px; gap: 5px; flex: none; white-space: nowrap;
}

.bulk-actions .btn-chip-label { display: none; }
.bulk-actions .btn-chip { padding: 7px; }

.item-menu-empty { padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); }

.contact-card {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.contact-card:hover { background: var(--surface); }
.contact-card.selected { background: var(--accent-soft); }
.contact-card .c-main { min-width: 0; flex: 1; }
.contact-card .c-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card .c-email { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card .c-meta { font-size: 10.5px; color: var(--text-faint); flex: none; text-align: right; }
.tag-chip {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
  margin-top: 3px;
}
.tag-chip.manual { background: var(--accent-2-soft); color: var(--accent-2); }

/* ---------- Detail panel ---------- */
#detail-panel { overflow: hidden; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.detail-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#reading-pane { flex: 1; overflow-y: auto; padding: 26px 32px; animation: fadeIn var(--normal) var(--ease); }

.empty-state {
  color: var(--text-faint);
  text-align: center;
  margin: auto;
  max-width: 260px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-state svg { width: 40px; height: 40px; opacity: .6; }
.empty-state p { margin: 0; font-size: 13px; }

.reading-header { border-bottom: 1px solid var(--border-soft); padding-bottom: 16px; margin-bottom: 16px; }
.reading-header h2 { font-size: 19px; font-weight: 700; margin-bottom: 10px; }
.reading-meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.reading-meta b { color: var(--text-faint); font-weight: 600; }
.reading-actions { margin: 14px 0 18px; display: flex; gap: 8px; }
.btn-chip {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn-chip svg { width: 14px; height: 14px; }
.btn-chip:hover { background: var(--surface-hover); border-color: var(--accent-dim); transform: translateY(-1px); }
.btn-chip.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

.attachment {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin: 4px 8px 4px 0;
  font-size: 12.5px;
  font-family: inherit;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
button.attachment { appearance: none; -webkit-appearance: none; }
.attachment svg { width: 13px; height: 13px; color: var(--accent-2); flex: none; }
.attachment .ic-eye { width: 13px; height: 13px; margin-left: 2px; opacity: .7; }
.attachment:hover { border-color: var(--accent-2); background: var(--accent-2-soft); transform: translateY(-1px); }

/* ---------- Preview des pièces jointes ---------- */
.preview-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 10px;
}
.preview-head h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-head-actions { display: flex; gap: 4px; flex: none; }
.preview-body {
  flex: 1;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.preview-body img { max-width: 100%; max-height: 72vh; display: block; border-radius: var(--radius-sm); }
.preview-pdf { width: 100%; height: 72vh; border: none; background: #fff; border-radius: var(--radius-sm); }
.preview-text {
  width: 100%; height: 72vh; margin: 0; padding: 16px;
  overflow: auto; white-space: pre-wrap; word-break: break-word;
  font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px;
  text-align: left; color: var(--text);
}

#reading-pane iframe.body-frame { display: block; width: 100%; max-width: 100%; border: none; background: transparent; }
#reading-pane .body { width: 100%; max-width: 100%; overflow-x: auto; }
#reading-pane .body-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: inherit; font-size: 13.5px; line-height: 1.55; color: var(--text);
}

/* ---------- Contact detail ---------- */
.contact-detail { padding: 34px 32px; overflow-y: auto; animation: fadeIn var(--normal) var(--ease); }
.contact-detail .cd-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.contact-detail .cd-name { font-size: 20px; font-weight: 700; }
.contact-detail .contact-email { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.contact-detail .cd-stats {
  display: flex; gap: 26px;
  padding: 16px 0;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 20px;
}
.cd-stat b { display: block; font-size: 18px; font-family: "Sora", sans-serif; }
.cd-stat span { font-size: 11.5px; color: var(--text-faint); }
.contact-detail .cd-actions { display: flex; gap: 10px; }

/* ---------- Topbar buttons ---------- */
.btn-primary {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(124,108,255,.28);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), filter var(--fast) var(--ease);
}
.btn-primary svg { width: 15px; height: 15px; }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.08); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--accent-dim); }
.btn-danger {
  background: var(--danger);
  border: none; color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: filter var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn-danger:hover { filter: brightness(1.08); transform: translateY(-1px); }

.bell-wrapper { position: relative; }
#bell-btn { position: relative; }
.badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--danger);
  border-radius: 10px;
  padding: 1px 5px;
  font-size: 10px; font-weight: 700;
  min-width: 15px; text-align: center;
  line-height: 1.4;
}
.hidden { display: none !important; }

.notif-panel {
  position: absolute;
  right: 0;
  top: 42px;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  z-index: 30;
  padding: 6px;
  box-shadow: 0 20px 44px rgba(0,0,0,.4);
  animation: popIn var(--normal) var(--ease);
}
.notif-item { padding: 10px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: background var(--fast); }
.notif-item:hover { background: var(--surface-hover); }
.notif-item .n-account { color: var(--accent-2); font-size: 11px; margin-bottom: 2px; font-weight: 600; }
.notif-item .n-subject { font-weight: 600; }
.notif-item .n-from { color: var(--text-muted); font-size: 12px; }
.notif-empty { padding: 20px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8,8,14,.62);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn var(--fast) var(--ease);
  padding: 16px;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  animation: popIn var(--normal) var(--ease);
  box-shadow: 0 30px 70px rgba(0,0,0,.5);
}
.modal-content.modal-sm { width: 380px; }
.modal-content.modal-lg { width: 820px; display: flex; flex-direction: column; min-height: 0; max-height: 90vh; }
.modal-content h2 { font-size: 17px; margin-bottom: 14px; }
.modal-content label { display: block; margin-bottom: 12px; font-size: 12.5px; color: var(--text-muted); }
.modal-content input[type=text],
.modal-content input[type=email],
.modal-content input[type=password],
.modal-content input[type=file],
.modal-content select,
.modal-content textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--fast) var(--ease);
}
.modal-content input:focus, .modal-content select:focus, .modal-content textarea:focus {
  border-color: var(--accent);
}
.modal-content .hint { font-size: 12px; color: var(--text-muted); margin: -2px 0 12px; line-height: 1.5; }
.modal-content .hint.error { color: var(--danger); }
.sync-btn { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.inline-form { margin-bottom: 4px; }
.inline-label { display: block; margin-bottom: 4px; font-size: 12.5px; }
.inline-input-row { display: flex; gap: 8px; margin-top: 4px; }
.inline-input-row input { flex: 1; margin-top: 0; }
.inline-input-row button { flex: none; padding: 8px 12px; font-size: 12.5px; white-space: nowrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-sep { border: none; border-top: 1px solid var(--border); margin: 18px 0 16px; }

/* ---------- Éditeur riche (compose + signature) ---------- */
.rte-toolbar {
  display: flex; gap: 4px; margin: 5px 0 0;
  padding: 4px; border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--surface-2);
}
.rte-toolbar button {
  width: 28px; height: 28px; padding: 0; font-size: 13px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer;
}
.rte-toolbar button:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.rte-editor {
  min-height: 160px; max-height: 340px; overflow-y: auto;
  padding: 10px 12px; margin-top: 0;
  border: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 13px; line-height: 1.55;
  outline: none;
}
.rte-editor:focus { border-color: var(--accent); }
.rte-editor img { max-width: 100%; border-radius: 4px; }
#signature-editor { min-height: 90px; max-height: 220px; }
.mail-signature { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
.rte-toolbar button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.rte-source {
  width: 100%; resize: vertical; font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px; white-space: pre; box-sizing: border-box;
}

/* ---------- Autocomplétion des contacts (champ "À") ---------- */
.to-field { position: relative; }
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  z-index: 40; max-height: 260px; overflow-y: auto;
  box-shadow: 0 20px 44px rgba(0,0,0,.4); padding: 4px;
}
.autocomplete-item {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 10px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
}
.autocomplete-item:hover, .autocomplete-item.active { background: var(--surface-hover); }
.autocomplete-item .ac-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.autocomplete-item .ac-email { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed; right: 18px; bottom: 18px; z-index: 80;
  display: flex; flex-direction: column-reverse; gap: 8px;
  max-width: 320px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 14px 34px rgba(0,0,0,.4);
  animation: toastIn var(--normal) var(--ease);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.leaving { animation: toastOut var(--fast) var(--ease) forwards; }

/* ---------- Keyframes ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Écran de préchargement ---------- */
#boot-loader {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background:
    radial-gradient(900px 600px at 20% 0%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 600px at 100% 100%, var(--accent-2-soft), transparent 55%),
    var(--bg);
  transition: opacity .45s var(--ease), visibility .45s var(--ease);
}
#boot-loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-mark {
  width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(124,108,255,.25);
  animation: bootPulse 1.8s var(--ease) infinite;
}
.boot-mark svg, .boot-mark img { width: 28px; height: 28px; object-fit: contain; }
@keyframes bootPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 12px 32px rgba(124,108,255,.25); }
  50% { transform: scale(1.06); box-shadow: 0 16px 40px rgba(124,108,255,.4); }
}
.boot-title { font-family: "Sora", sans-serif; font-weight: 700; font-size: 17px; letter-spacing: .01em; }
.boot-status { font-size: 12.5px; color: var(--text-muted); min-height: 16px; transition: opacity var(--fast) var(--ease); }
.boot-bar {
  width: 200px; height: 5px; border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border-soft);
}
.boot-bar-fill {
  height: 100%; width: 4%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width .4s var(--ease);
}

/* ---------- Bascule de thème ---------- */
.theme-toggle svg { width: 16px; height: 16px; transition: opacity var(--fast) var(--ease), transform var(--normal) var(--ease); }
.theme-toggle:hover svg { transform: rotate(-14deg); }

/* ---------- Mobile tabbar (caché en desktop) ---------- */
#mobile-tabbar { display: none; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1180px) {
  :root { --side-w: 232px; --list-w: 320px; }
}

@media (max-width: 900px) {
  :root { --topbar-h: 54px; --tabbar-h: 60px; }

  #rail { display: none; }

  #app {
    grid-template-columns: 100%;
    grid-template-rows: 100%;
  }
  #app > * { grid-column: 1; grid-row: 1; }

  #side-panel, #list-panel, #detail-panel {
    border-right: none;
    transform: translateX(100%);
    transition: transform var(--normal) var(--ease);
    z-index: 1;
  }
  #app[data-view="side"] #side-panel,
  #app[data-view="list"] #list-panel,
  #app[data-view="detail"] #detail-panel {
    transform: translateX(0);
    z-index: 2;
  }
  #app[data-view="side"] #side-panel { transform: translateX(0); }

  #topbar { padding-bottom: env(safe-area-inset-top, 0); }

  #mobile-tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-soft);
  }
  .tab-btn {
    flex: 1; border: none; background: transparent; color: var(--text-faint);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 10.5px; cursor: pointer;
  }
  .tab-btn svg { width: 20px; height: 20px; }
  .tab-btn.active { color: var(--accent); }

  body { padding-bottom: 0; }
  #app { padding-bottom: var(--tabbar-h); }

  .topbar-actions #compose-btn span { display: none; }
  .topbar-actions #compose-btn { padding: 9px 11px; }
}
/* =========================================================================
   Portail de connexion (auth-gate)
   Recouvre toute l'app tant qu'aucune session valide n'est présente.
   Réutilise les tokens de design existants (modal / btn-primary / hint).
   ========================================================================= */
#auth-gate {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 600px at 20% 0%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 600px at 100% 100%, var(--accent-2-soft), transparent 55%),
    var(--bg);
  transition: opacity .3s var(--ease), visibility .3s var(--ease);
}
#auth-gate.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
#auth-bg-mesh {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(700px 500px at 8% -6%, var(--accent-soft), transparent 60%),
    radial-gradient(600px 520px at 106% 18%, var(--accent-2-soft), transparent 55%);
  background-size: 130% 130%;
  animation: meshDrift 26s ease-in-out infinite alternate;
}
.auth-card {
  position: relative; z-index: 1;
  width: 360px; max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  padding: 32px 28px 26px;
  animation: popIn .25s var(--ease);
}
.auth-brand {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 22px;
}
.auth-brand img { width: 40px; height: 40px; object-fit: contain; }
.auth-brand-title { font-family: "Sora", sans-serif; font-weight: 700; font-size: 18px; letter-spacing: .01em; }
.auth-form label { display: block; margin-bottom: 12px; font-size: 12.5px; color: var(--text-muted); }
.auth-form input[type=text],
.auth-form input[type=email],
.auth-form input[type=password] {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.auth-form input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-submit { width: 100%; justify-content: center; margin-top: 4px; }
.auth-links {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; font-size: 12.5px;
}
.auth-links a { color: var(--accent); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
#auth-verify-panel .auth-links, #auth-forgot-form .auth-links, #auth-reset-form .auth-links, #auth-register-form .auth-links {
  justify-content: center;
}