/* ===========================================
   CFTC Gold Futures COT Regime Dashboard
   Premium Dark Theme
   =========================================== */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(31, 41, 55, 0.9);
    --border-color: rgba(75, 85, 99, 0.4);
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent-gold: #fbbf24;
    --accent-gold-dim: rgba(251, 191, 36, 0.2);
    --positive: #10b981;
    --negative: #ef4444;
    --neutral: #fbbf24;
    --regime-green: #10b981;
    --regime-yellow: #fbbf24;
    --regime-red: #ef4444;
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(251, 191, 36, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at top, rgba(251, 191, 36, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(16, 185, 129, 0.03) 0%, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #94a3b8;
    /* Slate Blue (Slate-400) */
    margin-bottom: 0;
    /* Subtle accent dot for identity */
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
}

.header h1::before {
    content: "";
    display: block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #64748b;
    /* Cool neutral (Slate) - distinct from risk colors */
    opacity: 0.8;
}

.market-selector {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.market-selector:hover {
    border-color: var(--accent-gold);
}

.market-selector:focus {
    outline: none;
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2);
}

.market-selector option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error State */
.error-container {
    text-align: center;
    padding: 3rem 2rem;
    background: var(--bg-card);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 1rem;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.error-container p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.retry-btn {
    background: var(--accent-gold);
    color: var(--bg-primary);
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.retry-btn:hover {
    background: #f59e0b;
    transform: translateY(-1px);
}

/* Dashboard */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

/* Regime Section */
.regime-section {
    display: flex;
    justify-content: center;
}

.regime-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: 2.5rem 4rem;
    text-align: center;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.regime-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(251, 191, 36, 0.2);
}

.regime-emoji {
    font-size: 4rem;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
}

.regime-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

/* Direction Arrow (Distinct Palette) */
.direction-arrow {
    font-size: 2.5rem;
    font-weight: 700;
}

.direction-arrow.bullish {
    color: #22d3ee;
    /* Cyan-400 (Distinct from green) */
    text-shadow: 0 0 10px rgba(34, 211, 238, 0.4);
}

.direction-arrow.bearish {
    color: #f472b6;
    /* Pink-400 (Distinct from red) */
    text-shadow: 0 0 10px rgba(244, 114, 182, 0.4);
}

.direction-arrow.neutral {
    color: var(--text-muted);
}

.regime-label {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.regime-label.trend {
    color: var(--regime-green);
}

.regime-label.neutral {
    color: var(--regime-yellow);
}

.regime-label.reversal {
    color: var(--regime-red);
}

.regime-score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.score-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.regime-score {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.regime-hint {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-style: italic;
    max-width: 280px;
    line-height: 1.4;
}

/* Info Section */
.info-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(10px);
}

.info-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.info-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.info-value-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.refresh-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: var(--accent-gold-dim);
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

/* Categories Section */
.categories-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.category-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(251, 191, 36, 0.3);
}

/* Primary card (Managed Money) - subtle emphasis */
.category-card.card-primary {
    border-color: rgba(251, 191, 36, 0.25);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.08);
}

.category-card.card-primary:hover {
    border-color: rgba(251, 191, 36, 0.5);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.12);
}

.category-card.card-primary .category-header h2 {
    color: var(--text-primary);
}

/* Secondary card (Swap Dealers) - baseline, inherits base styles */

/* Tertiary card (Retail) - subtle de-emphasis */
.category-card.card-tertiary {
    opacity: 0.92;
}

.category-card.card-tertiary .category-header h2 {
    font-size: 0.8125rem;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.875rem;
    border-bottom: 1px solid var(--border-color);
}

.category-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.contribution-badge {
    font-size: 0.875rem;
    font-weight: 700;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    background: var(--accent-gold-dim);
    color: var(--accent-gold);
}

.contribution-badge.positive {
    background: rgba(16, 185, 129, 0.15);
    color: var(--positive);
}

.contribution-badge.negative {
    background: rgba(239, 68, 68, 0.15);
    color: var(--negative);
}

.contribution-badge.neutral {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-secondary);
}

.category-metrics {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.metric-value {
    font-size: 0.9375rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 5rem;
}

.metric-value.positive {
    color: var(--positive);
}

.metric-value.negative {
    color: var(--negative);
}

/* Footer */
.footer {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.footer p {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--accent-gold);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: #f59e0b;
    text-decoration: underline;
}

.footer-note {
    margin-top: 0.25rem;
    font-size: 0.75rem;
}

/* Warning Banner */
.warning-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 0.75rem;
    color: var(--accent-gold);
    font-size: 0.875rem;
    font-weight: 500;
}

.warning-icon {
    font-size: 1.25rem;
}

/* 12-Week Bias Label */
.bias-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-size: 0.875rem;
}

.bias-title {
    color: var(--text-secondary);
}

.bias-value {
    font-weight: 600;
}

.bias-value.bullish {
    color: var(--positive);
}

.bias-value.bearish {
    color: var(--negative);
}

.bias-value.neutral {
    color: var(--text-secondary);
}

.bias-delta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Narrative Label */
.narrative-label {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    flex-wrap: wrap;
    text-align: left;
}

.narrative-title {
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
}

.narrative-content {
    color: var(--text-primary);
    line-height: 1.5;
}

/* Bias Indicator (elevated within metadata) */
.bias-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    margin-right: 0.5rem;
}

.bias-label-text {
    color: var(--text-secondary);
    font-weight: 500;
}

.bias-icon {
    font-size: 0.625rem;
    line-height: 1;
}

.bias-icon.bullish {
    color: var(--positive);
}

.bias-icon.bearish {
    color: var(--negative);
}

.bias-icon.neutral {
    color: var(--text-muted);
    font-size: 0.5rem;
}

.bias-indicator-value {
    font-weight: 600;
}

.bias-indicator-value.bullish {
    color: var(--positive);
}

.bias-indicator-value.bearish {
    color: var(--negative);
}

.bias-indicator-value.neutral {
    color: var(--text-secondary);
}

/* Metadata Section (demoted visual hierarchy) */
.metadata-section {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.metadata-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.metadata-label {
    color: var(--text-muted);
}

.metadata-value {
    color: var(--text-secondary);
    font-weight: 500;
}

.metadata-value.bullish {
    color: var(--positive);
}

.metadata-value.bearish {
    color: var(--negative);
}

.metadata-value.neutral {
    color: var(--text-secondary);
}

.metadata-delta {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.metadata-separator {
    color: var(--text-muted);
    opacity: 0.5;
}

.refresh-btn-small {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: 0.25rem;
}

.refresh-btn-small:hover {
    background: var(--accent-gold-dim);
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

/* History Section */
.history-section {
    margin-top: 0.5rem;
}

.toggle-history-btn {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.toggle-history-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-gold);
    color: var(--text-primary);
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.toggle-icon.open {
    transform: rotate(180deg);
}

.history-container {
    margin-top: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    overflow: hidden;
}

.history-table-wrapper {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    font-size: 0.75rem;
    white-space: nowrap;
}

.history-table th,
.history-table td {
    padding: 0.625rem 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.history-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.history-table th:first-child,
.history-table td:first-child {
    text-align: center;
}

.history-table th:nth-child(2),
.history-table td:nth-child(2) {
    text-align: left;
}

.history-table tbody tr:hover {
    background: rgba(251, 191, 36, 0.05);
}

.history-table tbody tr.current-week {
    background: rgba(251, 191, 36, 0.1);
    font-weight: 600;
}

.history-table tbody tr.week-n {
    background: rgba(16, 185, 129, 0.1);
}

.calculation-summary {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.calc-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.calc-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.875rem;
}

.calc-item-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.calc-formula {
    font-size: 0.6875rem;
    font-family: monospace;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding: 0.375rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.25rem;
}

.calc-result {
    font-size: 1rem;
    font-weight: 700;
}

.calc-result.positive {
    color: var(--positive);
}

.calc-result.negative {
    color: var(--negative);
}

/* Cross-Market Comparison Section */
.comparison-section {
    margin-top: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
}

.comparison-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.comparison-table-wrapper {
    overflow-x: auto;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.comparison-market {
    font-weight: 500;
    color: var(--text-primary);
}

.asset-icon {
    margin-right: 0.5rem;
    opacity: 0.7;
}

.comparison-regime {
    font-weight: 600;
}

.comparison-regime.trend {
    color: var(--positive);
}

.comparison-regime.neutral {
    color: var(--neutral);
}

.comparison-regime.reversal {
    color: var(--negative);
}

.comparison-regime.muted,
.comparison-duration.muted,
.comparison-bias.muted {
    color: var(--text-muted);
}

.comparison-duration {
    color: var(--text-secondary);
}

.comparison-bias.positive {
    color: var(--positive);
}

.comparison-bias.negative {
    color: var(--negative);
}

.comparison-note {
    margin-top: 0.75rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* Regime Change History Section */
.regime-history-section {
    margin-top: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
}

.regime-history-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.regime-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.regime-history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0.5rem;
    border-left: 3px solid var(--border-color);
    font-size: 0.8125rem;
}

.regime-history-item.trend {
    border-left-color: var(--positive);
}

.regime-history-item.neutral {
    border-left-color: var(--neutral);
}

.regime-history-item.reversal {
    border-left-color: var(--negative);
}

.regime-history-emoji {
    font-size: 1rem;
}

.regime-history-label {
    font-weight: 600;
    min-width: 5rem;
    color: var(--text-primary);
}

.regime-history-item.trend .regime-history-label {
    color: var(--positive);
}

.regime-history-item.neutral .regime-history-label {
    color: var(--neutral);
}

.regime-history-item.reversal .regime-history-label {
    color: var(--negative);
}

.regime-history-duration {
    color: var(--text-secondary);
    min-width: 5rem;
}

.regime-history-dates {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: auto;
}

.regime-history-empty {
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .regime-card {
        padding: 2rem;
        width: 100%;
    }

    .regime-emoji {
        font-size: 3rem;
    }

    .regime-label {
        font-size: 1.25rem;
    }

    .info-section {
        grid-template-columns: 1fr;
    }

    .categories-section {
        grid-template-columns: 1fr;
    }
}



/* Comparison Section (Position A Layout) */
.comparison-section {
    margin: 2rem 0;
    /* Vertical spacing to separate from Narrative and Categories */
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
}

.comparison-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.comparison-table-wrapper {
    overflow-x: auto;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.comparison-table {
    width: 100%;
    table-layout: fixed;
    /* Fixed layout for wrapping */
    border-collapse: collapse;
    font-size: 0.82rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
}

/* Ensure data fits */
.comparison-market {
    white-space: normal;
    word-break: break-word;
}

.comparison-bias {
    white-space: nowrap;
}

/* Widths */
.comparison-table th:nth-child(1),
.comparison-table td:nth-child(1) {
    width: 35%;
}

.comparison-table th:nth-child(2),
.comparison-table td:nth-child(2) {
    width: 20%;
}

.comparison-table th:nth-child(3),
.comparison-table td:nth-child(3) {
    width: 15%;
    text-align: right;
}

.comparison-table th:nth-child(4),
.comparison-table td:nth-child(4) {
    width: 30%;
    text-align: right;
}

.comparison-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}