/* ============================================
    DIGIBOT / AI CHAT WIDGET - STYLES (Production)
    Version: 1.0.0
    Author: Achraf S. (adapted)
    License: This code is licensed for distribution with the Envato package.  
============================================ */

:root {
    --chat-primary-start: #667eea;
    --chat-primary-end: #764ba2;
    --chat-bg: #ffffff;
    --chat-secondary-bg: #f8f9fa;
    --chat-text: #2d3748;
    --chat-text-light: #a0aec0;
    --chat-border: #e2e8f0;
    --chat-shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="purple"] {
    --chat-primary-start: #667eea;
    --chat-primary-end: #764ba2;
}
[data-theme="blue"] {
    --chat-primary-start: #4facfe;
    --chat-primary-end: #00f2fe;
}
[data-theme="green"] {
    --chat-primary-start: #11998e;
    --chat-primary-end: #38ef7d;
}
[data-theme="orange"] {
    --chat-primary-start: #fa709a;
    --chat-primary-end: #fee140;
}
[data-theme="pink"] {
    --chat-primary-start: #f093fb;
    --chat-primary-end: #f5576c;
}
.dark-mode {
    --chat-bg: #1a202c;
    --chat-secondary-bg: #2d3748;
    --chat-text: #e2e8f0;
    --chat-text-light: #8a9fba;
    --chat-border: #4a5568;
    --chat-shadow: rgba(0, 0, 0, 0.3);
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
   CHAT WIDGET STYLES
   ============================================ */

.chat-bubble-btn,
.chat-widget,
.chat-settings,
.chat-widget *,
.chat-settings * {
    box-sizing: border-box;
}

/* Floating Button */
.chat-bubble-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999999;
}

.chat-bubble-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.chat-bubble-icon,
.chat-close-icon {
    width: 28px;
    height: 28px;
    color: white;
    transition: all 0.3s ease;
}

.chat-bubble-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
    font-size: large;
}

.chat-close-icon {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0);
    font-size: x-large;
}

.chat-bubble-btn.active .chat-bubble-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0);
}

.chat-bubble-btn.active .chat-close-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.unread-badge.active {
    display: flex;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.chat-bubble-btn.bottom-left {
    left: 24px;
    right: auto;
}

/* Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 650px;
    max-height: calc(100vh - 140px);
    background: var(--chat-bg);
    border-radius: 16px;
    /* Premium layered shadow */
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 20px 25px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999998;
    padding-bottom: env(safe-area-inset-bottom);
    /* Ensure consistent, clean font rendering */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.chat-widget.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-widget.bottom-left {
    left: 24px;
    right: auto;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    /* Glassmorphism effect (subtle) */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-text h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

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

.status-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.header-action-btn,
.chat-close-btn {
    width: 2rem;
    height: 2rem;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

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

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-secondary-bg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

.message {
    display: flex;
    gap: 10px;
    animation: messageSlideIn 0.3s ease;
}

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

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

.message-avatar {
    width: 2rem;
    height: 2rem;
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--chat-border);
}

.user-message .message-avatar svg {
    color: var(--chat-text);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 75%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    color: var(--chat-text);
}

.bot-message .message-bubble {
    background: var(--chat-bg);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px var(--chat-shadow);
}

.user-message .message-bubble {
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble code {
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.message-time {
    font-size: 11px;
    color: var(--chat-text-light);
    padding: 0 4px;
}

.user-message .message-time {
    text-align: right;
}

.quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.quick-action-btn {
    padding: 6px 12px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--chat-text);
}

.dark-mode .quick-action-btn {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.3);
}

.quick-action-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: translateY(-1px);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

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

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

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

/* Input Area */
.chat-input-container {
    padding: 10px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    gap: 6px;
    align-items: center;
}


.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
    background: var(--chat-bg);
    color: var(--chat-text);
}

.chat-input:focus {
    border-color: var(--chat-primary-start);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-send-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}
/* Settings Panel */
.chat-settings {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 400px;
    max-width: calc(100vw - 40px);
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: 0 20px 60px var(--chat-shadow);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000000;
}

.chat-settings.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.settings-header {
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.settings-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 8px;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.settings-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.settings-group select {
    padding: 10px;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--chat-bg);
    color: var(--chat-text);
    cursor: pointer;
}

.theme-selector {
    display: flex;
    gap: 12px;
}

.theme-btn {
    width: 50px;
    height: 50px;
    border: 3px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.dark-mode .chat-messages::-webkit-scrollbar-thumb {
    background: #555;
}

.theme-btn.active {
    border-color: var(--chat-text);
}

.settings-btn {
    padding: 12px;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary-start) 0%, var(--chat-primary-end) 100%);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.settings-btn:hover {
    transform: translateY(-2px);
}

.settings-btn.danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

/* reduced-motion support  */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Responsive */
@media (max-width: 590px) {
    .container { padding: 15px; }
    .demo-header { padding: 20px; }
    .demo-header h1 { font-size: 1.5em; }
    .chat-widget { 
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    .chat-send-btn {
        width: 2.5rem; /* Restore size so it's clickable */
        height: 2.5rem;
    }
    .chat-input-container {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom)); /* Handle iPhone home bar */
    }
    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}