/* ===== Agent Commercial IA — feuille de style ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --sidebar-bg: #0f172a;
  --sidebar-fg: #cbd5e1;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --green: #059669; --green-soft: #ecfdf5;
  --red: #dc2626;   --red-soft: #fef2f2;
  --orange: #d97706;--orange-soft: #fffbeb;
  --blue: #2563eb;  --blue-soft: #eff6ff;
  --gray-soft: #f3f4f6;
  --radius: 12px;
}
html { font-size: 15px; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px 28px 48px; max-width: 1720px; width: 100%; margin: 0 auto; }

/* ===== Sidebar ===== */
.brand { padding: 18px 18px 12px; }
.brand .logo { font-size: 1.05rem; font-weight: 700; color: #fff; display: block; }
.brand .sub { font-size: .75rem; color: #64748b; }
.sidenav { flex: 1; padding: 8px 10px; }
.sidenav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-fg); font-size: .92rem; margin-bottom: 2px;
}
.sidenav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidenav a.active { background: var(--accent); color: #fff; }
.sidenav .icon { width: 20px; text-align: center; }
.sidenav .count {
  margin-left: auto; background: rgba(255,255,255,.15); border-radius: 99px;
  font-size: .72rem; padding: 1px 8px; font-weight: 600;
}
.sidenav a.active .count { background: rgba(255,255,255,.25); }
.side-footer { padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.08); }
.side-footer form button {
  width: 100%; background: none; border: none; color: #94a3b8; cursor: pointer;
  padding: 8px 12px; text-align: left; font-size: .88rem; border-radius: 8px;
  font-family: inherit;
}
.side-footer form button:hover { background: rgba(255,255,255,.06); }
.agent-status { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: .8rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.dot.on { background: #34d399; box-shadow: 0 0 6px #34d39988; }
.dot.paused { background: #fbbf24; }

/* ===== Topbar ===== */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 12px 28px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: 1.15rem; font-weight: 650; margin-right: auto; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: .88rem; font-weight: 550; cursor: pointer;
  font-family: inherit; line-height: 1.3; white-space: nowrap;
}
.btn:hover { background: var(--gray-soft); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-danger { color: var(--red); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

/* ===== Cartes ===== */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { font-size: 1rem; font-weight: 650; margin-bottom: 12px; }
.card h2 .hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-header h2 { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
/* Fiches détaillées : colonnes qui s'adaptent à la largeur (1 → 3 colonnes) */
.detail-grid {
  display: grid; gap: 18px; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}
.detail-grid > div { min-width: 0; }

/* ===== KPI ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .value { font-size: 1.55rem; font-weight: 700; }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi a { color: inherit; text-decoration: none; }

/* ===== Tableaux ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--gray-soft); vertical-align: middle; }
table.data tr:hover td { background: #fafbfc; }
table.data tr.unread td { font-weight: 650; background: #fcfcff; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem;
  font-weight: 600; background: var(--gray-soft); color: var(--muted); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ===== Onglets ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 14px; font-size: .9rem; color: var(--muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px; font-weight: 550;
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { font-size: .75rem; background: var(--gray-soft); border-radius: 99px; padding: 1px 7px; margin-left: 4px; }

/* ===== Formulaires ===== */
label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], input[type=time], input[type=datetime-local],
select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; font-family: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr; } }
.field { margin-bottom: 12px; }
.field .helptext, .helptext { display: block; font-size: .76rem; color: var(--muted); margin-top: 3px; font-weight: 400; }
.field ul.errorlist, ul.errorlist { color: var(--red); font-size: .8rem; list-style: none; margin: 4px 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { margin: 0; font-weight: 500; }
.checkbox-row input { width: auto; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ===== Messages (toasts) ===== */
.messages { position: fixed; top: 14px; right: 14px; z-index: 100; width: 360px; max-width: 90vw; }
.messages .msg {
  padding: 11px 14px; border-radius: 10px; margin-bottom: 8px; font-size: .88rem;
  background: var(--card); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,.09);
  display: flex; gap: 8px; align-items: flex-start;
}
.messages .msg.success { border-left: 4px solid var(--green); }
.messages .msg.error { border-left: 4px solid var(--red); }
.messages .msg.warning { border-left: 4px solid var(--orange); }
.messages .msg.info { border-left: 4px solid var(--blue); }

/* ===== Email / fil de discussion ===== */
.mail-msg { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: var(--card); }
.mail-msg .head {
  padding: 10px 16px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  border-bottom: 1px solid var(--gray-soft); font-size: .85rem;
}
.mail-msg .head .who { font-weight: 650; }
.mail-msg .head .when { color: var(--muted); margin-left: auto; font-size: .8rem; }
.mail-msg .body { padding: 14px 16px; white-space: pre-wrap; font-size: .92rem; word-break: break-word; }
.mail-msg.out { border-left: 3px solid var(--accent); }
.mail-msg.in { border-left: 3px solid var(--border); }
.mail-msg .attachments { padding: 0 16px 10px; font-size: .8rem; color: var(--muted); }

/* ===== Draft (brouillon IA) ===== */
.draft-panel { border: 1px solid #c7d2fe; background: #f5f7ff; border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.draft-panel h3 { font-size: .95rem; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ===== Timeline CRM ===== */
.timeline { list-style: none; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-soft); }
.timeline .t-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--gray-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: .85rem; }
.timeline .t-body { flex: 1; min-width: 0; font-size: .88rem; }
.timeline .t-when { color: var(--muted); font-size: .76rem; }
.timeline .t-content { color: var(--muted); white-space: pre-wrap; word-break: break-word; }

/* ===== Divers ===== */
.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: .92rem; }
.empty .big { font-size: 1.8rem; display: block; margin-bottom: 6px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .84rem; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; font-size: .88rem; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar form.search { display: flex; gap: 8px; flex: 1; min-width: 220px; }
.toolbar form.search input[type=text] { max-width: 340px; }
.checklist { list-style: none; }
.checklist li { display: flex; gap: 10px; padding: 7px 0; align-items: center; font-size: .9rem; }
.checklist .state { width: 22px; text-align: center; }
hr.sep { border: none; border-top: 1px solid var(--gray-soft); margin: 14px 0; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { word-break: break-word; }
/* Aperçu de la signature HTML (réglages personnalité) */
.sig-preview {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  background: #fff; font-size: .9rem; line-height: 1.5;
}
.sig-preview img { max-width: 100%; height: auto; }

/* Aperçu markdown (base de connaissance) */
.md-preview { font-size: .9rem; }
.md-preview h1, .md-preview h2, .md-preview h3 { margin: 14px 0 6px; line-height: 1.3; }
.md-preview h1 { font-size: 1.15rem; } .md-preview h2 { font-size: 1.02rem; }
.md-preview h3 { font-size: .94rem; }
.md-preview p { margin: 6px 0; }
.md-preview ul, .md-preview ol { margin: 6px 0 6px 22px; }
.md-preview blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--muted); margin: 8px 0; }
.md-preview code { background: var(--gray-soft); border-radius: 4px; padding: 1px 5px; font-size: .82rem; }
.md-preview table { border-collapse: collapse; margin: 8px 0; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 5px 9px; font-size: .84rem; }

.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); }
.login-card { background: var(--card); border-radius: 14px; padding: 30px; width: 360px; max-width: 92vw; }
.login-card h1 { font-size: 1.2rem; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: .85rem; margin-bottom: 18px; }
.searchbox-lg { display: flex; gap: 10px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidenav { display: flex; flex-wrap: wrap; }
  .content { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
}
