/* Alex — Agent commercial Praslas. Design sobre, pro, lisible. */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a202c;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --assistant-bg: #eff6ff;
  --client-bg: #f3f4f6;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #1a202c;
    --border: #2d3748;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --assistant-bg: #1e293b;
    --client-bg: #1a202c;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; font-size: 14px;
}

/* Header / nav */
header.app-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 52px; display: flex; align-items: center;
  gap: 24px; position: sticky; top: 0; z-index: 100;
}
header.app-header .brand { font-weight: 700; font-size: 16px; }
header.app-header .brand span { color: var(--primary); }
header.app-header nav { display: flex; gap: 4px; flex: 1; }
header.app-header nav a {
  padding: 8px 14px; border-radius: 6px; text-decoration: none;
  color: var(--text-muted); font-weight: 500; font-size: 13px;
}
header.app-header nav a:hover { background: var(--bg); color: var(--text); }
header.app-header nav a.active { background: var(--primary); color: white; }
header.app-header .me { color: var(--text-muted); font-size: 13px; }

/* Layout */
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border);
        border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }

/* Messages : layout 2 zones (liste + conversation), pattern MBM */
.msg-layout { display: flex; height: calc(100vh - 52px); }

/* Zone gauche : liste des threads (drawer 320px) */
.thread-list { width: 320px; flex-shrink: 0; background: var(--surface);
               border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.thread-list .search-bar { padding: 10px; border-bottom: 1px solid var(--border); }
.thread-list .search-bar input { width: 100%; padding: 8px 10px; border: 1px solid var(--border);
                                  border-radius: 6px; font-size: 13px; background: var(--bg); color: var(--text); }
.thread-list .items { flex: 1; overflow-y: auto; }
.thread-list .thread-item { padding: 10px 14px; border-bottom: 1px solid var(--border);
                            cursor: pointer; }
.thread-list .thread-item:hover { background: var(--bg); }
.thread-list .thread-item.selected { background: var(--assistant-bg); }
.thread-list .thread-item .row1 { display: flex; justify-content: space-between; align-items: center; }
.thread-list .thread-item .name { font-weight: 600; font-size: 13px; }
.thread-list .thread-item .time { font-size: 11px; color: var(--text-muted); }
.thread-list .thread-item .preview { color: var(--text-muted); font-size: 12px;
                                     white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.thread-list .thread-item .row2 { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.badge-ch { display: inline-block; font-size: 9px; font-weight: 700; color: white;
            padding: 2px 6px; border-radius: 3px; }
.badge-ch.email { background: #1976d2; }
.badge-ch.whatsapp { background: #25d366; }
.badge-ch.marketplace { background: #6e7781; }
.badge-pending { background: var(--warning); color: white; font-size: 9px; font-weight: 700;
                 padding: 2px 6px; border-radius: 3px; }

/* Zone centrale : conversation */
.conversation { flex: 1; display: flex; flex-direction: column; background: #fafafa; overflow: hidden; }
@media (prefers-color-scheme: dark) { .conversation { background: var(--bg); } }
.conv-header { padding: 8px 16px; border-bottom: 1px solid var(--border);
               background: var(--surface); display: flex; align-items: center; gap: 12px; }
.conv-header .client-name { font-weight: 700; font-size: 14px; }
.conv-header .client-detail { color: var(--text-muted); font-size: 12px; }
.conv-messages { flex: 1; overflow-y: auto; padding: 8px; }

/* Bulles pleine largeur (pattern MBM), pas gauche/droite */
.bubble { margin: 4px 0; padding: 8px 12px; border-radius: 4px;
          border-left: 3px solid var(--border); word-wrap: break-word; }
.bubble.client { background: #e9ecef; border-left-color: #1976d2; }
.bubble.assistant { background: #dbeafe; border-left-color: var(--primary); }
.bubble.assistant.sent { background: #d1fae5; border-left-color: var(--success); }
.bubble .bubble-head { display: flex; justify-content: space-between; font-size: 11px;
                       color: var(--text-muted); margin-bottom: 4px; }
.bubble .bubble-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.bubble .bubble-actions { margin-top: 6px; display: flex; gap: 6px; }
.bubble .status { font-size: 10px; font-weight: 600; text-transform: uppercase; }
.bubble .status.draft { color: var(--warning); }
.bubble .status.approved { color: var(--primary); }
.bubble .status.sent { color: var(--success); }

/* Composer (bas de la conversation) */
.conv-composer { border-top: 1px solid var(--border); background: var(--surface); padding: 8px; }
.conv-composer .gen-banner { background: var(--bg); padding: 6px 10px; border-radius: 4px;
                             font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: none; }
.conv-composer .gen-banner.active { display: block; }
.conv-composer .toolbar { display: flex; gap: 4px; margin-bottom: 6px; }
.conv-composer textarea { margin-bottom: 6px; }
.conv-composer .send-row { display: flex; justify-content: space-between; align-items: center; }

/* Panneau justification (commercial-only, dans un drawer repliable à droite) */
.justification-drawer { width: 300px; flex-shrink: 0; background: var(--surface);
                        border-left: 1px solid var(--border); overflow-y: auto; padding: 16px; display: none; }
.justification-drawer.open { display: block; }
.justification-drawer h3 { font-size: 14px; margin-bottom: 12px; }
.justification-drawer .field { margin-bottom: 12px; }
.justification-drawer .field label { font-size: 11px; color: var(--text-muted);
                                     text-transform: uppercase; letter-spacing: 0.5px; display: block; }
.justification-drawer .field .value { font-weight: 600; font-size: 14px; }
.justification-drawer .alert { background: #fef3c7; color: var(--warning);
                               padding: 8px 12px; border-radius: 6px; font-size: 12px; margin-top: 8px; }
.justification-drawer .empty { color: var(--text-muted); font-style: italic; font-size: 13px; }

/* Boutons */
button, .btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: 13px; font-weight: 500; transition: all 0.15s;
}
button:hover, .btn:hover { background: var(--bg); }
button.primary, .btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); }
button.success { background: var(--success); color: white; border-color: var(--success); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
textarea { width: 100%; border: 1px solid var(--border); border-radius: 6px;
           padding: 8px; font-family: inherit; font-size: 13px; resize: vertical; }

/* Login / pages simples */
.center-page { display: flex; align-items: center; justify-content: center;
               min-height: 100vh; text-align: center; }
.center-page .box { max-width: 400px; }
.center-page h1 { margin-bottom: 8px; }
.center-page p { color: var(--text-muted); margin-bottom: 20px; }

/* Joseph chat */
.chat-box { max-width: 700px; margin: 0 auto; }
.chat-history { min-height: 300px; }
.chat-input { display: flex; gap: 8px; margin-top: 16px; }
.chat-input input { flex: 1; padding: 10px; border: 1px solid var(--border);
                    border-radius: 6px; font-size: 14px; background: var(--surface); color: var(--text); }
.risk-green { color: var(--success); font-weight: 600; }
.risk-orange { color: var(--warning); font-weight: 600; }
.risk-red { color: var(--danger); font-weight: 600; }

/* Ressources */
.ressources-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.ressource-card { background: var(--surface); border: 1px solid var(--border);
                  border-radius: 8px; padding: 16px; text-decoration: none; color: var(--text); }
.ressource-card:hover { border-color: var(--primary); }
.ressource-card .icon { font-size: 24px; margin-bottom: 8px; }
.ressource-card .title { font-weight: 600; font-size: 13px; }
.ressource-card .desc { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
