/* ============================================================
   DESIGN SYSTEM — Le Journal de Bord
   Palette : crème chaud · encrier bleu · sépia · encre dorée
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Backgrounds */
  --bg:            #F5EDE0;
  --bg-alt:        #EDE2D0;
  --card:          #FDFAF5;
  --card-alt:      #F8F2E8;

  /* Text */
  --text:          #2C1A0E;
  --text-mid:      #5C4030;
  --text-muted:    #9A7E6A;

  /* Accent 1 — Encrier bleu (CTAs, liens, jauge) */
  --ink:           #2B4C7E;
  --ink-dark:      #1A3055;
  --ink-light:     #EAF0F9;

  /* Accent 2 — Rouille / cuir */
  --rust:          #B8653A;
  --rust-light:    #F3DCC9;

  /* Accent 3 — Or antique */
  --gold:          #B5883E;
  --gold-light:    #F5EAD0;

  /* Sémantique */
  --success:       #4A7B5A;
  --success-light: #D8EDDF;
  --warning:       #C89B3C;
  --danger:        #C24B4B;
  --danger-light:  #fef2f2;
  --danger-border: #fecaca;
  --danger-text:   #dc2626;

  /* Bordures & Ombres */
  --border:        #DDD0BB;
  --border-mid:    #C4A882;
  --shadow:        0 2px 8px rgba(44,26,14,0.08);
  --shadow-lg:     0 8px 28px rgba(44,26,14,0.14);

  /* Typographie */
  --font-heading:  'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:     'Source Sans 3', 'Inter', system-ui, -apple-system, sans-serif;

  /* Géométrie */
  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     20px;
}

/* ============================================================
   BASE
============================================================ */
body {
  font-family: var(--font-body);
  background: var(--bg);
  background-image: repeating-linear-gradient(
    transparent, transparent 27px,
    rgba(43,76,126,.07) 27px, rgba(43,76,126,.07) 28px
  );
  color: var(--text);
  min-height: 100vh;
  line-height: 1.65;
  font-size: 15px;
}
h1, h2, h3, h4 { font-family: var(--font-heading); }
a { color: var(--ink); }
.hidden { display: none !important; }

/* ============================================================
   LOADING SCREEN
============================================================ */
#loadingScreen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999; gap: 14px;
}
.spinner {
  width: 46px; height: 46px;
  border: 3px solid var(--border);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-title {
  font-family: var(--font-heading);
  font-size: 1.2rem; font-weight: 700; font-style: italic;
  color: var(--text);
}
.spinner-sub { font-size: 0.82rem; color: var(--text-muted); }

/* ============================================================
   AUTH SCREEN
============================================================ */
#authScreen {
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 600px 400px at 80% 20%, rgba(43,76,126,.06), transparent),
    radial-gradient(ellipse 400px 500px at 10% 80%, rgba(181,136,62,.06), transparent);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 420px; width: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
}
.auth-hero {
  background: var(--text);
  color: var(--card);
  padding: 32px 32px 26px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.auth-hero::before {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    transparent, transparent 28px,
    rgba(253,250,245,.05) 28px, rgba(253,250,245,.05) 29px
  );
}
.auth-hero-logo  { font-size: 2.8rem; margin-bottom: 8px; position: relative; }
.auth-hero h1    {
  font-family: var(--font-heading);
  font-size: 1.4rem; font-weight: 700; font-style: italic;
  letter-spacing: 0; position: relative;
}
.auth-hero p     { font-size: 0.82rem; opacity: .8; margin-top: 5px; position: relative; }

.auth-body { padding: 28px 28px 24px; }

.auth-tabs {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden; margin-bottom: 22px;
}
.auth-tab {
  flex: 1; padding: 9px 0; border: none;
  background: transparent; font-family: var(--font-body);
  font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
  cursor: pointer; transition: all .2s;
}
.auth-tab.active  { background: var(--text); color: var(--card); }
.auth-tab:not(.active):hover { background: var(--bg); }

.auth-separator {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0; color: var(--text-muted);
  font-size: .78rem; font-weight: 500;
}
.auth-separator::before,
.auth-separator::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.google-btn {
  width: 100%; padding: 11px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); display: flex; align-items: center; justify-content: center;
  gap: 10px; font-family: var(--font-body); font-size: .88rem;
  font-weight: 600; color: var(--text); cursor: pointer; transition: all .2s;
}
.google-btn:hover { background: var(--bg); box-shadow: var(--shadow); }

.auth-error {
  margin-top: 12px; padding: 10px 14px;
  background: var(--danger-light); border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm); color: var(--danger-text);
  font-size: .82rem; font-weight: 500; display: none;
}
.auth-error.show { display: block; }
.auth-error.auth-success {
  background: var(--success-light); border-color: var(--success); color: var(--success);
}

.forgot-link {
  display: block; text-align: right; background: none; border: none; padding: 0;
  font-family: var(--font-body); font-size: .78rem; color: var(--ink);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
  opacity: .7; transition: opacity .15s;
}
.forgot-link:hover { opacity: 1; }

/* ============================================================
   HEADER
============================================================ */
header {
  background: var(--text);
  color: var(--card);
  padding: 14px 24px;
  display: flex; align-items: center;
  justify-content: space-between; gap: 12px;
  box-shadow: 0 4px 18px rgba(44,26,14,.22);
  position: sticky; top: 0; z-index: 100;
  flex-wrap: wrap;
}
.header-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-brand-icon { font-size: 1.8rem; flex-shrink: 0; }
.header-brand-text { min-width: 0; }
.brand-name {
  font-family: var(--font-heading);
  font-size: 1.25rem; font-weight: 700; font-style: italic;
  color: var(--card); letter-spacing: -.3px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Instagram badge in header */
.ig-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  background: linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  color: #fff; border-radius: 20px;
  font-size: .73rem; font-weight: 700;
  text-decoration: none;
  transition: opacity .2s, transform .2s; white-space: nowrap;
}
.ig-badge:hover { opacity: .9; transform: translateY(-1px); }

.user-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(253,250,245,.12); border: 1px solid rgba(253,250,245,.25);
  border-radius: 20px; padding: 4px 11px;
  font-size: .74rem; font-weight: 600; color: var(--card);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Hamburger (mobile only) */
.hamburger-btn {
  display: none;
  background: rgba(253,250,245,.12);
  border: 1px solid rgba(253,250,245,.25);
  border-radius: var(--radius-sm);
  color: var(--card); cursor: pointer;
  padding: 7px 10px; font-size: 1.1rem;
  line-height: 1;
}

/* ============================================================
   BUTTONS
============================================================ */
.btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: .83rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
  transition: all .2s; font-family: var(--font-body);
}
.btn-primary {
  background: var(--ink); color: #fff;
  box-shadow: 0 3px 10px rgba(43,76,126,.35);
}
.btn-primary:hover   { background: var(--ink-dark); transform: translateY(-1px); box-shadow: 0 5px 16px rgba(43,76,126,.4); }
.btn-primary:disabled { opacity: .65; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: rgba(253,250,245,.13);
  color: var(--card); border: 1px solid rgba(253,250,245,.28);
}
.btn-ghost:hover { background: rgba(253,250,245,.22); }

.btn-neutral { background: var(--bg-alt); color: var(--text); border: 1px solid var(--border); }
.btn-neutral:hover { background: var(--border); }

.btn-danger-soft {
  background: transparent; color: var(--danger);
  border: 1.5px solid var(--danger); font-size: .73rem; padding: 4px 9px;
}
.btn-danger-soft:hover { background: var(--danger); color: #fff; }

.btn-sm   { padding: 5px 11px; font-size: .76rem; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; border-radius: 7px; }

.btn-signout {
  background: rgba(194,75,75,.15);
  color: #f5a5a5; border: 1px solid rgba(194,75,75,.3);
  font-size: .76rem; padding: 5px 11px;
}
.btn-signout:hover { background: rgba(194,75,75,.28); }

.btn-reset {
  background: transparent; color: rgba(253,250,245,.7);
  border: 1px solid rgba(253,250,245,.2); font-size: .76rem; padding: 5px 11px;
}
.btn-reset:hover { background: rgba(253,250,245,.1); color: var(--card); }

/* PWA install button — header (desktop) */
.btn-magic {
  background: linear-gradient(135deg, #B5883E, #D4A54A);
  color: #2C1A0E; border: none;
  font-weight: 700;
  box-shadow: 0 3px 12px rgba(181,136,62,.45);
}
.btn-magic:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 5px 18px rgba(181,136,62,.55); }

/* PWA install button — mobile menu */
.btn-install-mobile {
  width: 100%; padding: 12px 16px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #B5883E, #D4A54A);
  color: #2C1A0E; font-size: .9rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  cursor: pointer; font-family: var(--font-body);
  box-shadow: 0 3px 12px rgba(181,136,62,.4);
  transition: all .2s;
}
.btn-install-mobile:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* iOS modal step labels */
.ios-step { font-weight: 700; color: var(--ink); }

.btn-instagram {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; width: 100%;
  background: linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: .85rem; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: opacity .2s, transform .2s;
}
.btn-instagram:hover { opacity: .9; transform: translateY(-1px); }

/* ============================================================
   MOBILE MENU (bottom sheet)
============================================================ */
#mobileOverlay {
  position: fixed; inset: 0;
  background: rgba(44,26,14,.45); z-index: 199;
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
#mobileOverlay.show { opacity: 1; pointer-events: all; }

#mobileMenu {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 20px 32px; z-index: 200;
  box-shadow: 0 -4px 28px rgba(44,26,14,.18);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.4,0,.2,1);
}
#mobileMenu.open { transform: translateY(0); }
.mobile-menu-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 12px auto 18px; cursor: pointer;
}
.mobile-menu-title {
  font-family: var(--font-heading); font-size: .95rem;
  font-style: italic; color: var(--text-muted); margin-bottom: 14px;
}
.mobile-menu-actions {
  display: flex; flex-direction: column; gap: 10px;
}
.mobile-menu-actions .btn { justify-content: flex-start; font-size: .88rem; }
.mobile-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ============================================================
   APP LAYOUT — bandeau tableau de bord + espace de travail
============================================================ */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

/* Firestore loading bar */
.data-loading-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--ink) 25%, var(--gold) 50%, var(--ink) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================
   ZONE 1 — TABLEAU DE BORD (bureau sombre, fond encrier/cuir)
============================================================ */
.dashboard-banner {
  background: var(--text);
  background-image:
    radial-gradient(ellipse 700px 300px at 85% 10%, rgba(181,136,62,.18), transparent),
    radial-gradient(ellipse 450px 500px at 5%  90%, rgba(43,76,126,.18),  transparent);
  border-bottom: 2px solid rgba(0,0,0,.35);
  padding: 32px 20px;
}
.dashboard-inner {
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 36px;
}

/* Gauge column (left) */
.db-gauge-col {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  flex-shrink: 0;
}

/* Vertical divider */
.db-divider {
  width: 1px; align-self: stretch; flex-shrink: 0;
  background: rgba(253,250,245,.12);
}

/* Stats column (right) */
.db-stats-col {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 16px;
}

/* Featured stat block (boule de cristal + date de fin) */
.db-featured {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 14px 20px;
  background: rgba(181,136,62,.12);
  border: 1px solid rgba(181,136,62,.30);
  border-radius: var(--radius);
}
.db-feat-icon { font-size: 1.7rem; flex-shrink: 0; padding-top: 2px; }
.db-feat-val  {
  font-family: var(--font-heading);
  font-size: 1.45rem; font-weight: 800; line-height: 1.1;
  color: #F5CB5C;
}
.db-feat-lbl { font-size: .68rem; color: rgba(245,237,224,.55); text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; }
.db-feat-sub { font-size: .75rem; color: rgba(245,237,224,.72); margin-top: 2px; }

/* Crystal ball motivational quote */
.crystal-quote {
  font-family: var(--font-heading);
  font-size: .92rem; font-weight: 400; font-style: italic;
  color: var(--gold-light);
  margin-top: 8px;
  line-height: 1.4;
  border-top: 1px dashed rgba(181,136,62,.4);
  padding-top: 7px;
}

/* Stats grid inside the dark banner */
.dashboard-banner .stats-grid {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px; margin-bottom: 0;
}
.dashboard-banner .stat-card {
  background: rgba(253,250,245,.07);
  border: 1px solid rgba(253,250,245,.10);
  border-left: 3px solid rgba(253,250,245,.18);
  box-shadow: none;
}
.dashboard-banner .stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 18px rgba(0,0,0,.3); }
.dashboard-banner .stat-val { color: #F5EDE0; }
.dashboard-banner .stat-lbl { color: rgba(245,237,224,.55); }
.dashboard-banner .stat-sub { color: rgba(245,237,224,.48); }
.dashboard-banner .sc-blue   { border-left-color: rgba(100,136,200,.9); }
.dashboard-banner .sc-green  { border-left-color: rgba(74,123,90,.9); }
.dashboard-banner .sc-amber  { border-left-color: rgba(181,136,62,.9); }
.dashboard-banner .sc-violet { border-left-color: rgba(150,110,200,.9); }
.dashboard-banner .sc-teal   { border-left-color: rgba(58,125,140,.9); }

/* Gauge overrides for dark background */
.dashboard-banner .gauge-track { stroke: rgba(253,250,245,.15); }
.dashboard-banner .gauge-fill  { stroke: var(--gold); }
.dashboard-banner .gauge-pct   { color: #F5EDE0; }
.dashboard-banner .gauge-lbl   { color: rgba(245,237,224,.5); }
.dashboard-banner .ms-pip            { background: rgba(253,250,245,.15); }
.dashboard-banner .ms-pip.r25        { background: var(--rust); }
.dashboard-banner .ms-pip.r50        { background: var(--gold); }
.dashboard-banner .ms-pip.r75        { background: #6488c8; }
.dashboard-banner .ms-pip.r100       { background: var(--success); }

/* Start-date meta row */
.db-meta {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  font-size: .76rem; color: rgba(245,237,224,.5);
  text-transform: uppercase; letter-spacing: .4px;
}
.db-meta-val {
  font-family: var(--font-heading);
  font-size: .88rem; font-weight: 600; color: rgba(245,237,224,.82);
  text-transform: none; letter-spacing: 0;
}
.btn-tiny {
  font-size: .7rem; padding: 3px 10px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border-mid);
  cursor: pointer; font-family: var(--font-body); font-weight: 600;
  color: var(--ink); margin-top: 0;
}
.btn-tiny:hover { background: var(--ink-light); }
.dashboard-banner .btn-tiny            { color: rgba(245,237,224,.7); border-color: rgba(253,250,245,.22); }
.dashboard-banner .btn-tiny:hover      { background: rgba(253,250,245,.1); color: #F5EDE0; }

/* Share button in dark banner — gold accent */
.dashboard-banner .btn-share-ig {
  background: rgba(181,136,62,.18);
  border-color: rgba(181,136,62,.6);
  color: #F5EDE0;
}
.dashboard-banner .btn-share-ig:hover { background: rgba(181,136,62,.32); opacity: 1; }

/* ============================================================
   ZONE 2 — ESPACE DE TRAVAIL (Chapitres)
============================================================ */
.workspace {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  width: 100%;
}

/* Titre de document modifiable */
#document-title {
  font-family: var(--font-heading);
  font-size: 1.55rem; font-weight: 800;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border);
  outline: none;
  flex: 1; min-width: 0;
  padding: 2px 0 6px;
  line-height: 1.2;
  transition: border-color .2s;
}
#document-title:focus { border-bottom-color: var(--ink); }
#document-title::placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
  font-size: 1.1rem;
}

/* ============================================================
   GAUGE STYLES (communs à la bannière et à l'écran auth)
============================================================ */
.gauge-wrap { position: relative; width: 190px; height: 190px; }
.gauge-svg  { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-track {
  fill: none; stroke: var(--border-mid); stroke-width: 10; stroke-linecap: round;
}
.gauge-fill {
  fill: none; stroke: var(--ink); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 502.65; stroke-dashoffset: 502.65;
  transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1);
}
.gauge-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.gauge-pct {
  font-family: var(--font-heading);
  font-size: 2.6rem; font-weight: 800; line-height: 1; color: var(--text);
}
.gauge-lbl { font-size: .68rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; letter-spacing: .5px; text-transform: uppercase; }

/* Milestone bar */
.milestone-bar { display: flex; gap: 5px; }
.ms-pip { flex: 1; height: 5px; border-radius: 3px; background: var(--border); transition: background .6s; }
.ms-pip.r25  { background: var(--rust); }
.ms-pip.r50  { background: var(--gold); }
.ms-pip.r75  { background: var(--ink); }
.ms-pip.r100 { background: var(--success); }

/* ============================================================
   STATS GRID
============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px,1fr));
  gap: 13px; margin-bottom: 26px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-mid);
  transition: transform .18s, box-shadow .18s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.sc-blue   { border-left-color: var(--ink); }
.sc-green  { border-left-color: var(--success); }
.sc-amber  { border-left-color: var(--warning); }
.sc-violet { border-left-color: #7B5EA7; }
.sc-teal   { border-left-color: #3A7D8C; }
.sc-magic  { border-left-color: var(--gold); background: linear-gradient(135deg,var(--gold-light),var(--card)); }

.stat-icon { font-size: 1.3rem; margin-bottom: 5px; }
.stat-val  { font-family: var(--font-heading); font-size: 1.45rem; font-weight: 800; color: var(--text); }
.stat-lbl  { font-size: .7rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .4px; }
.stat-sub  { font-size: .72rem; color: var(--text-muted); margin-top: 4px; line-height: 1.3; }
.ink-text  { color: var(--ink); font-weight: 700; }

/* ============================================================
   SECTION HEADER
============================================================ */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
  padding-bottom: 10px; border-bottom: 2px solid var(--border);
}
.section-title {
  font-family: var(--font-heading);
  font-size: 1.2rem; font-weight: 700; font-style: italic; color: var(--text);
}

/* Groupe de boutons à droite du titre de document */
.section-actions {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}

/* Bouton secondaire "outline" */
.btn-outline {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px;
  font-family: var(--font-body); font-size: .82rem; font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.btn-outline:hover { background: var(--ink-light); }

/* Dropdown modèles de plan */
.template-wrap { position: relative; }

.template-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 270px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}

.template-menu-label {
  padding: 8px 16px;
  font-size: .68rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.template-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 16px;
  background: none; border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer; text-align: left;
  font-family: var(--font-body);
  transition: background .15s;
}
.template-item:last-child { border-bottom: none; }
.template-item:hover { background: var(--bg); }

.tmpl-icon { font-size: 1.35rem; flex-shrink: 0; }
.tmpl-name { font-size: .88rem; font-weight: 600; color: var(--text); }
.tmpl-desc { font-size: .73rem; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   CHAPTER CARDS
============================================================ */
.chapter-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 13px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-mid);
  transition: box-shadow .2s, border-left-color .3s, transform .15s;
}
.chapter-card.completed { border-left-color: var(--success); }
.chapter-card:hover     { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.chapter-header {
  padding: 15px 18px;
  display: flex; align-items: center; gap: 11px;
  cursor: pointer; user-select: none;
}
.chapter-header:hover { background: var(--bg); }

.ch-arrow { font-size: .72rem; color: var(--text-muted); transition: transform .28s; flex-shrink: 0; }
.chapter-card.expanded .ch-arrow { transform: rotate(90deg); }

/* Drag handles — zone de toucher élargie pour mobile */
.ch-drag-handle,
.ss-drag-handle {
  font-size: .95rem; letter-spacing: -1.5px;
  color: var(--text-muted); opacity: .45;
  cursor: grab; flex-shrink: 0;
  user-select: none;
  /* Padding généreux : zone de toucher ~44×44 px recommandée mobile */
  padding: 12px 10px;
  /* Évite que le navigateur interprète le début du drag comme un scroll */
  touch-action: none;
  transition: opacity .15s, color .15s;
}
.ch-drag-handle:hover,
.ss-drag-handle:hover { opacity: 1; color: var(--ink); }
.ch-drag-handle:active,
.ss-drag-handle:active { cursor: grabbing; opacity: 1; color: var(--ink); }

/* SortableJS — fantôme (placeholder laissé dans la liste) */
.sortable-ghost {
  opacity: .22;
  background: var(--ink-light) !important;
  border: 2px dashed var(--ink) !important;
  border-radius: var(--radius) !important;
}

/* SortableJS — élément en cours de déplacement (tenu en main) */
.sortable-drag {
  opacity: .93 !important;
  transform: scale(1.025) rotate(.5deg) !important;
  box-shadow: 0 12px 32px rgba(0,0,0,.18), 0 3px 8px rgba(0,0,0,.12) !important;
  cursor: grabbing !important;
  border-color: var(--ink) !important;
  z-index: 9999 !important;
}

/* Direct page inputs on leaf chapters (no subsections) */
.ch-direct-pages { padding: 8px 0 4px; }

.ch-info { flex: 1; min-width: 0; }
.ch-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.editable {
  border: none; background: transparent;
  font-family: inherit; font-size: inherit; font-weight: inherit; color: inherit;
  width: 100%; min-width: 80px; cursor: pointer;
  padding: 2px 5px; border-radius: 5px; transition: background .15s, outline .15s;
}
.editable:focus { outline: 2px solid var(--ink); background: #fff; cursor: text; }
.ch-title .editable { font-family: var(--font-heading); font-size: .95rem; font-weight: 600; }

.badge-done {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; background: var(--success-light); color: var(--success);
  border-radius: 20px; font-size: .7rem; font-weight: 700; white-space: nowrap;
}
.ch-progress-bar { margin-top: 6px; height: 4px; background: var(--border); border-radius: 3px; overflow: hidden; }
.ch-progress-fill {
  height: 100%; background: var(--ink); border-radius: 3px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.ch-progress-fill.done { background: var(--success); }
.ch-stats   { font-size: .73rem; color: var(--text-muted); margin-top: 4px; }
.ch-actions { display: flex; gap: 5px; flex-shrink: 0; }

.chapter-body {
  display: none; padding: 4px 18px 16px;
  border-top: 1px solid var(--border);
}
.chapter-card.expanded .chapter-body { display: block; }

/* ============================================================
   SUBSECTIONS
============================================================ */
.subsection { padding: 13px 0; border-bottom: 1px solid var(--border); }
.subsection:last-of-type { border-bottom: none; }

.ss-header { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.ss-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); flex-shrink: 0; opacity: .6; }
.ss-dot.done { background: var(--success); opacity: 1; }
.ss-title { flex: 1; min-width: 0; }
.ss-title .editable { font-size: .86rem; font-weight: 600; }

.ss-progress-row { display: flex; align-items: center; gap: 9px; padding-left: 17px; }
.prog-track { flex: 1; height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; }
.prog-fill  {
  height: 100%; background: var(--ink); border-radius: 4px;
  transition: width .55s cubic-bezier(.4,0,.2,1);
}
.prog-fill.done { background: var(--success); }

.pages-row {
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap; font-size: .8rem; color: var(--text-muted);
}
.pages-input {
  width: 52px; padding: 3px 6px;
  border: 1.5px solid var(--border); border-radius: 6px;
  font-size: .8rem; text-align: center; font-family: var(--font-body); color: var(--text);
  background: var(--card); transition: border-color .18s;
}
.pages-input:focus { outline: none; border-color: var(--ink); }

.prog-pct { font-size: .75rem; font-weight: 700; color: var(--text-muted); min-width: 36px; text-align: right; }
.prog-pct.done { color: var(--success); }

.add-ss-btn {
  width: 100%; margin-top: 11px; padding: 9px;
  background: transparent; border: 2px dashed var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: .81rem; font-family: var(--font-body); cursor: pointer; transition: all .18s;
}
.add-ss-btn:hover { border-color: var(--ink); color: var(--ink); background: var(--ink-light); }

/* ============================================================
   EMPTY STATE
============================================================ */
.empty-state { text-align: center; padding: 64px 20px; color: var(--text-muted); }
.empty-icon  { font-size: 3.8rem; margin-bottom: 14px; }
.empty-state h3 { font-family: var(--font-heading); font-size: 1.2rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p  { font-size: .87rem; margin-bottom: 22px; max-width: 380px; margin-inline: auto; line-height: 1.6; }

/* ============================================================
   FOOTER
============================================================ */
footer {
  background: var(--text);
  color: rgba(253,250,245,.75);
  padding: 32px 20px;
  margin-top: auto;
}
.footer-inner {
  max-width: 700px; margin: 0 auto;
  display: flex; flex-direction: column;
  align-items: center; gap: 10px; text-align: center;
}
.footer-brand {
  font-family: var(--font-heading);
  font-size: 1.05rem; font-weight: 600; font-style: italic;
  color: rgba(253,250,245,.9);
}
.footer-tagline { font-size: .8rem; line-height: 1.5; max-width: 360px; }
.footer-ig-link {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px;
  background: linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  color: #fff; border-radius: 20px; text-decoration: none;
  font-size: .82rem; font-weight: 700; transition: opacity .2s, transform .2s;
}
.footer-ig-link:hover { opacity: .9; transform: translateY(-1px); }
.footer-note { font-size: .73rem; opacity: .5; }

/* ============================================================
   MODALS
============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(44,26,14,.55);
  backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 34px 28px; max-width: 430px; width: 100%;
  box-shadow: 0 24px 60px rgba(44,26,14,.22);
  text-align: center; border: 1px solid var(--border);
}
.modal-emoji  { font-size: 2.6rem; margin-bottom: 10px; }
.modal h2     { font-family: var(--font-heading); font-size: 1.35rem; font-weight: 700; font-style: italic; margin-bottom: 5px; }
.modal .modal-sub { font-size: .86rem; color: var(--text-muted); margin-bottom: 22px; line-height: 1.5; }
.form-group   { text-align: left; margin-bottom: 16px; }
.form-label   { display: block; font-size: .8rem; font-weight: 700; margin-bottom: 5px; color: var(--text); text-transform: uppercase; letter-spacing: .4px; }
.form-control {
  width: 100%; padding: 10px 13px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: .88rem; font-family: var(--font-body); color: var(--text);
  background: var(--card); transition: border-color .18s;
}
.form-control:focus { outline: none; border-color: var(--ink); }
.modal-actions { display: flex; gap: 9px; margin-top: 4px; }
.modal-actions .btn { flex: 1; justify-content: center; }

/* ============================================================
   CONFETTI
============================================================ */
.confetti-piece {
  position: fixed; top: -16px; z-index: 9999; pointer-events: none;
  animation: cfFall linear forwards;
}
@keyframes cfFall {
  0%   { transform: translateY(0) rotateX(0deg) rotateZ(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotateX(360deg) rotateZ(540deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .confetti-piece { display: none; } }

/* ============================================================
   TOASTS
============================================================ */
#toastBox {
  position: fixed; bottom: 22px; right: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9000;
}
.toast {
  padding: 11px 17px; border-radius: var(--radius-sm);
  font-size: .83rem; font-weight: 600; color: #fff;
  background: var(--text); box-shadow: var(--shadow-lg);
  max-width: 295px;
  animation: toastIn .28s ease, toastOut .28s ease 2.7s forwards;
}
.toast.success { background: var(--success); }
.toast.warn    { background: var(--warning); color: var(--text); }
.toast.special { background: linear-gradient(135deg, var(--ink), var(--rust)); }
@keyframes toastIn  { from { opacity:0; transform:translateX(14px); } to { opacity:1; transform:translateX(0); } }
@keyframes toastOut { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(14px); } }

/* Pulse animation */
@keyframes numPulse { 0%{transform:scale(1);} 40%{transform:scale(1.16);} 100%{transform:scale(1);} }
.pulse { animation: numPulse .38s ease; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 3px; }

/* ============================================================
   RESPONSIVE — Tablet (≤ 900px)
============================================================ */
@media (max-width: 900px) {
  .dashboard-inner { gap: 24px; }
  .dashboard-banner .stats-grid { grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); }
  .db-feat-val { font-size: 1.25rem; }
}

/* ============================================================
   RESPONSIVE — Mobile (≤ 680px)
   Le bandeau passe en colonne : jauge centrée → stats dessous
============================================================ */
@media (max-width: 680px) {
  /* Dashboard banner : empiler jauge + stats */
  .dashboard-banner { padding: 24px 16px 20px; }
  .dashboard-inner  { flex-direction: column; gap: 20px; align-items: stretch; }
  .db-gauge-col     { flex-direction: row; justify-content: center; align-items: center;
                      gap: 20px; flex-wrap: wrap; }
  .db-divider       { width: 100%; height: 1px; align-self: auto; }
  .db-stats-col     { gap: 12px; }
  .dashboard-banner .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }

  /* Smaller gauge on mobile */
  .dashboard-banner .gauge-wrap { width: 150px; height: 150px; }
  .dashboard-banner .gauge-pct  { font-size: 2rem; }

  /* Show hamburger, hide desktop action buttons */
  .hamburger-btn { display: flex; align-items: center; }
  .desktop-only  { display: none !important; }

  /* Compact header */
  header { padding: 11px 16px; gap: 8px; }
  .brand-name { font-size: 1rem; }
  .ig-badge   { display: none; }
  .user-badge { display: none; }

  /* Workspace */
  .workspace { padding: 20px 14px 40px; }

  /* Section header : les boutons se wrappent et s'alignent à droite */
  .section-actions { flex-wrap: wrap; justify-content: flex-end; }
  .btn-outline     { font-size: .78rem; padding: 6px 10px; }

  /* Chapters: full width */
  .chapter-header { padding: 13px 14px; gap: 9px; }
  .chapter-body   { padding: 4px 14px 14px; }
  .ss-progress-row { flex-wrap: wrap; gap: 6px; }
  .prog-track { flex-basis: 100%; }

  /* Footer */
  footer { padding: 24px 16px; }
  .footer-ig-link { font-size: .78rem; }
}

/* ============================================================
   RESPONSIVE — Very small (≤ 400px)
============================================================ */
@media (max-width: 400px) {
  .dashboard-banner .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   SHARE BUTTON — "Partager mon avancée"
============================================================ */
.btn-share-ig {
  width: 100%; padding: 11px 14px;
  background: linear-gradient(135deg, #2C1A0E, #3D2412);
  color: #F5EDE0; border: 1.5px solid #B5883E;
  border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: .83rem; font-weight: 700;
  letter-spacing: .3px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: opacity .2s, transform .2s;
}
.btn-share-ig:hover   { opacity: .88; transform: translateY(-1px); }
.btn-share-ig:disabled { opacity: .55; cursor: wait; transform: none; }

/* ============================================================
   INSTAGRAM POST CARD — modèle off-screen (1080 × 1080 px)
   Capturé par html2canvas puis téléchargé en PNG
============================================================ */
#igPostCard {
  position: absolute; left: -9999px; top: 0;
  width: 1080px; height: 1080px; overflow: hidden;
}
.igp-bg {
  width: 1080px; height: 1080px; box-sizing: border-box;
  background: #2C1A0E;
  background-image:
    radial-gradient(ellipse 820px 520px at 88% 4%,  rgba(181,136,62,.22), transparent),
    radial-gradient(ellipse 620px 720px at 4%  95%,  rgba(43,76,126,.22),  transparent),
    repeating-linear-gradient(
      transparent, transparent 53px,
      rgba(253,250,245,.025) 53px, rgba(253,250,245,.025) 54px
    );
  display: flex; flex-direction: column; align-items: center;
  padding: 80px 108px 70px;
  position: relative;
}

/* Brand header */
.igp-header {
  width: 100%; display: flex; align-items: center; gap: 20px;
  margin-bottom: 48px;
}
.igp-logo  { font-size: 54px; line-height: 1; flex-shrink: 0; }
.igp-brand {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 38px; font-weight: 700; font-style: italic;
  color: #F5EDE0; letter-spacing: -.5px; line-height: 1.1;
}

/* Circular gauge */
.igp-gauge-wrap {
  position: relative; width: 340px; height: 340px;
  margin-bottom: 44px; flex-shrink: 0;
}
.igp-gauge-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.igp-track {
  fill: none; stroke: rgba(253,250,245,.10);
  stroke-width: 14; stroke-linecap: round;
}
.igp-fill {
  fill: none; stroke: #B5883E;
  stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 502.65; stroke-dashoffset: 502.65;
}
.igp-center {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.igp-pct {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 110px; font-weight: 800; color: #F5EDE0; line-height: 1;
}
.igp-avancement {
  font-family: 'Source Sans 3', 'Inter', system-ui, sans-serif;
  font-size: 20px; color: rgba(245,237,224,.50);
  letter-spacing: 4px; text-transform: uppercase; margin-top: 8px;
}

/* Headline */
.igp-headline {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 50px; font-weight: 700; font-style: italic;
  color: #F5EDE0; margin-bottom: 28px; text-align: center;
}

/* Stats row */
.igp-stats {
  display: flex; align-items: center; gap: 36px; margin-bottom: 32px;
}
.igp-stat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.igp-stat-num {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: 68px; font-weight: 800; color: #B5883E; line-height: 1;
}
.igp-stat-label {
  font-family: 'Source Sans 3', 'Inter', system-ui, sans-serif;
  font-size: 20px; color: rgba(245,237,224,.65); letter-spacing: 1px;
}
.igp-stat-sep {
  font-size: 50px; line-height: 1;
  color: rgba(245,237,224,.15); font-weight: 300;
}

/* Dynamic message badge */
.igp-message {
  font-family: 'Source Sans 3', 'Inter', system-ui, sans-serif;
  font-size: 28px; font-weight: 600; color: rgba(245,237,224,.88);
  padding: 14px 38px;
  border: 1.5px solid rgba(181,136,62,.38);
  border-radius: 50px;
  background: rgba(181,136,62,.10);
  margin-bottom: auto; /* pousse footer vers le bas */
}

/* Divider */
.igp-divider {
  align-self: stretch; height: 1px;
  background: rgba(253,250,245,.08);
  margin: 30px 0 22px;
}

/* Footer branding */
.igp-footer {
  font-family: 'Source Sans 3', 'Inter', system-ui, sans-serif;
  font-size: 22px; color: rgba(245,237,224,.38);
  letter-spacing: .5px; text-align: center;
}

/* ============================================================
   DESKTOP-ONLY helpers
============================================================ */
.mobile-only { display: none; }
@media (max-width: 768px) {
  .mobile-only  { display: flex; }
  .desktop-only { display: none; }

  /* ── Dropdown modèles de plan → bottom-sheet ────────────────
     Sur mobile le menu sort de l'écran si positionné en absolu.
     On le transforme en feuille glissante ancrée en bas. ───── */
  .template-menu {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    min-width: 100%; width: 100%;
    border-radius: 16px 16px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    max-height: 75vh; overflow-y: auto;
    /* Ombre portée vers le haut pour l'effet "émerge du bas" */
    box-shadow: 0 -6px 32px rgba(0,0,0,.18), 0 -1px 0 var(--border);
  }
  /* Poignée visuelle (affordance "glissable") */
  .template-menu::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 4px;
  }
  /* Cibles tactiles ≥ 52 px pour un toucher confortable */
  .template-item   { padding: 14px 20px; min-height: 52px; }
  .tmpl-icon       { font-size: 1.5rem; }
  .tmpl-name       { font-size: .92rem; }
  .tmpl-desc       { font-size: .76rem; }

  /* ── En-tête de la zone Chapitres ───────────────────────────
     Le titre prend toute la largeur (seul sur sa ligne),
     les boutons passent sur la ligne du dessous, alignés à droite */
  .section-header  { flex-direction: column; align-items: stretch; gap: 8px; }
  #document-title  { width: 100%; flex: none; }
  .section-actions { width: 100%; justify-content: flex-end; }
}

/* ============================================================
   BANNIÈRE INSTALLATION iOS — sticky bas d'écran
============================================================ */
.ios-install-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0,0,0,.12);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 250;
}
.ios-banner-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.ios-banner-icon { font-size: 1.6rem; flex-shrink: 0; }
.ios-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: .82rem;
  color: var(--text);
  line-height: 1.3;
}
.ios-banner-text strong { font-size: .88rem; }
.ios-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  padding: 6px;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 50%;
}
.ios-banner-close:hover { background: var(--bg); }
