/* =========================================================================
   亚马逊运营指挥台 · 设计系统
   石板靛蓝 · 数据优先 · 亮/暗双主题（跟随系统）
   ========================================================================= */

/* ---------- 设计 Token ---------- */
:root {
    /* 表面与文字 */
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;      /* 表头 / hover / 轨道 */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    /* 主色（靛蓝） */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-ring: rgba(79, 70, 229, 0.18);

    /* 语义色：涨 / 跌 / 警 / 信息 */
    --up: #10b981;   --up-soft: #d1fae5;   --up-ink: #065f46;
    --down: #f43f5e; --down-soft: #ffe4e6; --down-ink: #9f1239;
    --warn: #f59e0b; --warn-soft: #fef3c7; --warn-ink: #92400e;
    --info: #3b82f6; --info-soft: #dbeafe; --info-ink: #1e40af;

    /* 半径 / 阴影 */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-pop: 0 16px 40px rgba(15, 23, 42, .20);

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #131c2e;
        --surface-2: #1c2740;
        --border: #29344b;
        --border-strong: #3b4a68;
        --text: #e8edf6;
        --text-muted: #94a3b8;
        --text-faint: #64748b;

        --primary: #7c83ff;
        --primary-hover: #969bff;
        --primary-soft: #1b2344;
        --primary-ring: rgba(124, 131, 255, 0.25);

        --up: #34d399;   --up-soft: #06342a;   --up-ink: #6ee7b7;
        --down: #fb7185; --down-soft: #3f0d1b; --down-ink: #fda4af;
        --warn: #fbbf24; --warn-soft: #3a2705; --warn-ink: #fcd34d;
        --info: #60a5fa; --info-soft: #12234a; --info-ink: #93c5fd;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
        --shadow: 0 4px 16px rgba(0, 0, 0, .4);
        --shadow-pop: 0 16px 40px rgba(0, 0, 0, .6);

        color-scheme: dark;
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* 数字全局等宽对齐（signature） */
.stat-value, .bar-value, table, .current-page, .kpi-num { font-variant-numeric: tabular-nums; }

/* ---------- 顶栏 ---------- */
.header {
    background: var(--surface);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
}

.header-left .logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 9px;
}
/* logo 前的靛蓝方标（signature 小记号） */
.header-left .logo::before {
    content: "";
    width: 20px; height: 20px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    box-shadow: 0 2px 8px var(--primary-ring);
}

.header-right { display: flex; align-items: center; gap: 20px; }
#user-info { color: var(--text-muted); font-size: 14px; }

/* ---------- 布局 ---------- */
.main-container {
    display: flex;
    margin-top: 60px;
    height: calc(100vh - 60px);
}

.sidebar {
    width: 224px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.nav-menu { padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s, color .15s;
    cursor: pointer;
    position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active::before {
    content: "";
    position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 18px; border-radius: 0 3px 3px 0;
    background: var(--primary);
}
.nav-item .icon { font-size: 17px; margin-right: 11px; width: 20px; text-align: center; }

.content {
    flex: 1;
    padding: 28px 32px;
    overflow-y: auto;
    background: var(--bg);
}

/* ---------- 页头 ---------- */
.page-header { margin-bottom: 24px; }
.page-title {
    font-size: 23px; font-weight: 700; letter-spacing: -0.02em;
    color: var(--text); margin-bottom: 6px;
}
.page-subtitle { font-size: 13.5px; color: var(--text-muted); }

/* ---------- 卡片 ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 22px;
}
.card-title {
    font-size: 15px; font-weight: 650; letter-spacing: -0.01em;
    margin-bottom: 16px; color: var(--text);
}
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-head .card-title { margin-bottom: 0; }

/* ---------- 统计卡 ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s;
}
.stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.stat-label {
    font-size: 12.5px; color: var(--text-muted);
    margin-bottom: 10px; font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.stat-value {
    font-size: 29px; font-weight: 750; letter-spacing: -0.03em;
    color: var(--text); margin-bottom: 6px; line-height: 1.1;
}
.stat-value.negative { color: var(--down); }
.stat-trend { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-trend.negative { color: var(--down); }
.stat-trend.positive { color: var(--up); }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 15px; border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 550; cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(0.5px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); }
.btn-success { background: var(--up); color: #fff; }
.btn-danger { background: var(--down); color: #fff; }

/* ---------- 表格 ---------- */
.table-container { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead { background: var(--surface-2); position: sticky; top: 0; z-index: 10; }
th {
    padding: 11px 16px; text-align: left;
    font-weight: 600; font-size: 12px; letter-spacing: 0.03em;
    text-transform: uppercase; color: var(--text-muted);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
td {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    font-size: 13.5px; color: var(--text);
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 550; color: var(--text-muted); }
.form-input {
    width: 100%; padding: 8px 12px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
.form-input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.form-input::placeholder { color: var(--text-faint); }

.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- 分页 ---------- */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 20px; }
.pagination button {
    padding: 6px 13px; border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text);
    border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
    transition: background .15s, border-color .15s;
}
.pagination button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--primary); }
.pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.pagination .current-page { padding: 6px 12px; font-weight: 600; font-size: 13px; color: var(--text-muted); }

/* ---------- 状态 ---------- */
.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px; }
.empty-state { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 44px; margin-bottom: 14px; opacity: .7; }

/* ---------- 徽章 ---------- */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
    font-variant-numeric: tabular-nums;
}
.badge-success { background: var(--up-soft); color: var(--up-ink); }
.badge-warning { background: var(--warn-soft); color: var(--warn-ink); }
.badge-danger { background: var(--down-soft); color: var(--down-ink); }
.badge-info { background: var(--info-soft); color: var(--info-ink); }

/* ---------- 工作台 ---------- */
.dashboard-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.range-tabs {
    display: inline-flex; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
}
.range-tabs button {
    padding: 7px 15px; border: none; background: transparent;
    color: var(--text-muted); font-size: 13px; font-weight: 500; cursor: pointer;
    transition: background .15s, color .15s;
}
.range-tabs button:not(:last-child) { border-right: 1px solid var(--border); }
.range-tabs button:hover { background: var(--surface-2); color: var(--text); }
.range-tabs button.active { background: var(--primary); color: #fff; }

.dash-filter { padding: 13px 16px; }
.dash-filter .form-input { padding: 7px 10px; }
.dash-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

/* ---------- 图表 ---------- */
.chart-legend { display: flex; gap: 18px; margin-bottom: 10px; font-size: 12.5px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* SVG 折线图元素（供 charts.js 用 class 控制，适配暗色） */
.chart-grid { stroke: var(--border); }
.chart-axis { fill: var(--text-faint); }
.chart-dot { fill: var(--surface); }

/* 横向条形图 */
.bar-list { display: flex; flex-direction: column; gap: 13px; }
.bar-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; }
.bar-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .5s ease; }
.bar-value { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; }
.bar-sub { font-size: 12px; color: var(--text-faint); margin-left: 6px; font-weight: 400; }

/* 图表下方的口径说明（如多币种不可同轴比较） */
.chart-note { margin-top: 8px; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* 侧边栏菜单上的计数红点（如待审批用户数） */
.nav-badge {
    margin-left: auto;
    min-width: 18px;
    padding: 0 5px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--down);
    border-radius: 9px;
    font-variant-numeric: tabular-nums;
}

/* 产品单元格 */
.prod-cell { display: flex; align-items: center; gap: 10px; max-width: 360px; }
.prod-thumb {
    width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover;
    background: var(--surface-2); flex-shrink: 0; border: 1px solid var(--border);
}
.prod-name {
    font-size: 13px; color: var(--text); line-height: 1.4;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- 弹窗（统一收编，替代各页内联样式） ---------- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(2, 6, 23, .55);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-pop);
    max-width: 860px; width: 100%; max-height: 85vh; overflow: auto; padding: 22px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head .card-title { margin-bottom: 0; }
.modal-meta {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px 16px; margin-bottom: 18px; font-size: 13.5px; color: var(--text-muted);
}
.modal-meta strong { color: var(--text); }

/* ---------- 登录页 ---------- */
.login-screen {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 20px;
}
.login-checking { color: var(--text-muted); font-size: 15px; }
.login-card {
    width: 360px; max-width: 90%; text-align: center;
    padding: 44px 36px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
}
.login-logo {
    width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    box-shadow: 0 8px 24px var(--primary-ring);
}
.login-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 8px; color: var(--text); }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }
.login-btn {
    width: 100%; padding: 12px 0; font-size: 15px; font-weight: 600;
    cursor: pointer; border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: #fff; transition: background .15s;
}
.login-btn:hover:not(:disabled) { background: var(--primary-hover); }
.login-btn:disabled { opacity: .6; cursor: default; }
.login-hint { color: var(--down); font-size: 12px; margin-top: 14px; min-height: 1.2em; }
.header-right .user-name { color: var(--text); font-size: 14px; font-weight: 500; }
.header-right .logout-btn { padding: 5px 12px; font-size: 13px; }

/* ---------- 工具提示 ---------- */
.tooltip { position: relative; display: inline-block; }
.tooltip:hover::after {
    content: attr(data-tip); position: absolute; bottom: 100%; left: 50%;
    transform: translateX(-50%); padding: 4px 8px;
    background: var(--text); color: var(--surface); font-size: 12px;
    border-radius: 4px; white-space: nowrap; margin-bottom: 4px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
    .dash-2col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .content { padding: 20px 16px; }
    .sidebar { width: 60px; }
    .nav-item { justify-content: center; padding: 12px 0; }
    .nav-item span:not(.icon) { display: none; }
    .nav-item .icon { margin-right: 0; }
    .nav-item.active::before { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-value { font-size: 24px; }
    .dashboard-header { flex-direction: column; }
    .modal-meta { grid-template-columns: 1fr 1fr; }
    .header { padding: 0 16px; }
}
@media (max-width: 460px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ---------- 无障碍 ---------- */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- 工作台：今日预警横幅 / 排行表辅助 ---------- */
.alert-banner {
    display: flex; align-items: center; gap: 6px;
    background: var(--warn-soft); color: var(--warn-ink);
    border: 1px solid var(--warn); border-radius: 10px;
    padding: 10px 16px; margin-bottom: 16px;
    font-size: 14px; cursor: pointer;
}
.alert-banner:hover { filter: brightness(0.97); }
.alert-count {
    display: inline-block; min-width: 22px; text-align: center;
    background: var(--warn); color: #fff; border-radius: 999px;
    padding: 1px 8px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.cell-sub { font-size: 12px; color: var(--text-muted); }
.num-down { color: var(--down); }
