/* Mobile first: styles below target a phone; wider screens are handled by min-width media queries.
   Tokens and components follow the Figma mockup "Maquette S1-12 · v2". */
:root {
  --primary: #6d3bf5;
  --primary-strong: #5427d9;
  --primary-soft: #efe9ff;
  --accent: #ff6b4a; /* coral: only for what the AI does */
  --accent-strong: #b23a0e;
  --accent-soft: #ffeae4;
  --success: #12a57a;
  --success-strong: #0a7a5a;
  --success-soft: #e2f7ef;
  --danger-strong: #c42b31;
  --danger-soft: #fdecec;
  --text: #1a1433;
  --muted: #625c78;
  --border: #e6e1f0;
  --border-strong: #8e87a6;
  --surface: #ffffff;
  --bg: #f8f6fd;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-sm: 10px; --r-md: 16px; --r-lg: 24px;
  --tap: 44px; /* minimum touch target */
  --tabs-height: 64px;

  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Text ---------- */
h1 { font-size: 26px; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 18px; font-weight: 700; line-height: 1.3; letter-spacing: -0.005em; margin: 0; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 var(--s1); }
p, ul { margin: 0; }
ul { padding-left: 20px; }
a { color: var(--primary-strong); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 500; line-height: 1.45; }
.label { font-size: 12px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); }
.grow { flex: 1; min-width: 0; }
.icon { flex: none; }

/* ---------- Layout ---------- */
.page { max-width: 640px; margin: 0 auto; padding: var(--s5) var(--s4); display: flex; flex-direction: column; gap: var(--s5); }
.page-head { display: flex; align-items: center; gap: var(--s3); }
.page-head + p { margin-top: var(--s1); }
.cv-columns { display: flex; flex-direction: column; gap: var(--s5); }
.cv-column { display: flex; flex-direction: column; gap: var(--s5); }

/* ---------- Top bar and navigation ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--s5); padding: var(--s3) var(--s4); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-size: 18px; font-weight: 700; color: var(--text); text-decoration: none; }
.logo { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--r-sm); background: var(--primary); color: #fff; }
.logo-lg { width: 40px; height: 40px; }
/* On a phone the navigation is a tab bar fixed at the bottom */
.tabs { position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; padding: var(--s1); font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; }
.tabs a .tab-icon { display: inline-flex; padding: 4px 16px; border-radius: 999px; }
.tabs a[aria-current="page"] { color: var(--primary-strong); }
.tabs a[aria-current="page"] .tab-icon { background: var(--primary-soft); }
body.has-tabs { padding-bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom)); }
/* On a phone, signing out lives in "Compte" */
.topbar .topbar-logout { display: none; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.card-ia { border: 2px solid var(--accent); }
.card-success { background: var(--success-soft); border-color: var(--success); }
.card-empty { background: transparent; border: 1px dashed var(--border-strong); align-items: flex-start; gap: var(--s2); }
.card-head { display: flex; align-items: center; gap: var(--s2); }
.card-head h2 { flex: 1; }
.divider { text-align: center; }

/* A whole card is the button; the pencil is only a visual hint */
.item { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; display: flex; flex-direction: row; align-items: flex-start; gap: var(--s2); }
.item:hover { border-color: var(--primary); }
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s1); overflow-wrap: anywhere; }
.item-title { font-weight: 600; }
.item-meta { color: var(--primary-strong); font-size: 13px; font-weight: 500; }
.item-desc { color: var(--muted); white-space: pre-line; }
.edit-hint { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.cv-title-text { font-size: 18px; font-weight: 700; line-height: 1.3; }
.items { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.section { display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
.section > * { align-self: stretch; }
.section > .btn { align-self: flex-start; }
.section-head { display: flex; align-items: center; gap: var(--s2); }
.section-head h2 { flex: 1; }

/* ---------- Badges and chips ---------- */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--primary-soft); color: var(--primary-strong); }
.badge-ia { background: var(--accent-soft); color: var(--accent-strong); }
.badge-success { background: var(--success-soft); color: var(--success-strong); }
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { display: inline-flex; align-items: center; gap: var(--s1); min-height: var(--tap); padding: var(--s2) var(--s3); border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.chip.highlighted { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }

/* ---------- Buttons and links ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--tap); padding: var(--s2) var(--s5); border: none; border-radius: 999px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-strong); }
.btn-danger { background: var(--danger-strong); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn.is-loading { cursor: wait; }
.btn.is-loading::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
.link-action { display: inline-flex; align-items: center; gap: var(--s1); min-height: var(--tap); padding: 0; border: none; background: none; font: inherit; font-weight: 600; color: var(--primary-strong); text-decoration: none; cursor: pointer; }
.link-danger { color: var(--danger-strong); align-self: center; }
.link-row { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); font: inherit; font-weight: 600; color: var(--primary-strong); text-align: left; text-decoration: none; cursor: pointer; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border: none; border-radius: 999px; background: var(--bg); color: var(--text); cursor: pointer; }
.actions { display: flex; gap: var(--s3); }
.actions > .btn { flex: 1; }
:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
/* The file input is hidden behind its label-button: the label shows the focus */
.visually-hidden:focus-visible + .btn { outline: 3px solid var(--text); outline-offset: 2px; }

/* ---------- Forms ---------- */
label, legend { display: block; font-weight: 600; margin-bottom: var(--s1); }
fieldset { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
fieldset > legend { font-size: 12px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); padding: 0; }
input:not([type="checkbox"]):not([type="file"]), select, textarea { width: 100%; min-height: 48px; padding: var(--s3) var(--s4); font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
textarea { resize: vertical; min-height: 96px; }
/* Same chevron as the mockup instead of each browser's own arrow */
select { appearance: none; text-align: left; padding-right: 44px; cursor: pointer; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23625c78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center; }
/* A 2 px focus border drawn as a shadow, so the text does not move */
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); opacity: 0.45; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger-strong); box-shadow: 0 0 0 1px var(--danger-strong); }
.field { display: flex; flex-direction: column; }
.hint { color: var(--muted); font-size: 13px; font-weight: 500; margin-top: var(--s1); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.checkbox { display: flex; align-items: center; gap: var(--s2); min-height: var(--tap); font-weight: 400; margin: 0; }
.checkbox input { width: 22px; height: 22px; margin: 0; accent-color: var(--primary); }
.form { display: flex; flex-direction: column; gap: var(--s4); }
/* Commune suggestions under the field */
.suggestions { list-style: none; padding: var(--s1); margin-top: var(--s1); border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); }
.suggestions li.muted { padding: var(--s2) var(--s3); }
.suggestions button { width: 100%; min-height: var(--tap); padding: var(--s2) var(--s3); border: none; border-radius: 8px; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.suggestions button:hover, .suggestions button:focus-visible { background: var(--primary-soft); }

/* ---------- Messages ---------- */
.alert { display: flex; gap: var(--s2); padding: var(--s3); border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger-strong); }
.notice { padding: var(--s3); border-radius: var(--r-sm); background: var(--primary-soft); color: var(--text); }
.saved { color: var(--success-strong); font-weight: 600; }
.saved:empty { display: none; }
.status-granted { color: var(--success-strong); font-weight: 600; }
.status-error { color: var(--danger-strong); font-weight: 600; }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--primary-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width 0.3s; }
.steps { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.steps li { display: grid; grid-template-columns: 24px 1fr; gap: 0 var(--s3); color: var(--muted); }
.steps li .step-label { font-weight: 600; }
.steps li .step-detail { grid-column: 2; font-size: 13px; font-weight: 500; }
.steps li[data-state="active"], .steps li[data-state="done"] { color: var(--text); }
.steps li[data-state="active"] .step-detail { color: var(--primary-strong); }
.steps li[data-state="error"] .step-detail { color: var(--danger-strong); }
.step-icon { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
[data-state="active"] .step-icon { border-color: var(--primary); border-top-color: transparent; animation: spin 0.8s linear infinite; }
[data-state="done"] .step-icon { border-color: var(--success); background: var(--success); color: #fff; }
[data-state="error"] .step-icon { border-color: var(--danger-strong); background: var(--danger-strong); color: #fff; }
[data-state="error"] .step-label { color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  [data-state="active"] .step-icon, .btn.is-loading::before { animation: none; border-style: dotted; }
}
details.unused summary { cursor: pointer; font-weight: 600; }
details.unused ul { margin-top: var(--s2); }

/* ---------- Knowledge base facts ---------- */
.fact { display: flex; flex-direction: column; gap: var(--s1); align-items: flex-start; }
.fact > p { overflow-wrap: anywhere; white-space: pre-line; }
.fact-updated { background: var(--primary-soft); border: 2px solid var(--primary); }
.fact-updated .label { color: var(--primary-strong); }
.fact-time { display: inline-flex; padding: 2px 8px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 13px; font-weight: 600; }
.counts { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }

/* ---------- Legal pages and their links ---------- */
.legal section { display: flex; flex-direction: column; gap: var(--s2); }
.legal ul { display: flex; flex-direction: column; gap: var(--s1); }
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s1) var(--s4); font-size: 13px; }
.legal-links a { color: var(--muted); font-weight: 500; }

/* ---------- Dialogs: a sheet from the bottom on a phone, centered on a wide screen ---------- */
dialog { border: none; padding: 0; background: var(--surface); color: var(--text); max-height: 92dvh; overflow: auto; }
dialog::backdrop { background: rgb(26 20 51 / 0.55); }
dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--s3) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom)); }
dialog.sheet::before { content: ""; display: block; width: 40px; height: 4px; margin: 0 auto var(--s3); border-radius: 999px; background: var(--border-strong); }
dialog.dialog-center { width: calc(100% - 32px); max-width: 400px; margin: auto; border-radius: var(--r-lg); padding: var(--s5); }
.dialog-head { display: flex; align-items: center; gap: var(--s2); }
.dialog-head h2 { flex: 1; }
.confirm-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 999px; background: var(--danger-soft); color: var(--danger-strong); }

/* ---------- Wider screens ---------- */
@media (min-width: 640px) {
  .page { padding-top: var(--s6); }
  dialog.sheet { width: calc(100% - 32px); max-width: 560px; margin: auto; border-radius: var(--r-lg); padding: var(--s5); }
  dialog.sheet::before { display: none; }
}

@media (min-width: 768px) {
  .topbar { padding: var(--s3) var(--s6); }
  /* The tab bar moves into the top bar */
  .tabs { position: static; flex: 1; gap: var(--s2); padding: 0; border: none; background: none; }
  .tabs a { flex: none; flex-direction: row; gap: var(--s2); min-height: var(--tap); padding: var(--s2) var(--s4); border-radius: 999px; font-size: 15px; }
  .tabs a .tab-icon { padding: 0; background: none !important; }
  .tabs a[aria-current="page"] { background: var(--primary-soft); }
  body.has-tabs { padding-bottom: 0; }
  .topbar .topbar-logout { display: inline-flex; color: var(--muted); }
}

@media (min-width: 960px) {
  .page-wide { max-width: 1040px; }
  .cv-columns { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
}
