/**
 * BLAKIWI AI — Chat Widget Styles
 *
 * Floating bubble, slide-in panel, messages, and typing indicator.
 * Uses CSS custom properties for theming.
 *
 * @package PWSChatAI
 */

/* ── Custom Properties ───────────────────────── */

:root {
    --pws-primary-color: #6C63FF;
    --pws-bubble-size: 60px;
    --pws-panel-width: 380px;
    --pws-panel-height: 520px;
    --pws-radius: 16px;
    --pws-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --pws-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --pws-bg-light: #ffffff;
    --pws-bg-messages: #f5f5fa;
    --pws-text-primary: #1a1a2e;
    --pws-text-secondary: #666;
    --pws-border: #e8e8f0;
    --pws-user-bg: var(--pws-primary-color);
    --pws-user-text: #fff;
    --pws-bot-bg: #fff;
    --pws-bot-text: #1a1a2e;
    --pws-error-text: #dc3545;
}

/* ── Widget Container ────────────────────────── */

.pws-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--pws-font);
    font-size: 14px;
    line-height: 1.5;
}

.pws-chat-widget * {
    box-sizing: border-box;
}

/* ── Floating Bubble ─────────────────────────── */

.pws-chat-bubble {
    width: var(--pws-bubble-size);
    height: var(--pws-bubble-size);
    border-radius: 50%;
    background: var(--pws-primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--pws-shadow);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
    position: relative;
}

.pws-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.pws-chat-bubble:active {
    transform: scale(0.95);
}

.pws-chat-bubble--active {
    transform: rotate(0deg);
}

.pws-bubble-icon {
    width: 28px;
    height: 28px;
}

/* ── Chat Panel ──────────────────────────────── */

.pws-chat-panel {
    position: absolute;
    bottom: calc(var(--pws-bubble-size) + 16px);
    right: 0;
    width: var(--pws-panel-width);
    height: var(--pws-panel-height);
    background: var(--pws-bg-light);
    border-radius: var(--pws-radius);
    box-shadow: var(--pws-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s ease,
        visibility 0.3s ease,
        transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pws-chat-panel--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ── Header ──────────────────────────────────── */

.pws-chat-header {
    background: var(--pws-primary-color);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.pws-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pws-chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pws-chat-avatar svg {
    width: 22px;
    height: 22px;
}

.pws-chat-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.pws-chat-status {
    display: block;
    font-size: 12px;
    opacity: 0.85;
}

.pws-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.pws-chat-close:hover {
    opacity: 1;
}

.pws-chat-close svg {
    width: 20px;
    height: 20px;
}

/* ── Messages Area ───────────────────────────── */

.pws-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--pws-bg-messages);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pws-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.pws-chat-messages::-webkit-scrollbar-thumb {
    background: var(--pws-border);
    border-radius: 4px;
}

/* ── Message Bubbles ─────────────────────────── */

.pws-message {
    display: flex;
    max-width: 85%;
    animation: pwsFadeIn 0.3s ease;
}

.pws-message-user {
    align-self: flex-end;
}

.pws-message-bot {
    align-self: flex-start;
}

.pws-message-content {
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
    white-space: pre-wrap;
}

.pws-message-user .pws-message-content {
    background: var(--pws-user-bg);
    color: var(--pws-user-text);
    border-bottom-right-radius: 4px;
}

.pws-message-bot .pws-message-content {
    background: var(--pws-bot-bg);
    color: var(--pws-bot-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.pws-message-error .pws-message-content {
    color: var(--pws-error-text);
    background: #fff5f5;
}

@keyframes pwsFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Typing Indicator ────────────────────────── */

.pws-typing .pws-message-content {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
}

.pws-dot {
    width: 8px;
    height: 8px;
    background: var(--pws-primary-color);
    border-radius: 50%;
    opacity: 0.4;
    animation: pwsBounce 1.4s infinite ease-in-out both;
}

.pws-dot:nth-child(1) {
    animation-delay: 0s;
}

.pws-dot:nth-child(2) {
    animation-delay: 0.16s;
}

.pws-dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes pwsBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Input Area ──────────────────────────────── */

.pws-chat-input-wrap {
    padding: 12px 16px;
    border-top: 1px solid var(--pws-border);
    background: var(--pws-bg-light);
    flex-shrink: 0;
}

.pws-chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pws-chat-input {
    flex: 1;
    border: 1px solid var(--pws-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: var(--pws-font);
    outline: none;
    transition: border-color 0.2s;
    background: var(--pws-bg-messages);
    color: var(--pws-text-primary);
}

.pws-chat-input:focus {
    border-color: var(--pws-primary-color);
}

.pws-chat-input::placeholder {
    color: var(--pws-text-secondary);
}

.pws-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--pws-primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

.pws-chat-send:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}

.pws-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.pws-chat-send svg {
    width: 18px;
    height: 18px;
}

/* ── Footer ──────────────────────────────────── */

.pws-chat-footer {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--pws-text-secondary);
    border-top: 1px solid var(--pws-border);
    background: var(--pws-bg-light);
    flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────── */

/* Left-side panel positioning */
.pws-side-left .pws-chat-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

@media (max-width: 480px) {

    .pws-chat-widget {
        bottom: 12px;
        right: 12px;
    }

    .pws-chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        max-height: 100vh;
    }

    .pws-chat-bubble {
        --pws-bubble-size: 54px;
    }
}

/* ── Dark Theme (prefers-color-scheme) ───────── */

@media (prefers-color-scheme: dark) {

    .pws-chat-widget {
        --pws-bg-light: #1e1e2e;
        --pws-bg-messages: #14141f;
        --pws-text-primary: #e0e0e8;
        --pws-text-secondary: #999;
        --pws-border: #2a2a3d;
        --pws-bot-bg: #252538;
        --pws-bot-text: #e0e0e8;
    }

    .pws-chat-input {
        background: #252538;
        color: #e0e0e8;
    }
}