:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #162033;
  --muted: #667085;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e6f4f1;
  --danger: #b91c1c;
  --ink-soft: #344054;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  overflow-x: hidden;
}

body * {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 700;
}

.topbar {
  min-height: 92px;
  padding: 16px 24px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto minmax(300px, auto);
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

#status,
.muted,
.view-head p {
  color: var(--muted);
}

#status {
  margin-top: 6px;
}

.top-actions,
.stats,
.paper-actions,
.checks {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.top-actions {
  flex-wrap: wrap;
}

.stats {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  min-width: 84px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 6px;
}

.stat strong {
  display: block;
  font-size: 18px;
}

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

.workspace {
  padding: 20px 24px 30px;
  width: 100%;
  max-width: 100vw;
}

.view {
  display: none;
}

.view.active {
  display: block;
  min-width: 0;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 16px;
  max-width: 980px;
}

.module-button {
  min-height: 150px;
  padding: 22px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 10px;
  text-align: left;
  overflow: hidden;
  white-space: normal;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.module-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.module-button strong {
  font-size: 24px;
}

.module-button span {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: anywhere;
}

.desktop-tools {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  max-width: 980px;
}

.desktop-tools .muted {
  min-width: 220px;
  overflow-wrap: anywhere;
}

.view-head {
  margin-bottom: 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.panel,
.table-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 14px;
}

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

.import-page-panel {
  display: grid;
  gap: 12px;
  max-width: 760px;
}

.import-result {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  line-height: 1.5;
}

.paper-panel {
  display: grid;
  gap: 12px;
}

.paper-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1fr) repeat(3, minmax(126px, 0.7fr));
  gap: 10px;
  align-items: end;
}

.paper-form label,
.checks label,
.option-band strong {
  color: var(--muted);
  font-size: 13px;
}

.paper-form label {
  display: grid;
  gap: 5px;
}

.count-control {
  display: grid;
  grid-template-columns: minmax(64px, 1fr) 54px;
  gap: 6px;
}

.count-all {
  padding: 0 8px;
}

.count-all.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: var(--accent);
  font-weight: 700;
}

.option-band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 12px;
  padding-top: 4px;
}

.option-band > div {
  display: grid;
  gap: 8px;
}

.checks {
  flex-wrap: wrap;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.paper-actions {
  justify-content: flex-start;
}

.preview-panel {
  margin-top: 14px;
}

.preview-list {
  display: grid;
  gap: 10px;
}

.preview-item {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.preview-index {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.preview-meta {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 12px;
}

.preview-text {
  color: var(--ink-soft);
}

.empty {
  padding: 16px;
  color: var(--muted);
  background: #fbfcfd;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.tag-tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.upload {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.tag-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

button,
input,
select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

button {
  padding: 0 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary {
  background: #fff;
  color: var(--accent);
}

button:disabled {
  cursor: progress;
  opacity: 0.65;
}

input,
select {
  width: 100%;
  min-width: 0;
  padding: 0 9px;
}

.checks input {
  width: 16px;
  min-height: 16px;
}

.generated-paths {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-all;
}

.table-shell {
  width: 100%;
  max-width: 100%;
  border: 0;
  background: transparent;
}

table {
  display: block;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  min-width: 0;
}

.col-question {
  width: 46%;
}

.col-source {
  width: 16%;
}

.col-type,
.col-grade,
.col-difficulty,
.col-state {
  width: 8%;
}

.col-topic {
  width: 14%;
}

thead {
  display: none;
}

tbody {
  display: grid;
  width: 100%;
  gap: 12px;
}

tbody tr {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

td {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 0;
  border-bottom: 0;
  background: transparent;
  vertical-align: top;
}

tbody td:first-child {
  grid-column: 1;
  grid-row: 1 / span 6;
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

tbody td:not(:first-child)::before {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

tbody td:nth-child(2)::before {
  content: "来源";
}

tbody td:nth-child(3)::before {
  content: "题型";
}

tbody td:nth-child(4)::before {
  content: "年级";
}

tbody td:nth-child(5)::before {
  content: "考点";
}

tbody td:nth-child(6)::before {
  content: "难度";
}

tbody td:nth-child(7)::before {
  content: "状态";
}

.question-preview {
  line-height: 1.55;
}

.rich-question {
  display: grid;
  gap: 6px;
}

.rich-question p {
  line-height: 1.55;
  white-space: pre-wrap;
}

.rich-question img {
  display: block;
  max-width: min(100%, 520px);
  height: auto;
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.rich-question img.equation-image {
  display: inline-block;
  max-width: min(320px, 100%);
  max-height: 3.6em;
  width: auto;
  height: auto;
  margin: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  vertical-align: -0.75em;
  image-rendering: auto;
}

.math-formula {
  display: inline-flex;
  align-items: center;
  min-height: 1.4em;
  margin: 0 3px;
  padding: 0 2px;
  color: var(--text);
  font-family: "Times New Roman", "Cambria Math", "Microsoft YaHei", serif;
  font-size: 1.04em;
  line-height: 1;
  vertical-align: -0.1em;
}

.math-formula math {
  font-family: "Cambria Math", "Times New Roman", serif;
  font-size: 1.08em;
}

.math-rendered {
  gap: 2px;
}

.math-frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  vertical-align: -0.55em;
  margin: 0 2px;
  line-height: 1;
}

.math-frac .math-num {
  width: 100%;
  padding: 0 2px 1px;
  border-bottom: 1px solid currentColor;
  text-align: center;
  font-size: 0.86em;
}

.math-frac .math-den {
  padding: 1px 2px 0;
  text-align: center;
  font-size: 0.86em;
}

.math-sqrt span {
  border-top: 1px solid currentColor;
  padding-left: 2px;
}

.math-overline {
  border-top: 1px solid currentColor;
}

.math-vector {
  position: relative;
  padding-top: 0.15em;
}

.math-vector::before {
  content: "→";
  position: absolute;
  top: -0.65em;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7em;
}

.math-rendered sup,
.math-rendered sub,
.math-native sup,
.math-native sub {
  font-size: 0.72em;
  line-height: 0;
}

.question-table {
  width: auto;
  max-width: 100%;
  min-width: 0;
  margin: 6px 0;
  border-collapse: collapse;
  table-layout: auto;
}

.question-table td {
  min-width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: pre-wrap;
}

.reason {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.source-cell {
  word-break: break-word;
  line-height: 1.5;
  color: var(--ink-soft);
}

.row-state {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.row-status-cell {
  display: grid;
  gap: 8px;
}

.review-label {
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.4;
}

.review-label.manual {
  color: var(--accent-dark);
  font-weight: 700;
}

.row-review-btn {
  width: 100%;
  padding: 0 8px;
}

.row-state.saved {
  color: var(--accent);
}

.row-state.error,
.error {
  color: var(--danger);
}

.toast {
  color: var(--accent);
}

.pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pagination button {
  min-width: 36px;
  padding: 0 10px;
}

.pagination button.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.pagination .page-summary {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .topbar,
  .workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .stats {
    justify-content: flex-start;
  }

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

  .paper-form .wide {
    grid-column: 1 / -1;
  }

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

  tbody tr {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  }
}

@media (max-width: 980px) {
  tbody tr {
    grid-template-columns: 1fr;
  }

  tbody td:first-child {
    grid-column: 1;
    grid-row: auto;
    padding-right: 0;
    padding-bottom: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  h1 {
    font-size: 21px;
  }

  .top-actions,
  .paper-actions {
    width: 100%;
  }

  .top-actions button,
  .paper-actions button {
    flex: 1 1 120px;
  }

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

  .view-head,
  .panel-head {
    align-items: start;
    flex-direction: column;
  }

  .preview-item {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .preview-index {
    width: 30px;
    height: 30px;
  }

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

}

@media (max-width: 460px) {
  .workspace {
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel {
    padding: 12px;
  }

  .count-control {
    grid-template-columns: 1fr 52px;
  }
}
