/* ============================================================
   Demo Core — Variables, reset, sidebar, layout, topbar
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* === Brand (officielle Woopets.fr — préservée) === */
    --c-primary: #1b555c;
    --c-primary-hover: #134148;
    --c-primary-soft: #48b5a8;
    --c-primary-muted: #37a598;
    --c-primary-light: #dcf0ed;

    /* === Accent (peach officiel + corail vivid moderne) === */
    --c-accent: #f7ab77;
    --c-accent-hover: #ec8e4f;
    --c-accent-light: #fcf0e9;
    --c-accent-soft: #fae4d7;
    --c-accent-vivid: #ff7a59;
    --c-accent-vivid-hover: #e85a3a;

    /* === Surfaces (officielles Woopets.fr — famille light teal cohérente) === */
    --c-bg: #f0f9f9;
    --c-bg-warm: #e2f1ef;
    --c-bg-card: #ffffff;
    --c-bg-chat: #f0f9f9;
    --c-bg-elevated: #ffffff;
    --c-bg-sidebar: #e2f1ef;

    /* === Text (modernisés, taupe officiel pour le muted) === */
    --c-text: #131516;
    --c-text-secondary: #545454;
    --c-text-muted: #7d7474;
    --c-text-inverse: #ffffff;

    /* === Borders (light teals officiels Woopets.fr — visibles sur --c-bg-warm) === */
    --c-border: #cce7e3;
    --c-border-light: #dde8e4;

    /* === Chat bubbles === */
    --c-bubble-user: #1b555c;
    --c-bubble-user-text: #ffffff;
    --c-bubble-agent: #ffffff;
    --c-bubble-agent-text: #131516;

    /* === Functional === */
    --c-success: #16a34a;
    --c-danger: #dc2626;
    --c-warning: #d97706; /* amber-600 (Tailwind) */
    /* Famille bannière d'urgence (mode « situation sérieuse ») — ambres Tailwind */
    --c-warning-light: #fffbeb;  /* amber-50 — fond */
    --c-warning-border: #fcd34d; /* amber-300 — bordure */
    --c-warning-text: #92400e;   /* amber-800 — texte, 6,8:1 sur warning-light (AA) */

    /* === Shadows (woopets.fr double-layer) === */
    --shadow-xs: 0 1px 2px rgba(10, 30, 20, 0.04);
    --shadow-sm: 0 1px 3px rgba(10, 30, 20, 0.06), 0 1px 2px rgba(10, 30, 20, 0.04);
    --shadow-md: 0 4px 12px rgba(10, 30, 20, 0.08), 0 2px 4px rgba(10, 30, 20, 0.04);
    --shadow-lg: 0 8px 24px rgba(10, 30, 20, 0.1), 0 2px 4px rgba(10, 30, 20, 0.04);
    --shadow-xl: 0 20px 48px rgba(10, 30, 20, 0.14);
    --shadow-glow: 0 0 0 4px rgba(27, 85, 92, 0.12);
    --focus-ring: 0 0 0 3px rgba(27, 85, 92, 0.3);
    --focus-ring-accent: 0 0 0 3px rgba(247, 171, 119, 0.35);
    --focus-ring-vivid: 0 0 0 3px rgba(255, 122, 89, 0.35);

    /* === Radii === */
    --r-xs: 4px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-full: 9999px;

    /* === Typography (Google Fonts: Inter + Fraunces) === */
    --f-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --f-body: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;

    /* === Motion === */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --dur-fast: 150ms;
    --dur-normal: 250ms;
    --dur-slow: 400ms;

    /* === Sidebar (light variant) === */
    --sidebar-width: 260px;
    --sidebar-text: #2a2a2a;
    --sidebar-text-muted: #7a7a7a;
    --sidebar-hover: rgba(27, 85, 92, 0.06);
    --sidebar-active: rgba(27, 85, 92, 0.1);
    --sidebar-border: rgba(27, 85, 92, 0.08);
}

/* [V2-SKIN] Tokens du redesign V2 « Atelier-iOS ». Bloc d'override scopé : redéfinit un
   sous-ensemble des radii existants + ajoute les tokens --v2-* (densité, hairline, materials,
   grands titres, élévation). N'altère JAMAIS les couleurs de marque (--c-*). Le :root global
   (desktop / iframe embed) reste intact. Pas de fallback var(--x, #hex) (cf. CLAUDE.md). */
body.v2-skin {
    /* Radius iOS (un cran plus rond) — surcharge les radii consommés par les composants */
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 24px;

    /* Densité tactile */
    --v2-gap-tight: 8px;
    --v2-gap: 12px;
    --v2-pad-card: 14px;
    --v2-touch: 44px;

    /* Hairline iOS — double déclaration : fallback 1px d'abord (vieux WebView Android sans
       color-mix gardent celui-ci), puis 0.5px color-mix si supporté */
    --v2-hairline: 1px solid var(--c-border-light);
    --v2-hairline: 0.5px solid color-mix(in srgb, var(--c-text) 8%, transparent);

    /* Materials (barres translucides) — blur autorisé web mobile uniquement (T3), fond
       opaque teinté en shell (le code woopets-shell coupe backdrop-filter pour le GPU) */
    --v2-blur: saturate(180%) blur(20px);
    --v2-mat-bg: rgba(240, 249, 249, 0.72);
    --v2-mat-bg-strong: rgba(240, 249, 249, 0.86);

    /* Grands titres (Fraunces déjà chargée via --f-display) */
    --v2-title-size: clamp(1.55rem, 6vw, 2rem);
    --v2-title-weight: 600;

    /* Élévation carte douce */
    --v2-shadow-card: 0 1px 2px rgba(10, 30, 20, 0.04), 0 8px 24px rgba(10, 30, 20, 0.06);
}

html {
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: var(--f-body);
    color: var(--c-text);
    background: var(--c-bg);
    overflow: hidden;
}

/* Layout wrapper : sidebar + main en row, footer en frere apres (flex column sur body) */
.demo-layout {
    display: flex;
    flex-direction: row;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR — Light ivoire (woopets.fr aligned)
   ============================================================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
    opacity: 0;
    transition: opacity var(--dur-normal) var(--ease-out);
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.demo-sidebar {
    width: var(--sidebar-width);
    height: 100%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--c-bg-sidebar);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    z-index: 50;
    transition: transform var(--dur-normal) var(--ease-out);
}

/* STRATE 1 — Header (flex-shrink:0) : marque + fermeture mobile + CTA */
.sidebar-header {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.6rem 0.6rem 0.55rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 30px;
}

/* Bouton de fermeture — mobile uniquement (desktop : sidebar permanente) */
.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.sidebar-close-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: var(--sidebar-text);
}

.sidebar-brand svg {
    height: 22px;
    width: auto;
}

.sidebar-brand-text {
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    background: var(--c-primary);
    padding: 0.12rem 0.4rem;
    border-radius: var(--r-xs);
    letter-spacing: 0.06em;
}

/* CTA « Nouvelle conversation » pleine largeur (remplace l'ancien "+" icône-seule) */
.sidebar-new-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.4rem; /* respire sous le logo (s'ajoute au gap 0.5rem du header) */
    min-height: 44px;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--c-primary-soft);
    border-radius: var(--r-sm);
    background: var(--c-primary);
    color: var(--c-text-inverse);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast), transform var(--dur-fast);
}

.sidebar-new-cta svg { flex-shrink: 0; }
.sidebar-new-cta:hover { background: var(--c-primary-hover); }
.sidebar-new-cta:active { transform: scale(0.99); }

/* STRATE 2 — Body : unique zone scrollable (les conversations dominent).
   Bloc simple (pas un flex column) : sinon les enfants flex-shrink:1 se feraient
   comprimer/tronquer au lieu de laisser le body scroller quand le contenu déborde. */
.sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-conversations {
    padding: 0.5rem 0;
}

.sidebar-group {
    padding: 0 0.5rem;
}

.sidebar-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sidebar-text-muted);
    padding: 0.75rem 0.5rem 0.25rem;
}

.sidebar-conv-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.5rem;
    margin: 1px 0;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background var(--dur-fast), border-left-color var(--dur-fast);
    position: relative;
    border: none;
    border-left: 3px solid transparent;
    background: transparent;
    color: var(--sidebar-text);
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: 0.84rem;
    line-height: 1.35;
}

.sidebar-conv-item:hover {
    background: var(--sidebar-hover);
}

.sidebar-conv-item.active {
    background: var(--sidebar-active);
    border-left-color: var(--c-primary-soft);
}

.conv-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.conv-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bouton "⋯" par conversation → ouvre le menu contextuel (rename/pin/archive/delete).
   L'espace (24px + gap) est réservé en permanence (opacity, pas display) : basculer
   display:none → flex au :hover comprimait le titre → layout shift visible. */
.conv-item-menu-btn {
    display: flex;
    opacity: 0;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--r-xs);
    background: transparent;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: color var(--dur-fast), background var(--dur-fast), opacity var(--dur-fast);
}

.sidebar-conv-item:hover .conv-item-menu-btn,
.conv-item-menu-btn:focus-visible {
    opacity: 1;
}

.conv-item-menu-btn:hover {
    color: var(--sidebar-text);
    background: rgba(27, 85, 92, 0.1);
}

/* Menu contextuel de conversation (singleton position:fixed appende au body) */
.conv-menu {
    display: none;
    position: fixed;
    z-index: 9600;
    min-width: 185px;
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
    padding: 0.3rem;
}

.conv-menu.open {
    display: block;
}

.conv-menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: none;
    background: transparent;
    border-radius: var(--r-sm);
    color: var(--c-text);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background var(--dur-fast);
}

.conv-menu-item:hover {
    background: var(--c-bg);
}

.conv-menu-item svg {
    flex-shrink: 0;
}

.conv-menu-item.danger {
    color: var(--c-danger);
}

.conv-menu-item.danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

/* Renommage inline dans l'item de sidebar */
.conv-rename-input {
    width: 100%;
    border: 1px solid var(--c-primary-soft);
    border-radius: var(--r-xs);
    padding: 2px 6px;
    font-size: 0.84rem;
    font-family: inherit;
    line-height: 1.35;
    color: var(--c-text);
    background: var(--c-bg-card);
    outline: none;
}

/* Anti-zoom iOS : les inputs < 16px declenchent un zoom au focus */
@supports (-webkit-touch-callout: none) {
    .conv-rename-input {
        font-size: 16px;
    }
}

/* Acces a la vue archivee (bas de la liste) */
.sidebar-archived-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: calc(100% - 1rem);
    margin: 0.5rem 0.5rem 0.25rem;
    padding: 0.5rem;
    border: none;
    background: transparent;
    border-radius: var(--r-sm);
    color: var(--sidebar-text-muted);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.sidebar-archived-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

/* Header de la vue archivee (retour + titre) */
.sidebar-archived-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.5rem 0.25rem;
}

.sidebar-archived-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.sidebar-archived-back:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.sidebar-archived-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

/* Status dot : streaming en cours OU reponse non-lue */
.conv-item-status {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 2px;
}
.sidebar-conv-item.streaming .conv-item-status {
    background: var(--c-primary-soft);
    box-shadow: 0 0 0 0 rgba(72, 181, 168, 0.55);
    animation: sidebar-conv-pulse 1.4s ease-out infinite;
}
.sidebar-conv-item.unread .conv-item-status {
    background: var(--c-accent-vivid);
}
@keyframes sidebar-conv-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(72, 181, 168, 0.55); }
    70%  { box-shadow: 0 0 0 7px rgba(72, 181, 168, 0); }
    100% { box-shadow: 0 0 0 0 rgba(72, 181, 168, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .sidebar-conv-item.streaming .conv-item-status {
        animation: none;
        box-shadow: 0 0 0 2px rgba(72, 181, 168, 0.35);
    }
}

/* Etat grise pour les actions bloquees pendant un envoi/streaming.
 * Volontairement sans `pointer-events: none` : on laisse le clic passer
 * pour que la garde dans newConversation/deleteConversation puisse afficher
 * le toast d'explication (sinon l'user clique dans le vide sans feedback). */
.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.4);
}
.is-disabled:hover {
    background: transparent !important;
    color: inherit !important;
}

.sidebar-empty {
    padding: 2.5rem 1rem;
    text-align: center;
}
/* [V1.6] Empty state riche (clone de .pet-list-empty) — fond teal de la sidebar →
   var(--sidebar-text*) (PAS var(--c-text*), sinon texte quasi invisible). */
.sidebar-empty-icon {
    color: var(--sidebar-text-muted);
    opacity: 0.35;
    margin-bottom: 0.75rem;
}
/* Inter, pas Fraunces : un état vide n'est ni un expert ni un moment de marque
   (Règle de la Signature, DESIGN.md). */
.sidebar-empty-text {
    font-family: var(--f-body);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--sidebar-text);
    margin-bottom: 0.35rem;
}
.sidebar-empty-sub {
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--sidebar-text-muted);
}

/* ---- Sidebar pets section ---- */

/* Section animaux — repliable (<details>), ÉLEVÉE en tête du corps (avant les
   conversations) pour pousser l'ajout. border-bottom (et non -top) : elle se sépare
   des conversations en dessous, sans doublonner le border-bottom du header au-dessus.
   Plus de max-height/overflow propre : c'est .sidebar-body qui scrolle désormais. */
.sidebar-pets-section {
    border-bottom: 1px solid var(--sidebar-border);
    background: rgba(27, 85, 92, 0.03);
    padding: 0.25rem 0.5rem 0.5rem;
}

.sidebar-pets-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sidebar-text-muted);
    padding: 0 0.35rem 0.3rem;
}

.sidebar-pet-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.35rem;
    border-radius: var(--r-8);
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    font-family: inherit;
    cursor: pointer;
    transition: background var(--dur-fast);
    text-align: left;
}

.sidebar-pet-item:hover {
    background: var(--sidebar-hover);
}

.sidebar-pet-avatar {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.sidebar-pet-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-pet-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.sidebar-pet-breed {
    font-size: 0.68rem;
    color: var(--sidebar-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.sidebar-pet-add-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.3rem 0.35rem;
    margin-top: 0.15rem;
    border-radius: var(--r-8);
    border: none;
    background: transparent;
    color: var(--sidebar-text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    cursor: pointer;
    transition: color var(--dur-fast), background var(--dur-fast);
}

.sidebar-pet-add-btn:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
}

/* STRATE 3 — Footer compte (flex-shrink:0 + safe-area iOS).
   Pas de fond distinct : il reprend le fond de la sidebar (séparation via la
   bordure haute) — un fond blanc jurait avec le teal du reste du menu. */
.sidebar-bottom {
    flex-shrink: 0;
    border-top: 1px solid var(--sidebar-border);
    padding: 0.5rem;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
}

.sidebar-delete-all-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem;
    padding: 0.6rem;
    border-radius: var(--r-sm);
    background: transparent;
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text-muted);
    font-size: 0.85rem;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-delete-all-btn:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.3);
    color: var(--c-danger);
}

.sidebar-delete-all-btn svg {
    flex-shrink: 0;
}

.sidebar-settings-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.5rem;
    border-radius: var(--r-sm);
    color: var(--sidebar-text);
    font-size: 0.84rem;
    font-family: inherit;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background var(--dur-fast);
}

.sidebar-settings-btn:hover {
    background: var(--sidebar-hover);
}

/* Paramètres (langue + usage) désormais accessible à TOUS, anonymes inclus :
   l'ancien mask `body.is-anon .sidebar-settings-btn { display:none }` est retiré
   (le sélecteur de langue vit aussi dans le <details> « Plus » ci-dessous). */

/* ---- « Plus » : disclosure repliée (langue + liens légaux + copyright) ----
   Masquée sur desktop : le footer global pleine largeur (sous le chat) porte
   déjà langue + liens légaux → on évite la redondance. Visible mobile seulement
   (le footer global y est masqué, cf. media query mobile). */
.sidebar-more {
    display: none;
    margin-top: 2px;
    border-top: 1px solid var(--sidebar-border);
    padding-top: 2px;
}

.sidebar-more-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0.5rem;
    border-radius: var(--r-sm);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    transition: background var(--dur-fast);
}
.sidebar-more-summary::-webkit-details-marker { display: none; }
.sidebar-more-summary:hover { background: var(--sidebar-hover); }

.sidebar-more-caret {
    color: var(--sidebar-text-muted);
    transition: transform var(--dur-fast);
}
.sidebar-more[open] .sidebar-more-caret { transform: rotate(180deg); }

.sidebar-more-panel {
    padding: 0.35rem 0.5rem 0.5rem;
}

/* Sélecteur de langue — grille 5 colonnes lisible (vs 11px tassés du footer fixe supprimé) */
.sidebar-lang {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.25rem;
    margin-bottom: 0.6rem;
}

.sidebar-lang-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.4rem 0.15rem;
    border-radius: var(--r-sm);
    text-decoration: none;
    color: var(--sidebar-text-muted);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.sidebar-lang-btn:hover {
    background: var(--sidebar-hover);
    color: var(--c-primary);
}

.sidebar-lang-btn.active {
    background: var(--c-primary);
    color: var(--c-text-inverse);
}

.sidebar-lang-btn span[aria-hidden] { font-size: 1rem; line-height: 1; }

.sidebar-legal-links {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
}

/* Une colonne : évite le wrap des libellés FR longs (« Politique de
   confidentialité ») dans le drawer étroit, et donne des rangées tactiles. */
.sidebar-legal-links a {
    display: block;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    font-size: 0.76rem;
    line-height: 2.1;
    transition: color var(--dur-fast);
}

.sidebar-legal-links a:hover {
    color: var(--c-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.sidebar-copy {
    margin: 0;
    font-size: 0.7rem;
    color: var(--sidebar-text-muted);
}

/* ---- User section: row + popover ---- */

.sidebar-user-section {
    margin-bottom: 4px;
    position: relative;
}

.sidebar-user-section:empty {
    margin-bottom: 0;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background var(--dur-fast);
    width: 100%;
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    font-family: inherit;
    text-align: left;
}

.user-row:hover {
    background: var(--sidebar-hover);
}

.user-avatar-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--c-primary);
    color: white;
    font-weight: 700;
    font-size: 0.72rem;
    flex-shrink: 0;
}

.user-row-name {
    flex: 1;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-row-chevron {
    flex-shrink: 0;
    color: var(--sidebar-text-muted);
    transition: transform var(--dur-fast);
}

.user-row.popover-open .user-row-chevron {
    transform: rotate(180deg);
}

/* Popover above the user row */
.user-popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--c-bg-card);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 60;
    animation: popoverIn var(--dur-normal) var(--ease-spring);
}

.user-popover.open {
    display: block;
}

@keyframes popoverIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-popover-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--r-sm);
    color: var(--c-text);
    font-size: 0.82rem;
    font-family: inherit;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background var(--dur-fast);
}

.user-popover-item:hover {
    background: var(--c-bg-warm);
}

.user-popover-item.danger {
    color: var(--c-danger);
}

.user-popover-item.danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

.user-popover-divider {
    height: 1px;
    background: var(--c-border-light);
    margin: 3px 0;
}

/* Login button for non-authenticated */
.user-register-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.6rem;
    margin-bottom: 4px;
    border-radius: var(--r-sm);
    /* Vocabulaire « soumission » (Encre → hover teal) : le corail vif est réservé
       au bouton d'envoi — Règle du Corail Unique (DESIGN.md). */
    background: var(--c-text);
    color: var(--c-text-inverse);
    font-size: 0.84rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background var(--dur-fast);
}

.user-register-btn svg { flex-shrink: 0; }

.user-register-btn:hover { background: var(--c-primary); }

.user-login-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.5rem;
    border-radius: var(--r-sm);
    /* Teal lisible (AA ≥ 4,5:1) : la pêche ne passe pas en texte sur fond teinté (1,6:1). */
    color: var(--c-primary);
    font-size: 0.84rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background var(--dur-fast);
}

.user-login-btn:hover {
    background: var(--sidebar-hover);
}

/* ============================================================
   MAIN AREA
   ============================================================ */

.demo-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
}

/* [V3.1/V3.2] Bottom tab bar — responsive partagé (web mobile + app), JAMAIS desktop ni embed.
   En flux flex (dernier enfant de .demo-main), pas position:fixed. Translucide+blur web mobile,
   opaque en shell (perf GPU). hidden statique + révélation JS (W.revealTabbar). */
.app-tabbar { display: none; }
@media (max-width: 767px) {
    .app-tabbar:not([hidden]) {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        flex-shrink: 0;
        border-top: 1px solid var(--c-border-light);
        background: rgba(240, 249, 249, 0.92);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    /* Un onglet [hidden] (clic/news, révélés par leurs init shell/FR) doit rester masqué :
       sans cette règle, .app-tab{display:flex} (auteur) écrase le [hidden] de l'UA → l'onglet
       Clics apparaissait sur le web mobile alors qu'il est app-only. */
    .app-tab[hidden] { display: none; }
    .app-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 52px;
        padding: 6px 4px;
        border: none;
        background: transparent;
        color: var(--c-text-muted);
        cursor: pointer;
        position: relative;
        transition: color var(--dur-fast);
        /* Supprime le carré gris/translucide de tap natif WebKit au clic (mobile). */
        -webkit-tap-highlight-color: transparent;
    }
    .app-tab-icon {
        width: 24px;
        height: 24px;
        padding: 2px 14px;
        box-sizing: content-box;
        border-radius: var(--r-full);
        transition: background var(--dur-fast);
    }
    .app-tab-label { font-size: 0.7rem; font-weight: 500; line-height: 1; }
    .app-tab.active { color: var(--c-primary); }
    .app-tab.active .app-tab-icon { background: var(--c-primary-light); }
    .app-tab-dot {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: 6px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--c-accent-vivid);
    }
    /* Collision input ↔ tabbar : la barre porte la safe-area, l'input la perd. */
    body.has-tabbar .demo-input-area { padding-bottom: 0.85rem; }
    /* Mobile (tab bar active) : le nom + popover compte de la sidebar fait doublon avec le
       menu compte derrière l'avatar de la topbar (#topbarAccountBtn) → on le masque. La
       sidebar devient un historique pur ; compte/déconnexion/langue vivent dans le menu compte. */
    body.has-tabbar .sidebar-user-section { display: none; }
    /* Idem pour Paramètres / Clics Solidaires / Actus : redondants sur mobile (Réglages est
       dans le menu compte ; Clics et Actus sont des onglets de la bottom tab bar). Gardé sur
       desktop (has-tabbar est aussi posé sur desktop → @media obligatoire). Seuls les liens
       légaux (« Plus ») restent dans la sidebar mobile. */
    body.has-tabbar .sidebar-settings-btn,
    body.has-tabbar .sidebar-clic-entry,
    body.has-tabbar .sidebar-news-entry { display: none; }
    /* Clavier : masquer la barre (input remonte). keyboard-open = shell (T8) ; input-focused
       = filet web mobile (focus textarea → clavier monte). */
    body.keyboard-open .app-tabbar,
    body.input-focused .app-tabbar { display: none; }
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    @media (max-width: 767px) {
        body:not(.woopets-shell) .app-tabbar:not([hidden]) {
            background: rgba(240, 249, 249, 0.82);
            -webkit-backdrop-filter: blur(20px);
            backdrop-filter: blur(20px);
        }
    }
}

/* [V3.5] Avatar compte topbar — mobile-only (révélé par revealTabbar ; CSS le garde < 768px). */
.topbar-account-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--c-text-secondary);
    cursor: pointer;
    border-radius: var(--r-full);
}
@media (max-width: 767px) {
    .topbar-account-btn:not([hidden]) { display: flex; }
    /* [V3.5b] L'icône liste (historique conversations) n'apparaît que sur l'onglet Chat quand la
       tab bar est active ; sur les autres onglets le back/contexte prend le relais. */
    body.has-tabbar:not(.tab-chat) .topbar-menu-btn { display: none; }
}

/* [V3.8] Clavier (shell) : avec @capacitor/keyboard + resize:'none', le WebView ne se
   redimensionne pas → on rétrécit .demo-main de la hauteur du clavier (--kb-height posée par
   le bridge initKeyboard) pour remonter le composer au-dessus du clavier. INERTE sans le plugin
   (--kb-height absente → calc(100% - 0px) = 100%). Activé à la prochaine soumission store. */
body.woopets-shell .demo-main { transition: height 0.22s ease-out; }
@media (max-width: 767px) {
    body.keyboard-open.woopets-shell .demo-main {
        height: calc(100% - var(--kb-height, 0px));
    }
}

/* [V4.4] Onboarding 3 cartes — révélé par le bridge (demo-native.js) au 1er lancement de l'app.
   Inerte hors shell (élément hidden, jamais révélé sur web/embed). Palette Atelier-iOS. */
.app-onboarding {
    position: fixed;
    inset: 0;
    z-index: 99990;
    background: var(--c-bg);
    display: flex;
    flex-direction: column;
}
/* CRITIQUE : respecter l'attribut hidden (sinon .app-onboarding{display:flex} l'écrase et
   l'écran s'affiche sur desktop/web). Révélé UNIQUEMENT par le bridge app (initOnboarding). */
.app-onboarding[hidden] { display: none; }
.app-onboarding-pages {
    flex: 1;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.app-onboarding-pages::-webkit-scrollbar { display: none; }
.app-onboarding-page {
    flex: 0 0 100%;
    width: 100%;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 18px;
    padding: 48px 32px;
    padding-top: max(72px, env(safe-area-inset-top));
}
.app-onboarding-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--c-primary-light);
    color: var(--c-primary);
    margin-bottom: 8px;
}
.app-onboarding-title {
    font-family: var(--f-display);
    font-style: italic;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--c-text);
    margin: 0;
    line-height: 1.2;
}
.app-onboarding-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--c-text-secondary);
    max-width: 340px;
    margin: 0;
}
.app-onboarding-next,
.app-onboarding-cta,
.app-onboarding-later {
    margin-top: 12px;
    min-width: 200px;
    padding: 14px 24px;
    border-radius: var(--r-full);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
}
.app-onboarding-next,
.app-onboarding-cta {
    background: var(--c-primary);
    color: var(--c-text-inverse);
}
.app-onboarding-later {
    margin-top: 4px;
    background: transparent;
    color: var(--c-text-muted);
    font-weight: 500;
}
.app-onboarding-skip {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: 18px;
    z-index: 2;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--c-text-muted);
    font-size: 0.9rem;
    cursor: pointer;
}
.app-onboarding-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 16px 0 max(24px, env(safe-area-inset-bottom));
}
.app-onboarding-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-border);
    transition: width var(--dur-fast), background var(--dur-fast);
}
.app-onboarding-dot.active {
    width: 22px;
    border-radius: 4px;
    background: var(--c-primary);
}

/* ---- Topbar ---- */

.demo-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: 0 1.25rem;
    background: rgba(240, 249, 249, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--c-border-light);
    flex-shrink: 0;
}

/* [V2-SKIN] Topbar « Atelier-iOS » : hairline ; materials (blur renforcé) réservés au WEB
   MOBILE (:not(.woopets-shell)) sous @supports — en shell la topbar reste opaque (#f0f9f9,
   cf. body.woopets-shell .demo-topbar) car un backdrop-filter permanent y cause un lag de
   premier tap (bug GPU WebKit documenté). Android web mobile : blur OK (Chrome), fallback
   opaque si @supports faux. [V2.2 + V2.3] */
body.v2-skin .demo-topbar {
    border-bottom: var(--v2-hairline);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    body.v2-skin:not(.woopets-shell) .demo-topbar {
        background: var(--v2-mat-bg);
        -webkit-backdrop-filter: var(--v2-blur);
        backdrop-filter: var(--v2-blur);
    }
}

/* [V2.6 désactivé — décision UX] Les titres de sous-vues (Mes animaux, carnet, profil…)
   s'affichent dans le HEADER (topbar), comme les autres pages (Clics/Actus), pour rester
   cohérent. Le grand titre iOS #petViewLargeTitle reste dans le markup mais n'est jamais
   affiché, et le titre topbar n'est plus masqué en sous-vue (.has-large-title est inerte). */
.view-large-title { display: none; }

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--c-text-secondary);
    cursor: pointer;
    transition: background var(--dur-fast);
}

.topbar-menu-btn:hover {
    background: var(--c-bg-warm);
    color: var(--c-primary);
}

.topbar-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--c-text);
    letter-spacing: -0.01em;
}

.topbar-agent-indicator {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.3rem 0.75rem 0.3rem 0.3rem;
    background: var(--c-bg-card);
    border: 1px solid var(--c-border-light);
    border-radius: var(--r-full);
    box-shadow: var(--shadow-xs);
    animation: fadeIn var(--dur-normal) var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.indicator-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.indicator-avatar img,
.indicator-avatar .agent-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.indicator-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.indicator-name {
    font-family: var(--f-display);
    font-size: 0.92rem;
    font-weight: 500;
    font-style: italic;
    color: var(--c-primary);
    white-space: nowrap;
    line-height: 1.15;
    letter-spacing: -0.005em;
    /* Titre de conversation (pattern Claude) : tronquer proprement si long */
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(48vw, 560px);
}

.indicator-role {
    font-size: 0.68rem;
    color: var(--c-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--c-text-secondary);
    cursor: pointer;
    transition: background var(--dur-fast), border-color var(--dur-fast);
}

.topbar-new-btn:hover {
    background: var(--c-bg-warm);
    border-color: var(--c-primary-soft);
    color: var(--c-primary);
}

/* ---- Topbar brand (logo) — montré sur l'écran d'accueil mobile.
   Sur desktop, la sidebar porte déjà le logo, donc il reste masqué. ---- */
.topbar-brand {
    display: none;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
}

.topbar-brand svg {
    height: 24px;
    width: auto;
    display: block;
}

.topbar-brand-text {
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    background: var(--c-primary);
    padding: 0.12rem 0.4rem;
    border-radius: var(--r-xs);
    letter-spacing: 0.06em;
}

/* ---- Topbar register CTA — visiteur anonyme, écran d'accueil uniquement ---- */
.topbar-register-btn {
    display: none;
    align-items: center;
    padding: 0.42rem 0.9rem;
    border: none;
    border-radius: var(--r-full);
    /* Encre → hover teal : corail réservé au send (Règle du Corail Unique, DESIGN.md). */
    background: var(--c-text);
    color: var(--c-text-inverse);
    font-family: var(--f-body);
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--dur-fast), transform var(--dur-fast);
}

.topbar-register-btn:hover { background: var(--c-primary); }
.topbar-register-btn:active { transform: scale(0.97); }

/* Sur l'écran d'accueil, le bouton "+" est redondant (on est déjà sur un chat vierge). */
body.is-chat-welcome .topbar-new-btn { display: none; }
/* Le CTA d'inscription n'apparaît que pour les anonymes, sur l'écran d'accueil. */
body.is-anon.is-chat-welcome .topbar-register-btn { display: inline-flex; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.6rem 1.2rem;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    font-weight: 500;
    color: white;
    pointer-events: auto;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--dur-normal) var(--ease-out), transform var(--dur-normal) var(--ease-out);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.toast-error { background: var(--c-danger); }
.toast.toast-success { background: var(--c-success); }
.toast.toast-info { background: var(--c-primary); }
.toast.toast-warning { background: var(--c-warning); }

/* ============================================================
   SIDEBAR PETS SECTION
   ============================================================ */

/* La section animaux est un <details> ; .sidebar-pets-title en est le <summary> */
.sidebar-pets-section > summary {
    list-style: none;
    cursor: pointer;
}
.sidebar-pets-section > summary::-webkit-details-marker { display: none; }

.sidebar-pets-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sidebar-text-muted);
    padding: 0.5rem 0.35rem;
    min-height: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    border-radius: var(--r-xs);
    transition: background var(--dur-fast);
}

.sidebar-pets-title:hover { background: var(--sidebar-hover); }

.sidebar-pets-title-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-pets-title-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.sidebar-pets-caret {
    color: var(--sidebar-text-muted);
    transition: transform var(--dur-fast);
}

.sidebar-pets-section[open] .sidebar-pets-caret { transform: rotate(180deg); }

.sidebar-pets-list { padding-top: 2px; }

/* Compteur "(N)" accolé au titre quand l'utilisateur a des animaux */
.sidebar-pets-count { font-weight: 600; }

/* État vide RICHE (connecté sans animaux) : bénéfice IA + gros CTA d'ajout.
   Dans le contenu du <details> (pas le summary) → pas d'uppercase hérité. */
.sidebar-pets-benefit {
    margin: 0 0 0.5rem;
    padding: 0 0.35rem;
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--sidebar-text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.sidebar-pets-add-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: var(--r-sm);
    background: var(--c-primary);
    color: var(--c-text-inverse);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast);
}

.sidebar-pets-add-cta svg { flex-shrink: 0; }
.sidebar-pets-add-cta:hover { background: var(--c-primary-hover); }

.sidebar-pets-add-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: var(--r-xs);
    background: var(--sidebar-hover);
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
    border: none;
}

.sidebar-pets-add-icon:hover {
    background: var(--sidebar-active);
    color: var(--c-primary);
}

.sidebar-pet-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background var(--dur-fast);
}

.sidebar-pet-item:hover {
    background: var(--sidebar-hover);
}

.sidebar-pet-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-pet-info {
    flex: 1;
    min-width: 0;
}

.sidebar-pet-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.sidebar-pet-details {
    font-size: 0.7rem;
    color: var(--sidebar-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.sidebar-pet-actions {
    display: flex;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
    transition: opacity var(--dur-fast);
    flex-shrink: 0;
}

.sidebar-pet-item:hover .sidebar-pet-actions {
    opacity: 1;
}

.sidebar-pet-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: var(--r-xs);
    background: var(--sidebar-hover);
    color: var(--sidebar-text-muted);
    border: none;
    cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.sidebar-pet-action-btn:hover {
    background: var(--sidebar-active);
    color: var(--c-primary);
}

.sidebar-pet-action-btn.delete:hover {
    background: rgba(220, 38, 38, 0.1);
    color: var(--c-danger);
}

.sidebar-pets-empty {
    padding: 10px 8px;
    font-size: 0.78rem;
    color: var(--sidebar-text-muted);
    text-align: center;
}

/* ---- Topbar back button ---- */

.topbar-back-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--r-sm);
    background: transparent;
    border: none;
    color: var(--c-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
}

.topbar-back-btn:hover {
    background: var(--c-bg-warm);
    color: var(--c-text);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--c-border);
    border-radius: var(--r-full);
}

.demo-sidebar ::-webkit-scrollbar-thumb {
    background: rgba(27, 85, 92, 0.18);
}

/* ============================================================
   TEXT SELECTION
   ============================================================ */

::selection { background: rgba(27, 85, 92, 0.18); color: var(--c-text); }

/* ============================================================
   ACCESSIBILITY
   ============================================================ */

:focus { outline: none; }

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--r-sm);
}

.send-btn:focus-visible { box-shadow: var(--focus-ring); }

.sidebar-conv-item:focus-visible {
    box-shadow: inset 0 0 0 2px var(--c-primary);
}

.input-wrapper:has(.main-textarea:focus-visible) {
    border-color: var(--c-primary-soft);
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */

.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE — Core
   ============================================================ */

/* Tablet (768px–1023px) — sidebar compacte */
@media (min-width: 768px) and (max-width: 1023px) {
    :root { --sidebar-width: 220px; }
    .sidebar-brand-text { font-size: 0.8rem; }
    .conv-item-title { font-size: 0.78rem; }
}

/* Mobile (< 768px) — sidebar off-canvas, PLEIN ÉCRAN.
   bottom:0 (et non 96px) : l'ancienne barre légale fixe .site-footer 96px est
   supprimée (cf. site-footer.css) ; le drawer reprend toute la hauteur et le
   légal/langue vit désormais dans le <details> « Plus » du footer compte. */
@media (max-width: 767px) {
    .demo-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: auto;
        transform: translateX(-100%);
    }

    .demo-sidebar.open { transform: translateX(0); }
    .topbar-menu-btn { display: flex; }
    .sidebar-close-btn { display: flex; }

    /* « Plus » visible mobile uniquement (le footer global y est masqué ci-dessous) */
    .sidebar-more { display: block; }

    /* Le footer global pleine largeur n'a pas lieu d'être sur le chat mobile
       (légal désormais dans le drawer). On le masque UNIQUEMENT sur /demo/
       (présence de .demo-layout) ; il reste normal sur /legal/*, /contact/, /about/. */
    /* ~ (sibling) plutôt que body:has(...) : un :has() ancré sur body force
       WebKit à re-matcher à CHAQUE mutation DOM (innerHTML du boot, renders) —
       coûteux sur mobile. Même effet : le footer suit .demo-layout dans le DOM. */
    .demo-layout ~ .site-footer { display: none; }

    /* Le logo remplace le titre sur mobile. Le titre est masqué PAR DÉFAUT
       (pas via une classe) → « Nouvelle conversation » ne peut jamais flasher au
       boot, quel que soit le timing du JS ou l'état du cache Twig. Il ne
       réapparaît que dans les sous-vues (animaux, carnet de santé) via is-subview. */
    .topbar-title { display: none; }
    body.is-subview .topbar-title { display: block; cursor: pointer; }
    body.is-chat-welcome .topbar-brand { display: flex; }

    /* Toast : au-dessus du clavier virtuel */
    .toast-container { bottom: calc(env(safe-area-inset-bottom, 0px) + 4rem); }
}

/* Small mobile (< 480px) */
@media (max-width: 479px) {
    .demo-topbar { padding: 0 0.75rem; }
}

/* Tiny mobile (< 360px) */
@media (max-width: 359px) {
    .topbar-agent-indicator { padding: 0.2rem 0.45rem; gap: 0.35rem; }
    .indicator-name { font-size: 0.72rem; max-width: 44vw; }
    .indicator-role { display: none; }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    .demo-topbar { min-height: 40px; }
}

/* [V1.4] Sous-vues : glissement latéral iOS (drill-down) sur mobile/app — remplace le fade
   vertical (viewFadeIn/clicViewFadeIn) via une spécificité supérieure (.demo-chat-area .view-*) ;
   desktop (>767px) conserve le fade. reduced-motion neutralise globalement plus bas. */
@keyframes viewSlideInRight {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}
@media (max-width: 767px) {
    .demo-chat-area { overflow-x: clip; }
    .demo-chat-area .view-pet-form,
    .demo-chat-area .view-health-records,
    .demo-chat-area .view-app-clic,
    .demo-chat-area .view-app-news {
        animation: viewSlideInRight 240ms var(--ease-out);
    }
}

/* Touch devices — always show interactive elements */
@media (hover: none) and (pointer: coarse) {
    /* Pas de hover sur tactile → actions animaux toujours visibles (sinon intouchables). */
    .sidebar-pet-actions { opacity: 1; }
    /* Idem : le bouton menu "⋯" de conversation est hover-only (opacity:0 révélé
       au :hover) → intouchable au doigt (web mobile PWA + shell). On le révèle en
       permanence sur tactile. NON gaté shell : doit aussi corriger le PWA web mobile. [V1.1] */
    .conv-item-menu-btn { opacity: 0.6; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =========================================
   [NATIVE-HOOK] Shell Capacitor uniquement — classe posée par demo-native.js.
   La WebView native est plein écran (pas de chrome navigateur Safari) : le
   header et la sidebar doivent dégager l'encoche/Dynamic Island.

   Depuis Capacitor 8, WKWebView propage NATIVEMENT env(safe-area-inset-*) au CSS
   (avec ios.contentInset:'never' + viewport-fit=cover) → var(--wsafe-top, env(...))
   retombe directement sur env() natif. La variable --wsafe-* n'est plus injectée
   par personne (l'injection AppDelegate, requise en Cap 6 où env() renvoyait 0, a
   été retirée à la migration Cap 8) ; var(--wsafe-*, env(...)) ne la garde que
   comme fallback inoffensif. Inerte sur le web (woopets-shell n'y est jamais posée).
   ========================================= */
body.woopets-shell .demo-topbar {
    /* Reproduit la géométrie du site web sous l'encoche : la zone de contenu
       doit faire 56px avec le contenu CENTRÉ (web mesuré : 10px d'air de chaque
       côté). Comme box-sizing:border-box fait entrer le padding dans min-height,
       un simple padding-top > 56px ÉCRASE le centrage : le logo/nom d'agent se
       collait à la bordure basse, tout l'air partait au-dessus. Ici :
       min-height (wsafe + 56) − padding-top (wsafe) = 56px de zone de contenu
       → align-items:center re-centre, identique au web, décalé sous l'île. */
    padding-top: var(--wsafe-top, env(safe-area-inset-top));
    min-height: calc(var(--wsafe-top, env(safe-area-inset-top)) + 56px);
}

body.woopets-shell .demo-sidebar {
    padding-top: var(--wsafe-top, env(safe-area-inset-top));
}

/* --- Bannière hors-ligne (shell mobile uniquement) -------------------------
   #wooOfflineBanner et la classe body.woopets-offline ne sont POSÉS QUE par le
   bridge natif (demo-native.js, initNetwork) → totalement inertes sur le web.
   Pinne en haut sous l'encoche, au-dessus de l'UI (sous le kill-switch 99999).
   Évite l'écran d'erreur navigateur que la review Apple 4.2 sanctionne. */
.woopets-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9500;
    padding: calc(var(--wsafe-top, env(safe-area-inset-top)) + 6px) 12px 8px;
    background: var(--c-text);
    color: var(--c-text-inverse);
    font-size: 0.82rem;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

/* Envoi désactivé hors-ligne (classe posée uniquement par le bridge). */
body.woopets-offline .send-btn {
    opacity: 0.45;
    pointer-events: none;
}

/* --- Perf shell : latence de tap -------------------------------------------
   Le viewport du shell est zoomable (pas de maximum-scale, accessibilité) →
   WKWebView retient chaque tap ~350 ms pour discriminer un double-tap zoom.
   touch-action:manipulation supprime CE délai sur les éléments interactifs
   sans désactiver ni le scroll ni le pinch-zoom. Inerte sur le web. */
body.woopets-shell button,
body.woopets-shell a,
body.woopets-shell input,
body.woopets-shell textarea,
body.woopets-shell select,
body.woopets-shell label,
body.woopets-shell [role="button"] {
    touch-action: manipulation;
}

/* --- Perf shell : compositing GPU (lag du premier tap sur le menu) ---------
   Le backdrop-filter force WebKit à créer une « backdrop root » au premier
   composite (re-rasterisation plein écran) : sur GPU iPhone, la PREMIÈRE
   ouverture du menu payait ce coût en plein boot déjà saturé. Le voile rgba
   sombre suffit visuellement dans l'app. Le blur de la topbar (permanent →
   re-blur à chaque frame de scroll) est remplacé par un fond opaque de la
   même teinte. Inerte sur le web (classe jamais posée). */
body.woopets-shell .sidebar-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    /* Pré-rendu : display:block permanent (invisible via opacity:0), seule
       l'opacité anime → le premier tap sur le menu ne paie plus le
       style+layout+paint d'un fixed plein écran créé à la volée.
       pointer-events:none le rend inerte tant qu'il est invisible.
       Bonus : le fade-out joue aussi à la fermeture. */
    display: block;
    pointer-events: none;
}

body.woopets-shell .sidebar-overlay.active {
    pointer-events: auto;
}

body.woopets-shell .demo-topbar {
    /* rgba(240,249,249,.92) aplati : sans blur, un fond translucide laisserait
       transparaître le contenu scrollé sous la topbar. */
    background: #f0f9f9;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

@media (max-width: 767px) {
    /* Sidebar off-canvas : layer GPU pré-promue → le premier open du menu n'a
       pas à rasteriser 260px × hauteur d'écran au moment du tap. */
    body.woopets-shell .demo-sidebar {
        will-change: transform;
    }
}

/* --- Safe-area shell : écrans plein écran et bords d'écran -----------------
   La WebView est bord-à-bord (ios.contentInset 'never') : tout conteneur
   fullscreen ou ancré à un bord DOIT dégager la Dynamic Island (haut, ~59px)
   et le home indicator (bas, ~34px). Pattern : var(--wsafe-*) natif en
   priorité, env() en fallback. Inerte sur le web (classe jamais posée). */

@media (max-width: 767px) {
    /* Famille .auth-modal — fullscreen mobile (login, register, forgot
       password, account, limit/quota) : padding statique 24px → contenu et
       croix sous l'île. La croix (position:absolute top:16px) a besoin de son
       propre offset : le padding du conteneur ne la déplace pas. */
    body.woopets-shell .auth-modal {
        padding-top: calc(var(--wsafe-top, env(safe-area-inset-top)) + 24px);
        padding-bottom: calc(var(--wsafe-bottom, env(safe-area-inset-bottom)) + 24px);
    }

    body.woopets-shell .auth-modal-close {
        top: calc(var(--wsafe-top, env(safe-area-inset-top)) + 16px);
    }
}

/* Bas d'écran : zone input (toujours visible) + footer compte de la sidebar. */
body.woopets-shell .demo-input-area {
    padding-bottom: max(0.85rem, var(--wsafe-bottom, env(safe-area-inset-bottom)));
}

body.woopets-shell .sidebar-bottom {
    padding-bottom: calc(var(--wsafe-bottom, env(safe-area-inset-bottom)) + 0.5rem);
}

/* Défensifs : overlays centrés qui peuvent atteindre les bords si le contenu
   grossit (rating 90vh) ou si le fallback web s'active (scanner html5-qrcode). */
body.woopets-shell .training-rating-overlay {
    padding: calc(var(--wsafe-top, env(safe-area-inset-top)) + 20px) 20px
             calc(var(--wsafe-bottom, env(safe-area-inset-bottom)) + 20px);
}

body.woopets-shell .scanner-header {
    padding-top: max(16px, var(--wsafe-top, env(safe-area-inset-top)));
}

body.woopets-shell .scanner-subtitle {
    padding-bottom: max(16px, var(--wsafe-bottom, env(safe-area-inset-bottom)));
}

/* ============================================================
   Confirmation brandée (W.confirmDialog) — remplace window.confirm().
   Dans demo-core.css (non lazy) car utilisée par sidebar/chat/pets/health/photos.
   z-index 9700 : au-dessus de la lightbox photos (3000), sous les toasts (9999).
   ============================================================ */
.confirm-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9700;
    align-items: center;
    justify-content: center;
    padding: 20px;
    -webkit-backdrop-filter: blur(2px); /* WKWebView / Safari < 18 */
    backdrop-filter: blur(2px);
}

.confirm-modal-overlay.active { display: flex; }

.confirm-modal {
    background: var(--c-bg-card);
    border-radius: 16px;
    padding: 22px 22px 18px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
    animation: confirmModalIn 220ms var(--ease-spring);
}

@keyframes confirmModalIn {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .confirm-modal { animation: none; }
}

.confirm-modal-msg {
    font-size: 0.92rem;
    color: var(--c-text);
    line-height: 1.5;
    margin: 0 0 16px;
    overflow-wrap: break-word;
}

.confirm-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.confirm-modal-actions button {
    padding: 9px 16px;
    min-height: 40px;
    border-radius: var(--r-sm);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}

.confirm-modal-cancel {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-text-secondary);
}

.confirm-modal-cancel:hover {
    background: var(--c-bg-warm);
    color: var(--c-text);
}

.confirm-modal-ok {
    background: var(--c-primary);
    border: 1px solid var(--c-primary);
    color: var(--c-text-inverse);
}

.confirm-modal-ok:hover {
    background: var(--c-primary-hover);
    border-color: var(--c-primary-hover);
}

.confirm-modal-ok.danger {
    background: var(--c-danger);
    border-color: var(--c-danger);
}

.confirm-modal-ok.danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}
