/* ==========================================================================
   Macro & Asset Monitor - Dark Tech Theme Stylesheet
   ========================================================================== */

:root {
    --bg-main: #080c14;
    --bg-card: #0f172a;
    --bg-card-hover: #172544;
    --bg-panel: #0d1322;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --color-up: #10b981;        /* 涨: 翡翠绿 */
    --color-up-bg: rgba(16, 185, 129, 0.12);
    --color-down: #f43f5e;      /* 跌: 玫红 */
    --color-down-bg: rgba(244, 63, 94, 0.12);
    --color-neutral: #64748b;
    
    --accent-cyan: #38bdf8;
    --accent-purple: #a855f7;
    --accent-gold: #f59e0b;
    --accent-rose: #f43f5e;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", Consolas, "Courier New", monospace;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.tabular-nums {
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}

.app-container {
    max-width: 1540px;
    margin: 0 auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ==========================================================================
   Header Section
   ========================================================================== */

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-box {
    position: relative;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-icon {
    font-size: 18px;
    color: var(--accent-cyan);
    font-weight: bold;
}

.logo-pulse {
    position: absolute;
    inset: -2px;
    border-radius: 12px;
    border: 1px solid var(--accent-cyan);
    opacity: 0.4;
    animation: pulseGlow 2.5s infinite;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.2; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.04); }
}

.app-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent-cyan);
    border-radius: 4px;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.app-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--color-up);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--color-up);
    animation: blink 2s infinite ease-in-out;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.refresh-pill {
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

.update-time {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ==========================================================================
   Buttons & Controls
   ========================================================================== */

.btn {
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
    user-select: none;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.5);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon.spinning {
    display: inline-block;
    animation: spin 1s linear infinite;
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-group {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.04);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.btn-chip {
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
}

.btn-chip:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.btn-chip.active {
    background: #1e293b;
    color: var(--accent-cyan);
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
}

.btn-outline.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-weight: 600;
}

.btn-period {
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    min-width: 38px;
    justify-content: center;
}

.btn-period.active {
    background: var(--accent-cyan);
    color: #080c14;
    font-weight: 700;
}

.btn-period:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* ==========================================================================
   Metric Cards Grid (4 Core Assets)
   ========================================================================== */

.section-cards {
    width: 100%;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.metric-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    transition: var(--transition);
}

.metric-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border-color: var(--border-light);
}

.metric-card.active {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.2);
}

.metric-card.active::before {
    background: var(--card-theme-color, var(--accent-cyan));
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.asset-badge-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.asset-badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.card-asset-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-top-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
    font-family: var(--font-sans);
    letter-spacing: 0.2px;
}

.source-tag-sm {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.25);
    margin-left: 6px;
}

.card-ticker {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.card-mid {
    margin-bottom: 12px;
}

.price-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.asset-price {
    font-size: 26px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.5px;
}

.change-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.change-badge.up {
    color: var(--color-up);
    background: var(--color-up-bg);
}

.change-badge.down {
    color: var(--color-down);
    background: var(--color-down-bg);
}

.change-badge.neutral {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
}

/* Range bar */
.card-range-wrap {
    margin: 8px 0 10px 0;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 4px;
}

.range-track {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.range-fill {
    height: 100%;
    background: var(--card-theme-color, var(--accent-cyan));
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Mini Sparkline inside Card */
.sparkline-container {
    height: 52px;
    width: 100%;
    margin-top: 4px;
}

/* Skeleton Loading */
.skeleton-card {
    height: 180px;
    background: linear-gradient(90deg, #111827 25%, #1f2937 50%, #111827 75%);
    background-size: 200% 100%;
    animation: skeletonLoading 1.5s infinite;
}

@keyframes skeletonLoading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   Main Chart Panel
   ========================================================================== */

.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.chart-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.view-tabs {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border-color);
}

.tab-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: #1e293b;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.chart-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.chart-controls.hidden {
    display: none !important;
}

.indicator-toggles {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.toggle-label input {
    cursor: pointer;
    accent-color: var(--accent-cyan);
}

.control-hint {
    font-size: 12px;
    color: var(--text-muted);
}

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

.echarts-box {
    width: 100%;
    height: 100%;
}

.chart-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.chart-loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(56, 189, 248, 0.2);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ==========================================================================
   Macro Matrix Table
   ========================================================================== */

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

.panel-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.panel-info {
    font-size: 12px;
    color: var(--text-muted);
}

.table-responsive {
    overflow-x: auto;
}

.macro-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.macro-table th {
    padding: 10px 14px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

.macro-table td {
    padding: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    vertical-align: middle;
}

.macro-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.ticker-cell {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent-cyan);
}

.name-cell {
    font-weight: 600;
    color: var(--text-primary);
}

.category-sub {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

.price-cell {
    font-family: var(--font-mono);
    font-weight: 700;
}

.role-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.app-footer {
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-muted);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.status-badge {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */

@media (max-width: 1200px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 12px;
    }
    
    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }
    
    .header-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .chart-controls {
        width: 100%;
    }

    .chart-canvas-wrapper {
        height: 380px;
    }
}
