/* =========================================================
   MMI Mail — feuille de style
   ========================================================= */

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #5d6673;
  --line: #e3e7ee;
  --accent: #2155d6;
  --accent-hover: #1a46b5;
  --accent-soft: #dce6fc;
  --hover: #eef2f9;
  --read-row: #f7f9fc;
  --danger: #b3261e;
  --danger-soft: #fce8e6;
  --client: #0f7b6c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .10);
  --topbar-h: 64px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Boutons ---------- */

.btn-primary, .btn-outline, .btn-text {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 20px; border-radius: 999px; border: 0;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, box-shadow .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 1px 3px rgba(33, 85, 214, .35); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-outline { background: var(--panel); border: 1px solid #c4cad4; color: var(--text); }
.btn-outline:hover { background: var(--hover); }
.btn-text { background: transparent; color: var(--accent); padding: 0 12px; }
.btn-text:hover { background: var(--accent-soft); }
.btn-block { width: 100%; height: 44px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: rgba(60, 64, 67, .08); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 18px; height: 18px; }
.icon { display: inline-flex; }

/* ---------- Avatars ---------- */

.avatar {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 13px; font-weight: 700; letter-spacing: .02em; color: #fff;
}
.avatar-me { background: #7a4cc2; }
.avatar-client { background: var(--client); }

/* =========================================================
   Page de connexion
   ========================================================= */

.login-page {
  display: grid; place-items: center; min-height: 100%; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dfe8fd 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #e2f2ee 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 420px; padding: 40px 36px 28px;
  background: var(--panel); border-radius: 24px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 28px 0 4px; font-size: 26px; font-weight: 600; }
.login-sub { margin: 0 0 24px; color: var(--muted); }
.login-form { display: grid; gap: 16px; }
.login-form .btn-block { margin-top: 8px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  height: 46px; padding: 0 14px; border: 1px solid #c4cad4; border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.alert {
  margin-bottom: 16px; padding: 10px 14px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger); font-weight: 500;
}
.login-foot { margin: 28px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- Logo ---------- */

.brand {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none;
  font-size: 21px; font-weight: 600; color: #3c4350; letter-spacing: -.01em;
}
.brand-logo { width: 36px; height: 36px; }
.brand-lg { font-size: 24px; }
.brand-lg .brand-logo { width: 42px; height: 42px; }

/* =========================================================
   Messagerie
   ========================================================= */

.app { overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 16px 0 8px;
}
.topbar-spacer, .toolbar-spacer { flex: 1; }
.menu-toggle { margin-right: 4px; }

.account { display: flex; align-items: center; gap: 12px; }
.account-info { display: grid; text-align: right; line-height: 1.25; }
.account-info strong { font-weight: 600; }
.account-info span { color: var(--muted); font-size: 12px; }
.account form { margin: 0; }

.layout { display: flex; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }

/* ---------- Barre latérale ---------- */

.sidebar { width: 256px; flex: none; padding: 8px 12px 16px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.compose-btn {
  display: inline-flex; align-items: center; gap: 12px; align-self: flex-start;
  height: 56px; padding: 0 24px 0 18px; margin: 0 0 14px;
  border: 0; border-radius: 16px; background: #c9dafd; color: #0f2a6b;
  font-weight: 600; cursor: pointer; box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
  transition: box-shadow .15s, background-color .15s;
}
.compose-btn:hover { box-shadow: 0 2px 8px rgba(16, 24, 40, .18); background: #bfd2fc; }

.nav-item {
  display: flex; align-items: center; gap: 16px;
  height: 36px; padding: 0 14px 0 18px; border-radius: 0 999px 999px 0;
  text-decoration: none; color: var(--text);
}
.nav-item svg { color: var(--muted); }
.nav-item:hover { background: rgba(60, 64, 67, .08); }
.nav-item.active { background: var(--accent-soft); font-weight: 700; color: #0f2a6b; }
.nav-item.active svg { color: #0f2a6b; }
.nav-label { flex: 1; }
.badge { font-size: 12px; font-weight: 700; }

.contact-card { margin: 24px 0 0 6px; padding: 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.contact-title { margin: 0 0 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.contact { display: flex; align-items: center; gap: 10px; min-width: 0; }
.contact div:last-child { display: grid; min-width: 0; line-height: 1.3; }
.contact span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-backdrop { display: none; }

/* ---------- Zone principale ---------- */

.content {
  flex: 1; min-width: 0; margin: 0 16px 16px 0;
  background: var(--panel); border-radius: var(--radius);
  overflow-y: auto; outline: none;
}

.toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px 8px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar-title { margin: 0; font-size: 18px; font-weight: 600; }
.toolbar-count { color: var(--muted); font-size: 12px; margin-right: 4px; }

.loading { padding: 48px 24px; text-align: center; color: var(--muted); }

.empty { display: grid; justify-items: center; gap: 4px; padding: 72px 24px; text-align: center; color: var(--muted); }
.empty .icon svg { width: 56px; height: 56px; color: #c4cad4; margin-bottom: 12px; }
.empty p { margin: 0; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.empty .btn-primary { margin-top: 16px; }
.empty.error { color: var(--danger); }

/* ---------- Liste ---------- */

.row {
  display: grid; grid-template-columns: 200px minmax(0, 1fr) auto; align-items: center; gap: 16px;
  min-height: 44px; padding: 0 20px;
  background: var(--read-row); border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--text);
}
.row:hover { box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 3px rgba(60, 64, 67, .2); position: relative; z-index: 1; }
.row.unread { background: var(--panel); }
.row.unread .row-from, .row.unread .row-subject, .row.unread .row-date { font-weight: 700; }
.row-from { display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-count { color: var(--muted); font-size: 12px; font-weight: 400; }
.row-main { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-snippet { color: var(--muted); }
.row-snippet::before { content: " — "; }
.row-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row.unread .row-date { color: var(--text); }

/* ---------- Conversation ---------- */

.thread { padding: 8px 24px 40px 24px; max-width: 980px; }
.thread-subject { margin: 12px 0 18px 52px; font-size: 22px; font-weight: 400; overflow-wrap: anywhere; }

.messages { display: grid; }
.msg { border-bottom: 1px solid var(--line); }
.msg-head {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: start;
  padding: 14px 0 10px; cursor: pointer;
}
.msg-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.msg-meta { min-width: 0; }
.msg-from { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.msg-from strong { font-weight: 600; }
.msg-email, .msg-to, .msg-snippet, .msg-date { color: var(--muted); font-size: 12px; }
.msg-snippet { font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.msg-date { white-space: nowrap; padding-top: 2px; }
.msg-body {
  padding: 0 0 20px 52px; white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 14.5px; line-height: 1.6;
}
.msg:not(.open) .msg-body, .msg:not(.open) .msg-to { display: none; }
.msg.open .msg-snippet { display: none; }
.msg:not(.open) .msg-head:hover { background: var(--read-row); }

.reply { padding: 20px 0 0 52px; }
.reply-form { border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; background: var(--panel); }
.reply-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.reply-head .avatar { width: 28px; height: 28px; font-size: 11px; }
.reply-text {
  display: block; width: 100%; min-height: 180px; padding: 14px 16px;
  border: 0; resize: vertical; outline: none; line-height: 1.55;
}
.reply-actions { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }

.recipient-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 10px; border-radius: 999px; background: var(--hover); font-size: 13px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.hint { color: var(--muted); font-size: 12px; }

/* ---------- Fenêtre de rédaction ---------- */

.compose {
  position: fixed; right: 24px; bottom: 0; z-index: 30;
  width: 540px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column;
  background: var(--panel); border-radius: 12px 12px 0 0;
  box-shadow: 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12), 0 5px 5px -3px rgba(0, 0, 0, .2);
}
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 42px; padding: 0 8px 0 16px; border-radius: 12px 12px 0 0;
  background: #f2f6fc; font-weight: 600; cursor: pointer; user-select: none;
}
.compose-head-actions { display: flex; gap: 2px; }
.compose.minimized { width: 300px; }
.compose.minimized .compose-body { display: none; }

.compose-body { display: flex; flex-direction: column; height: min(520px, calc(100dvh - 120px)); }
.compose-field {
  display: flex; align-items: center; gap: 8px; min-height: 40px; margin: 0 16px;
  border-bottom: 1px solid var(--line);
}
.compose-label { color: var(--muted); }
.compose-field input { flex: 1; height: 38px; border: 0; outline: none; background: transparent; }
.compose-body textarea {
  flex: 1; min-height: 0; padding: 12px 16px; border: 0; outline: none; resize: none; line-height: 1.55;
}
.compose-actions { display: flex; align-items: center; gap: 12px; padding: 10px 12px 14px 16px; }

/* ---------- Notification ---------- */

.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 40;
  max-width: calc(100vw - 48px); padding: 12px 18px; border-radius: 8px;
  background: #303338; color: #fff; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

/* =========================================================
   Écrans moyens et mobiles
   ========================================================= */

@media (max-width: 1000px) {
  .row { grid-template-columns: 150px minmax(0, 1fr) auto; }
  .account-info { display: none; }
}

@media (min-width: 761px) {
  .menu-toggle { display: none; }
}

@media (max-width: 760px) {
  .topbar { padding-right: 12px; }
  .brand span { display: none; }
  .account .avatar { display: none; }

  .sidebar {
    position: fixed; z-index: 20; top: 0; left: 0; bottom: 0; width: 280px;
    padding-top: 16px; background: var(--bg); box-shadow: var(--shadow);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .3); }

  .content { margin: 0; border-radius: 16px 16px 0 0; }

  .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "from date" "main main";
    gap: 2px 12px; padding: 10px 16px;
  }
  .row-from { grid-area: from; }
  .row-date { grid-area: date; }
  .row-main { grid-area: main; white-space: normal; display: grid; }
  .row-subject, .row-snippet { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .row-snippet::before { content: none; }

  .thread { padding: 4px 16px 32px; }
  .thread-subject { margin-left: 0; font-size: 20px; }
  .msg-head { grid-template-columns: 40px minmax(0, 1fr); }
  .msg-date { grid-column: 2; padding-top: 0; white-space: normal; }
  .msg-body, .reply { padding-left: 0; }
  .reply-actions .hint { display: none; }

  .compose { inset: 0; width: auto; max-width: none; border-radius: 0; }
  .compose-head { border-radius: 0; }
  .compose-body { height: auto; flex: 1; }
  .compose.minimized { inset: auto 0 0 0; width: auto; }
  .compose .hint { display: none; }

  .toast { left: 16px; bottom: 16px; }
}
