/* ============================================================
   Mon Organiseur — styles
   Code couleur (exigence CLAUDE.md) :
     cours  : famille bleu/violet (CM bleu, TD violet, TP turquoise)
     DS     : rouge/orange vif, bordure épaisse + hachures → saute aux yeux
   ============================================================ */

:root {
  --bg: #f4f4f8;
  --card: #ffffff;
  --text: #17172b;
  --muted: #6b6b80;
  --line: #e4e4ee;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --danger: #dc2626;

  /* Cours */
  --cm-bg: #dbe7ff;  --cm-border: #2563eb; --cm-text: #1e3a8a;
  --td-bg: #ede4ff;  --td-border: #7c3aed; --td-text: #4c1d95;
  --tp-bg: #d8f4f1;  --tp-border: #0d9488; --tp-text: #134e4a;
  --other-bg: #ececf2; --other-border: #8b8ba3; --other-text: #3c3c52;

  /* DS : nettement différent, chaud et vif */
  --ds-bg: #ffe1d6;  --ds-border: #ea580c; --ds-text: #7c2d12; --ds-strong: #dc2626;

  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f17;
    --card: #1b1b28;
    --text: #f0f0f7;
    --muted: #9c9cb3;
    --line: #2c2c3d;
    --primary: #818cf8;
    --primary-soft: #23234a;
    --cm-bg: #1e2f5c;  --cm-border: #60a5fa; --cm-text: #dbe7ff;
    --td-bg: #33215c;  --td-border: #a78bfa; --td-text: #ede4ff;
    --tp-bg: #10393a;  --tp-border: #2dd4bf; --tp-text: #d8f4f1;
    --other-bg: #2a2a3a; --other-border: #9c9cb3; --other-text: #e4e4ee;
    --ds-bg: #5a1f10;  --ds-border: #fb923c; --ds-text: #ffe1d6; --ds-strong: #f87171;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12.5px; }
.center { text-align: center; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }

main {
  padding: 12px 12px calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  max-width: 900px; margin: 0 auto;
}

/* ---------- barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; position: relative;
}
.tab .ico { font-size: 22px; line-height: 1; }
.tab.active { color: var(--primary); font-weight: 600; }
.badge {
  position: absolute; top: 6px; right: calc(50% - 22px);
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- composants ---------- */
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card label { display: block; margin-top: 10px; font-size: 13px; color: var(--muted); }
.card label input, .card label select { margin-top: 4px; }

input[type=text], input[type=date], input[type=time], input[type=number], input[type=password], select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px; -webkit-appearance: none;
}
input[type=date], input[type=time] { min-height: 42px; }

.form .row { display: flex; gap: 10px; margin-top: 8px; }
.form .row > label { flex: 1; margin-top: 0; }
.form .row.actions { justify-content: flex-end; margin-top: 12px; }
.form > input[type=text] { margin-bottom: 4px; }
label.check { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; }
label.check input { width: 20px; height: 20px; margin: 0; }

.btn-primary, .btn-ghost, .btn-danger, .btn-small {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; font-size: 14px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: #fee2e2; color: var(--danger); margin-top: 10px; width: 100%; }
.btn-small { background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 6px 10px; font-size: 13px; }
.btn-icon {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 34px; height: 34px; border-radius: 10px; font-size: 20px; line-height: 1;
}
.full { width: 100%; margin-top: 10px; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; }

.segmented { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.segmented button.active { background: var(--primary); color: #fff; }
.segmented.small { margin: 4px 0 10px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.nav { display: flex; gap: 6px; align-items: center; }
.cal-title { font-weight: 700; font-size: 17px; margin: 10px 2px 6px; }
.cal-title::first-letter { text-transform: uppercase; }

.loading, .empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- légende ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.lg {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  border-left: 4px solid;
}
.lg-cm { background: var(--cm-bg); border-color: var(--cm-border); color: var(--cm-text); }
.lg-td { background: var(--td-bg); border-color: var(--td-border); color: var(--td-text); }
.lg-tp { background: var(--tp-bg); border-color: var(--tp-border); color: var(--tp-text); }
.lg-other { background: var(--other-bg); border-color: var(--other-border); color: var(--other-text); }
.lg-ds {
  background: var(--ds-bg); border-color: var(--ds-border); color: var(--ds-text);
  border: 2px solid var(--ds-border); border-left-width: 4px;
}
.lg-ds::before { content: "⚠️ "; }
.group-hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

/* ---------- vue semaine (grille horaire) ---------- */
/* Sur téléphone la grille défile horizontalement (colonnes ≥ 96px) pour rester lisible */
.cal-week-wrap {
  background: var(--card); border-radius: 14px; border: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.cal-week {
  display: grid;
  grid-template-columns: 34px repeat(var(--days, 5), minmax(96px, 1fr));
  min-width: 100%;
  --hour-h: 56px;
}
.wk-corner, .wk-day {
  padding: 6px 2px; text-align: center; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; background: var(--card); position: sticky; top: 0;
}
.wk-day small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.wk-day.today { color: var(--primary); }
.wk-day.today small { background: var(--primary); color: #fff; border-radius: 999px; display: inline-block; padding: 0 6px; }
.wk-hours { position: sticky; left: 0; z-index: 3; background: var(--card); border-right: 1px solid var(--line); }
.wk-corner { position: sticky; left: 0; z-index: 4; }
.wk-hour { height: var(--hour-h); font-size: 10px; color: var(--muted); text-align: right; padding-right: 4px; transform: translateY(-6px); }
.wk-col { position: relative; border-right: 1px solid var(--line); background:
  repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-h) - 1px), var(--line) calc(var(--hour-h) - 1px), var(--line) var(--hour-h));
}
.wk-col:last-child { border-right: 0; }
.wk-col.today { background-color: var(--primary-soft); }

.ev {
  position: absolute; left: 1px; right: 1px; overflow: hidden;
  border-radius: 6px; padding: 3px 4px; font-size: 11px; line-height: 1.2;
  border-left: 4px solid; cursor: pointer; user-select: none;
}
.ev b { display: block; font-size: 10.5px; font-weight: 700; }
.ev .ev-sub { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ev .ev-meta { display: block; opacity: .8; font-size: 9.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-cm { background: var(--cm-bg); border-color: var(--cm-border); color: var(--cm-text); }
.ev-td { background: var(--td-bg); border-color: var(--td-border); color: var(--td-text); }
.ev-tp { background: var(--tp-bg); border-color: var(--tp-border); color: var(--tp-text); }
.ev-other { background: var(--other-bg); border-color: var(--other-border); color: var(--other-text); }
.ev-ds {
  background: repeating-linear-gradient(135deg, var(--ds-bg) 0 8px, rgba(234,88,12,.18) 8px 12px);
  border: 2px solid var(--ds-border); border-left-width: 5px; color: var(--ds-text);
  box-shadow: 0 2px 8px rgba(234,88,12,.35); z-index: 5;
}
.ev-ds b { color: var(--ds-strong); }
.ev.half { right: 50%; }
.ev.half.second { left: 50%; right: 1px; }

/* ---------- vue mois ---------- */
.cal-month { background: var(--card); border-radius: 14px; border: 1px solid var(--line); overflow: hidden; }
.mo-head, .mo-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.mo-head div { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line); }
.mo-cell { min-height: 62px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 3px; font-size: 11px; cursor: pointer; }
.mo-cell:nth-child(7n) { border-right: 0; }
.mo-cell.other { opacity: .35; }
.mo-cell.selected { background: var(--primary-soft); }
.mo-cell .d { font-weight: 600; font-size: 12px; display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 999px; }
.mo-cell.today .d { background: var(--primary); color: #fff; }
.mo-chip { display: block; font-size: 9px; padding: 1px 3px; border-radius: 3px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid; font-weight: 600; }
.mo-chip.ev-ds { border: 1.5px solid var(--ds-border); border-left-width: 3px; box-shadow: none; }
.mo-more { font-size: 9px; color: var(--muted); }
.mo-day-detail { margin-top: 12px; }

/* ---------- vue liste ---------- */
.cal-list .day-block { margin-bottom: 14px; }
.day-head { font-weight: 700; font-size: 14px; margin: 0 2px 6px; }
.day-head::first-letter { text-transform: uppercase; }
.day-head.today { color: var(--primary); }
.day-head .rel { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.li-ev {
  display: flex; gap: 10px; align-items: stretch; background: var(--card);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; border-left: 5px solid; cursor: pointer;
}
.li-ev .time { min-width: 52px; font-size: 12px; font-weight: 600; color: var(--muted); }
.li-ev .time span { display: block; }
.li-ev .body { flex: 1; min-width: 0; }
.li-ev .title { font-weight: 700; font-size: 14px; }
.li-ev .meta { font-size: 12px; color: var(--muted); }
.li-ev.ev-ds { background: var(--ds-bg); border: 2px solid var(--ds-border); border-left-width: 6px; color: var(--ds-text); }
.li-ev.ev-ds .title { color: var(--ds-strong); }
.li-ev.ev-ds .time, .li-ev.ev-ds .meta { color: var(--ds-text); opacity: .85; }
.li-ev.ev-cm { border-color: var(--cm-border); }
.li-ev.ev-td { border-color: var(--td-border); }
.li-ev.ev-tp { border-color: var(--tp-border); }
.li-ev.ev-other { border-color: var(--other-border); }
.pill { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: rgba(0,0,0,.08); margin-left: 4px; vertical-align: middle; }
.pill-ds { background: var(--ds-strong); color: #fff; }
.pill-cm { background: var(--cm-border); color: #fff; }
.pill-td { background: var(--td-border); color: #fff; }
.pill-tp { background: var(--tp-border); color: #fff; }
.pill-other { background: var(--other-border); color: #fff; }

/* ---------- listes tâches / anniversaires ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: flex-start; gap: 10px; background: var(--card);
  border-radius: 12px; padding: 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.item input[type=checkbox] { width: 22px; height: 22px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--primary); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; font-size: 15px; word-break: break-word; }
.item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item.overdue .meta { color: var(--danger); font-weight: 600; }
.item.prio-2 { border-left: 4px solid var(--ds-border); }
.item.prio-0 { opacity: .8; }
.item .actions { display: flex; gap: 4px; flex-shrink: 0; }
.item .actions button { border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 8px; font-size: 15px; }
.item.soon { border-left: 4px solid var(--primary); }
.item.isToday { border-left: 4px solid var(--ds-strong); background: var(--ds-bg); }
.avatar { width: 40px; height: 40px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: 16px; }

/* ---------- fiche détail (bottom sheet) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + var(--safe-bottom));
  max-height: 80vh; overflow: auto; box-shadow: 0 -4px 24px rgba(0,0,0,.2);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet .kv { display: flex; gap: 8px; margin: 6px 0; font-size: 14px; }
.sheet .kv span:first-child { color: var(--muted); min-width: 80px; }
.sheet .ds-banner { background: var(--ds-bg); border: 2px solid var(--ds-border); color: var(--ds-text); border-radius: 10px; padding: 8px 10px; font-weight: 700; margin-bottom: 8px; }
.sheet .warn { font-size: 12.5px; color: var(--ds-text); background: var(--ds-bg); padding: 6px 8px; border-radius: 8px; margin-top: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px;
  border-radius: 999px; font-size: 13px; z-index: 40; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

@media (min-width: 700px) {
  .cal-week { --hour-h: 64px; }
  .ev { font-size: 12px; }
  .ev b { font-size: 12px; }
  .mo-cell { min-height: 90px; }
}
