/**
 * CardChat CSS Styles
 * ChatGPT-style chat interface
 */

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f7f7f8;
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden; /* Prevent body scroll */
}

/* Account for fixed navbar */
body {
    padding-top: 56px; /* Bootstrap navbar height */
}

/* Ensure main container accounts for navbar */
.container-fluid {
    margin-top: 0;
    padding-top: 0;
}

/* Chat Messages Container */
#chatMessages {
    background-color: #ffffff;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    height: 0; /* Force flexbox to calculate height correctly */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth;
    position: relative; /* Ensure proper positioning */
}

/* Message Styles */
.message {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-in;
}

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

.user-message {
    align-items: flex-end;
}

.assistant-message {
    align-items: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
}

.user-message .message-content {
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-message .message-content {
    background-color: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    padding: 12px 16px;
    background-color: #f0f0f0;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: #999;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    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);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Welcome Message */
.welcome-message {
    color: #666;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-message h5 {
    color: #333;
    margin-bottom: 16px;
}

.welcome-message ul {
    text-align: left;
}

.welcome-message li {
    padding: 8px 0;
    color: #555;
}

/* Chat Input Area */
#chatForm {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e5e5e5;
    padding: 16px;
    z-index: 100;
    display: flex;
    gap: 8px; /* Better spacing between input and button */
}

#messageInput {
    border-radius: 24px;
    border: 1px solid #d1d5db;
    padding: 12px 20px;
    font-size: 16px;
    resize: none;
    flex: 1 1 auto;
    min-width: 0; /* Allow flexbox to shrink below content size */
}

#messageInput:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

#sendButton {
    border-radius: 24px;
    padding: 12px 24px;
    font-weight: 500;
    min-width: 100px;
    flex-shrink: 0; /* Prevent button from shrinking */
}

/* Mobile-specific button styling */
@media (max-width: 576px) {
    #sendButton {
        min-width: 60px;
        padding: 12px 16px;
    }
}

/* Sidebar */
#cardInfoSidebar {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Function Call Indicator */
.function-call {
    background-color: #fff3cd;
    border-left: 3px solid #ffc107;
    padding: 8px 12px;
    margin: 8px 0;
    border-radius: 4px;
    font-size: 0.9em;
    color: #856404;
}

/* Error Messages */
.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .message-content {
        max-width: 90%;
    }
    
    #cardInfoSidebar {
        display: none;
    }
    
    .col-md-9 {
        width: 100% !important;
    }
    
    /* Ensure chat container can scroll on mobile */
    #chatMessages {
        padding: 15px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Better spacing for input form on mobile */
    #chatForm {
        padding: 12px;
    }
    
    #messageInput {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 10px 16px;
    }
    
    /* Ensure body padding accounts for navbar on mobile */
    body {
        padding-top: 56px;
    }
    
    /* Mobile card info header styling */
    .mobile-card-header {
        background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
        border-bottom: 1px solid #e9ecef;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        padding: 12px 16px;
    }
    
    .mobile-header-content {
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .mobile-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background-color: #f8f9fa;
        color: #495057;
        text-decoration: none;
        transition: all 0.2s ease;
        flex-shrink: 0;
        border: 1px solid #e9ecef;
    }
    
    .mobile-back-btn:hover {
        background-color: #e9ecef;
        color: #212529;
        text-decoration: none;
        transform: translateX(-2px);
    }
    
    .mobile-back-btn:active {
        transform: translateX(-2px) scale(0.95);
    }
    
    .mobile-card-image-wrapper {
        flex-shrink: 0;
        width: 50px;
        height: 32px;
        border-radius: 6px;
        overflow: hidden;
        box-shadow: 0 2px 6px rgba(0,0,0,0.15);
        background: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-card-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 6px;
    }
    
    .mobile-card-info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .mobile-card-name {
        font-size: 14px;
        font-weight: 600;
        color: #212529;
        line-height: 1.3;
        margin-bottom: 2px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
    }
    
    .mobile-card-bank {
        font-size: 12px;
        color: #5a4d45;
        font-weight: 500;
        line-height: 1.35;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        white-space: normal;
    }
}

/* Suggestion chips — reset ALL browser button defaults explicitly */
.suggestion-chip {
    display: inline-block;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background: #fff !important;
    border: 1px solid #fcebe3 !important;
    color: #eb5d1e !important;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    margin: 3px 3px 3px 0;
    text-align: left;
    line-height: 1.4;
    white-space: normal;
    word-break: break-word;
    transition: background 0.15s, border-color 0.15s;
    box-shadow: none !important;
    outline: none !important;
}
.suggestion-chip:hover {
    background: #fef8f5 !important;
    border-color: #eb5d1e !important;
    color: #eb5d1e !important;
}
.suggestion-chip:focus {
    box-shadow: none !important;
    outline: none !important;
    border-color: #eb5d1e !important;
}
.suggestion-chip:active {
    background: #fcebe3 !important;
}

/* Left panel tab switcher */
.panel-tab-link {
    display: block;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #a08f86;
    padding: 8px 4px;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
}
.panel-tab-link:hover {
    color: #4e4039;
    text-decoration: none;
}
.panel-tab-link.active {
    color: #4e4039;
    border-bottom-color: #eb5d1e;
}

/* Scrollbar Styling */
#chatMessages::-webkit-scrollbar {
    width: 8px;
}

#chatMessages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#chatMessages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#chatMessages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

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

.message-content code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

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

.message-content li {
    margin: 4px 0;
}

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

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