/* ========== Cockpit app — mobile-first ========== */
:root {
  --bg: #0d1220;
  --surface: #161d2e;
  --surface2: #1e2740;
  --text: #e8edf6;
  --muted: #8b98b0;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #4da3ff;
  --p1: #ff6161;
  --p2: #ffb454;
  --p3: #8fa3c0;
  --ok: #3ecf8e;
  --warn: #ffb454;
  --danger: #ff6161;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f4f9;
    --surface: #ffffff;
    --surface2: #eef1f8;
    --text: #182034;
    --muted: #5d6a83;
    --line: rgba(20, 30, 60, 0.1);
    --shadow: 0 3px 12px rgba(30, 40, 80, 0.1);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.today { font-size: 12.5px; color: var(--muted); text-transform: capitalize; }
.topbar h1 { margin: 0; font-size: 21px; letter-spacing: 0.2px; }
.topbar-actions { display: flex; gap: 6px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
}
.iconbtn svg { width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:active { transform: scale(0.94); }
.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- vue ---------- */
.view { padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; }
.section-label {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 2px 8px; font-size: 12.5px; font-weight: 600;
  letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted);
}
.section-label:first-child { margin-top: 2px; }
.section-label .count { font-weight: 500; opacity: 0.7; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.p1 { background: var(--p1); } .dot.p2 { background: var(--p2); } .dot.p3 { background: var(--p3); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card .title { font-weight: 600; font-size: 15.5px; margin: 6px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  font-size: 11.5px; padding: 2.5px 8px; border-radius: 20px;
  background: var(--surface2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.cat { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chip.due-late { color: #fff; background: var(--danger); border-color: transparent; font-weight: 600; }
.chip.due-soon { color: #201500; background: var(--warn); border-color: transparent; font-weight: 600; }
.chip.stale { color: var(--muted); }
.chip.wait { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.chip.block { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }

.action-text { color: var(--text); font-size: 14px; white-space: pre-wrap; }
.action-text.clamped {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.expand-btn { color: var(--accent); font-size: 13px; padding: 4px 0 0; font-weight: 500; }
.card-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.note-btn { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.note-perso {
  margin-top: 8px; padding: 10px; border-radius: 10px;
  background: var(--surface2); font-size: 13px; color: var(--muted);
  white-space: pre-wrap; border-left: 3px solid var(--p3);
}

.empty {
  text-align: center; color: var(--muted); padding: 44px 20px;
  font-size: 14.5px;
}
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- révisions ---------- */
.rev-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: var(--radius); padding: 18px 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.rev-hero .n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.rev-hero .themes { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; padding: 12px 18px; font-weight: 600; font-size: 15px;
  border: 1px solid var(--line); background: var(--surface2);
}
.btn.primary { background: var(--accent); color: #06101f; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.statgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-bottom: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  text-align: center; padding: 9px 2px;
}
.stat .v { font-size: 17px; font-weight: 700; }
.stat .l { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.statline { display: flex; gap: 7px; }
.statline .stat { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 11px 4px; }

/* ---------- session de révision ---------- */
.session-overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.session-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.session-progress { font-size: 13px; color: var(--muted); font-weight: 600; }
.progress-track { height: 4px; background: var(--surface2); border-radius: 4px; margin-bottom: 18px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.q-card { flex: 1; display: flex; flex-direction: column; }
.q-prompt { font-size: 19px; font-weight: 600; line-height: 1.45; margin: 14px 0; white-space: pre-wrap; }
.q-answer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; font-size: 15px; white-space: pre-wrap; margin-top: 6px;
  border-left: 3px solid var(--ok);
}
.q-mnemo {
  background: color-mix(in srgb, var(--warn) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 10px;
}
.session-actions { margin-top: auto; padding-top: 18px; display: flex; flex-direction: column; gap: 9px; }
.diff-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.diff-btn { border-radius: 12px; padding: 13px 6px; font-weight: 700; font-size: 14.5px; border: 1px solid var(--line); }
.diff-facile { background: color-mix(in srgb, var(--ok) 18%, var(--surface)); color: var(--ok); }
.diff-moyenne { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent); }
.diff-difficile { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--warn); }
.diff-echec { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
.feedback { text-align: center; color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- habitudes ---------- */
.habit { display: flex; align-items: center; gap: 12px; }
.habit .emoji {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 22px;
  background: var(--surface2); border: 1px solid var(--line);
}
.habit .meta { flex: 1; min-width: 0; }
.habit .name { font-weight: 600; font-size: 15.5px; }
.habit .state { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.habit .state.late { color: var(--danger); font-weight: 600; }
.habit .state.today { color: var(--warn); font-weight: 600; }
.habit .state.ok { color: var(--ok); }
.habit-done {
  flex: none; border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: 14px;
  background: color-mix(in srgb, var(--ok) 16%, var(--surface));
  color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
}
.habit-done[disabled] { opacity: 0.55; }
.card.h-late { border-left: 3px solid var(--danger); }
.card.h-today { border-left: 3px solid var(--warn); }
.card.h-ok { border-left: 3px solid var(--ok); }
.card.h-never { border-left: 3px solid var(--muted); }

/* ---------- inbox ---------- */
.inbox-form { display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.inbox-form textarea {
  width: 100%; min-height: 86px; resize: vertical;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; font: inherit; font-size: 15px;
}
.inbox-form textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); border-color: transparent; }
.inbox-item .when { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.inbox-item .txt { font-size: 14.5px; white-space: pre-wrap; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 0 3px; border-radius: 12px; color: var(--muted); position: relative;
}
.tab svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab span { font-size: 10.5px; font-weight: 600; }
.tab.active { color: var(--accent); }
.tab-badge {
  position: absolute; top: 1px; right: calc(50% - 22px);
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700;
  font-style: normal; display: grid; place-items: center;
}
.tab-badge.neutral { background: var(--accent); color: #06101f; }

/* ---------- divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px;
  font-size: 14px; box-shadow: var(--shadow); max-width: 88vw; text-align: center;
}
.loading { display: grid; place-items: center; padding: 60px 0; color: var(--muted); }
.loader { width: 26px; height: 26px; border: 3px solid var(--surface2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 10px; }

dialog#settings {
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  color: var(--text); padding: 0; width: min(92vw, 420px);
}
dialog#settings::backdrop { background: rgba(0, 0, 0, 0.55); }
.settings-form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.settings-form h2 { margin: 0; font-size: 18px; }
.settings-form .hint { margin: 0; font-size: 13px; color: var(--muted); }
.settings-form label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 5px; }
.settings-form input {
  background: var(--surface2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 10px 12px; font: inherit; font-size: 14px;
}
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
