/* Navigation et mise en page applicative. Chargé en dernier pour remplacer
   proprement les anciennes règles de page unique. */
:root {
  --sidebar-width: 258px;
  --mobile-nav-height: 76px;
  --app-surface: #fffdf8;
  --app-deep: #143f42;
}

body.app-open { overflow-x: hidden; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100dvh;
  background: var(--canvas);
  transition: grid-template-columns .22s ease;
}

.app-sidebar {
  position: fixed;
  z-index: 40;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  padding: 24px 18px;
  flex-direction: column;
  border-right: 1px solid rgba(32, 48, 54, .09);
  background: #fffdf9;
  transition: width .22s ease, padding .22s ease;
}

.sidebar-toggle {
  position: absolute;
  z-index: 2;
  top: 82px;
  right: -14px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf9;
  color: var(--primary-dark);
  box-shadow: 0 6px 18px rgba(39, 50, 47, .1);
}
.sidebar-toggle:hover { border-color: var(--primary); background: var(--lavender); }
.sidebar-toggle span { display: block; font-size: 20px; line-height: 1; transition: transform .22s ease; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 4px 6px 24px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.sidebar-brand > span:last-child { display: grid; gap: 2px; }
.sidebar-brand strong { font-size: 15px; letter-spacing: -.035em; }
.sidebar-brand small { color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .02em; }
.sidebar-brand .brand-mark { width: 42px; height: 42px; font-size: 12px; }

.desktop-nav { display: grid; gap: 6px; margin-top: 25px; }
.desktop-nav button {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  min-height: 50px;
  padding: 6px 12px 6px 8px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: #5f6e72;
  text-align: left;
}
.desktop-nav button > span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  color: #66787a;
  background: #f1eee6;
  font-size: 16px;
}
.desktop-nav button strong { font-size: 12px; font-weight: 800; }
.desktop-nav button:hover { color: var(--primary-dark); background: rgba(220, 235, 234, .45); }
.desktop-nav button.active { color: #fff; background: var(--primary-dark); box-shadow: 0 12px 28px rgba(23, 79, 82, .18); }
.desktop-nav button.active > span { color: var(--gold); background: rgba(255, 255, 255, .1); }

.sidebar-create {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  margin-top: 24px;
  border: 1px solid rgba(35, 109, 112, .16);
  background: var(--lavender);
  color: var(--primary-dark);
  font-size: 11px;
}
.sidebar-create span { font-size: 19px; line-height: 1; }
.sidebar-create:hover { border-color: var(--primary); background: #d1e5e3; }

.sidebar-note {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(35, 109, 112, .1);
  border-radius: 16px;
  background: rgba(220, 235, 234, .42);
}
.sidebar-note > span { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 10px; background: #fff; color: var(--primary); font-size: 10px; font-weight: 900; }
.sidebar-note p { display: grid; gap: 3px; margin: 0; }
.sidebar-note strong { font-size: 10px; }
.sidebar-note small { color: var(--muted); font-size: 8px; line-height: 1.4; }

.app-workspace { grid-column: 2; min-width: 0; }
.main-header {
  position: sticky;
  z-index: 30;
  top: 0;
  width: 100%;
  max-width: none;
  height: 76px;
  margin: 0;
  padding: 12px clamp(24px, 4vw, 58px);
  border-bottom: 1px solid rgba(32, 48, 54, .08);
  background: rgba(244, 239, 229, .88);
  backdrop-filter: blur(18px) saturate(120%);
}
.mobile-brand { display: none; padding: 0; border: 0; background: transparent; }
.page-context { display: grid; gap: 2px; }
.page-context small { color: var(--primary); font-size: 8px; font-weight: 900; letter-spacing: .14em; }
.page-context strong { color: #1a2b30; font-size: 17px; letter-spacing: -.03em; }
.account-menu .account-button { display: grid; min-width: 150px; padding: 8px 12px; text-align: left; }
.account-menu .account-button span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; font-size: 10px; white-space: nowrap; }
.account-menu .account-button small { margin-top: 2px; color: var(--muted); font-size: 8px; }
.account-menu .logout-button { width: 40px; height: 40px; padding: 0; font-size: 16px; }

.app-main { min-width: 0; }
.page-content { width: min(1180px, 100%); margin: 0 auto; padding: 48px clamp(24px, 4vw, 58px) 70px; }
.home-content { max-width: 1180px; padding-top: 48px; }
.dashboard-intro { max-width: 800px; }
.dashboard-intro .greeting { margin: 0 0 10px; font-size: 10px; }
.dashboard-intro h1 { margin: 0; color: #17282d; font-size: clamp(39px, 5vw, 64px); line-height: 1.01; letter-spacing: -.055em; text-wrap: balance; }
.dashboard-intro > p:last-child { max-width: 620px; margin: 18px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr); gap: 18px; margin-top: 36px; }
.dashboard-grid .create-hero { min-height: 150px; margin: 0; padding: 28px; }
.dashboard-grid .create-hero > span:nth-child(2) { display: grid; gap: 3px; }
.dashboard-grid .create-hero small { font-size: 8px; font-style: normal; font-weight: 900; letter-spacing: .13em; }
.dashboard-grid .create-hero strong { margin-top: 3px; font-size: 23px; }
.dashboard-grid .create-hero em { color: rgba(255, 255, 255, .7); font-size: 11px; font-style: normal; }
.dashboard-grid .active-child-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-height: 150px;
  margin: 0;
  padding: 25px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--app-surface);
  text-align: left;
  box-shadow: 0 10px 32px rgba(39, 50, 47, .05);
}
.dashboard-grid .active-child-card > span { color: var(--primary); font-size: 8px; font-weight: 900; letter-spacing: .13em; }
.dashboard-grid .active-child-card strong { margin-top: 18px; font-size: 20px; }
.dashboard-grid .active-child-card small { margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.dashboard-grid .active-child-card i { margin-top: auto; color: var(--primary); font-size: 10px; font-style: normal; font-weight: 850; }
.dashboard-grid .active-child-card:hover { border-color: rgba(35, 109, 112, .4); transform: translateY(-2px); }

.suggestions-heading { align-items: flex-end; margin-top: 42px; }
.suggestions-heading > div { display: grid; gap: 4px; }
.suggestions-heading small, .page-heading p, .account-section-title small, .data-actions small { margin: 0; color: var(--primary); font-size: 8px; font-weight: 900; letter-spacing: .14em; }
.suggestions-heading h2 { margin: 0; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.suggestions button { width: 100%; text-align: left; }

.dashboard-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 34px; }
.dashboard-links > button { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 13px; min-height: 104px; padding: 17px; border: 1px solid var(--line); background: var(--app-surface); text-align: left; }
.dashboard-links > button:hover { border-color: rgba(35, 109, 112, .38); box-shadow: 0 12px 30px rgba(39, 50, 47, .07); transform: translateY(-2px); }
.dashboard-link-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 17px; font-size: 20px; }
.dashboard-link-icon.lavender { color: var(--primary); background: var(--lavender); }
.dashboard-link-icon.mint { color: #fff; background: var(--mint); }
.dashboard-links button > span:nth-child(2) { display: grid; gap: 3px; }
.dashboard-links small { color: var(--muted); font-size: 7px; font-weight: 900; letter-spacing: .11em; }
.dashboard-links strong { font-size: 13px; }
.dashboard-links em { color: var(--muted); font-size: 9px; font-style: normal; }
.dashboard-links b { color: var(--primary); font-size: 18px; }
.home-content .trust-card { margin-top: 18px; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding-bottom: 30px; }
.page-heading > div { display: grid; gap: 7px; }
.page-heading h1 { margin: 0; color: #17282d; font-size: clamp(36px, 5vw, 58px); line-height: 1; letter-spacing: -.055em; }
.page-heading > div > span { max-width: 620px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.compact-button { width: auto; min-width: 150px; min-height: 46px; padding: 11px 16px; font-size: 10px; }
.collection-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 18px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 253, 248, .62); }
.collection-toolbar > div { display: flex; align-items: center; gap: 9px; }
.collection-toolbar > div > span { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 10px; color: var(--primary); background: var(--lavender); }
.collection-toolbar strong { font-size: 10px; }
.collection-toolbar button { border: 0; background: transparent; color: var(--primary); font-size: 9px; font-weight: 850; }
.collection-content .story-library, .collection-content .community-library { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.collection-content .story-card, .collection-content .community-card { min-height: 280px; }
.collection-content .story-card img, .collection-content .community-card img { height: 178px; }
.community-safety { display: flex; align-items: center; gap: 12px; margin: 12px 0 22px; padding: 16px 18px; border: 1px solid rgba(60, 141, 121, .18); border-radius: 17px; background: var(--mint-soft); }
.community-safety > span { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 11px; color: #fff; background: var(--mint); font-size: 11px; }
.community-safety strong { font-size: 11px; }
.community-safety p { margin: 3px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.collection-content .community-locked { grid-column: 1 / -1; min-height: 140px; }

.account-page { max-width: 1000px; }
.account-page-heading { align-items: flex-end; }
.account-overview { display: grid; gap: 18px; }
.account-page .account-section, .account-page .child-form { margin: 0; padding: 24px; border: 1px solid var(--line); border-radius: 22px; background: var(--app-surface); box-shadow: 0 8px 30px rgba(39, 50, 47, .04); }
.account-page .account-section-title { align-items: flex-end; }
.account-page .account-section-title > div { display: grid; gap: 3px; }
.account-page .account-section h3, .account-page .child-form h3 { font-size: 18px; }
.account-page .child-list, .account-page .session-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.account-page .child-card, .account-page .session-list article { min-height: 76px; }

.mobile-nav { display: none; }

.app-shell.sidebar-collapsed { --sidebar-width: 82px; }
.app-shell.sidebar-collapsed .app-sidebar { padding-right: 11px; padding-left: 11px; }
.app-shell.sidebar-collapsed .sidebar-toggle span { transform: rotate(180deg); }
.app-shell.sidebar-collapsed .sidebar-brand { justify-content: center; padding-right: 0; padding-left: 0; }
.app-shell.sidebar-collapsed .sidebar-brand > span:last-child,
.app-shell.sidebar-collapsed .desktop-nav button strong,
.app-shell.sidebar-collapsed .sidebar-create strong,
.app-shell.sidebar-collapsed .sidebar-note p { display: none; }
.app-shell.sidebar-collapsed .desktop-nav button { display: flex; grid-template-columns: none; justify-content: center; padding: 6px; }
.app-shell.sidebar-collapsed .desktop-nav button > span { width: 38px; height: 38px; }
.app-shell.sidebar-collapsed .sidebar-create { width: 48px; height: 48px; min-height: 48px; margin-right: auto; margin-left: auto; padding: 0; }
.app-shell.sidebar-collapsed .sidebar-create span { font-size: 22px; }
.app-shell.sidebar-collapsed .sidebar-note { display: flex; justify-content: center; padding: 10px; }
.app-shell.sidebar-collapsed .sidebar-note > span { flex: 0 0 27px; }

.app-shell.focus-mode { display: block; }
.app-shell.focus-mode .app-sidebar, .app-shell.focus-mode .main-header, .app-shell.focus-mode .mobile-nav { display: none !important; }
.app-shell.focus-mode .app-workspace { min-height: 100dvh; }

@media (max-width: 1100px) {
  :root { --sidebar-width: 220px; }
  .app-sidebar { padding-inline: 13px; }
  .sidebar-brand strong { font-size: 13px; }
  .collection-content .story-library, .collection-content .community-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: minmax(0, 1.25fr) minmax(250px, .75fr); }
}

@media (max-width: 820px) {
  body.app-open { padding-bottom: env(safe-area-inset-bottom); }
  .app-shell { display: block; }
  .app-sidebar { display: none; }
  .app-workspace { min-height: 100dvh; }
  .main-header { height: 68px; padding: 9px 16px; }
  .mobile-brand { display: block; }
  .mobile-brand .brand-mark { width: 40px; height: 40px; font-size: 11px; }
  .page-context { margin-right: auto; margin-left: 2px; }
  .page-context small { display: none; }
  .page-context strong { font-size: 14px; }
  .account-menu .account-button { min-width: 0; width: 42px; height: 42px; padding: 0; place-items: center; border-radius: 14px; }
  .account-menu .account-button span { display: block; width: 26px; font-size: 0; }
  .account-menu .account-button span::first-letter { font-size: 11px; }
  .account-menu .account-button small, .account-menu .logout-button { display: none; }
  .app-main { padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed;
    z-index: 50;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(32, 48, 54, .1);
    background: rgba(255, 253, 249, .94);
    box-shadow: 0 -10px 30px rgba(39, 50, 47, .08);
    backdrop-filter: blur(20px) saturate(125%);
  }
  .mobile-nav button { display: flex; align-items: center; justify-content: center; gap: 3px; min-width: 0; padding: 4px 2px; flex-direction: column; border: 0; background: transparent; color: #708084; }
  .mobile-nav button > span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; font-size: 17px; }
  .mobile-nav button > strong { font-size: 8px; font-weight: 800; }
  .mobile-nav button.active { color: var(--primary-dark); }
  .mobile-nav button.active > span { color: var(--primary-dark); background: var(--lavender); }
  .mobile-nav .mobile-create > span { width: 48px; height: 48px; margin-top: -20px; border: 5px solid var(--app-surface); border-radius: 17px; color: #fff; background: var(--primary-dark); box-shadow: 0 8px 20px rgba(23, 79, 82, .25); font-size: 25px; }
  .page-content, .home-content { padding: 30px 18px 42px; }
  .dashboard-intro h1 { font-size: clamp(36px, 10vw, 52px); }
  .dashboard-grid { grid-template-columns: 1fr; margin-top: 28px; }
  .dashboard-grid .create-hero, .dashboard-grid .active-child-card { min-height: 132px; }
  .dashboard-links { grid-template-columns: 1fr; }
  .page-heading { align-items: flex-start; flex-direction: column; padding-bottom: 22px; }
  .page-heading .compact-button { width: 100%; }
  .account-page .child-list, .account-page .session-list { grid-template-columns: 1fr; }
  .account-page-heading #closeAccount { display: none; }
  .app-shell.focus-mode .app-main { padding-bottom: 0; }
}

@media (max-width: 560px) {
  .page-content, .home-content { padding-inline: 14px; }
  .dashboard-intro > p:last-child { font-size: 12px; }
  .dashboard-grid .create-hero { padding: 22px 18px; border-radius: 24px; }
  .dashboard-grid .create-hero strong { font-size: 19px; }
  .dashboard-grid .active-child-card { padding: 21px; border-radius: 22px; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestions button { min-height: 64px; }
  .dashboard-links > button { min-height: 92px; }
  .collection-content .story-library, .collection-content .community-library { grid-template-columns: 1fr; }
  .collection-content .story-card, .collection-content .community-card { display: grid; grid-template-columns: 118px minmax(0, 1fr); min-height: 142px; border-radius: 20px; }
  .collection-content .story-card img, .collection-content .community-card img { width: 118px; height: 100%; min-height: 142px; }
  .collection-content .story-card-copy, .collection-content .community-card-copy { align-self: center; padding: 13px; }
  .collection-content .story-card-meta { flex-wrap: wrap; gap: 4px; }
  .collection-content .story-card-meta span { padding: 4px 6px; font-size: 8px; }
  .collection-toolbar { margin-top: 0; }
  .community-safety { align-items: flex-start; }
  .collection-content .community-locked { grid-template-columns: 1fr; text-align: center; }
  .collection-content .community-locked > span { margin: auto; }
  .account-page .account-section, .account-page .child-form { padding: 18px 15px; border-radius: 18px; }
  .account-page .account-section-title, .account-page .data-actions { align-items: stretch; }
  .account-page .account-section-title button { width: 100%; }
  .creation-screen .flow-page { padding-right: 14px; padding-left: 14px; }
  .creation-screen fieldset { padding: 16px 12px; }
  .creation-screen .image-style-choice { min-height: 94px; }
  .creation-screen .bottom-action { padding-right: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); padding-left: 12px; }
}

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