:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #f0f4ef;
  --ink: #202320;
  --muted: #667065;
  --line: #dce3d8;
  --accent: #14796a;
  --accent-strong: #0b594d;
  --accent-soft: #dcefe8;
  --gold: #a46b10;
  --error: #b42318;
  --shadow: 0 12px 30px rgba(26, 36, 28, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 36px;
  border-radius: 6px;
  padding: 0 14px;
}

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

button:disabled {
  cursor: default;
  opacity: 0.35;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0;
}

.subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#fileInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.upload-button:hover {
  background: var(--accent-strong);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  line-height: 1;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 92px;
  border: 1px dashed #b6c5b2;
  background: rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  margin-bottom: 16px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.drop-zone.dragging {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.drop-zone div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.drop-zone span {
  color: var(--muted);
  font-size: 13px;
}

.status {
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.status[data-type="error"] {
  color: var(--error);
  border-color: #f0b8b2;
  background: #fff6f5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
  gap: 16px;
  align-items: start;
}

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

.summary {
  order: 2;
  position: sticky;
  top: 16px;
  padding: 18px;
}

.tree-panel {
  order: 1;
}

.action-panel {
  display: grid;
  gap: 10px;
}

.action-panel button {
  width: 100%;
  min-height: 44px;
  text-align: center;
}

.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

#fileName {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.45;
}

dl {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

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

dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.depth-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.depth-stats span,
.title-wrap span,
.price-panel span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #425040;
  font-size: 12px;
}

.price-panel span[data-variant="price"] {
  background: #eef5ff;
  color: #1f5f9f;
  font-weight: 600;
}

.price-panel span[data-variant="missing-price"] {
  background: #fff1f0;
  color: var(--error);
  font-weight: 600;
}

.warnings {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid #ead5a9;
  border-radius: 6px;
  background: #fffaf0;
  color: var(--gold);
  font-size: 13px;
}

.warnings p {
  margin: 0;
}

.warnings p + p {
  margin-top: 6px;
}

.tree-panel {
  min-width: 0;
  padding: 14px;
  overflow: visible;
}

.tree-controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(240px, 430px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin: -14px -14px 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 18px rgba(28, 36, 30, 0.06);
  backdrop-filter: blur(8px);
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 40px 0 12px;
  background: #fbfcfb;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 121, 106, 0.12);
}

#clearSearch {
  position: absolute;
  right: 4px;
  top: 4px;
  min-height: 30px;
  width: 30px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.control-group button {
  padding-inline: 12px;
  white-space: nowrap;
}

.tree-meta {
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
}

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

.tree-node {
  --indent: calc((attr(data-depth number, 1) - 1) * 18px);
}

.node-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.tree-node.matched > .node-row {
  border-color: #ddbd61;
  background: #fffdf6;
}

.toggle {
  width: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 5px;
  color: var(--accent);
  font-size: 24px;
  line-height: 20px;
  transform: rotate(0deg);
  transition: transform 0.16s ease;
}

.toggle[data-open="true"] {
  transform: rotate(90deg);
}

.node-main {
  --title-text-offset: 54px;
  min-width: 0;
}

.title-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: start;
  gap: 10px;
  min-height: 28px;
}

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

.title-line strong,
.node-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.45;
}

.node-title {
  cursor: default;
}

.row-number {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.title-wrap span[data-variant="level"] {
  flex: 0 0 46px;
  width: 46px;
}

.price-panel {
  display: grid;
  grid-template-columns: repeat(3, 106px);
  align-items: flex-start;
  justify-content: end;
  justify-self: end;
  gap: 6px;
  flex-shrink: 0;
  width: 330px;
  min-height: 24px;
}

.price-panel span {
  justify-self: stretch;
  white-space: nowrap;
}

.editable-price {
  display: inline-grid;
  grid-template-columns: auto minmax(36px, 1fr);
  align-items: center;
  gap: 4px;
}

.editable-price input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: left;
}

.editable-price input::placeholder {
  color: inherit;
  opacity: 1;
}

.price-source-tooltip {
  width: min(420px, calc(100vw - 24px));
}

.price-result-dialog {
  width: min(720px, calc(100vw - 32px));
}

.price-result-list {
  display: grid;
  gap: 8px;
  max-height: min(46vh, 380px);
  overflow: auto;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #f0d2ce;
  border-radius: 8px;
  background: #fff8f7;
}

.price-result-list p {
  margin: 0;
  color: #7f211a;
  font-size: 13px;
  line-height: 1.5;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin-top: 7px;
  margin-left: var(--title-text-offset);
}

.field {
  display: inline-flex;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.field b {
  color: #4e584d;
  font-weight: 600;
}

.detail-tooltip {
  position: fixed;
  z-index: 40;
  width: min(520px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(12, 20, 16, 0.24);
  pointer-events: auto;
  user-select: text;
}

.detail-tooltip > strong {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
}

.detail-tooltip-grid {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.detail-tooltip-grid span {
  color: var(--muted);
}

.detail-tooltip-grid b {
  min-width: 0;
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.children {
  display: grid;
  gap: 6px;
  margin: 6px 0 0 28px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
}

.empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  transform: translate(-50%, -12px);
  min-width: 160px;
  padding: 10px 18px;
  border: 1px solid rgba(20, 121, 106, 0.22);
  border-radius: 8px;
  background: rgba(28, 42, 37, 0.92);
  color: #fff;
  text-align: center;
  box-shadow: 0 14px 36px rgba(15, 25, 20, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(22, 28, 24, 0.44);
}

.level-dialog {
  width: min(620px, 100%);
  max-height: min(74vh, 680px);
  overflow: auto;
  padding: 22px;
  border: 1px solid #efc7c2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(10, 18, 14, 0.26);
}

.level-dialog h2 {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: 0;
}

.level-dialog p {
  margin: 0;
  line-height: 1.55;
}

.level-issue-list {
  display: grid;
  gap: 8px;
  margin: 16px 0 18px;
  padding: 12px;
  border: 1px solid #f0d4d0;
  border-radius: 6px;
  background: #fff7f6;
  color: #7a271a;
  font-size: 13px;
}

.level-issue-more {
  color: var(--error);
  font-weight: 700;
}

.sheet-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.sheet-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 50px;
  padding: 10px 12px;
  text-align: left;
}

.sheet-option strong {
  overflow-wrap: anywhere;
}

.sheet-option span {
  color: var(--accent);
  font-size: 13px;
}

.sheet-option:disabled span {
  color: var(--error);
}

.primary-action {
  width: 100%;
  min-height: 42px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--accent-strong);
  color: #fff;
}

.plain-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.plain-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.admin-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: 100vh;
  background: #f4f6f9;
}

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 10px;
  background: #eaf1ff;
  border-right: 1px solid #dbe5f7;
}

.admin-brand {
  padding: 4px 12px 16px;
  color: #2264dd;
  font-size: 22px;
  font-weight: 800;
}

.admin-nav {
  display: grid;
  gap: 8px;
}

.admin-nav-item,
.admin-return {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 48px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.62);
  color: #344054;
  text-align: left;
  text-decoration: none;
}

.admin-nav-item.active {
  border-color: #2f6df6;
  background: #fff;
  color: #1f5fff;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #2f6df6;
}

.admin-return {
  margin-top: auto;
  background: #fff;
}

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

.admin-topbar,
.admin-card {
  border: 1px solid #e5e9f2;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(19, 31, 56, 0.04);
}

.admin-topbar {
  margin-bottom: 18px;
  padding: 20px 24px;
}

.admin-card {
  display: none;
  gap: 14px;
  padding: 20px 24px;
}

.admin-card.active {
  display: grid;
}

.price-manager-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(14, 22, 18, 0.08);
}

.price-action-row,
.price-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}

.price-action-row {
  grid-template-columns: minmax(240px, 1fr) 110px 150px 120px;
  align-items: center;
}

.danger-action {
  border-color: #f3b5ae;
  background: #fff3f2;
  color: var(--error);
  font-weight: 700;
}

.danger-action:hover {
  border-color: var(--error);
  color: var(--error);
}

.price-action-row input,
.price-search-row input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

.price-table-wrap {
  max-height: clamp(300px, calc(100vh - 370px), 620px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.price-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.price-table th,
.price-table td {
  max-width: 260px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.price-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef6f1;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.price-table tr:hover td {
  background: #f8fbf8;
}

.pagination {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 10px 0 0;
  background: #fff;
}

.pagination span {
  min-width: 74px;
  color: var(--muted);
  text-align: center;
}

.pagination-meta,
.pagination-status {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pagination-status {
  padding: 0;
  border: 0;
  background: transparent;
}

.pagination-status[hidden] {
  display: block;
  visibility: hidden;
}

#prevPageButton,
#nextPageButton {
  width: 88px;
}

.pagination-status[data-type="error"] {
  color: var(--error);
}

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.page-jump span {
  min-width: auto;
}

.page-jump input {
  width: 78px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}

.rule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.rule-actions {
  display: flex;
  gap: 10px;
}

.rule-actions button,
.rule-toolbar button {
  min-width: 120px;
}

.bottom-status {
  margin: 0;
}

.rule-table input,
.rule-table select {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.rule-table select {
  min-width: 96px;
}

.rule-price-input {
  max-width: 100px;
}

.modified-rule td {
  background: #fff8e8;
}

.modified-rule:hover td {
  background: #fff3d6;
}

.rule-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #2452a0;
  white-space: nowrap;
}

.rule-state.changed {
  background: #fff1cf;
  color: #9a5b00;
  font-weight: 700;
}

.rule-enabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 36px;
  white-space: nowrap;
}

.rule-enabled input {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

@media (max-width: 900px) {
  .shell {
    width: min(100% - 20px, 720px);
    padding-top: 16px;
  }

  .toolbar,
  .actions,
  .tree-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .workspace,
  .tree-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .summary {
    position: static;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .control-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
  }

  .upload-button {
    justify-content: center;
  }

  .price-action-row,
  .price-search-row {
    grid-template-columns: 1fr;
  }

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

  .admin-sidebar {
    position: static;
    height: auto;
  }

  .admin-main {
    padding: 12px;
  }

  .rule-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .price-panel {
    justify-self: stretch;
    width: 100%;
  }

  .children {
    margin-left: 12px;
    padding-left: 10px;
  }
}

@media (max-width: 560px) {
  .node-main {
    --title-text-offset: 0px;
  }

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

  .detail-tooltip-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
