/**
 * WelcomeAds Chat Widget — Stylowanie
 *
 * Design system zgodny z brand identity WelcomeAds:
 *  - Background:   #0F0F1A (najciemniejszy granat)
 *  - Card surface: #1A1A2E (chat window bg)
 *  - Gradient:     #FF4060 → #E02090 → #B000C0 (FAB, send, user bubble)
 *  - Typography:   Plus Jakarta Sans (headings) + DM Sans (body)
 *
 * Prefix `wa-` (WelcomeAds) zapobiega kolizji z CSS strony hostującej.
 *
 * @version 1.0.0
 */

/* ════════════════════════════════════════════════════════════════
   ROOT — zmienne lokalne (nie wycieka poza widget)
   ════════════════════════════════════════════════════════════════ */

.wa-chat {
    /* Kolory */
    --wa-bg-darkest: #0F0F1A;
    --wa-bg-card: #1A1A2E;
    --wa-bg-surface: #232340;
    --wa-bg-elevated: #2A2A48;

    --wa-text-primary: #FFFFFF;
    --wa-text-secondary: rgba(255, 255, 255, 0.72);
    --wa-text-muted: rgba(255, 255, 255, 0.48);

    --wa-border: rgba(255, 255, 255, 0.08);
    --wa-border-strong: rgba(255, 255, 255, 0.16);

    --wa-grad: linear-gradient(135deg, #FF4060 0%, #E02090 55%, #B000C0 100%);
    --wa-grad-soft: linear-gradient(135deg, rgba(255, 64, 96, 0.15) 0%, rgba(176, 0, 192, 0.15) 100%);
    --wa-glow: 0 8px 32px rgba(224, 32, 144, 0.4);
    --wa-shadow-card: 0 24px 64px rgba(0, 0, 0, 0.4);

    --wa-error: #FF5572;
    --wa-online: #22D391;

    /* Typografia */
    --wa-font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --wa-font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    /* Rozmiary */
    --wa-radius-sm: 10px;
    --wa-radius-md: 14px;
    --wa-radius-lg: 20px;
    --wa-radius-xl: 24px;

    /* Pozycja — podniesione, żeby nie kolidować z banerem cookies */
    position: fixed;
    bottom: 96px;
    z-index: 999999;
    font-family: var(--wa-font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--wa-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.wa-chat--right { right: 24px; }
.wa-chat--left { left: 24px; }

.wa-chat *,
.wa-chat *::before,
.wa-chat *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ════════════════════════════════════════════════════════════════
   TEASER (dymek zachęcający nad FAB)
   ════════════════════════════════════════════════════════════════ */

.wa-chat__teaser {
    position: absolute;
    bottom: 76px;            /* nad FAB (60px wysokość + 16px gap) */
    background: var(--wa-bg-card);
    border: 1px solid var(--wa-border-strong);
    border-radius: var(--wa-radius-lg);
    padding: 12px 38px 12px 18px;  /* miejsce na close po prawej */
    box-shadow: var(--wa-shadow-card);
    color: var(--wa-text-primary);
    font-family: var(--wa-font-body);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px) scale(0.94);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    user-select: none;
    /* Subtelny gradient border efekt */
    background-clip: padding-box;
}

.wa-chat--right .wa-chat__teaser { right: 0; }
.wa-chat--left .wa-chat__teaser { left: 0; }

/* Strzałka wskazująca FAB — mały trójkąt na dole dymka */
.wa-chat__teaser::after {
    content: '';
    position: absolute;
    bottom: -6px;
    width: 12px;
    height: 12px;
    background: var(--wa-bg-card);
    border-right: 1px solid var(--wa-border-strong);
    border-bottom: 1px solid var(--wa-border-strong);
    transform: rotate(45deg);
}

.wa-chat--right .wa-chat__teaser::after { right: 24px; }
.wa-chat--left .wa-chat__teaser::after { left: 24px; }

/* Stan widoczny + płynna animacja "floating" */
.wa-chat__teaser--visible {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    pointer-events: auto;
    animation: wa-teaser-float 5s cubic-bezier(0.45, 0.05, 0.55, 0.95) 0.6s infinite;
    will-change: transform;
}

/* Sinusoidalny ruch — większa amplituda i dłuższy cykl = płynniej */
@keyframes wa-teaser-float {
    0%, 100% { transform: translate3d(0, 0, 0); }
    50%      { transform: translate3d(0, -6px, 0); }
}

.wa-chat__teaser:hover {
    border-color: rgba(224, 32, 144, 0.4);
    box-shadow: var(--wa-shadow-card), 0 0 0 1px rgba(224, 32, 144, 0.2);
}

.wa-chat__teaser:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 3px;
}

/* Mały przycisk × po prawej stronie */
.wa-chat__teaser-close {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--wa-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
    padding: 0;
}

.wa-chat__teaser-close:hover {
    background: var(--wa-border);
    color: var(--wa-text-primary);
}

.wa-chat__teaser-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 1px;
}

.wa-chat__teaser-close svg {
    width: 12px;
    height: 12px;
}

/* Mobile — dymek nie może wystawać poza ekran */
@media (max-width: 520px) {
    .wa-chat__teaser {
        max-width: calc(100vw - 48px);
        white-space: normal;
        bottom: 72px;
    }
}

/* ════════════════════════════════════════════════════════════════
   FLOATING ACTION BUTTON (FAB)
   ════════════════════════════════════════════════════════════════ */

.wa-chat__fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wa-grad);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--wa-glow);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    position: relative;
    overflow: hidden;
}

.wa-chat__fab:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(224, 32, 144, 0.55);
}

.wa-chat__fab:active { transform: scale(0.96); }

.wa-chat__fab:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.6);
    outline-offset: 3px;
}

.wa-chat__fab svg {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s ease, transform 0.3s ease;
    position: absolute;
}

.wa-chat__fab-icon-close { opacity: 0; transform: rotate(-90deg); }

.wa-chat--open .wa-chat__fab-icon-open { opacity: 0; transform: rotate(90deg); }
.wa-chat--open .wa-chat__fab-icon-close { opacity: 1; transform: rotate(0deg); }

/* Delikatna pulsacja FAB — ripple efekt po zniknięciu teasera */
.wa-chat__fab--pulsing {
    animation: wa-fab-pulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    will-change: box-shadow;
}

@keyframes wa-fab-pulse {
    0% {
        box-shadow: 0 8px 32px rgba(224, 32, 144, 0.45),
                    0 0 0 0 rgba(224, 32, 144, 0.55);
    }
    70% {
        box-shadow: 0 8px 32px rgba(224, 32, 144, 0.4),
                    0 0 0 18px rgba(224, 32, 144, 0);
    }
    100% {
        box-shadow: 0 8px 32px rgba(224, 32, 144, 0.4),
                    0 0 0 0 rgba(224, 32, 144, 0);
    }
}

/* Hover wstrzymuje pulsację (lepszy feedback) */
.wa-chat__fab--pulsing:hover {
    animation-play-state: paused;
}

/* ════════════════════════════════════════════════════════════════
   CHAT WINDOW
   ════════════════════════════════════════════════════════════════ */

.wa-chat__window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--wa-bg-card);
    border-radius: var(--wa-radius-xl);
    box-shadow: var(--wa-shadow-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    border: 1px solid var(--wa-border);
}

.wa-chat--right .wa-chat__window { right: 0; }
.wa-chat--left .wa-chat__window { left: 0; }

.wa-chat--open .wa-chat__window {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ════════════════════════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════════════════════════ */

.wa-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--wa-bg-card) 0%, var(--wa-bg-surface) 100%);
    border-bottom: 1px solid var(--wa-border);
    position: relative;
}

.wa-chat__header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--wa-grad-soft);
    opacity: 0.4;
    pointer-events: none;
}

.wa-chat__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--wa-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(224, 32, 144, 0.35);
    position: relative;
    z-index: 1;
}

.wa-chat__avatar svg {
    width: 22px;
    height: 22px;
}

.wa-chat__header-text {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.wa-chat__title {
    font-family: var(--wa-font-display);
    font-size: 15px;
    font-weight: 700;
    color: var(--wa-text-primary);
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}

.wa-chat__subtitle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--wa-text-secondary);
}

.wa-chat__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--wa-online);
    box-shadow: 0 0 8px rgba(34, 211, 145, 0.6);
    animation: wa-pulse 2s ease-in-out infinite;
}

@keyframes wa-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.15); }
}

.wa-chat__action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--wa-radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--wa-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.wa-chat__action-btn:hover {
    background: var(--wa-border);
    color: var(--wa-text-primary);
}

.wa-chat__action-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.wa-chat__action-btn svg {
    width: 16px;
    height: 16px;
}

/* ════════════════════════════════════════════════════════════════
   MESSAGES AREA
   ════════════════════════════════════════════════════════════════ */

.wa-chat__messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: var(--wa-bg-card);
}

.wa-chat__messages::-webkit-scrollbar { width: 6px; }
.wa-chat__messages::-webkit-scrollbar-track { background: transparent; }
.wa-chat__messages::-webkit-scrollbar-thumb {
    background: var(--wa-border-strong);
    border-radius: 3px;
}
.wa-chat__messages::-webkit-scrollbar-thumb:hover { background: var(--wa-text-muted); }

.wa-chat__messages {
    scrollbar-width: thin;
    scrollbar-color: var(--wa-border-strong) transparent;
}

/* ════════════════════════════════════════════════════════════════
   MESSAGES BUBBLES
   ════════════════════════════════════════════════════════════════ */

.wa-msg {
    display: flex;
    max-width: 88%;
    animation: wa-fade-in 0.3s ease-out;
}

@keyframes wa-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.wa-msg--user { align-self: flex-end; }
.wa-msg--assistant,
.wa-msg--error { align-self: flex-start; }

.wa-msg__bubble {
    padding: 11px 15px;
    border-radius: var(--wa-radius-md);
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.wa-msg--user .wa-msg__bubble {
    background: var(--wa-grad);
    color: #fff;
    border-bottom-right-radius: 6px;
    font-weight: 500;
}

.wa-msg--assistant .wa-msg__bubble {
    background: var(--wa-bg-surface);
    color: var(--wa-text-primary);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--wa-border);
}

.wa-msg--welcome .wa-msg__bubble {
    background: var(--wa-bg-surface);
    border: 1px solid var(--wa-border);
}

.wa-msg--error .wa-msg__bubble {
    background: rgba(255, 85, 114, 0.12);
    color: var(--wa-error);
    border: 1px solid rgba(255, 85, 114, 0.32);
}

/* Linki w wiadomościach */
.wa-link {
    color: #FF7090;
    text-decoration: underline;
    text-decoration-color: rgba(255, 112, 144, 0.4);
    text-underline-offset: 2px;
    font-weight: 500;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
    word-break: break-word;
}

.wa-link:hover {
    color: #FFAFC2;
    text-decoration-color: currentColor;
}

.wa-msg--user .wa-link {
    color: #fff;
    text-decoration-color: rgba(255, 255, 255, 0.5);
}

.wa-msg--user .wa-link:hover {
    text-decoration-color: #fff;
}

/* ════════════════════════════════════════════════════════════════
   TYPING INDICATOR (kropki)
   ════════════════════════════════════════════════════════════════ */

.wa-msg--typing .wa-msg__bubble {
    padding: 14px 18px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.wa-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--wa-text-secondary);
    animation: wa-bounce 1.2s ease-in-out infinite;
}

.wa-dot:nth-child(2) { animation-delay: 0.15s; }
.wa-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes wa-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ════════════════════════════════════════════════════════════════
   INPUT AREA
   ════════════════════════════════════════════════════════════════ */

.wa-chat__input-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 14px 16px 8px;
    background: var(--wa-bg-card);
    border-top: 1px solid var(--wa-border);
    /* Zapobiega overflow na iOS Safari */
    width: 100%;
    box-sizing: border-box;
}

.wa-chat__input {
    flex: 1 1 0;
    min-width: 0;  /* KRYTYCZNE — pozwala flex-child się skurczyć poniżej content size */
    background: var(--wa-bg-surface);
    border: 1.5px solid var(--wa-border);
    border-radius: var(--wa-radius-md);
    padding: 11px 14px;
    color: var(--wa-text-primary);
    font-family: var(--wa-font-body);
    font-size: 16px;  /* 16px+ na mobile zapobiega auto-zoomowaniu na iOS */
    line-height: 1.5;
    resize: none;
    outline: none;
    min-height: 42px;
    max-height: 120px;
    transition: border-color 0.2s ease, background 0.2s ease;
    /* Twardy fix dla iOS — input nie wystaje poza kontener */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.wa-chat__input::placeholder {
    color: var(--wa-text-muted);
}

.wa-chat__input:focus {
    border-color: rgba(224, 32, 144, 0.5);
    background: var(--wa-bg-elevated);
}

.wa-chat__input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wa-chat__send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--wa-radius-md);
    background: var(--wa-grad);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(224, 32, 144, 0.3);
}

.wa-chat__send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(224, 32, 144, 0.45);
}

.wa-chat__send-btn:active:not(:disabled) { transform: scale(0.95); }

.wa-chat__send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.wa-chat__send-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

.wa-chat__send-btn svg {
    width: 18px;
    height: 18px;
    transform: translateX(1px) translateY(-1px);
}

/* ════════════════════════════════════════════════════════════════
   DISCLAIMER
   ════════════════════════════════════════════════════════════════ */

.wa-chat__disclaimer {
    padding: 4px 18px 12px;
    text-align: center;
    font-size: 10.5px;
    color: var(--wa-text-muted);
    line-height: 1.5;
    background: var(--wa-bg-card);
}

/* ════════════════════════════════════════════════════════════════
   MOBILE — fullscreen on small viewports
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 520px) {
    .wa-chat {
        bottom: 88px;  /* miejsce na baner cookies */
    }

    .wa-chat--right { right: 16px; }
    .wa-chat--left { left: 16px; }

    .wa-chat__window {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        transform: translateY(100%);
    }

    .wa-chat--open .wa-chat__window {
        transform: translateY(0) scale(1);
    }

    .wa-chat__fab {
        width: 56px;
        height: 56px;
    }

    .wa-chat__messages {
        padding: 16px 14px;
    }

    .wa-msg {
        max-width: 92%;
    }

    /* Safe area dla iPhone z notchem */
    .wa-chat__header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .wa-chat__disclaimer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* ════════════════════════════════════════════════════════════════
   REDUCED MOTION (accessibility)
   ════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    .wa-chat *,
    .wa-chat *::before,
    .wa-chat *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ════════════════════════════════════════════════════════════════
   DARK MODE PREFERENCE — widget jest dark zawsze, nic do robienia.
   Ale rezerwujemy klasy na wypadek przyszłego light mode.
   ════════════════════════════════════════════════════════════════ */

/* (zarezerwowane) */
