:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --text: #17201c;
  --muted: #66736d;
  --line: #e2e7e4;
  --brand: #128c5e;
  --brand-dark: #0b6b47;
  --brand-soft: #e4f4ec;
  --side: #10231b;
  --side-text: #c9d8d0;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --info-soft: #eaf2fb;
  --bubble-in: #ffffff;
  --bubble-out: #dcf6e6;
  --chat-bg: #efeae2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 27, .06), 0 2px 8px rgba(16, 35, 27, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513; --panel: #17201c; --text: #e6ece9; --muted: #93a39b; --line: #26332d;
    --brand: #2fb67f; --brand-dark: #23986a; --brand-soft: #173a2b; --side: #0a100d; --side-text: #b4c4bc;
    --warn: #f0b04a; --warn-soft: #3a2c12; --danger: #f07167; --danger-soft: #3a1c1a; --info-soft: #172636;
    --bubble-in: #1f2a25; --bubble-out: #1d4a35; --chat-bg: #121a16;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.pad { padding: 16px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; padding: 4px 8px 18px; }
.logo-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 14px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sidebar nav a { color: var(--side-text); text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 12px; font-size: 13px; }
.sidebar-foot a { color: var(--side-text); }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; background: none; border: 0; font-size: 22px; color: var(--text); cursor: pointer; }
.content { padding: 24px 28px 48px; max-width: 1320px; }

/* Components */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel.flush { padding: 0; overflow: hidden; }
.panel.narrow { max-width: 720px; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.cols.wide-left { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.section-title { margin-top: 28px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar p { margin: 0; flex: 1; min-width: 240px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type=search] { min-width: 240px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.secondary { background: var(--panel); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.copied { background: var(--brand-soft); color: var(--brand); }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; font-size: 13px; padding: 4px 0; text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.form.compact label { margin-bottom: 8px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=search], input[type=time], input[type=datetime-local], input:not([type]), select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea.code, .code { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
label.check { flex-direction: row !important; align-items: flex-start; gap: 8px !important; font-weight: 400 !important; }
label.check input { margin-top: 3px; width: auto; }
.checks-inline { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks-inline legend { margin-bottom: 6px; font-weight: 600; }
.checks-inline label { margin: 0; }

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--brand-soft); border: 1px solid transparent; }
.notice.ok { background: var(--brand-soft); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--info-soft); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; background: var(--line); color: var(--text); font-size: 13px; text-decoration: none; }
.pill.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.pill.small { font-size: 11px; padding: 1px 8px; }
.score { display: inline-block; min-width: 30px; text-align: center; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; }

/* Statuts */
.st { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--line); white-space: nowrap; }
.st-nouveau, .fill.st-nouveau { background: #e6e9f2; color: #44506b; }
.st-contacte, .fill.st-contacte { background: #e3edf9; color: #2a5d9f; }
.st-en_discussion, .fill.st-en_discussion { background: #e9e4f8; color: #5b3fa8; }
.st-qualifie, .fill.st-qualifie { background: #fff1d6; color: #9a6300; }
.st-lien_envoye, .fill.st-lien_envoye { background: #fde8d7; color: #a6521a; }
.st-lien_clique, .fill.st-lien_clique { background: #ffe1e1; color: #a83737; }
.st-inscrit, .fill.st-inscrit { background: #d9f3e5; color: #0b6b47; }
.st-a_rappeler, .fill.st-a_rappeler { background: #ffe0ef; color: #a32763; }
.st-pas_interesse, .fill.st-pas_interesse { background: #eceeed; color: #6b7570; }
.cst { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--line); }
.cst-en_cours { background: var(--brand-soft); color: var(--brand); }
.cst-en_pause { background: var(--warn-soft); color: var(--warn); }
.cst-planifiee { background: var(--info-soft); }
.tst { font-size: 12px; font-weight: 700; }
.tst-approved { color: var(--brand); }
.tst-rejected, .tst-disabled, .tst-paused { color: var(--danger); }
.tst-pending, .tst-in_appeal { color: var(--warn); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.kpi strong { font-size: 28px; line-height: 1.2; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-hint { font-size: 12px; color: var(--muted); }

.bars { list-style: none; margin: 0 0 10px; padding: 0; }
.bars li { display: grid; grid-template-columns: 110px 1fr 40px; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.fill { display: block; height: 100%; border-radius: 5px; }
.bar-value { text-align: right; font-weight: 600; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 7px 8px; }
.table a { text-decoration: none; }
.pager { display: flex; gap: 6px; align-items: center; margin: 10px 0; }
.pager a, .pager span.current { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); text-decoration: none; }
.pager span.current { background: var(--brand); color: #fff; border-color: var(--brand); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); text-decoration: none; color: var(--text); font-size: 14px; }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Inbox */
.inbox { list-style: none; margin: 0; padding: 0; }
.inbox li { border-bottom: 1px solid var(--line); }
.inbox li a { display: flex; gap: 12px; padding: 12px 16px; text-decoration: none; color: var(--text); }
.inbox li a:hover { background: var(--bg); }
.inbox li.unread { background: var(--warn-soft); }
.avatar { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.inbox-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.inbox-top { display: flex; gap: 4px; align-items: baseline; }
.inbox-date { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.inbox-snippet { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Conversation */
.contact-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.chat-panel { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.chat-head { display: flex; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-actions { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; }
.chat-actions form { margin: 0; }
.chat-panel > .notice { margin: 10px 18px 0; }
.chat { background: var(--chat-bg); padding: 18px; height: 58vh; min-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat.sim { height: 50vh; }
.msg { max-width: 78%; padding: 7px 11px 5px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); display: flex; flex-direction: column; }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.msg.preview { max-width: 100%; align-self: stretch; margin-bottom: 14px; }
.msg-sender { font-size: 11px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .03em; }
.msg-body { word-wrap: break-word; overflow-wrap: anywhere; }
.msg-meta { align-self: flex-end; font-size: 11px; color: var(--muted); }
.msg-meta .read { color: #34b7f1; }
.msg-meta .failed, .msg-error { color: var(--danger); }
.msg-error { font-size: 12px; }
.composer { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel); }
.composer-form { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.composer-bar select { flex: 1; min-width: 200px; }
.composer form.inline { margin-top: 4px; }
.side .panel { margin-bottom: 14px; }
.summary { background: var(--brand-soft); padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.danger-zone { text-align: center; }

/* Paramètres de modèle */
.param-map { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.param-row { display: grid; grid-template-columns: 1.2fr 1fr 1.3fr; gap: 8px; align-items: center; font-size: 13px; }
.kv { display: grid; gap: 6px; margin: 6px 0 14px; }
.kv > div { display: grid; grid-template-columns: 220px 1fr; gap: 10px; }
.kv span { color: var(--muted); }
pre.copy { white-space: pre-wrap; background: var(--bg); border: 1px dashed var(--line); padding: 10px 12px; border-radius: 8px; font: 13px/1.5 system-ui, sans-serif; cursor: copy; }
pre.copy.copied { border-color: var(--brand); }
.copy-input { font-size: 13px !important; }
.link-out { display: flex; gap: 8px; margin: 6px 0 14px; }
.qr-wrap { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
#qr { background: #fff; padding: 10px; border-radius: 8px; border: 1px solid var(--line); min-height: 240px; min-width: 240px; }
.step .step-foot { display: flex; justify-content: space-between; align-items: center; }
.add-step { margin-top: 10px; }

/* Démarrage */
.steps { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.steps li.done { border-color: var(--brand); }
.steps li p { margin: 0; font-size: 14px; }
.steps h3 { margin-bottom: 4px; }
.step-num { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--line); font-weight: 700; }
.steps li.done .step-num { background: var(--brand); color: #fff; }
.steps li.todo .step-num { background: var(--warn-soft); color: var(--warn); }

/* Authentification / installation */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 760px; }
.auth-card .logo { color: var(--text); padding: 0 0 16px; }
.checks { list-style: none; padding: 0; columns: 2; font-size: 14px; }
.checks .ok { color: var(--brand); }
.checks .ko { color: var(--danger); font-weight: 700; }

@media (max-width: 1100px) {
  .contact-layout, .cols, .cols.wide-left { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -260px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .menu-btn { display: block; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .grid2, .grid3, .param-row, .kv > div { grid-template-columns: minmax(0, 1fr); }
  .msg { max-width: 92%; }
  .checks { columns: 1; }
  .filters input[type=search] { min-width: 0; width: 100%; }
}
