/* contract-agent — feuille de style unique, sans dépendance externe. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #637083;
  --border: #e2e6ec;
  --primary: #2453d4;
  --primary-text: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e6f4ec;
  --warning: #8a5a00;
  --warning-bg: #fff4dc;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info: #234a9c;
  --info-bg: #e8effc;
  --code-bg: #f1f3f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1f27;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2c333f;
    --primary: #5b85f0;
    --ok: #6fd39b;
    --ok-bg: #173826;
    --warning: #f2c46b;
    --warning-bg: #3a2e14;
    --danger: #f59a90;
    --danger-bg: #3d1d1a;
    --info: #9db8f7;
    --info-bg: #1d2a47;
    --code-bg: #232a35;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; overflow-wrap: anywhere; }

.container { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 24px; padding-bottom: 24px; }
.footer { color: var(--muted); font-size: .8rem; padding-bottom: 32px; }

/* En-tête */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.badge {
  font-size: .7rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 .35em; margin-left: .25em;
}
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a:hover { background: var(--bg); text-decoration: none; }
nav a[aria-current="page"] { color: var(--text); background: var(--bg); font-weight: 600; }

/* Mise en page */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: .25rem 0 0; max-width: 75ch; }
.breadcrumb { margin: 0 0 .5rem; font-size: .9rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 20px; }
.grid-2:not(.grid-even) { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.ask-panel { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 16px; min-width: 0; max-height: calc(100vh - 32px); overflow-y: auto; }
@media (max-width: 900px) {
  .grid-2, .grid-2:not(.grid-even) { grid-template-columns: minmax(0, 1fr); }
  .ask-panel { position: static; max-height: none; overflow: visible; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; margin-bottom: 16px;
}
.stack > .card, .ask-panel > .card, .grid-2 > .card { margin-bottom: 0; }
.card-attention { border-left: 3px solid var(--warning); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary h2 { display: inline; }
details.card > summary::before { content: "▸ "; color: var(--muted); }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: .75rem; }

/* Statistiques */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-warning .stat-value { color: var(--warning); }

/* Tableaux */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
th a { color: inherit; }
th a.sorted { color: var(--text); }
th a.sorted::after { content: " ↑"; }
tbody tr:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }

/* Étiquettes */
.tag { display: inline-block; font-size: .75rem; padding: 0 .5em; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); }
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1em .6em; border-radius: 999px; margin: 1px 0; white-space: nowrap; }
.pill-ok { color: var(--ok); background: var(--ok-bg); }
.pill-warning { color: var(--warning); background: var(--warning-bg); }
.pill-danger { color: var(--danger); background: var(--danger-bg); }
.pill-info { color: var(--info); background: var(--info-bg); }
.pill-muted { color: var(--muted); background: var(--code-bg); }
.art { font-size: .75rem; color: var(--info); background: var(--info-bg); padding: 0 .4em; border-radius: 4px; white-space: nowrap; }

.chips, .suggestions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.suggestions { margin: 12px 0 0; }
.chip {
  font: inherit; font-size: .85rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; cursor: pointer; text-align: left;
}
.chip:hover { border-color: var(--primary); text-decoration: none; }
.chip[aria-current="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* Alertes */
.alert { border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; overflow-wrap: anywhere; }
.alert-ok { color: var(--ok); background: var(--ok-bg); }
.alert-warning { color: var(--warning); background: var(--warning-bg); }
.alert-danger { color: var(--danger); background: var(--danger-bg); }
.alert-info { color: var(--info); background: var(--info-bg); }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 32px; text-align: center; color: var(--muted); }

/* Clé / valeur */
.kv { display: grid; grid-template-columns: minmax(110px, 34%) minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.clauses { margin: 0; padding-left: 1.1rem; }
.clauses li { margin-bottom: .4rem; }
.articles { margin: 0; padding-left: 1.4rem; columns: 2 280px; column-gap: 24px; }
.articles li { break-inside: avoid; margin-bottom: .3rem; }
.history { margin: 0; padding-left: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Formulaires */
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 12px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], textarea, select {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
label.inline select { width: auto; margin: 0; }
input[type="file"] { display: block; margin-top: 6px; font: inherit; font-weight: 400; max-width: 100%; }
textarea { resize: vertical; margin: 0 0 10px; }
textarea:focus, input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 1px; }
.form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-block; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-small { font-size: .8rem; padding: 4px 10px; }
.usermenu { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.usermenu form { margin: 0; }
.usermenu a { color: var(--muted); }
.usermenu a[aria-current="page"] { color: var(--text); font-weight: 600; }
.auth-box { max-width: 440px; margin: 40px auto; }
.auth-box h1 { margin-top: 0; }
.auth-box .stack { gap: 4px; }
.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-form select { width: auto; margin: 0; padding: 4px 8px; }
td.actions { display: table-cell; }
td.actions form { display: inline-block; margin: 0 4px 4px 0; }
code.secret { font-size: 1.05rem; padding: 2px 8px; user-select: all; }
button:disabled { opacity: .55; cursor: wait; }
progress { width: 100%; height: 8px; accent-color: var(--primary); }

/* Indicateur HTMX (styles par défaut de htmx désactivés pour la CSP) */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; }
.spinner { align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.spinner::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Réponses */
.answer .question { font-weight: 600; margin: 0 0 .5rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.route { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 .5rem; }
.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-size: 1rem; margin: 1rem 0 .4rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose table { margin: .5rem 0; font-size: .9rem; display: block; overflow-x: auto; }
.prose blockquote, .excerpt { margin: .5rem 0; padding: .4rem .8rem; border-left: 3px solid var(--border); color: var(--muted); }
.excerpt { white-space: pre-wrap; font-size: .85rem; max-height: 320px; overflow-y: auto; }
.sources { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.sources summary { cursor: pointer; font-weight: 600; }
.sources ol { padding-left: 1.3rem; }
.sources li { margin: .5rem 0; }
.src { font-size: .75rem; white-space: nowrap; }
.src a { color: var(--muted); border-bottom: 1px dotted var(--border); }
.src a:hover { color: var(--primary); text-decoration: none; }
.group-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 1rem 0 .3rem; }
.group-title:first-of-type { margin-top: 0; }
.pieces { margin: 0; padding-left: 1.1rem; }
.pieces li { margin-bottom: .3rem; overflow-wrap: anywhere; }
.party { padding: 10px 0; border-top: 1px solid var(--border); }
.party:first-of-type { border-top: 0; padding-top: 0; }
.party-head { margin-bottom: 6px; overflow-wrap: anywhere; }
.kv-tight { gap: 3px 14px; font-size: .92rem; }
.code { background: var(--code-bg); padding: 8px 10px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
