/* RR — Application de prévision retraite
   Design tokens + base layout */

:root {
  /* Palette — bleu professionnel original (pas Retraite Québec) */
  --brand-50:  oklch(0.975 0.012 245);
  --brand-100: oklch(0.945 0.024 245);
  --brand-200: oklch(0.895 0.048 245);
  --brand-300: oklch(0.820 0.080 245);
  --brand-400: oklch(0.690 0.120 245);
  --brand-500: oklch(0.555 0.145 245);
  --brand-600: oklch(0.465 0.140 245);
  --brand-700: oklch(0.385 0.120 245);
  --brand-800: oklch(0.305 0.090 245);
  --brand-900: oklch(0.235 0.060 245);

  /* Neutres froids très légèrement bleutés */
  --n-0:   oklch(1 0 0);
  --n-25:  oklch(0.990 0.004 245);
  --n-50:  oklch(0.982 0.006 245);
  --n-100: oklch(0.965 0.008 245);
  --n-150: oklch(0.945 0.010 245);
  --n-200: oklch(0.920 0.012 245);
  --n-300: oklch(0.875 0.012 245);
  --n-400: oklch(0.755 0.012 245);
  --n-500: oklch(0.620 0.014 245);
  --n-600: oklch(0.500 0.014 245);
  --n-700: oklch(0.400 0.014 245);
  --n-800: oklch(0.280 0.014 245);
  --n-900: oklch(0.195 0.014 245);
  --n-950: oklch(0.145 0.014 245);

  /* Sémantique */
  --success: oklch(0.565 0.110 160);
  --warning: oklch(0.730 0.140 75);
  --danger:  oklch(0.585 0.185 25);

  /* Mode clair par défaut */
  --bg:          var(--n-50);
  --bg-sunken:   var(--n-100);
  --bg-raised:   var(--n-0);
  --bg-overlay:  var(--n-0);
  --border:      var(--n-200);
  --border-strong: var(--n-300);
  --text:        var(--n-900);
  --text-muted:  var(--n-600);
  --text-subtle: var(--n-500);
  --accent:      var(--brand-600);
  --accent-soft: var(--brand-50);
  --accent-text: var(--brand-700);
  --focus-ring:  oklch(0.690 0.120 245 / 0.35);

  /* Espacement & rayons — confort par défaut */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --field-h: 40px;
  --field-px: 12px;
  --section-gap: 32px;
  --field-gap: 20px;
  --label-gap: 6px;

  --shadow-xs: 0 1px 0 rgba(12, 28, 58, 0.04);
  --shadow-sm: 0 1px 2px rgba(12, 28, 58, 0.05), 0 1px 0 rgba(12, 28, 58, 0.03);
  --shadow-md: 0 4px 12px rgba(12, 28, 58, 0.06), 0 1px 2px rgba(12, 28, 58, 0.04);
  --shadow-lg: 0 12px 32px rgba(12, 28, 58, 0.10), 0 2px 6px rgba(12, 28, 58, 0.05);

  /* Type */
  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "Instrument Serif", "Instrument Sans", serif;
}

/* ---------- Densité compact ---------- */
html[data-density="compact"] {
  --field-h: 34px;
  --field-px: 10px;
  --section-gap: 22px;
  --field-gap: 14px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

/* ---------- Mode sombre ---------- */
html[data-theme="dark"] {
  --bg:          var(--n-950);
  --bg-sunken:   oklch(0.115 0.014 245);
  --bg-raised:   oklch(0.185 0.014 245);
  --bg-overlay:  oklch(0.225 0.014 245);
  --border:      oklch(0.265 0.014 245);
  --border-strong: oklch(0.330 0.014 245);
  --text:        var(--n-100);
  --text-muted:  var(--n-400);
  --text-subtle: var(--n-500);
  --accent:      var(--brand-400);
  --accent-soft: oklch(0.265 0.045 245);
  --accent-text: var(--brand-300);
  --focus-ring:  oklch(0.690 0.120 245 / 0.5);

  --shadow-xs: 0 1px 0 rgba(0,0,0,0.3);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.35), 0 1px 0 rgba(0,0,0,0.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}
button { font-family: inherit; }

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 60px 1fr;
}

/* Top bar */
.topbar {
  display: grid;
  grid-template-columns: 260px 1fr auto;
  align-items: center;
  padding: 0 24px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: grid; place-items: center;
  color: white; font-family: var(--font-display);
  font-size: 15px; font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15), var(--shadow-sm);
}
.brand-name { font-size: 15px; }
.brand-sub { color: var(--text-muted); font-weight: 400; font-size: 13px; margin-left: 4px; }

.topbar-center {
  display: flex; justify-content: center;
}
.cotisant-pill {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.cotisant-pill:hover { border-color: var(--border-strong); background: var(--bg-sunken); }
.cotisant-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 11px; font-weight: 600;
  display: grid; place-items: center;
}
.cotisant-meta { color: var(--text-muted); font-size: 12.5px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.autosave {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 12.5px;
  padding: 0 10px;
}
.autosave-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--success) 22%, transparent);
}

/* Icon buttons */
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- Main layout ---------- */
.main {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
}
.main[data-nav="topbar"] { grid-template-columns: 1fr; }
.main[data-nav="wizard"] { grid-template-columns: 1fr; }

/* ---------- Sidebar nav ---------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 22px 16px;
  position: sticky; top: 60px; align-self: start;
  height: calc(100vh - 60px);
  overflow-y: auto;
}
.sidebar-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-subtle);
  padding: 0 10px 10px;
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  font: inherit;
  width: 100%;
  text-decoration: none;
  transition: background .12s, color .12s, border-color .12s;
}
.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.current {
  background: var(--bg-raised);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
.nav-index {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-subtle);
  width: 22px; text-align: center;
}
.nav-item.current .nav-index { color: var(--accent); }
.nav-item.done .nav-index { color: var(--success); }
.nav-title { font-size: 14px; font-weight: 500; }
.nav-status {
  font-size: 11px; color: var(--text-subtle);
  font-family: var(--font-mono);
}

.progress-card {
  margin-top: 22px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
}
.progress-title {
  font-size: 12px; color: var(--text-muted);
  display: flex; justify-content: space-between;
  margin-bottom: 8px;
}
.progress-track {
  height: 6px; border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-hint { font-size: 11.5px; color: var(--text-subtle); margin-top: 8px; font-family: var(--font-mono); }

/* ---------- Tabs (alternative nav) ---------- */
.tabs-bar {
  display: none;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  gap: 4px;
  align-items: end;
}
.main[data-nav="tabs"] .tabs-bar { display: flex; }
.main[data-nav="tabs"] .sidebar { display: none; }

.tab {
  padding: 14px 16px 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit; font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.current {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 500;
}
.tab-index {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-subtle);
  width: 18px; height: 18px; border-radius: 4px;
  background: var(--bg-sunken);
  display: grid; place-items: center;
}
.tab.current .tab-index { color: white; background: var(--accent); }

/* ---------- Wizard (alternative nav) ---------- */
.wizard-bar {
  display: none;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  padding: 18px 40px;
}
.main[data-nav="wizard"] .wizard-bar { display: flex; }
.main[data-nav="wizard"] .sidebar { display: none; }
.wizard-steps {
  display: flex; gap: 0;
  width: 100%; max-width: 1100px; margin: 0 auto;
  align-items: center;
}
.wizard-step {
  display: flex; align-items: center; gap: 10px;
  flex: 1;
  color: var(--text-muted);
  font-size: 13px;
}
.wizard-step + .wizard-step::before {
  content: ""; flex: 1;
  height: 1px; background: var(--border);
  margin-right: 12px;
}
.wizard-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-muted);
}
.wizard-step.done .wizard-dot {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.wizard-step.current .wizard-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.wizard-step.current { color: var(--text); font-weight: 500; }

/* ---------- Content ---------- */
.content {
  padding: 28px 40px 80px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.content-head {
  display: flex; align-items: end; justify-content: space-between;
  margin-bottom: 22px;
  gap: 24px;
}
.content-eyebrow {
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--accent); letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 6px;
}
.content-title {
  font-family: var(--font-display);
  font-size: 30px; font-weight: 400;
  letter-spacing: -0.015em; line-height: 1.15;
  color: var(--text);
  margin: 0;
}
.content-lede {
  color: var(--text-muted);
  font-size: 14.5px;
  max-width: 620px;
  margin-top: 8px;
}

.content-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Layout grid for Relevé ---------- */
.relev-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: start;
}

/* ---------- Card / sections ---------- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-xs);
}
.card + .card { margin-top: 20px; }
html[data-density="compact"] .card { padding: 16px 18px; }

.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.card-title {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 10px;
}
.card-title-num {
  font-family: var(--font-mono);
  font-size: 11px;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent-text);
  display: grid; place-items: center;
}
.card-desc {
  color: var(--text-muted); font-size: 13px;
  max-width: 440px;
}

/* ---------- Fields ---------- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--field-gap);
}
.field-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.cols-1 { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: var(--label-gap); min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }

.label {
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.label-hint {
  font-size: 12px; color: var(--text-muted); font-weight: 400;
  margin-left: 4px;
}
.required-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); display: inline-block;
}
.optional-tag {
  font-size: 10.5px; color: var(--text-subtle);
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: 0.05em;
}
.info-btn {
  width: 15px; height: 15px;
  border: 1px solid currentColor;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  color: var(--text-subtle);
  cursor: help;
  position: relative;
  display: inline-block;
  vertical-align: -3px;
  font-size: 0; line-height: 0;
  flex-shrink: 0;
  transition: color .12s, background .12s;
}
.info-btn::before,
.info-btn::after {
  content: "";
  position: absolute;
  left: 50%;
  background: currentColor;
  border-radius: 1px;
}
/* dot */
.info-btn::before {
  top: 2.5px;
  width: 1.5px; height: 1.5px;
  transform: translateX(-50%);
  border-radius: 50%;
}
/* stem */
.info-btn::after {
  top: 5.5px;
  width: 1.5px; height: 5px;
  transform: translateX(-50%);
}
.info-btn:hover { color: var(--accent); background: var(--accent-soft); }

.input-wrap {
  position: relative; display: flex; align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.input-wrap:hover { border-color: var(--n-400); }
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
  background: var(--bg-raised);
}
.input, .select {
  flex: 1;
  height: var(--field-h);
  padding: 0 var(--field-px);
  border: 0; background: transparent;
  color: var(--text);
  font: inherit; font-size: 14px;
  outline: none;
  min-width: 0;
}
.input::placeholder { color: var(--text-subtle); }
.input.is-number { font-family: var(--font-mono); font-size: 13.5px; text-align: right; }
.input-prefix, .input-suffix {
  display: inline-flex; align-items: center;
  padding: 0 10px;
  color: var(--text-muted);
  font-family: var(--font-mono); font-size: 12.5px;
  background: var(--bg-sunken);
  border-left: 1px solid var(--border);
}
.input-prefix { border-left: 0; border-right: 1px solid var(--border); }
.input-wrap:focus-within .input-suffix,
.input-wrap:focus-within .input-prefix { color: var(--text); }

.field-help {
  font-size: 12px; color: var(--text-muted); line-height: 1.4;
}
.field-error { color: var(--danger); font-size: 12px; }

/* Segmented control */
.segmented {
  display: inline-flex; padding: 3px;
  background: var(--bg-sunken);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  gap: 2px;
}
.segmented > button {
  border: 0; background: transparent;
  padding: 6px 14px; border-radius: calc(var(--radius-md) - 4px);
  font: inherit; font-size: 13px; color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  display: inline-flex; align-items: center; gap: 6px;
}
.segmented > button:hover { color: var(--text); }
.segmented > button.active {
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

/* Year table — THE key part of Relevé */
.year-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg);
}
.year-table-head {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  background: var(--bg-sunken);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.year-table-head .col-num { text-align: right; }
.year-row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  align-items: center;
  padding: 4px 14px 4px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.year-row:last-child { border-bottom: 0; }
.year-row:nth-child(odd) { background: color-mix(in oklab, var(--bg-sunken) 35%, transparent); }
.year-row .yr {
  font-family: var(--font-mono); font-size: 12.5px;
  color: var(--text-muted);
}
.year-row .input-wrap { border-radius: var(--radius-sm); }
.year-row .input { height: 32px; font-size: 13px; }

.year-table-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: var(--bg-sunken);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.link-btn {
  background: transparent; border: 0;
  color: var(--accent-text); font: inherit; font-size: 13px;
  cursor: pointer; padding: 0;
  text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
}
.link-btn:hover { text-decoration-color: currentColor; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: var(--field-h); padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised); color: var(--text);
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--bg-sunken); }
.btn.primary {
  background: var(--brand-600); border-color: var(--brand-700);
  color: white;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.12);
}
.btn.primary:hover { background: var(--brand-700); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { color: var(--text); background: var(--bg-sunken); }

/* ---------- Help sidebar (right) ---------- */
.help-panel {
  position: sticky; top: 80px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.help-eyebrow {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--accent); letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 6px;
}
.help-title {
  font-size: 15px; font-weight: 600; margin: 0 0 10px;
}
.help-body { font-size: 13px; color: var(--text-muted); line-height: 1.55; }
.help-body p + p { margin-top: 10px; }
.help-divider { height: 1px; background: var(--border); margin: 16px 0; }
.help-kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 12.5px; }
.help-kv dt { color: var(--text-muted); }
.help-kv dd { margin: 0; font-family: var(--font-mono); color: var(--text); }

.help-callout {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid color-mix(in oklab, var(--accent) 20%, transparent);
}

/* ---------- Tweaks panel ---------- */
.tweaks {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 60;
  width: 300px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  font-size: 13px;
  display: none;
}
.tweaks[data-open="true"] { display: block; }
.tweaks h4 {
  margin: 0 0 12px;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.tweaks .tweak-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.tweaks .tweak-label { color: var(--text-muted); font-size: 12.5px; }
.tweaks .segmented > button { padding: 4px 10px; font-size: 12px; }

/* Focus visible */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
