/* Courrier : accent olive, puis la boîte (liste et lecture), la fenêtre d'écriture, les réglages.
   Tout passe par les jetons du socle ; seul le cadre d'un message reste blanc, comme le papier
   pour lequel les courriers sont mis en page. */
:root {
  --courrier: #66761F; --courrier-soft: #E8ECD2; --courrier-deep: #66761F;
  --acc: var(--courrier); --acc-soft: var(--courrier-soft); --acc-deep: var(--courrier-deep);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --courrier: #B5C46A; --courrier-soft: #2E3418; --courrier-deep: #66761F; }
}
:root[data-theme="dark"] { --courrier: #B5C46A; --courrier-soft: #2E3418; --courrier-deep: #66761F; }

/* ── Dossiers (barre latérale, feuille du téléphone, choix d'un dossier) ───── */
.cr-nouveau { width: 100%; flex: none; }
.cr-dossiers { display: flex; flex-direction: column; gap: 12px; }
.cr-compte { display: flex; flex-direction: column; gap: 1px; }
.cr-compte-nom { display: flex; align-items: center; gap: 6px; padding: 2px 12px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cr-compte-nom span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-alerte { display: inline-flex; color: var(--late); }
.cr-dossier { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-size: 14.5px; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; }
.cr-dossier span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-dossier b { font-size: 12px; font-weight: 600; color: var(--text); }
.cr-dossier:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.cr-dossier.on { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.cr-dossier.on b { color: var(--acc); }
.cr-choix { max-height: 60vh; overflow-y: auto; }
.cr-vide { flex: 1; }
.cr-tel { display: none; }

/* ── La boîte : deux volets ───────────────────────────────────────────────── */
.cr { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.cr-liste { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.cr-tete { display: flex; align-items: center; gap: 6px; padding: 14px 10px 8px 18px; }
.cr-titre { flex: 1; min-width: 0; }
.cr-titre h3 { font-size: 20px; }
.cr-titre h3, .cr-titre div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-cherche { position: relative; display: block; margin: 0 14px 8px; }
.cr-cherche .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.cr-cherche .input { min-height: 40px; padding-left: 38px; border-color: transparent; border-radius: var(--pill); background: var(--panel-2); }
.cr-filtres { display: flex; gap: 6px; padding: 0 14px 10px; }
.cr-filtres .chip { cursor: pointer; }
.cr-liste.choix .cr-filtres { display: none; }
.cr-selection { display: flex; align-items: center; gap: 2px; margin: 0 8px 8px; padding: 3px 6px; border-radius: var(--radius); background: var(--acc-soft); color: var(--acc); font-size: 13.5px; }
.cr-selection[hidden] { display: none; }
.cr-selection .icon-btn { color: var(--acc); }
.cr-lignes { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 16px; }
.cr-ligne { position: relative; display: flex; align-items: flex-start; gap: 10px; margin-top: 1px; padding: 10px 4px 10px 12px; border-radius: var(--radius); cursor: pointer; }
.cr-ligne:hover { background: var(--panel-2); }
.cr-ligne.on, .cr-ligne.sel { background: var(--acc-soft); }
.cr-ligne.non-lu::before { content: ''; position: absolute; left: 3px; top: 25px; width: 6px; height: 6px; border-radius: 50%; background: var(--acc); }
.cr-coche, .cr-avatar { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 14.5px; }
.cr-coche { cursor: pointer; }
.cr-ligne:hover .cr-coche, .cr-ligne.on .cr-coche { background: var(--panel); }
.cr-coche .ico { display: none; }
.cr-ligne.sel .cr-coche { background: var(--acc-deep); color: #fff; }
.cr-ligne.sel .cr-coche span { display: none; }
.cr-ligne.sel .cr-coche .ico { display: block; }
.cr-corps { flex: 1; min-width: 0; display: grid; gap: 1px; }
.cr-l1 { display: flex; align-items: baseline; gap: 6px; }
.cr-qui { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; color: var(--text); }
.cr-n { flex: none; font-size: 12px; color: var(--muted); }
.cr-date { flex: none; margin-left: auto; font-size: 12px; color: var(--muted); }
.cr-objet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--text); }
.cr-l3 { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.cr-extrait { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.cr-extrait .pill { height: 19px; padding: 0 7px; font-size: 11.5px; }
.cr-ligne.non-lu .cr-qui, .cr-ligne.non-lu .cr-objet { font-weight: 700; }
.cr-ligne.non-lu .cr-date { color: var(--acc); font-weight: 600; }
.cr-etoile { display: grid; place-items: center; width: 34px; height: 34px; flex: none; margin-top: 1px; border: 0; border-radius: 50%; background: transparent; color: color-mix(in srgb, var(--muted) 45%, transparent); cursor: pointer; }
.cr-etoile:hover { color: var(--muted); }
.cr-etoile.on { color: var(--warn); }
.cr-etoile.on .ico, .cr-barre .icon-btn.on .ico { fill: currentColor; }
.cr-plus { display: flex; margin: 12px auto 0; }
.cr-borne { margin: 12px 0 0; text-align: center; }
.cr-note { margin: 4px 4px 8px; padding: 10px 12px; }
.tourne .ico { animation: cr-tour 1s linear infinite; }
@keyframes cr-tour { to { transform: rotate(360deg); } }

/* ── Lecture d'une conversation ───────────────────────────────────────────── */
.cr-lecture { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); }
.cr-rien { margin: auto; }
.cr-barre { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 8px 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
.cr-fil { width: 100%; max-width: 940px; margin: 0 auto; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 10px; }
.cr-sujet { margin-bottom: 6px; font-size: 22px; overflow-wrap: anywhere; }
.cr-msg { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); overflow: hidden; }
.cr-msg-tete { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.cr-avatar { background: var(--acc-soft); color: var(--acc); }
.cr-msg-qui { flex: 1; min-width: 0; }
.cr-msg-de, .cr-msg-sous { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-msg.ouvert .cr-msg-sous { white-space: normal; overflow-wrap: anywhere; }
.cr-msg.non-lu .cr-msg-de b { color: var(--acc); }
.cr-msg-droite { display: flex; align-items: center; gap: 6px; flex: none; color: var(--muted); }
.cr-msg-corps { display: none; border-top: 1px solid var(--line); }
.cr-msg.ouvert .cr-msg-corps { display: block; }
.cr-charge { padding: 14px; }
.cr-cadre { display: block; width: 100%; height: 120px; border: 0; background: #fff; }
.cr-images { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: var(--panel-2); color: var(--muted); }
.cr-images span { flex: 1; }
.cr-pieces { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.cr-piece { max-width: 100%; text-decoration: none; }
.cr-piece:hover { text-decoration: none; }
a.cr-piece:hover { border-color: var(--acc); color: var(--acc); }
.cr-piece span { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.cr-piece i { font-style: normal; font-size: 12px; }
.cr-piece button { display: grid; place-items: center; width: 22px; height: 22px; margin-right: -6px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; }
.cr-piece button:hover { background: var(--panel-2); color: var(--text); }
.cr-suite { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 6px; }

/* ── Écrire : une fenêtre au-dessus de la boîte ───────────────────────────── */
.cr-ecrire { position: fixed; z-index: 35; right: 24px; bottom: 0; width: min(580px, calc(100vw - 288px)); height: min(640px, calc(100dvh - 32px)); display: flex; flex-direction: column; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; background: var(--panel); box-shadow: var(--shadow-float); }
.cr-ecrire.reduit { width: 320px; height: auto; }
.cr-ecrire.reduit .cr-e-corps, .cr-ecrire.reduit .cr-e-pied { display: none; }
.cr-ecrire.reduit .cr-e-tete { border-bottom: 0; }
.cr-e-tete { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.cr-e-titre { cursor: pointer; white-space: nowrap; }
.cr-e-etat { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-e-corps { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.cr-e-champ { display: flex; align-items: center; gap: 10px; flex: none; min-height: 42px; padding: 0 10px 0 16px; border-bottom: 1px solid var(--line); }
.cr-e-champ[hidden] { display: none; }
.cr-e-champ > span { width: 40px; flex: none; font-size: 13px; color: var(--muted); }
.cr-e-champ input, .cr-e-champ select { flex: 1; min-width: 0; height: 42px; border: 0; outline: none; background: transparent; color: var(--text); font-family: inherit; }
.cr-e-corps textarea { flex: 1; min-height: 180px; padding: 14px 16px; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font-family: inherit; line-height: 1.5; }
.cr-e-contacts { display: grid; flex: none; margin: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.cr-e-contacts[hidden] { display: none; }
.cr-e-contacts button { display: flex; align-items: baseline; gap: 8px; min-height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.cr-e-contacts button:hover, .cr-e-contacts button:focus-visible { background: var(--panel-2); }
.cr-e-contacts span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-e-citer { display: flex; align-items: flex-start; gap: 8px; flex: none; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); cursor: pointer; }
.cr-e-citer input { width: 16px; height: 16px; margin-top: 1px; flex: none; accent-color: var(--acc); }
.cr-e-pieces { display: flex; flex-wrap: wrap; gap: 8px; flex: none; padding: 0 16px; }
.cr-e-pieces:not(:empty) { padding-bottom: 12px; }
.cr-e-pied { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.cr-e-pied label.icon-btn { cursor: pointer; }

/* ── Réglages ─────────────────────────────────────────────────────────────── */
.cr-reglages { max-width: 820px; }
.cr-reglages code { font-size: 12.5px; overflow-wrap: anywhere; }
.cr-r-compte, .cr-r-tour { align-items: center; flex-wrap: wrap; padding: 10px 12px; }
.cr-r-tour { align-items: flex-start; }
.cr-r-qui { flex: 1; min-width: 180px; overflow-wrap: anywhere; }
.cr-r-erreur { color: var(--late); }
.cr-r-annule { color: var(--muted); text-decoration: line-through; }
.cr-r-bascules { display: grid; gap: 16px; }
.cr-r-copie { display: flex; gap: 8px; }
.cr-r-copie .input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.cr-r-four { margin: 10px 0 12px; }
.cr-r-four .chip { cursor: pointer; }
.cr-form { display: grid; gap: 12px; }
.cr-form textarea.input { min-height: 84px; padding: 10px 14px; resize: vertical; }
.cr-form details > summary { padding: 4px 0; color: var(--muted); cursor: pointer; }
.cr-form details > .field { margin-top: 12px; }

/* ── Téléphone : un volet à la fois, la fenêtre d'écriture prend tout l'écran ─ */
@media (max-width: 720px) {
  .cr { display: block; height: calc(100vh - 62px - env(safe-area-inset-bottom)); height: calc(100dvh - 62px - env(safe-area-inset-bottom)); }
  .cr-liste, .cr-lecture { height: 100%; border-right: 0; }
  .cr.lit .cr-liste, .cr:not(.lit) .cr-lecture { display: none; }
  .cr-tel { display: inline-grid; }
  .cr-pc { display: none; }
  .cr-tete { padding: calc(8px + env(safe-area-inset-top)) 8px 8px 8px; }
  .cr-barre { padding: calc(6px + env(safe-area-inset-top)) 8px 6px; }
  .cr-fil { padding: 14px 10px 32px; }
  .cr-sujet { padding: 0 4px; font-size: 20px; }
  .cr-msg.ouvert .cr-msg-tete { flex-wrap: wrap; row-gap: 4px; }
  .cr-msg.ouvert .cr-msg-droite { flex-basis: 100%; padding-left: 48px; }
  .cr-msg.ouvert .cr-msg-droite .small { margin-right: auto; }
  .cr-ecrire { inset: 0; z-index: 46; width: auto; height: auto; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); border: 0; border-radius: 0; }
  /* Envoyer reste en haut : le clavier ne le cache jamais. */
  .cr-e-pied { order: 1; border-top: 0; border-bottom: 1px solid var(--line); }
  .cr-e-corps { order: 2; }
}
