* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f5f6f8;
    color: #1f2937;
    font-size: 14px;
}

/* ---- 嵌入 iframe 时隐藏自身 chrome ---- */
html.embedded .topbar,
html.embedded .orgfilter-bar { display: none !important; }
html.embedded .layout { min-height: 100vh; }
html.embedded .sidebar { max-height: 100vh; }
html.embedded .container { max-width: none; margin: 12px 0 0; padding: 0 16px; }

/* ---- 顶栏 ---- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: #1f2937; color: #f9fafb;
}
.topbar .brand { font-weight: 600; letter-spacing: 0.5px; }
.topbar nav { display: flex; align-items: center; gap: 4px; flex: 1; margin-left: 24px; }
.topbar nav a {
    color: #d1d5db; text-decoration: none;
    padding: 6px 12px; border-radius: 4px;
}
.topbar nav a:hover { background: #374151; color: #fff; }
.topbar nav a.active { background: #374151; color: #fff; }
.topbar nav .spacer { flex: 1; }
.topbar nav .user { color: #9ca3af; margin-right: 8px; }
.topbar nav .logout { color: #fca5a5; }

/* ---- 布局 ---- */
.container { max-width: 1280px; margin: 24px auto; padding: 0 24px; }
.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    min-height: calc(100vh - 56px);
}
.sidebar {
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 56px);
    position: sticky;
    top: 0;
}
.content {
    padding: 24px 32px;
    overflow-x: auto;
}
.content h1 { margin-top: 0; font-size: 22px; }
.content h2 { margin-top: 32px; font-size: 16px; color: #374151; }

/* ---- Flash ---- */
.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 12px; font-size: 14px; }
.flash-error   { background: #fee2e2; color: #991b1b; border-left: 3px solid #dc2626; }
.flash-success { background: #d1fae5; color: #065f46; border-left: 3px solid #059669; }

/* ---- Auth ---- */
.auth-box { max-width: 360px; margin: 80px auto; background: #fff; padding: 32px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.auth-box h1 { margin: 0 0 20px; font-size: 20px; }
.auth-box label { display: block; margin-bottom: 14px; font-size: 13px; color: #4b5563; }
.auth-box input { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.auth-box button { width: 100%; padding: 10px; background: #2563eb; color: #fff; border: 0; border-radius: 4px; font-size: 14px; cursor: pointer; }
.auth-box button:hover { background: #1d4ed8; }
.auth-box .hint { font-size: 13px; color: #6b7280; margin-top: -10px; }

/* ---- Sidebar form ---- */
.sidebar-form section {
    border-bottom: 1px solid #f3f4f6;
    padding: 10px 0;
}
.sidebar-form h3 { margin: 4px 0 8px; font-size: 13px; color: #374151; text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-form label { display: block; font-size: 12px; color: #4b5563; margin-bottom: 8px; }
.sidebar-form input[type=number], .sidebar-form input[type=text], .sidebar-form input[type=date], .sidebar-form select {
    display: block; width: 100%; margin-top: 3px;
    padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px;
}
.sidebar-form .inline-num { display: inline-block; width: 60px; margin: 0 4px; }
.sidebar-form .check-row, .sidebar-form .radio-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.sidebar-form .check-row input, .sidebar-form .radio-row input { margin: 0; width: auto; }
.sidebar-actions { display: flex; gap: 8px; padding: 12px 0; border-bottom: 1px solid #f3f4f6; }
.presets-section { padding-bottom: 16px; }
.preset-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ---- Buttons ---- */
.btn { padding: 7px 14px; border: 1px solid #d1d5db; background: #fff; border-radius: 4px; cursor: pointer; font-size: 13px; color: #374151; text-decoration: none; display: inline-block; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.primary:hover { background: #1d4ed8; }
.btn.success { background: #059669; color: #fff; border-color: #059669; }
.btn.success:hover { background: #047857; }
.btn.danger { color: #dc2626; border-color: #fca5a5; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ---- Cards ---- */
.cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 16px;
}
.card { background: #fff; border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.card-label { font-size: 12px; color: #6b7280; }
.card-value { margin-top: 4px; font-size: 18px; font-weight: 600; color: #111827; }
.card-value-small { margin-top: 6px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px; }
.card-sub { margin-top: 4px; font-size: 11px; color: #9ca3af; }

.chip {
    display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px;
    background: #e5e7eb; color: #374151;
}
.chip-正常 { background: #d1fae5; color: #065f46; }
.chip-新品 { background: #dbeafe; color: #1e40af; }
.chip-停售 { background: #fee2e2; color: #991b1b; }
.chip-低销额 { background: #fef3c7; color: #92400e; }

/* ---- 九宫格 ---- */
.nine-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    margin-top: 12px;
}
.grid-cell {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex; flex-direction: column; gap: 4px;
}
.grid-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.grid-code { font-size: 18px; font-weight: 700; }
.grid-strategy { font-size: 12px; color: #6b7280; }
.grid-count { font-size: 13px; color: #111827; font-weight: 500; margin-top: 4px; }
.grid-revbar { background: #f3f4f6; border-radius: 3px; overflow: hidden; height: 6px; margin: 4px 0 2px; }
.grid-revbar span { display: block; height: 100%; background: linear-gradient(90deg, #2563eb, #059669); }
.grid-rev { font-size: 11px; color: #6b7280; }
.grid-sl { font-size: 11px; color: #9ca3af; }

.grid-AX { border-left: 3px solid #dc2626; }
.grid-AY { border-left: 3px solid #ea580c; }
.grid-AZ { border-left: 3px solid #d97706; }
.grid-BX { border-left: 3px solid #ca8a04; }
.grid-BY { border-left: 3px solid #65a30d; }
.grid-BZ { border-left: 3px solid #16a34a; }
.grid-CX { border-left: 3px solid #0891b2; }
.grid-CY { border-left: 3px solid #2563eb; }
.grid-CZ { border-left: 3px solid #7c3aed; }

/* ---- Charts ---- */
.charts-row {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px;
}
.chart-box { background: #fff; border-radius: 8px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.chart-box h3 { margin: 0 0 10px; font-size: 13px; color: #374151; }

/* ---- Detail: 过滤条 + 表格 ---- */
.filter-bar { background: #fff; padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter-row label { font-size: 12px; color: #4b5563; }
.filter-row label input[type=text], .filter-row label select { padding: 5px 8px; border: 1px solid #d1d5db; border-radius: 4px; margin-left: 4px; }
.filter-row fieldset { border: 1px solid #e5e7eb; border-radius: 4px; padding: 4px 10px 6px; }
.filter-row legend { font-size: 11px; color: #6b7280; padding: 0 4px; }
.filter-row label.inline { display: inline-flex; align-items: center; gap: 3px; margin-right: 6px; font-size: 12px; }
.filter-actions { margin-top: 10px; display: flex; gap: 8px; align-items: center; }
.total-hint { margin-left: auto; font-size: 12px; color: #6b7280; }

.table-wrap { background: #fff; border-radius: 8px; overflow: auto; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.sku-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sku-table th, .sku-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #f3f4f6; white-space: nowrap; }
.sku-table th { background: #f9fafb; color: #374151; font-weight: 600; position: sticky; top: 0; }
.sku-table td.num, .sku-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sku-table td.name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.sku-table tr:hover { background: #f9fafb; }
.sku-table .empty { text-align: center; color: #9ca3af; padding: 32px; }

.tag {
    display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 600;
    background: #e5e7eb; color: #374151; margin-right: 2px;
}
.tag-A { background: #fee2e2; color: #991b1b; }
.tag-B { background: #fef3c7; color: #92400e; }
.tag-C { background: #d1fae5; color: #065f46; }
.tag-X { background: #dbeafe; color: #1e40af; }
.tag-Y { background: #fef3c7; color: #92400e; }
.tag-Z { background: #fce7f3; color: #9d174d; }
.tag-int { background: #e0e7ff; color: #3730a3; }
.tag-AX, .tag-AY, .tag-AZ, .tag-BX, .tag-BY, .tag-BZ, .tag-CX, .tag-CY, .tag-CZ { background: #111827; color: #fff; }

.pagination { margin-top: 12px; display: flex; gap: 12px; align-items: center; justify-content: center; font-size: 13px; }
.pagination a { color: #2563eb; text-decoration: none; padding: 4px 10px; border: 1px solid #d1d5db; border-radius: 4px; }
.pagination a:hover { background: #f9fafb; }
.page-info { color: #6b7280; }

/* ---- Upload ---- */
.upload-form { background: #fff; padding: 24px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); max-width: 520px; }
.upload-form label { display: block; margin-bottom: 14px; font-size: 13px; color: #4b5563; }
.upload-form select, .upload-form input[type=file] { display: block; width: 100%; margin-top: 4px; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 14px; }
.upload-form button { margin-top: 8px; padding: 10px 20px; }
.upload-report { margin-top: 16px; background: #f0fdf4; border-left: 3px solid #059669; padding: 12px 16px; border-radius: 4px; }
.upload-report h3 { margin: 0 0 6px; font-size: 14px; color: #065f46; }
.upload-report ul { margin: 0; padding-left: 20px; }
.upload-help { margin-top: 24px; background: #fff; padding: 16px 20px; border-radius: 8px; color: #4b5563; font-size: 13px; }
.upload-help h3 { margin-top: 0; font-size: 14px; }
.hint { color: #6b7280; margin-top: -4px; margin-bottom: 16px; }

/* ---- Placeholder ---- */
.placeholder { background: #fff; border: 1px dashed #d1d5db; border-radius: 8px; padding: 40px; text-align: center; color: #6b7280; }
.placeholder h2 { margin-top: 0; font-size: 16px; color: #374151; }

/* V2: toolbar row, material table tweaks, flags */
.toolbar-row {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
    background: #fff; padding: 10px 14px; border-radius: 8px;
    margin: 12px 0; box-shadow: 0 1px 2px rgba(0,0,0,0.04); font-size: 13px;
}
.toolbar-row form { margin: 0; }
.toolbar-hint { color: #6b7280; font-size: 12px; margin-left: 4px; }

.material-table input[type=number], .material-table input[type=text] {
    padding: 3px 6px; border: 1px solid #e5e7eb; border-radius: 3px; font-size: 12px;
}
.material-table .ltOverride { background: #fefce8; }

.flag-low { color: #dc2626; font-weight: 600; }

/* 组织过滤条 */
.orgfilter-bar {
    background: #374151; color: #e5e7eb;
    padding: 6px 24px; border-top: 1px solid #4b5563;
    font-size: 12px;
}
.orgfilter-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.orgfilter-label { color: #9ca3af; font-weight: 500; }
.orgfilter-drop { position: relative; }
.orgfilter-drop summary {
    cursor: pointer; list-style: none;
    padding: 4px 10px; background: #4b5563; border-radius: 4px;
    color: #f9fafb; display: inline-flex; align-items: center; gap: 6px;
    user-select: none;
}
.orgfilter-drop summary::-webkit-details-marker { display: none; }
.orgfilter-drop summary:hover { background: #6b7280; }
.orgfilter-drop[open] summary { background: #6b7280; }
.orgfilter-drop .badge {
    background: #2563eb; color: #fff; font-size: 10px;
    padding: 1px 6px; border-radius: 10px; font-weight: 600;
}
.orgfilter-drop .badge-all {
    background: #1f2937; color: #9ca3af; font-size: 10px;
    padding: 1px 6px; border-radius: 10px;
}
.orgfilter-drop .caret { font-size: 9px; color: #d1d5db; }
.orgfilter-panel {
    position: absolute; top: 100%; left: 0; margin-top: 4px;
    background: #fff; color: #1f2937;
    min-width: 340px; max-width: 480px; max-height: 320px; overflow-y: auto;
    padding: 8px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 100;
}
.orgfilter-panel .check-row {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: 3px; font-size: 12px;
    cursor: pointer;
}
.orgfilter-panel .check-row:hover { background: #f3f4f6; }
.orgfilter-panel .empty-hint { padding: 12px; color: #9ca3af; font-size: 12px; }
.orgfilter-hint { color: #9ca3af; margin-left: auto; }
.orgfilter-hint.muted { color: #6b7280; }
.orgfilter-form .btn { color: #1f2937; }
.orgfilter-form .btn.primary { color: #fff; }

/* ---- 全局 loading 遮罩 ---- */
.dl-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(17, 24, 39, 0.35);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 120ms ease;
}
.dl-overlay.show { opacity: 1; pointer-events: auto; }
.dl-overlay-box {
    background: #fff; color: #1f2937;
    padding: 18px 22px; border-radius: 8px;
    box-shadow: 0 10px 32px rgba(0,0,0,0.25);
    display: flex; align-items: center; gap: 14px;
    min-width: 180px; max-width: 80vw;
    font-size: 14px;
}
.dl-spinner {
    width: 22px; height: 22px; flex: 0 0 22px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: dl-spin 0.75s linear infinite;
}
@keyframes dl-spin { to { transform: rotate(360deg); } }
.dl-overlay-msg { line-height: 1.4; }

/* ---- 全局 toast ---- */
.dl-toast-root {
    position: fixed; top: 20px; right: 20px; z-index: 10000;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.dl-toast {
    min-width: 240px; max-width: 420px;
    padding: 10px 14px; border-radius: 6px;
    background: #111827; color: #fff;
    font-size: 13px; line-height: 1.5;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    opacity: 0; transform: translateX(20px);
    transition: opacity 160ms ease, transform 160ms ease;
    pointer-events: auto;
    word-break: break-word;
}
.dl-toast.show { opacity: 1; transform: translateX(0); }
.dl-toast.success { background: #059669; }
.dl-toast.error { background: #dc2626; }
.dl-toast.info { background: #2563eb; }
.dl-toast.warn { background: #d97706; }
