:root {
    /* Color Palette */
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    
    /* Gradients */
    --header-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --card-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --trend-gradient: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);

    /* Spacing & Radius */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Transitions */
    --transition-base: all 0.3s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

/* 页面头部 */
.header {
    text-align: center;
    margin-bottom: 48px;
    padding: 40px 0 80px; /* 增加底部内边距，为绝对定位的元素留出空间，防止重叠 */
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.page-nav {
    position: absolute;
    bottom: 20px;
    left: 20px; /* 将导航移至左下角，与右下角的语言切换平衡 */
    z-index: 10;
}

/* 新的胶囊式导航样式 */
.nav-segment-control {
    display: inline-flex;
    background-color: #f3f4f6;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.nav-segment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    border: 1px solid transparent;
}

.nav-segment:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.03);
}

.nav-segment.active {
    background-color: white;
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.05);
}

.nav-icon {
    font-size: 1.1em;
    line-height: 1;
}

.nav-hint {
    font-size: 0.75em;
    color: var(--text-secondary);
    font-weight: 400;
    opacity: 0.8;
    margin-left: 4px;
    white-space: nowrap;
}

.language-switcher {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 10;
}

#languageSelect {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9em;
    background-color: white;
    transition: var(--transition-base);
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

#languageSelect:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: var(--header-gradient);
}

.header h1 {
    font-size: 2.25em;
    font-weight: 800;
    margin-bottom: 12px;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    width: 56px;
    height: 56px;
    background: var(--header-gradient);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
    font-style: normal;
}

.header-text {
    background: var(--header-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* 通用 Section 样式 */
section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

section h2 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 板块一：全局指挥舱 (Overview) */
.dashboard-overview {
    background: transparent;
    padding: 0;
    box-shadow: none;
    border: none;
}

.dashboard-overview h2 {
    padding-left: 10px;
}

.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
}

.kpi-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(229, 231, 235, 0.5);
    transition: var(--transition-base);
    position: relative;
    overflow: hidden;
    color: var(--text-primary);
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--header-gradient);
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.kpi-label {
    font-size: 0.875em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.kpi-value {
    font-size: 2.25em;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.1;
}

.kpi-detail, .kpi-trend {
    font-size: 0.875em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 板块二：动态榜单 (Leaderboard) */
.leaderboard-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    background: var(--bg-color);
    padding: 16px;
    border-radius: var(--radius-md);
}

.search-input, .sort-select {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95em;
    background-color: white;
    transition: var(--transition-base);
    color: var(--text-primary);
}

.search-input {
    flex: 1;
    min-width: 200px;
}

.search-input:focus, .sort-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: var(--bg-color);
    border-bottom: 2px solid var(--border-color);
}

th {
    padding: 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f9fafb;
}

td {
    padding: 14px 16px;
    vertical-align: middle;
    color: var(--text-primary);
    font-size: 0.95em;
}

td strong {
    color: var(--primary-color);
    font-weight: 600;
}

.app-name-link {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

.app-name-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.app-name-link strong {
    color: inherit;
}

.sparkline-container {
    width: 100px;
    height: 32px;
}

.region-flag {
    font-size: 1.4em;
    line-height: 1.0;
    vertical-align: middle;
}

.region-code {
    font-size: 1.0em;
    vertical-align: middle;
}

.growth-rate, .growth-amount {
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    display: inline-block;
}

.growth-rate.positive, .growth-amount.positive {
    color: #065f46;
    background-color: #d1fae5;
}

.growth-rate.negative, .growth-amount.negative {
    color: #991b1b;
    background-color: #fee2e2;
}

/* 板块三：深度分析 (Charts) */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 24px;
}

.chart-container {
    background: white;
    padding: 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.chart-container h3 {
    margin-bottom: 20px;
    font-size: 1.1em;
    color: var(--text-primary);
    font-weight: 600;
    border-left: 4px solid var(--primary-color);
    padding-left: 12px;
}

.chart {
    width: 100%;
    height: 350px;
}

#chartTopApps, #chartGenres {
    height: 600px;
}

/* 板块四：黑马雷达 (Trend Spotter) */
.trend-spotter {
    margin-bottom: 0;
}

.section-desc {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95em;
}

.trending-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.trending-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.trending-card {
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: var(--transition-base);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.trending-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.03) 0%, rgba(244, 63, 94, 0.03) 100%);
    z-index: -1;
}

.trending-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(244, 63, 94, 0.3);
}

.trending-card h3 {
    font-size: 1.25em;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-weight: 700;
}

.trending-card .growth-badge {
    display: inline-block;
    background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85em;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(236, 72, 153, 0.3);
}

.trending-card .app-info {
    font-size: 0.9em;
    color: var(--text-secondary);
    display: grid;
    gap: 6px;
}

.trending-card .app-info div {
    display: flex;
    align-items: center;
    gap: 8px;
}

.trending-card .app-info div::before {
    content: '•';
    color: #f43f5e;
    font-weight: bold;
}

/* Loading Spinner */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.5s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    font-weight: 600;
    color: var(--text-secondary);
}

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

.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c7c7cc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1aa;
}

/* 应用详情弹窗 */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
    padding: 20px;
}

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

.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 0;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    background: white;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.modal-close {
    color: var(--text-secondary);
    font-size: 28px;
    font-weight: 400;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f3f4f6;
}

.modal-close:hover {
    background: #e5e7eb;
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-body {
    padding: 32px;
    overflow-y: auto;
    flex: 1;
    background: #f9fafb;
}

.modal-chart-container {
    background: white;
    padding: 24px;
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.modal-chart-container h3 {
    margin-bottom: 24px;
    font-size: 1.1em;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-chart-container h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 2px;
}

.modal-chart {
    width: 100%;
    height: 400px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { 
        transform: scale(0.95);
        opacity: 0; 
    }
    to { 
        transform: scale(1);
        opacity: 1; 
    }
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header {
        padding: 30px 16px 80px;
    }
    
    .header h1 {
        font-size: 1.75em;
    }
    
    .page-nav {
        width: calc(100% - 32px);
        left: 16px;
        right: 16px;
        bottom: 70px; /* 给语言选择器留出空间 */
        display: flex;
        justify-content: center;
    }
    
    .nav-segment-control {
        width: 100%;
        justify-content: space-between;
    }
    
    .nav-segment {
        flex: 1;
        justify-content: center;
        padding: 6px 8px;
        font-size: 0.8em;
    }
    
    .leaderboard-controls {
        flex-direction: column;
    }
    
    .search-input, .sort-select {
        width: 100%;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    #chartTopApps, #chartGenres {
        height: 400px;
    }
    
    .kpi-cards {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .modal {
        padding: 0;
    }
    
    .modal-header {
        padding: 20px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .modal-chart-container {
        padding: 16px;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .modal-chart {
        flex: 1;
        min-height: 300px;
    }
    
    .language-switcher {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: 20px;
        width: max-content;
    }
}
