:root {
  --green: #243b34; --green-2: #2f4b42; --green-soft: #e3ece6; --cream: #f6f3ed; --paper: #fffdf9;
  --gold: #b49a6a; --gold-soft: #f3ead8; --ink: #1f2e29; --muted: #6b7671; --line: #e7e0d3;
  --red: #b4473b; --red-soft: #f7e1dd; --blue: #3c6e8f; --blue-soft: #e1ecf3;
  --bubble-in: #ffffff; --bubble-out: #dfeee4; --chat-bg: #efe8dc;
  --radius: 12px; --shadow: 0 1px 2px rgba(20,35,30,.06), 0 6px 18px rgba(20,35,30,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--cream); color: var(--ink); font: 14px/1.5 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; margin: 0 0 12px; }
h1 { font-size: 30px; } h2 { font-size: 24px; }
h3 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
a { color: var(--green); }
input, select, textarea, button { font: inherit; color: inherit; }

/* ---------- Boutons ---------- */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer; background: #ece6da; color: var(--ink); white-space: nowrap; transition: filter .15s, transform .05s; }
.btn:hover { filter: brightness(.96); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--green); color: var(--cream); }
.btn.gold { background: var(--gold); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; color: var(--red); border-color: #e9cbc6; }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px; }
.btn.big { padding: 11px 22px; font-size: 15px; }
.link { background: none; border: 0; color: var(--green); text-decoration: underline; cursor: pointer; padding: 0; font-size: 13px; }

/* ---------- Connexion ---------- */
#login { min-height: 100vh; display: grid; place-items: center; background: var(--green); padding: 16px; }
.login-card { background: var(--paper); border-radius: 18px; padding: 34px 30px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { height: 46px; display: block; margin: 0 auto 14px; filter: brightness(0) saturate(100%) invert(19%) sepia(14%) saturate(1046%) hue-rotate(108deg) brightness(93%) contrast(88%); }
.login-card h1 { text-align: center; font-size: 26px; margin-bottom: 20px; }

/* ---------- Barre du haut ---------- */
.topbar { height: 60px; background: var(--green); display: flex; align-items: center; gap: 14px; padding: 0 18px; position: sticky; top: 0; z-index: 20; }
.brand img { height: 30px; display: block; }
.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tabs a { color: #d9d4c8; text-decoration: none; padding: 8px 14px; border-radius: 9px; font-weight: 600; display: flex; gap: 6px; align-items: center; }
.tabs a.active, .tabs a:hover { background: rgba(255,255,255,.1); color: #fff; }
.spacer { flex: 1; }
.count:empty { display: none; }
.count { background: var(--gold); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.agent-filter { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 9px; padding: 7px 10px; }
.agent-filter option { color: var(--ink); }
.menu { position: relative; }
.avatar-btn { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--gold); background: var(--gold-soft); color: var(--green); font-weight: 700; cursor: pointer; }
.menu-pop { position: absolute; right: 0; top: 44px; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow), 0 10px 30px rgba(0,0,0,.15); min-width: 220px; padding: 6px; z-index: 30; }
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); background: none; border: 0; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--cream); }
#banner:empty { display: none; }
#banner { background: var(--gold-soft); color: #6b5426; padding: 8px 18px; font-size: 13px; border-bottom: 1px solid #e9dcc0; }
#banner a { color: inherit; font-weight: 600; }

/* ---------- Boîte de réception ---------- */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 60px); }
.inbox.with-details { grid-template-columns: 340px minmax(0, 1fr) 340px; }
#banner:not(:empty) ~ #view .inbox { height: calc(100vh - 96px); }
.list { background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.search { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--cream); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; font-weight: 500; }
.filter.on { background: var(--green); color: #fff; border-color: var(--green); }
.filter b { margin-left: 3px; }
.items { overflow-y: auto; flex: 1; }
.item { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #f1ece2; cursor: pointer; align-items: center; text-decoration: none; color: inherit; }
.item:hover { background: #faf6ee; }
.item.sel { background: var(--green-soft); }
.av { width: 42px; height: 42px; border-radius: 50%; background: var(--gold-soft); color: var(--green); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.item .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .p { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .r { text-align: right; display: grid; gap: 4px; justify-items: end; }
.item .t { font-size: 11px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); display: inline-block; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: #ece6da; color: var(--ink); white-space: nowrap; }
.tag.gold { background: var(--gold-soft); color: #7c6431; }
.tag.green { background: var(--green-soft); color: #24573c; }
.tag.red { background: var(--red-soft); color: #8b3027; }
.tag.blue { background: var(--blue-soft); color: #2b5470; }
.empty-list { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Conversation ---------- */
.conv { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.conv-head { background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.conv-head .who { min-width: 0; }
.conv-head .who b { font-size: 16px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .who span { font-size: 12.5px; color: var(--muted); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: min(560px, 78%); padding: 8px 11px 6px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); font-size: 14.2px; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 3px; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 3px; }
.bubble .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble .doc { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.05); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-weight: 600; text-decoration: none; color: var(--ink); }
.bubble audio { display: block; width: 250px; max-width: 100%; height: 36px; margin-bottom: 4px; }
.day { align-self: center; font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.6); padding: 2px 10px; border-radius: 99px; margin: 8px 0; }

/* Zone d'action (bas de conversation) */
.dock { background: var(--paper); border-top: 1px solid var(--line); padding: 12px 16px 14px; display: grid; gap: 10px; max-height: 60%; overflow-y: auto; }
.working { display: flex; align-items: center; gap: 8px; color: var(--blue); font-size: 13px; font-weight: 500; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.card-action { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: #fff; }
.card-action.gold { border-color: #e4d3ae; background: #fffaf0; }
.card-action .title { font-weight: 600; display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-bottom: 8px; }
.prop-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid #f1ece2; }
.prop-row:first-of-type { border-top: 0; }
.prop-row .pt { font-weight: 600; font-size: 13.5px; }
.prop-row .ps { font-size: 12px; color: var(--muted); }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.composer { display: grid; gap: 8px; }
.composer .label { font-size: 12px; font-weight: 600; color: #7c6431; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.composer textarea, .card-action textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; background: #fff; min-height: 46px; line-height: 1.45; }
.composer.ai textarea { border-color: #dcc79a; background: #fffcf4; }
.composer textarea:focus, .card-action textarea:focus { outline: none; border-color: var(--green); }
.why { font-size: 12.5px; color: var(--muted); }
.why summary { cursor: pointer; }
.why div { white-space: pre-wrap; background: var(--cream); border-radius: 8px; padding: 8px 10px; margin-top: 6px; }
.warn { color: var(--red); font-size: 12.5px; }
.sim { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sim input { flex: 1; min-width: 180px; border: 1px dashed var(--blue); border-radius: 8px; padding: 6px 10px; background: var(--blue-soft); }
.kbd { font-size: 11px; opacity: .75; margin-left: 6px; }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 30px; }
.placeholder h2 { color: var(--ink); }

/* ---------- Panneau détails ---------- */
.details { background: var(--paper); border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 16px 20px; }
.details h3:first-child { margin-top: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.field { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff; }
.prop { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: #fff; }
.prop .pt { font-weight: 600; font-size: 13.5px; }
.prop .u { font-size: 11.5px; word-break: break-all; color: var(--muted); }
.internal { margin-top: 6px; font-size: 12px; }
.internal summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.events { font-size: 12px; max-height: 240px; overflow-y: auto; }
.events div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.events time { color: var(--muted); margin-right: 6px; }

/* ---------- Suivi (pipeline) ---------- */
.page { padding: 22px 26px; max-width: 1400px; }
.strip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: #ece6da; color: var(--muted); }
.chip.has { background: var(--green); color: var(--cream); }
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 250px; background: #efe9de; border-radius: var(--radius); padding: 10px; }
.col h3 { display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.lcard { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: pointer; display: block; text-decoration: none; color: inherit; }
.lcard:hover { border-color: var(--gold); }
.lcard .n { font-weight: 600; }
.lcard .s { font-size: 12px; color: var(--muted); margin: 4px 0 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Paramètres ---------- */
.settings { display: grid; grid-template-columns: 220px minmax(0, 760px); gap: 24px; }
.side-tabs { display: grid; gap: 2px; align-content: start; }
.side-tabs a { padding: 9px 12px; border-radius: 9px; text-decoration: none; color: var(--ink); font-weight: 500; }
.side-tabs a.active { background: var(--green); color: var(--cream); }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel p.hint { margin-top: 0; }
table.team { width: 100%; border-collapse: collapse; }
table.team th, table.team td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.team th { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.status { font-size: 13px; margin-top: 6px; }
.status.ok { color: #24573c; } .status.ko { color: var(--red); }
code.copy { background: var(--cream); padding: 3px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }

/* ---------- Formulaires & dialogues ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label input:not([type=checkbox]):not([type=radio]), label select, label textarea { display: block; width: 100%; margin-top: 5px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; color: var(--ink); background: #fff; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-weight: 500; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chips label { margin: 0; }
.chips input { display: none; }
.chips span { display: inline-block; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); cursor: pointer; color: var(--ink); font-weight: 500; background: #fff; }
.chips input:checked + span { background: var(--green); color: #fff; border-color: var(--green); }
.more summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog { border: 0; border-radius: 16px; padding: 24px; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); background: var(--paper); }
dialog::backdrop { background: rgba(20,35,30,.45); }
#dlg-json { width: min(820px, 96vw); }
#json-editor { width: 100%; font: 12px/1.45 ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--muted); }
.error { color: var(--red); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--green); color: var(--cream); padding: 11px 18px; border-radius: 10px; opacity: 0; transition: all .2s; pointer-events: none; z-index: 60; max-width: 90vw; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
  .inbox.with-details { grid-template-columns: 300px minmax(0, 1fr); }
  .inbox.with-details .details { position: fixed; right: 0; top: 60px; bottom: 0; width: min(360px, 92vw); z-index: 15; box-shadow: -10px 0 30px rgba(0,0,0,.12); }
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .tabs { margin-left: 0; } .tabs a { padding: 8px 9px; }
  .brand { display: none; }
  #btn-new { padding: 8px 12px; }
  .agent-filter { max-width: 110px; }
  .inbox, .inbox.with-details { grid-template-columns: 1fr; }
  .inbox.open .list { display: none; }
  .inbox:not(.open) .conv { display: none; }
  .back { display: inline-flex; }
  .messages { padding: 14px 10px; }
  .settings { grid-template-columns: 1fr; }
  .side-tabs { grid-auto-flow: column; overflow-x: auto; }
  .row2 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}

.details-close { display: none; justify-content: flex-end; padding-top: 10px; }
@media (max-width: 1199px) { .details-close { display: flex; } }
