:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #e1e7ef;
  --nav: #111b2e;
  --nav-soft: #1b2941;
  --blue: #2868d8;
  --blue-soft: #edf4ff;
  --red: #d92d20;
  --red-soft: #fff0ef;
  --yellow: #b65e00;
  --yellow-soft: #fff7e4;
  --green: #137a4c;
  --green-soft: #edf9f2;
  --purple-soft: #f5efff;
  --gray-soft: #f0f2f5;
  --shadow: 0 8px 24px rgba(23, 32, 51, .07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--panel);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid rgba(40, 104, 216, .28);
  outline-offset: 1px;
}
h1, h2, h3, h4, p { margin-top: 0; }
h1, h2, h3 { color: var(--text); }
h1 { font-size: 1.24rem; margin-bottom: 4px; }
h2 { font-size: 1rem; margin-bottom: 0; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: #edf2f8; }
.login-card { width: min(100%, 400px); padding: 32px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
.login-card h1, .login-card p { text-align: center; }
.login-card label { display: grid; gap: 7px; margin: 16px 0; color: var(--muted); font-size: .9rem; }
.login-mark, .brand-mark { display: grid; place-items: center; color: #fff; background: var(--blue); font-weight: 700; }
.login-mark { width: 48px; height: 48px; margin: 0 auto 16px; border-radius: 13px; }
.form-message { min-height: 22px; margin-top: 10px; color: var(--red); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px; color: #d6dfed; background: var(--nav); }
.brand-block { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand-block strong { display: block; color: #fff; font-size: .98rem; }
.brand-block span { display: block; margin-top: 3px; color: #8191aa; font-size: .69rem; letter-spacing: .04em; }
.brand-mark { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 9px; }
.side-nav { display: grid; gap: 4px; }
.nav-item { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; min-height: 44px; padding: 8px 11px; border: 0; border-radius: 8px; color: #aebbd0; background: transparent; text-align: left; }
.nav-item span { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid #35445d; border-radius: 6px; font-size: .72rem; }
.nav-item small { color: #72829c; font-size: .68rem; }
.nav-item:hover { color: #fff; background: #16243a; }
.nav-item.is-active { color: #fff; background: var(--blue); }
.nav-item.is-active span { border-color: rgba(255,255,255,.42); }
.nav-item.is-active small { color: #dbe8ff; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 8px 2px; border-top: 1px solid #29364b; }
.sidebar-footer strong, .sidebar-footer span { display: block; }
.sidebar-footer strong { color: #fff; font-size: .85rem; }
.sidebar-footer span { margin-top: 3px; color: #8191aa; font-size: .72rem; }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 8px; color: inherit; background: transparent; }
.sidebar .icon-button { border-color: #35445d; }

.workspace { min-width: 0; }
.workspace-head { display: flex; align-items: center; gap: 14px; min-height: 74px; padding: 14px 26px; border-bottom: 1px solid var(--border); background: var(--panel); }
.workspace-head p { margin: 0; font-size: .82rem; }
.global-status { margin-left: auto; color: var(--muted); font-size: .82rem; }
.app-page { padding: 20px 26px 34px; }
.panel, .summary-panel, .relation-panel, .search-results { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.compact-panel { padding: 13px; }
.toolbar, .summary-head, .section-head, .detail-head, .section-title-row, .page-actions, .modal-head, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.toolbar { margin-bottom: 8px; }
.page-actions { justify-content: flex-end; margin-bottom: 14px; }
.section-title-row { margin: 17px 0 10px; }
.section-title-row p { margin: 4px 0 0; font-size: .8rem; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); background: var(--panel); white-space: nowrap; }
.button.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button.secondary { background: var(--panel); }
.button.danger { color: var(--red); border-color: #fac7c3; }
.button.small { min-height: 32px; padding: 5px 9px; font-size: .8rem; }
.button.wide { width: 100%; }
.tiny-button { min-height: 28px; padding: 4px 7px; border: 1px solid var(--border); border-radius: 5px; color: var(--blue); background: rgba(255,255,255,.72); white-space: nowrap; font-size: .72rem; }
.tiny-button:hover { border-color: #aac4ee; background: var(--blue-soft); }
.search-form { display: flex; width: min(100%, 430px); }
.search-form.small { width: 300px; }
.search-form input { border-radius: 7px 0 0 7px; }
.search-form .button { border-radius: 0 7px 7px 0; }
.relation-filter { display: inline-flex; align-items: center; padding: 0; margin: 0 auto 0 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--panel); }
.relation-filter legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.relation-filter label { position: relative; }
.relation-filter input { position: absolute; opacity: 0; pointer-events: none; }
.relation-filter span { display: block; padding: 9px 11px; color: var(--muted); border-right: 1px solid var(--border); font-size: .82rem; }
.relation-filter label:last-child span { border-right: 0; }
.relation-filter input:checked + span { color: #fff; background: var(--blue); }
.sort-controls { display: flex; align-items: flex-end; gap: 8px; }
.sort-controls label { display: grid; gap: 3px; color: var(--muted); font-size: .72rem; }
.sort-controls select { min-width: 130px; }

.status-message { min-height: 24px; margin: 7px 0; color: var(--muted); font-size: .84rem; }
.status-message.error { color: var(--red); }
.search-results { padding: 7px; margin-bottom: 14px; box-shadow: none; }
.search-result { width: 100%; display: flex; justify-content: space-between; gap: 12px; padding: 10px 11px; border: 0; border-bottom: 1px solid var(--border); color: var(--text); background: transparent; text-align: left; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--panel-soft); }
.loading-state, .placeholder-page { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.placeholder-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; color: var(--blue); background: var(--blue-soft); font-size: 1.5rem; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .9s linear infinite; }
.refresh-icon { display: inline-block; font-size: 1.15em; }
.is-refreshing .refresh-icon { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .is-refreshing .refresh-icon { animation: none; } }

.summary-panel { padding: 16px 17px; margin-bottom: 16px; }
.summary-head .muted { margin-top: 6px; }
.summary-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 13px; color: var(--muted); }
.summary-meta strong { color: var(--text); }
.text-red { color: var(--red) !important; }
.text-yellow { color: var(--yellow) !important; }
.text-green { color: var(--green) !important; }
.relation-panel { padding: 15px; margin-bottom: 16px; box-shadow: none; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: .8rem; }
.legend span, .relation-level { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.red { background: var(--red); }.dot.yellow { background: var(--yellow); }.dot.green { background: var(--green); }.dot.blue { background: var(--blue); }
.relation-graph svg { display: block; width: 100%; height: auto; min-height: 260px; }
.graph-line { stroke: var(--border); stroke-width: 2; }.graph-line.high { stroke: var(--red); }.graph-line.medium { stroke: var(--yellow); }.graph-line.low { stroke: var(--green); }
.graph-node { cursor: pointer; }.graph-node:focus rect { stroke-width: 3; }.graph-node rect { stroke-width: 1.5; rx: 9; }
.graph-node text { fill: var(--text); text-anchor: middle; font-size: 12px; }
.graph-node.current rect { fill: var(--blue-soft); stroke: var(--blue); }.graph-node.high rect { fill: var(--red-soft); stroke: var(--red); }.graph-node.medium rect { fill: var(--yellow-soft); stroke: var(--yellow); }.graph-node.low rect { fill: var(--green-soft); stroke: var(--green); }
.graph-label { fill: var(--muted); font-size: 11px; text-anchor: middle; }.mobile-relations { display: none; }

.data-table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.data-table { width: 100%; min-width: 1260px; border-collapse: separate; border-spacing: 0; }
.data-table th { position: sticky; top: 0; z-index: 2; padding: 11px 10px; text-align: left; color: var(--muted); background: var(--panel-soft); font-weight: 600; font-size: .78rem; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 10px; vertical-align: middle; border-bottom: 1px solid var(--border); font-size: .83rem; }
.data-table tbody tr:last-child td { border-bottom: 0; }.data-table tbody tr:hover td { background-color: #f9fbfe; }
.directory-table { min-width: 1170px; }
.relation-level { font-weight: 600; white-space: nowrap; }.relation-level.high { color: var(--red); }.relation-level.medium { color: var(--yellow); }.relation-level.low { color: var(--green); }.relation-level.current { color: var(--blue); }
.site, .number { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }.sub { margin-top: 4px; color: var(--muted); white-space: nowrap; font-size: .75rem; }
.member-link, .text-link { border: 0; padding: 0; color: var(--blue); background: transparent; font-weight: 600; }.member-link:hover, .text-link:hover { text-decoration: underline; }
.positive { color: var(--green); }.negative { color: var(--red); }.order-status { font-weight: 600; white-space: nowrap; }
.data-cell { display: flex; align-items: center; gap: 7px; }.row-refresh { width: 34px; height: 34px; padding: 0; }
.tag { display: inline-block; padding: 2px 6px; color: var(--blue); background: var(--blue-soft); border-radius: 999px; font-size: .72rem; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 7px; margin-top: 11px; }

#back-to-graph { margin-bottom: 14px; }.detail-head { margin-bottom: 12px; }.detail-head .muted { margin-top: 5px; }
.detail-tabs { display: flex; min-height: 48px; gap: 3px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.detail-tab { min-height: 48px; padding: 0 13px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; white-space: nowrap; }.detail-tab.is-active { color: var(--blue); border-bottom-color: var(--blue); }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; }.detail-panel { padding: 15px; box-shadow: none; }.detail-panel h3 { margin-bottom: 9px; }
.pull-rate-panel { margin-bottom: 13px; }.pull-rate-panel h3 { margin-bottom: 3px; }.pull-rate-panel h4 { margin: 15px 0 8px; }
.pull-rate-summary { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 11px; margin-top: 13px; }.pull-rate-note { margin: 9px 0 0; }.pull-rate-table { min-width: 720px; }
.fact { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }.fact:last-child { border-bottom: 0; }.fact dt { color: var(--muted); }.fact dd { margin: 0; text-align: right; word-break: break-word; }
.kpi-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 11px; margin-bottom: 13px; }.kpi { padding: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; }.kpi-label { color: var(--muted); margin-bottom: 6px; }.kpi-value { font-weight: 600; font-variant-numeric: tabular-nums; }.kpi-value.compact { font-size: .92rem; }
.detail-table { min-width: 760px; }.payout-table { min-width: 1120px; }

.kpi-strip { display: grid; grid-template-columns: repeat(4,minmax(150px,1fr)); gap: 10px; margin-bottom: 14px; }.kpi-strip article { padding: 14px 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }.kpi-strip span { display: block; color: var(--muted); font-size: .78rem; }.kpi-strip strong { display: block; margin-top: 7px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.channel-page-note { margin: -4px 0 12px; font-size: .78rem; }
.channel-table-wrap { max-height: calc(100vh - 270px); }.channel-table { min-width: 3500px; }.channel-table th, .channel-table td { padding: 9px 8px; }
.channel-table .sticky-col { position: sticky; z-index: 4; }.channel-table th.sticky-col { z-index: 6; }.channel-table .col-id { left: 0; width: 68px; min-width: 68px; max-width: 68px; }.channel-table .col-date { left: 68px; width: 70px; min-width: 70px; max-width: 70px; }.channel-table .col-product { left: 138px; width: 106px; min-width: 106px; max-width: 106px; }
.channel-table td.sticky-col { background: var(--panel); }.channel-table tbody tr:hover td.sticky-col { background: #f9fbfe; }
.channel-name { display: block; max-width: 178px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }.channel-name:focus { outline: 2px solid rgba(40,104,216,.3); outline-offset: 2px; border-radius: 3px; }
.product-cell { display: block; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .74rem; }.compact-date { border: 0; padding: 0; color: var(--text); background: transparent; font-variant-numeric: tabular-nums; }
.link-stack { display: grid; gap: 4px; }.sync-state { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: .72rem; }.sync-state.synced { color: var(--green); }.sync-state.failed { color: var(--red); }.sync-state.pending { color: var(--yellow); }
.row-blue td, .row-blue td.sticky-col { background-color: var(--blue-soft); }.row-green td, .row-green td.sticky-col { background-color: var(--green-soft); }.row-yellow td, .row-yellow td.sticky-col { background-color: var(--yellow-soft); }.row-purple td, .row-purple td.sticky-col { background-color: var(--purple-soft); }.row-red td, .row-red td.sticky-col { background-color: var(--red-soft); }.row-gray td, .row-gray td.sticky-col { background-color: var(--gray-soft); }
.channel-actions { display: flex; gap: 5px; }.pending-value { color: var(--muted); font-style: normal; }.calculated-value { font-variant-numeric: tabular-nums; white-space: nowrap; }

.admin-grid { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(360px,.9fr); gap: 14px; }.admin-grid > .panel { padding: 15px; }.admin-table { min-width: 680px; }.group-cards { display: grid; gap: 10px; margin-top: 11px; }.group-card { padding: 12px; border: 1px solid var(--border); border-radius: 8px; }.group-card-head { display: flex; justify-content: space-between; gap: 10px; }.permission-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }.permission-tag { padding: 3px 6px; border-radius: 999px; color: var(--muted); background: var(--panel-soft); font-size: .7rem; }.permission-tag.edit { color: var(--blue); background: var(--blue-soft); }

.modal { width: min(94vw, 660px); padding: 20px; border: 0; border-radius: 12px; color: var(--text); background: var(--panel); box-shadow: 0 24px 70px rgba(15,23,42,.25); }.modal::backdrop { background: rgba(15,23,42,.55); }.wide-modal { width: min(94vw, 900px); }.modal-head { margin-bottom: 16px; }.modal-head h2 { font-size: 1.05rem; }.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }.form-grid label, .modal > form > label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; }.form-grid .span-2 { grid-column: 1 / -1; }.check-label { display: flex !important; align-items: center; grid-auto-flow: column; justify-content: flex-start; }.check-label input { width: 17px; min-height: 17px; }.modal-actions { justify-content: flex-end; margin-top: 16px; }.permission-matrix { display: grid; gap: 4px; margin-top: 15px; }.permission-row { display: grid; grid-template-columns: 1fr 90px 90px; align-items: center; padding: 8px 9px; border-bottom: 1px solid var(--border); }.permission-row label { display: flex; align-items: center; gap: 5px; color: var(--muted); }.permission-row input { width: 16px; min-height: 16px; }
.history-list { display: grid; gap: 10px; }.history-item { padding: 11px; border: 1px solid var(--border); border-radius: 8px; }.history-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .76rem; }.history-diff { margin-top: 8px; white-space: pre-wrap; word-break: break-word; font-size: .78rem; }
.history-item pre, #history-content pre { max-width: 320px; max-height: 220px; overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .7rem; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 30; max-width: min(420px,calc(100vw - 40px)); padding: 11px 14px; border-radius: 8px; color: #fff; background: #172033; box-shadow: var(--shadow); }.toast.error { background: var(--red); }
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 188px minmax(0,1fr); }
  .admin-grid { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(2,minmax(150px,1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }.sidebar { position: fixed; z-index: 20; left: -230px; width: 220px; transition: left .2s ease; }.app-shell.menu-open .sidebar { left: 0; }
  .mobile-only { display: inline-grid; }.workspace-head { padding: 12px; }.app-page { padding: 14px 12px 26px; }
  .toolbar, .page-actions { align-items: stretch; flex-direction: column; }.search-form, .search-form.small { width: 100%; }.relation-filter { margin: 0; align-self: flex-start; }
  .detail-grid, .kpi-grid, .pull-rate-summary, .form-grid { grid-template-columns: 1fr; }.form-grid .span-2 { grid-column: auto; }.kpi-strip { grid-template-columns: 1fr 1fr; }
  .relation-graph svg { display: none; }.mobile-relations { display: block; }.mobile-current { width: 100%; padding: 10px; border: 1px solid var(--blue); border-radius: 8px; background: var(--blue-soft); }.mobile-relation { width: 100%; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; }.mobile-reason { color: var(--muted); text-align: right; }
  .permission-row { grid-template-columns: 1fr 70px 70px; }.modal { padding: 16px; }
}
