@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --font-serif: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

  /* Sage (sidebar / surfaces sombres) — même esprit que le CRM */
  --sage-950: #0D1A19;
  --sage-900: #1A2E2C;
  --sage-800: #243F3D;
  --sage-700: #2C4E4B;
  --sage-600: #3B6461;
  --sage-500: #4D7E7B;
  --sage-400: #6FA09D;
  --sage-300: #93BAB7;
  --sage-200: #B8D4D2;
  --sage-100: #DFF0EE;
  --sage-50:  #F2F9F8;

  --ink-950: var(--sage-900);
  --ink-900: var(--sage-900);
  --ink-800: rgba(255,255,255,0.06);
  --ink-700: rgba(77,126,123,0.22);
  --ink-line: rgba(255,255,255,0.06);
  --ink-text: #E4F0EE;
  --ink-muted: #A8C5C2;

  /* Papier (canevas / contenu) */
  --paper: #F0F3F5;
  --surface: #ffffff;
  --surface-2: #F6F8FA;
  --border: #DDE3E8;
  --border-soft: #EBF0F3;
  --text: #0F1519;
  --muted: #6B7A86;
  --muted-soft: #9AAAB6;

  /* Accent — vert sage (actions, sceau, focus) */
  --brass: var(--sage-600);
  --brass-dark: var(--sage-800);
  --brass-bg: rgba(59,100,97,0.09);
  --brass-line: var(--sage-200);

  /* Statuts (mêmes teintes que le pipeline du CRM) */
  --vert-txt: #047857;  --vert-bg: #F0FDF4;  --vert-bd: #BBF7D0;
  --ambre-txt: #B45309; --ambre-bg: #FFFBEB; --ambre-bd: #FDE68A;
  --rouge-txt: #B91C1C; --rouge-bg: #FEF2F2; --rouge-bd: #FECACA;

  --radius: 4px;
  --radius-sm: 3px;
  --shadow-card: 0 1px 3px rgba(11,14,15,.08), 0 1px 2px rgba(11,14,15,.06);
  --shadow-pop: 0 8px 24px rgba(11,14,15,.12), 0 2px 8px rgba(11,14,15,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }

/* ── Sceau (signature graphique) ─────────────────────────────────── */
.seal {
  --seal-size: 26px;
  width: var(--seal-size);
  height: var(--seal-size);
  border-radius: var(--radius);
  flex: 0 0 auto;
  position: relative;
  background: var(--sage-600);
  box-shadow: 0 2px 8px rgba(59,100,97,.5), inset 0 1px 0 rgba(255,255,255,.15);
}
.seal::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 2px;
  border: 1px dashed rgba(255,255,255,.5);
}

/* ── Écran de connexion ─────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sage-900);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 34px 30px 30px;
  box-shadow: var(--shadow-pop);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  margin-bottom: 22px;
  color: var(--text);
}
.auth-logo span { color: var(--brass); font-family: var(--font-sans); }
.auth-card h1 { font-family: var(--font-serif); font-weight: 700; font-size: 1.2rem; margin: 0 0 6px; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 0.86rem; margin: 0 0 20px; }

/* ── Structure : sidebar + contenu ──────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex: 0 0 auto;
  background: var(--sage-900);
  color: var(--ink-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255,255,255,.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.brand-text {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0;
  color: #E8F0EF;
  line-height: 1.3;
}
.brand-text .brand-dot { color: var(--sage-400); font-family: var(--font-sans); }
.brand-sub { display: block; font-family: var(--font-sans); font-size: 0.62rem; color: var(--sage-400); text-transform: uppercase; letter-spacing: .1em; margin-top: 2px; font-weight: 500; }

.nav { flex: 1; padding: 14px 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 0.83rem;
  font-weight: 400;
  transition: background .1s, color .1s;
}
.nav-item svg { flex: 0 0 auto; opacity: .9; color: var(--sage-400); transition: color .1s; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #E4F0EE; }
.nav-item:hover svg { color: var(--sage-300); }
.nav-item.actif { background: rgba(77,126,123,.22); color: #E4F0EE; box-shadow: none; position: relative; font-weight: 500; }
.nav-item.actif svg { color: var(--sage-300); }
.nav-item.actif::before {
  content: '';
  position: absolute; left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 2px; height: 14px;
  background: var(--sage-400);
  border-radius: 0 1px 1px 0;
}

.sidebar-foot { padding: 8px; border-top: 1px solid rgba(255,255,255,.05); }
.sidebar-foot .nav-item { color: var(--ink-muted); }
.sidebar-foot .nav-item:hover { color: #fff; background: rgba(185,28,28,.12); }
.sidebar-foot .nav-item:hover svg { color: #FCA5A5; }

.content { flex: 1; min-width: 0; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 36px 60px;
}

h1.titre-page { font-family: var(--font-serif); font-weight: 700; font-size: 1.4rem; margin: 0 0 5px; letter-spacing: -0.01em; }
p.souspage { color: var(--muted); font-size: 0.85rem; margin: 0 0 24px; max-width: 640px; }

/* ── Cartes statistiques (esprit "kpi-card" du CRM) ──────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 15px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--border);
  opacity: .8;
}
.stat-card.accent-brass::before { background: var(--sage-600); }
.stat-card.accent-vert::before { background: var(--vert-txt); }
.stat-card.accent-ambre::before { background: var(--ambre-txt); }
.stat-card.accent-rouge::before { background: var(--rouge-txt); }
.stat-card .valeur { font-family: var(--font-serif); font-size: 1.7rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-card .label { color: var(--muted-soft); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-top: 7px; }

/* ── Panels / cartes ─────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-card);
}

/* ── Formulaires ──────────────────────────────────────────────────── */
label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: 700; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
label .hint { font-weight: 400; color: var(--muted-soft); text-transform: none; letter-spacing: 0; }
input[type=text], input[type=number], input[type=file], input[type=password] {
  width: 100%; padding: 0 12px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.87rem; background: #fff; color: var(--text); font-family: var(--font-sans);
}
input[type=file] { height: auto; padding: 8px 12px; }
select {
  width: 100%; padding: 0 34px 0 12px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.87rem; background-color: #fff; color: var(--text); font-family: var(--font-sans);
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%236B7A86' d='M5 6.5L1.5 3h7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
select:focus, input:focus { outline: none; border-color: var(--sage-600); box-shadow: 0 0 0 2px rgba(59,100,97,0.14); }
button, .btn {
  margin-top: 20px; padding: 0 18px; height: 34px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--sage-600); color: #fff; cursor: pointer; font-size: 0.85rem; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; transition: background .1s, border-color .1s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.1);
}
button:hover, .btn:hover { background: var(--sage-500); }
button:active, .btn:active { background: var(--sage-700); }
.btn-secondaire { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-secondaire:hover { background: var(--surface-2); }
.btn-vert { background: #047857; }
.btn-vert:hover { background: #059669; }
form.inline { display: inline; margin: 0; }

/* ── Messages ─────────────────────────────────────────────────────── */
.erreur {
  margin-top: 16px; padding: 10px 13px; background: var(--rouge-bg);
  border: 1px solid var(--rouge-bd); border-radius: var(--radius); color: var(--rouge-txt); font-size: 0.83rem; font-weight: 500;
}
.succes-box {
  margin-top: 20px; padding: 18px 20px; background: var(--paper); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.86rem;
}
.succes-box h3 {
  margin: 0 0 14px; font-family: var(--font-serif); font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; gap: 9px;
}
.succes-box h3::before {
  content: '';
  width: 16px; height: 16px; border-radius: var(--radius-sm); flex: 0 0 auto;
  background: var(--sage-600);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
}
.champ { margin-top: 13px; }
.champ .cle-label { font-weight: 700; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.code-box {
  display: block; word-break: break-all; background: var(--surface-2); padding: 9px 11px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.76rem; font-family: var(--font-mono); color: #1f2937; cursor: pointer;
  transition: background .2s;
}
.copier-btn {
  border: none; background: none; color: var(--sage-700); font-size: 0.74rem; cursor: pointer; font-weight: 600; padding: 0;
}
.copier-btn:hover { text-decoration: underline; }
.warn { margin-top: 10px; font-size: 0.78rem; color: var(--ambre-txt); }
.pubkey-box {
  margin-bottom: 22px; padding: 13px 16px; background: var(--sage-50); border: 1px solid var(--sage-200);
  border-radius: var(--radius); font-size: 0.83rem; color: var(--sage-800);
}
.pubkey-box strong { color: var(--text); }

/* ── Table ─────────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-card); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 15px; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
th { color: var(--muted); font-weight: 700; font-size: 0.66rem; text-transform: uppercase; letter-spacing: .07em; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--sage-50); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px 2px 7px; border-radius: var(--radius-sm); font-size: 0.72rem; font-weight: 600; border: 1px solid transparent;
  letter-spacing: 0.01em;
}
.badge::before { content: ''; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.badge-vert { color: var(--vert-txt); background: var(--vert-bg); border-color: var(--vert-bd); }
.badge-orange { color: var(--ambre-txt); background: var(--ambre-bg); border-color: var(--ambre-bd); }
.badge-rouge { color: var(--rouge-txt); background: var(--rouge-bg); border-color: var(--rouge-bd); }

.lien-action { color: var(--sage-700); font-size: 0.78rem; text-decoration: none; margin-right: 14px; font-weight: 600; }
.lien-action:hover { text-decoration: underline; }
.id-mono { font-family: var(--font-mono); font-size: 0.76rem; color: var(--muted); }
.vide { color: var(--muted-soft); padding: 52px 0; text-align: center; font-size: 0.87rem; }
.search-bar { margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.search-bar input { max-width: 300px; }

.retour-lien { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 0.83rem; text-decoration: none; }
.retour-lien:hover { color: var(--text); }

/* ── Avatars (initiales) ──────────────────────────────────────────── */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius); flex: 0 0 auto;
  background: var(--sage-50); color: var(--sage-700); border: 1px solid var(--sage-200);
  font-family: var(--font-serif); font-weight: 700; font-size: 0.78rem;
}
.avatar-sm { width: 24px; height: 24px; font-size: 0.65rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1.05rem; }

/* ── Bouton discret (export CSV, etc.) ───────────────────────────────── */
.btn-discret {
  margin-top: 0; background: var(--surface); color: var(--sage-700);
  border: 1px solid var(--sage-200); box-shadow: none;
}
.btn-discret:hover { background: var(--sage-50); }

/* ── Rappel clé publique (pied de sidebar) ───────────────────────────── */
.pubkey-reminder {
  padding: 8px 10px; margin-bottom: 6px; border-radius: var(--radius);
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.05); cursor: default;
}
.pubkey-reminder-label { display: block; font-size: 0.62rem; text-transform: uppercase; letter-spacing: .06em; color: rgba(168,197,194,.6); font-weight: 700; }
.pubkey-reminder-val { display: block; margin-top: 3px; font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-text); }

/* ── Prochaines échéances ─────────────────────────────────────────────── */
.echeances-panel { padding: 16px 20px; }
.souspage-titre { font-family: var(--font-serif); font-size: 0.94rem; font-weight: 700; margin: 0 0 14px; }
.echeances-liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.echeances-liste li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.echeances-liste li:last-child { border-bottom: none; }
.echeance-nom { flex: 1; font-weight: 600; font-size: 0.84rem; }

/* ── Filtres de statut ─────────────────────────────────────────────────── */
.filtres-statut { display: flex; gap: 7px; margin-bottom: 14px; }
.filtre-chip {
  margin-top: 0; height: 28px; padding: 0 13px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 0.76rem; font-weight: 600; cursor: pointer;
  box-shadow: none;
}
.filtre-chip:hover { background: var(--surface-2); }
.filtre-chip.actif { background: var(--sage-600); color: #fff; border-color: var(--sage-600); }

/* ── Fiche client ─────────────────────────────────────────────────────── */
.fiche-entete { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.fiche-entete > div { flex: 1; }
.fiche-nom { font-family: var(--font-serif); font-size: 1.2rem; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.01em; }
.fiche-grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.fiche-info { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 13px; display: flex; flex-direction: column; gap: 5px; }
.fiche-info .cle-label { font-weight: 700; font-size: 0.68rem; color: var(--muted-soft); text-transform: uppercase; letter-spacing: .05em; }
.fiche-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.fiche-colonnes .panel { margin-bottom: 0; }
.historique-liste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; font-size: 0.83rem; }
.historique-liste li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.historique-liste li:last-child { border-bottom: none; }

@media (max-width: 860px) {
  .fiche-colonnes { grid-template-columns: 1fr; }
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; }
  .brand { border-bottom: none; border-right: 1px solid rgba(255,255,255,.05); padding: 14px 16px; }
  .nav { flex-direction: row; padding: 8px; overflow-x: auto; }
  .nav-item.actif::before { left: 50%; top: auto; bottom: -8px; transform: translateX(-50%); width: 14px; height: 2px; border-radius: 1px 1px 0 0; }
  .sidebar-foot { border-top: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding: 20px; }
}

/* ── Tickets SAV ──────────────────────────────────────────────────── */
textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.87rem; background: #fff; color: var(--text); font-family: var(--font-sans); resize: vertical;
}
textarea:focus { outline: none; border-color: var(--sage-600); box-shadow: 0 0 0 2px rgba(59,100,97,0.14); }

.ticket-thread { display: flex; flex-direction: column; gap: 14px; }
.ticket-msg { max-width: 78%; padding: 11px 14px; border-radius: 10px; font-size: 0.86rem; line-height: 1.55; }
.ticket-msg.client { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.ticket-msg.vendeur { align-self: flex-end; background: var(--sage-600); color: #fff; }
.ticket-msg-meta { font-size: 0.68rem; text-transform: uppercase; letter-spacing: .05em; opacity: .7; margin-bottom: 5px; }
.ticket-msg-texte { white-space: pre-wrap; word-wrap: break-word; }
.ticket-msg-pj { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.ticket-msg-pj a { font-size: 0.76rem; padding: 3px 9px; border-radius: 20px; text-decoration: none; background: rgba(255,255,255,.2); color: inherit; }
.ticket-msg.client .ticket-msg-pj a { background: var(--surface-3, #EDF1F3); color: var(--text); }
