/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:    #5b6ef5;
  --brand-dk: #3b4fd4;
  --bg:       #f0f2f8;
  --surface:  #ffffff;
  --border:   #e2e6f0;
  --text:     #1a202c;
  --muted:    #718096;
  --green:    #38a169;
  --red:      #e53e3e;
  --orange:   #dd6b20;
  --radius:   12px;
  --shadow:   0 2px 12px rgba(0,0,0,.08);
  --sidebar-w:300px;
  --header-h: 70px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ───────────────────────────────────────────────────── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  display: flex; align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.header-left { display: flex; align-items: center; gap: .75rem; }
.logo { font-size: 2rem; }
.header-left h1 { font-size: 1.25rem; font-weight: 700; }
.header-left .subtitle { font-size: .75rem; opacity: .75; }

.header-stats { display: flex; gap: .75rem; margin-left: auto; }
.stat-pill {
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: .4rem .9rem;
  display: flex; flex-direction: column; align-items: center;
  min-width: 80px;
}
.stat-label { font-size: .65rem; opacity: .8; text-transform: uppercase; letter-spacing: .5px; }
.stat-val { font-size: 1.1rem; font-weight: 700; }

.header-actions { display: flex; gap: .5rem; margin-left: 1rem; }

/* ── Layout ───────────────────────────────────────────────────── */
.layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.sidebar-title {
  padding: 1rem 1.25rem .75rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.agents-list { overflow-y: auto; padding: .75rem; flex: 1; display: flex; flex-direction: column; gap: .5rem; }

.agent-card {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all .18s ease;
  background: #fafbff;
}
.agent-card:hover { border-color: var(--brand); background: #eef1ff; transform: translateX(3px); }
.agent-card.active { border-color: var(--brand); background: #eef1ff; box-shadow: 0 0 0 3px rgba(91,110,245,.12); }

.card-name { font-weight: 700; font-size: .95rem; margin-bottom: .35rem; }
.card-client { font-size: .75rem; color: var(--muted); margin-bottom: .5rem; }
.card-phone { font-size: .8rem; font-family: 'Courier New', monospace; color: var(--brand-dk); margin-bottom: .4rem; }
.card-tech { font-size: .7rem; color: var(--muted); }

/* Status badges */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-running { background: #c6f6d5; color: #276749; }
.badge-stopped { background: #fed7d7; color: #9b2335; }
.badge-unknown  { background: #e2e8f0; color: #4a5568; }

/* ── Main panel ───────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: var(--muted);
}
.welcome-icon { font-size: 4rem; margin-bottom: 1rem; }
.welcome h2 { font-size: 1.4rem; margin-bottom: .5rem; color: #4a5568; }

/* Agent detail layout */
.agent-detail { display: flex; flex-direction: column; gap: 1.25rem; }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-head h3 { font-size: 1rem; font-weight: 700; }
.card-body { padding: 1.25rem; }

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .75rem;
}
.info-item {
  background: #f7f9ff;
  border-radius: 8px;
  padding: .75rem;
  border-left: 3px solid var(--brand);
}
.info-item .info-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); margin-bottom: .3rem;
}
.info-item .info-val { font-size: .95rem; font-weight: 600; word-break: break-all; }

/* Prompt editor */
.prompt-editor {
  width: 100%;
  min-height: 380px;
  padding: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: .82rem;
  line-height: 1.65;
  resize: vertical;
  background: #fafbff;
  color: var(--text);
  transition: border-color .2s;
}
.prompt-editor:focus { outline: none; border-color: var(--brand); }

.prompt-meta { font-size: .75rem; color: var(--muted); margin-top: .4rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem;
  border: none; border-radius: 8px;
  font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: all .18s ease;
  text-decoration: none;
}
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dk); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(91,110,245,.35); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-outline { background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.3); }
.btn-outline:hover { background: rgba(255,255,255,.25); }
.btn-sm { padding: .35rem .75rem; font-size: .78rem; }
.btn-group { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .9rem; }

/* Config JSON editor */
.json-editor {
  width: 100%;
  min-height: 220px;
  padding: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: .8rem;
  line-height: 1.6;
  resize: vertical;
  background: #fafbff;
}
.json-editor:focus { outline: none; border-color: var(--brand); }

/* Backups list */
.backups-list { display: flex; flex-direction: column; gap: .35rem; }
.backup-item {
  display: flex; align-items: center; gap: .5rem;
  font-size: .78rem; color: var(--muted);
  padding: .3rem .5rem; border-radius: 6px;
  border: 1px solid var(--border);
}

/* ── Modal logs ───────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-box {
  background: #1a1a2e;
  border-radius: var(--radius);
  width: 90vw; max-width: 860px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  color: white;
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
  background: none; border: none; color: white;
  font-size: 1.1rem; cursor: pointer; opacity: .7;
}
.modal-close:hover { opacity: 1; }
.logs-pre {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
  font-family: 'Menlo', monospace;
  font-size: .75rem;
  line-height: 1.55;
  color: #a0f0a0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300;
  padding: .8rem 1.4rem;
  border-radius: 10px;
  font-weight: 600; font-size: .9rem;
  color: white;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  transition: opacity .3s;
}
.toast.hidden { display: none; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.info    { background: var(--brand); }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2rem; color: var(--muted); font-size: .85rem; }

/* ── Divider ──────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }

/* ── Calls table ──────────────────────────────────────────────── */
.calls-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.calls-table th {
  text-align: left;
  padding: .5rem .75rem;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.calls-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.calls-table tr:last-child td { border-bottom: none; }
.calls-table tr:hover td { background: #f7f8fc; }

/* ── Transcript modal ─────────────────────────────────────────── */
.transcript-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.transcript-line {
  padding: .5rem .9rem;
  border-radius: 8px;
  font-size: .85rem;
  line-height: 1.5;
}
.transcript-agent {
  background: #eef2ff;
  border-left: 3px solid var(--brand);
}
.transcript-user {
  background: #f0fdf4;
  border-left: 3px solid var(--green);
}
.transcript-line strong {
  display: block;
  font-size: .7rem;
  opacity: .6;
  margin-bottom: .2rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Call table enriched ──────────────────────────────────────── */
.call-phone { font-family: monospace; font-size: .82rem; }
.call-dir   { font-size: .8rem; white-space: nowrap; }
.call-src   {
  display: inline-block;
  padding: .15rem .45rem;
  background: #edf2f7;
  border-radius: 6px;
  font-size: .7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.call-status {
  display: inline-block;
  padding: .25rem .6rem;
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.call-status-ok   { background: #c6f6d5; color: #22543d; }
.call-status-ko   { background: #fed7d7; color: #742a2a; }
.call-status-live { background: #fff3cd; color: #744210; }
.call-status-unk  { background: #e2e8f0; color: #4a5568; }

/* Bouton Voir */
.btn-see {
  padding: .3rem .7rem;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.btn-see:hover { background: var(--brand-dk); }

/* ── Pagination ───────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding: .6rem .75rem;
  background: #f7fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.pagination-btn {
  padding: .4rem 1rem;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.pagination-btn:hover:not(:disabled) { background: var(--brand-dk); }
.pagination-btn:disabled { background: #cbd5e0; cursor: not-allowed; }
.pagination-info { font-size: .82rem; color: var(--muted); font-weight: 500; }

/* ── Create Agent button ──────────────────────────────────────── */
.btn-create-agent {
  width: 100%;
  padding: .65rem .75rem;
  margin-bottom: .75rem;
  background: linear-gradient(135deg, var(--brand), #764ba2);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: .02em;
  transition: opacity .15s, transform .15s;
}
.btn-create-agent:hover { opacity: .9; transform: translateY(-1px); }

/* ── Modal XL (create agent) ──────────────────────────────────── */
.modal-xl {
  width: 92%;
  max-width: 860px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.create-agent-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
}

/* ── Form sections ────────────────────────────────────────────── */
.form-section {
  background: #f7fafc;
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
}
.form-section-title {
  font-weight: 700;
  font-size: .92rem;
  color: var(--text);
  margin-bottom: .9rem;
  letter-spacing: .02em;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: .4rem;
}
.form-group label small {
  font-weight: 400;
  font-size: .72rem;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: .5rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  font-family: inherit;
  background: white;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand);
}
.form-group input[type="range"] {
  padding: 0;
  border: none;
  background: none;
  accent-color: var(--brand);
}
.form-group small {
  font-size: .72rem;
  color: var(--muted);
}
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr;     gap: .85rem; margin-bottom: .85rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .85rem; margin-bottom: .85rem; }
.form-row-2:last-child,
.form-row-3:last-child { margin-bottom: 0; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Monitoring page ──────────────────────────────────────────── */
.mon-wrap {
  padding: calc(var(--header-h) + 1.5rem) 1.5rem 2rem;
  max-width: 1300px;
  margin: 0 auto;
}

/* Alertes */
.mon-alert {
  padding: .7rem 1.1rem;
  border-radius: 8px;
  margin-bottom: .6rem;
  font-size: .85rem;
  font-weight: 600;
}
.mon-alert-ok       { background:#c6f6d5; color:#22543d; border-left:4px solid #38a169; }
.mon-alert-warning  { background:#fefcbf; color:#744210; border-left:4px solid #dd6b20; }
.mon-alert-critical { background:#fed7d7; color:#742a2a; border-left:4px solid #e53e3e; }

/* Grille cartes */
.mon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}
.mon-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.mon-card-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .5rem;
}
.mon-val {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: .3rem;
}
.mon-val small {
  font-size: .9rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: .25rem;
}
.mon-sub {
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: .7rem;
  min-height: 1rem;
}
.mon-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.mon-bar-fill {
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 3px;
  transition: width .5s ease, background .3s;
}

/* Graphiques */
.mon-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1rem;
}
.mon-chart-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.mon-chart-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .75rem;
}
.mon-chart-box canvas { height: 180px !important; }
