/* AI Assistant - Professional Full-Screen Application */
* {
    box-sizing: border-box;
}

:root {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-primary: #0f172a;
    --color-primary-hover: #1e293b;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-user-query: #f1f5f9;
    --color-ai-card: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --max-content: 960px;
    --max-content-wide: min(100%, calc(100vw - 64px));
}

.chatbot-widget {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    overflow: hidden;
}

.chatbot-button {
    display: none;
}

.chatbot-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-text {
    font-weight: 500;
    font-size: 14px;
}

/* Main Application Window */
.chatbot-window {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatbot-window.minimized { height: 60px; }
.chatbot-window.hidden { display: none; }

/* Professional Header */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 64px;
    background: var(--color-primary);
    color: white;
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.chatbot-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.02em;
}

.chatbot-icon-small {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
}

.chatbot-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background-color 0.2s ease;
}

.control-btn:hover { background: rgba(255, 255, 255, 0.2); }
.close-btn:hover { background: rgba(239, 68, 68, 0.4); }

/* Session Toolbar - Integrated */
.session-management {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 32px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.session-controls {
    display: flex;
    gap: 10px;
}

.session-btn {
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-surface);
    color: var(--color-text);
}

.session-btn.primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.session-btn.primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.session-btn.secondary {
    background: var(--color-surface);
    color: var(--color-text-muted);
}

.session-btn.secondary:hover {
    background: var(--color-user-query);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.session-info {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Session History Panel */
.session-history-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg);
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.session-history-panel.hidden {
    display: none;
}

.session-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.session-history-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
}

.close-history-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--color-text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.close-history-btn:hover {
    color: var(--color-text);
    background: var(--color-user-query);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    max-width: var(--max-content);
    margin: 0 auto;
    width: 100%;
}

.session-item {
    padding: 16px 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--color-surface);
}

.session-item:hover {
    background: var(--color-user-query);
    border-color: var(--color-text-muted);
}

.session-item.active {
    background: var(--color-user-query);
    border-color: var(--color-primary);
}

.session-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.session-item-question {
    font-weight: 500;
    font-size: 14px;
    color: var(--color-text);
    flex: 1;
    margin-right: 12px;
}

.session-item-date {
    font-size: 12px;
    color: var(--color-text-muted);
}

.session-item-preview {
    font-size: 13px;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.load-more-item {
    border: 2px dashed var(--color-border);
    background: var(--color-surface);
    cursor: default;
}

.load-more-item:hover {
    background: var(--color-surface);
    border-color: var(--color-border);
}

.load-more-item .session-btn {
    border: 1px solid var(--color-primary);
    background: var(--color-surface);
    color: var(--color-primary);
    transition: all 0.2s ease;
}

.load-more-item .session-btn:hover {
    background: var(--color-primary);
    color: white;
}

/* Messages - Vertical scroll only, full-width for charts and content */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 32px 32px;
    width: 100%;
    max-width: var(--max-content-wide);
    margin: 0 auto;
    min-height: 0;
    min-width: 0;
    contain: layout;
}

.message {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
}

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

.message.ai-message {
    align-items: stretch;
}

.message-content {
    max-width: 100%;
    width: 100%;
    min-width: 0;
    padding: 16px 20px;
    border-radius: var(--radius);
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden;
    line-height: 1.6;
    font-size: 14px;
}

.user-message .message-content {
    max-width: 85%;
    background: var(--color-user-query);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-weight: 500;
}

.ai-message .message-content {
    background: var(--color-ai-card);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.message-body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Data Tables - Scrollable within message, independent of chat scroll */
.results-table-container {
    overflow: auto;
    margin-top: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    max-width: 100%;
    max-height: min(400px, 50vh);
}

.results-table-container::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.results-table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.results-table-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.results-table-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.results-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 13px;
}

.results-table th,
.results-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.results-table th {
    background: var(--color-primary);
    color: white;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.results-table tbody tr:hover {
    background: var(--color-user-query);
}

.results-table tbody tr:last-child td {
    border-bottom: none;
}

.results-intro {
    margin-bottom: 12px;
    color: var(--color-text-muted);
    font-size: 14px;
    line-height: 1.5;
}

.message-time {
    display: none;
}

.welcome-message {
    text-align: center;
    margin-bottom: 32px;
    padding: 24px;
}

.welcome-message .message-content {
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--color-text-muted);
}

/* Input Area - Command Bar Style */
.chat-input-area {
    padding: 20px 32px 28px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: var(--max-content);
    margin: 0 auto;
}

.message-input {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 20px;
    font-size: 15px;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    line-height: 1.5;
    max-height: 120px;
    background: var(--color-surface);
}

.message-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.message-input::placeholder {
    color: var(--color-text-muted);
}

.send-btn {
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.send-btn:disabled {
    background: var(--color-border);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.input-footer {
    display: none;
    align-items: center;
    justify-content: space-between;
}

.typing-indicator {
    font-size: 12px;
    color: #6c757d;
    font-style: italic;
}

/* Message streaming animation */
.message-streaming {
    animation: messageStream 0.3s ease-out;
}

.typing-indicator-animation {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
}

.typing-indicator-animation .typing-dot {
    width: 6px;
    height: 6px;
    margin: 0 2px;
    background-color: #b0b0b0;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-indicator-animation .typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator-animation .typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1.0);
    }
}


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

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(248, 250, 252, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-border);
    border-top: 3px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 14px;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Error Modal */
.error-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.error-modal.hidden {
    display: none;
}

.error-modal-content {
    background: var(--color-surface);
    border-radius: var(--radius);
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--color-border);
}

.error-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
}

.error-header h3 {
    margin: 0;
    color: #dc2626;
    font-size: 16px;
    font-weight: 600;
}

.close-error-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--color-text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.close-error-btn:hover {
    color: var(--color-text);
    background: var(--color-user-query);
}

.error-body {
    padding: 20px 24px;
}

.error-body p {
    margin: 0;
    color: var(--color-text);
    line-height: 1.6;
    font-size: 14px;
}

.error-footer {
    padding: 16px 24px 20px;
    display: flex;
    justify-content: flex-end;
}

.retry-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.retry-btn:hover {
    background: var(--color-primary-hover);
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-messages,
    .input-container {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .chatbot-header,
    .session-management {
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .chat-input-area {
        padding: 16px 20px 24px;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mb-0 {
    margin-bottom: 0;
}

.mt-1 {
    margin-top: 4px;
}

.mb-1 {
    margin-bottom: 4px;
}

.p-2 {
    padding: 8px;
}

.p-3 {
    padding: 12px;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar,
.session-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.session-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.session-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.session-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Chart Button - Professional Action */
.chart-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 12px;
}

.chart-button:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.chart-button:disabled {
    background: var(--color-border);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.chart-button svg {
    width: 16px;
    height: 16px;
}

.chart-container {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.chart-container .chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.chart-container .chart-header-text {
    flex: 1;
    min-width: 0;
}

.chart-container .chart-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-text);
}

.chart-container .chart-insight {
    margin-top: 6px;
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.5;
    font-weight: 400;
}

/* Chart skip message (when chart would not add value) */
.chart-container.chart-skip-message {
    background: #f0f9ff;
    border-color: #bae6fd;
}

.chart-skip-message .chart-skip-body {
    padding: 16px 0 8px;
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
}

.chart-container .close-chart-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.chart-container .close-chart-btn:hover {
    color: var(--color-text);
}

.chart-wrapper {
    min-height: 300px;
    width: 100%;
}

.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: var(--color-text-muted);
}

.chart-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top: 3px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

.chart-error {
    padding: 12px;
    background: #fef2f2;
    color: #991b1b;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid #fecaca;
}
