:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #607080;
  --line: #d8e0e6;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn: #9a5b00;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  min-height: 38px;
  padding: 0 14px;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

button.secondary:hover:not(:disabled) {
  background: #d5e8e6;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 24px auto;
}

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

.topbar h1 {
  font-size: 28px;
  letter-spacing: 0;
  margin: 0;
}

.topbar p {
  color: var(--muted);
  margin: 4px 0 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

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

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

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

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

label,
.summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.16);
}

.discount-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.mapping-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.mapping-header h2 {
  font-size: 16px;
  margin: 0;
}

.tabbar {
  background: #eef4f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
}

.tab-button {
  background: transparent;
  color: var(--muted);
}

.tab-button:hover:not(:disabled) {
  background: #ddebed;
  color: var(--ink);
}

.tab-button.active {
  background: #ffffff;
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(31, 41, 51, 0.12);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: grid;
  gap: 12px;
}

.mapping-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 52vh;
  overflow: auto;
}

.settings-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 52vh;
  overflow: auto;
}

.empty-state,
.empty-cell {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.mapping-table,
.settings-table,
#outputTable {
  border-collapse: collapse;
  width: 100%;
}

.mapping-table th,
.mapping-table td,
.settings-table th,
.settings-table td,
#outputTable th,
#outputTable td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.mapping-table th,
.settings-table th,
#outputTable th {
  background: #eef4f5;
  color: #344654;
  font-size: 12px;
  font-weight: 800;
  position: sticky;
  top: 0;
  z-index: 1;
}

.mapping-table td:nth-child(2) {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mapping-table select {
  min-width: 128px;
}

.results-panel {
  min-width: 0;
  overflow: hidden;
}

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

.summary-strip > div {
  background: #fbfcfd;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
}

.summary-strip strong {
  font-size: 20px;
}

.table-scroll {
  height: calc(100vh - 190px);
  min-height: 420px;
  overflow: auto;
}

#outputTable td.number,
#outputTable th.number {
  text-align: right;
}

.message-ok {
  color: var(--accent-dark);
}

.message-warn {
  color: var(--warn);
}

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

@media (max-width: 980px) {
  .app-shell {
    width: min(100vw - 20px, 760px);
    margin: 10px auto;
  }

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

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

  .topbar-actions button {
    flex: 1;
  }

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

  .table-scroll {
    height: 58vh;
  }
}

@media (max-width: 560px) {
  .discount-grid,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 23px;
  }
}
