/**
 * Smart Website AI - Frontend Chat Widget Stylesheet
 * 
 * Supports CSS Custom Properties configured via WordPress Admin Customizer.
 * @package SmartWebsiteAI
 */

:root {
    --swai-primary: #2563eb;
    --swai-secondary: #1e40af;
    --swai-header-bg: #1d4ed8;
    --swai-header-text: #ffffff;
    --swai-customer-bubble: #2563eb;
    --swai-customer-text: #ffffff;
    --swai-ai-bubble: #f3f4f6;
    --swai-ai-text: #1f2937;
    --swai-border-color: #e5e7eb;
    --swai-border-radius: 16px;
    --swai-widget-width: 380px;
    --swai-widget-height: 580px;
    --swai-launcher-size: 60px;
    --swai-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --swai-font-size: 14px;
    --swai-offset-x: 20px;
    --swai-offset-y: 20px;
    --swai-mobile-offset-x: 10px;
    --swai-mobile-offset-y: 10px;
    --swai-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* Base Widget Container */
.swai-widget-container {
    position: fixed;
    z-index: 999990;
    font-family: var(--swai-font-family);
    font-size: var(--swai-font-size);
    line-height: 1.5;
    box-sizing: border-box;
}

.swai-widget-container *,
.swai-widget-container *::before,
.swai-widget-container *::after {
    box-sizing: border-box;
}

/* Positioning */
.swai-pos-bottom-right {
    bottom: var(--swai-offset-y);
    right: var(--swai-offset-x);
}

.swai-pos-bottom-left {
    bottom: var(--swai-offset-y);
    left: var(--swai-offset-x);
}

/* Floating Launcher Button */
.swai-launcher-btn {
    width: var(--swai-launcher-size);
    height: var(--swai-launcher-size);
    border-radius: 50%;
    background-color: var(--swai-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
    outline: none;
}

.swai-launcher-btn:hover {
    transform: scale(1.06);
    background-color: var(--swai-secondary);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.swai-launcher-btn:focus-visible {
    outline: 3px solid var(--swai-secondary);
    outline-offset: 3px;
}

.swai-launcher-btn .dashicons {
    font-size: 28px;
    width: 28px;
    height: 28px;
    line-height: 28px;
}

.swai-launcher-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

/* Unread Badge */
.swai-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    animation: swai-pulse 2s infinite;
}

@keyframes swai-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Chat Window Panel */
.swai-chat-window {
    position: absolute;
    bottom: calc(var(--swai-launcher-size) + 14px);
    width: var(--swai-widget-width);
    height: var(--swai-widget-height);
    max-height: calc(100vh - 100px);
    background-color: #ffffff;
    border-radius: var(--swai-border-radius);
    box-shadow: var(--swai-shadow);
    border: 1px solid var(--swai-border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.swai-pos-bottom-right .swai-chat-window {
    right: 0;
}

.swai-pos-bottom-left .swai-chat-window {
    left: 0;
}

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

/* Header */
.swai-chat-header {
    background-color: var(--swai-header-bg);
    color: var(--swai-header-text);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.swai-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.swai-avatar-wrap {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.swai-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.swai-avatar-fallback {
    color: var(--swai-header-text);
    font-size: 22px;
    width: 22px;
    height: 22px;
}

.swai-online-indicator {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    background-color: #22c55e;
    border: 2px solid var(--swai-header-bg);
    border-radius: 50%;
}

.swai-header-meta {
    display: flex;
    flex-direction: column;
}

.swai-bot-name {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--swai-header-text);
    line-height: 1.2;
}

.swai-support-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
}

.swai-status-dot {
    width: 6px;
    height: 6px;
    background-color: #22c55e;
    border-radius: 50%;
    display: inline-block;
}

.swai-header-actions {
    display: flex;
    gap: 6px;
}

.swai-btn-icon {
    background: transparent;
    border: none;
    color: var(--swai-header-text);
    opacity: 0.85;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.swai-btn-icon:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.2);
}

.swai-btn-icon:focus-visible {
    outline: 2px solid #ffffff;
}

/* Conversation Scroll Area */
.swai-conversation {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #fafbfc;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    outline: none;
}

/* Messages List */
.swai-messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.swai-message-row {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    word-break: break-word;
    animation: swai-msg-in 0.2s ease-out;
}

@keyframes swai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.swai-msg-incoming {
    align-self: flex-start;
}

.swai-msg-outgoing {
    align-self: flex-end;
}

.swai-bubble {
    padding: 10px 14px;
    font-size: var(--swai-font-size);
    line-height: 1.45;
}

.swai-msg-incoming .swai-bubble {
    background-color: var(--swai-ai-bubble);
    color: var(--swai-ai-text);
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.swai-msg-outgoing .swai-bubble {
    background-color: var(--swai-customer-bubble);
    color: var(--swai-customer-text);
    border-radius: 16px 16px 4px 16px;
}

.swai-timestamp {
    font-size: 10px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
}

.swai-msg-outgoing .swai-timestamp {
    text-align: right;
}

/* Citations Box */
.swai-citations-box {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
}

.swai-citations-title {
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #4b5563;
}

.swai-citation-link {
    display: block;
    color: var(--swai-primary);
    text-decoration: underline;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.swai-citation-link:hover {
    color: var(--swai-secondary);
}

/* Typing Indicator */
.swai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background-color: var(--swai-ai-bubble);
    border-radius: 16px 16px 16px 4px;
    align-self: flex-start;
    width: fit-content;
}

.swai-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: swai-bounce 1.4s infinite ease-in-out both;
}

.swai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.swai-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.swai-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes swai-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.swai-typing-label {
    margin-left: 6px;
    font-size: 11px;
    color: #6b7280;
}

/* Human Handoff Banner */
.swai-handoff-banner {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 10px 12px;
    margin-top: 8px;
    animation: swai-msg-in 0.3s ease-out;
}

.swai-handoff-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.swai-handoff-prompt-text {
    font-size: 12px;
    font-weight: 500;
    color: #1e40af;
    display: flex;
    align-items: center;
    gap: 6px;
}

.swai-handoff-btn {
    background-color: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
    white-space: nowrap;
}

.swai-handoff-btn:hover {
    background-color: #1d4ed8;
}

.swai-handoff-details {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #bfdbfe;
    font-size: 12px;
    color: #1e3a8a;
}

.swai-handoff-notice {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.swai-handoff-notice p {
    margin: 0;
    line-height: 1.4;
}

.swai-handoff-schedule {
    background-color: #dbeafe;
    padding: 6px 10px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.swai-schedule-days {
    font-size: 11px;
    color: #3b82f6;
}

/* Composer Form */
.swai-composer-form {
    padding: 10px 14px;
    background-color: #ffffff;
    border-top: 1px solid var(--swai-border-color);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.swai-composer-input-wrap {
    flex: 1;
    position: relative;
}

.swai-message-input {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 8px 12px;
    border: 1px solid var(--swai-border-color);
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: var(--swai-font-size);
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.swai-message-input:focus {
    border-color: var(--swai-primary);
}

.swai-message-input:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
}

.swai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--swai-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
    padding: 0;
}

.swai-send-btn:hover:not(:disabled) {
    background-color: var(--swai-secondary);
    transform: scale(1.05);
}

.swai-send-btn:disabled {
    background-color: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

.swai-send-btn .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
    line-height: 20px;
}

/* Footer Branding (Permanent Lock: Centered & Non-Editable) */
.swai-chat-footer,
.swai-chat-footer-branding {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    padding: 8px 12px;
    background-color: #f9fafb;
    border-top: 1px solid #f3f4f6;
    font-size: 11px;
    color: #9ca3af;
    flex-shrink: 0;
}
.swai-chat-footer .swai-footer-text,
.swai-chat-footer-branding .swai-footer-text {
    width: 100%;
    text-align: center;
    display: block;
    margin: 0 auto;
}

/* Phase 7: WooCommerce Live Product Card */
.swai-product-card {
    display: flex;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    margin-top: 8px;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.swai-product-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.swai-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.swai-product-name {
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.swai-product-price {
    font-size: 13px;
    font-weight: 700;
    color: #059669;
}

.swai-stock-badge {
    display: inline-block;
    align-self: flex-start;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.swai-stock-badge.swai-in-stock {
    background: #d1fae5;
    color: #065f46;
}

.swai-stock-badge.swai-out-of-stock {
    background: #fee2e2;
    color: #991b1b;
}

.swai-product-btn {
    display: inline-block;
    align-self: flex-start;
    margin-top: 4px;
    padding: 4px 10px;
    background: var(--swai-primary);
    color: #ffffff;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.15s ease;
}

.swai-product-btn:hover {
    opacity: 0.9;
    color: #ffffff;
}

/* Phase 7: Order Status Card */
.swai-order-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.swai-order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    color: #111827;
}

.swai-order-status {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.swai-order-status.swai-status-completed {
    background: #d1fae5;
    color: #065f46;
}

.swai-order-status.swai-status-processing {
    background: #dbeafe;
    color: #1e40af;
}

.swai-order-status.swai-status-on-hold {
    background: #fef3c7;
    color: #92400e;
}

.swai-order-status.swai-status-pending {
    background: #fee2e2;
    color: #991b1b;
}

.swai-order-date {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 6px;
}

.swai-order-items {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 12px;
    color: #374151;
}

.swai-order-items li {
    padding: 3px 0;
    border-top: 1px dashed #f3f4f6;
}

/* Phase 7: Order Guest Verification Box */
.swai-order-verify-box {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.swai-verify-step-1,
.swai-verify-step-2 {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.swai-verify-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 12px;
    box-sizing: border-box;
}

.swai-verify-input:focus {
    border-color: var(--swai-primary);
    outline: none;
}

.swai-verify-btn {
    background: var(--swai-primary);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.swai-verify-btn:hover {
    opacity: 0.9;
}

.swai-verify-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.swai-verify-msg {
    font-size: 11px;
    line-height: 1.4;
}

/* Quick Replies (Conversational Pill Buttons) */
.swai-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 4px;
}

.swai-quick-reply-btn {
    background-color: #ffffff;
    color: var(--swai-primary);
    border: 1px solid var(--swai-primary);
    border-radius: 14px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.2;
    transition: all 0.15s ease;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.swai-quick-reply-btn:hover {
    background-color: var(--swai-primary);
    color: #ffffff;
}

.swai-quick-reply-btn:focus-visible {
    outline: 2px solid var(--swai-primary);
    outline-offset: 1px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .swai-chat-window,
    .swai-launcher-btn,
    .swai-message-row,
    .swai-unread-badge,
    .swai-typing-dot {
        transition: none !important;
        animation: none !important;
    }
}
