:root {
    --bg-color: #F5F5F7;
    --card-bg: #FFFFFF;
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --accent: #0066CC;
    --border: #D2D2D7;
    --error: #FF3B30;
    --success: #34C759;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: row;
    /* Global row layout */
    overflow: hidden;
    /* Prevent outer scroll */
    padding: 0;
    /* Remove padding from container */
}

/* Left Panel (Main App) */
.left-panel {
    flex: 2;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}

.header {
    text-align: center;
}

.title {
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 17px;
    font-weight: 400;
}

/* Settings Area */
.settings-container {
    background: #FAFAFA;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
}

.settings-toggle {
    background: none;
    border: none;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
    width: fit-content;
}

.settings-toggle:hover {
    color: var(--text-primary);
}

.settings-icon {
    width: 16px;
    height: 16px;
}

.settings-panel {
    padding: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    margin-top: 4px;
    transition: all 0.3s ease;
}

.settings-panel.hidden {
    display: none;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.settings-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0px; 
}

.settings-group.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.settings-group.checkbox-group input {
    width: auto;
    margin: 0;
}

.settings-group.checkbox-group label {
    text-transform: none;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--text-primary);
    cursor: pointer;
}

.settings-group input {
    background: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.settings-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.save-button {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.save-button:hover {
    opacity: 0.9;
}

.settings-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Ingestion Area */
.ingestion-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drop-zone {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #FAFAFA;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: #FFFFFF;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.icon-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.upload-icon {
    width: 24px;
    height: 24px;
}

.upload-text {
    font-size: 15px;
    font-weight: 500;
}

.status-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 100px;
    overflow-y: auto;
}

.status-item {
    font-size: 13px;
    padding: 10px 16px;
    background: #F2F2F7;
    border-radius: 10px;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
}

.status-item.success {
    color: var(--success);
}

.status-item.error {
    color: var(--error);
}

.status-item.pending {
    color: var(--accent);
}

/* Message Width Overrides */
.message.agent.wide-message {
    max-width: 95%;
}

/* MD Styling - Apple Aesthetic Tables */
.message table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 16px 0;
    font-size: 14px;
    background: #FFFFFF;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.message th {
    background: #F9F9FB;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.message td {
    padding: 12px 14px;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.message tr:last-child td {
    border-bottom: none;
}

.message tr:hover td {
    background: #F5F5F7;
}

/* Specific alignments for financial tables */
.message td:nth-child(3),
.message th:nth-child(3) {
    text-align: right;
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: 500;
}

.message ul,
.message ol {
    margin: 12px 0 12px 24px;
    line-height: 1.6;
}

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

.message strong {
    font-weight: 600;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 20px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 15px;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.agent {
    align-self: flex-start;
    background-color: #E9E9EB;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.info {
    align-self: center;
    background: none;
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
}

/* Input Container */
.input-container {
    padding-top: 10px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#query-input {
    width: 100%;
    background: #F2F2F7;
    border: none;
    border-radius: 24px;
    padding: 14px 50px 14px 20px;
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

#query-input:focus {
    background: #FFFFFF;
    box-shadow: 0 0 0 1px var(--border);
}

.send-button {
    position: absolute;
    right: 8px;
    width: 34px;
    height: 34px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.send-button:hover {
    opacity: 0.8;
}

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

/* Loading animation for chat */
.loading::after {
    content: " .";
    animation: dots 1.5s steps(5, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        color: rgba(0, 0, 0, 0);
        text-shadow: .25em 0 0 rgba(0, 0, 0, 0), .5em 0 0 rgba(0, 0, 0, 0);
    }

    40% {
        color: var(--text-secondary);
        text-shadow: .25em 0 0 rgba(0, 0, 0, 0), .5em 0 0 rgba(0, 0, 0, 0);
    }

    60% {
        text-shadow: .25em 0 0 var(--text-secondary), .5em 0 0 rgba(0, 0, 0, 0);
    }

    80%,
    100% {
        text-shadow: .25em 0 0 var(--text-secondary), .5em 0 0 var(--text-secondary);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #D2D2D7;
    border-radius: 3px;
}

/* Insights Panel (Right Column) */
.insights-panel {
    flex: 1;
    min-width: 350px;
    max-width: 450px;
    /* Wider panel */
    background: #FAFAFA;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    border: none;
    /* Removed border */
    border-radius: 0;
    /* Full height */
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.time-toggles {
    display: flex;
    background: #EEE;
    border-radius: 8px;
    padding: 2px;
}

.toggle-btn {
    border: none;
    background: transparent;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    /* Increased padding */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

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

.insights-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.insights-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.refresh-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.refresh-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--accent);
}

.refresh-btn svg {
    width: 16px;
    height: 16px;
}

.insights-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 13px;
}

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

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

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

.insights-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.insight-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.insight-card h4 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.insight-body {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
}

.insight-body ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.insight-body li {
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.insight-body li:last-child {
    border-bottom: none;
}

.insight-body .category-name {
    color: var(--text-secondary);
}

.insight-body .category-amount {
    font-weight: 500;
    font-family: 'SF Mono', 'Menlo', monospace;
}

.subscription-item {
    padding: 6px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.subscription-item:last-child {
    border-bottom: none;
}

.subscription-name {
    font-weight: 500;
}

.subscription-cost {
    color: var(--text-secondary);
    font-size: 12px;
}

.subscription-extra {
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.04);
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    margin-top: 2px;
}

.anomaly-item {
    border-left: 3px solid transparent;
    padding-left: 8px !important;
    margin-bottom: 8px;
}

.anomaly-high {
    color: var(--error);
    font-weight: 600;
}

.anomaly-medium {
    color: #f59e0b;
    font-weight: 500;
}

.anomaly-low {
    color: var(--text-secondary);
}

.trend-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.trend-up {
    color: var(--error);
}

.trend-down {
    color: var(--success);
}

.trend-stable {
    color: var(--text-secondary);
}