/* ============================================================
   NutriLink — Design system commun (patient + professionnel)
   Zéro dépendance. Thème clair uniquement.
   ============================================================ */

:root {
  color-scheme: light;

  /* --- Neutres --- */
  --bg:            #f8faf9;
  --bg-alt:        #f1f6f4;
  --surface:       #ffffff;
  --surface-2:     #f7faf9;
  --surface-3:     #f0f5f3;
  --border:        #e2e9e7;
  --border-strong: #c4d1ce;

  --text:          #10201d;
  --text-2:        #47605b;
  --text-3:        #7b918c;
  --text-inv:      #ffffff;

  /* --- Marque --- */
  --brand:         #16876a;
  --brand-hover:   #11704f;
  --brand-soft:    #e2f2ec;
  --brand-ring:    rgba(22, 135, 106, .28);

  --accent:        #3d5a9e;   /* espace pro */
  --accent-hover:  #32497f;
  --accent-soft:   #e6ecf8;

  /* --- Sémantique --- */
  --ok:            #17855a;
  --ok-soft:       #e0f3ea;
  --warn:          #b5760a;
  --warn-soft:     #fdf1dc;
  --danger:        #c0392f;
  --danger-soft:   #fbe7e5;
  --info:          #2f6fa8;
  --info-soft:     #e4eff8;

  /* --- Formes --- */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(9, 30, 26, .06), 0 1px 3px rgba(9, 30, 26, .05);
  --sh-2: 0 2px 6px rgba(9, 30, 26, .07), 0 8px 20px rgba(9, 30, 26, .06);
  --sh-3: 0 10px 30px rgba(9, 30, 26, .13), 0 2px 8px rgba(9, 30, 26, .08);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --header-h: 62px;
  --maxw: 1280px;
}

/* L'espace pro bascule la couleur primaire sur l'accent */
[data-space="pro"] {
  --brand:       var(--accent);
  --brand-hover: var(--accent-hover);
  --brand-soft:  var(--accent-soft);
  --brand-ring:  rgba(61, 90, 158, .28);
}

/* ============================ Reset ============================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .92rem; }
p  { margin: 0 0 .7em; }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { margin: 0; padding-left: 1.15em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 2px solid var(--bg); }

/* ============================ Layout =========================== */

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.stack   { display: flex; flex-direction: column; gap: 14px; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.row     { display: flex; align-items: center; gap: 10px; }
.row-wrap{ display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.spacer  { flex: 1 1 auto; }
.grid    { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 620px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.hide { display: none !important; }
.scroll-x { overflow-x: auto; }

/* ============================ Header =========================== */

.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header .wrap { height: 100%; display: flex; align-items: center; gap: 16px; }

.logo { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--brand), color-mix(in srgb, var(--brand) 55%, #7cc9a4));
  color: #fff; font-size: 15px; font-weight: 800;
}
.logo-sub { font-size: .7rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .08em; }

.nav { display: flex; align-items: center; gap: 2px; }
.nav a, .nav button {
  padding: 7px 12px; border-radius: var(--r-pill); border: 0; background: transparent;
  color: var(--text-2); font-size: .9rem; font-weight: 550; cursor: pointer;
}
.nav a:hover, .nav button:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active, .nav button.active { background: var(--brand-soft); color: var(--brand); }
@media (max-width: 820px) { .nav { display: none; } }

/* ============================ Cartes =========================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: 18px; }
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 18px; }
.card-body.tight { padding: 12px 14px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card.hoverable { transition: box-shadow .16s, transform .16s, border-color .16s; }
.card.hoverable:hover { box-shadow: var(--sh-2); border-color: var(--border-strong); }

.section-title { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--text-3); }

/* ============================ Boutons ========================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--r); border: 1px solid transparent;
  background: var(--surface-3); color: var(--text);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .14s, border-color .14s, color .14s, transform .06s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-quiet { background: transparent; color: var(--text-2); }
.btn-quiet:hover { background: var(--surface-3); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: .82rem; border-radius: var(--r-sm); }
.btn-lg { padding: 12px 22px; font-size: 1rem; border-radius: var(--r); }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; width: 34px; height: 34px; }

/* ============================ Formulaires ====================== */

.field { display: flex; flex-direction: column; gap: 5px; }
.label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.hint  { font-size: .78rem; color: var(--text-3); }

.input, .select, .textarea {
  width: 100%; padding: 9px 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  transition: border-color .14s, box-shadow .14s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.select { appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.input-search { padding-left: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b918c' stroke-width='2.2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='M20 20l-3.6-3.6'/></svg>");
  background-repeat: no-repeat; background-position: 10px center; background-size: 16px;
}
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-size: .89rem; }
.check input { margin-top: 3px; accent-color: var(--brand); width: 16px; height: 16px; flex: none; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r); padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  padding: 6px 13px; border-radius: 7px; font-size: .86rem; font-weight: 600; cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* ============================ Badges =========================== */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-pill);
  font-size: .74rem; font-weight: 650; letter-spacing: .01em;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge-ok     { background: var(--ok-soft);     color: var(--ok); }
.badge-warn   { background: var(--warn-soft);   color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info   { background: var(--info-soft);   color: var(--info); }
.badge-brand  { background: var(--brand-soft);  color: var(--brand); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* ============================ Avatar =========================== */

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 700; font-size: .84rem; letter-spacing: .02em;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}
.avatar-sm { width: 30px; height: 30px; font-size: .7rem; }
.avatar-lg { width: 62px; height: 62px; font-size: 1.15rem; }

/* ============================ Tables =========================== */

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; padding: 9px 12px; font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================ Divers =========================== */

.empty { padding: 42px 20px; text-align: center; color: var(--text-3); }
.empty-icon { font-size: 30px; opacity: .5; margin-bottom: 8px; }

.kpi-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: .78rem; color: var(--text-3); font-weight: 550; }

.bar { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

.muted { color: var(--text-3); }
.small { font-size: .82rem; }
.xs    { font-size: .75rem; }
.mono  { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.bold  { font-weight: 650; }
.tnum  { font-variant-numeric: tabular-nums; }
.center{ text-align: center; }
.nowrap{ white-space: nowrap; }
.cap   { text-transform: capitalize; }

/* ============================ Modale =========================== */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(244, 248, 247, .72); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  animation: fade .16s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--sh-3);
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  animation: pop .18s cubic-bezier(.2,.9,.3,1.1);
}
.modal.wide { max-width: 860px; }
.modal-head { padding: 17px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop  { from { opacity: 0; transform: translateY(10px) scale(.98) } to { opacity: 1; transform: none } }

/* ============================ Toasts =========================== */

.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: var(--r); box-shadow: var(--sh-3); padding: 11px 15px;
  font-size: .88rem; max-width: 340px; animation: slidein .2s ease;
}
.toast.err { border-left-color: var(--danger); }
.toast.warn{ border-left-color: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateX(18px) } to { opacity: 1; transform: none } }

/* ============================ Onglets ========================== */

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 10px 14px; font-size: .89rem; font-weight: 600; color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }


/* ========================= Paiement en ligne =================== */

/* --- Marques de carte --- */
.cb-marque {
  display: inline-grid; place-items: center; min-width: 38px; height: 24px;
  padding: 0 7px; border-radius: 5px; font-size: .62rem; font-weight: 800;
  letter-spacing: .04em; color: #fff; background: var(--text-3);
  font-family: var(--font); flex: none;
}
.cb-visa       { background: #1a1f71; }
.cb-mastercard { background: #cf4500; }
.cb-amex       { background: #1174b8; }
.cb-cb         { background: #0d5b4a; }
.cb-inconnue   { background: var(--surface-3); color: var(--text-3); box-shadow: inset 0 0 0 1px var(--border); }

/* --- Formulaire de carte --- */
.cb-form { display: flex; flex-direction: column; gap: 12px; }
.cb-champ { position: relative; display: flex; align-items: center; }
.cb-champ .input { padding-right: 56px; letter-spacing: .04em; }
.cb-champ-marque { position: absolute; right: 9px; pointer-events: none; }

.cb-err { font-size: .76rem; color: var(--danger); display: none; }
.cb-err.on { display: block; }
.cb-form .input:focus { border-color: var(--brand); }

/* --- Bandeaux d'information --- */
.cb-reassure {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.cb-cadenas { font-size: 1rem; line-height: 1.2; flex: none; }

.cb-demo {
  margin-top: 10px; padding: 9px 12px; border-radius: var(--r);
  background: var(--warn-soft); color: var(--warn); line-height: 1.55;
  border: 1px dashed color-mix(in srgb, var(--warn) 35%, transparent);
}
.cb-demo .mono { color: inherit; font-weight: 650; }

.cb-politique {
  padding: 13px 15px; border-radius: var(--r);
  background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 25%, transparent);
}
.cb-politique .titre { font-weight: 700; font-size: .86rem; color: var(--info); margin-bottom: 5px; }
.cb-politique ul { margin: 0; padding-left: 17px; font-size: .82rem; line-height: 1.65; color: var(--text-2); }
.cb-politique.cb-frais { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.cb-politique.cb-frais .titre { color: var(--danger); }

/* --- Cartes enregistrées --- */
.cb-liste { display: flex; flex-direction: column; gap: 9px; }
.cb-carte {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  transition: border-color .12s, background .12s, box-shadow .12s;
  font: inherit; color: inherit;
}
.cb-carte:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cb-carte.on { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-ring); }
.cb-carte.perimee { opacity: .58; }
.cb-carte .num { font-weight: 650; letter-spacing: .04em; }
.cb-carte .meta { font-size: .76rem; color: var(--text-3); }
.cb-carte-radio {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid var(--border-strong); display: grid; place-items: center;
}
.cb-carte.on .cb-carte-radio { border-color: var(--brand); }
.cb-carte.on .cb-carte-radio::after { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }

/* --- Authentification 3-D Secure --- */
.cb-3ds-banque {
  display: flex; align-items: center; gap: 12px; padding: 13px 15px;
  border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border);
}
.cb-3ds-logo { font-size: 1.5rem; }
.cb-otp { text-align: center; font-size: 1.35rem; letter-spacing: .5em; padding-left: .5em; }

/* --- Progression de la prise d'empreinte --- */
.cb-progres { display: flex; align-items: center; gap: 11px; padding: 16px 4px; font-size: .88rem; color: var(--text-2); }
.cb-spin {
  width: 19px; height: 19px; border-radius: 50%; flex: none;
  border: 2px solid var(--surface-3); border-top-color: var(--brand);
  animation: cb-tourne .7s linear infinite;
}
@keyframes cb-tourne { to { transform: rotate(360deg) } }

/* --- Ligne de transaction --- */
.cb-tx { display: flex; gap: 13px; align-items: flex-start; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.cb-tx:last-child { border-bottom: 0; }
.cb-tx .montant { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.cb-tx .montant.nul { color: var(--text-3); font-weight: 600; }

/* ============================ Impression ======================= */

@media print {
  .app-header, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
