:root {
  --sidebar-w: 188px;
  --page-gap: 10px;
  --radius: 8px;
  --radius-sm: 6px;
  --bg: #0e1422;
  --surface: rgba(22, 31, 50, 0.86);
  --surface-soft: rgba(25, 36, 58, 0.72);
  --surface-strong: rgba(17, 25, 42, 0.94);
  --line: rgba(232, 205, 139, 0.20);
  --line-soft: rgba(255, 255, 255, 0.08);
  --ink: #f5f1e7;
  --ink-2: rgba(245, 241, 231, 0.72);
  --ink-3: rgba(245, 241, 231, 0.48);
  --accent: #e5bd5a;
  --accent-2: #8bd8cc;
  --danger: #e9596b;
  --ok: #39cf7b;
  --button-bg: rgba(35, 47, 70, 0.88);
  --button-line: rgba(229, 189, 90, 0.42);
  --button-text: #f2d78d;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  --topbar-h: 50px;
  --monitor-h: clamp(104px, 12vh, 126px);
  --content-bottom-gap: 12px;
  color-scheme: dark;
}

body[data-theme="light"] {
  --bg: #eef4f7;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-soft: rgba(248, 251, 253, 0.96);
  --surface-strong: #ffffff;
  --line: rgba(30, 48, 70, 0.15);
  --line-soft: rgba(30, 48, 70, 0.10);
  --ink: #172235;
  --ink-2: #425268;
  --ink-3: #778398;
  --accent: #9d6819;
  --accent-2: #176f66;
  --danger: #b4233b;
  --ok: #15834b;
  --button-bg: transparent;
  --button-line: #132944;
  --button-text: #132944;
  --shadow: 0 10px 24px rgba(31, 44, 61, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(229, 189, 90, 0.07), transparent 34%),
    linear-gradient(150deg, var(--bg), #111c2d 56%, #0d1525);
  color: var(--ink);
  font: 13px/1.5 "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body[data-theme="light"] {
  background: linear-gradient(180deg, #edf4f8, #f7fafc);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 1.35vw, 26px);
  line-height: 1.15;
  font-weight: 800;
}

h2 {
  font-size: clamp(16px, 1vw, 19px);
  line-height: 1.2;
  font-weight: 800;
}

h3 {
  margin-bottom: 8px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.edit-hint,
.quote-pending-count {
  display: none !important;
}

.sidebar {
  position: fixed;
  inset: 10px auto 10px 10px;
  z-index: 40;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 11px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.mark {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(229, 189, 90, 0.42);
  border-radius: 8px;
  background: rgba(229, 189, 90, 0.10);
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
}

.brand-text strong,
.brand-text span {
  display: block;
  white-space: nowrap;
}

.brand-text strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.brand-text span {
  color: var(--ink-3);
  font-size: 11px;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

nav a:hover,
nav a.active {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(229, 189, 90, 0.10);
}

.nav-icon {
  width: 18px;
  text-align: center;
  color: var(--accent);
}

main {
  height: 100vh;
  min-height: 0;
  margin-left: calc(var(--sidebar-w) + 20px);
  padding: 10px 18px var(--content-bottom-gap) 14px;
  display: flex;
  flex-direction: column;
  gap: var(--page-gap);
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  color: var(--ink);
}

.topbar-actions,
.actions,
.toolbar,
.form-row,
.sales-action-bar,
.action-group,
.btn-group,
.purchase-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.preset-title-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.preset-header-actions {
  flex: 1 1 auto;
}

.preset-import-strip {
  min-height: 26px;
  margin: 6px 0 8px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(15, 30, 52, 0.72);
  color: var(--ink-3);
  overflow: hidden;
}

.preset-import-strip .file-status,
.preset-import-strip .btn-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#refreshStatus {
  flex: 0 0 auto;
  min-width: 92px;
  text-align: left;
}

.actions,
.purchase-actions,
.preset-header-actions {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}

button {
  min-width: 0;
  min-height: 34px;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--button-line);
  border-radius: var(--radius);
  background: var(--button-bg);
  color: var(--button-text);
  box-shadow: none;
  cursor: pointer;
  font: inherit;
  font-weight: 750;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button:disabled,
button:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
}

button.danger-action,
button.mini.danger {
  border-color: rgba(233, 89, 107, 0.45);
  color: var(--danger);
}

button.mini {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: var(--surface-strong);
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: vertical;
}

select option {
  color: var(--ink);
  background: var(--surface-strong);
}

input:focus,
select:focus,
textarea:focus,
.editable-cell:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.btn-status,
.file-status {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-status.error {
  color: var(--danger);
}

.demo-mode-badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(57, 207, 123, 0.45);
  border-radius: var(--radius-sm);
  color: var(--ok);
  background: rgba(57, 207, 123, 0.10);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.demo-mode-notice {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 2000;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid rgba(57, 207, 123, 0.42);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  font-weight: 700;
}

.demo-mode-notice.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

body[data-theme="light"] .demo-mode-notice {
  background: #fff;
}

.sticky-monitor {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 1.03fr) minmax(260px, 1.03fr) minmax(220px, 0.72fr) minmax(320px, 1.25fr);
  gap: 10px;
  min-height: var(--monitor-h);
}

.monitor-card,
.quote-inline-panel {
  height: var(--monitor-h);
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.monitor-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
}

.shanxi-quote-card {
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 6px;
  padding: 8px 8px;
}

.shanxi-quote-info {
  min-width: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  padding-left: 14px;
  text-align: center;
}

.shanxi-quote-info strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.1;
}

.shanxi-quote-info span {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shanxi-price-input {
  min-width: 0;
  display: grid;
  grid-template-columns: 86px;
  align-items: baseline;
  justify-items: center;
}

.shanxi-price-input input {
  width: 86px;
  min-width: 0;
  height: 25px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  appearance: textfield;
}

.shanxi-price-input input::placeholder {
  color: var(--ink-3);
  font-size: 15px;
  font-weight: 800;
  opacity: 0.86;
}

.shanxi-price-input input:focus {
  outline: none;
}

.shanxi-price-input input::-webkit-outer-spin-button,
.shanxi-price-input input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.shanxi-price-input em {
  color: var(--ink);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.shanxi-quote-card-actions {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 6px;
}

.shanxi-quote-card-actions button {
  width: 74px;
  min-width: 0 !important;
  height: 26px;
  min-height: 0 !important;
  padding: 0 6px !important;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.shanxi-quote-card-actions .btn-status {
  width: 74px;
  font-size: 9px;
  line-height: 1.1;
}

.monitor-title {
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 7px;
}

.monitor-title .script-name {
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

#wechatStatus,
#quoteMailStatus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px !important;
  font-weight: 800 !important;
  white-space: nowrap;
}

.top-logs {
  min-width: 0;
  max-height: calc(var(--monitor-h) - 20px);
  display: grid;
  align-content: end;
  gap: 3px;
  overflow: auto;
  padding-right: 2px;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.35;
}

.top-logs div {
  min-width: 0;
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.top-logs strong {
  color: var(--ink-2);
  font-weight: 750;
}

.top-logs span {
  color: var(--ink-3);
}

.quote-inline-panel {
  position: relative;
  display: block;
  padding: 0;
}

.quote-inline-panel > #quotePool {
  position: absolute;
  top: 10px;
  right: 68px;
  bottom: 10px;
  left: 68px;
  height: auto;
  min-height: 0;
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.quote-action-main,
.quote-copy-action {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 48px;
  height: auto;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
  line-height: 1.2;
}

.quote-action-main {
  left: 12px;
}

.quote-copy-action {
  right: 12px;
}

.quote-vertical-text {
  display: block;
  white-space: nowrap;
  line-height: 1.18;
}

.quote-message,
.quote-preview-empty,
.quote-summary {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 8px 10px;
  display: block;
  overflow: auto;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.quote-preview-empty {
  display: grid;
  place-items: center;
  text-align: center;
}

.quote-summary-head {
  margin-bottom: 5px;
  color: var(--ink);
  font-weight: 800;
}

.quote-summary-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.quote-summary-line strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
}

.quote-summary-more {
  margin-top: 4px;
  color: var(--ink-3);
}

.shanxi-quote-panel {
  gap: 10px;
}

.shanxi-quote-head {
  align-items: center;
}

.shanxi-quote-actions {
  flex: 1 1 auto;
}

.shanxi-quote-actions input {
  flex: 0 0 150px;
}

.shanxi-quote-meta {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink-2);
  font-weight: 700;
  overflow: hidden;
}

.shanxi-quote-meta strong {
  color: var(--ink);
}

.shanxi-quote-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.76fr) minmax(260px, 0.24fr);
  gap: 10px;
  overflow: hidden;
}

.shanxi-quote-preview,
.shanxi-quote-rules {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  overflow: auto;
}

.shanxi-quote-preview {
  display: grid;
  place-items: center;
  padding: 10px;
}

.shanxi-quote-preview img {
  display: none;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1208 / 1714;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.shanxi-quote-preview img[src] {
  display: block;
}

.shanxi-quote-rules {
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.shanxi-quote-rule {
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.shanxi-quote-rule span {
  display: block;
  color: var(--ink-3);
  font-size: 12px;
}

.shanxi-quote-rule strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
}

@media (max-width: 980px) {
  .shanxi-quote-head {
    align-items: stretch;
    flex-direction: column;
  }

  .shanxi-quote-actions {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .shanxi-quote-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .shanxi-quote-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.page {
  display: none;
}

.page.active {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--page-gap);
  overflow: hidden;
}

.page.active > .panel,
#overview.page.active > .panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel,
.box,
.fold-panel,
.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  min-height: 0;
  padding: 12px;
}

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.panel-head > div:first-child {
  min-width: 0;
  flex: 0 0 auto;
}

.panel-head > .sales-title-row {
  flex: 1 1 auto;
}

.purchase-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sales-title-row {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.sales-title-row h2 {
  flex: 0 0 auto;
}

.purchase-title-row h2 {
  flex: 0 0 auto;
}

.grid {
  display: grid;
  gap: 10px;
}

.stats {
  flex: 0 0 auto;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  margin-bottom: 10px;
}

.stat {
  min-height: clamp(46px, 6vh, 64px);
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stat span,
.stat strong {
  white-space: nowrap;
}

.stat span {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.stat strong {
  flex: 0 0 auto;
  color: var(--ink);
  font-size: clamp(17px, 1.25vw, 22px);
  font-weight: 850;
}

#overview > .stats {
  grid-template-columns: repeat(5, minmax(132px, 1fr));
}

#overview .fold-panel {
  display: block;
}

.overview-profit-head {
  margin-bottom: 6px;
}

.compact-stat-row {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: stretch;
}

.overview-profit-stats .stat {
  min-height: 46px;
  min-width: 0;
  gap: 6px;
  padding-inline: 10px;
}

.overview-profit-stats .stat strong {
  font-size: clamp(15px, 1vw, 18px);
}

.overview-date-actions {
  display: grid;
  grid-template-columns: minmax(132px, 1fr) minmax(132px, 1fr) 68px;
  gap: 8px;
  min-width: 0;
  justify-self: end;
  width: min(560px, 100%);
  margin-left: auto;
}

.overview-date-actions .date-picker-only {
  min-width: 132px;
  padding-inline: 10px 8px;
}

.overview-date-actions button {
  min-width: 0;
}

.date-picker-only {
  cursor: pointer;
  caret-color: transparent;
}

.sales-action-bar {
  flex: 1 1 auto;
  justify-content: space-between;
  overflow-x: auto;
  padding: 0;
  margin-bottom: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.sales-import-strip {
  min-height: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 2px 6px;
  margin-top: -2px;
  margin-bottom: 4px;
  overflow: hidden;
  border-bottom: 1px solid var(--line-soft);
}

.sales-import-strip .file-status,
.sales-import-strip .btn-status {
  max-width: 34vw;
}

.action-group.left,
.action-group.right {
  flex-wrap: nowrap;
}

.action-group.right {
  margin-left: auto;
}

.btn-group {
  flex: 0 0 auto;
}

.purchase-tabs {
  flex: 0 0 auto;
  margin-bottom: 0;
}

.purchase-tabs button {
  min-width: 76px;
}

.purchase-actions button,
.preset-header-actions button,
.panel-head .actions button,
.sales-action-bar button {
  flex: 0 0 auto;
}

.clear-filter-action {
  min-width: 88px;
}

.preset-header-actions {
  max-width: min(76vw, 980px);
}

.profit-kpi-row {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  margin-bottom: 8px;
}

.overview-detail-fold {
  flex: 0 0 auto;
  margin-top: 8px;
  overflow: hidden;
}

.overview-filter-summary {
  list-style: none;
  min-height: 39px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 560px);
  align-items: center;
  gap: 10px;
}

.overview-filter-summary::-webkit-details-marker {
  display: none;
}

.overview-detail-fold[open] {
  min-height: 0;
}

.overview-detail-fold > .table-wrap,
.overview-profit-grid-wrap,
#overview .profit-matrix-wrap {
  max-height: min(34vh, 360px);
}

.panel-subhead {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px 8px;
}

.panel-subhead .profit-kpi-row {
  margin-bottom: 0;
}

.panel-subhead .profit-actions {
  justify-content: flex-end;
}

.finance-grid {
  flex: 0 0 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: start;
  gap: 10px;
}

.box {
  min-height: 0;
  padding: 12px;
  height: clamp(360px, 52vh, 500px);
  display: flex;
  flex-direction: column;
}

.form-row.small {
  display: grid;
  grid-template-columns: repeat(2, minmax(88px, 1fr)) auto auto;
}

.finance-grid .box:nth-child(3) .form-row.small {
  grid-template-columns: repeat(2, minmax(110px, 1fr)) auto;
}

.result,
.result-text,
.textarea-result {
  flex: 1 1 auto;
  min-height: 80px;
  margin-top: 8px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink-2);
}

.result,
.result-text {
  padding: 10px 12px;
}

.result-text {
  display: grid;
  place-items: center;
  text-align: center;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: none;
  scrollbar-color: var(--accent) rgba(255, 255, 255, 0.08);
  scrollbar-width: auto;
}

body[data-theme="light"] .table-wrap {
  scrollbar-color: #111827 #e3e9ef;
}

.table-wrap::-webkit-scrollbar,
.top-logs::-webkit-scrollbar,
.actions::-webkit-scrollbar,
.sales-action-bar::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.top-logs::-webkit-scrollbar {
  width: 6px;
}

.table-wrap::-webkit-scrollbar-track,
.top-logs::-webkit-scrollbar-track,
.actions::-webkit-scrollbar-track,
.sales-action-bar::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.table-wrap::-webkit-scrollbar-thumb,
.top-logs::-webkit-scrollbar-thumb,
.actions::-webkit-scrollbar-thumb,
.sales-action-bar::-webkit-scrollbar-thumb {
  border: 2px solid rgba(17, 25, 42, 0.92);
  border-radius: 10px;
  background: var(--accent);
}

body[data-theme="light"] .table-wrap::-webkit-scrollbar-track,
body[data-theme="light"] .top-logs::-webkit-scrollbar-track,
body[data-theme="light"] .actions::-webkit-scrollbar-track,
body[data-theme="light"] .sales-action-bar::-webkit-scrollbar-track {
  background: #e3e9ef;
}

body[data-theme="light"] .table-wrap::-webkit-scrollbar-thumb,
body[data-theme="light"] .top-logs::-webkit-scrollbar-thumb,
body[data-theme="light"] .actions::-webkit-scrollbar-thumb,
body[data-theme="light"] .sales-action-bar::-webkit-scrollbar-thumb {
  border-color: #e3e9ef;
  background: #111827;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-2);
  font-size: 12px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 7px 8px;
  background: rgba(25, 36, 58, 0.98);
  color: var(--ink);
  font-weight: 800;
}

body[data-theme="light"] th {
  background: #eaf0f6;
}

td:last-child,
th:last-child {
  border-right: 0;
}

tbody tr:hover td {
  background: rgba(229, 189, 90, 0.07);
}

tbody tr.row-jump-highlight td {
  background: rgba(229, 189, 90, 0.20) !important;
  box-shadow: inset 0 0 0 1px rgba(229, 189, 90, 0.55);
}

button.copy-ok,
button.copy-ok.secondary,
.quote-copy-action.copy-ok {
  border-color: #20b866 !important;
  color: #20d07a !important;
  background: rgba(32, 184, 102, 0.14) !important;
}

body[data-theme="light"] tbody tr:nth-child(even) td {
  background: #f8fafc;
}

body[data-theme="light"] tbody tr:hover td {
  background: #e7f2f1;
}

body[data-theme="light"] tbody tr.row-jump-highlight td {
  background: #fff0bf !important;
  box-shadow: inset 0 0 0 1px #c79d31;
}

.sales-grid-wrap,
.purchase-grid-wrap,
.preset-grid-wrap,
.profit-matrix-wrap {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  max-height: none;
}

.sales-panel {
  height: auto;
}

.sales-table {
  table-layout: fixed;
}

.sales-table td,
.sales-table th {
  height: 36px;
}

.sales-table tbody tr {
  height: 40px;
}

.sales-table tbody td.address-cell,
.sales-table tbody td.remark-cell,
.sales-table tbody td.address-cell .editable-cell,
.sales-table tbody td.remark-cell .editable-cell {
  text-align: left;
}

.preset-table,
.purchase-table,
.stock-table {
  width: max-content;
  min-width: 100%;
}

.profit-matrix,
.overview-profit-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.profit-matrix th,
.profit-matrix td,
.overview-profit-table th,
.overview-profit-table td {
  height: 31px;
  min-height: 31px;
  padding: 5px 4px;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.22;
  text-overflow: ellipsis;
}

.overview-profit-table th {
  padding-top: 6px;
  padding-bottom: 6px;
}

.overview-profit-table td.profit-col-date,
.overview-profit-table td.profit-col-quantity,
.overview-profit-table td.profit-col-investment-weight,
.overview-profit-table td.profit-col-net-rate,
.overview-profit-table td.profit-col-service-margin-rate {
  font-variant-numeric: tabular-nums;
}

.editable-cell {
  display: block;
  height: 34px;
  padding: 7px 9px;
  overflow: hidden;
  color: var(--ink-2);
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
  outline: none;
}

.editable-cell:hover {
  background: rgba(229, 189, 90, 0.08);
  color: var(--ink);
}

.formula-cell,
.readonly-cell {
  background: rgba(255, 255, 255, 0.035);
}

.formula-cell .editable-cell,
.readonly-cell .editable-cell,
.fixed-cell {
  color: var(--ink-3);
}

.formula-cell .editable-cell::after {
  content: " fx";
  color: rgba(229, 189, 90, 0.50);
  font-size: 10px;
}

.dirty-cell {
  background: rgba(229, 189, 90, 0.13) !important;
}

.draft-cell {
  background: rgba(139, 216, 204, 0.10) !important;
}

.cell-select,
.cell-input,
.profit-matrix input {
  width: 100%;
  min-width: 100px;
  height: 32px;
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  background: transparent;
}

.profit-matrix input {
  min-width: 0;
  padding: 5px 4px;
  text-align: center;
}

.profit-matrix td:first-child input {
  text-align: left;
}

.profit-matrix button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 11px;
}

.row-actions,
.preset-actions,
.profit-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px 6px;
}

.action-col {
  position: sticky;
  right: 0;
  z-index: 3;
  width: 74px;
  min-width: 74px;
  background: var(--surface-strong);
}

th.action-col {
  z-index: 5;
}

.select-col,
.select-head {
  position: sticky;
  left: 0;
  z-index: 5;
  width: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
  background: var(--surface-strong);
}

thead .select-col {
  z-index: 6;
}

.select-cell {
  padding: 4px;
}

.select-cell-inner {
  display: grid;
  grid-template-columns: 16px 34px;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

.sales-check,
.select-all-check {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.insert-tools {
  display: grid;
  grid-template-columns: repeat(2, 16px);
  gap: 2px;
}

.insert-trigger {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  border-radius: 4px;
  font-size: 10px;
}

.filter-head {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  gap: 6px;
  align-items: center;
}

.th-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.filter-trigger {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 900;
}

.filter-trigger.active {
  background: rgba(229, 189, 90, 0.22);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(229, 189, 90, 0.34) inset;
}

body[data-theme="light"] .filter-trigger,
body[data-theme="light"] .insert-trigger {
  background: transparent;
  color: #111827;
  border-color: #111827;
}

body[data-theme="light"] .filter-trigger.active {
  background: rgba(181, 133, 34, 0.14);
  color: #8a5b00;
  border-color: #b58522;
}

.filter-menu {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  z-index: 40;
  width: min(300px, 78vw);
  max-height: 360px;
  display: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.filter-trigger.open + .filter-menu,
.filter-menu.open {
  display: block;
}

.filter-search {
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
}

.filter-tools {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.filter-tools button,
.filter-only {
  min-height: 26px;
  padding: 3px 7px;
  font-size: 12px;
}

.filter-options {
  max-height: 235px;
  overflow: auto;
  padding: 6px;
}

.filter-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  color: var(--ink-2);
  text-align: left;
}

.filter-option span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-empty {
  padding: 10px;
  color: var(--ink-3);
}

.col-resize {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 5;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.col-resize:hover {
  background: rgba(229, 189, 90, 0.28);
}

.overview-profit-detail-title,
.table-loading,
.table-error {
  padding: 10px 12px;
  color: var(--ink-2);
  font-weight: 750;
}

.table-error {
  color: var(--danger);
}

.fold-panel {
  padding: 0;
}

.fold-panel summary {
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.fold-panel summary::-webkit-details-marker {
  display: none;
}

.list {
  display: grid;
  gap: 6px;
}

.item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-3);
}

.item strong {
  color: var(--ink);
}

@media (max-width: 1560px) {
  :root {
    --sidebar-w: 176px;
    --topbar-h: 46px;
    --monitor-h: clamp(100px, 11vh, 118px);
  }

  main {
    margin-left: calc(var(--sidebar-w) + 16px);
    padding-right: 14px;
  }

  .sidebar {
    padding-inline: 10px;
  }

  nav a {
    padding-inline: 8px;
    font-size: 12.5px;
  }

  .brand-text strong {
    font-size: 14px;
  }
}

@media (max-width: 1320px) {
  :root {
    --monitor-h: 98px;
  }

  body {
    overflow: hidden;
  }

  main {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .sticky-monitor {
    grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr);
  }

  .page.active,
  .page.active > .panel {
    overflow: hidden;
  }

  .compact-stat-row,
  #overview > .stats {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .overview-profit-stats.compact-stat-row {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .overview-date-actions {
    grid-column: 1 / -1;
    grid-template-columns: minmax(132px, 1fr) minmax(132px, 1fr) 68px;
  }

  .overview-filter-summary {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .panel-subhead .profit-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 1020px) {
  :root {
    --sidebar-w: 64px;
  }

  .brand-text,
  nav a span:not(.nav-icon) {
    display: none;
  }

  .brand {
    justify-content: center;
  }

  nav a {
    justify-content: center;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .purchase-title-row {
    justify-content: space-between;
  }

  .sales-title-row {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }
}
