/* ═══════════════════════════════════════════════════════════════
   Mémo — design épuré premium, iPad-first. Clair + sombre.
   Inter · accent violet calme · surfaces douces · profondeur subtile
   ═══════════════════════════════════════════════════════════════ */

/* ░░ TOKENS — thème clair (défaut) ░░ */
:root {
  --bg: #f4f4f7;
  --bg-grad:
    radial-gradient(1100px 620px at 88% -12%, rgba(109, 94, 246, .10) 0%, transparent 58%),
    radial-gradient(900px 520px at -8% 4%, rgba(236, 72, 153, .07) 0%, transparent 52%),
    #f4f4f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --surface-3: #eeeef3;
  --elevated: #ffffff;
  --border: rgba(17, 17, 26, .08);
  --border-strong: rgba(17, 17, 26, .14);
  --rule: rgba(30, 35, 80, .17);

  --text: #16161d;
  --muted: #6a6a78;
  --faint: #9a9aa8;

  --accent: #6d5ef6;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(109, 94, 246, .12);
  --accent-grad: linear-gradient(125deg, #6d5ef6, #8b5cf6 55%, #b06ef0);

  --green: #10b981;
  --green-soft: rgba(16, 185, 129, .14);
  --red: #f43f5e;
  --red-soft: rgba(244, 63, 94, .12);
  --amber: #f59e0b;
  --blue: #3b82f6;

  --r-sm: 12px;
  --r: 18px;
  --r-lg: 24px;
  --r-xl: 30px;

  --shadow-sm: 0 1px 2px rgba(20, 20, 40, .06), 0 1px 1px rgba(20, 20, 40, .04);
  --shadow: 0 10px 30px -14px rgba(30, 25, 70, .25), 0 2px 8px -4px rgba(30, 25, 70, .10);
  --shadow-lg: 0 28px 60px -24px rgba(30, 25, 70, .35);
  --glow: 0 14px 38px -14px rgba(109, 94, 246, .5);

  --ease: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --rail-w: 230px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
}

/* ░░ TOKENS — thème sombre ░░ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0f;
    --bg-grad:
      radial-gradient(1100px 620px at 88% -12%, rgba(109, 94, 246, .18) 0%, transparent 56%),
      radial-gradient(900px 520px at -8% 4%, rgba(176, 110, 240, .12) 0%, transparent 50%),
      #0b0b0f;
    --surface: #15151c;
    --surface-2: #1b1b24;
    --surface-3: #23232e;
    --elevated: #1c1c25;
    --border: rgba(255, 255, 255, .08);
    --border-strong: rgba(255, 255, 255, .16);
    --rule: rgba(255, 255, 255, .22);
    --text: #f3f3f7;
    --muted: #a2a2b2;
    --faint: #6b6b7c;
    --accent-soft: rgba(139, 92, 246, .2);
    --green-soft: rgba(16, 185, 129, .18);
    --red-soft: rgba(244, 63, 94, .18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 18px 44px -20px rgba(0, 0, 0, .7), 0 4px 12px -6px rgba(0, 0, 0, .5);
    --shadow-lg: 0 30px 70px -28px rgba(0, 0, 0, .8);
    --glow: 0 16px 44px -16px rgba(139, 92, 246, .6);
    color-scheme: dark;
  }
}
[data-theme="dark"] {
  --bg: #0b0b0f;
  --bg-grad:
    radial-gradient(1100px 620px at 88% -12%, rgba(109, 94, 246, .18) 0%, transparent 56%),
    radial-gradient(900px 520px at -8% 4%, rgba(176, 110, 240, .12) 0%, transparent 50%),
    #0b0b0f;
  --surface: #15151c;
  --surface-2: #1b1b24;
  --surface-3: #23232e;
  --elevated: #1c1c25;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --rule: rgba(255, 255, 255, .22);
  --text: #f3f3f7;
  --muted: #a2a2b2;
  --faint: #6b6b7c;
  --accent-soft: rgba(139, 92, 246, .2);
  --green-soft: rgba(16, 185, 129, .18);
  --red-soft: rgba(244, 63, 94, .18);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 18px 44px -20px rgba(0, 0, 0, .7), 0 4px 12px -6px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 70px -28px rgba(0, 0, 0, .8);
  --glow: 0 16px 44px -16px rgba(139, 92, 246, .6);
  color-scheme: dark;
}

/* ░░ RESET ░░ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-grad) fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;     /* pas de sélection "toute la page" au appui long */
  -webkit-touch-callout: none;                       /* pas de loupe / menu au appui long */
}
/* …mais les champs texte restent éditables et sélectionnables (indispensable pour Griffonner/Scribble) */
input, textarea, [contenteditable] {
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }
input, textarea { -webkit-appearance: none; appearance: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }

/* ░░ BOUTONS ░░ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 15px; letter-spacing: -.01em;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  transition: transform .15s var(--ease), background .2s, border-color .2s, box-shadow .2s, opacity .2s;
  white-space: nowrap; user-select: none;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: var(--glow); }
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn--block { width: 100%; }
.btn--sm { height: 36px; padding: 0 13px; font-size: 13.5px; border-radius: 10px; }
.btn--icon { width: 44px; height: 44px; padding: 0; border-radius: var(--r-sm); }
.btn--icon.btn--sm { width: 36px; height: 36px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: var(--r-sm);
  color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); transition: transform .15s var(--ease), color .2s, background .2s;
}
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn:hover { color: var(--text); }
.iconbtn:active { transform: scale(.92); }
.iconbtn.is-spin svg { animation: spin 1s linear infinite; }

/* ░░ CHAMPS ░░ */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: -.01em; }
.field .hint { font-size: 12.5px; color: var(--faint); line-height: 1.45; }
.input, .textarea, .select {
  width: 100%; height: 48px; padding: 0 15px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-size: 16px; color: var(--text); outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.textarea { height: auto; min-height: 120px; padding: 13px 15px; line-height: 1.55; resize: vertical; }
.select { cursor: pointer; }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  height: 36px; padding: 0 15px; border-radius: 99px; font-size: 13.5px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  box-shadow: var(--shadow-sm); transition: transform .15s var(--ease), color .2s, border-color .2s, background .2s;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.chip:active { transform: scale(.95); }
.chip.is-active { background: var(--text); color: var(--bg); border-color: transparent; }
.period-chips { margin-bottom: 14px; }
.chip .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--green); }

/* ░░ ÉCRAN MOT DE PASSE ░░ */
.gate {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  padding: 24px; background: transparent;
}
.gate__card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 36px 28px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
  animation: pop .5s var(--ease-spring);
}
.gate__logo {
  width: 72px; height: 72px; border-radius: 18px; display: grid; place-items: center;
  box-shadow: var(--glow); margin-bottom: 6px;
}
.gate__logo img { width: 72px; height: 72px; border-radius: 17px; display: block; }
.gate__card h1 { font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.gate__card p { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.gate__card .input { text-align: center; }
.gate__card .btn { margin-top: 4px; }
.gate__err { color: var(--red); font-size: 13px; min-height: 18px; font-weight: 600; }

/* ░░ APP SHELL ░░ */
.app { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: calc(var(--safe-top) + 18px) clamp(16px, 4vw, 34px) 14px;
  padding-left: max(clamp(16px, 4vw, 34px), var(--safe-left));
  padding-right: max(clamp(16px, 4vw, 34px), var(--safe-right));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.topbar__left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rail-toggle { display: none; } /* visible seulement en layout rail (≥1100px) */
.topbar__title h1 { font-size: clamp(24px, 5vw, 32px); font-weight: 800; letter-spacing: -.035em; line-height: 1.05; }
.topbar__sub { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; font-weight: 500; }
.topbar__actions { display: flex; align-items: center; gap: 10px; padding-bottom: 2px; }

.view {
  padding: clamp(16px, 4vw, 34px);
  padding-left: max(clamp(16px, 4vw, 34px), var(--safe-left));
  padding-right: max(clamp(16px, 4vw, 34px), var(--safe-right));
  padding-bottom: calc(var(--safe-bottom) + 120px);
  max-width: 1180px; margin: 0 auto;
  animation: viewIn .4s var(--ease);
}
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ░░ TAB BAR (mobile / portrait) ░░ */
.tabbar {
  position: fixed; z-index: 40;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 14px);
  display: flex; gap: 4px; padding: 7px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border); border-radius: 99px; box-shadow: var(--shadow-lg);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 74px; padding: 8px 0 6px; border-radius: 99px;
  color: var(--faint); font-size: 10.5px; font-weight: 600; letter-spacing: -.01em;
  transition: color .2s, background .25s var(--ease);
}
.tab svg { width: 23px; height: 23px; }
.tab.is-active { color: #fff; background: var(--accent-grad); box-shadow: var(--glow); }

/* ░░ CARTES ░░ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.section-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 30px 2px 14px; }
.section-h h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.section-h .muted { color: var(--muted); font-size: 13px; font-weight: 500; }
.view > .section-h:first-child { margin-top: 6px; }

/* ░░ KPI ░░ */
.kpi-hero {
  position: relative; overflow: hidden;
  padding: clamp(22px, 4vw, 32px);
  display: block;
}
.kpi-hero::before {
  content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background: radial-gradient(420px 220px at 88% 0%, var(--accent-soft), transparent 70%);
}
.kpi-hero__main { position: relative; }
.kpi-hero__label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi-hero__value { font-size: clamp(36px, 8vw, 56px); font-weight: 800; letter-spacing: -.04em; line-height: 1; margin: 8px 0 10px; font-variant-numeric: tabular-nums; }
.kpi-hero__trend { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; padding: 5px 11px; border-radius: 99px; }
.trend-up { color: var(--green); background: var(--green-soft); }
.trend-down { color: var(--red); background: var(--red-soft); }
.trend-flat { color: var(--muted); background: var(--surface-2); }
.kpi-hero__chart { position: relative; height: 150px; margin-top: 18px; }
.hero-chart { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.chart-tip {
  position: absolute; top: -6px; transform: translateX(-50%);
  display: flex; gap: 7px; align-items: baseline; white-space: nowrap;
  padding: 5px 11px; border-radius: 10px; font-size: 13px; font-weight: 700;
  background: var(--elevated); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  pointer-events: none; z-index: 3;
}
.chart-tip b { color: var(--muted); font-weight: 600; font-size: 11.5px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 14px; }
.kpi {
  padding: 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.kpi__label { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi__label svg { width: 15px; height: 15px; color: var(--accent); }
.kpi__value { font-size: clamp(20px, 3.4vw, 27px); font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: 12px; color: var(--faint); font-weight: 500; }

/* ░░ SPARKLINE ░░ */
.spark-wrap { position: relative; width: 100%; }
.spark { width: 100%; display: block; overflow: visible; }
.spark .area { fill: url(#sparkFill); }
.spark .line { fill: none; stroke: url(#sparkStroke); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark-dot { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); transform: translate(-50%, -50%); box-shadow: 0 0 0 3px var(--accent-soft), 0 0 12px 2px rgba(139, 92, 246, .55); pointer-events: none; }
.spark-dot::after { content: ''; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--accent); opacity: .6; animation: sparkPulse 1.9s var(--ease) infinite; }
@keyframes sparkPulse { 0% { transform: scale(.7); opacity: .55; } 100% { transform: scale(2.4); opacity: 0; } }
.store-card .spark-dot { width: 7px; height: 7px; box-shadow: 0 0 0 2px var(--accent-soft); }
.store-card .spark-dot::after { display: none; }

/* ░░ STORES ░░ */
.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.store-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; transition: transform .2s var(--ease), box-shadow .2s; }
.store-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.store-card__top { display: flex; align-items: center; gap: 12px; }
.store-card__avatar { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 17px; color: #fff; background: var(--accent-grad); flex: none; }
.store-card__name { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.store-card__domain { font-size: 12px; color: var(--faint); }
.store-card__row { display: flex; justify-content: space-between; align-items: flex-end; }
.store-card__big { font-size: 26px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.store-card__meta { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.status-dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; }
.status-dot.ok { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.err { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

/* liste top produits / commandes */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 13px 4px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-rank { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 12.5px; font-weight: 700; color: var(--muted); flex: none; }
.list-row__title { flex: 1; min-width: 0; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__sub { font-size: 12.5px; color: var(--faint); font-weight: 500; }
.list-row__val { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* ░░ OBJECTIFS ░░ */
.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.goal-card { padding: 20px; display: flex; gap: 18px; align-items: center; transition: transform .2s var(--ease), box-shadow .2s; }
.goal-card.is-done { opacity: .72; }
.goal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.goal-card__body { flex: 1; min-width: 0; }
.goal-card__title { font-weight: 700; font-size: 16px; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.goal-card__title .tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); }
.goal-card__nums { font-size: 13.5px; color: var(--muted); margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.goal-card__nums b { color: var(--text); font-weight: 700; }
.progress { height: 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress__bar { height: 100%; border-radius: 99px; background: var(--accent-grad); transition: width .8s var(--ease); }
.progress__bar.done { background: linear-gradient(125deg, var(--green), #34d399); }
.goal-card__deadline { margin-top: 14px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 9px; border-radius: 9px; font-size: 12.5px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; color: var(--muted); background: var(--surface-2); }
.goal-card__deadline svg { width: 15px; height: 15px; flex: none; }
.goal-card__deadline.urgent { color: var(--accent); background: var(--accent-soft); }
.goal-card__deadline.over { color: var(--red); background: var(--red-soft); }
.goal-card__deadline.reached { color: var(--green); background: var(--green-soft); }

/* anneau de progression */
.ring { --p: 0; width: 76px; height: 76px; flex: none; position: relative; display: grid; place-items: center; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--surface-3); stroke-width: 8; }
.ring__fill { fill: none; stroke: url(#ringGrad); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .9s var(--ease); }
.ring__fill.done { stroke: var(--green); }
.ring__pct { position: absolute; font-size: 16px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ░░ NOTES ░░ */
.notes-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.search { flex: 1; position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }
.search .input { padding-left: 42px; height: 46px; }
.notes-masonry { columns: 3; column-gap: 14px; }
.note {
  break-inside: avoid; margin-bottom: 14px; padding: 18px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-left: 4px solid var(--note, var(--accent));
  transition: transform .18s var(--ease), box-shadow .2s; cursor: pointer; position: relative;
}
.note:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.note:active { transform: scale(.99); }
.note__menu { position: absolute; top: 9px; right: 9px; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--faint); background: transparent; transition: background .2s, color .2s, transform .12s var(--ease); z-index: 2; }
.note__menu svg { width: 18px; height: 18px; }
.note__menu:hover { background: var(--surface-2); color: var(--text); }
.note__menu:active { transform: scale(.88); }
.note.is-pinned { border-left-width: 5px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-btn { display: flex; align-items: center; gap: 13px; height: 54px; padding: 0 18px; border-radius: 14px; background: var(--surface-2); font-size: 16px; font-weight: 600; color: var(--text); transition: transform .12s var(--ease); }
.sheet-btn svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.sheet-btn:active { transform: scale(.98); }
.sheet-btn.danger { color: var(--red); }
.sheet-btn.danger svg { color: var(--red); }
.note__title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; margin-bottom: 6px; padding-right: 36px; }
.note__body { color: var(--muted); font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; }
.note__date { font-size: 11.5px; color: var(--faint); margin-top: 12px; font-weight: 500; }

/* ░░ RÉGLAGES ░░ */
.settings-stack { display: flex; flex-direction: column; gap: 14px; max-width: 720px; }
.panel { padding: 22px; }
.panel__title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 4px; }
.panel__desc { font-size: 13px; color: var(--muted); margin-bottom: 18px; line-height: 1.5; }
.panel .field + .field { margin-top: 14px; }
.store-line { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.store-line:last-of-type { border-bottom: none; }
.store-line__info { flex: 1; min-width: 0; }
.store-line__name { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.store-line__sub { font-size: 12.5px; color: var(--faint); }

.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 13px; }
.seg button { padding: 8px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600; color: var(--muted); transition: color .2s, background .2s; }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ligne réglage avec interrupteur (ex : fond galaxie) */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 18px; }
.setting-row__title { font-weight: 600; font-size: 15px; }
.setting-row__desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.switch { width: 50px; height: 30px; border-radius: 99px; background: var(--surface-3); position: relative; flex: none; transition: background .25s var(--ease); }
.switch.is-on { background: var(--accent); }
.switch__knob { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); transition: transform .25s var(--ease-spring); }
.switch.is-on .switch__knob { transform: translateX(20px); }
.switch:active .switch__knob { width: 28px; }

details.help { border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); margin-top: 14px; overflow: hidden; }
details.help summary { padding: 13px 16px; font-weight: 600; font-size: 14px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.help summary::-webkit-details-marker { display: none; }
details.help[open] summary { border-bottom: 1px solid var(--border); }
details.help .help__body { padding: 14px 16px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }
details.help ol { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
details.help code { background: var(--surface-3); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ░░ ÉTATS VIDES / SQUELETTES ░░ */
.empty { text-align: center; padding: 56px 24px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty__icon { width: 72px; height: 72px; border-radius: 22px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 12px; }
.empty__icon svg { width: 34px; height: 34px; }
.empty h3 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.empty p { color: var(--muted); font-size: 14px; max-width: 320px; line-height: 1.55; }
.empty .btn { margin-top: 16px; }

.skel { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ░░ MODALE ░░ */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; align-items: flex-end; justify-items: center; }
@media (min-width: 740px) { .modal { align-items: center; } }
.modal__backdrop { position: absolute; inset: 0; background: rgba(8, 8, 14, .5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .25s var(--ease); }
.modal__sheet {
  position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-lg);
  padding: 24px clamp(20px, 4vw, 28px) calc(var(--safe-bottom) + 24px);
  animation: sheetUp .4s var(--ease-spring);
}
@media (min-width: 740px) { .modal__sheet { border-radius: var(--r-xl); margin: 24px; animation: pop .35s var(--ease-spring); } }
.modal__grab { width: 40px; height: 5px; border-radius: 99px; background: var(--border-strong); margin: -8px auto 16px; }
@media (min-width: 740px) { .modal__grab { display: none; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal__head h2 { font-size: 21px; font-weight: 800; letter-spacing: -.03em; }
.modal__form { display: flex; flex-direction: column; gap: 15px; }
.modal__actions { display: flex; gap: 10px; margin-top: 8px; }
.modal__actions .btn { flex: 1; }

/* ░░ TOASTS ░░ */
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 14px); display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: 92vw; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 600;
  background: var(--elevated); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toastIn .35s var(--ease-spring);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.ok svg { color: var(--green); }
.toast.err svg { color: var(--red); }
.toast.leaving { animation: toastOut .25s var(--ease) forwards; }

/* ░░ ANIMATIONS ░░ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes toastIn { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-14px); opacity: 0; } }
.stagger > * { animation: viewIn .45s var(--ease) backwards; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .07s; }
.stagger > *:nth-child(3) { animation-delay: .12s; }
.stagger > *:nth-child(4) { animation-delay: .17s; }
.stagger > *:nth-child(5) { animation-delay: .22s; }
.stagger > *:nth-child(6) { animation-delay: .27s; }
/* mises à jour live silencieuses : on ne rejoue PAS l'animation d'entrée */
#view.no-anim .stagger > * { animation: none !important; }

/* indicateur « en direct » (pastille verte qui pulse) à côté du libellé de sync */
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 5px; vertical-align: middle; box-shadow: 0 0 0 0 rgba(16, 185, 129, .5); animation: livePulse 2.4s ease-out infinite; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, .55); } 70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }

/* ░░ RESPONSIVE ░░ */
@media (max-width: 860px) {
  .kpi-hero { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .notes-masonry { columns: 2; }
}
@media (max-width: 480px) {
  .notes-masonry { columns: 1; }
  .tab { width: 64px; }
}

/* iPad paysage & desktop : rail latéral au lieu de la barre flottante */
@media (min-width: 1100px) {
  .app { padding-left: var(--rail-w); transition: padding-left .32s var(--ease); }
  /* bouton afficher/masquer la sidebar */
  .rail-toggle { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--muted); flex: none; transition: background .2s, color .2s; }
  .rail-toggle:hover { background: var(--surface-2); color: var(--text); }
  .rail-toggle svg { width: 22px; height: 22px; }
  .app.rail-hidden { padding-left: 0; }
  .app.rail-hidden .tabbar { transform: translateX(-100%); }
  .tabbar {
    left: 0; transform: none; top: 0; bottom: 0; transition: transform .32s var(--ease);
    flex-direction: column; justify-content: center; gap: 8px;
    width: var(--rail-w); border-radius: 0; border: none; border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    padding: 24px 18px;
  }
  .tabbar::before {
    content: "Mémo"; position: absolute; top: calc(var(--safe-top) + 28px); left: 24px;
    font-size: 22px; font-weight: 800; letter-spacing: -.03em; color: var(--text);
  }
  .tab { flex-direction: row; justify-content: flex-start; gap: 14px; width: 100%; padding: 13px 16px; border-radius: 14px; font-size: 15px; }
  .tab svg { width: 21px; height: 21px; }
  .topbar { padding-top: calc(var(--safe-top) + 26px); }
  .view { padding-top: 22px; }
}

/* ░░ ÉDITEUR DE NOTE plein écran (Apple Pencil) ░░ */
.editor {
  position: fixed; inset: 0; z-index: 78; display: flex; flex-direction: column;
  background: var(--bg-grad) fixed; animation: sheetUp .32s var(--ease);
}
.editor__bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 12px) max(14px, var(--safe-right)) 10px max(14px, var(--safe-left));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(180%); -webkit-backdrop-filter: blur(18px) saturate(180%);
}
.editor__title { flex: 1; min-width: 0; height: 44px; border: none; background: transparent; font-size: 20px; font-weight: 800; letter-spacing: -.02em; outline: none; color: var(--text); }
.editor__title::placeholder { color: var(--faint); }
.iconbtn.is-active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.editor__sub { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px max(14px, var(--safe-left)) 4px; }
.ed-accents { display: flex; gap: 8px; }
.acc-dot { width: 26px; height: 26px; border-radius: 99px; border: 3px solid transparent; transition: transform .15s var(--ease); }
.acc-dot:active { transform: scale(.9); }
.editor__pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.write-hint { margin: 8px max(18px, var(--safe-left)) 4px; padding: 11px 14px; font-size: 13px; line-height: 1.45; color: var(--muted); background: var(--accent-soft); border-radius: 12px; }
.write-hint b { color: var(--text); }
/* La feuille d'écriture reste TOUJOURS claire (papier blanc, encre foncée,
   lignes visibles) — identique en mode clair et sombre. */
.editor__body { flex: 1; width: 100%; border: none; background: #fff; outline: none; padding: 8px max(18px, var(--safe-left)) 40px; font-size: 17px; line-height: 34px; color: #1c1c22; caret-color: #1c1c22; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.editor__body.rt:empty::before { content: attr(data-ph); color: #a6a6b0; pointer-events: none; }
/* tous les blocs calés sur la grille de 34px → le texte tombe sur les lignes */
.editor__body.rt h2 { font-size: 23px; font-weight: 800; letter-spacing: -.02em; line-height: 34px; margin: 0; }
.editor__body.rt h3 { font-size: 18px; font-weight: 700; line-height: 34px; margin: 0; }
.editor__body.rt p, .editor__body.rt div { line-height: 34px; margin: 0; }
.editor__body.rt ul, .editor__body.rt ol { margin: 0; padding-left: 24px; }
.editor__body.rt li { line-height: 34px; }
.editor__body.paper-ruled { background-color: #fff; background-image: repeating-linear-gradient(transparent 0 33px, rgba(30, 35, 80, .22) 33px 34px), linear-gradient(90deg, transparent 0 46px, rgba(244, 63, 94, .5) 46px 48px, transparent 48px); background-attachment: local; padding-left: 60px; }
.editor__body.paper-grid { background-color: #fff; background-image: repeating-linear-gradient(transparent 0 33px, rgba(30, 35, 80, .16) 33px 34px), repeating-linear-gradient(90deg, transparent 0 33px, rgba(30, 35, 80, .16) 33px 34px); background-attachment: local; }
.rt-colors { display: flex; align-items: center; gap: 6px; }
.rt-swatch { width: 24px; height: 24px; border-radius: 99px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); flex: none; transition: transform .12s var(--ease); }
.rt-swatch:active { transform: scale(.88); }
.rt-swatch--default { background: #1c1c22; box-shadow: 0 0 0 1px rgba(255, 255, 255, .35); }
.rt-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px max(14px, var(--safe-left)); border-bottom: 1px solid var(--border); }
.rt-btn { height: 34px; padding: 0 13px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--muted); background: var(--surface-2); transition: transform .12s var(--ease), background .2s, color .2s; }
.rt-btn:active { transform: scale(.95); }
.rt-btn.is-active { background: var(--text); color: var(--bg); }
.rt-div { width: 1px; height: 24px; background: var(--border); flex: none; }
.draw-wrap { flex: 1; min-height: 0; position: relative; margin: 4px max(14px, var(--safe-right)) 0 max(14px, var(--safe-left)); border-radius: var(--r); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.draw-wrap.is-erasing { cursor: cell; }
.draw-wrap.is-lasso { cursor: crosshair; }
#zoomPct { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
.draw-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.draw-wrap { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.paper-ruled { background-color: #fff; background-image: repeating-linear-gradient(#fff 0 31px, #d9deec 31px 32px); }
.paper-grid { background-color: #fff; background-image: repeating-linear-gradient(#eef0f7 0 23px, transparent 23px 24px), repeating-linear-gradient(90deg, #eef0f7 0 23px, transparent 23px 24px); }
.penbar {
  display: flex; align-items: center; justify-content: center; gap: 8px; row-gap: 8px; flex-wrap: wrap; flex: none;
  margin: 12px auto calc(var(--safe-bottom) + 14px); padding: 9px 12px;
  max-width: calc(100% - 24px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(22px) saturate(180%); -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg);
}
.pen-group { display: flex; align-items: center; gap: 6px; flex: none; }
.pen-div { width: 1px; height: 26px; background: var(--border); flex: none; }
@media (max-width: 620px) { .pen-div { display: none; } }
.pen-tool { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; color: var(--muted); transition: background .2s, color .2s, transform .12s var(--ease); }
.pen-tool svg { width: 22px; height: 22px; }
.pen-tool:active { transform: scale(.9); }
.pen-tool.is-active { background: var(--accent-soft); color: var(--accent); }
.ink-dot { width: 27px; height: 27px; border-radius: 99px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); flex: none; transition: transform .12s var(--ease); }
.ink-dot:active { transform: scale(.88); }
.ink-dot.is-active { box-shadow: 0 0 0 2px var(--accent); transform: scale(1.12); }
.pen-size { padding: 0 6px; }
.pen-size input[type="range"] { -webkit-appearance: none; appearance: none; width: 96px; height: 6px; border-radius: 99px; background: var(--surface-3); outline: none; }
.pen-size input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 99px; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer; }
.pen-size input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 3px solid var(--surface); border-radius: 99px; background: var(--accent); cursor: pointer; }
.pen-paper { height: 34px; padding: 0 13px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.pen-paper.is-active { background: var(--text); color: var(--bg); }
.pen-ocr { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pen-ocr:active { transform: scale(.95); }
.pen-ocr[disabled] { opacity: .6; }
.note-thumb { width: 100%; height: 150px; display: block; border-radius: 12px; margin: 4px 0 2px; background-color: #fff; box-shadow: inset 0 0 0 1px var(--border); }

/* ═══ FOND GALACTIQUE ═══════════════════════════════════════════════
   Base + nébuleuses + voie lactée = CSS statique (ci-dessous).
   Étoiles scintillantes lumineuses + filantes = <canvas> (voir app.js).
   Couche fixe derrière toute l'app (z-index -1), n'intercepte aucun toucher. */
#cosmos { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
#cosmos canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* clair : galaxie douce — la page reste claire */
#cosmos {
  background:
    radial-gradient(60% 55% at 80% -10%, rgba(124, 92, 246, .13), transparent 60%),
    radial-gradient(55% 50% at -6% 4%, rgba(236, 72, 153, .09), transparent 58%),
    radial-gradient(55% 50% at 50% 112%, rgba(59, 130, 246, .09), transparent 60%);
}
/* sombre : espace profond + nébuleuses colorées + bande de voie lactée */
[data-theme="dark"] #cosmos {
  background:
    radial-gradient(1100px 760px at 20% 16%, rgba(124, 92, 246, .26), transparent 56%),
    radial-gradient(900px 680px at 86% 26%, rgba(236, 72, 153, .18), transparent 55%),
    radial-gradient(1000px 820px at 64% 92%, rgba(56, 120, 245, .20), transparent 58%),
    linear-gradient(122deg, transparent 34%, rgba(150, 140, 225, .09) 47%, rgba(196, 182, 255, .15) 52%, rgba(150, 140, 225, .09) 57%, transparent 66%),
    radial-gradient(1500px 1150px at 50% -16%, #1b1640 0%, #0d0b22 44%, #070610 100%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #cosmos {
    background:
      radial-gradient(1100px 760px at 20% 16%, rgba(124, 92, 246, .26), transparent 56%),
      radial-gradient(900px 680px at 86% 26%, rgba(236, 72, 153, .18), transparent 55%),
      radial-gradient(1000px 820px at 64% 92%, rgba(56, 120, 245, .20), transparent 58%),
      linear-gradient(122deg, transparent 34%, rgba(150, 140, 225, .09) 47%, rgba(196, 182, 255, .15) 52%, rgba(150, 140, 225, .09) 57%, transparent 66%),
      radial-gradient(1500px 1150px at 50% -16%, #1b1640 0%, #0d0b22 44%, #070610 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
