/* Watson — assistant du site (FAB corbeau + panneau de chat).
   Porté du widget CaseOne (apps/caseone/src/styles/Watson.css), theme-aware --of-*. */

.watson-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

/* --- Bouton flottant (FAB) --- */
.watson-fab {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    background: var(--of-accent);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.watson-fab:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.42), 0 4px 10px rgba(0, 0, 0, 0.22);
}

.watson-fab:focus-visible {
    outline: 3px solid var(--of-accent);
    outline-offset: 2px;
}

/* Le corbeau déborde du cercle par le haut */
.watson-fab-img {
    width: 96px;
    height: 106px;
    object-fit: contain;
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    filter: drop-shadow(0 5px 14px rgba(0, 0, 0, 0.52));
    animation: watson-idle-float 3s ease-in-out infinite;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.watson-fab-open { transform: scale(0.92); }

.watson-img-fading {
    opacity: 0 !important;
    animation: none !important;
}

@keyframes watson-idle-float {
    0%, 100% { transform: translateX(-50%) translateY(0px); }
    50%      { transform: translateX(-50%) translateY(-4px); }
}

@keyframes watson-bounce-kf {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    28%      { transform: translateX(-50%) translateY(-18px); }
    52%      { transform: translateX(-50%) translateY(-9px); }
    72%      { transform: translateX(-50%) translateY(-15px); }
}

@keyframes watson-tilt-kf {
    0%, 100% { transform: translateX(-50%) rotate(0deg); }
    20%      { transform: translateX(-50%) rotate(-14deg); }
    55%      { transform: translateX(-50%) rotate(14deg); }
    80%      { transform: translateX(-50%) rotate(-5deg); }
}

/* Promenade — seul l'oiseau sort du cercle vers la gauche puis revient */
@keyframes watson-walk-full-kf {
    0%   { transform: translateX(-50%)               scaleX(1)  translateY(0); }
    7%   { transform: translateX(calc(-50% - 20px))  scaleX(-1) translateY(-4px); }
    22%  { transform: translateX(calc(-50% - 75px))  scaleX(-1) translateY(0); }
    37%  { transform: translateX(calc(-50% - 160px)) scaleX(-1) translateY(0); }
    50%  { transform: translateX(calc(-50% - 160px)) scaleX(-1) translateY(0); }
    51%  { transform: translateX(calc(-50% - 160px)) scaleX(1)  translateY(0); }
    65%  { transform: translateX(calc(-50% - 80px))  scaleX(1)  translateY(-4px); }
    83%  { transform: translateX(calc(-50% - 20px))  scaleX(1)  translateY(-4px); }
    93%  { transform: translateX(calc(-50% - 4px))   scaleX(1)  translateY(-1px); }
    100% { transform: translateX(-50%)               scaleX(1)  translateY(0); }
}

.watson-fab-img.watson-anim-bounce { animation: watson-bounce-kf 0.72s ease-in-out; }
.watson-fab-img.watson-anim-tilt { animation: watson-tilt-kf 0.88s ease-in-out; }
.watson-fab-img.watson-anim-walk-full { animation: watson-walk-full-kf 3.9s ease-in-out; }

@keyframes watson-approach-img-kf {
    0%   { transform: translateX(-50%) scale(1); }
    22%  { transform: translateX(-50%) scale(2.5); }
    76%  { transform: translateX(-50%) scale(2.5); }
    100% { transform: translateX(-50%) scale(1); }
}

.watson-fab-img.watson-anim-approach {
    animation: watson-approach-img-kf 5s ease-in-out;
    transform-origin: 100% 100%;
}

/* --- Bulle de message --- */
.watson-bubble {
    position: absolute;
    bottom: 96px;
    right: 0;
    width: 250px;
    background: var(--of-card-bg);
    color: var(--of-text);
    border: 1px solid var(--of-border);
    font-size: 0.875rem;
    line-height: 1.5;
    padding: 10px 14px;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: scale(0.82) translateY(8px);
    transform-origin: bottom right;
    transition: opacity 0.28s ease, transform 0.28s ease;
    pointer-events: none;
    word-break: break-word;
}

.watson-bubble.watson-bubble-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.watson-bubble.watson-bubble-approach {
    bottom: 300px;
    right: -10px;
}

/* --- Panneau de conversation --- */
.watson-panel[hidden] { display: none; }

.watson-panel {
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--of-card-bg);
    border: 1px solid var(--of-border);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.watson-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--of-bg-alt);
    border-bottom: 1px solid var(--of-border);
}

.watson-panel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    object-position: top;
    background: var(--of-accent);
}

.watson-panel-title {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--of-text);
}

.watson-panel-title small {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--of-text-muted);
}

.watson-panel-close {
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--of-text-secondary);
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
}

.watson-panel-close:hover { background: var(--of-border-subtle); color: var(--of-text); }

.watson-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.watson-msg {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.watson-msg-user {
    align-self: flex-end;
    background: var(--of-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Accent doré → texte sombre requis pour le contraste (WCAG AA).
   Surface CaseOne : l'accent est toujours l'or signature, quel que soit data-theme. */
[data-theme="sombre"] .watson-msg-user,
[data-theme="sombre"] .watson-send-btn,
body[data-surface="caseone"] .watson-msg-user,
body[data-surface="caseone"] .watson-send-btn {
    color: #1A1A2E;
}

.watson-msg-assistant {
    align-self: flex-start;
    background: var(--of-bg-alt);
    color: var(--of-text);
    border: 1px solid var(--of-border);
    border-bottom-left-radius: 4px;
}

.watson-msg-typing {
    align-self: flex-start;
    color: var(--of-text-muted);
    font-size: 0.85rem;
    padding: 4px 2px;
}

/* Bouton « Prendre RDV » : n'apparaît que si le serveur l'a signalé */
.watson-rdv-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--of-gold);
    color: #1A1A2E;
    border: none;
    border-radius: var(--of-radius-pill, 9999px);
    padding: 10px 18px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
}

.watson-rdv-btn:hover { filter: brightness(1.06); }

.watson-panel-inputbar {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--of-border);
    background: var(--of-bg-alt);
}

.watson-panel-inputbar textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--of-border);
    border-radius: 10px;
    background: var(--of-card-bg);
    color: var(--of-text);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    padding: 9px 12px;
    height: 42px;
    max-height: 96px;
}

.watson-panel-inputbar textarea:focus {
    outline: 2px solid var(--of-accent);
    outline-offset: -1px;
}

.watson-send-btn {
    border: none;
    border-radius: 10px;
    width: 42px;
    height: 42px;
    background: var(--of-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.watson-send-btn:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 640px) {
    .watson-widget { right: 14px; bottom: 14px; }
    .watson-panel { height: 480px; }
}

@media (prefers-reduced-motion: reduce) {
    .watson-fab-img { animation: none; }
}
