:root {
  /* Theme inspired by the sample UI (blue topbar + light sidebar). */
  --bg: #ecf0f5;
  --card: #ffffff;
  --ink: #1f2d3d;
  --muted: #6b7280;
  --line: #d2d6de;
  --primary: #3c8dbc;
  --primary-dark: #367fa9;
  --sidebar-bg: #f9fafc;
  --sidebar-hover: #eef6ff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --radius: 4px;
  --topbar-h: 52px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.topbar .logo {
  font-weight: 800;
  letter-spacing: 0.3px;
  font-size: 16px;
  color: #fff;
}

.topbar .logo:hover {
  text-decoration: none;
}

.topbar-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar-who {
  font-size: 13px;
  opacity: 0.95;
}

.layout {
  min-height: calc(100vh - var(--topbar-h));
  display: grid;
  grid-template-columns: 161px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 10px 10px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.top-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.side-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.side-nav a.nav-item {
  display: block;
  padding: 10px 10px;
  border-radius: 3px;
  background: transparent;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  color: #374151;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.side-nav a.nav-item:hover {
  text-decoration: none;
  background: var(--sidebar-hover);
  border-color: rgba(60, 141, 188, 0.25);
}

.side-nav a.nav-item[aria-current="page"] {
  background: rgba(60, 141, 188, 0.16);
  border-color: rgba(60, 141, 188, 0.35);
  border-left-color: var(--primary);
  color: #111827;
}

.nav-ico {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(31, 45, 61, 0.65);
  flex: 0 0 auto;
}

.nav-ico svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
}

.main {
  min-width: 0;
  padding: 16px;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-main {
  width: min(460px, calc(100vw - 24px));
}

.login-card {
  padding: 18px;
}

.period {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 3px;
}

.msg {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: rgba(217, 237, 247, 0.8);
  border: 1px solid rgba(188, 232, 241, 0.9);
  border-left: 4px solid var(--primary);
  border-radius: 3px;
}

.warn {
  color: #92400e;
}

.muted {
  color: var(--muted);
}

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.85);
  margin-left: 8px;
}

.tag-locked {
  border-color: rgba(243, 156, 18, 0.6);
  background: rgba(243, 156, 18, 0.12);
}

.tag-ok {
  border-color: rgba(0, 166, 90, 0.6);
  background: rgba(0, 166, 90, 0.12);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px;
  box-shadow: var(--shadow);
}

.card h1,
.card h2,
.card h3 {
  margin: 8px 0 10px;
}

.hint {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

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

.grid > * {
  min-width: 0;
}

.cash-grid {
  grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
}

.import-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
}

.rebate-main-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .cash-grid,
  .import-grid,
  .rebate-main-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav ul {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

.kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.kpi .k {
  color: var(--muted);
  font-size: 13px;
}

.kpi .v {
  font-size: 18px;
  font-weight: 800;
}

.scroll {
  max-height: 62vh;
  overflow: auto;
}

.scroll .tbl {
  min-width: 900px;
}

.table-x {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.table-x .tbl {
  min-width: 100%;
}

.table-x-wide .tbl {
  min-width: 980px;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
}

.tbl th,
.tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
}

.tbl th {
  text-align: left;
  color: rgba(31, 45, 61, 0.92);
  background: rgba(217, 237, 247, 0.75);
  border-bottom: 1px solid rgba(188, 232, 241, 0.95);
  position: relative;
}

.col-resizer {
  position: absolute;
  right: -2px;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 8;
}

.col-resizer:hover {
  background: rgba(60, 141, 188, 0.18);
}

body.is-col-resizing,
body.is-col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.confirm-info {
  min-width: 3.8em;
  max-width: 3.8em;
  text-align: center;
  white-space: normal;
  word-break: break-all;
  font-weight: 700;
}

.tbl th.num {
  text-align: right;
}

.tbl tr:hover td {
  background: rgba(249, 250, 252, 0.9);
}

.tbl.small td,
.tbl.small th {
  padding: 7px 9px;
}

.subtotal-row td {
  font-weight: 700;
  background: rgba(217, 237, 247, 0.35);
}

/* Bank table: tighter rows and slightly narrower columns to show more items per page. */
.bank-tbl {
  table-layout: fixed;
  width: 100%;
  min-width: 0;
}

.bank-tbl th,
.bank-tbl td {
  padding: 6px 8px;
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

.bank-tbl th:nth-child(2),
.bank-tbl td:nth-child(2) {
  min-width: 10ch;
  white-space: nowrap;
}

.bank-tbl th:nth-child(3),
.bank-tbl td:nth-child(3) {
  min-width: 10ch;
  white-space: nowrap;
}

.bank-tbl th:nth-child(4),
.bank-tbl td:nth-child(4),
.bank-tbl th:nth-child(5),
.bank-tbl td:nth-child(5) {
  white-space: normal;
  word-break: break-word;
}

.bank-tbl th:nth-child(5),
.bank-tbl td:nth-child(5) {
  white-space: normal;
  word-break: break-word;
}

.bank-tbl th:nth-child(7),
.bank-tbl td:nth-child(7) {
  min-width: 22ch;
  white-space: nowrap;
}

.bank-tbl select.mini {
  min-width: 96px;
  width: 100%;
}

.bank-tbl .inline-form {
  flex-wrap: nowrap;
  gap: 6px;
}

.bank-tbl .inline-form .mini {
  min-width: 120px;
  width: auto;
}

.bank-tbl .inline-form .tool-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.bank-grid {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

.bank-table-wrap {
  overflow: visible;
  padding-bottom: 0;
}

.bank-summary-wrap {
  overflow: visible;
}

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

label {
  display: block;
  margin: 10px 0 6px;
  color: rgba(0, 0, 0, 0.75);
  font-size: 14px;
}

input,
select {
  width: 100%;
  padding: 10px 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(60, 141, 188, 0.6);
  box-shadow: 0 0 0 2px rgba(60, 141, 188, 0.15);
}

button,
.btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 3px;
  border: 1px solid var(--primary-dark);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}

button:hover,
.btn:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  text-decoration: none;
}

.tool-btn {
  margin-top: 0;
  padding: 7px 10px;
  background: var(--primary);
  border-color: var(--primary-dark);
  color: #fff;
}

.tool-btn:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.danger-btn {
  background: #dd4b39;
  border-color: #c64333;
  color: #fff;
  font-weight: 800;
}

.danger-btn:hover {
  background: #c64333;
  border-color: #b63b2d;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0;
}

.actions.end {
  justify-content: flex-end;
}

.inline {
  display: inline-block;
  margin-right: 8px;
}

.period-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.period-inline label {
  margin: 0;
}

.period-inline .period-label {
  color: rgba(0, 0, 0, 0.75);
  font-size: 14px;
}

.period-inline button {
  margin-top: 0;
}

input.compact-number {
  width: 5.6em;
  min-width: 5.6em;
  padding: 6px 7px;
}

select.compact-month {
  width: 4.6em;
  min-width: 4.6em;
  padding: 6px 7px;
}

.period-head {
  justify-content: flex-start;
}

.period-head h2 {
  margin: 0;
}

.import {
  padding: 10px 0;
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

.import-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.import-form .file-pick {
  width: auto;
  min-width: min(430px, 100%);
}

.file-pick::file-selector-button {
  margin-right: 10px;
  padding: 7px 10px;
  border: 1px solid #367fa9;
  border-radius: 3px;
  background: #3c8dbc;
  color: #fff;
  cursor: pointer;
}

.file-pick:hover::file-selector-button {
  background: #367fa9;
  border-color: #2f6f93;
}

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.month-end td {
  background: rgba(243, 156, 18, 0.10);
}

.cat-default {
  color: #374151;
}

.cat-income-public {
  color: #0f766e;
  font-weight: 700;
}

.cat-income-private {
  color: #075985;
  font-weight: 700;
}

.cat-income-other {
  color: #166534;
}

.cat-goods {
  color: #92400e;
  font-weight: 700;
}

.cat-salary {
  color: #1d4ed8;
}

.cat-social {
  color: #047857;
}

.cat-housing {
  color: #7c3aed;
}

.cat-reimburse {
  color: #b45309;
}

.cat-tax {
  color: #b91c1c;
}

.cat-other-cost {
  color: #6b7280;
}

.cat-refund {
  color: #7c2d12;
}

.cat-exclude {
  color: #64748b;
  text-decoration: line-through;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
}

.inline-form button {
  margin-top: 0;
}

input.mini,
select.mini {
  width: auto;
  min-width: 120px;
  padding: 7px 8px;
  border-radius: 3px;
  font-size: 13px;
}

/* Excel-like preview grid */
.excel-wrap {
  border: 1px solid var(--line);
  background: #fff;
  overflow: auto;
  max-height: 68vh;
}

.excel {
  border-collapse: collapse;
  font-size: 12px;
}

.hq-preview .excel {
  font-size: 16px;
}

.sales-preview .excel {
  font-size: 14px;
}

.kpi.kpi-lg .v {
  font-size: 20px;
}

.hint.hint-lg {
  font-size: 16px;
}

.hq-preview .excel-wrap {
  max-height: 76vh;
}

.sales-preview .excel-wrap {
  max-height: none;
  overflow-x: auto;
  overflow-y: hidden;
}

.sales-preview .excel.sales-preview-table {
  width: max-content;
  min-width: 100%;
}

.excel th,
.excel td {
  border: 1px solid #e5e7eb;
  padding: 4px 6px;
  white-space: nowrap;
  vertical-align: top;
}

.excel thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f3f4f6;
  color: rgba(31, 45, 61, 0.9);
  font-weight: 700;
}

.excel .rowhdr {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f3f4f6;
  text-align: right;
  color: rgba(107, 114, 128, 0.95);
  font-weight: 700;
}

.excel .corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  background: #e5e7eb;
}

.expert-board-wrap {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fafcff;
}

.expert-store h3 {
  margin: 6px 0 10px;
  font-size: 15px;
}

.expert-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  max-height: none;
  overflow: visible;
}

.expert-card {
  aspect-ratio: 1 / 1;
  min-height: 96px;
  border: 1px solid rgba(60, 141, 188, 0.35);
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff 0%, #eef6ff 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 10px;
}

.expert-name {
  font-weight: 800;
  line-height: 1.2;
}

.expert-remain {
  margin-top: 8px;
  color: #1f4f7a;
  font-variant-numeric: tabular-nums;
}

.table-fit {
  overflow: visible;
}

.b4-table-wrap {
  overflow: visible;
}

.rebate-board-wrap,
.rebate-recent-wrap {
  overflow: visible;
}

.users-table-wrap,
.rules-table-wrap {
  overflow: visible;
}

.rebate-pay-board,
.rebate-recent {
  table-layout: fixed;
  width: 100%;
}

.rebate-pay-board th:nth-child(1),
.rebate-pay-board td:nth-child(1) {
  width: 12ch;
}

.rebate-pay-board th:nth-child(2),
.rebate-pay-board td:nth-child(2),
.rebate-pay-board th:nth-child(3),
.rebate-pay-board td:nth-child(3),
.rebate-pay-board th:nth-child(4),
.rebate-pay-board td:nth-child(4) {
  width: 10ch;
}

.rebate-pay-board th:nth-child(5),
.rebate-pay-board td:nth-child(5) {
  width: 12ch;
}

.rebate-pay-board th:nth-child(6),
.rebate-pay-board td:nth-child(6) {
  width: 8ch;
}

.rebate-pay-board th:nth-child(7),
.rebate-pay-board td:nth-child(7) {
  width: 25ch;
}

.rebate-pay-board .inline-form {
  gap: 6px;
}

.rebate-pay-board .inline-form input.mini {
  min-width: 9ch;
  width: 9ch;
}

.rebate-pay-board .inline-form button.tool-btn {
  padding: 5px 8px;
}

.rebate-recent th:nth-child(1),
.rebate-recent td:nth-child(1) {
  width: 12ch;
}

.rebate-recent th:nth-child(2),
.rebate-recent td:nth-child(2) {
  width: 12ch;
}

.rebate-recent th:nth-child(3),
.rebate-recent td:nth-child(3) {
  width: 10ch;
}

.rebate-recent th:nth-child(4),
.rebate-recent td:nth-child(4) {
  white-space: normal;
  word-break: break-word;
}

.rebate-settle {
  table-layout: fixed;
  font-size: 13px;
}

.rebate-settle th,
.rebate-settle td {
  padding: 7px 8px;
}

.rebate-settle th:nth-child(1),
.rebate-settle td:nth-child(1) {
  width: 28%;
}

.rebate-settle th:nth-child(2),
.rebate-settle td:nth-child(2) {
  width: 24%;
}

.rebate-settle th:nth-child(3),
.rebate-settle td:nth-child(3) {
  width: 14%;
}

.rebate-settle th:nth-child(4),
.rebate-settle td:nth-child(4) {
  width: 18%;
}

.rules-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 14px;
}

.rules-main,
.rules-side {
  min-width: 0;
}

.rules-expert-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.rules-expert-stack {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.rules-expert-col {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  background: #fbfdff;
}

.rules-expert-col h3 {
  margin: 4px 0 8px;
  font-size: 15px;
}

.rules-xiehe {
  min-height: 170px;
}

.rules-static-wrap {
  overflow: visible;
}

.rules-static-table {
  table-layout: fixed;
  width: 100%;
}

.rules-static-table th,
.rules-static-table td {
  white-space: normal;
  word-break: break-word;
}

.rules-add-form {
  gap: 8px;
  align-items: center;
  margin: 6px 0 12px;
}

.rules-add-form .inline-label {
  display: inline-block;
  margin: 0;
  white-space: nowrap;
}

.rules-add-form input.mini {
  min-width: 14ch;
}

.rules-add-form select.mini {
  min-width: 11ch;
}

.rules-add-form .danger-btn {
  margin-top: 0;
}

.ratio-inline-form {
  flex-wrap: nowrap;
  margin: 0;
}

.ratio-inline-form .ratio-mini {
  min-width: 7ch;
}

@media (max-width: 1100px) {
  .rules-layout {
    grid-template-columns: 1fr;
  }

  .rules-expert-grid {
    grid-template-columns: 1fr;
  }

  .bank-grid {
    grid-template-columns: 1fr;
  }
}
