/**
 * Compagnon de motivation — Styles + animations de l'avatar
 *
 * États (classes .coworker-mood-{mood} sur #luafi-coworker-avatar) :
 *  - idle       : respiration lente, yeux qui clignent
 *  - focus      : yeux légèrement plissés, antenne qui vibre
 *  - encourage  : petites oscillations, bouche plus souriante
 *  - celebrate  : bras levés, sautillements, confettis via celebration.js
 *  - sleeping   : yeux fermés (lignes), ronflement subtil
 */

/* ============================================================
 * 1. AVATAR — Position fixed bottom-right, draggable-friendly
 * ============================================================ */

#luafi-coworker-avatar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 110px;
    height: 130px;
    z-index: 9999;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    filter: drop-shadow(0 6px 12px rgba(99, 102, 241, 0.25));
}

#luafi-coworker-avatar[hidden] {
    display: none;
}

#luafi-coworker-avatar:hover {
    transform: translateY(-4px) scale(1.03);
    filter: drop-shadow(0 10px 18px rgba(99, 102, 241, 0.35));
}

#luafi-coworker-avatar:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 4px;
    border-radius: 18px;
}

#luafi-coworker-avatar svg {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ============================================================
 * 2. MOODS — Animations
 * ============================================================ */

/* --- IDLE : respiration lente + clignement ---
   La tête fait un "breathe" toutes les 4s, les yeux clignent toutes les 5s */
.coworker-mood-idle .coworker-head {
    transform-origin: 60px 60px;
    animation: coworker-breathe 4s ease-in-out infinite;
}

.coworker-mood-idle .coworker-eye-left,
.coworker-mood-idle .coworker-eye-right {
    transform-origin: center;
    animation: coworker-blink 5s ease-in-out infinite;
}

.coworker-mood-idle .coworker-antenna circle {
    transform-origin: 60px 16px;
    animation: coworker-pulse 2s ease-in-out infinite;
}

@keyframes coworker-breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.03); }
}

@keyframes coworker-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    95%, 97%      { transform: scaleY(0.1); }
}

@keyframes coworker-pulse {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50%      { opacity: 1; transform: scale(1.2); }
}

/* --- FOCUS : yeux plissés (rétrécis), antenne vibrante, légère tension --- */
.coworker-mood-focus .coworker-head {
    transform-origin: 60px 60px;
    animation: coworker-focus-tension 2s ease-in-out infinite;
}

.coworker-mood-focus .coworker-eye-left,
.coworker-mood-focus .coworker-eye-right {
    transform: scaleY(0.7);
    transform-origin: center;
}

.coworker-mood-focus .coworker-pupil-left,
.coworker-mood-focus .coworker-pupil-right {
    animation: coworker-pupil-look 3s steps(2, end) infinite;
}

.coworker-mood-focus .coworker-antenna circle {
    animation: coworker-focus-glow 1.5s ease-in-out infinite;
}

.coworker-mood-focus .coworker-mouth {
    d: path("M52 73 L68 73");
}

@keyframes coworker-focus-tension {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-1px); }
}

@keyframes coworker-pupil-look {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(2px, 0); }
}

@keyframes coworker-focus-glow {
    0%, 100% { opacity: 0.7; transform: scale(1); fill: #fbbf24; }
    50%      { opacity: 1; transform: scale(1.3); fill: #f59e0b; }
}

/* --- ENCOURAGE : oscillations douces, bouche plus souriante --- */
.coworker-mood-encourage {
    animation: coworker-wiggle 0.8s ease-in-out infinite;
}

.coworker-mood-encourage .coworker-mouth {
    d: path("M48 70 Q60 82 72 70");
}

.coworker-mood-encourage .coworker-antenna circle {
    animation: coworker-pulse 1s ease-in-out infinite;
}

@keyframes coworker-wiggle {
    0%, 100% { transform: rotate(-2deg); }
    50%      { transform: rotate(2deg); }
}

/* --- CELEBRATE : sautillements + bras levés --- */
.coworker-mood-celebrate {
    animation: coworker-hop 0.6s ease-in-out infinite;
}

.coworker-mood-celebrate .coworker-arm-left {
    transform: rotate(-30deg);
    transform-origin: 21px 100px;
    animation: coworker-arm-wave-left 0.4s ease-in-out infinite alternate;
}

.coworker-mood-celebrate .coworker-arm-right {
    transform: rotate(30deg);
    transform-origin: 99px 100px;
    animation: coworker-arm-wave-right 0.4s ease-in-out infinite alternate;
}

.coworker-mood-celebrate .coworker-mouth {
    d: path("M48 68 Q60 84 72 68");
}

.coworker-mood-celebrate .coworker-antenna circle {
    animation: coworker-focus-glow 0.6s ease-in-out infinite;
}

@keyframes coworker-hop {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-12px); }
}

@keyframes coworker-arm-wave-left {
    0%   { transform: rotate(-30deg); }
    100% { transform: rotate(-50deg); }
}

@keyframes coworker-arm-wave-right {
    0%   { transform: rotate(30deg); }
    100% { transform: rotate(50deg); }
}

/* --- SLEEPING : yeux fermés (lignes), petite oscillation --- */
.coworker-mood-sleeping .coworker-eye-left,
.coworker-mood-sleeping .coworker-eye-right {
    opacity: 0;
}

.coworker-mood-sleeping .coworker-pupil-left,
.coworker-mood-sleeping .coworker-pupil-right {
    opacity: 0;
}

.coworker-mood-sleeping .coworker-mouth {
    d: path("M54 73 Q60 70 66 73");
}

.coworker-mood-sleeping .coworker-antenna circle {
    opacity: 0.4;
    animation: coworker-snore 3s ease-in-out infinite;
}

.coworker-mood-sleeping .coworker-head {
    transform-origin: 60px 60px;
    animation: coworker-snore-tilt 3s ease-in-out infinite;
}

@keyframes coworker-snore {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 0.6; }
}

@keyframes coworker-snore-tilt {
    0%, 100% { transform: rotate(-3deg); }
    50%      { transform: rotate(3deg); }
}

/* ============================================================
 * 3. SPEECH BUBBLE
 * ============================================================ */

.coworker-bubble {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    max-width: 260px;
    min-width: 120px;
    padding: 10px 14px;
    background: #ffffff;
    color: #1f2937;
    border-radius: 14px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
    font-weight: 500;
    text-align: left;
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 10000;
}

.coworker-bubble[hidden] {
    display: none !important;
}

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

.coworker-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-right: 1px solid rgba(99, 102, 241, 0.2);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    transform: rotate(45deg);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .coworker-bubble {
        background: #1f2937;
        color: #f3f4f6;
        border-color: rgba(129, 140, 248, 0.3);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    .coworker-bubble::after {
        background: #1f2937;
        border-color: rgba(129, 140, 248, 0.3);
    }
}

body.dark-mode .coworker-bubble {
    background: #1f2937;
    color: #f3f4f6;
    border-color: rgba(129, 140, 248, 0.3);
}

body.dark-mode .coworker-bubble::after {
    background: #1f2937;
    border-color: rgba(129, 140, 248, 0.3);
}

/* ============================================================
 * 4. CONTROL PANEL
 * ============================================================ */

.coworker-panel {
    position: fixed;
    bottom: 170px;
    right: 20px;
    width: 280px;
    background: #ffffff;
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: #1f2937;
    z-index: 10001;
    overflow: hidden;
    animation: coworker-panel-appear 0.2s ease-out;
}

@keyframes coworker-panel-appear {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.coworker-panel[hidden] {
    display: none;
}

.coworker-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    color: #ffffff;
}

.coworker-panel-header strong {
    font-size: 0.95rem;
    font-weight: 700;
}

.coworker-panel-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: grid;
    place-items: center;
    transition: background 0.15s;
}

.coworker-panel-close:hover {
    background: rgba(255, 255, 255, 0.35);
}

.coworker-panel-body {
    padding: 12px 16px;
}

.coworker-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.coworker-row:last-child {
    border-bottom: none;
}

.coworker-row > label {
    font-weight: 600;
    color: #4b5563;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.coworker-row > span {
    font-weight: 600;
    color: #4b5563;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.coworker-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-transform: none !important;
    letter-spacing: normal !important;
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: #1f2937 !important;
}

.coworker-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #6366f1;
    cursor: pointer;
}

.coworker-row select,
.coworker-row input[type="range"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #ffffff;
    color: #1f2937;
    cursor: pointer;
}

.coworker-row select:focus,
.coworker-row input[type="range"]:focus {
    outline: 2px solid #6366f1;
    outline-offset: 1px;
}

.coworker-dnd-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.coworker-dnd-buttons button {
    flex: 1;
    min-width: 56px;
    padding: 6px 8px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s;
}

.coworker-dnd-buttons button:hover {
    background: #6366f1;
    color: #ffffff;
    border-color: #6366f1;
}

.coworker-dnd-buttons .coworker-dnd-off {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}

.coworker-dnd-buttons .coworker-dnd-off:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
}

.coworker-test-row {
    padding-top: 12px;
}

.coworker-test-btn {
    width: 100%;
    padding: 8px 12px;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.coworker-test-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Dark mode pour le panel */
@media (prefers-color-scheme: dark) {
    .coworker-panel {
        background: #1f2937;
        color: #f3f4f6;
        border-color: rgba(129, 140, 248, 0.3);
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    }
    .coworker-row {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }
    .coworker-row > label,
    .coworker-row > span {
        color: #9ca3af;
    }
    .coworker-toggle {
        color: #f3f4f6 !important;
    }
    .coworker-row select {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    .coworker-dnd-buttons button {
        background: #374151;
        color: #d1d5db;
        border-color: #4b5563;
    }
    .coworker-dnd-buttons button:hover {
        background: #6366f1;
        color: #ffffff;
    }
    .coworker-dnd-buttons .coworker-dnd-off {
        background: #7f1d1d;
        color: #fecaca;
        border-color: #991b1b;
    }
}

body.dark-mode .coworker-panel {
    background: #1f2937;
    color: #f3f4f6;
    border-color: rgba(129, 140, 248, 0.3);
}

body.dark-mode .coworker-row {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .coworker-row > label,
body.dark-mode .coworker-row > span {
    color: #9ca3af;
}

body.dark-mode .coworker-toggle {
    color: #f3f4f6 !important;
}

body.dark-mode .coworker-row select {
    background: #374151;
    color: #f3f4f6;
    border-color: #4b5563;
}

body.dark-mode .coworker-dnd-buttons button {
    background: #374151;
    color: #d1d5db;
    border-color: #4b5563;
}

/* ============================================================
 * 5. RESPONSIVE
 * ============================================================ */

@media (max-width: 640px) {
    #luafi-coworker-avatar {
        width: 80px;
        height: 95px;
        bottom: 12px;
        right: 12px;
    }

    .coworker-bubble {
        max-width: 200px;
        font-size: 0.78rem;
        right: -40px;
    }

    .coworker-panel {
        width: calc(100vw - 24px);
        right: 12px;
        bottom: 130px;
    }
}

/* ============================================================
 * 6. ACCESSIBILITÉ — prefers-reduced-motion
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
    #luafi-coworker-avatar,
    .coworker-mood-idle .coworker-head,
    .coworker-mood-idle .coworker-eye-left,
    .coworker-mood-idle .coworker-eye-right,
    .coworker-mood-idle .coworker-antenna circle,
    .coworker-mood-focus .coworker-head,
    .coworker-mood-focus .coworker-pupil-left,
    .coworker-mood-focus .coworker-pupil-right,
    .coworker-mood-focus .coworker-antenna circle,
    .coworker-mood-encourage,
    .coworker-mood-encourage .coworker-antenna circle,
    .coworker-mood-celebrate,
    .coworker-mood-celebrate .coworker-arm-left,
    .coworker-mood-celebrate .coworker-arm-right,
    .coworker-mood-celebrate .coworker-antenna circle,
    .coworker-mood-sleeping .coworker-head,
    .coworker-mood-sleeping .coworker-antenna circle {
        animation: none !important;
    }
}
