:root {
  --bg: #f4f1eb;
  --surface: #fffaf1;
  --surface-strong: #ffffff;
  --text: #21201d;
  --muted: #6f695f;
  --line: #ddd2c0;
  --accent: #c88a17;
  --accent-dark: #845a08;
  --green: #37765b;
  --rose: #b95d4a;
  --ink: #2c3440;
  --shadow: 0 18px 48px rgba(42, 35, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(200, 138, 23, 0.13), transparent 28rem),
    linear-gradient(315deg, rgba(55, 118, 91, 0.13), transparent 32rem),
    var(--bg);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.workspace {
  display: grid;
  gap: 18px;
}

.topbar,
.panel,
.reference-panel {
  border: 1px solid rgba(132, 90, 8, 0.16);
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 112px;
  padding: 24px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.section-head p,
.compact-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.top-actions,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-strong);
  font-weight: 700;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background-color 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  color: #ffffff;
  background: var(--green);
}

.button.secondary {
  border-color: rgba(55, 118, 91, 0.25);
  color: #ffffff;
  background: var(--ink);
}

.button.ghost {
  border-color: var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}

.panel,
.reference-panel {
  border-radius: 8px;
  padding: 20px;
}

.compact-panel {
  padding: 18px 20px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 0.8fr) minmax(220px, 1.4fr);
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(200, 138, 23, 0.26);
  outline-offset: 1px;
}

.table-wrap,
.breakdown-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  background: rgba(200, 138, 23, 0.09);
}

td {
  font-size: 14px;
}

.lesson-table {
  min-width: 920px;
  margin-top: 14px;
}

.lesson-table td:nth-child(5),
.lesson-table td:nth-child(6),
.lesson-table td:nth-child(7),
.breakdown-table td:nth-child(2),
.breakdown-table td:nth-child(3),
.breakdown-table td:nth-child(4) {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.icon-button {
  min-height: 34px;
  border: 1px solid rgba(185, 93, 74, 0.22);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--rose);
  background: #fff7f5;
  font-size: 13px;
  font-weight: 700;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

.metric span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.metric.highlight {
  border-color: rgba(55, 118, 91, 0.3);
  background: linear-gradient(135deg, rgba(55, 118, 91, 0.12), #ffffff);
}

.metric.highlight strong {
  color: var(--green);
}

.breakdown-table {
  min-width: 560px;
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
}

.reference-panel {
  display: grid;
  gap: 16px;
}

.reference-panel h2 {
  margin-bottom: 0;
}

.rule-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.rule-block ul,
.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-block li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(132, 90, 8, 0.2);
  color: var(--muted);
  font-size: 14px;
}

.rule-block li:last-child {
  border-bottom: 0;
}

.rule-block strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.history-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
  font-weight: 800;
}

.history-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.small-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  font-weight: 700;
}

.small-button.danger {
  color: var(--rose);
}

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

  .sidebar {
    position: static;
  }

  .reference-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .reference-panel h2 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding: 10px 0;
  }

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

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .button,
  .section-head .button {
    width: 100%;
  }

  .field-grid,
  .result-grid,
  .reference-panel {
    grid-template-columns: 1fr;
  }

  .panel,
  .reference-panel,
  .topbar {
    padding: 16px;
  }

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

  .history-actions {
    justify-content: stretch;
  }

  .history-actions button {
    flex: 1;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-shell {
    display: block;
    width: 100%;
    padding: 0;
  }

  .top-actions,
  .section-head .button,
  .icon-button,
  .history-actions,
  .sidebar {
    display: none !important;
  }

  .topbar,
  .panel {
    break-inside: avoid;
    box-shadow: none;
    border-color: #cccccc;
    margin-bottom: 12px;
  }

  input,
  select {
    border: 0;
    padding-left: 0;
  }
}
