:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3348;
  --text: #e8eaf0;
  --text-muted: #8b90a5;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.logo { font-size: 1.25rem; font-weight: 700; }
.badge {
  margin-left: 1rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  background: var(--surface2);
  color: var(--text-muted);
}
.badge.connected { background: #166534; color: var(--green); }

.page { display: none; padding: 2rem; max-width: 1400px; margin: 0 auto; }
.page.active { display: block; }

.hero { text-align: center; margin-bottom: 3rem; }
.hero h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.hero p { color: var(--text-muted); }

.metier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metier-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  cursor: pointer;
  transition: all 0.2s;
}
.metier-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(99,102,241,0.15);
}
.metier-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.metier-card h3 { margin-bottom: 0.5rem; }
.metier-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.ext {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--accent-hover);
}
.metier-card { cursor: default; }
.metier-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(99,102,241,0.12);
}
.metier-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.metier-actions button,
.metier-actions a {
  flex: 1;
  min-width: 120px;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.metier-actions button {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.metier-actions button:hover { border-color: var(--accent); }
.metier-actions a {
  border: none;
  background: var(--accent);
  color: white;
}
.metier-actions a:hover { background: var(--accent-hover); }

.ivr-info {
  text-align: center;
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.ivr-info code {
  background: var(--surface2);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  color: var(--accent-hover);
}

/* Dashboard */
.dash-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}
.dash-header h2 { flex: 1; }
.btn-back, .btn-simulate {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-back { background: var(--surface2); color: var(--text); }
.btn-simulate { background: var(--accent); color: white; }
.btn-simulate:hover { background: var(--accent-hover); }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.panel h3 { margin-bottom: 1rem; font-size: 1rem; }
.rdv-panel, .agenda-panel { grid-column: span 1; }
.chat-panel { grid-row: span 2; }

.call-idle { text-align: center; padding: 2rem; color: var(--text-muted); }
.call-indicator {
  width: 60px; height: 60px;
  border-radius: 50%;
  margin: 0 auto 1rem;
  background: var(--green);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { box-shadow: 0 0 0 20px rgba(34,197,94,0); }
}
.hidden { display: none !important; }

.chat-messages {
  height: 300px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.5rem;
}
.chat-msg {
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: 85%;
}
.chat-msg.user { background: var(--surface2); margin-left: auto; }
.chat-msg.assistant { background: #1e1b4b; border: 1px solid #312e81; }
.chat-empty { color: var(--text-muted); text-align: center; padding: 2rem; }
.chat-input { display: flex; gap: 0.5rem; }
.chat-input input {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.chat-input button {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.agenda-list { display: flex; flex-direction: column; gap: 0.5rem; }
.agenda-item {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 0.85rem;
}
.agenda-time { color: var(--accent-hover); font-weight: 600; }

.rdv-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.rdv-table th {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.rdv-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.status-confirme { color: var(--green); }
.status-en_attente { color: var(--orange); }
.status-annule { color: var(--red); }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.stat-card {
  text-align: center;
  padding: 1rem;
  background: var(--surface2);
  border-radius: 8px;
}
.stat-value { display: block; font-size: 2rem; font-weight: 700; color: var(--accent-hover); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  .chat-panel { grid-row: auto; }
}

/* Cabinet (espace médecin / gestion) */
.btn-link {
  color: var(--accent-hover);
  text-decoration: none;
  margin-right: 1rem;
  font-size: 0.9rem;
}
.cabinet-main { padding: 1.5rem 2rem; max-width: 1200px; margin: 0 auto; }
.cabinet-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.cabinet-toolbar select {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
.toolbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-primary, .btn-call {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-call { background: var(--green); color: #052e16; }
.btn-ghost {
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.cabinet-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.cabinet-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}
.cabinet-tabs .tab {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  font-size: 0.9rem;
}
.cabinet-tabs .tab.active {
  color: var(--text);
  background: var(--surface2);
}
.cabinet-panel { display: none; }
.cabinet-panel.active { display: block; }
.card-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.rdv-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rdv-card-time {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-hover);
  min-width: 4rem;
}
.rdv-card-body { flex: 1; display: flex; flex-direction: column; gap: 0.2rem; }
.rdv-card-tel { color: var(--text-muted); font-size: 0.85rem; }
.rdv-card-motif { font-size: 0.9rem; }
.rdv-card-actions { display: flex; gap: 0.35rem; }
.btn-icon {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  cursor: pointer;
  font-size: 1rem;
}
.btn-icon.danger:hover { border-color: var(--red); }
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--text-muted); font-weight: 500; background: var(--surface2); }
.row-muted { opacity: 0.5; }
.actions-cell { white-space: nowrap; }
.btn-sm {
  padding: 0.3rem 0.6rem;
  margin-right: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
}
.btn-sm.danger:hover { border-color: var(--red); color: var(--red); }
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  text-transform: capitalize;
}
.status-confirme { background: #14532d; color: var(--green); }
.status-en_attente { background: #78350f; color: var(--orange); }
.status-annule { background: #7f1d1d; color: #fca5a5; }
.status-termine { background: var(--surface2); color: var(--text-muted); }
.empty-msg { color: var(--text-muted); padding: 2rem; text-align: center; }
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none !important; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
}
.modal-box h3 { margin-bottom: 1rem; }
.modal-sub { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.9rem; }
.modal-box label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.modal-box input, .modal-box select, .modal-box textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: #14532d;
  color: var(--green);
  border-radius: 8px;
  z-index: 200;
  font-size: 0.9rem;
}
.toast.error { background: #7f1d1d; color: #fca5a5; }
.toast.hidden { display: none; }

@media (max-width: 700px) {
  .cabinet-stats { grid-template-columns: 1fr; }
  .rdv-card { flex-wrap: wrap; }
}