/* Kaptan Data Solutions — feuille de style unique, sans framework. */

:root {
  --primary: #5e00b2;
  --primary-strong: #4a008d;
  --primary-soft: #f3eafc;
  --accent: #2a4bc8;
  --ink: #17121f;
  --ink-soft: #4b4458;
  --muted: #776f86;
  --line: #e6e0ee;
  --bg: #ffffff;
  --bg-soft: #faf8fd;
  --ok: #15803d;
  --ok-soft: #e8f6ed;
  --ko: #b91c1c;
  --ko-soft: #fdecec;
  --warn-soft: #fff6e0;
  --surface: #ffffff;
  --header-bg: rgba(255, 255, 255, .94);
  --on-primary: #ffffff;
  --chip: #f0eef3;
  --hero-1: #efe4fb;
  --hero-2: #e6ecff;
  --ok-ink: #14532d;
  --ok-line: #bfe5cb;
  --ko-ink: #7f1d1d;
  --ko-line: #f8caca;
  --warn-ink: #6b4e00;
  --warn-line: #f4e2ae;
  --warn: #8a5a00;
  color-scheme: light;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 18, 31, .05), 0 8px 24px rgba(23, 18, 31, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --max: 1120px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  line-height: 1.6; font-size: 16px;
  display: flex; flex-direction: column; min-height: 100vh;
}
main { flex: 1; }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-strong); }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.02em; margin: 0 0 .6em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); margin-top: 1.6em; }
h3 { font-size: 1.15rem; margin-top: 1.2em; }
p, ul, ol { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 780px; }
.section { padding: 48px 0; }
.section-soft { background: var(--bg-soft); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.lead { font-size: 1.15rem; color: var(--ink-soft); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--bg); padding: 8px 12px; z-index: 100; border-radius: 6px; }
.skip-link:focus { left: 8px; }

/* ---------- En-tête ---------- */
.site-header { position: sticky; top: 0; z-index: 50; background: var(--header-bg); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand img { width: 38px; height: 38px; }
.footer-logo { width: 180px; height: auto; margin-bottom: 12px; }

/* Visuels de marque des outils (16:9) */
.tool-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.tool-card .tool-thumb { aspect-ratio: 16 / 9; width: 100%; object-fit: cover; background: #fff; border-bottom: 1px solid var(--line); }
.tool-card .tool-card-body { padding: 18px 20px 20px; }
.tool-card h3 { margin: 0 0 6px; }
.tool-banner { width: 100%; max-width: 560px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.tool-hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 32px; align-items: center; margin-bottom: 28px; }
@media (max-width: 860px) { .tool-hero { grid-template-columns: 1fr; } }
.nav-panel a.nav-tool { display: flex; align-items: center; gap: 10px; }
.nav-panel a.nav-tool img { width: 44px; height: 25px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); flex: none; }
.brand span { white-space: nowrap; }
.nav-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; font: inherit; color: var(--ink); }
.site-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.site-nav a, .site-nav summary { color: var(--ink-soft); text-decoration: none; padding: 8px 12px; border-radius: 10px; font-weight: 500; cursor: pointer; list-style: none; }
.site-nav summary::-webkit-details-marker { display: none; }
.site-nav a:hover, .site-nav summary:hover, .site-nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.nav-menu { position: relative; }
.nav-menu[open] > .nav-panel { display: grid; }
.nav-panel { display: none; position: absolute; right: 0; top: calc(100% + 8px); width: min(560px, 92vw); grid-template-columns: repeat(2, 1fr); gap: 4px 20px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.nav-panel h4 { margin: 4px 12px; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav-panel a { display: block; padding: 6px 12px; }
.nav-user { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.nav-user img { width: 28px; height: 28px; border-radius: 50%; }
.nav-user form { margin: 0; }

@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .site-nav { display: none; position: absolute; left: 0; right: 0; top: 64px; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 16px 16px; box-shadow: var(--shadow); }
  .site-nav.is-open { display: flex; }
  .nav-panel { position: static; width: auto; grid-template-columns: 1fr; box-shadow: none; border: 0; padding: 0 0 0 8px; }
  .nav-user { margin: 8px 0 0; }
}

/* ---------- Boutons, cartes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: 999px; border: 1px solid transparent; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, box-shadow .15s; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); color: var(--on-primary); box-shadow: 0 6px 20px rgba(94,0,178,.25); }
.btn-ghost { background: var(--surface); color: var(--primary); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--primary); }
.btn-small { padding: 6px 14px; font-size: .875rem; }
.btn[disabled], .htmx-request .btn-submit { opacity: .6; pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card h3 { margin-top: 0; }
.card-link { text-decoration: none; color: inherit; display: block; transition: transform .15s, border-color .15s; }
.card-link:hover { transform: translateY(-2px); border-color: var(--primary); color: inherit; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--chip); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Héros ---------- */
.hero { padding: 56px 0 40px; background: radial-gradient(1200px 400px at 10% -10%, var(--hero-1), transparent), radial-gradient(900px 400px at 100% 0, var(--hero-2), transparent); }
.hero-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 40px; align-items: center; }
.hero img { border-radius: var(--radius); }
.hero-grid.hero-portrait { grid-template-columns: 300px 1fr; }
@media (max-width: 860px) {
  .hero-grid, .hero-grid.hero-portrait { grid-template-columns: 1fr; }
  .hero-portrait img { max-width: 240px; }
}
.eyebrow { font-size: .8rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--primary); margin-bottom: 12px; }

.cta-band { background: linear-gradient(135deg, #1a0535, #2d0a5e); color: #fff; border-radius: 20px; padding: 36px 28px; text-align: center; }
.cta-band h2 { margin-top: 0; color: #fff; }
.cta-band p { color: rgba(255,255,255,.75); max-width: 620px; margin: 0 auto 20px; }

/* ---------- Texte long (mentions, CV) ---------- */
.prose h2 { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.prose li { margin-bottom: .4em; }
.timeline-item { margin-bottom: 22px; }
.timeline-item h3 { margin: 0; }
.timeline-item .meta { color: var(--muted); font-size: .9rem; margin-bottom: 6px; }

/* ---------- Formulaires ---------- */
.form { display: grid; gap: 16px; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.field .required { color: var(--primary); }
.field input[type=text], .field input[type=email], .field input[type=number], .field input[type=file], .field select, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: 3px solid rgba(94,0,178,.15); }
.field .help { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.field .errors { color: var(--ko); font-size: .875rem; margin: 4px 0 0; padding: 0; list-style: none; }
.field-check { display: flex; align-items: flex-start; gap: 10px; }
.field-check input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--primary); }
.field-check label { font-weight: 500; margin: 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.alert { padding: 14px 16px; border-radius: 12px; margin: 0 0 16px; border: 1px solid transparent; }
.alert-error { background: var(--ko-soft); color: var(--ko-ink); border-color: var(--ko-line); }
.alert-success { background: var(--ok-soft); color: var(--ok-ink); border-color: var(--ok-line); }
.alert-info { background: var(--warn-soft); color: var(--warn-ink); border-color: var(--warn-line); }

/* ---------- Outils ---------- */
.tool-layout { display: grid; grid-template-columns: 340px 1fr; gap: 28px; align-items: start; }
@media (max-width: 960px) { .tool-layout { grid-template-columns: 1fr; } }
.tool-panel { position: sticky; top: 84px; }
@media (max-width: 960px) { .tool-panel { position: static; } }
.verdict { display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: var(--radius); font-weight: 700; font-size: 1.3rem; }
.verdict-ok { background: var(--ok-soft); color: var(--ok); }
.verdict-ko { background: var(--ko-soft); color: var(--ko); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 18px 0; }
.metric { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
.metric .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.metric .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.figures figure { margin: 0; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff; }
.figures figcaption { font-size: .85rem; color: #5b5466; text-align: center; margin-top: 6px; }
.empty-state { border: 2px dashed var(--line); border-radius: var(--radius); padding: 48px 24px; text-align: center; color: var(--muted); }
.spinner { display: none; align-items: center; gap: 10px; color: var(--primary); font-weight: 600; }
.htmx-request .spinner, .htmx-request.spinner { display: inline-flex; }
.spinner::before { content: ""; width: 18px; height: 18px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
pre.summary { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: .85rem; }
details.advanced summary { cursor: pointer; font-weight: 600; color: var(--primary); margin: 4px 0 8px; }
.verdict-warn { background: var(--warn-soft); color: var(--warn); }
.verdict-list { list-style: none; padding: 0; margin: 0 0 8px; }
.verdict-list li { padding: 8px 12px; border-radius: 10px; margin-bottom: 6px; font-size: .95rem; }
.verdict-list .lvl-ok { background: var(--ok-soft); color: var(--ok-ink); }
.verdict-list .lvl-warn { background: var(--warn-soft); color: var(--warn-ink); }
.verdict-list .lvl-alert { background: var(--ko-soft); color: var(--ko-ink); }
.result-section { margin-top: 28px; }
.result-section h3 { margin: 0 0 10px; font-size: 1.1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th { background: var(--bg-soft); font-weight: 600; color: var(--ink-soft); }
.data-table tr:last-child td { border-bottom: 0; }
.figures-wide { grid-template-columns: 1fr; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.preview-grid .table-wrap { max-height: 360px; overflow-y: auto; }
.itg-template { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 4px; margin: 0 0 16px; min-width: 0; }
.itg-template[hidden], .itg-range[hidden] { display: none; }
.itg-template legend { font-weight: 700; padding: 0 6px; }
.itg-group { margin: 14px 0 6px; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.itg-range label { display: flex; justify-content: space-between; gap: 8px; }
.itg-range output { font-variant-numeric: tabular-nums; color: var(--primary); font-weight: 600; }
.itg-range input[type=range] { width: 100%; accent-color: var(--primary); }
.itg-preview { margin: 0 0 8px; text-align: center; background: #000; border-radius: 12px; padding: 8px; }
.itg-preview img { max-width: 100%; height: auto; max-height: 70vh; width: auto; }
/* Winston-Lutz : vignettes de démo */
.wl-demos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.wl-demos form { margin: 0; }
.wl-demo { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-size: .85rem; cursor: pointer; }
.wl-demo:hover, .wl-demo:focus-visible { border-color: var(--primary, #5e00b2); }
.wl-demo img { width: 100%; max-width: 100px; height: auto; border-radius: 6px; }

/* ---------- Pied de page ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--bg-soft); padding: 36px 0 28px; margin-top: 48px; font-size: .92rem; color: var(--ink-soft); }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .footer-grid { grid-template-columns: 1fr; } }
.site-footer h4 { margin: 0 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: 6px; }
.site-footer a { color: var(--ink-soft); text-decoration: none; }
.site-footer a:hover { color: var(--primary); }

/* ---------- Consentement ---------- */
.consent { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 60; max-width: 560px; margin-left: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(23,18,31,.18); padding: 18px 20px; }
.consent[hidden] { display: none; }
.consent p { margin: 0 0 12px; font-size: .95rem; }
.consent .actions { margin-top: 0; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Analyse experte IA (Markdown rendu) — Picket Fence, CBCT */
.ai-analysis { max-width: none; }
.ai-analysis table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 12px 0; display: block; overflow-x: auto; }
.ai-analysis th, .ai-analysis td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.ai-analysis th { background: var(--primary-soft); }
.ai-analysis h1, .ai-analysis h2, .ai-analysis h3 { font-size: 1.1rem; margin-top: 1.2em; }

/* Marie AI — chat */
.chat { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.chat-msg { display: flex; }
.chat-user { justify-content: flex-end; }
.chat-bubble { max-width: min(760px, 100%); padding: 12px 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); overflow-wrap: anywhere; }
.chat-user .chat-bubble { background: var(--primary); color: var(--on-primary); border-color: var(--primary); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.chat-assistant .chat-bubble { background: var(--bg-soft); border-bottom-left-radius: 4px; }
.chat-assistant .chat-bubble > :last-child { margin-bottom: 0; }
.chat-error { background: var(--ko-soft) !important; color: var(--ko-ink); border-color: var(--ko-line) !important; }
.chat-form { position: sticky; bottom: 12px; }

/* ---------- Thème sombre : choix du visiteur (data-theme) ou, à défaut, réglage du système ---------- */
:root[data-theme="dark"] {
  --primary: #c39bff; --primary-strong: #dcc4ff; --primary-soft: #2a1b40; --accent: #8ea2ff;
  --ink: #ece8f3; --ink-soft: #c6bfd2; --muted: #9d95ab; --line: #322c3e;
  --bg: #121017; --bg-soft: #18151f; --surface: #1d1926; --header-bg: rgba(18, 16, 23, .92);
  --on-primary: #1a0535; --chip: #29243a; --hero-1: #2a1640; --hero-2: #141b38;
  --ok: #4ade80; --ok-soft: #0f2a1a; --ok-ink: #bbf7d0; --ok-line: #1f5133;
  --ko: #f87171; --ko-soft: #331616; --ko-ink: #fecaca; --ko-line: #5f2525;
  --warn: #fbbf24; --warn-soft: #2e2511; --warn-ink: #fde68a; --warn-line: #5b4a1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #c39bff; --primary-strong: #dcc4ff; --primary-soft: #2a1b40; --accent: #8ea2ff;
    --ink: #ece8f3; --ink-soft: #c6bfd2; --muted: #9d95ab; --line: #322c3e;
    --bg: #121017; --bg-soft: #18151f; --surface: #1d1926; --header-bg: rgba(18, 16, 23, .92);
    --on-primary: #1a0535; --chip: #29243a; --hero-1: #2a1640; --hero-2: #141b38;
    --ok: #4ade80; --ok-soft: #0f2a1a; --ok-ink: #bbf7d0; --ok-line: #1f5133;
    --ko: #f87171; --ko-soft: #331616; --ko-ink: #fecaca; --ko-line: #5f2525;
    --warn: #fbbf24; --warn-soft: #2e2511; --warn-ink: #fde68a; --warn-line: #5b4a1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
/* Les figures matplotlib et visuels d'outils ont un fond blanc : on les garde sur blanc. */

/* ---------- Bouton de thème, bouton retour ---------- */
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; order: 2; }
.site-nav { order: 1; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer; padding: 0; }
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.back-bar { padding-top: 18px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); text-decoration: none; font-weight: 500; font-size: .92rem; padding: 6px 12px 6px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.back-link:hover { color: var(--primary); border-color: var(--primary); }
.back-link svg { width: 16px; height: 16px; transition: transform .15s; }
.back-link:hover svg { transform: translateX(-2px); }
.back-bar + .section, .back-bar + .hero { padding-top: 24px; }
@media (max-width: 860px) { .site-nav { order: 3; } }
