.ai-analysis-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 160px);
    background: #ffffff;
    border: 1px solid #e1e8ef;
    border-radius: 10px;
    overflow: hidden;
}

/* Chat Area */
.ai-chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
}

/* Welcome State */
.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.ai-welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.ai-welcome-icon i {
    font-size: 28px;
    color: #ffffff;
}

.ai-welcome h2 {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 8px 0;
}

.ai-welcome p {
    font-size: 14px;
    color: #64748b;
    margin: 0 0 28px 0;
    max-width: 420px;
}

.ai-suggestions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.ai-suggestion-chip {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #1d4ed8;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-suggestion-chip:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

/* Messages */
.ai-message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: messageSlideIn 0.3s ease;
}

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

/* User prompts stay chat-narrow on the right. Assistant responses use the full
   chat width so tables, stat grids, and sheet output aren't squashed. */
.ai-message.user {
    margin-left: auto;
    flex-direction: row-reverse;
    max-width: 720px;
}

.ai-message.assistant {
    width: 100%;
}

.ai-message.assistant .ai-message-content {
    flex: 1;
    min-width: 0; /* lets the content shrink correctly inside the flex row */
}

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
}

.ai-message.user .ai-message-avatar {
    background: #dbeafe;
    color: #2563eb;
}

.ai-message.assistant .ai-message-avatar {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
}

.ai-message-content {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.6;
    color: #334155;
}

.ai-message.user .ai-message-content {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}

/* Stat Cards inside AI response */
.ai-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 14px 0;
}

.ai-stat-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}

.ai-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.5px;
}

.ai-stat-value.positive {
    color: #2563eb;
}

.ai-stat-value.highlight {
    color: #2563eb;
}

.ai-stat-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 4px;
}

/* Trend indicator */
.ai-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    padding: 3px 8px;
    border-radius: 4px;
}

.ai-trend.up {
    color: #2563eb;
    background: #f0fdf4;
}

.ai-trend.down {
    color: #dc2626;
    background: #fef2f2;
}

/* Typing Indicator */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input Area */
.ai-input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.ai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 16px;
    transition: border-color 0.15s ease;
}

.ai-input-wrapper:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ai-input-icon {
    color: #2563eb;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    font-weight: 500;
    color: #0f172a;
    background: transparent;
}

.ai-input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.ai-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: #2563eb;
    color: #ffffff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.ai-send-btn:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: default;
}

.ai-send-btn:not(:disabled):hover {
    background: #1d4ed8;
}

/* Mini bar chart in response */
.ai-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 60px;
    margin: 14px 0 4px;
    padding: 0 4px;
}

.ai-bar {
    flex: 1;
    border-radius: 4px 4px 0 0;
    background: #2563eb;
    transition: height 0.6s ease;
    position: relative;
    min-width: 0;
}

.ai-bar.previous {
    background: #cbd5e1;
}

.ai-bar-labels {
    display: flex;
    gap: 6px;
    padding: 0 4px;
}

.ai-bar-label {
    flex: 1;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    font-weight: 500;
}

/* Inline tables for spreadsheet/report */
.ai-sheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 10px 0;
}

/* Headers stay on one line; data cells wrap when needed. */
.ai-sheet-table thead th {
    white-space: nowrap;
}

.ai-sheet-table thead th {
    background: #0f172a;
    color: #ffffff;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
}

.ai-sheet-table tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
}

.ai-sheet-table tbody tr:hover {
    background: #f8fafc;
}

/* Download buttons */
.ai-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    background: #2563eb;
    color: #ffffff;
    transition: background 0.15s ease;
}

.ai-download-btn:hover {
    background: #1d4ed8;
}

.ai-download-pdf {
    background: #dc2626;
}

.ai-download-pdf:hover {
    background: #b91c1c;
}

/* Markdown content styling */
.ai-message-content h1,
.ai-message-content h2,
.ai-message-content h3 {
    margin: 12px 0 6px;
    color: #0f172a;
}

.ai-message-content h1 { font-size: 18px; }
.ai-message-content h2 { font-size: 16px; }
.ai-message-content h3 { font-size: 14px; }

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

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

.ai-message-content strong {
    color: #0f172a;
}

.ai-message-content a {
    color: #2563eb;
    text-decoration: none;
}

.ai-message-content a:hover {
    text-decoration: underline;
}

.ai-message-content p {
    margin: 6px 0;
}
