/* ============================================
   STOCKET Design System - Shared Variables & Styles
   ============================================ */

:root {
    /* Brand Colors - warm paper accent */
    --brand: #a33a32;
    --brand-light: #f1d7d4;
    --brand-border: #dfb9af;
    --brand-hover: #f6e9e5;
    --brand-hover-bg: #f6e9e5;
    --brand-hover-border: #ead5cf;

    /* Data Accent Colors */
    --accent: #6f7f87;
    --accent-light: #eef2f1;
    --accent-secondary: #61757b;
    --accent-secondary-light: #eef2f1;
    --accent-tertiary: #8f856f;
    --accent-info: #6f7f87;

    /* Semantic Colors */
    --up: #587a60;
    --up-bg: #edf4ef;
    --down: #9a5c56;
    --down-bg: #f7ece8;
    --neutral: #96978e;

    /* Surface Layers - warm research-paper style */
    --bg-base: #f3f4f1;
    --bg-surface: #faf9f6;
    --bg-elevated: #ffffff;
    --bg-hover: rgba(47, 49, 47, 0.045);
    --bg-overlay: rgba(47, 49, 47, 0.22);
    --overlay: rgba(250, 249, 246, 0.86);

    /* Borders - Subtle, not harsh */
    --border: #deded6;
    --border-hover: #d2d0c7;
    --border-active: #dfb9af;

    /* Text */
    --text-primary: #2f312f;
    --text-secondary: #666860;
    --text-muted: #96978e;
    --text-dim: #b7b6ad;

    /* Spacing */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    /* Shadows */
    --shadow-sm: 0 3px 10px rgba(64, 61, 53, 0.07);
    --shadow-md: 0 10px 28px rgba(64, 61, 53, 0.08);
    --shadow-lg: 0 18px 48px rgba(64, 61, 53, 0.12);
    --shadow-glow: 0 0 0 1px var(--border-active), 0 10px 28px rgba(64, 61, 53, 0.08);

    /* Typography */
    --font-main: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "STSong", Georgia, serif;
    --font-number: "SF Mono", "Menlo", "Monaco", "Cascadia Code", monospace;
}

/* ============================================
   Typography
   ============================================ */
html, body {
    font-family: var(--font-main);
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 16px;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 数字统一字面 */
.summary-card-value,
.data-value,
.value-positive,
.value-negative,
.rank-cell,
.breadth-table td,
.stocks-table td,
.history-table td {
    font-family: var(--font-number);
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.data-value {
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   Sidebar Styles
   ============================================ */
.sidebar-group {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 6px;
    background: var(--bg-base);
}

.sidebar-group-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-group-header:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.sidebar-group-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.sidebar-group-icon {
    font-size: 18px;
    color: var(--text-muted);
}

.sidebar-group-content {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-group.collapsed .sidebar-group-content {
    display: none;
}

.sidebar-item:hover {
    background-color: var(--bg-hover);
}

/* 全站侧边栏文字体系（统一栏目风格，使用更高优先级覆盖各页面局部规则） */
aside .sidebar-group-header {
    font-family: var(--font-main) !important;
    font-weight: 700 !important;
    color: var(--text-secondary) !important;
}

aside .sidebar-group-title,
aside .sidebar-group-title.sidebar-text {
    font-family: var(--font-main) !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    letter-spacing: 0.01em !important;
    color: var(--text-secondary) !important;
}

aside a.sidebar-item,
aside .sidebar-item {
    font-family: var(--font-main) !important;
    font-weight: 650 !important;
    letter-spacing: 0 !important;
    color: var(--text-secondary) !important;
}

aside .sidebar-item .sidebar-text,
aside .sidebar-item .sidebar-text.text-sm,
aside .sidebar-item .sidebar-text.font-medium,
aside .sidebar-item span:not(.material-icons-round) {
    font-family: var(--font-main) !important;
    font-size: 15px !important;
    font-weight: 650 !important;
    color: var(--text-secondary) !important;
}

aside .sidebar-item .material-icons-round,
aside .sidebar-group-icon {
    font-size: 21px !important;
    color: #8f8d84 !important;
    font-variation-settings: 'wght' 500;
}

aside .sidebar-item:hover .sidebar-text,
aside .sidebar-item:hover span:not(.material-icons-round),
aside .sidebar-item:hover .material-icons-round,
aside .sidebar-group-header:hover .sidebar-group-title,
aside .sidebar-group-header:hover .sidebar-group-icon {
    color: var(--text-primary) !important;
}

/* 全站侧边栏强制统一（跨栏目统一视觉，不依赖页面私有样式） */
aside .sidebar-group {
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.66) !important;
    padding: 8px !important;
}

aside .sidebar-group-header {
    min-height: 34px;
    border-radius: 10px !important;
}

aside .sidebar-item {
    min-height: 44px;
    border-radius: 10px !important;
}

aside .sidebar-item .sidebar-text,
aside .sidebar-item span:not(.material-icons-round) {
    color: var(--text-secondary) !important;
    font-size: 15px !important;
    font-weight: 700 !important;
}

aside .sidebar-group-title,
aside .sidebar-group-title.sidebar-text {
    color: var(--text-secondary) !important;
    font-size: 12px !important;
    font-weight: 700 !important;
}

aside .sidebar-item .material-icons-round,
aside .sidebar-group-icon {
    color: #8f8d84 !important;
    font-size: 22px !important;
}

/* Sidebar collapse states */
aside.collapsed .sidebar-group {
    margin-bottom: 8px;
    border: 0;
    background: transparent;
    padding: 0;
}

aside.collapsed .sidebar-group-header {
    display: none;
}

aside.collapsed .sidebar-group-content {
    display: flex !important;
    margin-top: 0;
}

/* ============================================
   Transitions & Animations
   ============================================ */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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

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

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

/* ============================================
   Skeleton Loading
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-surface) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-card {
    height: 80px;
    border-radius: var(--radius-md);
}

.skeleton-chart {
    height: 300px;
    border-radius: var(--radius-lg);
}

/* ============================================
   Card Component
   ============================================ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

/* ============================================
   Value Colors
   ============================================ */
.value-positive {
    color: var(--up);
    font-weight: 600;
}

.value-negative {
    color: var(--down);
    font-weight: 600;
}

.value-neutral {
    color: var(--text-muted);
}

/* ============================================
   Custom Scrollbar
   ============================================ */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ============================================
   Summary Cards — White Gradient Border Style
   ============================================ */
.summary-cards {
    position: relative;
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-radius: 16px;
    border: 1px solid transparent;
    background:
        linear-gradient(180deg, rgba(15, 16, 20, 0.98), rgba(11, 12, 15, 0.98)) padding-box,
        linear-gradient(180deg, rgba(255, 255, 255, 0.46) 0%, rgba(255, 255, 255, 0.18) 38%, rgba(255, 255, 255, 0.08) 100%) border-box;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 28px rgba(0, 0, 0, 0.35);
}

.summary-cards::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 35%);
}

.summary-card {
    flex: 1;
    padding: 22px 20px;
    position: relative;
    transition: background 0.2s ease;
    min-width: 0;
}

.summary-card + .summary-card {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.summary-card:hover {
    background: rgba(255, 255, 255, 0.02);
}

.summary-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
}

.summary-card-label {
    font-size: 12px;
    font-weight: 500;
    color: rgba(239, 241, 245, 0.72);
    letter-spacing: 0;
    text-transform: none;
}

.summary-card-icon {
    display: none;
}

.summary-card-value {
    font-size: 34px;
    font-weight: 700;
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -0.03em;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.07);
}

.summary-card-sub {
    font-size: 12px;
    color: rgba(226, 232, 240, 0.52);
    margin-top: 10px;
    font-variant-numeric: tabular-nums;
    line-height: 1.35;
}

.summary-card-value.positive { color: #4ade80; }
.summary-card-value.negative { color: #fb7185; }

/* ============================================
   Table Heatmap Bar Background
   ============================================ */
.heatmap-bar {
    position: relative;
}

.heatmap-bar::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 2px;
    opacity: 0.15;
    z-index: 0;
    transition: width 0.3s ease;
}

.heatmap-bar.positive::before {
    background: var(--up);
    width: var(--bar-width, 0%);
}

.heatmap-bar.negative::before {
    background: var(--down);
    width: var(--bar-width, 0%);
}

.heatmap-bar > * {
    position: relative;
    z-index: 1;
}

/* ============================================
   Responsive Utilities
   ============================================ */

/* Tablet */
@media (max-width: 1024px) {
    .summary-cards {
        flex-wrap: wrap;
    }
    .summary-card {
        flex: 1 1 calc(33.333% - 1px);
    }
}

/* ============================================
   Warm Paper Global Components
   ============================================ */
body {
    background:
        linear-gradient(90deg, rgba(47, 49, 47, 0.018) 1px, transparent 1px),
        linear-gradient(180deg, rgba(47, 49, 47, 0.014) 1px, transparent 1px),
        var(--bg-base);
    background-size: 42px 42px, 42px 42px, auto;
}

main,
.main-content,
.content-area,
.page-container,
.dashboard-container {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
}

.card,
.summary-cards,
.summary-card,
.chart-wrapper,
.compare-chart-wrapper,
.table-wrapper,
.stocks-table-wrapper,
.breadth-table,
.filter-panel,
.control-panel,
.section-panel {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow-sm) !important;
    color: var(--text-secondary) !important;
}

.summary-cards {
    overflow: hidden;
}

.summary-cards::after {
    display: none;
}

.summary-card + .summary-card {
    border-left: 1px solid var(--border) !important;
}

.summary-card:hover,
.card:hover {
    background: #fffdfb !important;
    border-color: var(--border-hover) !important;
    box-shadow: var(--shadow-md) !important;
}

.page-title,
.section-title,
.summary-card-value,
h1,
h2,
h3,
h4 {
    color: var(--text-primary) !important;
    letter-spacing: 0 !important;
}

.section-title,
.summary-card-label,
.summary-card-sub,
.data-value,
label,
th {
    color: var(--text-secondary) !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
}

.summary-card-value {
    font-size: 34px;
    text-shadow: none;
}

button,
input,
select,
textarea,
.btn,
.filter-btn,
.tab-btn {
    font-family: var(--font-main) !important;
    border-radius: 7px !important;
}

input,
select,
textarea,
.search-input {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-sm) !important;
}

input:focus,
select:focus,
textarea:focus,
.search-input:focus {
    border-color: var(--brand-border) !important;
    box-shadow: 0 0 0 3px rgba(143, 133, 111, 0.12), var(--shadow-sm) !important;
    outline: none !important;
}

table,
.stocks-table,
.breadth-table table {
    color: var(--text-secondary) !important;
}

th {
    background: var(--bg-surface) !important;
    border-bottom: 1px solid var(--border) !important;
}

td {
    border-bottom-color: var(--border) !important;
}

tr:hover,
.stocks-table tr:hover {
    background: var(--brand-hover-bg) !important;
}

.tag,
.badge,
.pill,
.filter-tag,
.status-badge {
    background: #f5f0ea !important;
    border: 1px solid var(--border) !important;
    color: #756d64 !important;
    border-radius: 6px !important;
}

a {
    color: #0f766e;
}

code,
pre {
    font-family: var(--font-number) !important;
}

code {
    color: #9f2f2b !important;
    background: #f4eeee !important;
    border: 1px solid #ead5d2 !important;
    border-radius: 4px !important;
    padding: 1px 5px;
}

pre {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
}

/* Mobile */
@media (max-width: 768px) {
    .summary-cards {
        flex-wrap: wrap;
        border-radius: 12px;
    }
    .summary-card {
        flex: 1 1 calc(50% - 1px);
        padding: 18px 14px;
        border-left: none;
        border-bottom: 1px solid var(--border);
    }
    .summary-card:nth-child(odd) {
        border-right: 1px solid var(--border);
    }
    .summary-card:nth-last-child(-n+2) {
        border-bottom: none;
    }
    .summary-card:last-child:nth-child(odd) {
        border-right: none;
    }
    .summary-card + .summary-card {
        border-left: none;
    }
    .summary-card-value {
        font-size: 24px;
    }

    /* Sidebar: overlay on mobile */
    aside {
        position: fixed !important;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    aside.mobile-open {
        transform: translateX(0);
    }
    aside.collapsed {
        transform: translateX(-100%);
    }

    /* Full-width content on mobile */
    main {
        margin-left: 0 !important;
    }

    /* Stack header items */
    header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px !important;
    }

    /* Responsive tables: horizontal scroll */
    .breadth-table,
    .stocks-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .breadth-table table,
    .stocks-table {
        min-width: 600px;
    }

    /* Chart containers */
    .chart-wrapper,
    .compare-chart-wrapper {
        height: 280px !important;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .summary-cards {
        flex-direction: column;
    }
    .summary-card {
        flex: none;
        border-right: none !important;
    }
    .summary-card + .summary-card {
        border-top: 1px solid var(--border);
    }
    .summary-card-value {
        font-size: 22px;
    }
}
