:root {
    --fg-primary: #4a6bdf;
    --fg-primary-dark: #3a5bdf;
    --fg-bullish: #dc3545;
    --fg-bearish: #28a745;
    --fg-neutral: #6c757d;
    --fg-code: #fd7e14;
    --fg-light-bg: #f8f9fa;
    --fg-white: #ffffff;
    --fg-dark-bg: #1a1d23;
    --fg-dark-card: #2d3748;
    --fg-dark-text: #e2e8f0;
    --fg-border: #dee2e6;
    --fg-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

[data-theme="dark"] {
    --bs-body-bg: var(--fg-dark-bg);
    --bs-body-color: var(--fg-dark-text);
    --bs-card-bg: var(--fg-dark-card);
    --bs-border-color: #4a5568;
    --bs-tertiary-bg: var(--fg-dark-card);
}

/* Dark mode text colors */
[data-theme="dark"] .text-muted {
    color: #a0aec0 !important;
}

[data-theme="dark"] .score-low {
    color: #a0aec0 !important;
}

[data-theme="dark"] .badge.bg-secondary {
    background-color: #4a5568 !important;
    color: #e2e8f0 !important;
}

[data-theme="dark"] .border-bottom {
    border-color: #4a5568 !important;
}

[data-theme="dark"] .fw-bold {
    color: var(--fg-dark-text);
}

[data-theme="dark"] .score-badge {
    color: inherit;
}

[data-theme="dark"] .score-high {
    color: #fc8181 !important;
}

[data-theme="dark"] .score-medium {
    color: #f6ad55 !important;
}

[data-theme="dark"] .score-main {
    color: #fc8181 !important;
}

[data-theme="dark"] .score-sub {
    color: #f6ad55 !important;
}

[data-theme="dark"] .text-primary {
    color: #63b3ed !important;
}

[data-theme="dark"] .stock-name {
    color: #63b3ed !important;
}

[data-theme="dark"] .rank-number {
    color: #fc8181 !important;
}

[data-theme="dark"] .stock-code {
    color: #63b3ed !important;
}

[data-theme="dark"] .badge-topic-count {
    background-color: rgba(99, 179, 237, 0.2);
    color: #63b3ed;
}

[data-theme="dark"] .reason-text {
    color: #f6ad55 !important;
}

[data-theme="dark"] .reason-icon {
    color: #ffc107 !important;
}

[data-theme="dark"] .stage-badge {
    border: none;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    line-height: 1.6;
    background-color: var(--bs-body-bg, var(--fg-light-bg));
    transition: all 0.3s ease;
}

.navbar-brand {
    font-weight: 700;
    color: var(--fg-primary) !important;
    font-size: 1.5rem;
}

.navbar {
    box-shadow: var(--fg-shadow);
    background-color: var(--bs-card-bg, var(--fg-white)) !important;
}

.card {
    border: none;
    box-shadow: var(--fg-shadow);
    border-radius: 0.75rem;
    background-color: var(--bs-card-bg, var(--fg-white));
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.stock-card {
    cursor: pointer;
}

.stock-code {
    color: var(--fg-primary);
    font-weight: 500;
}

.cluster-tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    margin: 0.25rem;
}

.cluster-tag-topic {
    background-color: rgba(74, 107, 223, 0.1);
    color: var(--fg-primary);
    border: 1px solid var(--fg-primary);
}

.cluster-tag-reason {
    background-color: rgba(40, 167, 69, 0.1);
    color: var(--fg-bearish);
    border: 1px solid var(--fg-bearish);
}

.cluster-item {
    background-color: rgba(0, 0, 0, 0.02);
    transition: all 0.2s ease;
}

.cluster-item:hover {
    background-color: rgba(74, 107, 223, 0.05);
}

[data-theme="dark"] .cluster-item {
    background-color: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .cluster-item:hover {
    background-color: rgba(74, 107, 223, 0.1);
}

.clusters-container {
    max-height: 400px;
    overflow-y: auto;
}

.score-badge {
    font-size: 1.25rem;
    font-weight: 700;
}

.score-high {
    color: var(--fg-bullish);
}

.score-medium {
    color: var(--fg-code);
}

.score-low {
    color: var(--fg-neutral);
}

/* Main score - red */
.score-main {
    color: var(--fg-bullish);
    font-weight: 700;
}

/* Sub score - orange */
.score-sub {
    color: var(--fg-code);
}

/* Rank number - red */
.rank-number {
    color: var(--fg-bullish);
}

/* Topic count badge */
.badge-topic-count {
    background-color: rgba(74, 107, 223, 0.15);
    color: var(--fg-primary);
    font-weight: 500;
}

/* Reason text and icon */
.reason-text {
    color: var(--fg-code);
}

.reason-icon {
    color: #ffc107;
}

.stage-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.stage-main_wave {
    background-color: rgba(220, 53, 69, 0.1);
    color: var(--fg-bullish);
}

.stage-early {
    background-color: rgba(253, 126, 20, 0.1);
    color: var(--fg-code);
}

.stage-late {
    background-color: rgba(253, 126, 20, 0.1);
    color: var(--fg-code);
}

.stage-confirmation {
    background-color: rgba(74, 107, 223, 0.1);
    color: var(--fg-primary);
}

.stage-fermentation {
    background-color: rgba(74, 107, 223, 0.1);
    color: var(--fg-primary);
}

.stage-unknown {
    background-color: rgba(74, 107, 223, 0.1);
    color: var(--fg-primary);
}

/* Vote Progress */
.vote-progress {
    height: 1.25rem;
    background-color: #e9ecef;
    border-radius: 0.75rem;
    overflow: hidden;
    display: flex;
}

.progress-bar-bullish {
    background-color: var(--fg-bullish);
}

.progress-bar-bearish {
    background-color: var(--fg-bearish);
}

.progress-bar-neutral {
    background-color: var(--fg-neutral);
}

/* Timeline */
.timeline {
    position: relative;
    padding: 2rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to bottom, var(--fg-primary), var(--fg-primary-dark));
    transform: translateX(-50%);
    border-radius: 1.5px;
}

.timeline-item {
    position: relative;
    margin: 2.5rem 0;
}

.timeline-item-left .card {
    margin-right: 50%;
    margin-left: 0;
    transform: translateX(-1rem);
}

.timeline-item-right .card {
    margin-left: 50%;
    margin-right: 0;
    transform: translateX(1rem);
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 1.5rem;
    width: 1rem;
    height: 1rem;
    background-color: var(--fg-primary);
    border: 3px solid var(--bs-body-bg, var(--fg-white));
    border-radius: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

/* Back to Top */
#backToTop {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background-color: var(--fg-primary);
    border: none;
    color: white;
    display: none;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2);
}

#backToTop:hover {
    background-color: var(--fg-primary-dark);
    transform: translateY(-2px);
}

#backToTop.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Signal Badges */
.badge-signal.badge-bullish {
    background-color: var(--fg-bullish);
    color: white;
}

.badge-signal.badge-bearish {
    background-color: var(--fg-bearish);
    color: white;
}

.badge-signal.badge-neutral {
    background-color: var(--fg-neutral);
    color: white;
}

/* Accordion */
.accordion-button:not(.collapsed) {
    background-color: var(--fg-primary);
    color: white;
}

.accordion-button:focus {
    box-shadow: 0 0 0 0.25rem rgba(74, 107, 223, 0.25);
}

/* Analysis Content */
.analysis-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 0.95em;
}

.analysis-content h4,
.reasoning-text h4 {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--fg-primary);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.reasoning-text p,
.debate-content p,
.analysis-content p {
    margin-bottom: 0;
}

.analysis-content h4:first-child,
.reasoning-text h4:first-child {
    margin-top: 0;
}

.analysis-content ul,
.reasoning-text ul,
.debate-content ul {
    list-style-type: none;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.analysis-content li::before,
.reasoning-text li::before,
.debate-content li::before {
    content: "•";
    color: var(--fg-primary);
    font-weight: bold;
    display: inline-block;
    width: 1em;
    margin-left: -1em;
}

code {
    color: var(--fg-code);
    background-color: rgba(253, 126, 20, 0.1);
    padding: 0.1em 0.3em;
    border-radius: 0.25rem;
    font-size: 0.9em;
}

[data-theme="dark"] code {
    color: #ffc107;
    background-color: rgba(255, 193, 7, 0.15);
}

.text-success {
    color: var(--fg-bullish) !important;
}

.text-danger {
    color: var(--fg-bearish) !important;
}

/* Date Picker */
.date-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-picker-wrapper input[type="date"] {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    background-color: var(--bs-card-bg, var(--fg-white));
    color: var(--bs-body-color, #212529);
}

/* Loading */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--fg-neutral);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    .timeline::before,
    .timeline-item::before {
        left: 1rem;
    }

    .timeline-item-left .card,
    .timeline-item-right .card {
        margin-left: 3rem;
        margin-right: 0;
        transform: none;
    }

    .overview-card .col-md-6 {
        border: none !important;
    }
}
