@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Atkinson+Hyperlegible:wght@400;700&display=swap');

:root {
  /* Thème clair — Forêt Apaisante (défaut) */
  --background: #F9FAFB;
  --surface: #F3F4F6;
  --surface-raised: #FFFFFF;
  --primary: #10B981;
  --primary-contrast: #073B2C;
  --text: #1F2937;
  --text-muted: #5B6472;
  --border: #E2E5E9;
  --danger: #E76F51;
  --danger-surface: #FBEAE5;

  --emotion-frustration: #F59E0B;
  --emotion-rejet: #EF4444;
  --emotion-fatigue: #6366F1;
  --emotion-rumination: #8B5CF6;
  --emotion-autre: #6B7280;

  --font-heading: 'Nunito', sans-serif;
  --font-body: 'Atkinson Hyperlegible', sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-soft: 0 4px 16px rgba(31, 41, 55, 0.08);
  --banner-h: 44px;
  --nav-h: 64px;
  /* Hauteur réelle rendue par .bottom-nav, zone de gestes iOS/Android incluse.
     Toute réservation d'espace pour la barre (padding du contenu, calculs de
     décalage) doit utiliser cette variable plutôt que --nav-h seul, sinon le
     contenu scrollé se retrouve caché derrière la barre sur les téléphones à
     barre de gestes. */
  --nav-total-h: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  --netlify-badge-clearance: 60px;

  color-scheme: light;
}

[data-theme="dark"] {
  /* Thème sombre — Nuit Profonde */
  --background: #121212;
  --surface: #1E1E1E;
  --surface-raised: #242424;
  --primary: #A78BFA;
  --primary-contrast: #1E1730;
  --text: #E5E7EB;
  --text-muted: #9CA3AF;
  --border: #303030;
  --danger: #E76F51;
  --danger-surface: #2A1D17;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --background: #121212;
    --surface: #1E1E1E;
    --surface-raised: #242424;
    --primary: #A78BFA;
    --primary-contrast: #1E1730;
    --text: #E5E7EB;
    --text-muted: #9CA3AF;
    --border: #303030;
    --danger: #E76F51;
    --danger-surface: #2A1D17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--background);
  color: var(--text);
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

h1, h2, h3, .heading {
  font-family: var(--font-heading);
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

p { margin: 0 0 12px; color: var(--text); }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

a { color: var(--primary); }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap;
}

/* ---------- App shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* Doit rester en phase avec .emergency-banner et .bottom-nav ci-dessous,
     zones système incluses, sinon le contenu se retrouve caché sous le
     bandeau ou la barre de navigation (tous deux fixed) sur mobile. */
  padding-top: calc(var(--banner-h) + env(safe-area-inset-top, 0px));
  padding-bottom: var(--nav-total-h);
}

/* ---------- Emergency banner (always visible) ---------- */
.emergency-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--banner-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 50;
  background: var(--danger-surface);
  border-bottom: 1px solid var(--border);
}

.emergency-toggle {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--danger);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  /* En box-sizing: border-box, padding-bottom seul réduirait la zone des
     boutons au lieu d'agrandir la barre — on inclut donc la zone système
     directement dans la hauteur totale, comme --nav-total-h le prévoit. */
  height: var(--nav-total-h);
  display: flex;
  background: var(--surface-raised);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Sur Netlify, un badge "Powered by Netlify" flotte en bas à droite et recouvre
   les derniers boutons de la barre sur écran étroit (la barre prend toute la
   largeur sous 600px, voir .bottom-nav ci-dessus). Compresser les boutons ne
   marche pas ("Comprendre" refuse de rétrécir sous sa largeur de contenu) —
   on remonte donc toute la barre au-dessus du badge à la place, en ne touchant
   ni à sa largeur ni à la taille de ses boutons. Classe posée par app.js
   uniquement quand le site tourne réellement sur Netlify. */
@media (max-width: 599px) {
  body.on-netlify #app {
    padding-bottom: calc(var(--nav-total-h) + var(--netlify-badge-clearance));
  }
  body.on-netlify .bottom-nav {
    bottom: var(--netlify-badge-clearance);
  }
}

.bottom-nav button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
}

.bottom-nav button .nav-icon { font-size: 20px; }

.bottom-nav button.active { color: var(--primary); }

/* ---------- Screens ---------- */
main#screens { flex: 1; }

.screen {
  display: none;
  padding: 20px 20px 32px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.screen.active { display: block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 22px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  min-height: 48px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  font-weight: 600;
}

.btn-block { width: 100%; }

/* ---------- Home ---------- */
.home-hero { text-align: center; padding: 24px 0 8px; }
.home-hero p { color: var(--text-muted); }

.check-in-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.check-in-icon { font-size: 22px; flex-shrink: 0; }

.check-in-text {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.log-cta {
  width: 100%;
  min-height: 120px;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: var(--primary-contrast);
  border: none;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 22px;
  box-shadow: var(--shadow-soft);
  margin: 8px 0 24px;
}

.quick-links {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.quick-link {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
  color: var(--text);
  font-weight: 600;
}

.quick-link .qicon { font-size: 22px; display: block; margin-bottom: 4px; }

.section-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 15px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
}

.recent-list { display: flex; flex-direction: column; gap: 10px; }

.entry-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.entry-dot {
  width: 12px; height: 12px; border-radius: 50%;
  flex-shrink: 0;
}

.entry-meta { flex: 1; }
.entry-emotion { font-weight: 700; font-family: var(--font-heading); }
.entry-date { font-size: 13px; color: var(--text-muted); }
.entry-intensity { font-size: 13px; color: var(--text-muted); }

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
}

/* ---------- Log overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--background);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
}

.overlay-close {
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}

.log-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 24px 40px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.log-step { display: none; }
.log-step.active { display: block; }

.log-step h2 { text-align: center; font-size: 22px; margin-bottom: 6px; }
.log-step .log-sub { text-align: center; color: var(--text-muted); margin-bottom: 28px; }

.intensity-grid {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.intensity-btn {
  flex: 1;
  aspect-ratio: 1;
  max-width: 68px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-raised);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 20px;
  color: var(--text);
}

.intensity-btn[data-level="1"] { opacity: 0.65; }
.intensity-btn[data-level="5"] { border-color: var(--danger); color: var(--danger); }
.intensity-btn.selected { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }

.emotion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.emotion-btn {
  border: 2px solid var(--border);
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.emotion-btn .eicon { font-size: 26px; }
.emotion-btn.autre { grid-column: 1 / -1; }

.log-details-toggle {
  display: block;
  margin: 20px auto 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  text-decoration: underline;
}

.log-details {
  margin-top: 16px;
}

.log-details textarea {
  width: 100%;
  min-height: 80px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px;
  resize: vertical;
}

.log-confirm {
  text-align: center;
  padding-top: 40px;
}

.log-confirm .confirm-icon { font-size: 48px; margin-bottom: 12px; }

/* ---------- History ---------- */
.range-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.range-toggle button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-weight: 600;
  font-size: 14px;
}

.range-toggle button.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

.chart-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.pattern-insight {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text);
}

.pattern-insight strong { font-family: var(--font-heading); }

.ai-patterns-section { margin-bottom: 20px; }
.ai-patterns-section .breakdown-steps { margin-top: 0; }

.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.history-item .entry-dot { margin-top: 4px; }
.history-trigger { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Plan d'action ---------- */
.plan-view-toggle {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.icon-btn {
  border: none;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.action-icon { font-size: 26px; }
.action-text { flex: 1; font-weight: 600; }

.action-card.editing input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--background);
  color: var(--text);
}

.action-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
}

.add-action {
  width: 100%;
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  padding: 14px;
  font-weight: 600;
}

/* ---------- Découpeur de tâches ---------- */
.breakdown-section { margin-top: 28px; }

.breakdown-panel {
  margin-top: 14px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
}

.breakdown-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.breakdown-panel textarea {
  width: 100%;
  min-height: 70px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px;
  resize: vertical;
  margin-bottom: 12px;
}

.breakdown-status {
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.breakdown-status.is-error { color: var(--danger); }

.breakdown-steps {
  list-style: none;
  margin: 16px 0 4px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.breakdown-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-weight: 600;
  font-size: 15px;
}

.breakdown-steps li .step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-contrast);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Plan crisis fullscreen ---------- */
.crisis-overlay {
  background: var(--background);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
}

.crisis-overlay h2 { font-size: 24px; margin-bottom: 24px; }

.crisis-action {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
  font-size: 19px;
  font-weight: 700;
  font-family: var(--font-heading);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 420px;
  width: 100%;
}

.crisis-action .action-icon { font-size: 30px; }

/* ---------- Psychoéducation ---------- */
.learn-grid { display: flex; flex-direction: column; gap: 12px; }

.learn-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.learn-card h3 { font-size: 17px; margin-bottom: 8px; }
.learn-card p { font-size: 15px; color: var(--text); margin-bottom: 0; }
.learn-card .learn-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

/* ---------- Emergency modal ---------- */
.emergency-modal-body {
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.emergency-modal-body h2 { margin-bottom: 4px; }
.emergency-modal-body .log-sub { color: var(--text-muted); margin-bottom: 20px; }

.resource-card {
  display: block;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
  text-decoration: none;
}

.resource-name { font-family: var(--font-heading); font-weight: 700; color: var(--text); font-size: 16px; }
.resource-number { font-size: 22px; font-weight: 800; color: var(--primary); font-family: var(--font-heading); margin: 4px 0; }
.resource-desc { font-size: 13px; color: var(--text-muted); }

/* ---------- Settings row (theme toggle) ---------- */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.theme-switch {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  color: var(--text);
}

@media (min-width: 600px) {
  .bottom-nav { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* ---------- Premium / paywall ---------- */
.paywall {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 12px;
}
.paywall h3 { margin: 0 0 8px; }
.paywall p { color: var(--text-muted); margin: 0 0 12px; }
.paywall-buttons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.paywall-buttons .btn { text-align: center; text-decoration: none; display: block; }
.paywall-small { font-size: 0.85em; }
.paywall-key { display: flex; gap: 8px; margin-top: 12px; }
.paywall-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text);
  font: inherit;
}
