:root {
  /* Palette Tarn Compta */
  --pourpre-50: #f7f3fb; --pourpre-100: #efe5f6; --pourpre-300: #c4a1dd;
  --pourpre-400: #a673c9; --pourpre-700: #5d2e7c; --pourpre-800: #4a2563; --pourpre-900: #371a49;
  --or-500: #b8923f; --or-300: #d9bd7e; --or-100: #f3e8cf;
  --parchment: #f4efe6;
  --ink-900: #1c1822; --ink-700: #3a3343; --ink-500: #6b6276;
  --ink-300: #b8b1c1; --ink-200: #ddd8e3; --ink-100: #efecf3; --ink-50: #f8f6fb;
  --white: #fff;

  --font-sans: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --font-display: 'Spectral', Georgia, 'Times New Roman', serif;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px; --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(36,16,48,.08), 0 1px 2px rgba(36,16,48,.04);
  --shadow-md: 0 6px 16px rgba(36,16,48,.08), 0 2px 4px rgba(36,16,48,.04);
  --shadow-brand: 0 12px 28px rgba(93,46,124,.28);
  --ring: 0 0 0 3px rgba(166,115,201,.45);

  /* rôles */
  --brand: var(--pourpre-700); --brand-hover: var(--pourpre-800);
  --bg: var(--ink-50); --card: var(--white); --ink: var(--ink-900);
  --muted: var(--ink-500); --line: var(--ink-200); --danger: #b23a48;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--ink-900);
  line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* ------------------------- En-tête ------------------------- */
header { background: var(--pourpre-800); color: #fff; padding: 18px 24px; position: relative; }
header h1 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -.01em; }
header small { opacity: .8; font-size: 13px; }
#who { position: absolute; right: 20px; top: 20px; font-size: 13px; opacity: .95; display: flex; align-items: center; gap: 10px; }

main { max-width: 1000px; margin: 28px auto; padding: 0 20px; display: grid; gap: 22px; }

/* ------------------------- Cartes ------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 22px; box-shadow: var(--shadow-sm); }
.card h2 { margin: 0 0 14px; font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink-900); }

/* ------------------------- Formulaires ------------------------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 5px; font-weight: 500; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-md); font: inherit; background: #fff; color: var(--ink-900); transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--pourpre-400); box-shadow: var(--ring); }
textarea { resize: vertical; min-height: 90px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.actions { margin-top: 16px; display: flex; gap: 10px; }
.actions.end { justify-content: flex-end; }
td .sub { display: block; color: var(--muted); font-size: 12px; }

/* ------------------------- Boutons ------------------------- */
button { cursor: pointer; border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 10px 18px; font: inherit; font-weight: 600; letter-spacing: -.01em;
  background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); transition: background .15s, box-shadow .15s, transform .05s; }
button:hover { background: var(--brand-hover); box-shadow: var(--shadow-md); }
button:active { transform: translateY(1px); }
button.ghost { background: #fff; color: var(--ink-700); border-color: var(--line); box-shadow: none; font-weight: 500; }
button.ghost:hover { background: var(--ink-50); border-color: var(--ink-300); }
button.link { background: none; border: 0; box-shadow: none; color: var(--pourpre-700); padding: 2px 6px; font-weight: 500; }
button.link:hover { background: none; text-decoration: underline; }
button.link.danger { color: var(--danger); }

/* ------------------------- Tableau ------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:hover { background: var(--pourpre-50); }
.col-actions { width: 170px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input { max-width: 300px; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }

/* ------------------------- Tags / messages ------------------------- */
.tag { display: inline-block; background: var(--pourpre-50); color: var(--pourpre-700);
  border: 1px solid var(--pourpre-100); border-radius: var(--radius-pill); padding: 1px 9px; font-size: 12px; margin: 1px 2px; }
.msg { padding: 11px 14px; border-radius: var(--radius-md); font-size: 14px; margin-bottom: 14px; display: none; }
.msg.ok { background: #e3f0ea; color: #2f7a5a; display: block; }
.msg.err { background: #f6e4e6; color: var(--danger); display: block; }

/* ------------------------- Sections repliables ------------------------- */
details.card summary { cursor: pointer; font-family: var(--font-display); font-weight: 600; font-size: 16px; }
details.card[open] summary { margin-bottom: 12px; }
.creds { margin: 12px 0; font-size: 14px; }
.creds .cred { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.creds .cred .grow { flex: 1; }
.collab-form { margin-top: 6px; }
.sec-h { font-family: var(--font-display); font-size: 14px; font-weight: 600; color: var(--ink-700); margin: 18px 0 6px; }
.sec-h:first-of-type { margin-top: 8px; }
code { background: var(--ink-100); padding: 1px 5px; border-radius: var(--radius-sm); font-size: .92em; }

/* ------------------------- Dialogue ------------------------- */
dialog { border: 0; border-radius: var(--radius-lg); padding: 0; max-width: 520px; width: 92%; box-shadow: var(--shadow-md); }
dialog::backdrop { background: rgba(28,24,34,.45); }
dialog .card { border: 0; box-shadow: none; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }
[hidden] { display: none !important; }

/* ------------------------- Écran d'accueil / connexion ------------------------- */
.gate { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 40px; padding: 48px 24px; background: var(--parchment); text-align: center; }
.gate .albi { width: 440px; max-width: 90vw; height: auto; }
.gate .rule { width: 48px; height: 2px; background: var(--or-500); border: 0; }
.gate .subtitle { color: var(--ink-500); font-family: var(--font-display); font-size: 15px; margin-top: -18px; }
.gate .gate-actions { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 340px; }
.gate button.primary { background: var(--pourpre-700); color: #fff; border-radius: var(--radius-md);
  padding: 15px 28px; font-size: 18px; font-weight: 600; min-width: 180px; box-shadow: var(--shadow-sm); }
.gate button.primary:hover { background: var(--pourpre-800); box-shadow: var(--shadow-brand); }
.gate .setup { width: 100%; max-width: 340px; text-align: left; background: rgba(255,255,255,.6);
  border: 1px solid var(--or-300); border-radius: var(--radius-lg); padding: 18px; }
.gate .setup h2 { font-family: var(--font-display); font-size: 16px; margin-bottom: 4px; }
.gate .authErr { color: var(--danger); font-size: 14px; max-width: 340px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------- Mobile (≤ 640 px) ------------------------- */
@media (max-width: 640px) {
  header { padding: 14px 16px; }
  header h1 { font-size: 19px; }
  #who { position: static; margin-top: 10px; justify-content: flex-start; }

  main { margin: 16px auto; padding: 0 12px; gap: 16px; }
  .card { padding: 16px; border-radius: var(--radius-md); }

  /* Formulaires : une seule colonne */
  .row { grid-template-columns: 1fr; }
  .actions { flex-wrap: wrap; }
  .actions button { flex: 1 1 auto; }

  /* Barre d'outils : recherche pleine largeur */
  .toolbar { flex-wrap: wrap; }
  .toolbar input { max-width: none; width: 100%; }
  .toolbar .spacer { display: none; }
  #reload { width: 100%; }

  /* Tableau de contacts -> cartes empilées (chaque ligne = une fiche) */
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { border: 1px solid var(--line); border-radius: var(--radius-md);
    padding: 6px 14px; margin-bottom: 12px; background: #fff; box-shadow: var(--shadow-sm); }
  tbody tr:hover { background: #fff; }
  td { border: 0; padding: 7px 0; display: flex; gap: 14px; align-items: baseline;
    justify-content: space-between; border-bottom: 1px solid var(--ink-100); text-align: right; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); flex: 0 0 40%; text-align: left;
    font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
  td:empty { display: none; }
  td .sub { display: inline; }
  /* Cellule actions : rangée de boutons pleine largeur, sans libellé */
  td.cell-actions { flex-wrap: wrap; justify-content: flex-start; gap: 4px; padding-top: 10px; }
  td.cell-actions::before { content: none; }
  td.cell-actions button { padding: 9px 12px; font-size: 14px; }

  .creds .cred { flex-wrap: wrap; }

  /* Écran d'accueil : un peu plus compact */
  .gate { padding: 32px 20px; gap: 28px; }
}
