/* ═══════════════════════════════════════════════════════════════
   พี่วิทย์ AI Chat Widget — Standalone WordPress Plugin
   ═══════════════════════════════════════════════════════════════ */

#pwit-chat-root {
    --pwit-primary: #6366f1;
    --pwit-primary-dark: #4f46e5;
    --pwit-bg: #0f172a;
    --pwit-surface: #1e293b;
    --pwit-surface-2: #334155;
    --pwit-text: #f1f5f9;
    --pwit-text-muted: #94a3b8;
    --pwit-border: #475569;
    --pwit-user-bg: #6366f1;
    --pwit-bot-bg: #1e293b;
    --pwit-radius: 16px;
    --pwit-shadow: 0 20px 60px rgba(0,0,0,0.4);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 999999;
}

/* ── FAB Button ──────────────────────────────────── */
#pwit-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 4px 20px rgba(99,102,241,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000000;
}
#pwit-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(99,102,241,0.6);
}
#pwit-chat-fab {
    animation: pwit-fab-entrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1s both;
}
@keyframes pwit-fab-entrance {
    from { opacity: 0; transform: scale(0) rotate(-180deg); }
    to { opacity: 1; transform: scale(1) rotate(0deg); }
}
#pwit-chat-fab svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
#pwit-chat-fab .fab-icon-close { display: none; }
#pwit-chat-fab.is-open .fab-icon-open { display: none; }
#pwit-chat-fab.is-open .fab-icon-close { display: block; }

/* Badge */
#pwit-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Chat Panel ──────────────────────────────────── */
#pwit-chat-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    background: var(--pwit-bg);
    border-radius: var(--pwit-radius);
    box-shadow: var(--pwit-shadow);
    border: 1px solid var(--pwit-border);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
#pwit-chat-panel.is-open {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: pwit-panelOpen 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pwit-panelOpen {
    from { opacity: 0; transform: translateY(20px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ──────────────────────────────────────── */
#pwit-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--pwit-surface);
    border-bottom: 1px solid var(--pwit-border);
    flex-shrink: 0;
}
.pwit-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}
.pwit-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
    stroke: none;
}
.pwit-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.pwit-status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--pwit-surface);
    animation: pwit-statusPulse 2s ease-in-out infinite;
}
@keyframes pwit-statusPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    50% { box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}
.pwit-header-info { flex: 1; }
.pwit-header-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--pwit-text);
}
.pwit-header-subtitle {
    font-size: 11px;
    color: var(--pwit-text-muted);
}
#pwit-chat-close-btn,
#pwit-chat-clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
}
#pwit-chat-close-btn:hover,
#pwit-chat-clear-btn:hover { background: var(--pwit-surface-2); }
#pwit-chat-close-btn svg,
#pwit-chat-clear-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--pwit-text-muted);
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
}
#pwit-chat-clear-btn svg {
    fill: var(--pwit-text-muted);
    stroke: none;
    width: 20px;
    height: 20px;
}

/* ── Messages Area ───────────────────────────────── */
#pwit-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.pwit-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}
.pwit-msg-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 4px;
    position: relative;
}
.pwit-msg-wrapper-user {
    justify-content: flex-end;
}
.pwit-msg-wrapper-bot {
    justify-content: flex-start;
}
.pwit-msg-actions {
    display: none;
    flex-direction: column;
    gap: 2px;
    align-self: center;
}
.pwit-msg-wrapper:hover .pwit-msg-actions {
    display: flex;
}
/* User: actions on the left of bubble */
.pwit-msg-wrapper-user .pwit-msg-actions {
    order: -1;
}
/* Bot: actions on the right of bubble */
.pwit-msg-wrapper-bot .pwit-msg-actions {
    order: 1;
}
.pwit-action-btn {
    background: var(--pwit-surface-2);
    border: none;
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.pwit-action-btn:hover {
    opacity: 1;
}
.pwit-action-btn svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: var(--pwit-text-muted);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.pwit-msg-user {
    align-self: flex-end;
    background: var(--pwit-user-bg);
    color: #fff;
    border-bottom-right-radius: 4px;
    animation: pwit-msgSlideLeft 0.3s ease;
}
.pwit-msg-bot {
    align-self: flex-start;
    background: var(--pwit-surface);
    color: var(--pwit-text);
    border: 1px solid var(--pwit-border);
    border-bottom-left-radius: 4px;
    animation: pwit-msgSlideRight 0.3s ease;
}
@keyframes pwit-msgSlideLeft {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes pwit-msgSlideRight {
    from { opacity: 0; transform: translateX(-16px); }
    to { opacity: 1; transform: translateX(0); }
}
.pwit-msg-bot a {
    color: #818cf8;
    text-decoration: underline;
}
.pwit-msg-bot strong { color: #e2e8f0; }
.pwit-msg-bot ul, .pwit-msg-bot ol {
    padding-left: 18px;
    margin: 6px 0;
}

/* Typing indicator */
.pwit-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    align-self: flex-start;
    background: var(--pwit-surface);
    border-radius: 12px;
    border: 1px solid var(--pwit-border);
}
.pwit-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pwit-text-muted);
    animation: pwit-bounce 1.4s infinite ease-in-out;
}
.pwit-typing span:nth-child(2) { animation-delay: 0.2s; }
.pwit-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pwit-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Input Area ──────────────────────────────────── */
#pwit-chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--pwit-border);
    background: var(--pwit-surface);
    flex-shrink: 0;
}
#pwit-chat-input {
    flex: 1;
    border: 1px solid var(--pwit-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    background: var(--pwit-bg);
    color: var(--pwit-text);
    outline: none;
    resize: none;
    font-family: inherit;
    max-height: 100px;
}
#pwit-chat-input:focus {
    border-color: var(--pwit-primary);
}
#pwit-chat-input::placeholder {
    color: var(--pwit-text-muted);
}
#pwit-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--pwit-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    align-self: flex-end;
}
#pwit-chat-send:hover { background: var(--pwit-primary-dark); }
#pwit-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
#pwit-chat-send svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 480px) {
    #pwit-chat-panel.is-open {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0;
    }
    #pwit-chat-fab.is-open {
        display: none !important;
    }
}


/* ── Role Selector ───────────────────────────────── */
#pwit-role-selector {
    padding: 24px 20px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    animation: pwit-fadeInUp 0.5s ease;
}
.pwit-role-hero {
    margin-bottom: 4px;
}
.pwit-role-hero-img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--pwit-primary);
    box-shadow: 0 0 20px rgba(99,102,241,0.3);
    animation: pwit-pulse-glow 2s ease-in-out infinite;
}
.pwit-role-hero-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(99,102,241,0.3);
    animation: pwit-pulse-glow 2s ease-in-out infinite;
}
.pwit-role-hero-icon svg {
    width: 36px;
    height: 36px;
    fill: #fff;
}
.pwit-role-greeting {
    font-size: 20px;
    font-weight: 700;
    color: var(--pwit-text);
    animation: pwit-fadeInUp 0.6s ease 0.1s both;
}
.pwit-role-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--pwit-text);
    animation: pwit-fadeInUp 0.6s ease 0.2s both;
}
.pwit-role-subtitle {
    font-size: 12px;
    color: var(--pwit-text-muted);
    margin-bottom: 8px;
    animation: pwit-fadeInUp 0.6s ease 0.3s both;
}
.pwit-role-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 0 10px;
    width: 100%;
    animation: pwit-fadeInUp 0.6s ease 0.4s both;
}
.pwit-role-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 12px;
    border: 1px solid var(--pwit-border);
    border-radius: 12px;
    background: var(--pwit-surface);
    color: var(--pwit-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
}
.pwit-role-btn:hover {
    background: var(--pwit-primary);
    border-color: var(--pwit-primary);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(99,102,241,0.35);
}
.pwit-role-btn:active {
    transform: translateY(0) scale(0.98);
}
.pwit-role-btn:hover .pwit-role-icon {
    fill: #fff;
}
.pwit-role-icon {
    width: 28px;
    height: 28px;
    fill: var(--pwit-text-muted);
    transition: fill 0.2s;
}

/* ── Animations ──────────────────────────────────── */
@keyframes pwit-fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pwit-pulse-glow {
    0%, 100% { box-shadow: 0 0 12px rgba(99,102,241,0.3); }
    50% { box-shadow: 0 0 24px rgba(99,102,241,0.6); }
}
@keyframes pwit-slideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}
