/* =============================================
   WooChat Translator — Frontend Widget v2.0
   ============================================= */

:root {
    --wct-primary: #6366f1;
    --wct-primary-dark: #4f46e5;
    --wct-header-bg: var(--wct-primary);
    --wct-visitor-bubble: var(--wct-primary);
    --wct-admin-bubble: #f8f9fa;
    --wct-bg: #ffffff;
    --wct-bg-light: #f8f9fa;
    --wct-text: #1a1a2e;
    --wct-text-light: #64748b;
    --wct-border: #e2e8f0;
    --wct-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --wct-widget-width: 380px;
    --wct-widget-height: 520px;
    --wct-bubble-max-width: 82%;
    --wct-bubble-radius: 16px;
    --wct-font-size: 14px;
    --wct-header-text-color: #ffffff;
    --wct-btn-bottom: 24px;
    --wct-btn-bottom-mobile: 16px;
}

/* Toggle Button — !important overrides theme conflicts (e.g. [class*=ct-toggle]) */
button#wct-toggle-btn.wct-toggle-btn {
    position: fixed !important;
    bottom: var(--wct-btn-bottom, 24px) !important;
    color: white !important;
    border: none !important;
    border-width: 0 !important;
    border-style: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 999998 !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    padding: 0 !important;
    margin: 0 !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    outline: none !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    line-height: 1 !important;
    text-decoration: none !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    font-size: 0 !important;
    overflow: visible !important;
}

.wct-toggle-btn svg {
    font-size: initial !important;
}

.wct-bottom-right button#wct-toggle-btn.wct-toggle-btn { right: 24px !important; left: auto !important; }
.wct-bottom-left button#wct-toggle-btn.wct-toggle-btn { left: 24px !important; right: auto !important; }

button#wct-toggle-btn.wct-toggle-btn:hover {
    transform: scale(1.08) !important;
    filter: brightness(1.1) !important;
}

button#wct-toggle-btn.wct-toggle-btn:focus {
    outline: none !important;
    box-shadow: inherit !important;
}

button#wct-toggle-btn.wct-toggle-btn.wct-open .wct-icon-chat { display: none !important; }
button#wct-toggle-btn.wct-toggle-btn.wct-open .wct-icon-close { display: block !important; }

/* Online Dot on Toggle Button */
.wct-online-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid white;
    z-index: 2;
    animation: wctPulseOnline 2s infinite;
}

@keyframes wctPulseOnline {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Online Dot in Header */
.wct-header-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wct-header-online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    animation: wctPulseOnline 2s infinite;
}

/* Badge */
.wct-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
    border: 2px solid white;
}

/* Chat Window */
.wct-chat-window {
    position: fixed;
    bottom: calc(var(--wct-btn-bottom, 24px) + var(--wct-btn-size, 60px) + 12px);
    width: var(--wct-widget-width);
    height: var(--wct-widget-height);
    background: var(--wct-bg);
    border-radius: var(--wct-bubble-radius);
    box-shadow: var(--wct-shadow);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--wct-border);
    animation: wctSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.wct-bottom-right .wct-chat-window { right: 24px; }
.wct-bottom-left .wct-chat-window { left: 24px; }

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

/* Header */
.wct-widget-header {
    background: var(--wct-header-bg);
    color: var(--wct-header-text-color, #ffffff);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.wct-header-info h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--wct-header-text-color, #ffffff);
}

.wct-header-info small {
    opacity: 0.85;
    font-size: 12px;
    color: var(--wct-header-text-color, #ffffff);
}

/* Pre-form notice */
.wct-pre-form-notice {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.5;
    color: #92400e;
    text-align: left;
}

/* Start Form */
.wct-start-form {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.wct-start-inner {
    text-align: center;
    width: 100%;
}

.wct-start-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.wct-start-text {
    color: var(--wct-text-light);
    font-size: var(--wct-font-size);
    margin-bottom: 20px;
}

.wct-start-form input {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    border: 1.5px solid var(--wct-border);
    border-radius: 10px;
    font-size: var(--wct-font-size);
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.wct-start-form input:focus {
    border-color: var(--wct-primary);
}

.wct-btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--wct-primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.wct-btn-primary:hover {
    background: var(--wct-primary-dark);
}

/* Messages */
.wct-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.wct-msg {
    max-width: var(--wct-bubble-max-width);
    padding: 10px 14px;
    border-radius: var(--wct-bubble-radius);
    font-size: var(--wct-font-size);
    line-height: 1.45;
    word-wrap: break-word;
    animation: wctFadeIn 0.2s ease;
}

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

.wct-msg-visitor {
    background: var(--wct-visitor-bubble);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.wct-msg-admin {
    background: var(--wct-admin-bubble);
    color: var(--wct-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--wct-border);
}

.wct-msg-system {
    background: transparent;
    color: var(--wct-text-light);
    align-self: center;
    font-size: 12px;
    text-align: center;
    max-width: 100%;
}

.wct-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
}

.wct-msg-visitor .wct-msg-time { text-align: right; }
.wct-msg-admin .wct-msg-time { text-align: left; }

/* Typing indicator */
.wct-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
}

.wct-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--wct-text-light);
    border-radius: 50%;
    animation: wctBounce 1.4s infinite;
}

.wct-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wct-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes wctBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Input Bar */
.wct-input-bar {
    border-top: 1px solid var(--wct-border);
    padding: 12px 16px;
    flex-shrink: 0;
    background: white;
}

.wct-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.wct-input-bar textarea {
    flex: 1;
    border: 1.5px solid var(--wct-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: var(--wct-font-size);
    resize: none;
    outline: none;
    max-height: 80px;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.wct-input-bar textarea:focus {
    border-color: var(--wct-primary);
}

.wct-btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--wct-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.wct-btn-send:hover {
    background: var(--wct-primary-dark);
}

.wct-btn-send:active {
    transform: scale(0.93);
}

.wct-powered-by {
    text-align: center;
    margin-top: 6px;
    color: var(--wct-text-light);
}

.wct-powered-by small {
    font-size: 11px;
}

/* Reset — zabezpieczenie przed stylami motywu */
#wct-chat-widget *,
#wct-chat-widget *::before,
#wct-chat-widget *::after {
    box-sizing: border-box;
}

#wct-chat-widget button:not(.wct-toggle-btn),
#wct-chat-widget input,
#wct-chat-widget textarea,
#wct-chat-widget select {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* Offline state — subtle visual change */
.wct-widget.wct-offline .wct-toggle-btn {
    opacity: 0.85;
}

.wct-widget.wct-offline .wct-widget-header small {
    color: var(--wct-header-text-color, #ffffff);
    opacity: 0.9;
}

/* Tablet */
@media (max-width: 600px) {
    .wct-chat-window {
        width: calc(100vw - 24px) !important;
        max-width: 420px !important;
        right: 12px !important;
        left: 12px !important;
    }
}

/* Mobile */
@media (max-width: 440px) {
    .wct-chat-window {
        width: calc(100vw - 16px) !important;
        height: calc(100dvh - 100px) !important;
        max-height: calc(100dvh - 100px) !important;
        bottom: calc(var(--wct-btn-bottom-mobile, 16px) + var(--wct-btn-size, 60px) + 4px) !important;
        right: 8px !important;
        left: 8px !important;
        border-radius: 16px 16px 12px 12px !important;
        max-width: none !important;
    }

    button#wct-toggle-btn.wct-toggle-btn {
        bottom: var(--wct-btn-bottom-mobile, 16px) !important;
    }

    .wct-bottom-right button#wct-toggle-btn.wct-toggle-btn { right: 16px !important; }
    .wct-bottom-left button#wct-toggle-btn.wct-toggle-btn { left: 16px !important; }

    /* Header mobilny — kompaktowy */
    .wct-widget-header {
        padding: 12px 16px !important;
    }

    .wct-header-info h4 {
        font-size: 15px !important;
    }

    .wct-header-info small {
        font-size: 11px !important;
    }

    /* Formularz startowy — mobilny */
    .wct-start-form {
        padding: 16px !important;
    }

    .wct-start-icon {
        font-size: 36px !important;
        margin-bottom: 8px !important;
    }

    .wct-start-text {
        font-size: 13px !important;
        margin-bottom: 14px !important;
    }

    .wct-start-form input {
        padding: 10px 14px !important;
        margin-bottom: 10px !important;
        font-size: 14px !important;
    }

    .wct-btn-primary {
        padding: 11px !important;
        font-size: 14px !important;
    }

    /* Wiadomości — mobilne */
    .wct-messages {
        padding: 12px !important;
        gap: 6px !important;
    }

    .wct-msg {
        max-width: 90% !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
    }

    /* Input — mobilny */
    .wct-input-bar {
        padding: 10px 12px !important;
    }

    .wct-input-bar textarea {
        padding: 8px 12px !important;
        font-size: 14px !important;
    }

    .wct-btn-send {
        width: 36px !important;
        height: 36px !important;
    }

    .wct-powered-by small {
        font-size: 10px !important;
    }
}

/* Bardzo małe ekrany */
@media (max-width: 360px) {
    .wct-chat-window {
        width: 100vw !important;
        height: calc(100dvh - 80px) !important;
        max-height: calc(100dvh - 80px) !important;
        bottom: calc(var(--wct-btn-bottom-mobile, 16px) + var(--wct-btn-size, 60px)) !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 16px 16px 0 0 !important;
    }

    button#wct-toggle-btn.wct-toggle-btn {
        bottom: var(--wct-btn-bottom-mobile, 16px) !important;
    }

    .wct-bottom-right button#wct-toggle-btn.wct-toggle-btn { right: 10px !important; }
    .wct-bottom-left button#wct-toggle-btn.wct-toggle-btn { left: 10px !important; }
}

/* Landscape mobile — zmniejsz wysokość */
@media (max-height: 500px) {
    .wct-chat-window {
        height: calc(100dvh - 70px) !important;
        max-height: calc(100dvh - 70px) !important;
        bottom: calc(var(--wct-btn-bottom-mobile, 16px) + var(--wct-btn-size, 60px)) !important;
    }

    .wct-widget-header {
        padding: 8px 12px !important;
    }

    .wct-start-icon {
        font-size: 28px !important;
        margin-bottom: 4px !important;
    }
}
