/* ========================================
   CHAT POPUP STYLES
   Award-Winning Professional Design
   ======================================== */

/* Premium Font Stack */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Chat Toggle Button */
.chat-toggle-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #003366;
    color: var(--white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 20px rgba(0, 51, 102, 0.3);
    transition: all 0.3s ease;
    z-index: 999;
}

.chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 51, 102, 0.4);
    background: #004080;
}

.chat-toggle-btn.active {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Chat Container */
.chat-container {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 420px;
    height: 650px;
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 998;
    overflow: hidden;
}

.chat-container.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

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

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

.chat-status-dot {
    width: 8px;
    height: 8px;
    background: #27ae60;
    border-radius: 50%;
}

.chat-header-title h3 {
    margin: 0;
    font-size: 17px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    font-weight: 600;
    color: var(--white);
    letter-spacing: 0.01em;
}

.chat-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
    font-weight: 400;
    letter-spacing: 0.01em;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

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

.chat-header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--white);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 16px;
}

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

/* Model Selector - Hidden but keeping CSS for potential future use */
.model-selector {
    display: none;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, #f8f9fa 0%, #f1f3f5 100%);
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.18);
    background-clip: padding-box;
}

/* Message Bubbles */
.message {
    margin-bottom: 16px;
    animation: messageSlideIn 0.25s ease-out;
}

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

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message.assistant {
    display: flex;
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 13px 17px;
    border-radius: 14px;
    word-wrap: break-word;
    position: relative;
    line-height: 1.6;
    font-weight: 400;
    letter-spacing: 0.01em;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

.message.user .message-bubble {
    background: #003366;
    color: var(--white);
    border-bottom-right-radius: 4px;
    box-shadow:
        0 2px 8px rgba(0, 51, 102, 0.12),
        0 1px 3px rgba(0, 51, 102, 0.08);
}

.message.assistant .message-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e8ecef;
    border-bottom-left-radius: 4px;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.02);
}

.message-content {
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.5;
}

.message-content br {
    line-height: 1.3;
    display: block;
    content: "";
    margin: 0.2em 0;
}

/* Markdown formatting */
.message-content h1,
.message-content h2,
.message-content h3 {
    font-weight: 600;
    margin: 6px 0 4px 0;
    line-height: 1.3;
}

.message-content h1 {
    font-size: 18px;
}

.message-content h2 {
    font-size: 16px;
}

.message-content h3 {
    font-size: 15px;
}

.message-content strong {
    font-weight: 600;
    color: inherit;
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message.user .message-content pre {
    background: rgba(255, 255, 255, 0.15);
}

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

.message-content ul,
.message-content ol {
    margin: 4px 0;
    padding-left: 24px;
}

.message-content ul {
    list-style-type: disc;
}

.message-content ol {
    list-style-type: decimal;
}

.message-content li {
    margin: 1px 0;
    line-height: 1.4;
    padding-left: 4px;
}

.message-content a {
    color: #FF6600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.message.user .message-content a {
    color: #FFD700;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
    display: block;
}

.message.user .message-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.9);
}

.message.assistant .message-time {
    text-align: left;
    color: var(--light-text);
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 13px 17px;
    background: #ffffff;
    border: 1px solid #e8ecef;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    margin-bottom: 16px;
    margin-left: 20px;
    max-width: 70px;
    width: fit-content;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.02);
}

.typing-indicator.show {
    display: flex;
    animation: messageSlideIn 0.25s ease-out;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingFade 1.4s infinite ease-in-out both;
}

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

@keyframes typingFade {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Chat Input Area */
.chat-input-wrapper {
    padding: 16px 20px 20px 20px;
    background: var(--white);
    border-top: 1px solid #e1e8ed;
    border-radius: 0 0 16px 16px;
}

.chat-input-form {
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid #e1e8ed;
    border-radius: 10px;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    resize: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.5;
    color: #1e293b;
    background: #ffffff;
}

.chat-input::placeholder {
    color: #94a3b8;
}

.chat-input:focus {
    outline: none;
    border-color: #003366;
    box-shadow:
        0 0 0 3px rgba(0, 51, 102, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.04);
}

.chat-send-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, #FF6600 0%, #ff7a1f 100%);
    color: var(--white);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(255, 102, 0, 0.15);
}

.chat-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #ff7a1f 0%, #FF8C3D 100%);
    box-shadow: 0 4px 12px rgba(255, 102, 0, 0.25);
    transform: translateY(-1px);
}

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

/* Loading State */
.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--white);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Message */
.error-message-bubble {
    background: #fee;
    border: 1px solid #fcc;
    color: var(--error-color);
}

.retry-btn {
    margin-top: 8px;
    padding: 4px 12px;
    background: var(--error-color);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.retry-btn:hover {
    background: #d73444;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 60px 40px;
    color: #64748b;
}

.welcome-message h4 {
    color: #003366;
    margin-bottom: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.welcome-message p {
    margin-bottom: 32px;
    font-size: 15px;
    line-height: 1.6;
    color: #475569;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.quick-action-btn {
    padding: 11px 20px;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    letter-spacing: 0.01em;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.quick-action-btn:hover {
    border-color: #003366;
    color: #003366;
    background: #f8f9fa;
}

/* Responsive Design */
@media (max-width: 600px) {
    .chat-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* For mobile browsers with dynamic viewport */
        right: 0;
        bottom: 0;
        border-radius: 0;
        max-height: -webkit-fill-available;
    }

    .chat-header {
        padding: 16px 20px;
        border-radius: 0;
    }

    .chat-toggle-btn {
        right: 20px;
        bottom: 20px;
        width: 56px;
        height: 56px;
        font-size: 24px;
    }

    .chat-messages {
        padding: 20px;
    }

    .message-bubble {
        max-width: 85%;
        font-size: 15px;
        padding: 12px 15px;
    }

    .chat-input-wrapper {
        padding: 12px 16px 16px;
        border-radius: 0;
    }

    .chat-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 14px;
    }

    .chat-send-btn {
        min-width: 60px;
        min-height: 44px;
        padding: 12px 18px;
    }

    .welcome-message {
        padding: 40px 24px;
    }

    .welcome-message h4 {
        font-size: 18px;
    }

    .welcome-message p {
        font-size: 14px;
        max-width: 280px;
    }

    .quick-action-btn {
        padding: 12px 18px;
        font-size: 14px;
        min-height: 44px;
    }

    .typing-indicator {
        padding: 12px 16px;
        margin-left: 20px;
    }
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
    @media (max-width: 600px) {
        .chat-input-wrapper {
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }

        .chat-container {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* Touch Optimizations */
.quick-action-btn,
.chat-send-btn,
.chat-header-btn,
.chat-toggle-btn {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Tablet Optimizations */
@media (min-width: 601px) and (max-width: 1024px) {
    .chat-container {
        width: 400px;
        height: 600px;
    }
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    .chat-container {
        background: #1a1a1a;
    }
    
    .chat-messages {
        background: linear-gradient(180deg, #1a1a1a 0%, #2a2a2a 100%);
    }
    
    .message.assistant .message-bubble {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #3a3a3a;
    }
    
    .chat-input-wrapper {
        background: #1a1a1a;
    }
    
    .chat-input {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #3a3a3a;
    }
    
    .model-selector {
        background: #2a2a2a;
    }
    
    .model-selector select {
        background: #1a1a1a;
        color: #e0e0e0;
        border-color: #3a3a3a;
    }
}
