:root {
  --primary-dark: #0b3d66;
  --primary: #1565a8;
  --primary-light: #2d7dd2;
  --accent: #3fb8af;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1a2b3c;
  --text-secondary: #6b7c93;
  --border: #e1e8f0;
  --danger: #d2422d;
  --warning: #e0a800;
  --success: #2e9e5b;
  --sidebar: #0e2f4f;
  --sidebar-hover: #16456f;
  --sidebar-selected: #2d7dd2;
  --radius: 10px;
  --shadow: 0 4px 14px rgba(26, 43, 60, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

#app { height: 100vh; display: flex; }

/* ---------- Boutons ---------- */
button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: 7px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: #eaf3fb; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: #fbeae6; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cartes ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Champs ---------- */
label { font-size: 13px; color: var(--text-secondary); display: block; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45, 125, 210, 0.15);
}
textarea { resize: vertical; min-height: 60px; }

.field-row { display: flex; gap: 12px; }
.field-row > div { flex: 1; }

/* ---------- Auth (connexion/inscription) ---------- */
.auth-screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--primary-dark), #133a59 60%, #0b2740);
}
.auth-box {
  width: 440px;
  max-width: 92vw;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  overflow: hidden;
}
.auth-header {
  background: var(--primary-dark);
  padding: 28px 24px 22px;
  text-align: center;
  color: white;
}
.auth-header h1 { margin: 0; font-size: 26px; }
.auth-header p { margin: 6px 0 0; font-size: 13px; color: #aecbe6; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; text-align: center; padding: 14px; background: none; border: none;
  font-weight: 600; color: var(--text-secondary); border-bottom: 3px solid transparent;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-body { padding: 24px; max-height: 60vh; overflow-y: auto; }
.auth-error {
  background: #fbeae6; color: var(--danger); padding: 10px 12px;
  border-radius: 6px; font-size: 13px; margin: 10px 0;
}
.auth-hint { font-size: 11.5px; color: var(--text-secondary); margin-top: 4px; }

/* ---------- Layout principal ---------- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  color: white;
}
.sidebar-header { text-align: center; padding: 22px 12px 16px; }
.sidebar-header .logo { font-size: 19px; font-weight: 800; }
.sidebar-header .doc-name { font-size: 12px; color: #9fc1dd; margin-top: 6px; }
.sidebar-header .doc-specialty { font-size: 11px; color: #6c93b5; }

.nav { flex: 1; overflow-y: auto; padding: 6px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 7px; margin-bottom: 2px;
  color: #cbdcec; font-size: 14px; cursor: pointer; user-select: none;
  background: none; border: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-selected); color: white; font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { padding: 14px; }
.sidebar-footer .btn { width: 100%; color: white; border-color: #3e6488; }

/* ---------- Contenu ---------- */
.content { flex: 1; overflow-y: auto; padding: 28px 32px; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.page-title { font-size: 24px; font-weight: 700; margin: 0; }
.subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.search-input { max-width: 320px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card { padding: 18px 20px; }
.kpi-label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.kpi-value { font-size: 30px; font-weight: 800; color: var(--primary-dark); }

@media (max-width: 1000px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 10px 12px; color: var(--text-secondary); font-weight: 600; border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid #eef2f7; }
tr:hover td { background: #f7fafd; }
.table-actions { display: flex; gap: 6px; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-secondary); }
.empty-state .big-icon { font-size: 42px; margin-bottom: 10px; }

/* ---------- Layout deux colonnes (liste + formulaire) ---------- */
.two-col { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- Modale ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 35, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: white; border-radius: 12px; width: 800px; max-width: 95vw;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: white;
}
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-secondary); line-height: 1; }
.modal-body { padding: 20px 22px; }

/* ---------- Onglets dossier patient ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  background: none; border: none; padding: 9px 14px; font-size: 13.5px;
  color: var(--text-secondary); border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-blue { background: #e3f0fb; color: var(--primary); }
.badge-green { background: #e4f6ea; color: var(--success); }
.badge-orange { background: #fdf1de; color: var(--warning); }
.badge-red { background: #fbeae6; color: var(--danger); }
.badge-gray { background: #eef1f5; color: var(--text-secondary); }

/* ---------- Agenda ---------- */
.agenda-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.agenda-toolbar .period-label { font-weight: 700; font-size: 15px; min-width: 220px; }
.view-switch { display: flex; gap: 4px; margin-left: auto; }
.view-switch button {
  background: white; border: 1px solid var(--border); padding: 8px 14px;
  font-size: 13px; border-radius: 6px; color: var(--text-secondary); font-weight: 600;
}
.view-switch button.active { background: var(--primary); color: white; border-color: var(--primary); }

.agenda-grid { display: grid; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: white; }

/* Vue jour / semaine : grille horaire */
.agenda-time-grid { display: grid; grid-template-columns: 60px 1fr; }
.agenda-time-grid.week { grid-template-columns: 60px repeat(7, 1fr); }
.agenda-day-col-header, .agenda-time-cell-header { padding: 10px 6px; text-align: center; font-size: 12.5px; font-weight: 700; color: var(--text-secondary); border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); background: #fafcfe; }
.agenda-day-col-header.today { color: var(--primary); }
.hour-label { font-size: 11px; color: var(--text-secondary); padding: 4px 6px; text-align: right; border-top: 1px solid #f0f3f7; }
.hour-row { position: relative; border-top: 1px solid #f0f3f7; border-left: 1px solid var(--border); min-height: 46px; }
.hour-row.weekend { background: #fbfcfe; }

.agenda-event {
  position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 3px 7px;
  color: white; font-size: 11.5px; overflow: hidden; cursor: pointer; line-height: 1.3;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.agenda-event b { display: block; font-size: 12px; }

/* Vue mois */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-cell-header { padding: 8px; text-align: center; font-size: 12px; font-weight: 700; color: var(--text-secondary); background: #fafcfe; border-bottom: 1px solid var(--border); }
.month-cell {
  min-height: 100px; border-right: 1px solid #f0f3f7; border-bottom: 1px solid #f0f3f7;
  padding: 6px; font-size: 12px; vertical-align: top;
}
.month-cell .day-num { font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; }
.month-cell.today .day-num { color: var(--primary); }
.month-cell.other-month { background: #fafbfc; color: #c3cdd9; }
.month-event {
  background: var(--primary-light); color: white; border-radius: 4px; padding: 2px 5px;
  font-size: 10.5px; margin-bottom: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer;
}

.placeholder-module {
  text-align: center; padding: 80px 20px; color: var(--text-secondary);
}
.placeholder-module .big-icon { font-size: 50px; margin-bottom: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; overflow-x: auto; }
  .sidebar-header, .sidebar-footer { display: none; }
  .nav { display: flex; padding: 6px; }
  .nav-item { white-space: nowrap; }
  .content { padding: 18px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .agenda-time-grid.week { grid-template-columns: 40px repeat(7, minmax(90px, 1fr)); overflow-x: auto; }
}
