﻿/* ========== ROOT VARIABLES ========== */
:root {
    /* Theme-specific colors (change with theme) */
    --accent-color: rgba(255, 100, 150, 1);
    --accent-light: rgba(255, 155, 186, 0.6);
    --accent-soft: rgba(255, 170, 200, 0.7);
    --accent-fill: rgba(255, 155, 186, 0.15);
    --accent-pink-border: rgba(255, 155, 186, 0.25);
    --row-hover-bg: rgba(255, 155, 186, 0.05);
    --bg-gradient-start: #ffe6f0;
    --bg-gradient-mid: #fff0f6;
    --bg-gradient-end: #ffffff;
    
    /* Status colors (NEVER change with theme - always warm colors) */
    --alert-red-soft: rgba(255, 182, 193, 0.7);
    --alert-red-softer: rgba(255, 182, 193, 0.5);
    --alert-orange-soft: rgba(255, 204, 153, 0.7);
    --alert-orange-softer: rgba(255, 220, 180, 0.5);
    --alert-yellow-soft: rgba(255, 241, 153, 0.7);
    --alert-yellow-softer: rgba(255, 249, 196, 0.5);
    
    /* Shadow System - 缁熶竴闃村奖绯荤粺 */
    --shadow-card: 0 6px 14px rgba(0, 0, 0, 0.06);
    --shadow-card-soft: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-header: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-status-ring: 0 0 0 4px;
    
    /* Typography System - 缁熶竴瀛椾綋绯荤粺 */
    --fs-page-title: clamp(16px, 3vw, 20px);
    --fs-section-title: clamp(12px, 2vw, 14px);
    --fs-kpi-label: clamp(14px, 2.5vw, 16px);
    --fs-kpi-value: clamp(32px, 6vw, 44px);
    --fs-kpi-small-value: clamp(18px, 3vw, 20px);
    --fs-body: clamp(11px, 1.8vw, 12px);
    --fs-small: clamp(9px, 1.5vw, 10px);
    --fs-tiny: clamp(8px, 1.3vw, 9px);
    --fs-badge: clamp(9px, 1.5vw, 10px);
    --fs-icon-large: clamp(26px, 5vw, 32px);
    --fs-icon-medium: clamp(18px, 3vw, 20px);
    --fs-icon-badge: clamp(13px, 2.5vw, 15px);
    
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;
    --fw-extrabold: 800;
    --fw-black: 900;
}

:root[data-theme="blue"] {
    /* Only override theme-specific colors */
    --accent-color: rgba(100, 150, 255, 1);
    --accent-light: rgba(155, 186, 255, 0.6);
    --accent-soft: rgba(170, 205, 255, 0.75);
    --accent-fill: rgba(155, 186, 255, 0.15);
    --accent-pink-border: rgba(155, 186, 255, 0.25);
    --row-hover-bg: rgba(155, 186, 255, 0.05);
    --bg-gradient-start: #e6f0ff;
    --bg-gradient-mid: #f0f6ff;
    --bg-gradient-end: #ffffff;
    /* Status colors are NOT overridden - they stay warm colors */
}

/* ========== GLOBAL RESET ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    padding: clamp(8px, 1.5vw, 12px);
    max-width: 100%;
    overflow-x: hidden;
}

img, svg, canvas {
    max-width: 100%;
    height: auto;
}

/* ========== CONTAINER ========== */
.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 24px);
    display: flex;
    flex-direction: column;
}

/* ========== HEADER ========== */
.header {
    background: white;
    border-radius: 16px;
    padding: clamp(10px, 2vw, 14px) clamp(14px, 3vw, 20px);
    box-shadow: var(--shadow-header);
    display: flex;
    align-items: center;
    gap: clamp(10px, 2vw, 16px);
    margin-bottom: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
}

.header h1 {
    font-family: 'Krona One', sans-serif;
    font-size: var(--fs-page-title);
    color: #2d2d2d;
}

.theme-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    order: 4;
}

.theme-selector label {
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    color: #666;
}

.theme-selector select {
    padding: 8px 12px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    cursor: pointer;
    background: white;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 120px;
    max-width: 240px;
    order: 2;
    margin-left: auto;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--fs-kpi-label);
}

.search-box input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: var(--fs-section-title);
    max-width: 100%;
    box-sizing: border-box;
}

.date-selector {
    order: 3;
}

.date-selector select {
    padding: 9px 14px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    cursor: pointer;
    background: white;
    max-width: 100%;
}

/* ========== SHOWING LABEL ========== */
.showing-label {
    background: white;
    padding: 8px 20px;
    border-radius: 10px;
    box-shadow: var(--shadow-card-soft);
    margin-bottom: 8px;
    font-size: var(--fs-body);
    color: #666;
    flex-shrink: 0;
    max-width: 100%;
    overflow-wrap: break-word;
}

#showingText {
    font-weight: 700;
    color: var(--accent-color);
}

/* ========== MAIN DASHBOARD GRID ========== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    grid-template-rows: auto auto;
    row-gap: 16px;
    column-gap: 12px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    align-content: start;
}

.left-column {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    min-height: 0;
}

.right-column {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 32px;
    overflow: hidden;
    min-height: 0;
}

/* Grid row for aligned cards */
.aligned-cards-row {
    grid-column: 1 / 3;
    grid-row: 2;
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 12px;
    min-height: 0;
    overflow: visible;
    margin-top: 0px;
}

/* ========== PERFORMANCE SUMMARY ========== */
.performance-summary {
    background: #ffffff;
    border-radius: 18px;
    padding: clamp(14px, 2.5vw, 18px) clamp(16px, 3vw, 20px) clamp(16px, 3vw, 20px) clamp(16px, 3vw, 20px);
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
}

.performance-summary h2 {
    font-family: 'Krona One', sans-serif;
    font-size: var(--fs-section-title);
    color: #2d2d2d;
    margin-top: 0;
    margin-bottom: 16px;
}

.performance-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: clamp(12px, 2vw, 16px);
}

@media (max-width: 768px) {
    .performance-layout {
        grid-template-columns: 1fr;
        gap: clamp(14px, 2.5vw, 20px);
    }
}

/* Big Net Profit Card */
.big-kpi-card {
    background: linear-gradient(135deg, rgb(255, 255, 255), rgb(255, 255, 255));
    border: 2px solid var(--accent-pink-border);
    border-radius: 16px;
    padding: clamp(16px, 3vw, 20px) clamp(14px, 2.5vw, 18px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.big-kpi-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.big-kpi-icon {
    font-size: var(--fs-icon-large);
    line-height: 1;
}

.big-kpi-label {
    font-size: var(--fs-kpi-label);
    font-weight: var(--fw-semibold);
    color: #333;
    text-transform: none;
    letter-spacing: 0;
}

.big-kpi-value {
    font-size: var(--fs-kpi-value);
    font-weight: var(--fw-black);
    color: #1a1a1a;
    line-height: 1;
    margin-bottom: 10px;
    letter-spacing: -2px;
}

.big-kpi-target {
    font-size: var(--fs-body);
    color: #999;
    margin-bottom: 12px;
}

.big-kpi-progress {
    display: none;
}

.big-kpi-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-light));
    border-radius: 10px;
    transition: width 0.8s ease;
}

.big-kpi-change {
    font-size: var(--fs-section-title);
    font-weight: var(--fw-bold);
    padding: 8px 16px;
    border-radius: 12px;
}

.change-positive {
    color: #2e7d32;
    background: rgba(76, 175, 80, 0.15);
}

.change-negative {
    color: #c62828;
    background: rgba(244, 67, 54, 0.15);
}

/* Small KPI Grid (2x2) */
.small-kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: clamp(10px, 2vw, 14px);
}

@media (max-width: 480px) {
    .small-kpi-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: clamp(10px, 2vw, 12px);
    }
}

.small-kpi-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
    border: 2px solid var(--accent-pink-border);
    border-radius: 14px;
    padding: clamp(18px, 2.8vw, 22px) clamp(10px, 1.8vw, 12px);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.small-kpi-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.small-kpi-icon {
    font-size: var(--fs-icon-medium);
    line-height: 1;
}

.small-kpi-label {
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    color: #333;
    text-transform: none;
    letter-spacing: 0;
}

.small-kpi-value {
    font-size: var(--fs-kpi-small-value);
    font-weight: var(--fw-black);
    color: #2d2d2d;
    line-height: 1.1;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.small-kpi-progress {
    display: none;
}

.small-kpi-progress-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 8px;
    transition: width 0.8s ease;
    opacity: 0.8;
}

.small-kpi-change {
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    padding: 3px 8px;
    border-radius: 8px;
    display: inline-block;
}

/* ========== SECTION CARDS ========== */
.section-card {
    background: #ffffff;
    border-radius: 16px;
    padding: clamp(14px, 2.5vw, 18px) clamp(16px, 3vw, 20px) clamp(18px, 3vw, 22px) clamp(16px, 3vw, 20px);
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.04);
    max-width: 100%;
    overflow: hidden;
}

.section-card h2 {
    font-family: 'Krona One', sans-serif;
    font-size: var(--fs-section-title);
    color: #2d2d2d;
    margin-top: 0;
    margin-bottom: 10px;
}

/* ========== TOP PRODUCTS ========== */
.section-card.top-products-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 18px 18px 16px 18px;
}

.top-products-layout {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Rank Badges */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    white-space: nowrap;
}

/* Top Products: Larger rank badges for prominence */
.section-card.top-products-card .rank-badge {
    padding: 3px 9px;
    border-radius: 11px;
    font-size: var(--fs-badge);
}

.section-card.top-products-card .rank-number {
    font-size: var(--fs-badge);
}

.section-card.top-products-card .rank-medal {
    font-size: var(--fs-icon-badge);
    line-height: 1;
}

.rank-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

/* Top Products: Smaller rank circles for 4-8 */
.section-card.top-products-card .rank-circle {
    width: 26px;
    height: 26px;
}

.section-card.top-products-card .rank-circle .rank-number {
    font-size: var(--fs-badge);
}

.rank-circle .rank-number {
    font-size: var(--fs-body);
    font-weight: var(--fw-bold);
    color: #666;
}

.rank-badge.rank-1 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 235, 150, 0.15));
    border: 1px solid rgba(255, 215, 0, 0.4);
    color: #b8860b;
}

.rank-badge.rank-2 {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.2), rgba(220, 220, 220, 0.15));
    border: 1px solid rgba(192, 192, 192, 0.5);
    color: #696969;
}

.rank-badge.rank-3 {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.2), rgba(225, 167, 110, 0.15));
    border: 1px solid rgba(205, 127, 50, 0.5);
    color: #8b4513;
}

.rank-number {
    font-size: var(--fs-badge);
    font-weight: var(--fw-extrabold);
}

.rank-medal {
    font-size: var(--fs-section-title);
    line-height: 1;
}

/* Products Table */
.products-table-wrapper {
    overflow-y: hidden;
    overflow-x: visible;
    width: 100%;
    flex: 1;
    min-height: 0;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.products-table th {
    text-align: left;
    padding: clamp(6px, 1.5vw, 10px) clamp(8px, 1.8vw, 12px);
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2.5px solid rgba(0, 0, 0, 0.08);
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.products-table th.rank-col {
    width: 100px;
    text-align: center;
}

/* Top Products: Compact header styling */
.section-card.top-products-card .products-table th {
    padding: 6px 10px;
    font-size: var(--fs-tiny);
    line-height: 1.15;
}

.products-table td {
    padding: clamp(8px, 1.5vw, 12px) clamp(8px, 1.8vw, 12px);
    font-size: var(--fs-body);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    line-height: 1.6;
    vertical-align: middle;
}

.products-table td.rank-col {
    text-align: center;
    vertical-align: middle;
}

/* Top Products: Uniform cell styling with vertical centering */
.section-card.top-products-card .products-table td {
    padding: 8px 10px;
    font-size: var(--fs-small);
    line-height: 1.3;
    vertical-align: middle;
}

.section-card.top-products-card .products-table tr.top-3 td {
    padding: 8px 10px;
}

.products-table tr.top-3 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.06), transparent);
}

.products-table tr:hover {
    background: var(--row-hover-bg);
}

/* Search "No Results" styling - REMOVED (no longer used) */

/* Search Highlight Styling - Zero Layout Impact */
.row-match {
    background: rgba(255, 215, 0, 0.12) !important;
    box-shadow: inset 3px 0 0 rgba(255, 193, 7, 0.6);
    /* No padding, no border, no margin - pure background + inset shadow */
}

.search-hit {
    background: rgba(255, 200, 0, 0.45);
    border-radius: 3px;
    /* Critical: no padding, no font-weight change, inherit line-height */
    padding: 0;
    font-weight: inherit;
    line-height: inherit;
    color: inherit;
}

/* ========== CHART TOOLTIP STYLES ========== */

.chart-tooltip,
#chartjs-tooltip {
    position: absolute;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 8px 12px;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    opacity: 0;
    transform: translateY(4px) scale(0.96);
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 200px;
    white-space: nowrap;
}

.chart-tooltip.is-visible,
#chartjs-tooltip.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chart-tooltip-day {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    margin-bottom: 2px;
    text-align: center;
}

.chart-tooltip-value {
    font-size: 14px;
    font-weight: 700;
    color: #333;
    text-align: center;
}

/* ========== CHART LEGEND STYLES ========== */

#chart-legend .legend-item:hover {
    opacity: 1 !important;
    transform: scale(1.05);
}

/* ========== INVENTORY ALERTS ========== */
.inventory-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

/* Pulsing animation for critical status dots */
@keyframes pulse-critical {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.inventory-table {
    width: 100%;
    border-collapse: collapse;
}

.inventory-table th {
    text-align: left;
    padding: clamp(6px, 1.2vw, 8px) clamp(8px, 1.5vw, 10px);
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.05);
}

.inventory-table td {
    padding: clamp(7px, 1.3vw, 9px) clamp(8px, 1.5vw, 10px);
    font-size: var(--fs-body);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.inventory-table .status-col {
    width: 60px;
    text-align: center;
}

.inventory-table .stock-col {
    width: 200px;
}

/* Stock Progress Bar */
.stock-progress {
    width: 100%;
    height: 28px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.stock-progress-fill {
    height: 100%;
    transition: width 0.6s ease;
    border-radius: 8px;
    position: relative;
}

.stock-progress-fill.critical {
    background: linear-gradient(90deg, var(--alert-red-soft), var(--alert-red-softer));
}

.stock-progress-fill.low {
    background: linear-gradient(90deg, var(--alert-orange-soft), var(--alert-orange-softer));
}

.stock-progress-fill.watch {
    background: linear-gradient(90deg, var(--alert-yellow-soft), var(--alert-yellow-softer));
}

.stock-progress-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    color: #333;
    white-space: nowrap;
    z-index: 1;
}

/* Ring Status Indicator */
.status-ring {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    position: relative;
}

.status-ring.critical {
    border: 3px solid #ef5350;
    background: rgba(239, 83, 80, 0.1);
    box-shadow: var(--shadow-status-ring) rgba(239, 83, 80, 0.15);
}

.status-ring.low {
    border: 3px solid #ff9800;
    background: rgba(255, 152, 0, 0.1);
    box-shadow: var(--shadow-status-ring) rgba(255, 152, 0, 0.15);
}

.status-ring.watch {
    border: 3px solid #ffc107;
    background: rgba(255, 193, 7, 0.1);
    box-shadow: var(--shadow-status-ring) rgba(255, 193, 7, 0.15);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-ring.critical .status-dot {
    background: #ef5350;
    animation: pulse-critical 1.5s ease-in-out infinite;
}

.status-ring.low .status-dot {
    background: #ff9800;
}

.status-ring.watch .status-dot {
    background: #ffc107;
}

/* Action Pills */
.action-pill {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: var(--fs-small);
    font-weight: var(--fw-bold);
    white-space: nowrap;
}

.action-pill.order-today {
    background: rgba(239, 83, 80, 0.15);
    color: #d32f2f;
}

.action-pill.order-tomorrow {
    background: rgba(255, 152, 0, 0.15);
    color: #f57c00;
}

.action-pill.monitor {
    background: rgba(255, 193, 7, 0.15);
    color: #f9a825;
}

/* ========== WEEKLY REVENUE TREND ========== */
.revenue-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: clamp(14px, 2.5vw, 18px) clamp(16px, 3vw, 20px) clamp(14px, 2.5vw, 18px) clamp(16px, 3vw, 20px);
    position: relative;
}

.revenue-card h2 {
    margin-top: 0;
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
}

.chart-container {
    width: 100%;
    flex: 1;
    min-height: clamp(220px, 35vh, 320px);
    max-height: clamp(280px, 45vh, 450px);
    position: relative;
    overflow: visible;
}

#revenueChart {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ========== RESPONSIVE ========== */

/* Tablet and below - Single column layout */
@media (max-width: 1024px) {
    body {
        overflow-y: auto;
        height: auto;
    }
    
    .container {
        height: auto;
        overflow: visible;
    }
    
    .header {
        flex-wrap: wrap;
        gap: clamp(8px, 1.5vw, 12px);
    }
    
    .search-box {
        min-width: 150px;
        max-width: 200px;
        flex: 1 1 auto;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        row-gap: clamp(16px, 3vw, 20px);
        overflow: visible;
    }

    .left-column {
        grid-column: 1;
        grid-row: 1;
        overflow: visible;
    }

    .right-column {
        grid-column: 1;
        grid-row: 2;
        overflow: visible;
    }

    .aligned-cards-row {
        grid-column: 1;
        grid-row: 3;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: clamp(16px, 3vw, 20px);
    }
}

@media (max-width: 768px) {
    body {
        padding: clamp(6px, 1.2vw, 8px);
        overflow-y: auto;
        height: auto;
    }
    
    .container {
        height: auto;
        overflow: visible;
        max-width: 100%;
    }

    .header {
        padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 16px);
        gap: clamp(8px, 1.5vw, 12px);
        flex-wrap: wrap;
    }

    .header h1 {
        font-size: clamp(14px, 2.5vw, 16px);
    }
    
    .header-logo {
        width: clamp(36px, 7vw, 40px);
        height: clamp(36px, 7vw, 40px);
    }
    
    .header-brand {
        min-width: auto;
        flex: 1 1 100%;
    }
    
    .search-box {
        min-width: 120px;
        max-width: 100%;
        flex: 1 1 auto;
    }
    
    .date-selector,
    .theme-selector {
        flex: 0 1 auto;
    }
    
    .theme-selector label,
    .date-selector select,
    .theme-selector select {
        font-size: var(--fs-body);
    }

    .dashboard-grid {
        row-gap: 18px;
        column-gap: 14px;
        overflow: visible;
    }
    
    .left-column,
    .right-column {
        overflow: visible;
        gap: 16px;
    }

    .performance-summary,
    .section-card {
        padding: 16px;
        margin-bottom: 0;
    }
    
    .performance-summary h2,
    .section-card h2 {
        margin-bottom: clamp(8px, 1.5vw, 12px);
    }

    .products-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    
    .products-table {
        min-width: 500px;
    }
    
    .products-table th,
    .products-table td {
        padding: 8px 6px;
        font-size: var(--fs-small);
    }
    
    .rank-badge,
    .rank-badge-placeholder {
        width: 48px;
        padding: 2px 6px;
        font-size: var(--fs-tiny);
    }
    
    .rank-medal {
        font-size: var(--fs-body);
    }
    
    .inventory-card,
    .revenue-card {
        min-height: 300px;
        max-width: 100%;
        overflow: hidden;
    }
    
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    
    .inventory-table {
        min-width: 600px;
    }
    
    .inventory-table th,
    .inventory-table td {
        font-size: var(--fs-small);
        padding: 8px;
    }
    
    .chart-container {
        min-height: 250px;
        max-width: 100%;
        overflow: hidden;
    }
}

@media (max-width: 480px) {
    body {
        padding: clamp(4px, 1vw, 6px);
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        padding: clamp(10px, 2vw, 12px);
        gap: clamp(8px, 1.5vw, 10px);
    }

    .header-brand {
        justify-content: center;
        text-align: center;
        gap: clamp(8px, 1.5vw, 10px);
        flex: 1 1 100%;
    }
    
    .header h1 {
        font-size: clamp(12px, 2.2vw, 14px);
    }

    .search-box {
        max-width: 100%;
        min-width: 100%;
        order: 5;
        margin-left: 0;
    }
    
    .search-box input {
        width: 100%;
    }
    
    .date-selector {
        order: 3;
        width: 100%;
    }
    
    .date-selector select {
        width: 100%;
    }
    
    .theme-selector {
        order: 4;
        width: 100%;
        justify-content: space-between;
    }
    
    .theme-selector select {
        flex: 1;
        max-width: 200px;
    }
    
    .dashboard-grid {
        row-gap: clamp(12px, 2vw, 16px);
        column-gap: clamp(8px, 1.5vw, 12px);
    }
    
    .performance-summary,
    .section-card {
        padding: clamp(10px, 1.8vw, 14px);
        max-width: 100%;
        overflow: hidden;
    }
    
    .inventory-card,
    .revenue-card {
        min-height: clamp(250px, 40vh, 300px);
        max-width: 100%;
        overflow: hidden;
    }
    
    .products-table {
        min-width: 420px;
        width: 100%;
    }
    
    .inventory-table {
        min-width: 500px;
        width: 100%;
    }
    
    .stock-progress {
        height: clamp(20px, 4vw, 24px);
    }
    
    .stock-progress-label {
        font-size: var(--fs-badge);
    }
    
    .status-ring {
        width: clamp(26px, 5vw, 28px);
        height: clamp(26px, 5vw, 28px);
    }
    
    .action-pill {
        font-size: var(--fs-badge);
        padding: clamp(4px, 1vw, 5px) clamp(8px, 1.5vw, 10px);
    }
}

/* =========================
   TOOLTIP 修复：确保tooltip显示
   ========================= */

.chart-tooltip {
  z-index: 99999;
}

/* =========================
   响应式适配 - 平板
   ========================= */

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .left-column,
    .right-column {
        grid-column: 1;
        width: 100%;
    }

    .aligned-cards-row {
        grid-column: 1;
        grid-template-columns: 1fr;
    }
}

/* =========================
   移动端横向滚动适配 - 核心修复
   全局禁止页面横向滚动，但每个卡片内部可以横向滚动
   ========================= */

/* 全局禁止页面横向滚动 */
html {
    max-width: 100%;
    overflow-x: hidden !important;
}

body {
    max-width: 100%;
    overflow-x: hidden !important;
}

.container {
    max-width: 100%;
    overflow-x: hidden !important;
}

/* 移动端（<=768px）：每个白色卡片内部可横向滚动 */
@media (max-width: 768px) {
    /* 全局防溢出 */
    html {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden !important;
    }

    body {
        width: 100%;
        max-width: 100%;
        padding: clamp(6px, 2vw, 8px);
        overflow-x: hidden !important;
    }

    .container {
        width: 100%;
        max-width: 100%;
        min-height: auto;
        overflow-x: hidden !important;
    }

    /* Header 移动端布局 */
    .header {
        padding: clamp(10px, 3vw, 12px);
        gap: clamp(8px, 2vw, 10px);
        flex-wrap: wrap;
    }

    .header-brand {
        flex: 1 1 100%;
        order: 1;
        gap: 8px;
    }

    .header h1 {
        font-size: clamp(13px, 3.5vw, 15px);
    }

    .header-logo {
        width: clamp(32px, 8vw, 36px);
        height: clamp(32px, 8vw, 36px);
    }

    .search-box {
        flex: 1 1 100%;
        order: 2;
        margin-left: 0;
        min-width: 0;
        max-width: 100%;
    }

    .search-box input {
        font-size: clamp(12px, 3vw, 13px);
        padding: 8px 12px 8px 36px;
    }

    .date-selector {
        flex: 1 1 auto;
        order: 3;
    }

    .date-selector select {
        width: 100%;
        font-size: clamp(11px, 2.8vw, 12px);
        padding: 8px 12px;
    }

    .theme-selector {
        flex: 1 1 auto;
        order: 4;
    }

    .theme-selector label {
        font-size: clamp(11px, 2.8vw, 12px);
    }

    .theme-selector select {
        width: 100%;
        font-size: clamp(11px, 2.8vw, 12px);
        padding: 8px 12px;
    }

    /* Dashboard 网格改为单列 */
    .dashboard-grid {
        display: flex;
        flex-direction: column;
        gap: clamp(10px, 2.5vw, 12px);
        overflow: visible;
    }

    .left-column,
    .right-column {
        width: 100%;
        overflow: visible;
    }

    .aligned-cards-row {
        display: flex;
        flex-direction: column;
        gap: clamp(10px, 2.5vw, 12px);
    }

    /* 所有卡片基础样式 */
    .section-card {
        width: 100%;
        max-width: 100%;
        padding: clamp(12px, 3vw, 14px);
    }

    .section-card h2 {
        font-size: clamp(13px, 3.2vw, 14px);
    }

    /* 1. Performance Summary - 白色卡片可横向滚动 */
    .performance-summary {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        padding: clamp(12px, 3vw, 14px);
    }
    
    .performance-layout {
        width: max-content;
        min-width: 700px;
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        gap: clamp(10px, 2.5vw, 16px);
    }

    .big-kpi-card {
        padding: clamp(14px, 3.5vw, 16px);
    }

    .small-kpi-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: clamp(8px, 2vw, 10px);
    }

    .small-kpi-card {
        padding: clamp(10px, 2.5vw, 12px) clamp(8px, 2vw, 10px);
    }

    /* 2. Inventory Alerts - 白色卡片可横向滚动 */
    .inventory-card {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    
    .table-wrapper {
        overflow: visible;
        min-width: 100%;
    }
    
    .inventory-table {
        width: max-content;
        min-width: 750px;
        border-collapse: collapse;
        display: table;
    }

    .inventory-table th {
        position: sticky;
        top: 0;
        background: white;
        z-index: 2;
        padding: clamp(6px, 1.5vw, 8px) clamp(7px, 1.8vw, 10px);
        font-size: clamp(10px, 2.5vw, 11px);
        white-space: nowrap;
    }

    .inventory-table td {
        padding: clamp(7px, 1.5vw, 9px) clamp(7px, 1.8vw, 10px);
        font-size: clamp(10px, 2.5vw, 11px);
        white-space: nowrap;
    }

    .inventory-table .status-col {
        width: 50px;
    }

    .inventory-table .stock-col {
        min-width: 200px;
    }

    /* Stock Progress Bar 移动端适配 */
    .stock-progress {
        height: clamp(22px, 5.5vw, 26px);
        min-width: 150px;
    }

    .stock-progress-label {
        font-size: clamp(9px, 2.2vw, 10px);
    }

    /* Status Ring 缩小 */
    .status-ring {
        width: clamp(20px, 5vw, 24px);
        height: clamp(20px, 5vw, 24px);
    }

    /* Action Pills */
    .action-pill {
        font-size: clamp(9px, 2.2vw, 10px);
        padding: clamp(3px, 0.8vw, 4px) clamp(6px, 1.5vw, 8px);
    }
    
    /* 3. Top Products - 白色卡片可横向滚动 */
    .top-products-card {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    
    .top-products-layout {
        overflow: visible;
        min-width: 100%;
    }
    
    .products-table-wrapper {
        overflow: visible;
        min-width: 100%;
    }
    
    .products-table {
        width: max-content;
        min-width: 700px;
        border-collapse: collapse;
        display: table;
    }

    .products-table th {
        position: sticky;
        top: 0;
        background: white;
        z-index: 2;
        padding: clamp(6px, 1.5vw, 8px) clamp(7px, 1.8vw, 10px);
        font-size: clamp(10px, 2.5vw, 11px);
        white-space: nowrap;
    }

    .products-table td {
        padding: clamp(7px, 1.5vw, 9px) clamp(7px, 1.8vw, 10px);
        font-size: clamp(10px, 2.5vw, 11px);
        white-space: nowrap;
    }

    .products-table th.rank-col {
        width: 60px;
    }

    .section-card.top-products-card .products-table th,
    .section-card.top-products-card .products-table td {
        padding: clamp(5px, 1.2vw, 7px) clamp(6px, 1.5vw, 8px);
        font-size: clamp(9px, 2.2vw, 10px);
    }
    
    /* 4. Weekly Revenue Trend - 白色卡片可横向滚动 */
    .revenue-card {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        padding: clamp(12px, 3vw, 14px) !important;
        position: relative;
    }
    
    .revenue-card h2 {
        margin-bottom: 10px;
    }
    
    .chart-container {
        width: 100%;
        min-width: 100%;
        height: 280px;
        position: relative;
        overflow: visible;
    }
    
    .chart-container canvas {
        width: 100% !important;
        height: 100% !important;
    }
    
    /* 美化横向滚动条样式 */
    .performance-summary::-webkit-scrollbar,
    .inventory-card::-webkit-scrollbar,
    .top-products-card::-webkit-scrollbar,
    .revenue-card::-webkit-scrollbar {
        height: 8px;
    }
    
    .performance-summary::-webkit-scrollbar-thumb,
    .inventory-card::-webkit-scrollbar-thumb,
    .top-products-card::-webkit-scrollbar-thumb,
    .revenue-card::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }
    
    .performance-summary::-webkit-scrollbar-track,
    .inventory-card::-webkit-scrollbar-track,
    .top-products-card::-webkit-scrollbar-track,
    .revenue-card::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.05);
        border-radius: 4px;
        margin: 0 8px;
    }

    /* 字体变量覆盖 */
    :root {
        --fs-page-title: clamp(14px, 3.5vw, 16px);
        --fs-section-title: clamp(12px, 3vw, 13px);
        --fs-kpi-label: clamp(13px, 3.2vw, 14px);
        --fs-kpi-value: clamp(24px, 6vw, 28px);
        --fs-kpi-small-value: clamp(15px, 3.8vw, 17px);
        --fs-body: clamp(10px, 2.5vw, 11px);
        --fs-small: clamp(9px, 2.2vw, 10px);
        --fs-tiny: clamp(8px, 2vw, 9px);
        --fs-badge: clamp(9px, 2.2vw, 10px);
    }
}

/* 小屏幕（<=480px）进一步调整最小宽度 */
@media (max-width: 480px) {
    body {
        padding: 6px;
    }

    .header {
        padding: 10px;
        gap: 8px;
    }

    .small-kpi-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        gap: 10px;
    }

    .section-card {
        padding: 12px;
    }
    
    /* 进一步增大最小宽度以确保内容完整显示 */
    .performance-layout {
        min-width: 750px;
    }
    
    .inventory-table {
        min-width: 800px;
    }
    
    .products-table {
        min-width: 750px;
    }
    
    .chart-container {
        width: 100% !important;
        min-width: 100% !important;
    }
}