/* AGENTE DSG — interface de contrôle */
:root {
  --ink: #14232b;
  --ink-2: #1d313b;
  --ink-3: #2a4450;
  --side-text: #c9d6dc;
  --accent: #f0a92e;
  --accent-ink: #3a2600;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --line: #e1e4de;
  --line-strong: #c9cdc6;
  --text: #1b2327;
  --muted: #66727a;
  --valid: #1f7a4d;   --valid-bg: #e3f3ea;
  --warn: #9a5b00;    --warn-bg: #fdf0d8;
  --danger: #b42318;  --danger-bg: #fbe5e2;
  --info: #1f5f99;    --info-bg: #e3eef8;
  --neutral-bg: #eceee9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 35, 43, .06), 0 1px 1px rgba(20, 35, 43, .04);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.prewrap { white-space: pre-wrap; }
.text-danger { color: var(--danger); }
.link { color: var(--info); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ---------- Marque ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; }
.brand small { display: block; color: var(--side-text); font-size: 11.5px; font-weight: 400; letter-spacing: .02em; }
.brand strong { display: block; font-size: 14.5px; letter-spacing: .04em; }
.brand-mark {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; letter-spacing: .04em;
}
.brand-lg { color: var(--text); padding: 0 0 8px; }
.brand-lg small { color: var(--muted); }

/* ---------- Connexion ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, var(--ink) 0 38%, var(--bg) 38% 100%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 28px;
  box-shadow: 0 20px 50px rgba(20, 35, 43, .18); display: grid; gap: 14px; }

/* ---------- Coquille ---------- */
.shell { display: flex; min-height: 100%; }
.sidebar { width: 236px; flex: 0 0 236px; background: var(--ink); color: var(--side-text); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#nav { flex: 1; padding: 4px 10px; }
.nav-group { padding: 6px 0; border-top: 1px solid rgba(255, 255, 255, .06); }
.nav-group:first-child { border-top: 0; }
.nav-caption { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d929b; padding: 6px 10px 2px; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px; text-decoration: none; color: var(--side-text); font-weight: 500; }
.nav-link span:first-child { flex: 1; }
.nav-link:hover { background: var(--ink-2); color: #fff; }
.nav-link.active { background: var(--ink-3); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-future { color: #8095a0; }
.nav-phase { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; border: 1px solid #3c5562; color: #8fa4ad; }
.nav-badge { min-width: 20px; padding: 0 6px; height: 20px; display: inline-grid; place-items: center; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); font-size: 11.5px; font-weight: 700; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); display: grid; gap: 8px; }
.user-name { color: #fff; font-weight: 600; }
.user-role { font-size: 12px; }
.sidebar .btn-ghost { color: var(--side-text); border-color: #3c5562; }
.sidebar .btn-ghost:hover { background: var(--ink-2); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }
.page[aria-busy="true"] { opacity: .6; transition: opacity .2s .15s; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* ---------- Cartes / grilles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow-x: auto; }
.card:not(.flush) { overflow-x: auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-title { font-size: 14px; font-weight: 650; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: 16px; }
.placeholder { display: grid; gap: 10px; justify-items: start; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; box-shadow: var(--shadow); position: relative; }
a.tile:hover { border-color: var(--line-strong); }
.tile-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile-muted .tile-value { color: var(--line-strong); }
.tile-muted .tile-note { color: var(--muted); font-weight: 600; }
.tile-warn { border-left: 4px solid var(--accent); }
.tile-danger { border-left: 4px solid var(--danger); }
.tile-danger .tile-value { color: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.row-start { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-end { display: flex; align-items: center; gap: 10px; text-align: right; }

.worker { display: flex; gap: 12px; align-items: flex-start; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot-on { background: var(--valid); box-shadow: 0 0 0 4px var(--valid-bg); }
.dot-off { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-bg); }

/* ---------- Tableaux ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbf9; white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: 7px 10px; }
.card:not(.flush) .table.compact th { background: transparent; }
.clickable { cursor: pointer; }
.clickable:hover td { background: #f8f9f6; }
.row-active td { background: var(--warn-bg); }
.cell-main { font-weight: 500; word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 36px 14px !important; }

/* ---------- Puces ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--neutral-bg); color: #4a555b; }
.chip-valid, .chip-completed, .chip-success, .chip-perm-allow { background: var(--valid-bg); color: var(--valid); }
.chip-expiring, .chip-high, .chip-waiting_approval, .chip-pending, .chip-perm-approval_required { background: var(--warn-bg); color: var(--warn); }
.chip-expired, .chip-failed, .chip-failure, .chip-denied, .chip-urgent, .chip-missing, .chip-perm-deny { background: var(--danger-bg); color: var(--danger); }
.chip-running, .chip-to_verify { background: var(--info-bg); color: var(--info); }
.chip-none { background: var(--neutral-bg); color: #5b666c; letter-spacing: .03em; }

.level { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.level-critical { background: var(--danger); }
.level-high { background: #e07b00; }
.level-medium { background: #e3c000; }
.level-info { background: var(--info); }

/* ---------- Alertes ---------- */
.alert-list { display: grid; gap: 10px; }
.alert-card { display: flex; justify-content: space-between; gap: 16px; align-items: center; background: var(--surface);
  border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.alert-card p { margin: 4px 0; }
.alert-main { min-width: 0; }
.level-border-critical { border-left-color: var(--danger); }
.level-border-high { border-left-color: #e07b00; }
.level-border-medium { border-left-color: #e3c000; }
.level-border-info { border-left-color: var(--info); }
.is-closed { opacity: .6; }

.banner { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; }
.banner-danger { background: var(--danger-bg); color: var(--danger); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Formulaires ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 280px; }
input, select, textarea { border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input, select { height: 38px; }
input[type="file"] { height: auto; padding: 7px; }
.toolbar input, .toolbar select { width: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(240, 169, 46, .3); }
input:disabled, select:disabled, textarea:disabled { background: #f6f7f4; color: var(--muted); }
textarea { resize: vertical; }
.form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.field { display: grid; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 600; color: #3e4a50; }
.field-hint { font-size: 11.5px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-error { margin: 0; padding: 9px 12px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); font-size: 13px; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: auto; min-height: 0; }
.collapsible { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.collapsible summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 38px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-3); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 4px 8px; cursor: pointer; border-radius: 6px; }
.icon-btn:hover { background: var(--neutral-bg); }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin: 12px 0; color: var(--muted); font-size: 13px; }
.pager span:first-child { margin-right: auto; }

/* ---------- Modale ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20, 35, 43, .45); display: grid; place-items: start center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 24px 60px rgba(0, 0, 0, .25); }
.modal-wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { word-break: break-word; }
.modal-body { padding: 18px 20px 22px; overflow-x: auto; }
.detail { display: grid; gap: 14px; }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; background: #f8f9f6; border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.detail-meta > div { display: grid; gap: 3px; justify-items: start; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.detail-actions input { flex: 1 1 200px; width: auto; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 6px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: baseline; }
.code { background: var(--ink); color: #dbe6ea; border-radius: 8px; padding: 12px; font: 12px/1.5 var(--mono); overflow-x: auto; margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: grid; gap: 8px; }
.timeline li { position: relative; display: flex; flex-wrap: wrap; gap: 6px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--line-strong); }

/* ---------- Notifications ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  transition: opacity .4s, transform .4s; font-weight: 500; border-left: 4px solid var(--info); }
.toast-success { border-left-color: #41b883; }
.toast-error { border-left-color: #ff6b5b; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .topbar-title { font-weight: 700; letter-spacing: .04em; }
  .page { padding: 18px 16px 40px; }
  .alert-card { flex-direction: column; align-items: stretch; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-end .muted { display: none; }
}

/* ---------- Fase 2 : analyse ---------- */
.label-row { display: inline-flex; align-items: center; gap: 6px; }
.origin { font-size: 10.5px; font-weight: 600; padding: 0 6px; border-radius: 99px; letter-spacing: .02em; text-transform: uppercase; }
.origin-user { background: var(--neutral-bg); color: #4a555b; }
.origin-auto { background: var(--info-bg); color: var(--info); }
.origin-rule { background: #efe6fb; color: #5b3a99; }
.analysis { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fcfcfa; }
.sub-title { font-size: 13px; font-weight: 650; margin: 4px 0 0; }
.conf { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.conf-track { width: 70px; height: 6px; border-radius: 99px; background: var(--neutral-bg); overflow: hidden; display: inline-block; }
.conf-fill { display: block; height: 100%; border-radius: 99px; }
.conf-high { background: var(--valid); }
.conf-mid { background: #e0a100; }
.conf-low { background: var(--danger); }
.text-ok { color: var(--valid); font-weight: 600; }
.extracted { max-height: 320px; overflow: auto; white-space: pre-wrap; background: #f6f7f4; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12px/1.5 var(--mono); margin: 0; }
.snippet { font-size: 12.5px; color: #4a555b; background: var(--warn-bg); border-radius: 6px; padding: 2px 6px; margin-top: 3px; display: inline-block; max-width: 560px; }
.banner-info { background: var(--info-bg); color: #1d4f7c; }
.banner-ok { background: var(--valid-bg); color: var(--valid); font-weight: 600; }
.banner .btn-small { margin-left: 10px; }
.btn-small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.input-small { width: 90px !important; display: inline-block; }
.find-results { display: grid; gap: 10px; }
.result-card { border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; }
.result-card.is-ok { border-left-color: var(--valid); }
.result-card.is-ko { border-left-color: var(--danger); }
.pill { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.pill-ok { background: var(--valid-bg); color: var(--valid); }
.pill-ko { background: var(--danger-bg); color: var(--danger); }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.check-list li { display: grid; grid-template-columns: 18px 80px 1fr; gap: 6px; align-items: baseline; }
.check-list .ok .check-icon { color: var(--valid); font-weight: 700; }
.check-list .ko .check-icon { color: var(--danger); font-weight: 700; }
.check-name { font-weight: 600; }
.detail-meta > div > span:not(.chip) { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }

/* ---------- Fase 3 : e-mails et approbations ---------- */
.approval-box { border: 2px solid var(--accent); background: #fffaf0; border-radius: 10px; padding: 12px 14px; }
.approval-title { font-weight: 700; font-size: 12.5px; letter-spacing: .04em; color: var(--warn); margin-bottom: 6px; }
.kv-list { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; margin: 0; font-size: 13.5px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.reply-body { font: 14px/1.55 var(--font); min-height: 260px; }
.draft-preview { white-space: pre-wrap; font-size: 13px; color: #3e4a50; margin: 6px 0 0; }
.old-draft { margin-top: 10px; }
.stack > .form { margin: 0; }

/* Fase 6: listas de caixas de verificação compactas */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 16px; }

/* Fase 7: pasta + estado numa só coluna (caminhos longos) */
.check-list .folder-line { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 4px 12px; min-width: 0; overflow-wrap: anywhere; }

/* Fase 8A */
.row-start.wrap { flex-wrap: wrap; }
.contact-row { grid-template-columns: 1fr 1.4fr 1fr auto auto; align-items: center; }
.tpl-row { grid-template-columns: 1.4fr 1.2fr 1fr auto auto; align-items: center; }
.command-card { display: grid; gap: 10px; }
@media (max-width: 760px) { .contact-row, .tpl-row { grid-template-columns: 1fr; } }
