/* CSForm AI Agent — interface
   Encre #1D2433 · papier #FFFFFF · bureau #EEF1F5 · tampon indigo #2A3F8F */
:root {
  --ink: #1d2433; --ink-2: #3a4458; --muted: #5d677a; --line: #d9dee7; --line-2: #e8ebf1;
  --paper: #ffffff; --desk: #eef1f5; --desk-2: #f6f7fa;
  --accent: #2a3f8f; --accent-ink: #ffffff; --accent-soft: #e7ebf7;
  --ok: #1f7a4d; --ok-soft: #e6f3ec; --warn: #a15c00; --warn-soft: #fbf0df; --err: #b42318; --err-soft: #fbeceb;
  --radius: 8px; --radius-lg: 12px;
  --side: 248px; --panel: 330px;
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e9f0; --ink-2: #c7cddb; --muted: #9aa3b5; --line: #343c4d; --line-2: #2a3140;
    --paper: #1b2130; --desk: #131823; --desk-2: #171d2a;
    --accent: #8ea2ec; --accent-ink: #10162a; --accent-soft: #252f4d;
    --ok: #5cc493; --ok-soft: #1c3329; --warn: #e3a54d; --warn-soft: #3a2d17; --err: #f08a7e; --err-soft: #3c2120;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--desk); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.boot { padding: 40px; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { background: var(--desk-2); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; font-size: .9em; }

/* ---------- structure ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 15px; }
.side .new { margin: 4px 14px 12px; }
.nav { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--desk-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .grp { margin: 16px 10px 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.me { border-top: 1px solid var(--line); padding: 12px 14px; font-size: .88rem; display: flex; align-items: center; gap: 10px; }
.me .who { flex: 1; min-width: 0; }
.me .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who span { color: var(--muted); font-size: .8rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: none; }
.page { padding: 28px 32px 48px; max-width: 1180px; width: 100%; }
.page h1 { font-size: 1.55rem; letter-spacing: -.015em; margin: 0 0 4px; }
.page .sub { color: var(--muted); margin: 0 0 22px; }
.head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head .grow { flex: 1; min-width: 200px; }
.head h1 + .sub { margin-bottom: 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 14, 25, .45); }
  .top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .top b { flex: 1; }
  .page { padding: 18px 14px 40px; }
}

/* ---------- éléments ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--paper); cursor: pointer; font-weight: 600; font-size: .92rem; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.danger.solid { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: .84rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.iconbtn { border: 0; background: transparent; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; }
.iconbtn:hover { background: var(--desk-2); color: var(--ink); }
.iconbtn svg { width: 18px; height: 18px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 1.05rem; margin: 0 0 12px; }
.card h3 { font-size: .95rem; margin: 16px 0 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

label.f { display: block; font-weight: 600; font-size: .86rem; margin: 12px 0 4px; }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); }
textarea.in { resize: vertical; min-height: 90px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: .92rem; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--desk-2); color: var(--ink-2); border: 1px solid var(--line-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.pill.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.alert { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; }
.alert.err { border-color: var(--err); background: var(--err-soft); }
.alert.ok { border-color: var(--ok); background: var(--ok-soft); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; }
.stat b { display: block; font-size: 1.5rem; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .85rem; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ---------- modale & notifications ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 25, .5); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: var(--paper); border-radius: var(--radius-lg); width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 20px 22px; border: 1px solid var(--line); }
.modal.wide { width: min(860px, 100%); }
.modal h2 { margin: 0 0 12px; font-size: 1.15rem; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 8px; font-size: .9rem; }
.toast.err { background: var(--err); color: #fff; }

/* ---------- connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { font-size: 1.4rem; margin: 14px 0 2px; }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-columns: 1fr var(--panel); height: 100vh; min-height: 0; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--paper); }
.chat-head .title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode button { border: 0; background: var(--paper); padding: 5px 10px; font-size: .82rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.mode button.on { background: var(--accent); color: var(--accent-ink); }
.thread { flex: 1; overflow-y: auto; padding: 22px 20px 12px; }
.thread-inner { max-width: 820px; margin: 0 auto; }
.welcome { text-align: left; max-width: 620px; margin: 6vh auto 0; }
.welcome h2 { font-size: 1.5rem; letter-spacing: -.015em; margin: 0 0 6px; }
.welcome p { color: var(--muted); margin: 0 0 18px; }
.examples { display: grid; gap: 8px; }
.examples button { text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: 9px; padding: 10px 13px; cursor: pointer; color: var(--ink-2); }
.examples button:hover { border-color: var(--accent); color: var(--ink); }

.msg { margin: 0 0 16px; display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 86%; padding: 10px 14px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant .bubble.err { border-color: var(--err); background: var(--err-soft); }
.msg .att { font-size: .8rem; opacity: .85; margin-top: 4px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble h3, .bubble h4 { margin: 10px 0 6px; font-size: 1rem; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* carte de tâche */
.task { border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-lg); margin: 0 0 18px; overflow: hidden; }
.task-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.task-top b { font-size: .9rem; }
.pipe { display: flex; gap: 0; font-size: .74rem; font-weight: 600; color: var(--muted); flex-wrap: wrap; }
.pipe span { padding: 2px 8px; position: relative; }
.pipe span + span::before { content: "›"; position: absolute; left: -3px; color: var(--line); }
.pipe span.done { color: var(--ok); }
.pipe span.now { color: var(--accent); }
.task-body { padding: 12px 14px; }
.plan { margin: 0 0 10px; padding-left: 20px; font-size: .9rem; }
.plan li { margin: 2px 0; }
.steps { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.steps li { display: flex; gap: 8px; padding: 5px 0; border-top: 1px dashed var(--line-2); align-items: baseline; }
.steps li:first-child { border-top: 0; }
.steps .ic { width: 16px; flex: none; text-align: center; font-weight: 700; }
.steps .t { flex: 1; min-width: 0; }
.steps .d { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.ic.running { color: var(--accent); } .ic.success { color: var(--ok); } .ic.partial, .ic.waiting { color: var(--warn); } .ic.error { color: var(--err); } .ic.skipped { color: var(--muted); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* suivi par fichier : le « tampon » */
.batch { margin-top: 12px; border-top: 1px solid var(--line-2); padding-top: 10px; }
.batch-sum { font-size: .86rem; margin-bottom: 8px; display: flex; gap: 12px; flex-wrap: wrap; }
.bfile { display: grid; grid-template-columns: 1fr 120px auto; gap: 10px; align-items: center; padding: 6px 0; font-size: .86rem; }
.bfile .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bfile .m { grid-column: 1 / -1; color: var(--muted); font-size: .78rem; margin-top: -4px; }
.bar { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.bar.success i { background: var(--ok); } .bar.attention i { background: var(--warn); } .bar.error i { background: var(--err); }
.stamp { font-size: .7rem; font-weight: 700; letter-spacing: .02em; padding: 1px 6px; border: 1.5px solid currentColor; border-radius: 3px; transform: rotate(-4deg); display: inline-block; white-space: nowrap; }
.stamp.success { color: var(--ok); } .stamp.attention { color: var(--warn); } .stamp.error { color: var(--err); } .stamp.processing, .stamp.pending { color: var(--muted); transform: none; border-style: dashed; }
.stamp.fresh { animation: stamp .35s ease-out; }
@keyframes stamp { from { transform: rotate(-4deg) scale(1.6); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }
@media (max-width: 600px) { .bfile { grid-template-columns: 1fr auto; } .bfile .bar { display: none; } }

.confirm { border: 1.5px solid var(--warn); background: var(--warn-soft); border-radius: 9px; padding: 12px 14px; margin-top: 12px; }
.confirm b { display: block; margin-bottom: 4px; }
.results { margin-top: 12px; border-top: 1px solid var(--line-2); padding-top: 10px; }
.results .row { margin-top: 6px; }
.report-grid { display: flex; gap: 14px; flex-wrap: wrap; font-size: .86rem; margin-bottom: 8px; }

/* zone de saisie */
.composer { border-top: 1px solid var(--line); background: var(--paper); padding: 12px 20px 16px; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.queue { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.qi { display: grid; grid-template-columns: 1fr 90px 70px auto; gap: 10px; align-items: center; font-size: .84rem; background: var(--desk-2); border: 1px solid var(--line-2); border-radius: 7px; padding: 5px 8px; }
.qi .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qi.err { border-color: var(--err); color: var(--err); }
.qi .note { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); }
.box { border: 1px solid var(--line); border-radius: 12px; background: var(--paper); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.box:focus-within { border-color: var(--accent); }
.box textarea { border: 0; resize: none; padding: 6px 8px; min-height: 48px; max-height: 220px; background: transparent; outline: none; }
.box .tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.drop { position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent); display: none; place-items: center; z-index: 20; font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.drop.on { display: grid; }

/* panneau espace de travail */
.ws { border-left: 1px solid var(--line); background: var(--paper); display: flex; flex-direction: column; min-height: 0; }
.ws-head { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.ws-head b { flex: 1; }
.ws-body { overflow-y: auto; flex: 1; padding: 8px 10px 16px; }
.ws h4 { font-size: .78rem; color: var(--muted); margin: 14px 6px 4px; font-weight: 600; }
.fi { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; font-size: .86rem; }
.fi:hover { background: var(--desk-2); }
.fi .ext { font-size: .66rem; font-weight: 700; width: 36px; text-align: center; border-radius: 4px; padding: 2px 0; background: var(--desk-2); border: 1px solid var(--line-2); color: var(--ink-2); flex: none; }
.ext.pdf { color: #b42318; } .ext.docx { color: #2a5bb8; } .ext.xlsx { color: #1f7a4d; } .ext.pptx { color: #b5541c; } .ext.zip { color: var(--muted); }
.fi .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fi .v { font-size: .72rem; color: var(--accent); font-weight: 700; }
.fi .acts { display: none; }
.fi:hover .acts, .fi:focus-within .acts { display: flex; }
.ws-exports .fi .n { font-weight: 600; }
@media (max-width: 1100px) {
  .chat { grid-template-columns: 1fr; height: calc(100vh - 0px); }
  .ws { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 92vw); z-index: 45; transform: translateX(100%); transition: transform .2s; }
  .ws.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 14, 25, .45); }
}
@media (max-width: 900px) { .chat { height: calc(100vh - 53px); } }

/* signatures */
.sigs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.sig { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--paper); overflow: hidden; }
.sig .img { height: 110px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, var(--desk-2) 0 8px, var(--paper) 8px 16px); border-bottom: 1px solid var(--line-2); }
.sig img { max-height: 90px; max-width: 90%; }
.sig .meta { padding: 10px 12px; font-size: .86rem; }
.pad { border: 1px dashed var(--muted); border-radius: 9px; background: #fff; touch-action: none; width: 100%; height: 180px; display: block; cursor: crosshair; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.tool-actions { font-size: .82rem; color: var(--muted); margin: 8px 0 0; padding-left: 18px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
pre.json { background: var(--desk-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 8px; font-size: .78rem; max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 4px 0 0; }
.ws-close { display: none; }
.ws-toggle { display: none; }
@media (max-width: 1100px) { .ws-close, .ws-toggle { display: inline-flex; } }
@media (max-width: 640px) {
  .chat-head { flex-wrap: wrap; padding: 10px 12px; row-gap: 8px; }
  .chat-head .title { flex-basis: 100%; order: -1; }
  .mode button { padding: 5px 8px; }
  .thread { padding: 14px 10px 8px; }
  .composer { padding: 10px 10px 12px; }
  .msg .bubble { max-width: 94%; }
}
.ws details > summary { list-style: none; cursor: pointer; }
.ws details > summary::-webkit-details-marker { display: none; }
.ws details > summary h4::before { content: "▸ "; }
.ws details[open] > summary h4::before { content: "▾ "; }
