:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef4ff;
  --ink: #182233;
  --muted: #647083;
  --line: #d9e1ec;
  --blue: #1d5fd1;
  --blue-dark: #174ba2;
  --yellow: #f5bd2f;
  --green: #16865c;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(29, 95, 209, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(20px, 5vw, 56px) 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 18px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid #f1d477;
  background: #fff5d1;
  color: #735200;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(10px, 2vw, 24px) 48px;
}

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

.module-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  width: 100%;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.module-item.active {
  border-color: var(--blue);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.module-index {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.module-item strong,
.module-item small {
  display: block;
}

.module-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tool-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hidden {
  display: none;
}

.panel-heading,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading {
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.ghost-button,
.copy-button,
.danger-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.copy-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.danger-button {
  border-color: #dc2626;
  background: #dc2626;
  color: #fff;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.2);
}

.ghost-button:hover,
.copy-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 24px;
}

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

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

.helper-input-grid {
  grid-template-columns: repeat(2, minmax(160px, 220px));
  justify-content: start;
}

.compact-helper-controls {
  gap: 12px;
  padding: 16px 24px;
}

.compact-helper-controls label {
  font-size: 13px;
}

.compact-helper-controls select {
  min-height: 40px;
  padding: 7px 10px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 95, 209, 0.15);
  outline: none;
}

.example-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0 24px 24px;
}

.example-strip div {
  min-height: 74px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--yellow);
  border-radius: 8px;
  background: #fffdf5;
  padding: 12px 14px;
}

.example-strip strong,
.example-strip span {
  display: block;
}

.example-strip strong {
  color: var(--ink);
  font-size: 14px;
}

.example-strip span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fbfcff;
}

.tax-summary-strip strong {
  color: var(--green);
}

.tax-summary-strip {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.foreign-summary-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.validation-status.check-fail {
  color: var(--danger);
  background: #ffe4e4;
  border: 1px solid #f5a3a3;
  border-radius: 8px;
  display: inline-block;
  padding: 4px 8px;
}

.validation-status.check-pass {
  color: var(--green);
}

.summary-strip div {
  padding: 18px 24px;
  border-right: 1px solid var(--line);
}

.summary-strip div:last-child {
  border-right: 0;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-strip strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.result-shell {
  padding: 24px;
}

.table-toolbar {
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.helper-table {
  min-width: 0;
  table-layout: fixed;
}

.helper-table th,
.helper-table td {
  padding: 8px 7px;
}

.helper-table th:nth-child(1),
.helper-table td:nth-child(1) {
  width: 8%;
}

.helper-table th:nth-child(2),
.helper-table th:nth-child(3),
.helper-table th:nth-child(4),
.helper-table td:nth-child(2),
.helper-table td:nth-child(3),
.helper-table td:nth-child(4) {
  width: 17%;
}

.helper-table th:nth-child(5),
.helper-table td:nth-child(5) {
  width: 17%;
}

.helper-table th:nth-child(6),
.helper-table td:nth-child(6) {
  width: 24%;
}

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

th {
  background: #f0f5fd;
  color: #334155;
  font-size: 13px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.number {
  text-align: right;
}

.amount {
  color: var(--green);
  font-weight: 800;
}

.table-input {
  font-size: 14px;
  min-height: 34px;
  border: 1px solid transparent;
  background: #f8fafc;
  padding: 6px 8px;
}

.table-input:focus {
  background: #fff;
}

.number-input {
  text-align: right;
}

.table-input:disabled {
  background: #eef2f7;
  color: #647083;
  cursor: not-allowed;
}

.check-pass {
  color: var(--green);
  font-weight: 800;
}

.check-fail {
  color: var(--danger);
  font-weight: 800;
}

.helper-sum-check,
.helper-tax-check {
  white-space: normal;
  line-height: 1.35;
}

.tax-alert-row td {
  background: #ffdede;
  border-bottom-color: #f3a0a0;
}

.tax-alert-row .amount {
  color: var(--danger);
}

.tax-alert-row input {
  background: #fff7f7;
  border-color: #ef8d8d;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.hint.error {
  color: var(--danger);
  font-weight: 700;
}

.export-preview {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px 14px;
}

.export-preview strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 14px;
}

.export-preview pre {
  min-height: 42px;
  max-height: 160px;
  margin: 0;
  overflow: auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

.rule-note {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #fbfcff;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.rule-note strong {
  display: block;
  color: var(--ink);
  margin-bottom: 6px;
}

.rule-note p {
  margin: 0;
}

.rule-note p + p {
  margin-top: 8px;
}

.rule-note a {
  color: var(--blue-dark);
  font-weight: 700;
}

@media (max-width: 840px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .module-list {
    flex-direction: row;
    overflow-x: auto;
  }

  .module-item {
    min-width: 245px;
  }

  .input-grid,
  .example-strip,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .summary-strip div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-strip div:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 520px) {
  .panel-heading,
  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .ghost-button,
  .copy-button,
  .danger-button {
    width: 100%;
  }
}
