/* ==========================================================================
   iamail — système visuel
   Direction : poste de triage clinique. Calme, fiable, précis.
   ========================================================================== */

:root {
  /* Palette */
  --ink:        #10241F;   /* texte principal — pin profond */
  --ink-soft:   #2C4640;
  --muted:      #5C7169;   /* texte secondaire — sauge */
  --bg:         #F5F7F4;   /* fond appli — vert-blanc brumeux */
  --surface:    #FFFFFF;   /* cartes */
  --surface-2:  #F0F4F1;   /* zones creuses */
  --brand:      #0F7A5F;   /* émeraude « soin » */
  --brand-ink:  #0A5744;
  --brand-wash: #E7F1EC;   /* fond léger émeraude */
  --accent:     #E4952B;   /* ambre — signal « à valider » */
  --accent-wash:#FBEFD9;
  --danger:     #C2451E;
  --danger-wash:#FBE7DF;
  --line:       #E1E9E4;
  --line-strong:#CFDBD4;

  /* Rayons & ombres */
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16,36,31,.05);
  --shadow-md: 0 4px 16px -6px rgba(16,36,31,.14);
  --shadow-lg: 0 18px 48px -20px rgba(16,36,31,.28);

  /* Typo */
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

  --sidebar-w: 244px;
}

/* --- Reset léger --- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15;
  letter-spacing: -.01em; margin: 0; color: var(--ink); }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
a { color: var(--brand-ink); }
img { max-width: 100%; }

.eyebrow {
  font-family: var(--font-mono); font-size: .7rem; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ==========================================================================
   App shell : sidebar + contenu
   ========================================================================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--ink); color: #C7D6CF;
  display: flex; flex-direction: column; gap: .3rem;
  padding: 1.2rem .8rem; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: .55rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.3rem;
  color: #fff; padding: .3rem .5rem 1.2rem;
}
.sidebar .brand .dot {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 15px;
}
.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .7rem; border-radius: var(--r-sm);
  color: #B4C7BF; text-decoration: none; font-weight: 500; font-size: .92rem;
  transition: background .15s, color .15s;
}
.nav-link .ic { width: 18px; text-align: center; opacity: .9; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-link .count {
  margin-left: auto; font-family: var(--font-mono); font-size: .72rem;
  background: var(--accent); color: #3a2600; padding: .05rem .4rem; border-radius: var(--r-pill);
}
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: .7rem .6rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .who .name { color: #fff; font-weight: 600; font-size: .9rem; }
.sidebar .who a { color: #9DB3AB; font-size: .82rem; text-decoration: none; }
.sidebar .who a:hover { color: #fff; }

.content { flex: 1; min-width: 0; }
.page { max-width: 1120px; margin: 0 auto; padding: 2rem 2rem 4rem; }
.page-head { margin-bottom: 1.6rem; }
.page-head h1 { margin-top: .3rem; }
.page-head .lead { color: var(--muted); max-width: 60ch; }

/* Barre mobile (masquée en desktop) */
.topbar { display: none; }

/* ==========================================================================
   Cartes & primitives
   ========================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.3rem; box-shadow: var(--shadow-sm);
  margin-bottom: 1.1rem;
}
.card > h2 { margin-bottom: .2rem; }
.card > h2 + .muted { margin-bottom: 1rem; display: block; }
.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: .8rem; }
.flex { display: flex; gap: .8rem; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.flex.between { justify-content: space-between; }
.spread { margin-left: auto; }

/* Chips / tags */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .03em;
  padding: .18rem .5rem; border-radius: var(--r-pill);
  background: var(--brand-wash); color: var(--brand-ink);
}
.chip.amber { background: var(--accent-wash); color: #92580b; }
.chip.grey  { background: var(--surface-2); color: var(--muted); }
.chip.line  { background: transparent; border: 1px solid var(--line-strong); color: var(--muted); }

.dot-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-status.wait { background: var(--accent); }
.dot-status.sent { background: var(--brand); }
.dot-status.rej  { background: var(--line-strong); }
.dot-status.err  { background: var(--danger); }

/* ==========================================================================
   Boutons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font-family: var(--font-body); font-weight: 600; font-size: .92rem;
  padding: .6rem 1.05rem; border-radius: var(--r-sm); border: 1px solid transparent;
  background: var(--brand); color: #fff; cursor: pointer; text-decoration: none;
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--brand-ink); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--surface); color: var(--ink-soft); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger-wash); }
.btn.danger:hover { background: var(--danger-wash); }
.btn.sm { padding: .38rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }

/* ==========================================================================
   Formulaires
   ========================================================================== */
label { display: block; font-size: .82rem; font-weight: 500; color: var(--ink-soft);
  margin: 0 0 .3rem; }
.field { margin-bottom: .9rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  padding: .6rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #9AACA4; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-wash);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 170px; margin-bottom: 0; }
.row + .row { margin-top: .9rem; }
.hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; }

details.adder { margin-top: 1rem; border-top: 1px dashed var(--line); padding-top: .9rem; }
details.adder > summary {
  cursor: pointer; font-weight: 600; color: var(--brand-ink); list-style: none;
  display: inline-flex; align-items: center; gap: .4rem;
}
details.adder > summary::-webkit-details-marker { display: none; }
details.adder > summary::before { content: "+"; font-family: var(--font-mono); }
details.adder[open] > summary::before { content: "−"; }
details.adder > form { margin-top: 1rem; }

/* ==========================================================================
   Flash
   ========================================================================== */
.flash { padding: .7rem 1rem; border-radius: var(--r-sm); margin-bottom: .8rem;
  font-size: .9rem; display: flex; gap: .5rem; align-items: center; }
.flash.success { background: var(--brand-wash); color: var(--brand-ink); }
.flash.error { background: var(--danger-wash); color: #8a2f14; }

/* ==========================================================================
   Dashboard
   ========================================================================== */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 1.4rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat .num { font-family: var(--font-display); font-weight: 700; font-size: 2.3rem;
  line-height: 1; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: .85rem; margin-top: .35rem; }
.stat.feature { background: var(--ink); color: #fff; }
.stat.feature .lbl { color: #A9C0B8; }
.stat.feature .num { color: #fff; }
.stat.feature::after {
  content: ""; position: absolute; right: -30px; bottom: -30px;
  width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle, rgba(15,122,95,.55), transparent 70%);
}
.stat .num.amber { color: var(--accent); }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: .7rem; align-items: baseline;
  padding: .55rem 0; border-bottom: 1px solid var(--line); }
.activity li:last-child { border-bottom: 0; }
.activity .ts { font-family: var(--font-mono); font-size: .74rem; color: var(--muted);
  flex-shrink: 0; width: 92px; }

/* ==========================================================================
   Triage (boîte à valider) — élément signature
   ========================================================================== */
.triage { display: grid; gap: 1.3rem; }
.slip {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); overflow: hidden;
}
.slip-head {
  display: flex; align-items: flex-start; gap: .8rem; flex-wrap: wrap;
  padding: 1rem 1.3rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.slip-head .subject { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.slip-head .from { color: var(--muted); font-size: .85rem; }
.slip-head .meta { margin-left: auto; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.slip-body { display: grid; grid-template-columns: 1fr 1fr; }
.slip-col { padding: 1.1rem 1.3rem; }
.slip-col.received { background: var(--surface-2); border-right: 1px solid var(--line);
  border-left: 3px solid var(--line-strong); }
.slip-col .col-label {
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: .5rem; display: block;
}
.mail-text { white-space: pre-wrap; font-size: .92rem; color: var(--ink-soft); line-height: 1.55; }
.slip-col.reply textarea { min-height: 170px; background: var(--surface); }

.rdv-box { margin-top: .9rem; background: var(--brand-wash); border-radius: var(--r-md);
  padding: .8rem .9rem; }
.rdv-box .rdv-title { font-weight: 600; color: var(--brand-ink); display: flex; gap: .4rem; align-items: center; }

.slip-actions { display: flex; gap: .7rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line);
  background: var(--surface); }

.confidence { display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--font-mono); font-size: .74rem; color: var(--muted); }
.confidence .bar { width: 46px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.confidence .bar > i { display: block; height: 100%; background: var(--brand); }

/* ==========================================================================
   Tables (historique, listes config)
   ========================================================================== */
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th { text-align: left; font-family: var(--font-mono); font-weight: 500;
  font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  padding: .5rem .5rem; border-bottom: 1px solid var(--line); }
table.tbl td { padding: .65rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }

/* Liste de règles (catégories) */
.rule { display: flex; gap: .9rem; padding: .9rem 0; border-bottom: 1px solid var(--line); }
.rule:last-of-type { border-bottom: 0; }
.rule .rule-ic { width: 38px; height: 38px; flex-shrink: 0; border-radius: 10px;
  display: grid; place-items: center; background: var(--brand-wash); color: var(--brand-ink); font-size: 18px; }
.rule .rule-main { flex: 1; min-width: 0; }
.rule .rule-name { font-weight: 600; }
.rule .rule-consigne { color: var(--muted); font-size: .88rem; margin-top: .1rem; }

/* Empty states */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: .4rem; }

/* ==========================================================================
   Auth (login / signup) — écran partagé
   ========================================================================== */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-aside { background: var(--ink); color: #E7F1EC; padding: 3rem;
  display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; right: -120px; top: 40%;
  width: 380px; height: 380px; border-radius: 50%;
  background: radial-gradient(circle, rgba(15,122,95,.5), transparent 70%); }
.auth-aside .brand { font-family: var(--font-display); font-weight: 700; font-size: 1.5rem;
  color: #fff; display: flex; gap: .55rem; align-items: center; }
.auth-aside .pitch { font-family: var(--font-display); font-size: 2rem; font-weight: 600;
  line-height: 1.2; max-width: 15ch; letter-spacing: -.01em; position: relative; z-index: 1; }
.auth-aside .points { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; position: relative; z-index: 1; }
.auth-aside .points li { display: flex; gap: .55rem; align-items: flex-start; color: #B7CEC5; font-size: .95rem; }
.auth-aside .points .tick { color: var(--brand); }
.auth-main { display: grid; place-items: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin-bottom: .3rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between;
    padding: .8rem 1rem; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
  .topbar .brand { font-family: var(--font-display); font-weight: 700; color: #fff;
    display: flex; gap: .5rem; align-items: center; }
  .topbar nav a { color: #C7D6CF; text-decoration: none; margin-left: .9rem; font-size: .9rem; }
  .page { padding: 1.2rem 1rem 3rem; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .slip-body { grid-template-columns: 1fr; }
  .slip-col.received { border-right: 0; border-bottom: 1px solid var(--line); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
