/**
 * Chat Widget Styles
 * Floating chat button + slide-up chat panel
 * Matches existing floating-stack glassmorphism pattern
 */

/* ============================================================================
   CSS VARIABLES
   ============================================================================ */
:root {
    --chat-primary: #304e96;
    --chat-primary-hover: #395ba9;
    --chat-accent: #7fd1de;
    --chat-bg: #ffffff;
    --chat-panel-bg: #f8f9fa;
    --chat-header-bg: #18274b;
    --chat-header-text: #ffffff;
    --chat-user-msg-bg: #304e96;
    --chat-user-msg-text: #ffffff;
    --chat-assistant-msg-bg: #e9ecef;
    --chat-assistant-msg-text: #212529;
    --chat-system-msg-bg: #fff3cd;
    --chat-system-msg-text: #856404;
    --chat-admin-msg-bg: #d4edda;
    --chat-admin-msg-text: #155724;
    --chat-input-bg: #ffffff;
    --chat-input-border: #ced4da;
    --chat-input-text: #212529;
    --chat-border: #dee2e6;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --chat-radius: 16px;
    --chat-source-bg: #f0f4ff;
    --chat-source-border: #c5d3f0;
    --chat-source-text: #304e96;
}

[data-theme="dark"] {
    --chat-bg: #1a1a2e;
    --chat-panel-bg: #16162a;
    --chat-header-bg: #0d0d1a;
    --chat-header-text: #e0e0e0;
    --chat-user-msg-bg: #2a3f7a;
    --chat-user-msg-text: #e0e0e0;
    --chat-assistant-msg-bg: #2a2a40;
    --chat-assistant-msg-text: #e0e0e0;
    --chat-system-msg-bg: #3d3520;
    --chat-system-msg-text: #ffc107;
    --chat-admin-msg-bg: #1e3a2a;
    --chat-admin-msg-text: #8fd4a8;
    --chat-input-bg: #1e1e30;
    --chat-input-border: #3a3a50;
    --chat-input-text: #e0e0e0;
    --chat-border: #2a2a40;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --chat-source-bg: #1e2540;
    --chat-source-border: #2a3f6a;
    --chat-source-text: #7fd1de;
}

/* ============================================================================
   FLOATING CHAT BUTTON (in stack)
   ============================================================================ */
.chat-widget-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(48, 78, 150, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #ffffff;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), inset 0 1px 1px rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 1;
}

.chat-widget-btn:hover {
    background: rgba(57, 91, 169, 0.95);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25), inset 0 1px 1px rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.chat-widget-btn:active {
    transform: scale(0.95);
}

.chat-widget-btn.active {
    background: rgba(127, 209, 222, 0.9);
    color: #18274b;
}

/* Unread badge */
.chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.chat-widget-badge.visible {
    display: flex;
}

[data-theme="dark"] .chat-widget-btn {
    background: rgba(30, 40, 70, 0.85);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-widget-btn:hover {
    background: rgba(42, 63, 122, 0.95);
}

/* Stack positioning */
.floating-stack .chat-widget-btn {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 1;
}

/* ============================================================================
   CHAT PANEL (floating)
   ============================================================================ */
.chat-panel {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 380px;
    height: 650px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    border: 1px solid var(--chat-border);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9001;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-panel.open {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ============================================================================
   CHAT HEADER
   ============================================================================ */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--chat-header-bg);
    color: var(--chat-header-text);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header-title {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-title i {
    color: var(--chat-accent);
}

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

.chat-header-btn {
    background: none;
    border: none;
    color: var(--chat-header-text);
    font-size: 1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s ease;
    opacity: 0.7;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    opacity: 1;
}

/* ============================================================================
   CHAT MESSAGES AREA
   ============================================================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--chat-panel-bg);
    scroll-behavior: smooth;
}

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

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

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

[data-theme="dark"] .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: chatMsgIn 0.2s ease;
}

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

.chat-msg-user {
    align-self: flex-end;
    background: var(--chat-user-msg-bg);
    color: var(--chat-user-msg-text);
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
    align-self: flex-start;
    background: var(--chat-assistant-msg-bg);
    color: var(--chat-assistant-msg-text);
    border-bottom-left-radius: 4px;
}

.chat-msg-system {
    align-self: center;
    background: var(--chat-system-msg-bg);
    color: var(--chat-system-msg-text);
    font-size: 0.8rem;
    text-align: center;
    max-width: 90%;
    border-radius: 8px;
}

.chat-msg-admin {
    align-self: flex-start;
    background: var(--chat-admin-msg-bg);
    color: var(--chat-admin-msg-text);
    border-bottom-left-radius: 4px;
}

.chat-msg-admin::before {
    content: 'Brandan: ';
    font-weight: 600;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--chat-assistant-msg-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: none;
}

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

.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-assistant-msg-text);
    opacity: 0.4;
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTypingBounce {
    0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* ============================================================================
   SOURCE CARDS
   ============================================================================ */
.chat-sources {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    align-self: flex-start;
    max-width: 85%;
}

.chat-source-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--chat-source-bg);
    border: 1px solid var(--chat-source-border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--chat-source-text);
    font-size: 0.8rem;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-source-card:hover {
    background: var(--chat-primary);
    color: #fff;
    border-color: var(--chat-primary);
}

.chat-source-card i {
    font-size: 0.9rem;
    flex-shrink: 0;
}

.chat-source-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-source-meta {
    font-size: 0.7rem;
    opacity: 0.7;
    white-space: nowrap;
}

/* ============================================================================
   CHAT INPUT AREA
   ============================================================================ */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--chat-input-border);
    border-radius: 20px;
    background: var(--chat-input-bg);
    color: var(--chat-input-text);
    font-size: 16px; /* Must be 16px+ to prevent iOS zoom on focus */
    outline: none;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
}

.chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 2px rgba(48, 78, 150, 0.15);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--chat-primary-hover);
}

.chat-send-btn:active {
    transform: scale(0.9);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================================
   CHAT FOOTER / ACTIONS BAR
   ============================================================================ */
.chat-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
    flex-shrink: 0;
    font-size: 0.75rem;
}

.chat-talk-btn {
    background: none;
    border: 1px solid var(--chat-primary);
    color: var(--chat-primary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.chat-talk-btn:hover {
    background: var(--chat-primary);
    color: #fff;
}

.chat-rate-info {
    color: var(--chat-assistant-msg-text);
    opacity: 0.6;
}

/* ============================================================================
   WELCOME MESSAGE
   ============================================================================ */
.chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--chat-assistant-msg-text);
}

.chat-welcome-icon {
    font-size: 2.5rem;
    color: var(--chat-primary);
    margin-bottom: 12px;
}

.chat-welcome h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.chat-welcome p {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-bottom: 16px;
    line-height: 1.5;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-suggestion-btn {
    background: var(--chat-source-bg);
    border: 1px solid var(--chat-source-border);
    color: var(--chat-source-text);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    text-align: left;
}

.chat-suggestion-btn:hover {
    background: var(--chat-primary);
    color: #fff;
    border-color: var(--chat-primary);
}

/* ============================================================================
   LIVE CHAT CONTACT FORM (inline)
   ============================================================================ */
.chat-contact-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-contact-form label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--chat-assistant-msg-text);
}

.chat-contact-form input {
    padding: 8px 12px;
    border: 1px solid var(--chat-input-border);
    border-radius: 8px;
    background: var(--chat-input-bg);
    color: var(--chat-input-text);
    font-size: 16px; /* Must be 16px+ to prevent iOS zoom on focus */
    outline: none;
}

.chat-contact-form input:focus {
    border-color: var(--chat-primary);
}

.chat-contact-submit {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-contact-submit:hover {
    background: var(--chat-primary-hover);
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */
@media (max-width: 576px) {
    .chat-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-panel.open {
        transform: translateY(0) scale(1);
    }
}

@media (min-width: 577px) and (max-width: 768px) {
    .chat-panel {
        width: 340px;
        height: 480px;
    }
}

/* Landscape compact */
@media (orientation: landscape) and (max-height: 500px) {
    .chat-widget-btn {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
    }

    .chat-panel {
        height: calc(100vh - 20px);
        bottom: 10px;
    }
}

/* ============================================================================
   FULL PAGE CHAT (chat.php)
   ============================================================================ */
.chat-fullpage {
    max-width: 800px;
    margin: 0 auto;
    height: calc(100vh - 200px);
    min-height: 500px;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    overflow: hidden;
    box-shadow: var(--chat-shadow);
}

.chat-fullpage .chat-messages {
    flex: 1;
}

.chat-fullpage .chat-msg {
    max-width: 70%;
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .chat-panel,
    .chat-msg,
    .chat-widget-btn,
    .chat-typing-dot {
        animation: none;
        transition: none;
    }

    .chat-panel.open {
        transform: none;
    }
}

/* ============================================================================
   PRINT - Hide chat widget
   ============================================================================ */
@media print {
    .chat-widget-btn,
    .chat-panel,
    .chat-widget-badge {
        display: none !important;
    }
}
