/* ========================================
   Global Variables & Theme
   ======================================== */
:root {
    /* Premium Dark Theme Colors */
    --bg-color: #0f1115;
    --panel-bg: #161b22;
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent-color: #58a6ff;
    --success-color: #238636;
    --danger-color: #da3633;
    --warning-color: #d29922;

    /* Typography Scale */
    --text-micro:  0.625rem;   /* 10px — 超密集标签/角标 */
    --text-xs:     0.75rem;    /* 12px — Badge/次要辅助文字 */
    --text-sm:     0.8125rem;  /* 13px — 弱化正文/摘要 */
    --text-base:   0.9375rem;  /* 15px — 标准正文 */
    --text-md:     1rem;       /* 16px — 强调正文/表头 */
    --text-lg:     1.25rem;    /* 20px — 面板标题 */
    --text-xl:     1.5rem;     /* 24px — 页面标题 */
    --text-2xl:    2.5rem;     /* 40px — 装饰性大字/图标 */

    /* Line Height */
    --leading-tight:   1.25;
    --leading-normal:  1.5;
    --leading-relaxed: 1.65;

    /* Layout */
    --header-height: 60px;
    --subnav-height: 48px;
    --panel-radius: 8px;
    --spacing: 16px;
    
    /* Global Sidebar layout variables */
    --sidebar-width: 240px;
}

body.sidebar-collapsed {
    --sidebar-width: 68px;
}

@media (max-width: 768px) {
    :root, body, body.sidebar-collapsed {
        --sidebar-width: 0px;
    }
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-variant-numeric: tabular-nums;
    min-height: 100vh;
    overflow-y: auto;
    padding-left: var(--sidebar-width);
    transition: padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.share-image-toast {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 99999;
    max-width: min(320px, calc(100vw - 32px));
    padding: 10px 14px;
    border: 1px solid rgba(88, 166, 255, 0.3);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.94);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    color: #e2e8f0;
    font-size: var(--text-sm);
    font-weight: 700;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.share-image-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.share-image-toast.error {
    border-color: rgba(239, 68, 68, 0.42);
    color: #fca5a5;
}

.share-btn-text {
    white-space: nowrap;
}

/* ========================================
   Global Sidebar (Premium Terminal Style)
   ======================================== */
.global-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    background: rgba(22, 27, 34, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1050; /* 绝对贯通，覆盖 topbar (1000) */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    overflow: hidden;
}

@media (max-width: 768px) {
    .global-sidebar {
        display: flex !important;
        transform: translateX(-100%);
        width: 260px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .global-sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1040; /* Below sidebar 1050 */
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }
    
    /* Ensure contents are fully visible in mobile sidebar */
    .global-sidebar .user-profile-info,
    .global-sidebar .nav-text,
    .global-sidebar .sidebar-brand-text,
    .global-sidebar .credit-text {
        opacity: 1 !important;
        pointer-events: auto !important;
        transform: none !important;
        display: flex !important;
        width: auto !important;
    }
    
    .global-sidebar .sidebar-logo {
        padding-left: 20px !important;
        padding-right: 20px !important;
    }
    
    .global-sidebar .sidebar-user-profile {
        padding: 12px 20px !important;
        justify-content: flex-start !important;
    }
    
    .global-sidebar .sidebar-footer-controls {
        flex-direction: row !important;
    }
    
    /* Hide the collapse toggle button inside sidebar on mobile */
    .sidebar-toggle-btn {
        display: none !important;
    }
}

.sidebar-logo {
    height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
    padding-top: max(0px, env(safe-area-inset-top));
    display: flex;
    align-items: center;
    padding-left: 20px;
    padding-right: 20px;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    white-space: nowrap;
    flex-shrink: 0;
    transition: padding 0.3s ease;
}

body.sidebar-collapsed .sidebar-logo {
    padding-left: 22px;
    padding-right: 22px;
}

.sidebar-logo a {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: var(--text-base);
}

.sidebar-logo .icon {
    font-size: var(--text-lg);
    color: var(--accent-color);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-brand-text {
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
}

body.sidebar-collapsed .sidebar-brand-text {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
}

.sidebar-user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    white-space: nowrap;
    flex-shrink: 0;
    transition: padding 0.3s ease;
}

body.sidebar-collapsed .sidebar-user-profile {
    padding: 12px 14px;
    justify-content: center;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-sm);
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.user-profile-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
}

body.sidebar-collapsed .user-profile-info {
    opacity: 0;
    width: 0;
    pointer-events: none;
    transform: translateX(-10px);
    display: none;
}

.sidebar-user-profile .avatar-link {
    text-decoration: none;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    flex-shrink: 0;
}

.sidebar-user-profile .avatar-link:hover .user-avatar {
    transform: scale(1.06);
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.5);
}

.sidebar-user-profile .user-name-text {
    font-size: var(--text-sm);
    color: var(--text-primary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    transition: color 0.2s ease;
}

.sidebar-user-profile .user-name-text:hover {
    color: var(--accent-color);
}

.sidebar-user-profile .user-tier-container {
    display: inline-flex;
}

.sidebar-user-profile .tier-badge-link {
    font-size: var(--text-micro);
    padding: 2px 6px;
    border-radius: 4px;
    text-decoration: none;
    line-height: 1;
    display: inline-block;
}

.sidebar-menu {
    flex: 1;
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    font-size: var(--text-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    gap: 12px;
    position: relative;
}

.sidebar-menu a .nav-icon {
    font-size: 1.15em;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, color 0.2s ease;
}

.sidebar-menu a .nav-text {
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
}

body.sidebar-collapsed .sidebar-menu a .nav-text {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
}

/* Hover 微动效 */
.sidebar-menu a:hover {
    color: var(--text-primary);
    background: rgba(88, 166, 255, 0.08);
}

.sidebar-menu a:hover .nav-icon {
    color: var(--accent-color);
    transform: scale(1.05);
}

/* 活性选中态（Active）左侧发光指示线 & 图标微光 */
.sidebar-menu a.active {
    color: var(--accent-color);
    background: rgba(88, 166, 255, 0.12);
    font-weight: 500;
}

.sidebar-menu a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 15%;
    height: 70%;
    width: 3px;
    background: var(--accent-color);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px var(--accent-color), 0 0 4px var(--accent-color);
    transition: all 0.2s ease;
}

.sidebar-menu a.active .nav-icon {
    color: var(--accent-color);
    filter: drop-shadow(0 0 6px rgba(88, 166, 255, 0.6));
}

/* 侧栏底部折叠控制区 */
.sidebar-footer {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}

.sidebar-footer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body.sidebar-collapsed .sidebar-footer-controls {
    flex-direction: column;
    gap: 8px;
}

body.sidebar-collapsed .credit-text {
    display: none;
}

.sidebar-logout-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    outline: none;
}

.sidebar-logout-btn:hover {
    background: rgba(218, 54, 51, 0.15);
    color: var(--danger-color);
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    outline: none;
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.sidebar-toggle-btn .toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar-toggle-btn .toggle-icon {
    transform: rotate(180deg);
}

/* 纯 CSS Tooltip 浮层（折叠状态下悬浮显示） */
@media (min-width: 769px) {
    body.sidebar-collapsed .sidebar-menu a::after {
        content: attr(data-title);
        position: absolute;
        left: 80px;
        top: 50%;
        transform: translateY(-50%) translateX(10px);
        background: #161b22;
        color: var(--text-primary);
        padding: 6px 10px;
        border-radius: 4px;
        font-size: var(--text-xs);
        border: 1px solid var(--border-color);
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1060;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    }
    
    body.sidebar-collapsed .sidebar-menu a:hover::after {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* ========================================
   Global Navigation Bar
   ======================================== */
.global-nav {
    /* 顶底 Safe Area 适配 */
    padding-top: max(0px, env(safe-area-inset-top));
    height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
    background-color: rgba(22, 27, 34, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end; /* 右侧对齐，释放左侧空间 */
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    position: sticky;
    top: 0;
    z-index: 1000;
    gap: 16px;
    box-sizing: border-box;
    transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-sidebar-toggle {
    display: none;
}

@media (max-width: 768px) {
    .mobile-sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        padding: 6px;
        margin-right: auto; /* Push everything else to the right */
        border-radius: 6px;
    }
    .mobile-sidebar-toggle:hover {
        background: rgba(255, 255, 255, 0.1);
    }
}

.global-nav .logo {
    font-size: var(--text-lg);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.global-nav .logo a {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}

.global-nav .nav-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.global-nav .nav-menu a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: var(--text-base);
    transition: all 0.2s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.global-nav .nav-text-short {
    display: none;
}

.global-nav .nav-text-full {
    display: inline;
}

/* SVG icon alignment in nav links */
.nav-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

.logout-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
}

.global-nav .nav-menu a:hover {
    color: var(--text-primary);
    background-color: rgba(88, 166, 255, 0.1);
}

.global-nav .nav-menu a.active {
    color: var(--accent-color);
    background-color: rgba(88, 166, 255, 0.15);
    font-weight: 500;
}

.global-nav .nav-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.global-nav .market-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-sm);
    white-space: nowrap;
}

.global-nav .status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

.global-nav .status-indicator.active {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.global-nav .refresh-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    white-space: nowrap;
}

.global-nav .refresh-btn:hover:not(:disabled) {
    background-color: #4a8fd9;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
}

.global-nav .refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.global-nav .refresh-timer {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

.global-nav .date-picker-group {
    display: flex;
    align-items: center;
    background-color: rgba(88, 166, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.global-nav .date-picker-group:hover {
    border-color: var(--accent-color);
    background-color: rgba(88, 166, 255, 0.1);
}

.global-nav .latest-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.global-nav .latest-btn:hover {
    color: var(--text-primary);
    background-color: rgba(88, 166, 255, 0.1);
}

.global-nav .latest-btn.active {
    background-color: var(--accent-color);
    color: white;
}

.global-nav .nav-date-input {
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    padding: 5px 10px;
    font-size: var(--text-sm);
    cursor: pointer;
    outline: none;
    font-family: inherit;
}

/* Custom calendar icon color for Chrome/Edge */
.global-nav .nav-date-input::-webkit-calendar-picker-indicator {
    filter: invert(0.8) sepia(100%) saturate(1000%) hue-rotate(180deg);
    cursor: pointer;
}

.global-nav .nav-date-input:focus {
    box-shadow: inset 0 0 0 1px var(--accent-color);
}

/* ========================================
   Sub Navigation (Module Navigation)
   ======================================== */
.sub-nav {
    height: var(--subnav-height);
    background-color: rgba(22, 27, 34, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    gap: 12px;
    position: sticky;
    top: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
    z-index: 999;
    overflow-x: auto;
    overflow-y: hidden;
}

.sub-nav.sub-nav-return-only {
    gap: 0;
}

.sub-nav::-webkit-scrollbar {
    height: 4px;
}

.sub-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sub-nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.sub-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: var(--text-sm);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sub-nav a:hover {
    color: var(--text-primary);
    background-color: rgba(88, 166, 255, 0.1);
}

.sub-nav a.active {
    color: var(--accent-color);
    background-color: rgba(88, 166, 255, 0.15);
    font-weight: 500;
}

.sub-nav a.ai-insight-return-link {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 6px;
    color: #c7d2fe;
    background-color: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(129, 140, 248, 0.36);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
    font-weight: 700;
    padding: 7px 12px;
}

.sub-nav a.ai-insight-return-link:hover,
.sub-nav a.ai-insight-return-link:focus-visible {
    color: #eef2ff;
    background-color: rgba(99, 102, 241, 0.2);
    border-color: rgba(165, 180, 252, 0.58);
    outline: none;
}

.ai-insight-return-icon {
    display: inline-flex;
    width: 1em;
    height: 1em;
}

.ai-insight-return-icon svg {
    width: 1em;
    height: 1em;
}

.ai-insight-return-text-full,
.ai-insight-return-text-compact {
    line-height: 1;
}

.ai-insight-return-text-compact {
    display: none;
}

.ai-insight-return-meta {
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1;
    padding-left: 6px;
    border-left: 1px solid rgba(129, 140, 248, 0.26);
}

/* Sub Navigation Actions (Right-aligned shortcuts) */
.sub-nav-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sub-nav-actions a.nav-action-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: var(--text-xs);
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.sub-nav-actions a.nav-action-link:hover {
    color: var(--text-primary);
    background-color: rgba(88, 166, 255, 0.1);
    border-color: rgba(88, 166, 255, 0.3);
}

.sub-nav-actions a svg {
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.1em;
}

.sub-nav-actions a.ibs-pro-nav-btn {
    padding: 6px 12px;
    font-size: var(--text-xs);
    border-radius: 6px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .sub-nav-actions {
        display: none !important;
    }
}

/* ========================================
   Common Components
   ======================================== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dashboard-grid {
    padding: var(--spacing);
    display: flex;
    flex-direction: column;
    gap: var(--spacing);
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

.panel-container {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--panel-radius);
    overflow: hidden;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(255, 255, 255, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text-primary);
}

.subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 400;
}

/* ========================================
   Responsive Design
   ======================================== */

/* Mobile Layout (max-width: 768px) - Bottom Tab Bar + Slim Top Nav */
@media (max-width: 768px) {
    :root {
        /* Typography Scaled Up for Mobile */
        --text-xs:     0.8125rem;  /* 12px → 13px */
        --text-sm:     0.875rem;   /* 13px → 14px */
        --text-base:   1rem;       /* 15px → 16px */
        --text-md:     1.0625rem;  /* 16px → 17px */
        --text-lg:     1.375rem;   /* 20px → 22px */
        --text-xl:     1.625rem;   /* 24px → 26px */

        /* Slim single-row header (down from 100px) */
        --header-height: 52px;
        /* Tab bar height token for consistent reference */
        --tab-bar-height: 56px;
    }

    /* ── Top nav: single row, no menu items ── */
    .global-nav {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
        min-height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        flex-wrap: nowrap;
        align-items: center;
        /* Auto-hide transition */
        transition: transform 0.3s ease;
        box-sizing: border-box;
    }

    /* When nav-hidden class is applied, slide the nav out of view */
    .global-nav.nav-hidden {
        transform: translateY(-100%);
    }

    .sub-nav {
        /* Auto-hide transition - sub-nav follows global-nav */
        transition: transform 0.3s ease;
    }

    .sub-nav.nav-hidden {
        transform: translateY(calc(-100% - var(--header-height) - max(0px, env(safe-area-inset-top))));
    }

    .global-nav .logo {
        flex: 0 0 auto;
        min-width: 0;
        margin-right: auto;
    }

    /* 隐藏 壹桩·捞鱼雷达 文本以节省空间 */
    .global-nav .logo a span:last-child {
        display: none;
    }

    /* Menu items moved to bottom Tab Bar — hide from top nav */
    .global-nav .nav-menu {
        display: none;
    }

    .global-nav .nav-controls {
        flex-shrink: 0;
    }

    /* Ensure sub-nav sticks below the slim global nav */
    .sub-nav {
        top: var(--header-height);
    }

    /* ── Bottom padding to prevent content from being covered by Tab Bar ── */
    body {
        padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px));
    }

    /* ── Edge-to-Edge: 去嵌套优化 ── */
    .dashboard-grid {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .panel-container {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* Tablet Layout (769px - 1200px) & Foldable Unfolded */
@media (min-width: 700px) and (max-width: 1200px) {
    /* 展开态/平板双列流式卡片排版，防拉伸与坍塌 */
    .dashboard-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: var(--spacing) !important;
        flex-direction: unset !important;
    }
    
    .chart-container, .chart-wrapper, .echarts {
        height: 380px !important;
    }

    .global-nav {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        gap: 4px;
        box-sizing: border-box;
        justify-content: flex-end; /* 保持靠右 */
    }

    .global-nav .nav-controls {
        gap: 6px;
    }

    /* 隐藏中屏下非核心的时间指示与文字以防止挤压折行 */
    .global-nav .refresh-timer,
    .global-nav .market-status .status-text {
        display: none !important;
    }

    .global-nav .market-status {
        gap: 0;
    }

    /* 稍微压缩日期按钮 */
    .global-nav .date-picker-group .latest-btn {
        padding: 3px 6px;
        font-size: 11px;
    }

    .global-nav .nav-date-display {
        padding: 4px 6px !important;
        font-size: 11px !important;
    }

    .sub-nav {
        top: calc(var(--header-height) + max(0px, env(safe-area-inset-top)));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        gap: 6px;
    }

    .sub-nav a.ai-insight-return-link {
        padding: 7px 10px;
    }
}

@media (max-width: 600px) {

    .global-nav .refresh-timer,
    .global-nav .status-text {
        display: none;
    }

    .global-nav .refresh-btn {
        padding: 4px 10px;
        font-size: var(--text-xs);
    }

    .global-nav .latest-btn {
        padding: 6px 8px;
        font-size: var(--text-xs);
    }

    .global-nav .nav-date-input {
        padding: 5px 4px;
        width: 40px;
        /* Only show the icon on very small screens */
    }

    .sub-nav a.ai-insight-return-link {
        gap: 5px;
        padding: 7px 10px;
    }

    .ai-insight-return-text-full,
    .ai-insight-return-meta {
        display: none;
    }

    .ai-insight-return-text-compact {
        display: inline;
    }

    .global-nav .nav-date-input::-webkit-datetime-edit {
        display: none;
    }


    .dashboard-grid {
        padding: 8px 0;
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        gap: 12px;
    }
}

/* ========================================
   Bottom Tab Bar (Mobile only, ≤768px)
   ======================================== */
.bottom-tab-bar {
    display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {
    .bottom-tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--tab-bar-height, 56px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: rgba(22, 27, 34, 0.97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border-color);
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        z-index: 1000;
    }

    .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 0;
        min-height: 48px; /* 触控区域 ≥ 48px */
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.625rem; /* 10px — tab label */
        line-height: 1;
        transition: color 0.2s ease;
        position: relative;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }

    .tab-item .tab-icon {
        font-size: 1.25rem; /* 20px icon */
        line-height: 1;
        transition: transform 0.2s ease;
    }

    .tab-item:active .tab-icon {
        transform: scale(0.9);
    }

    .tab-item.active {
        color: var(--accent-color);
    }

    /* 当前页顶部圆点指示器 */
    .tab-item.active::before {
        content: '';
        position: absolute;
        top: 2px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--accent-color);
    }

    .tab-item .tab-label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 64px;
    }
}

/* ========================================
   Bottom Sheet (More pages)
   ======================================== */
.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 1001;
    transition: background 0.3s ease;
    pointer-events: none;
}

.bottom-sheet-overlay.visible {
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    background: var(--panel-bg);
    border-radius: 16px 16px 0 0;
    border-top: 1px solid var(--border-color);
    z-index: 1002;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.bottom-sheet.open {
    transform: translateY(0);
}

/* Drag handle indicator */
.sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: grab;
}

.sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color);
}

/* Sheet header */
.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px 12px;
    border-bottom: 1px solid var(--border-color);
}

.sheet-title {
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text-primary);
}

.sheet-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
}

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

/* Sheet menu items */
.sheet-menu {
    padding: 8px 0;
    list-style: none;
}

.sheet-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-base);
    transition: all 0.15s ease;
    min-height: 52px;
    position: relative;
    cursor: pointer;
}

.sheet-menu-item:active {
    background: rgba(88, 166, 255, 0.08);
}

.sheet-menu-item .sheet-item-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.sheet-menu-item.active {
    color: var(--accent-color);
}

/* 当前页左侧 accent 竖条 */
.sheet-menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    border-radius: 0 2px 2px 0;
    background: var(--accent-color);
}

/* ========================================
   Ultra-narrow screen (≤360px, e.g. fold outer)
   ======================================== */
@media (max-width: 360px) {
    /* Tab bar: icon only, no text */
    .tab-item .tab-label {
        display: none !important;
    }

    .bottom-tab-bar {
        height: calc(48px + max(0px, env(safe-area-inset-bottom)));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
        box-sizing: border-box;
    }

    .tab-item {
        min-height: 40px;
    }

    .tab-item .tab-icon {
        font-size: 1.375rem; /* 22px — slightly larger when no label */
    }

    /* Sheet adapts to full width */
    .bottom-sheet {
        max-height: 70vh;
    }

    /* 压缩极窄外屏顶栏 */
    .global-nav {
        padding-left: 4px;
        padding-right: 4px;
        gap: 2px;
    }
    .global-nav .logo a span:last-child {
        display: none !important;
    }
    .global-nav .nav-controls {
        gap: 4px;
    }
    .global-nav .refresh-btn {
        padding: 4px 6px;
        font-size: 10px;
    }
}

/* ========================================
   Landscape low-height: hide Tab Bar (审核意见)
   ======================================== */
@media (orientation: landscape) and (max-height: 360px) {
    .bottom-tab-bar {
        display: none;
    }

    body {
        padding-bottom: 0;
    }
}

/* Safe Area support for all viewports */
body {
    padding-top: env(safe-area-inset-top);
}

/* ========================================
   Accessibility Helpers
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   Plotly Chart Watermark (CSS Overlay)
   ======================================== */
.plotly-watermark {
    position: relative;
}

.plotly-watermark::after {
    content: attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark) '  ' attr(data-watermark);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 40px;
    font-size: 20px;
    font-weight: 600;
    font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
    color: rgba(255, 255, 255, 0.06);
    transform: rotate(-25deg);
    transform-origin: center center;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    white-space: nowrap;
    letter-spacing: 8px;
    word-spacing: 60px;
    line-height: 80px;
}

/* ========================================
   Modal UI (Glassmorphism & General)
   ======================================== */
.modal-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 17, 21, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(145deg, #1e232d, #141820);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    width: 90%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.modal-overlay.show .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
}

.modal-header h3 {
    color: #e6edf3;
    font-size: var(--text-lg);
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #8b949e;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
}

.modal-close:hover {
    color: #e6edf3;
    background: rgba(248, 81, 73, 0.8);
    border-color: #f85149;
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: 70vh;
}

/* ========================================
   Inline Restricted Content Hint (叠加在受限容器上)
   ======================================== */
.chart-paywall-hint {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 21, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: inherit;
}

.chart-paywall-inner {
    text-align: center;
    padding: 16px 20px;
}

.chart-paywall-icon {
    font-size: 28px;
    margin-bottom: 8px;
    opacity: 0.8;
}

.chart-paywall-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: 12px;
}

.chart-paywall-btn {
    background: linear-gradient(135deg, rgba(210, 153, 34, 0.2), rgba(226, 179, 64, 0.1));
    border: 1px solid rgba(210, 153, 34, 0.4);
    color: var(--warning-color);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-paywall-btn:hover {
    background: linear-gradient(135deg, rgba(210, 153, 34, 0.3), rgba(226, 179, 64, 0.15));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(210, 153, 34, 0.2);
}

/* Inline chart-paywall-btn as <a> tag — reset link styles */
a.chart-paywall-btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}


/* ========================================
   Nav Tier Badge Link (导航栏等级标签)
   ======================================== */
.tier-badge-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: var(--text-xs);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tier-badge-link:hover {
    filter: brightness(1.2);
    transform: translateY(-1px);
}
