/**
 * CuraFile AI Chat Widget Styles
 * 
 * Modern, accessible, mobile-responsive chat interface.
 * Colors are overridden by admin settings via CSS variables.
 */

/* ─── CSS Variables (defaults, overridden by JS) ─────────────── */
:root {
    --curafile-primary: #0066CC;
    --curafile-secondary: #004499;
    --curafile-bg: #ffffff;
    --curafile-text: #1a1a2e;
    --curafile-text-light: #6b7280;
    --curafile-border: #e5e7eb;
    --curafile-bot-bg: #f0f4f8;
    --curafile-user-bg: var(--curafile-primary);
    --curafile-radius: 16px;
    --curafile-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ─── Chat Toggle Button ─────────────────────────────────────── */
.curafile-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--curafile-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 102, 204, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999998;
}

.curafile-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 102, 204, 0.5);
}

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

.curafile-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 Window ────────────────────────────────────────────── */
.curafile-chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 400px;
    max-height: 600px;
    height: 80vh;
    background: var(--curafile-bg);
    border-radius: var(--curafile-radius);
    box-shadow: var(--curafile-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
    animation: curafile-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--curafile-border);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

@keyframes curafile-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ─── Header ─────────────────────────────────────────────────── */
.curafile-chat-header {
    background: linear-gradient(135deg, var(--curafile-primary), var(--curafile-secondary));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

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

.curafile-chat-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

.curafile-chat-subtitle {
    font-size: 12px;
    opacity: 0.85;
}

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

.curafile-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

/* ─── Messages Area ──────────────────────────────────────────── */
.curafile-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

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

.curafile-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

/* ─── Message Bubbles ────────────────────────────────────────── */
.curafile-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: curafile-msg-in 0.25s ease-out;
}

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

.curafile-message-bot {
    background: var(--curafile-bot-bg);
    color: var(--curafile-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.curafile-message-user {
    background: var(--curafile-user-bg);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.curafile-message-bot p {
    margin: 0 0 8px;
}

.curafile-message-bot p:last-child {
    margin-bottom: 0;
}

.curafile-message-bot em {
    font-size: 12px;
    color: var(--curafile-text-light);
}

/* Source links */
.curafile-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--curafile-border);
}

.curafile-sources-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--curafile-text-light);
    margin-bottom: 6px;
}

.curafile-source-link {
    display: block;
    font-size: 12px;
    color: var(--curafile-primary);
    text-decoration: none;
    padding: 3px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.curafile-source-link:hover {
    text-decoration: underline;
}

/* Disclaimer */
.curafile-disclaimer {
    font-size: 11px;
    color: var(--curafile-text-light);
    background: #fef9e7;
    border: 1px solid #fde68a;
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 8px;
}

/* ─── Registration Form ──────────────────────────────────────── */
.curafile-registration-form {
    padding: 20px 18px;
    border-top: 1px solid var(--curafile-border);
    background: #fafbfc;
}

.curafile-reg-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--curafile-text);
    margin-bottom: 4px;
}

.curafile-reg-desc {
    font-size: 12px;
    color: var(--curafile-text-light);
    margin-bottom: 14px;
}

.curafile-form-group {
    margin-bottom: 12px;
}

.curafile-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--curafile-text);
    margin-bottom: 4px;
}

.curafile-form-group label .required {
    color: #ef4444;
}

.curafile-form-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--curafile-border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--curafile-text);
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.curafile-form-input:focus {
    border-color: var(--curafile-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.curafile-form-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--curafile-border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--curafile-text);
    background: #fff;
    outline: none;
    box-sizing: border-box;
}

.curafile-consent-group {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 14px 0;
}

.curafile-consent-group input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
}

.curafile-consent-group label {
    font-size: 12px;
    color: var(--curafile-text-light);
    line-height: 1.4;
}

.curafile-privacy-link {
    color: var(--curafile-primary);
    text-decoration: underline;
    cursor: pointer;
    font-size: 12px;
}

.curafile-reg-submit {
    width: 100%;
    padding: 10px;
    background: var(--curafile-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.curafile-reg-submit:hover {
    background: var(--curafile-secondary);
}

.curafile-reg-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.curafile-reg-error {
    color: #ef4444;
    font-size: 12px;
    margin-top: 6px;
    display: none;
}

/* ─── Chat Input ─────────────────────────────────────────────── */
.curafile-chat-input-area {
    border-top: 1px solid var(--curafile-border);
    background: #fff;
    flex-shrink: 0;
}

.curafile-chat-form {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    gap: 8px;
}

.curafile-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--curafile-border);
    border-radius: 24px;
    font-size: 14px;
    color: var(--curafile-text);
    outline: none;
    transition: border-color 0.2s;
    background: #f9fafb;
}

.curafile-chat-input:focus {
    border-color: var(--curafile-primary);
    background: #fff;
}

.curafile-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--curafile-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.curafile-chat-send:hover {
    background: var(--curafile-secondary);
}

/* ─── Typing Indicator ───────────────────────────────────────── */
.curafile-typing-indicator {
    padding: 8px 18px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.curafile-typing-indicator span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: curafile-bounce 1.4s infinite ease-in-out both;
}

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

@keyframes curafile-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ─── Mobile Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
    .curafile-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        max-height: none;
        bottom: 80px;
        right: 8px;
        left: 8px;
        border-radius: 12px;
    }

    .curafile-chat-window.bottom-left {
        left: 8px;
        right: 8px;
    }

    .curafile-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .curafile-chat-toggle.bottom-left {
        right: auto;
        left: 16px;
    }
}

/* ─── Privacy Modal ──────────────────────────────────────────── */
.curafile-privacy-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 20px;
}

.curafile-privacy-content {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 340px;
    max-height: 80%;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
    color: var(--curafile-text);
}

.curafile-privacy-content h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.curafile-privacy-close {
    margin-top: 16px;
    padding: 8px 20px;
    background: var(--curafile-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

/* ─── Confirm Dialog ─────────────────────────────────────────── */
.curafile-confirm-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 20px;
}

.curafile-confirm-box {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    max-width: 300px;
}

.curafile-confirm-box p {
    margin: 0 0 16px;
    font-size: 14px;
    color: var(--curafile-text);
}

.curafile-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.curafile-confirm-actions button {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    cursor: pointer;
}

.curafile-confirm-yes {
    background: #ef4444;
    color: #fff;
}

.curafile-confirm-no {
    background: #e5e7eb;
    color: var(--curafile-text);
}
