/* Widget flottant de l'assistant IA — moteur générique (voir public/js/agentcore-widget.js).
   Branché par rôle via data-attributes sur #agentcore-widget (public/js lit ces valeurs) :
   aucune donnée LuveLink en dur ici ni dans le JS, pour rester réutilisable tel quel sur un
   futur site (demande explicite : "comme un plugin que on branche sur le site"). Couleurs
   pilotées par variables CSS (--aw-*), déjà alignées sur le design system LuveLink
   (docs/REGLES_CODE.md §4) mais redéfinissables par qui réutilise ce module ailleurs. */
:root {
    --aw-primary: #D61F5B;
    --aw-primary-2: #B5164B;
    --aw-ink: #241A2E;
    --aw-muted: #5B5266;
    --aw-line: #EAE6EE;
    --aw-canvas: #FFF4F7;
    --aw-surface: #ffffff;
    color-scheme: light;
}

#agentcore-widget, #agentcore-widget * { box-sizing: border-box; min-width: 0; }
#agentcore-widget { font-family: 'Nunito', system-ui, sans-serif; }
#agentcore-widget button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* Ce widget est copié tel quel sur des pages qui ne chargent jamais Tailwind (panels Filament,
   pages staff) : `.sr-only` n'existe nulle part là où ce fichier est le seul CSS chargé — le
   label caché du champ de saisie s'affichait donc en clair, dupliquant le placeholder juste à
   côté (capture d'écran d'Eliot, 2026-11-11). Toujours définir ses propres classes ici, jamais
   compter sur une classe utilitaire externe. */
#agentcore-widget .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Mobile-first : la bulle et le panneau sont pensés pour un petit écran par défaut (feuille
   bas-d'écran bornée), puis adaptés en panneau flottant à partir de 640px — plus de règles
   `max-width` qui se chevauchent avec la base (source du débordement/incohérence vus sur
   capture d'écran le 2026-11-09, corrigé par une réécriture complète de cette section). */
.aw-toggle {
    position: fixed; z-index: 900;
    right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
    display: grid; place-items: center; width: 56px; height: 56px; padding: 0;
    border: 0; border-radius: 50%; cursor: pointer;
    background: var(--aw-primary);
    box-shadow: 0 14px 34px rgba(184, 47, 97, .32);
    transition: transform .18s ease, box-shadow .18s ease;
}
.aw-toggle:hover { transform: translateY(-2px); box-shadow: 0 18px 42px rgba(184, 47, 97, .4); }
.aw-toggle:active { transform: translateY(0) scale(.96); }
.aw-toggle img { width: 34px; height: 34px; display: block; object-fit: contain; }
.aw-toggle .aw-icon-close { display: none; color: #fff; }
.aw-toggle.is-open .aw-icon-img { display: none; }
.aw-toggle.is-open .aw-icon-close { display: block; }
.aw-toggle:focus-visible { outline: 3px solid rgba(184, 47, 97, .35); outline-offset: 3px; }
/* Un seul bouton de fermeture visible à la fois sur mobile : la bulle se cache derrière la
   feuille ouverte (sinon elle perce au-dessus du panneau). */
.aw-toggle.is-open { display: none; }

.aw-panel {
    position: fixed; z-index: 899; inset: auto 0 0 0;
    width: 100%; max-width: 100%; height: min(78dvh, 620px); max-height: 100dvh;
    display: none; grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--aw-canvas); border-radius: 20px 20px 0 0; overflow: hidden;
    box-shadow: 0 30px 80px rgba(28, 20, 40, .22), 0 8px 22px rgba(28, 20, 40, .08);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
.aw-panel.open { display: grid; animation: awIn .2s ease-out; }
@keyframes awIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* Desktop/tablette (pointeur fin, place disponible) : panneau flottant au-dessus de la bulle,
   jamais une feuille plein-largeur. */
@media (min-width: 640px) {
    .aw-toggle { right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); width: 58px; height: 58px; }
    .aw-toggle img { width: 36px; height: 36px; }
    .aw-toggle.is-open { display: grid; }
    .aw-panel {
        inset: auto max(20px, env(safe-area-inset-right)) max(90px, calc(78px + env(safe-area-inset-bottom))) auto;
        width: 400px; max-width: calc(100vw - 24px); height: min(640px, calc(100dvh - 120px));
        border-radius: 20px;
        padding: 0;
    }
    .aw-hint { display: inline; }
}

.aw-head {
    display: flex; align-items: center; gap: 12px; padding: 16px 14px 14px 16px;
    background: var(--aw-primary); color: #fff;
}
.aw-head-mark { flex: 0 0 38px; width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,.2); display: grid; place-items: center; overflow: hidden; }
.aw-head-mark img { width: 30px; height: 30px; object-fit: contain; }
.aw-head-copy { min-width: 0; flex: 1; }
.aw-head-copy strong { display: block; font-family: 'Nunito', 'Arial Rounded MT Bold', Arial, sans-serif; font-size: 15px; font-weight: 700; letter-spacing: -.1px; }
.aw-head-copy span { display: block; margin-top: 2px; font-size: 11.5px; line-height: 1.35; color: rgba(255,255,255,.88); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aw-head-close { flex: 0 0 44px; width: 44px; height: 44px; border: 0; border-radius: 12px; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; cursor: pointer; }
.aw-head-close:hover { background: rgba(255,255,255,.24); }

/* Barre d'usage optionnelle (crédit IA LuveLink, voir widget.blade.php) — générique côté
   moteur, ne connaît qu'un label + un pourcentage fournis par l'appelant. */
.aw-usage { padding: 8px 16px; background: var(--aw-canvas); border-bottom: 1px solid rgba(0,0,0,.06); }
.aw-usage-label { display: block; font-size: 11px; color: #6b7280; margin-bottom: 4px; }
.aw-usage-bar { height: 4px; border-radius: 999px; background: rgba(0,0,0,.08); overflow: hidden; }
.aw-usage-bar-fill { height: 100%; background: var(--aw-primary); border-radius: inherit; transition: width .2s ease; }

.aw-messages { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--aw-canvas); scrollbar-gutter: stable; }

/* Lien d'ouverture de page proposé par l'assistant — jamais une redirection automatique
   (voir sendMessage() dans agentcore-widget.js), le visiteur tape dessus quand il veut. */
.aw-nav-link {
    align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
    min-height: 44px; padding: 10px 16px; border-radius: 999px;
    background: var(--aw-primary); color: #fff; text-decoration: none;
    font-family: 'Nunito', 'Arial Rounded MT Bold', Arial, sans-serif; font-weight: 700; font-size: 13px;
}
.aw-nav-link:hover { background: var(--aw-primary-2); }

.aw-empty { margin: auto; max-width: 270px; text-align: center; color: var(--aw-muted); }
.aw-empty svg { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--aw-primary); }
.aw-empty strong { display: block; color: var(--aw-ink); font-family: 'Nunito', 'Arial Rounded MT Bold', Arial, sans-serif; font-size: 15px; }
.aw-empty p { margin: 6px 0 0; font-size: 12.5px; line-height: 1.5; }
.aw-starters { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.aw-starter {
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
    min-height: 68px; padding: 10px; border: 1px solid var(--aw-line); border-radius: 14px;
    background: var(--aw-surface); color: var(--aw-ink); font: inherit; font-size: 12.5px; font-weight: 700;
    cursor: pointer; transition: border-color .15s ease, transform .15s ease;
}
.aw-starter:hover { border-color: var(--aw-primary); transform: translateY(-1px); }
.aw-starter svg { width: 18px; height: 18px; color: var(--aw-primary); }

.aw-msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.aw-msg.user { align-self: flex-end; background: var(--aw-primary); color: #fff; border-bottom-right-radius: 5px; }
.aw-msg.assistant { align-self: flex-start; background: var(--aw-surface); color: var(--aw-ink); border: 1px solid var(--aw-line); border-bottom-left-radius: 5px; }
.aw-msg.error { align-self: flex-start; background: #fde8e8; color: #9b1c1c; border: 1px solid #f5c2c2; }
.aw-msg.pending { display: flex; align-items: center; gap: 4px; min-width: 46px; min-height: 36px; }
.aw-msg.pending span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .3; animation: awDot 1s ease-in-out infinite; }
.aw-msg.pending span:nth-child(2) { animation-delay: .14s; }
.aw-msg.pending span:nth-child(3) { animation-delay: .28s; }
@keyframes awDot { 0%, 60%, 100% { opacity: .28; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* Carte de confirmation éditable — chaque champ proposé par l'IA reste modifiable avant
   validation (demande explicite : "la possibilité de remplir différents champs"), jamais du
   texte brut non éditable. Toute action qui en passe par là est "sensible" côté backend (voir
   AgentToolExecutor::execute($confirmed: true)) — jamais exécutée sans ce passage. */
.aw-form-card { align-self: stretch; border: 1px solid var(--aw-line); border-radius: 14px; background: var(--aw-surface); padding: 12px; }
.aw-form-card .aw-form-title { display: flex; align-items: center; gap: 6px; font-family: 'Nunito', 'Arial Rounded MT Bold', Arial, sans-serif; font-weight: 600; font-size: 13px; color: var(--aw-ink); margin-bottom: 8px; }
.aw-form-card .aw-form-title svg { width: 15px; height: 15px; color: var(--aw-primary); flex: none; }
.aw-form-field { margin-bottom: 8px; }
.aw-form-field label { display: block; font-size: 11px; font-weight: 700; color: var(--aw-muted); margin-bottom: 3px; }
.aw-form-field label em { color: var(--aw-primary); font-style: normal; margin-left: 2px; }
.aw-form-field input, .aw-form-field textarea {
    width: 100%; min-height: 44px; padding: 7px 10px; border: 1px solid var(--aw-line); border-radius: 9px;
    font: inherit; font-size: 16px; background: var(--aw-canvas); color: var(--aw-ink);
}
.aw-form-field input:focus, .aw-form-field textarea:focus { outline: 2px solid var(--aw-primary); outline-offset: 1px; }
.aw-form-field.invalid input { border-color: #dc2626; }
.aw-form-field .aw-form-err { display: none; font-size: 10.5px; color: #dc2626; margin-top: 3px; }
.aw-form-field.invalid .aw-form-err { display: block; }
.aw-form-footer { display: flex; gap: 8px; margin-top: 10px; }
.aw-form-footer button { flex: 1; min-height: 44px; border-radius: 10px; border: 0; font: inherit; font-weight: 700; font-size: 12.5px; cursor: pointer; }
.aw-form-cancel { background: var(--aw-canvas); color: var(--aw-ink); border: 1px solid var(--aw-line) !important; }
.aw-form-cancel:hover { background: var(--aw-line); }
.aw-form-submit { background: var(--aw-primary); color: #fff; display: flex; align-items: center; justify-content: center; gap: 6px; }
.aw-form-submit:hover { background: var(--aw-primary-2); }
.aw-form-submit:disabled { opacity: .6; cursor: default; }
.aw-form-submit.danger { background: #dc2626; }
.aw-form-submit svg { width: 15px; height: 15px; }

.aw-form { padding: 11px 12px 12px; border-top: 1px solid var(--aw-line); background: var(--aw-surface); }
.aw-composer { display: flex; align-items: flex-end; gap: 7px; padding: 5px 5px 5px 12px; border: 1px solid var(--aw-line); border-radius: 14px; background: var(--aw-canvas); }
.aw-composer textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 110px; resize: none; border: 0; background: transparent; padding: 11px 0; font: inherit; font-size: 16px; color: var(--aw-ink); line-height: 1.4; }
.aw-composer textarea:focus { outline: none; }
.aw-composer textarea::placeholder { color: var(--aw-muted); }
.aw-send { flex: 0 0 44px; height: 44px; border: 0; border-radius: 11px; background: var(--aw-primary); color: #fff; display: grid; place-items: center; cursor: pointer; }
.aw-send:hover { background: var(--aw-primary-2); }
.aw-send:disabled { opacity: .5; cursor: default; }
.aw-send svg { width: 17px; height: 17px; }
.aw-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.aw-action-link { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; padding: 10px 2px; margin: -10px -2px; color: var(--aw-muted); font: inherit; font-size: 10.5px; font-weight: 700; cursor: pointer; min-height: 44px; }
.aw-action-link:hover { color: var(--aw-ink); }
.aw-action-link svg { width: 13px; height: 13px; }
/* Astuce clavier masquée par défaut (mobile, pas de clavier physique) — réapparaît en
   desktop/tablette ci-dessus (min-width: 640px). */
.aw-hint { display: none; margin-left: auto; color: var(--aw-muted); font-size: 9.5px; }

@media (prefers-reduced-motion: reduce) {
    .aw-panel.open, .aw-msg.pending span, .aw-toggle { animation: none !important; transition: none !important; }
}

/* Très petit écran (ex. iPhone SE) : une seule colonne pour les suggestions, plus lisible
   qu'une grille 2 colonnes compressée. */
@media (max-width: 360px) {
    .aw-starters { grid-template-columns: 1fr; }
}
