:root {
  --ink: #202925;
  --muted: #77837d;
  --paper: #f5f2ec;
  --surface: #fffdfa;
  --line: #dfe4dd;
  --rail: #152522;
  --rail-2: #20362f;
  --accent: #157a68;
  --accent-soft: #e2f0eb;
  --gold: #c28c35;
  --gold-soft: #fbf0d9;
  --danger: #b64f48;
  --danger-soft: #fae8e5;
  --blue: #4a7396;
  --blue-soft: #e9f0f6;
  --shadow: 0 14px 32px rgba(30, 42, 38, .07);
  --radius: 10px;
  --sans: Avenir Next, PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); font-family: var(--sans); }
body { letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.rail { background: var(--rail); color: #eff5ed; padding: 24px 16px 18px; display: flex; flex-direction: column; min-height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 26px; }
.brand-logo { width: 38px; height: 38px; border-radius: 9px; background: #ed1b24; display: grid; place-items: center; overflow: hidden; }
.brand-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand strong { display: block; font-size: 14px; font-weight: 700; }
.brand span { display: block; margin-top: 3px; color: #9eb1a9; font-size: 10px; letter-spacing: .08em; }
.rail-label { color: #8da49a; font-size: 10px; letter-spacing: .12em; padding: 0 10px 10px; }
.nav { display: grid; gap: 6px; }
.nav-item { width: 100%; border: 1px solid transparent; background: transparent; color: #b8c7c0; padding: 11px 12px; border-radius: 8px; text-align: left; display: flex; align-items: center; gap: 10px; font-size: 12px; transition: .18s ease; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: var(--rail-2); border-color: #3b6256; box-shadow: inset 3px 0 0 var(--gold); }
.nav-index { width: 19px; height: 19px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 5px; font-size: 9px; opacity: .82; }
.rail-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding: 16px 9px 0; color: #9eb1a9; font-size: 10px; line-height: 1.7; }
.rail-foot b { color: #f2f5ec; font-size: 11px; font-weight: 650; }
.main { min-width: 0; padding: 28px clamp(18px, 3vw, 44px) 38px; }
.topline, .content, .footer { max-width: 1420px; margin-left: auto; margin-right: auto; }
.topline { margin-bottom: 22px; display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.eyebrow { color: var(--accent); font-size: 10px; letter-spacing: .14em; font-weight: 700; margin: 0 0 8px; }
h1, h2, h3, h4, h5, p { margin: 0; }
h1 { font-size: clamp(22px, 3vw, 31px); line-height: 1.15; letter-spacing: -.02em; }
.subline { margin-top: 8px; color: var(--muted); font-size: 12px; }
.source-stack { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 580px; }
.source-chip, .tag { border: 1px solid var(--line); background: rgba(255,253,249,.72); color: var(--muted); border-radius: 999px; padding: 6px 9px; font-size: 10px; white-space: nowrap; }
.source-chip b { color: var(--ink); font-weight: 650; }
.muted-chip { color: #9aa49e; }
.view { display: none; }
.view.active { display: block; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 13px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 11px; }
.kpi-value { display: flex; align-items: baseline; gap: 5px; margin-top: 7px; font-size: 23px; font-weight: 750; line-height: 1; }
.kpi-value small { color: var(--muted); font-size: 10px; font-weight: 600; }
.kpi-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; color: var(--muted); font-size: 10px; }
.up { color: var(--accent) !important; }
.down { color: var(--danger) !important; }
.neutral { color: var(--muted) !important; }
.gold-text { color: #93641d !important; }
.blue-text { color: var(--blue) !important; }
.panel, .side-panel, .target-card, .upload-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding: 18px 18px 15px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 16px; line-height: 1.2; }
.panel-head p { color: var(--muted); font-size: 11px; margin-top: 6px; line-height: 1.5; }
.head-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.select, .search { min-height: 32px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; color: var(--ink); padding: 0 10px; font-size: 11px; outline: none; }
.select:focus, .search:focus, .file-input:focus-visible + .file-label { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21,122,104,.1); }
.sort-select { min-width: 174px; }
.search { width: 210px; }
.filter-tabs { display: flex; gap: 4px; padding: 4px; background: #f0f2ed; border-radius: 8px; }
.filter-tabs button { border: 0; border-radius: 6px; padding: 6px 9px; background: transparent; color: var(--muted); font-size: 10px; }
.filter-tabs button.active { background: #fffefa; color: var(--ink); box-shadow: 0 1px 4px rgba(20,32,28,.08); }
.table-wrap { overflow: auto; max-width: 100%; }
.quantity-table-wrap { max-height: calc(100vh - 290px); overflow: auto; overscroll-behavior: contain; }
table { width: 100%; min-width: 980px; border-collapse: separate; border-spacing: 0; font-size: 11px; }
th { position: sticky; top: 0; z-index: 1; background: #f1f4ef; color: #5e6e68; text-align: right; white-space: nowrap; font-size: 10px; font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th:has(.metric-head-sub) { white-space: normal; min-width: 126px; }
.metric-head-title, .metric-head-sub { display: block; }
.metric-head-sub { margin-top: 4px; color: var(--muted); font-size: 9px; font-weight: 500; line-height: 1.25; overflow-wrap: anywhere; }
th:first-child, td:first-child { text-align: left; }
td { text-align: right; white-space: nowrap; padding: 11px 12px; border-bottom: 1px solid #edf0eb; vertical-align: middle; }
tbody tr:hover td { background: #fbfcf8; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { background: #f8f5ed; font-weight: 750; border-top: 1px solid var(--line); border-bottom: 0; }
.total-row td { background: #f8f5ed; font-weight: 750; border-top: 1px solid var(--line); }
.total-row:hover td { background: #f8f5ed; }
.name-cell { color: var(--ink); font-weight: 650; }
.name-cell small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 400; }
.number { font-variant-numeric: tabular-nums; }
.delta { font-weight: 700; }
.delta small, td small { display: block; margin-top: 3px; font-size: 9px; font-weight: 500; }
.pill { display: inline-flex; align-items: center; gap: 3px; border-radius: 999px; padding: 4px 7px; font-size: 9px; line-height: 1; font-weight: 700; }
.pill.up { background: var(--accent-soft); }
.pill.down { background: var(--danger-soft); }
.pill.gold { background: var(--gold-soft); color: #93641d !important; }
.pill.muted { background: #edf0ec; color: var(--muted) !important; }
.pill.blue { background: var(--blue-soft); color: var(--blue) !important; }
.signal-stack { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.region-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; }
.side-panel { padding: 16px; }
.side-panel h3 { font-size: 13px; }
.side-panel > p { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.rank-list { display: grid; gap: 10px; margin-top: 16px; }
.rank-item { border-bottom: 1px solid #edf0eb; padding-bottom: 10px; }
.rank-item:last-child { border-bottom: 0; padding-bottom: 0; }
.rank-line { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; }
.rank-line strong { font-size: 11px; }
.bar { height: 5px; background: #e9eee9; border-radius: 999px; overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.bar i.danger { background: var(--danger); }
.bar i.gold { background: var(--gold); }
.target-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.target-card { padding: 16px; }
.target-card h3 { font-size: 12px; }
.target-card .big { margin-top: 8px; font-size: 22px; font-weight: 750; }
.target-card .sub { color: var(--muted); font-size: 10px; font-weight: 500; }
.target-bar { height: 7px; margin-top: 12px; background: #ebeee8; border-radius: 999px; overflow: hidden; }
.target-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.target-bar i.gold { background: var(--gold); }
.target-bar i.gold-text { background: var(--gold); }
.target-bar i.down { background: var(--danger); }
.target-card-foot { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 10px; }
.target-card .metric-note { margin-top: 8px; }
.metric-note { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; line-height: 1.25; font-weight: 500; font-variant-numeric: tabular-nums; }
.metric-note strong { color: var(--ink); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 12px; padding: 11px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.5; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.down { background: var(--danger); }
.dot.up { background: var(--accent); }
.dot.gold { background: var(--gold); }
.empty { padding: 38px 16px; text-align: center; color: var(--muted); font-size: 12px; }
.empty strong { display: block; color: var(--ink); font-size: 14px; margin-bottom: 6px; }
.note-line { margin-top: 12px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.footer { margin-top: 18px; color: #97a39c; font-size: 10px; display: flex; justify-content: space-between; gap: 10px; }

.setup-hero { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; margin-bottom: 14px; }
.setup-intro { background: var(--rail); color: #f2f5ec; border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.setup-intro .eyebrow { color: #d9b26d; }
.setup-intro h2 { max-width: 560px; font-size: 24px; line-height: 1.25; }
.setup-intro p { max-width: 640px; margin-top: 10px; color: #b7c6be; font-size: 11px; line-height: 1.65; }
.setup-status { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.setup-status h3 { font-size: 13px; }
.status-list { display: grid; gap: 9px; margin-top: 14px; }
.status-line { display: flex; justify-content: space-between; gap: 10px; font-size: 10px; border-bottom: 1px solid #edf0eb; padding-bottom: 8px; }
.status-line:last-child { border-bottom: 0; padding-bottom: 0; }
.status-line span:first-child { color: var(--muted); }
.status-line strong { text-align: right; font-weight: 650; }
.upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.upload-card { padding: 15px; min-width: 0; }
.upload-card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.role-badge { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 4px 7px; color: var(--muted); font-size: 9px; font-weight: 700; }
.upload-card.required { border-top: 3px solid var(--accent); }
.upload-card.optional { border-top: 3px solid var(--gold); }
.upload-card h3 { font-size: 13px; }
.upload-card > p { min-height: 31px; margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-label { display: flex; align-items: center; justify-content: center; min-height: 84px; margin-top: 14px; border: 1px dashed #b8c7be; border-radius: 8px; background: #fafbf8; color: var(--accent); font-size: 11px; font-weight: 700; text-align: center; padding: 12px; transition: .16s ease; }
.file-label:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-name { overflow: hidden; margin-top: 10px; color: var(--ink); font-size: 10px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-top: 4px; color: var(--muted); font-size: 9px; min-height: 14px; }
.name-label { display: block; margin-top: 13px; color: var(--muted); font-size: 9px; font-weight: 650; }
.version-name { width: 100%; min-height: 32px; margin-top: 5px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; color: var(--ink); padding: 0 9px; font-size: 10px; outline: none; }
.version-name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21,122,104,.1); }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.compact-btn { min-height: 30px; padding: 6px 8px; font-size: 9px; }
.compact-btn:disabled { cursor: not-allowed; opacity: .45; }
.history-select { min-width: 0; flex: 1 1 150px; min-height: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; color: var(--ink); padding: 0 7px; font-size: 9px; outline: none; }
.history-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21,122,104,.1); }
.history-load-row { display: flex; align-items: center; gap: 7px; margin-top: 7px; color: var(--muted); font-size: 9px; }
.history-load-row > span { width: 22px; flex: 0 0 22px; }
.remote-save-btn { color: #795a26; }
.remote-save-btn:hover { border-color: var(--gold); color: #795a26; }
.upload-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; background: #f8f5ed; border-top: 1px solid var(--line); }
.primary-btn, .secondary-btn { border-radius: 7px; padding: 9px 14px; font-size: 11px; font-weight: 700; }
.primary-btn { border: 1px solid #126856; background: var(--accent); color: #fff; box-shadow: 0 5px 12px rgba(21,122,104,.18); }
.primary-btn:hover { background: #126856; }
.primary-btn:disabled { cursor: not-allowed; opacity: .45; box-shadow: none; }
.secondary-btn { border: 1px solid var(--line); background: #fffdfa; color: var(--ink); }
.secondary-btn:hover { border-color: var(--accent); color: var(--accent); }
.source-health { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.alert { padding: 11px 13px; border-radius: 8px; font-size: 10px; line-height: 1.5; }
.alert.error { border: 1px solid #e4b7b2; background: var(--danger-soft); color: #8d3c38; }
.alert.success { border: 1px solid #b7d8cc; background: var(--accent-soft); color: #236c5d; }
.alert.info { border: 1px solid #d7c79e; background: var(--gold-soft); color: #795a26; }
.remote-panel { margin-bottom: 14px; }
.remote-connect { display: flex; align-items: center; gap: 8px; padding: 13px 16px 10px; }
.remote-connect label { flex: 0 0 auto; color: var(--muted); font-size: 10px; font-weight: 650; }
.remote-connect input { min-width: 0; flex: 1 1 260px; min-height: 34px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; color: var(--ink); padding: 0 10px; font-size: 10px; outline: none; }
.remote-connect input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21,122,104,.1); }
.remote-hint { padding: 0 16px 12px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.remote-history-list { padding: 0 16px 14px; }
.remote-history-row { background: #fcfaf4; }
.detail-row td { padding: 0; background: #f8faf6; border-bottom: 1px solid var(--line); }
.detail-row:hover td { background: #f8faf6; }
.expand-trigger { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #d6ded7; border-radius: 6px; background: #f7faf6; color: var(--accent); padding: 5px 7px; font-size: 10px; font-weight: 700; }
.expand-trigger:hover, .expand-trigger[aria-expanded="true"] { border-color: #9ac7b8; background: var(--accent-soft); }
.region-breakdown { padding: 14px 18px 16px; }
.breakdown-intro { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.breakdown-intro strong { font-size: 11px; }
.breakdown-intro span { color: var(--muted); font-size: 10px; }
.breakdown-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.metric-breakdown { min-width: 0; border: 1px solid #e0e7df; border-radius: 8px; background: #fffefa; padding: 10px; }
.metric-breakdown h4 { margin: 0 0 8px; font-size: 11px; }
.breakdown-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.breakdown-column h5 { margin: 0 0 5px; color: var(--muted); font-size: 9px; font-weight: 650; }
.breakdown-list { display: grid; gap: 5px; }
.breakdown-item { min-width: 0; padding-bottom: 5px; border-bottom: 1px solid #edf0eb; }
.breakdown-item:last-child { border-bottom: 0; padding-bottom: 0; }
.breakdown-region { display: block; overflow: hidden; color: var(--ink); font-size: 9px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.breakdown-values, .breakdown-delta { display: block; margin-top: 2px; font-size: 9px; font-variant-numeric: tabular-nums; }
.breakdown-values { color: var(--muted); }
.breakdown-delta { font-weight: 700; }
.customer-grid { display: grid; gap: 8px; padding: 14px 18px; }
.customer-card { border: 1px solid #e0e7df; border-radius: 8px; overflow: hidden; background: #fffefa; }
.customer-head { width: 100%; border: 0; background: transparent; padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.customer-head:hover { background: #f5f8f3; }
.customer-head strong { font-size: 11px; }
.customer-head span { color: var(--muted); font-size: 10px; }
.customer-products { padding: 0 12px 12px; }
.customer-products table { min-width: 760px; font-size: 10px; }
.customer-products th, .customer-products td { padding: 8px 9px; }
.customer-products th { position: static; }

@media (max-width: 1050px) { .app-shell { grid-template-columns: 190px minmax(0, 1fr); } .region-layout, .setup-hero { grid-template-columns: 1fr; } .side-panel { order: -1; } }
@media (max-width: 720px) {
  .app-shell { display: block; }
  .rail { min-height: auto; padding: 12px 12px 10px; }
  .brand { padding: 0 4px 12px; }
  .rail-label, .rail-foot { display: none; }
  .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .nav-item { min-width: 0; padding: 8px 7px; font-size: 10px; gap: 6px; }
  .nav-index { width: 17px; height: 17px; font-size: 8px; }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--gold); }
  .main { padding: 20px 12px 24px; }
  .topline { display: block; margin-bottom: 16px; }
  .source-stack { justify-content: flex-start; margin-top: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 19px; }
  .panel-head { display: block; padding: 15px 13px 12px; }
  .head-tools { justify-content: flex-start; margin-top: 12px; }
  .target-grid, .upload-grid { grid-template-columns: 1fr; }
  .setup-intro h2 { font-size: 20px; }
  .breakdown-grid { grid-template-columns: 1fr; }
  .upload-actions { align-items: stretch; flex-direction: column; }
  .upload-actions .primary-btn { width: 100%; }
  .remote-connect { align-items: stretch; flex-direction: column; }
  .remote-connect input, .remote-connect .primary-btn { width: 100%; }
  .quantity-table-wrap { max-height: calc(100vh - 320px); }
  .footer { display: block; line-height: 1.6; }
}
