/* ============ Thème (variables) ============ */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #3b82f6;
  --primary-ink: #ffffff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --ring: rgba(59, 130, 246, .35);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 10px;
}
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131a2a;
  --surface-2: #1b2436;
  --border: #283349;
  --text: #e8edf6;
  --muted: #93a1ba;
  --primary: #60a5fa;
  --primary-ink: #08111f;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --ring: rgba(96, 165, 250, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
#app.loading { display: grid; place-items: center; height: 100vh; color: var(--muted); }

a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }

/* ============ Boutons / champs ============ */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .6rem 1rem; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600; cursor: pointer; display: inline-flex;
  align-items: center; gap: .5rem; transition: .15s; line-height: 1;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.05); background: var(--primary); }
.btn-success { background: var(--success); border-color: var(--success); color: #042018; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #2a0707; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .4rem .65rem; font-size: .85rem; }
.btn-icon { padding: .5rem; border-radius: 50%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; transition: .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
label { display: block; font-size: .82rem; color: var(--muted); margin: 0 0 .3rem; font-weight: 600; }
.field { margin-bottom: .85rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* ============ Cartes ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.muted { color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }

/* ============ Layout dashboard ============ */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; padding: .4rem .6rem 1rem; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.nav-link {
  display: flex; align-items: center; gap: .7rem; padding: .65rem .75rem;
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none;
  font-weight: 600; cursor: pointer;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--primary); color: var(--primary-ink); }
.nav-link .ico { font-size: 1.1rem; }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .9rem 1.4rem;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .8rem; }
.content { padding: 1.4rem; max-width: 1200px; width: 100%; }

/* ============ Statuts ============ */
.status-todo { background: var(--surface-2); color: var(--muted); }
.status-in_progress { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning); }
.status-done, .status-corrige_ok { background: color-mix(in srgb, var(--success) 22%, transparent); color: var(--success); }
.status-skipped { background: var(--surface-2); color: var(--muted); }
.status-a_corriger { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning); }
.status-corrige_ko { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }

/* ============ Planning ============ */
.planning-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .6rem; }
.day-col { background: var(--surface-2); border-radius: var(--radius); padding: .6rem; min-height: 120px; }
.day-col h3 { text-align: center; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.slot { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius-sm); padding: .55rem .6rem; margin-bottom: .5rem; }
.slot .t { font-weight: 700; font-size: .9rem; }
.slot .meta { font-size: .78rem; color: var(--muted); }
.slot-actions { display: flex; gap: .3rem; margin-top: .4rem; flex-wrap: wrap; }

/* ============ Login ============ */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-box { width: 100%; max-width: 440px; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .9rem; margin-top: 1rem; }
.profile { cursor: pointer; text-align: center; padding: 1.1rem .6rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); transition: .15s; }
.profile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.profile .av { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto .5rem; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.3rem; }
.profile .nm { font-weight: 700; }
.profile .rl { font-size: .75rem; color: var(--muted); }

.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; max-width: 260px; margin: 1rem auto; }
.pinpad button { padding: 1rem; font-size: 1.2rem; font-weight: 700; }
.pin-dots { display: flex; justify-content: center; gap: .6rem; margin: 1rem 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--primary); border-color: var(--primary); }

/* ============ Modal & toast ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 540px; max-height: 90vh; overflow: auto; padding: 1.3rem; }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 999px;
  font-weight: 600; z-index: 100; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ============ Tâches & progression ============ */
.progress { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--success); border-radius: 999px; transition: width .35s ease; min-width: 0; }
.task { display: flex; align-items: center; gap: .8rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.task.done { background: color-mix(in srgb, var(--success) 8%, var(--surface)); }
.task.done .t { text-decoration: line-through; color: var(--muted); }
.task .t { font-weight: 600; }
.task .meta { font-size: .8rem; color: var(--muted); }
.task .check {
  width: 34px; height: 34px; min-width: 34px; padding: 0; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); color: var(--success);
  font-size: 1rem; font-weight: 800; cursor: pointer; display: grid; place-items: center; transition: .15s;
}
.task .check:hover { border-color: var(--success); }
.task .check.on { background: var(--success); border-color: var(--success); color: #fff; }

/* ============ Chat IA ============ */
.chat-log { height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .6rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.bubble { max-width: 85%; padding: .5rem .7rem; border-radius: 12px; font-size: .92rem; white-space: pre-wrap; line-height: 1.35; }
.bubble.ai { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; }
.bubble.user { background: var(--primary); color: var(--primary-ink); align-self: flex-end; }
.bubble.thinking { display: inline-flex; align-items: center; gap: .35rem; opacity: .85; }
.think-emoji { display: inline-block; animation: think-pulse 1.6s ease-in-out infinite; }
.think-dots { display: inline-flex; gap: 3px; }
.think-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .35; animation: think-bounce 1.2s ease-in-out infinite; }
.think-dots i:nth-child(2) { animation-delay: .2s; }
.think-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes think-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: .9; } }
@keyframes think-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .think-emoji, .think-dots i { animation: none; } }
.chat-row { display: flex; gap: .5rem; margin-top: .6rem; align-items: flex-end; }
.chat-row textarea { flex: 1; }

/* ============ Divers ============ */
.thumb { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.list { display: flex; flex-direction: column; gap: .8rem; }
.split { display: flex; gap: 1rem; align-items: flex-start; }
.exo-content { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--radius-sm); padding: .8rem; font-size: .92rem; }

/* ============ Suivi (dashboard heatmap type GitHub) ============ */
.suivi { display: flex; flex-direction: column; gap: 1rem; }
.dash-card { display: flex; flex-direction: column; gap: .8rem; }
.dash-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.dash-name { font-weight: 600; font-size: 1.05rem; }
.dash-stats { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }
.dash-pill { display: inline-flex; align-items: baseline; gap: .3rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .25rem .6rem; font-size: .82rem; }
.dash-pill b { font-size: .95rem; }
.dash-pill .dp-lbl { color: var(--muted); }

.hm-wrap { --hm-cell: 13px; overflow-x: auto; padding-bottom: .2rem; }
.hm-months { display: grid; gap: 0 3px; margin-bottom: 3px; }
.hm-mo { font-size: .68rem; color: var(--muted); white-space: nowrap; overflow: visible; }
.hm-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, var(--hm-cell)); grid-auto-columns: var(--hm-cell); gap: 3px; width: max-content; }
.hm-day { width: var(--hm-cell); height: var(--hm-cell); border-radius: 2px; background: var(--surface-2); border: 1px solid var(--border); }
.hm-day.out { background: transparent; border-color: transparent; }
.hm-day.lvl-1, .hm-day.lvl-2, .hm-day.lvl-3, .hm-day.lvl-4 { border-color: transparent; }
.hm-day.lvl-1 { opacity: .35; }
.hm-day.lvl-2 { opacity: .58; }
.hm-day.lvl-3 { opacity: .8; }
.hm-day.lvl-4 { opacity: 1; }
.hm-legend { display: flex; align-items: center; gap: 3px; font-size: .72rem; color: var(--muted); }
.hm-legend .hm-day { width: 12px; height: 12px; }
.hm-legend > span { margin: 0 .25rem; }

/* ============ Responsive (tablette / mobile) ============ */
@media (max-width: 840px) {
  .hm-wrap { --hm-cell: 11px; }
  .dash-stats { margin-left: 0; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto;
    flex-direction: row; justify-content: space-around; border-right: none;
    border-top: 1px solid var(--border); padding: .4rem; z-index: 20;
  }
  .brand, .sidebar .spacer, .sidebar .side-extra { display: none; }
  .nav-link { flex-direction: column; gap: .15rem; font-size: .7rem; padding: .4rem .3rem; }
  .nav-link .ico { font-size: 1.3rem; }
  .content { padding: 1rem; padding-bottom: 5rem; }
  .week-grid { grid-template-columns: 1fr; }
}
