/**
 * WowFix Chat Widget Styles
 * Modern, responsive chat interface
 */

:root {
    --wowfix-primary: #2563eb;
    --wowfix-accent: #f59e0b;
    --wowfix-text: #1f2937;
    --wowfix-text-light: #6b7280;
    --wowfix-bg: #ffffff;
    --wowfix-bg-secondary: #f9fafb;
    --wowfix-border: #e5e7eb;
    --wowfix-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --wowfix-radius: 12px;
    --wowfix-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Container */
.wowfix-chat-container {
    position: fixed;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--wowfix-text);
}

/* Position variations */
.wowfix-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.wowfix-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.wowfix-position-top-right {
    top: 20px;
    right: 20px;
}

.wowfix-position-top-left {
    top: 20px;
    left: 20px;
}

/* Chat bubble */
.wowfix-chat-bubble {
    width: 60px;
    height: 60px;
    background: var(--wowfix-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--wowfix-shadow);
    transition: var(--wowfix-transition);
    position: relative;
}

.wowfix-chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 25px 30px -5px rgba(0, 0, 0, 0.15), 0 15px 15px -5px rgba(0, 0, 0, 0.08);
}

.wowfix-chat-icon {
    width: 30px;
    height: 30px;
    color: white;
    transition: var(--wowfix-transition);
}

.wowfix-chat-open .wowfix-chat-icon {
    transform: rotate(90deg);
    opacity: 0;
}

/* Notification dot */
.wowfix-chat-notification {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    background: var(--wowfix-accent);
    border-radius: 50%;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: var(--wowfix-transition);
}

.wowfix-chat-notification-active {
    opacity: 1;
    transform: scale(1);
    animation: wowfix-pulse 2s infinite;
}

@keyframes wowfix-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
    }
}

/* Chat window */
.wowfix-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: var(--wowfix-bg);
    border-radius: var(--wowfix-radius);
    box-shadow: var(--wowfix-shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--wowfix-transition);
}

/* Position adjustments for window */
.wowfix-position-bottom-left .wowfix-chat-window {
    right: auto;
    left: 0;
}

.wowfix-position-top-right .wowfix-chat-window,
.wowfix-position-top-left .wowfix-chat-window {
    bottom: auto;
    top: 80px;
}

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

/* Header */
.wowfix-chat-header {
    padding: 20px;
    background: var(--wowfix-primary);
    color: white;
    border-radius: var(--wowfix-radius) var(--wowfix-radius) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wowfix-chat-header-content {
    flex: 1;
}

.wowfix-chat-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.wowfix-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    opacity: 0.9;
    margin: 0;
}

.wowfix-status-indicator {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    display: inline-block;
}

.wowfix-status-indicator.online {
    background: #10b981;
    animation: wowfix-blink 2s infinite;
}

@keyframes wowfix-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.wowfix-chat-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--wowfix-transition);
}

.wowfix-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.wowfix-chat-close svg {
    width: 16px;
    height: 16px;
    color: currentColor;
}

/* Messages area */
.wowfix-chat-messages {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background: var(--wowfix-bg-secondary);
}

.wowfix-chat-messages-container {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message styles */
.wowfix-chat-message {
    display: flex;
    gap: 8px;
    animation: wowfix-fadeIn 0.3s ease-out;
}

@keyframes wowfix-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wowfix-chat-message-user {
    flex-direction: row-reverse;
}

.wowfix-chat-message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.wowfix-chat-message-bot .wowfix-chat-message-content {
    background: var(--wowfix-bg);
    color: var(--wowfix-text);
    border: 1px solid var(--wowfix-border);
}

.wowfix-chat-message-user .wowfix-chat-message-content {
    background: var(--wowfix-primary);
    color: white;
}

.wowfix-chat-message-error .wowfix-chat-message-content {
    background: #fee;
    color: #dc2626;
    border-color: #fecaca;
}

.wowfix-chat-message-content a {
    color: inherit;
    text-decoration: underline;
}

.wowfix-chat-message-time {
    font-size: 11px;
    color: var(--wowfix-text-light);
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.wowfix-chat-message:hover .wowfix-chat-message-time {
    opacity: 1;
}

/* Typing indicator */
.wowfix-chat-typing {
    display: none;
    padding: 12px 16px;
    margin: 0 20px 20px;
    background: var(--wowfix-bg);
    border: 1px solid var(--wowfix-border);
    border-radius: 18px;
    width: fit-content;
}

.wowfix-chat-typing-active {
    display: flex;
    gap: 4px;
    align-items: center;
}

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

.wowfix-chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.wowfix-chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wowfix-typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* Quick actions */
.wowfix-chat-quick-actions {
    padding: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    border-top: 1px solid var(--wowfix-border);
    background: var(--wowfix-bg);
    min-height: 0;
}

.wowfix-quick-action {
    padding: 8px 16px;
    background: var(--wowfix-bg);
    border: 1px solid var(--wowfix-border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--wowfix-transition);
    white-space: nowrap;
}

.wowfix-quick-action:hover {
    background: var(--wowfix-bg-secondary);
    border-color: var(--wowfix-primary);
    color: var(--wowfix-primary);
}

.wowfix-quick-action-urgent {
    background: var(--wowfix-accent);
    color: white;
    border-color: var(--wowfix-accent);
    font-weight: 500;
}

.wowfix-quick-action-urgent:hover {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
}

/* Input form */
.wowfix-chat-input-form {
    padding: 16px;
    border-top: 1px solid var(--wowfix-border);
    background: var(--wowfix-bg);
    border-radius: 0 0 var(--wowfix-radius) var(--wowfix-radius);
}

.wowfix-chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.wowfix-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--wowfix-border);
    border-radius: 24px;
    font-size: 14px;
    background: var(--wowfix-bg-secondary);
    transition: var(--wowfix-transition);
    outline: none;
}

.wowfix-chat-input:focus {
    border-color: var(--wowfix-primary);
    background: var(--wowfix-bg);
}

.wowfix-chat-send {
    width: 40px;
    height: 40px;
    background: var(--wowfix-primary);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--wowfix-transition);
}

.wowfix-chat-send:hover {
    background: var(--wowfix-primary);
    transform: scale(1.05);
}

.wowfix-chat-send:active {
    transform: scale(0.95);
}

.wowfix-chat-send svg {
    width: 18px;
    height: 18px;
}

/* Lead form */
.wowfix-chat-lead-form {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--wowfix-bg);
    border-radius: var(--wowfix-radius);
    padding: 24px;
    display: none;
    flex-direction: column;
    z-index: 10;
}

.wowfix-chat-lead-form-active {
    display: flex;
}

.wowfix-chat-lead-form h4 {
    margin: 0 0 20px;
    font-size: 18px;
    font-weight: 600;
    color: var(--wowfix-text);
}

.wowfix-lead-form {
    flex: 1;
    overflow-y: auto;
}

.wowfix-form-group {
    margin-bottom: 16px;
}

.wowfix-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--wowfix-text);
}

.wowfix-form-group input,
.wowfix-form-group select,
.wowfix-form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--wowfix-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--wowfix-bg);
    transition: var(--wowfix-transition);
    outline: none;
}

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

.wowfix-form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.wowfix-form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.wowfix-btn-primary,
.wowfix-btn-secondary {
    flex: 1;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--wowfix-transition);
    border: none;
    outline: none;
}

.wowfix-btn-primary {
    background: var(--wowfix-primary);
    color: white;
}

.wowfix-btn-primary:hover {
    background: #1d4ed8;
}

.wowfix-btn-secondary {
    background: var(--wowfix-bg);
    color: var(--wowfix-text);
    border: 1px solid var(--wowfix-border);
}

.wowfix-btn-secondary:hover {
    background: var(--wowfix-bg-secondary);
}

/* Mobile styles */
@media (max-width: 768px) {
    /* Chat container positioning */
    .wowfix-chat-container {
        bottom: 10px !important;
        right: 10px !important;
        left: auto !important;
        top: auto !important;
    }
    
    /* Full screen chat window when open */
    .wowfix-chat-open .wowfix-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    /* Ensure close button is always visible on mobile */
    .wowfix-chat-close {
        display: flex !important;
        position: absolute !important;
        top: 10px !important;
        right: 10px !important;
        width: 44px !important;
        height: 44px !important;
        background: rgba(255, 255, 255, 0.9) !important;
        border: 2px solid rgba(0, 0, 0, 0.1) !important;
        z-index: 9999 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    }
    
    .wowfix-chat-close:hover {
        background: rgba(255, 255, 255, 1) !important;
    }
    
    .wowfix-chat-close svg {
        width: 20px !important;
        height: 20px !important;
        color: #000 !important;
    }
    
    /* Add safe area padding for notched devices */
    .wowfix-chat-header {
        padding-top: env(safe-area-inset-top, 20px);
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    /* Adjust messages area for safe areas */
    .wowfix-chat-messages {
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    /* Ensure input form has safe area padding */
    .wowfix-chat-input-form {
        padding-bottom: env(safe-area-inset-bottom, 16px);
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    /* Keep bubble in corner */
    .wowfix-chat-bubble {
        width: 56px;
        height: 56px;
        position: fixed;
        bottom: 10px;
        right: 10px;
    }
    
    /* Message optimizations for mobile */
    .wowfix-chat-message-content {
        max-width: 80%;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Input optimizations */
    .wowfix-chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Quick actions adjustments */
    .wowfix-quick-action {
        font-size: 14px;
        padding: 10px 16px;
    }
    
    /* Lead form adjustments */
    .wowfix-chat-lead-form {
        padding: 20px;
        padding-top: calc(20px + env(safe-area-inset-top));
    }
    
    .wowfix-form-group input,
    .wowfix-form-group select,
    .wowfix-form-group textarea {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Landscape mode optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    .wowfix-chat-messages {
        max-height: calc(100vh - 140px);
    }
    
    .wowfix-chat-header {
        padding: 15px 20px;
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .wowfix-chat-title {
        font-size: 16px;
    }
    
    .wowfix-chat-status {
        font-size: 12px;
    }
}

/* Very small screens */
@media (max-width: 350px) {
    .wowfix-chat-bubble {
        width: 50px;
        height: 50px;
    }
    
    .wowfix-chat-icon {
        width: 26px;
        height: 26px;
    }
    
    .wowfix-quick-action {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Prevent rubber band scrolling on chat window */
    .wowfix-chat-open .wowfix-chat-window {
        position: fixed;
        overflow: hidden;
    }
    
    .wowfix-chat-messages {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --wowfix-bg: #1f2937;
        --wowfix-bg-secondary: #111827;
        --wowfix-text: #f9fafb;
        --wowfix-text-light: #9ca3af;
        --wowfix-border: #374151;
    }
    
    .wowfix-chat-message-bot .wowfix-chat-message-content {
        background: #374151;
        border-color: #4b5563;
    }
}

/* Scrollbar styling */
.wowfix-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.wowfix-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.wowfix-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.wowfix-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Print styles */
@media print {
    .wowfix-chat-container {
        display: none !important;
    }
}
