:root {
    /* Color Palette - Vibrant Dark Mode */
    --bg-base: #0f172a;
    --bg-gradient-1: #1e1b4b;
    --bg-gradient-2: #312e81;
    --bg-gradient-3: #172554;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-glow: rgba(99, 102, 241, 0.4);
    --accent-primary: #6366f1;
    --accent-hover: #4f46e5;
    
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-bg-light: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    --message-user: #4f46e5;
    --message-ai: rgba(255, 255, 255, 0.05);

    --font-sans: 'Inter', sans-serif;
    --font-display: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background-color: var(--bg-base);
    min-height: 100vh;
    overflow: hidden; /* Prevent scrolling on body, let internal containers scroll */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Dynamic Animated Background */
.animated-bg {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    background: radial-gradient(circle at 15% 50%, var(--bg-gradient-1), transparent 50%),
                radial-gradient(circle at 85% 30%, var(--bg-gradient-2), transparent 50%),
                radial-gradient(circle at 50% 80%, var(--bg-gradient-3), transparent 50%);
    background-size: 200% 200%;
    animation: pulseGradients 15s ease-in-out infinite alternate;
}

@keyframes pulseGradients {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.glass-panel-light {
    background: var(--glass-bg-light);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
}

.hidden {
    display: none !important;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    padding: 40px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 12px;
    background: linear-gradient(to right, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-desc {
    color: var(--text-secondary);
    margin-bottom: 30px;
    line-height: 1.5;
}

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

#api-key-input {
    flex: 1;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#api-key-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.primary-btn {
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.98); }

.secondary-btn {
    background: transparent;
    color: #f8fafc;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.secondary-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.api-note {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Dashboard Layout */
.dashboard {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.8s ease-out forwards;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    height: 70px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
}

.logo-icon {
    color: var(--accent-primary);
    font-size: 1.8rem;
}

.alpha-tag {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.70rem;
    font-weight: 700;
    margin-left: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.highlight {
    color: var(--accent-primary);
}

.scenario-pill {
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
    font-size: 0.9rem;
    font-weight: 500;
}

.content-grid {
    flex: 1;
    display: flex;
    gap: 24px;
    padding: 24px;
    height: calc(100vh - 70px);
}

/* Left Panel - Context */
.context-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.panel-header h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
}

.badge {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.context-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.scenario-text {
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.scenario-text strong {
    color: var(--text-primary);
}

.chart-container {
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid var(--glass-border);
}

.advice-ticker-box {
    background: rgba(99, 102, 241, 0.1);
    border-left: 4px solid var(--accent-primary);
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin-top: 10px;
    min-height: 60px;
    display: flex;
    flex-direction: column;
}

.advice-ticker-box strong {
    color: #a5b4fc;
    margin-bottom: 4px;
}

.fade-text {
    animation: textFadeIn 0.8s ease-in-out forwards;
}

@keyframes textFadeIn {
    0% { opacity: 0; transform: translateY(5px); }
    100% { opacity: 1; transform: translateY(0); }
}

.chart-caption {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.5;
}

/* Right Panel - Chat */
.chat-panel {
    flex: 1;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar {
    position: relative;
}

.avatar-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f43f5e, #be123c);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    bottom: 0;
    right: 0;
    border: 2px solid var(--glass-bg);
}

.status-indicator.online { background: #10b981; }

.chat-details h2 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.status-text {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    max-width: 85%;
    animation: fadeInMessage 0.3s ease-out;
}

.ai-message {
    align-self: flex-start;
}
.user-message {
    align-self: flex-end;
}

.msg-bubble {
    padding: 14px 18px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95rem;
}

.ai-message .msg-bubble {
    background: var(--message-ai);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

.user-message .msg-bubble {
    background: var(--message-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.markdown-body p {
    margin-bottom: 12px;
}
.markdown-body p:last-child {
    margin-bottom: 0;
}
.markdown-body strong {
    font-weight: 600;
}
.markdown-body em {
    font-style: italic;
    color: rgba(255,255,255,0.8);
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

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

.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 14px 16px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    resize: none;
    max-height: 150px;
    outline: none;
    line-height: 1.5;
    transition: border-color 0.2s;
}

#chat-input:focus {
    border-color: rgba(99, 102, 241, 0.5);
}

.send-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}
.send-btn:active {
    transform: scale(0.95);
}

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

/* Animations */
@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* End Modal Specifics */
.end-modal-content {
    max-width: 900px;
    width: 95%;
}

.end-charts-wrapper {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
    text-align: left;
}

.chart-box {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
}

.chart-box h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
    text-align: center;
}

.chart-container-small {
    width: 100%;
    height: 250px;
}

.optimal-score-card {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    color: #a7f3d0;
}

.optimal-score-card h3 {
    font-family: var(--font-display);
    margin-bottom: 8px;
    font-size: 1.2rem;
    color: #34d399;
}
.optimal-score-card p {
    font-size: 1.1rem;
    line-height: 1.5;
}
