:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --border: #e1e7f0;
  --text: #172333;
  --muted: #64728a;
  --primary: #175a9c;
  --primary-dark: #0f3f70;
  --brand-maroon: #a4213c;
  --accent: #0e9e78;
  --danger: #c2352f;
  --warning: #c07c15;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 30, 55, 0.06), 0 8px 24px rgba(15, 30, 55, 0.06);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #0d1f38;
  color: #dfe6f5;
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  padding: 0 6px 18px;
  border-bottom: 2px solid var(--brand-maroon);
  margin-bottom: 14px;
  line-height: 1.3;
}
.sidebar .brand img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar .brand small { display:block; font-weight:400; opacity:.6; font-size:.72rem; margin-top:4px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  color: #c3cde3;
  font-size: 0.92rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .ic { width: 18px; text-align:center; }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 34px 60px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0 0 4px; font-size: 1.5rem; }
.page-header p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }
.card h3 { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 14px;
  }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 6px; }
  .sidebar nav a { margin-bottom: 0; }
  .main { padding: 18px 14px 40px; }
  .card { overflow-x: auto; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .inline-fields { flex-direction: column; }
  .inline-fields > div { min-width: 0; width: 100%; }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .num { font-size: 1.7rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 0.82rem; }

button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 8px;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .btn:hover { border-color: #c7cede; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.accent, .btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger, .btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small, .btn.small { padding: 5px 10px; font-size: 0.78rem; }

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
label { font-size: 0.82rem; color: var(--muted); display:block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.inline-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-fields > div { flex: 1; min-width: 140px; }

table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .02em; }
tr:hover td { background: #fafbff; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #eef1fb;
  color: var(--primary-dark);
}
.badge.ok { background: #e4f7f0; color: #0d8f6c; }
.badge.warn { background: #fdf1e0; color: var(--warning); }
.badge.err { background: #fbe7e5; color: var(--danger); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: #eef1fb; color: var(--primary-dark); border-radius: 6px;
  padding: 3px 8px; font-size: 0.76rem; display:flex; align-items:center; gap:5px;
}
.tag button.small { border: none; background: none; padding: 0; color: var(--danger); }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 999; display:flex; flex-direction:column; gap:8px; }
.toast {
  background: #1c2333; color:#fff; padding: 11px 16px; border-radius: 8px;
  font-size: 0.86rem; box-shadow: var(--shadow); min-width: 220px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: #0d8f6c; }

/* Grille d'emploi du temps */
.timetable {
  display: grid;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.78rem;
}
.timetable .cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 5px;
  min-height: 46px;
  position: relative;
}
.timetable .head { background: #f2f4fa; font-weight: 600; text-align: center; padding: 8px 4px; }
.timetable .time-col { background: #f8f9fd; font-weight: 600; text-align:center; display:flex; align-items:center; justify-content:center; }
.timetable .pause-row,
.timetable-table .pause-row { background: #fdecd2; }
.timetable-table tr:has(.pause-row) .time-col { background: #fce3ba; color: #8a5a10; }
.session-block {
  border-left: 3px solid var(--primary);
  border-radius: 5px; padding: 4px 6px; height: 100%;
  color: var(--text);
}
.session-block .mat { font-weight: 700; display:block; }
.session-block .prof { color: var(--muted); font-size: 0.72rem; }
.slot-empty { color: #c3c9db; font-size: 0.72rem; text-align:center; padding-top: 10px; }
.slot-empty:hover { background: #f7f8fc; cursor: pointer; }

/* Assistant IA - chat */
.chat-wrap {
  display: flex; flex-direction: column; height: calc(100vh - 220px); min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 16px 22px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}
.chat-header .chat-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0;
}
.chat-header .chat-title { font-weight: 700; font-size: 1rem; }
.chat-header .chat-subtitle { font-size: 0.78rem; opacity: 0.85; }

.stepper { display: flex; padding: 14px 22px; border-bottom: 1px solid var(--border); background: #f9fafc; gap: 4px; overflow-x: auto; }
.stepper .step { display: flex; align-items: center; gap: 7px; font-size: 0.76rem; color: var(--muted); white-space: nowrap; padding: 4px 10px 4px 4px; border-radius: 99px; }
.stepper .step .num {
  width: 21px; height: 21px; border-radius: 50%; background: #e2e6ef; color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}
.stepper .step.done .num { background: var(--accent); color: #fff; }
.stepper .step.done .num::before { content: "\f00c"; font-family: "Font Awesome 6 Free"; font-weight: 900; }
.stepper .step.active { background: #eaf1fc; color: var(--primary-dark); font-weight: 700; }
.stepper .step.active .num { background: var(--primary); color: #fff; }
.stepper .sep { flex: 1; min-width: 8px; max-width: 24px; height: 1px; background: var(--border); align-self: center; }

.chat-messages { flex: 1; overflow-y: auto; padding: 22px; display:flex; flex-direction:column; gap:16px; }
.msg-row { display: flex; gap: 10px; max-width: 88%; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center;
  justify-content: center; font-size: 0.85rem; margin-top: 2px;
}
.msg-row .avatar.ai { background: var(--primary); color: #fff; }
.msg-row .avatar.user { background: #dfe6f0; color: var(--text); }
.msg { padding: 12px 16px; border-radius: 14px; font-size: 0.9rem; line-height:1.55; white-space: pre-wrap; }
.msg.ai { background: #f1f4fb; border-bottom-left-radius: 3px; }
.msg.user { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.msg .choices { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; align-items:center; }
.chat-input {
  border-top: 1px solid var(--border); padding: 14px 18px; display:flex; gap:10px; align-items:flex-end; background: var(--surface);
}
.chat-input textarea { resize: none; min-height: 40px; max-height: 140px; }

.print-only { display: none; }
#print-area { display: none; }
body.exporting #print-area { display: block; padding: 20px; }
body.exporting .app-shell { display: none !important; }

.table-scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.timetable-table { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 0.78rem; }
.timetable-table th, .timetable-table td { border: 1px solid var(--border); }
.timetable-table .time-col { background: #f8f9fd; font-weight: 600; text-align: center; white-space: nowrap; }

@media print {
  .sidebar, .page-header .actions, .no-print { display: none !important; }
  .app-shell, .main { display: block; padding: 0; margin:0; }
  body { background: #fff; }
  .print-only { display: block; }
  #print-area { display: block; }
  body:not(.exporting) #print-area { display: none; }
}
