:root {
  --bg: #f6f8fb;
  --panel: #fff;
  --text: #172033;
  --muted: #687386;
  --line: #e6ebf2;
  --blue: #176bff;
  --green: #22c66f;
  --orange: #ffad1f;
  --purple: #8957f6;
  --cyan: #07bfd3;
  --indigo: #6075f7;
  --pink: #fb5c91;
  --yellow: #f4b400;
  --sky: #56b7ff;
  --mint: #55d2b2;
  --shadow: 0 12px 34px rgba(24, 38, 64, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

button, select, input {
  font: inherit;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
}

.brand-logo {
  width: 86px;
  height: 38px;
  flex: none;
  object-fit: contain;
  object-position: left center;
}

.brand strong {
  min-width: 0;
  line-height: 1.2;
}

.nav {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 14px;
  color: #344052;
  border-radius: 6px;
  text-decoration: none;
  cursor: default;
}

.nav a span {
  width: 20px;
  color: #7c8aa0;
  text-align: center;
}

.nav a.active {
  color: var(--blue);
  background: #eaf2ff;
  font-weight: 700;
}

.nav a.active span {
  color: var(--blue);
}

.sync-time {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding: 18px 24px 26px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.sync-time span {
  font-size: 20px;
}

.sync-time b {
  color: #344052;
  font-weight: 500;
}

.workspace {
  min-width: 0;
  overflow-x: hidden;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}

.filters, .actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.filter {
  position: relative;
}

.filter span {
  position: absolute;
  left: 14px;
  top: -7px;
  padding: 0 4px;
  background: white;
  color: var(--muted);
  font-size: 11px;
}

select, .actions button, .pager button, .pager input {
  height: 38px;
  border: 1px solid var(--line);
  background: white;
  color: #263246;
  border-radius: 6px;
}

select {
  min-width: 150px;
  padding: 0 36px 0 14px;
}

input[type="search"] {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: #263246;
}

.actions button {
  padding: 0 12px;
  border-color: transparent;
}

.bell {
  position: relative;
  width: 38px;
}

.bell em {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  color: white;
  background: #ff3030;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  line-height: 18px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: white;
  background: linear-gradient(135deg, #7bb0ff, #4e7de8);
  border-radius: 50%;
}

main {
  padding: 16px 20px 24px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 12px;
}

.kpi {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 104px;
  padding: 14px 20px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.icon {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  flex: none;
  color: white;
  border-radius: 12px;
  font-size: 24px;
  font-weight: 800;
}

.icon.blue { background: linear-gradient(135deg, #4f85ff, #1b62f4); }
.icon.green { background: linear-gradient(135deg, #4ddc87, #0fa95d); }
.icon.orange { background: linear-gradient(135deg, #ffbd3c, #ff9416); }
.icon.purple { background: linear-gradient(135deg, #b46dff, #7847e8); }
.icon.pink { background: linear-gradient(135deg, #ff7aa7, #ef3f6b); }

.page {
  display: none;
}

.active-page {
  display: block;
}

.kpi-body {
  min-width: 0;
}

.kpi-body span {
  color: #263246;
  font-size: 14px;
  white-space: nowrap;
}

.kpi-body strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 1.8vw, 28px);
  line-height: 1.15;
  letter-spacing: 0;
  white-space: nowrap;
}

.kpi-body p {
  display: flex;
  gap: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.kpi-body b {
  font-weight: 500;
}

.up { color: #ff1f1f; }
.down { color: #00aa63; }
.flat { color: var(--muted); }

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(460px, .94fr);
  gap: 18px;
  margin-bottom: 10px;
}

.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px 6px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.panel small {
  color: #9aa5b5;
  font-size: 13px;
}

.segmented {
  display: flex;
  overflow: hidden;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  min-width: 62px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented .selected {
  color: white;
  background: var(--blue);
}

.unit {
  padding: 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.bar-chart {
  display: grid;
  grid-template-columns: 180px 1fr;
  grid-template-rows: 28px 1fr;
  gap: 10px 14px;
  min-height: 536px;
  padding: 10px 18px 20px;
}

.axis {
  position: relative;
  height: 28px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid #d9e1eb;
}

.axis span {
  position: absolute;
  bottom: 7px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.bars {
  position: relative;
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 180px minmax(0, 1fr) 104px;
  gap: 14px;
  min-height: 448px;
  padding-top: 4px;
}

.bar-item {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 180px minmax(0, 1fr) 104px;
  align-items: center;
  min-height: 34px;
}

.bar-value {
  color: #344052;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-track {
  height: 22px;
  overflow: visible;
  background: #edf2f8;
  border-radius: 999px;
}

.bar-col {
  width: var(--w);
  height: 100%;
  min-width: 5px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c), white 20%));
}

.bar-label {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: #344052;
  font-size: 12px;
  text-align: left;
}

.bar-label b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: white;
  background: var(--c);
  border-radius: 50%;
  font-size: 11px;
}

.bar-label span {
  overflow: hidden;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  min-height: 536px;
  padding: 8px 22px 18px;
}

#shareCanvas {
  justify-self: center;
  width: 360px;
  height: 360px;
  max-width: 100%;
}

.share-table {
  display: grid;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
}

.share-head, .legend-row, .share-total {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 104px 56px;
  gap: 10px;
  align-items: center;
}

.share-head {
  color: #344052;
  font-weight: 700;
}

.legend-row {
  color: #344052;
  min-height: 22px;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.legend-name i {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
}

.legend-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-total {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.table-panel {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  padding: 0 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  height: 34px;
  padding: 0 18px;
  border: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: #344052;
  background: #f8fafc;
  font-weight: 700;
}

tfoot td {
  height: 40px;
  color: #0f172a;
  background: #f8fbff;
  border-top: 2px solid #cfd9e8;
  font-weight: 800;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rank-badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: white;
  background: var(--c);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}

.detail-link {
  color: var(--blue);
  font-weight: 700;
}

.refund-cell {
  color: #ef3f6b;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
  gap: 18px;
  margin-bottom: 10px;
}

.statement-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.statement-panel {
  min-width: 0;
  overflow: hidden;
}

.statement-section td {
  height: 38px;
  color: #176bff;
  background: #eef5ff;
  font-weight: 800;
}

.wide-panel {
  min-width: 0;
}

.line-chart {
  min-height: 300px;
  padding: 8px 18px 18px;
}

.compact-line-chart {
  min-height: 260px;
}

.chart-svg {
  width: 100%;
  height: 260px;
  overflow: visible;
}

.compact-line-chart .chart-svg {
  height: 220px;
}

.compact-table {
  padding: 8px 12px 16px;
}

.compact-table td,
.compact-table th {
  height: 36px;
  font-size: 13px;
}

.muted-inline {
  color: var(--muted);
  font-size: 12px;
}

.mini-donut-wrap {
  display: grid;
  gap: 6px;
  padding: 8px 18px 18px;
}

#adShareCanvas {
  justify-self: center;
  width: 320px;
  height: 260px;
  max-width: 100%;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 18px 12px;
  color: #4a5568;
  font-size: 12px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
}

.metric-bars {
  display: grid;
  gap: 14px;
  padding: 8px 18px 18px;
}

.metric-row {
  display: grid;
  gap: 7px;
}

.metric-row-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #344052;
  font-size: 13px;
}

.metric-track {
  height: 10px;
  overflow: hidden;
  background: #eef2f7;
  border-radius: 999px;
}

.metric-fill {
  height: 100%;
  width: var(--w);
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c), white 35%));
  border-radius: inherit;
}

.metric-sub {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.rate-list {
  display: grid;
  gap: 10px;
  padding: 8px 18px 18px;
}

.rate-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.rate-name {
  min-width: 0;
}

.rate-name strong {
  display: block;
  overflow: hidden;
  color: #263246;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rate-name span {
  color: var(--muted);
  font-size: 12px;
}

.rate-value {
  color: #ef3f6b;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  color: #344052;
  font-size: 13px;
}

.pager div {
  display: flex;
  align-items: center;
  gap: 16px;
}

.pager b, .pager button {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  border-radius: 6px;
}

.pager b {
  color: white;
  background: var(--blue);
}

.pager input {
  width: 46px;
  height: 30px;
  text-align: center;
}

.account-balance-panel {
  overflow: hidden;
}

.account-balance-table {
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.account-balance-table table {
  width: max-content;
  min-width: 2300px;
  table-layout: auto;
  font-size: 12px;
}

.account-balance-table .account-code-col {
  width: 92px;
}

.account-balance-table .account-name-col {
  width: 180px;
}

.account-balance-table .balance-amount-col {
  width: 126px;
}

.account-balance-table .occurrence-amount-col {
  width: 152px;
}

.account-balance-table .purchase-amount-col {
  width: 132px;
}

.account-balance-table .status-col {
  width: 88px;
}

.account-balance-table .reason-col {
  width: 260px;
}

.account-balance-table tbody td:nth-child(1),
.account-balance-table tfoot td:nth-child(1) {
  width: 92px;
}

.account-balance-table tbody td:nth-child(2),
.account-balance-table tfoot td:nth-child(2) {
  width: 180px;
}

.account-balance-table tbody td:nth-child(3),
.account-balance-table tbody td:nth-child(4),
.account-balance-table tbody td:nth-child(11),
.account-balance-table tbody td:nth-child(12),
.account-balance-table tfoot td:nth-child(2),
.account-balance-table tfoot td:nth-child(3),
.account-balance-table tfoot td:nth-child(10),
.account-balance-table tfoot td:nth-child(11) {
  min-width: 126px;
  width: 126px;
}

.account-balance-table tbody td:nth-child(5),
.account-balance-table tbody td:nth-child(6),
.account-balance-table tbody td:nth-child(7),
.account-balance-table tbody td:nth-child(8),
.account-balance-table tbody td:nth-child(9),
.account-balance-table tbody td:nth-child(10),
.account-balance-table tfoot td:nth-child(4),
.account-balance-table tfoot td:nth-child(5),
.account-balance-table tfoot td:nth-child(6),
.account-balance-table tfoot td:nth-child(7),
.account-balance-table tfoot td:nth-child(8),
.account-balance-table tfoot td:nth-child(9) {
  min-width: 152px;
  width: 152px;
}

.account-balance-table tbody td:nth-child(13),
.account-balance-table tbody td:nth-child(14),
.account-balance-table tfoot td:nth-child(12),
.account-balance-table tfoot td:nth-child(13) {
  min-width: 132px;
  width: 132px;
}

.account-balance-table tbody td:nth-child(15),
.account-balance-table tfoot td:nth-child(14) {
  width: 88px;
}

.account-balance-table tbody td:nth-child(16),
.account-balance-table tfoot td:nth-child(15) {
  width: 260px;
}

.account-balance-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbff;
}

.account-balance-table thead tr:nth-child(2) th {
  top: 41px;
}

.account-balance-table th:first-child,
.account-balance-table td:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-balance-table th:nth-child(2),
.account-balance-table td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-head,
.system-amount {
  background: #f4fbf8;
}

.diff-head,
.diff-amount {
  background: #fff9ed;
}

.account-balance-table th.num,
.account-balance-table td.num {
  overflow: hidden;
  padding-left: 10px;
  padding-right: 10px;
  text-overflow: clip;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.account-balance-table th:nth-last-child(2),
.account-balance-table td:nth-last-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-balance-table th:last-child,
.account-balance-table td:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  background: #eef2f7;
  color: #475569;
}

.status-aligned { background: #e7f8ef; color: #047857; }
.status-small_fx_diff { background: #fff7df; color: #a16207; }
.status-source_incomplete { background: #fff1e8; color: #c2410c; }
.status-source_missing { background: #ffe8e8; color: #b91c1c; }
.status-bridge_excluded { background: #eef2ff; color: #4338ca; }
.status-pending_module { background: #eef2f7; color: #475569; }
.status-rule_pending { background: #fff1e8; color: #c2410c; }
.status-closing_entry { background: #f5f3ff; color: #6d28d9; }
.status-platform_warning { background: #fff7df; color: #a16207; }
.status-platform_blocker { background: #ffe8e8; color: #b91c1c; }
.status-empty { display: none; }

.issue-note {
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-balance-table th {
  padding-left: 6px;
  padding-right: 6px;
}

.account-balance-table td {
  padding-left: 8px;
  padding-right: 8px;
}

.account-balance-table tfoot td {
  position: sticky;
  bottom: 0;
  background: #f8fbff;
  font-weight: 800;
}

.inventory-analysis-table table {
  min-width: 2500px;
  table-layout: auto;
}

.inventory-ledger-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}

.inventory-warehouse-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.inventory-sku-picker {
  min-width: 260px;
  max-width: 520px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.inventory-sku-picker summary {
  min-height: 30px;
  padding: 6px 10px;
  color: #344052;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.inventory-sku-picker input {
  width: calc(100% - 20px);
  margin: 0 10px 8px;
}

.inventory-sku-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding: 0 10px 10px;
}

.inventory-sku-check {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.inventory-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #344052;
  font-size: 13px;
  white-space: nowrap;
}

.inventory-check input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.overall-ledger-check {
  border-color: #b8cdfc;
  background: #edf4ff;
  color: var(--blue);
  font-weight: 700;
}

.inventory-clear-btn {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #f3c4c4;
  border-radius: 6px;
  background: #fff7f7;
  color: #b91c1c;
  font-size: 13px;
  cursor: pointer;
}

.inventory-sort-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: #344052;
  font-size: 13px;
}

.inventory-sort-control select {
  min-width: 170px;
  height: 30px;
  padding: 0 28px 0 10px;
  border-radius: 6px;
}

.inventory-analysis-table th,
.inventory-analysis-table td {
  white-space: nowrap;
}

.inventory-analysis-table th:nth-child(1),
.inventory-analysis-table td:nth-child(1) {
  min-width: 96px;
}

.inventory-analysis-table th:nth-child(2),
.inventory-analysis-table td:nth-child(2) {
  min-width: 150px;
}

.inventory-analysis-table th:nth-child(3),
.inventory-analysis-table td:nth-child(3) {
  min-width: 132px;
}

.inventory-analysis-table th:nth-child(4),
.inventory-analysis-table td:nth-child(4) {
  min-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inventory-analysis-table th.num,
.inventory-analysis-table td.num {
  min-width: 110px;
  font-variant-numeric: tabular-nums;
}

.inventory-summary-rows td {
  background: #eef6ff;
  border-bottom: 2px solid #c7d7ef;
  color: #0f172a;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chart-grid, .analysis-grid, .statement-grid, .kpis { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .topbar, .filters, .actions { align-items: stretch; flex-direction: column; height: auto; }
  .topbar { padding: 14px; }
  main { padding: 14px; }
  .kpis, .chart-grid, .analysis-grid, .statement-grid, .share-grid { grid-template-columns: 1fr; }
  .kpi { padding: 16px; }
}

.account-monthly-balance-table table {
  min-width: 1180px;
}

.account-monthly-balance-table th:first-child,
.account-monthly-balance-table td:first-child {
  min-width: 112px;
}

.account-monthly-balance-table th:nth-child(2),
.account-monthly-balance-table td:nth-child(2) {
  min-width: 260px;
}

.account-monthly-balance-table .muted-row td {
  color: #8a94a6;
}
