/**
 * SmartAI Chat Widget Stylesheet - Isolated & Responsive
 */

#smartai-widget-root {
    position: fixed;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#smartai-widget-root *,
#smartai-widget-root *::before,
#smartai-widget-root *::after {
    box-sizing: border-box;
}

/* Color Themes */
#smartai-widget-root.smartai-theme-blue {
    --smartai-primary: #2563eb;
    --smartai-primary-hover: #1d4ed8;
    --smartai-primary-light: #eff6ff;
    --smartai-gradient: linear-gradient(135deg, #1e3a8a, #2563eb);
}

#smartai-widget-root.smartai-theme-indigo {
    --smartai-primary: #4f46e5;
    --smartai-primary-hover: #4338ca;
    --smartai-primary-light: #eef2ff;
    --smartai-gradient: linear-gradient(135deg, #3730a3, #4f46e5);
}

#smartai-widget-root.smartai-theme-emerald {
    --smartai-primary: #059669;
    --smartai-primary-hover: #047857;
    --smartai-primary-light: #ecfdf5;
    --smartai-gradient: linear-gradient(135deg, #065f46, #059669);
}

#smartai-widget-root.smartai-theme-slate {
    --smartai-primary: #334155;
    --smartai-primary-hover: #1e293b;
    --smartai-primary-light: #f8fafc;
    --smartai-gradient: linear-gradient(135deg, #0f172a, #334155);
}

/* Positions */
#smartai-widget-root.smartai-pos-right {
    right: 24px;
    bottom: var(--smartai-offset-bottom, 24px);
}

#smartai-widget-root.smartai-pos-left {
    left: 24px;
    bottom: var(--smartai-offset-bottom, 24px);
}

/* Launcher Container & Button */
#smartai-launcher-container {
    position: relative;
    display: inline-block;
}

#smartai-launcher-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--smartai-gradient);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
    outline: none;
}

#smartai-launcher-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 14px 28px -4px rgba(0, 0, 0, 0.3);
}

#smartai-launcher-btn .smartai-icon {
    width: 28px;
    height: 28px;
    display: none;
}

#smartai-launcher-btn .smartai-icon.active {
    display: block;
}

/* Radar Pulse Glow */
.smartai-radar-ring {
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 2px solid var(--smartai-primary);
    opacity: 0;
    animation: smartai-pulse 2.4s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
    pointer-events: none;
}

@keyframes smartai-pulse {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
    }
    70% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* Elastic Bounce */
.smartai-bounce {
    animation: smartai-float 3s ease-in-out infinite;
}

@keyframes smartai-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Chat Popup Window */
#smartai-chat-window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    height: 590px;
    max-height: calc(100vh - 110px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

#smartai-widget-root.smartai-pos-left #smartai-chat-window {
    left: 0;
    transform-origin: bottom left;
}

#smartai-widget-root.smartai-pos-right #smartai-chat-window {
    right: 0;
}

#smartai-chat-window.smartai-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.92) translateY(20px);
    display: none !important;
}

/* Header */
.smartai-window-header {
    background: var(--smartai-gradient);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.smartai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.smartai-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    position: relative;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.smartai-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #ffffff;
}

.smartai-header-title {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.smartai-header-sub {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 2px;
}

#smartai-header-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

#smartai-header-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Body */
.smartai-window-body {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background: #f8fafc;
}

/* Lead Gate Screen */
#smartai-lead-gate {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
}

.smartai-lead-header {
    text-align: center;
    margin-bottom: 20px;
}

.smartai-lead-badge {
    display: inline-block;
    background: var(--smartai-primary-light);
    color: var(--smartai-primary);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 8px;
}

.smartai-lead-header h4 {
    margin: 0 0 6px 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.smartai-lead-header p {
    margin: 0;
    font-size: 12px;
    color: #64748b;
}

.smartai-form-group {
    margin-bottom: 14px;
}

.smartai-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}

.smartai-form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 13px;
    color: #0f172a;
    background: #ffffff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.smartai-form-group input:focus {
    border-color: var(--smartai-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.smartai-error-text {
    font-size: 11px;
    color: #ef4444;
    margin-top: 3px;
    display: block;
}

#smartai-lead-submit {
    width: 100%;
    padding: 12px;
    background: var(--smartai-gradient);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    margin-top: 8px;
    transition: opacity 0.2s;
}

#smartai-lead-submit:hover {
    opacity: 0.95;
}

/* Chat Stream */
#smartai-chat-stream {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#smartai-messages-list {
    flex: 1;
    padding: 18px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Message Rows */
.smartai-msg-row {
    display: flex;
    gap: 8px;
    max-width: 86%;
}

.smartai-msg-ai {
    align-self: flex-start;
}

.smartai-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.smartai-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--smartai-primary);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.smartai-msg-content {
    display: flex;
    flex-direction: column;
}

.smartai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
}

.smartai-msg-ai .smartai-msg-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.smartai-msg-user .smartai-msg-bubble {
    background: var(--smartai-primary);
    color: #ffffff;
    border-top-right-radius: 4px;
}

.smartai-msg-attachment-thumb {
    max-width: 200px;
    border-radius: 8px;
    margin-bottom: 6px;
    display: block;
}

.smartai-msg-time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 3px;
    padding: 0 4px;
}

.smartai-msg-user .smartai-msg-time {
    text-align: right;
}

/* Suggestion Chips */
.smartai-suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.smartai-chip-btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 11.5px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.smartai-chip-btn:hover {
    background: var(--smartai-primary-light);
    border-color: var(--smartai-primary);
    color: var(--smartai-primary);
}

/* Typing Indicator */
#smartai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
}

.smartai-typing-dots {
    background: #ffffff;
    padding: 8px 14px;
    border-radius: 16px;
    display: inline-flex;
    gap: 4px;
    border: 1px solid #e2e8f0;
}

.smartai-typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: smartai-wave 1.4s infinite ease-in-out;
}

.smartai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.smartai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes smartai-wave {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Image Preview Bar */
#smartai-image-preview-container {
    padding: 8px 14px;
    background: #f1f5f9;
    border-top: 1px solid #e2e8f0;
}

.smartai-preview-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
}

.smartai-preview-card img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
}

.smartai-preview-card span {
    font-size: 11px;
    color: #475569;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#smartai-remove-img {
    background: none;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
}

/* Footer / Input Bar */
.smartai-window-footer {
    padding: 10px 14px 8px 14px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

#smartai-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.smartai-btn-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.smartai-btn-icon:hover {
    background: #f1f5f9;
    color: var(--smartai-primary);
}

.smartai-input-wrap {
    flex: 1;
}

#smartai-text-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    font-size: 13.5px;
    color: #0f172a;
    outline: none;
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s;
}

#smartai-text-input:focus {
    border-color: var(--smartai-primary);
    background: #ffffff;
}

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

#smartai-send-btn:hover {
    opacity: 0.92;
    transform: scale(1.05);
}

.smartai-footer-powered {
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    margin-top: 6px;
}

.smartai-footer-powered span {
    font-weight: 600;
    color: #64748b;
}

/* Utility Hidden */
.smartai-hidden {
    display: none !important;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    #smartai-chat-window {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 9999999 !important;
    }
}
