/* ==========================================================================
   AI Financial Agent — Dark Financial Dashboard Theme
   ========================================================================== */

/* --- Tokens --- */
:root {
    --bg:             #0b0d11;
    --surface:        #141720;
    --surface-alt:    #1a1e2b;
    --surface-hover:  #1f2435;
    --border:         #262b3a;
    --text:           #e4e4e7;
    --text-muted:     #8b8fa3;
    --accent:         #3b82f6;
    --accent-hover:   #2563eb;
    --bullish:        #22c55e;
    --bearish:        #ef4444;
    --neutral:        #eab308;
    --radius:         10px;
    --radius-sm:      6px;
    --font:           "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
                      Roboto, Helvetica, Arial, sans-serif;
    --font-mono:      "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --- */
.container { max-width: 1140px; margin: 0 auto; padding: 0 24px; width: 100%; }

/* --- Header --- */
.site-header {
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}
.logo:hover { text-decoration: none; }
.logo-icon { color: var(--accent); font-size: 1.3rem; }

/* --- Footer --- */
.site-footer {
    margin-top: auto;
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* --- Hero --- */
.hero {
    text-align: center;
    padding: 56px 0 32px;
}
.hero h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { color: var(--text-muted); margin-top: 10px; font-size: 1.05rem; max-width: 560px; margin-left: auto; margin-right: auto; }

.pipeline-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 32px;
    flex-wrap: wrap;
}
.pipeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.step-icon { font-size: 1.6rem; }
.pipeline-arrow { color: var(--border); font-size: 1.4rem; margin-top: -16px; }

/* --- Form --- */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px;
    max-width: 500px;
    margin: 0 auto 64px;
}

.form-group {
    margin-bottom: 24px;
}
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.form-group input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }
.form-hint { display: block; margin-top: 6px; font-size: 0.78rem; color: var(--text-muted); }

/* --- Research Document Upload --- */
.optional-label {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.doc-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0;
}

.doc-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.doc-ticker-select {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 100px;
    outline: none;
    cursor: pointer;
}
.doc-ticker-select:focus { border-color: var(--accent); }

.doc-file-label {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
}
.doc-file-label:hover { border-color: var(--accent); }

.doc-file-name {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.doc-remove-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.doc-remove-btn:hover {
    border-color: var(--bearish);
    color: var(--bearish);
    background: rgba(239, 68, 68, 0.1);
}

.btn-add-doc {
    padding: 10px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
    width: 100%;
}
.btn-add-doc:hover:not(:disabled) {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}
.btn-add-doc:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-block;
    text-decoration: none;
}
.btn-secondary:hover { background: var(--surface-hover); text-decoration: none; }

.error-banner {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

/* --- Results Header --- */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 40px 0 24px;
    flex-wrap: wrap;
    gap: 16px;
}
.results-header h1 { font-size: 1.6rem; font-weight: 700; }

.ticker-badge {
    display: inline-block;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 10px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

/* --- Progress Pipeline --- */
.progress-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px 20px;
    margin-bottom: 32px;
}

.progress-pipeline-track {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
}

.progress-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.stage-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--surface-alt);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: all 0.4s ease;
}

.stage-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    max-width: 70px;
    transition: color 0.3s;
}

.progress-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin-top: 19px;
    min-width: 24px;
    transition: background 0.4s;
}

/* Active stage — pulsing */
.progress-stage.active .stage-circle {
    border-color: var(--accent);
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}
.progress-stage.active .stage-label { color: var(--accent); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    50%      { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
}

/* Complete stage */
.progress-stage.complete .stage-circle {
    background: var(--bullish);
    border-color: var(--bullish);
    color: #fff;
}
.progress-stage.complete .stage-label { color: var(--bullish); }
.progress-line.complete { background: var(--bullish); }

.progress-status {
    text-align: center;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Results Sections --- */
.results-section {
    margin-bottom: 32px;
}
.results-section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.hidden { display: none !important; }

/* --- Data Tables --- */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.data-table tbody tr {
    background: var(--surface);
    transition: background 0.15s;
}
.data-table tbody tr:hover { background: var(--surface-hover); }

/* Signal pills */
.signal-pill {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.signal-bullish { background: rgba(34, 197, 94, 0.15); color: var(--bullish); }
.signal-bearish { background: rgba(239, 68, 68, 0.15); color: var(--bearish); }
.signal-neutral { background: rgba(234, 179, 8, 0.15); color: var(--neutral); }

/* Confidence bar */
.confidence-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 100px;
}
.confidence-track {
    flex: 1;
    height: 6px;
    background: var(--surface-alt);
    border-radius: 3px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
    transition: width 0.6s ease;
}
.confidence-value {
    font-size: 0.82rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-width: 36px;
}

/* Risk bar */
.risk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}
.risk-track {
    width: 60px;
    height: 6px;
    background: var(--surface-alt);
    border-radius: 3px;
    overflow: hidden;
}
.risk-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}
.risk-low    { background: var(--bullish); }
.risk-medium { background: var(--neutral); }
.risk-high   { background: var(--bearish); }
.risk-value  {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 600;
}
.risk-value.risk-low    { color: var(--bullish); }
.risk-value.risk-medium { color: var(--neutral); }
.risk-value.risk-high   { color: var(--bearish); }

/* Risk factor pills */
.risk-factors { display: flex; flex-wrap: wrap; gap: 6px; }
.risk-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Expandable reasoning */
.reasoning-cell details { margin-top: 4px; }
.reasoning-cell summary {
    color: var(--accent);
    cursor: pointer;
    font-size: 0.8rem;
    user-select: none;
}
.reasoning-cell summary:hover { text-decoration: underline; }
.reasoning-preview {
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.5;
}
.reasoning-full {
    margin-top: 8px;
    color: var(--text);
    font-size: 0.84rem;
    line-height: 1.65;
    white-space: pre-wrap;
}

/* --- Decision Cards --- */
.decisions-cards {
    display: grid;
    gap: 16px;
}

.decision-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: fadeIn 0.4s ease-out;
}
.decision-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 10px;
}
.decision-card-header .ticker-badge { font-size: 1rem; }

.action-badge {
    display: inline-block;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.action-buy  { background: rgba(34, 197, 94, 0.15); color: var(--bullish); }
.action-sell { background: rgba(239, 68, 68, 0.15); color: var(--bearish); }
.action-hold { background: rgba(234, 179, 8, 0.15); color: var(--neutral); }

.decision-meta {
    display: flex;
    gap: 24px;
    padding: 14px 20px;
    background: var(--surface-alt);
    font-size: 0.85rem;
}
.decision-meta span { color: var(--text-muted); }
.decision-meta strong { color: var(--text); font-family: var(--font-mono); }

.decision-reasoning {
    padding: 16px 20px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
}

/* --- Complete Banner --- */
.complete-banner {
    text-align: center;
    padding: 20px;
    margin: 16px 0 40px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: var(--radius);
    color: var(--bullish);
    font-weight: 600;
    font-size: 1.05rem;
    animation: fadeIn 0.5s ease;
}
.complete-icon { margin-right: 8px; }

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.35s ease-out; }

/* --- Chat Panel --- */
.chat-messages {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-height: 480px;
    overflow-y: auto;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out;
}

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

.chat-message-content {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.user-message .chat-message-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.assistant-message .chat-message-content {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 2px;
}

.chat-input-form {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--accent); }

.chat-send-btn {
    width: auto;
    padding: 12px 24px;
    flex-shrink: 0;
}
.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Markdown inside chat messages */
.chat-message-content p { margin: 0 0 0.5em; }
.chat-message-content p:last-child { margin-bottom: 0; }

.chat-message-content strong { font-weight: 700; color: #fff; }
.assistant-message .chat-message-content strong { color: var(--text); }

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

.chat-message-content code {
    font-family: var(--font-mono);
    font-size: 0.82em;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
}

.chat-message-content pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
}
.chat-message-content pre code {
    background: none;
    padding: 0;
    font-size: 0.82rem;
    line-height: 1.5;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}
.chat-message-content li {
    margin-bottom: 4px;
    line-height: 1.55;
}

.chat-message-content .md-h {
    font-size: 1rem;
    font-weight: 700;
    margin: 10px 0 4px;
}
.chat-message-content .md-h:first-child { margin-top: 0; }

.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 10px 16px;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* --- Price Charts --- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    justify-items: center;
}
.charts-grid .chart-card {
    width: 100%;
    max-width: 800px;
}
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.chart-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}
.chart-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
}
.chart-change {
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-mono);
}
.chart-change.positive { color: var(--bullish); }
.chart-change.negative { color: var(--bearish); }
.chart-period {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}
.chart-legend {
    display: flex;
    gap: 16px;
    padding: 6px 16px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}
.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 3px;
    border-radius: 1px;
}
.chart-body {
    height: 400px;
    width: 100%;
}

@media (min-width: 1200px) {
    .charts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .charts-grid .chart-card {
        max-width: none;
    }
    /* Center a lone last chart spanning the full row */
    .charts-grid .chart-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        max-width: 50%;
        justify-self: center;
    }
    .chart-body {
        height: 350px;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.6rem; }
    .progress-pipeline-track { flex-wrap: wrap; gap: 4px; justify-content: center; }
    .progress-line { display: none; }
    .stage-label { font-size: 0.65rem; }
    .data-table { font-size: 0.8rem; }
    .data-table th, .data-table td { padding: 8px 10px; }
    .results-header { flex-direction: column; }
    .decision-meta { flex-wrap: wrap; gap: 12px; }
    .pipeline-arrow { display: none; }
    .chat-message { max-width: 95%; }
    .chat-messages { max-height: 360px; }
}
