:root {
  --bg: #f7f8fa;
  --bg-2: #eef1f4;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --border-strong: #d4d8dd;
  --card: #ffffff;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-soft: rgba(13, 148, 136, 0.10);
  --accent-ring: rgba(13, 148, 136, 0.18);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.07);
  --good: #166534;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--fg);
  line-height: 1.5;
  letter-spacing: -0.005em;
}

/* lock gate */
body.locked > header,
body.locked > main,
body.locked > footer { display: none; }
body:not(.locked) #lockScreen { display: none; }
.lock-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadein 0.25s ease-out;
}
.lock-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.lock-icon { font-size: 36px; line-height: 1; margin-bottom: 4px; }
.lock-card input {
  font: inherit;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  text-align: center;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lock-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.lock-card button {
  font: inherit;
  font-weight: 500;
  padding: 11px;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.lock-card button:hover { background: var(--accent-strong); }
.lock-card button:active { transform: translateY(1px); }
.lock-error { color: var(--warn); font-size: 13px; margin: 0; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

header {
  padding: 36px 24px 8px;
  max-width: 1100px;
  margin: 0 auto;
}
header h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
header .sub { margin: 0; color: var(--muted); font-size: 15px; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px 56px;
  display: grid;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card h3 {
  margin: 18px 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: end;
}
.row.right { justify-content: flex-end; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
label > input[type="checkbox"] { margin-right: 6px; }
label:has(> input[type="checkbox"]) { flex-direction: row; align-items: center; color: var(--fg); font-weight: 400; }

input[type="number"], input[type="text"], select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: white;
  min-width: 160px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="number"]:hover, input[type="text"]:hover, select:hover { border-color: #b8bdc4; }
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  transition: background 0.12s, transform 0.05s;
}
button:hover { background: var(--accent-strong); }
button:active { transform: translateY(1px); }
button.ghost {
  background: transparent;
  color: var(--accent-strong);
  border-color: var(--border-strong);
}
button.ghost:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
button.link {
  background: none;
  border: none;
  color: var(--accent-strong);
  padding: 0;
  text-decoration: underline;
}
button.link:hover { background: none; color: var(--accent); }
button.icon {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 2px 6px;
  font-size: 16px;
  border-radius: 4px;
}
button.icon:hover { color: var(--warn); background: var(--warn-soft); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tbody tr:last-child td { border-bottom: none; }
td input { width: 100px; min-width: 0; }
td select { min-width: 200px; }

.tiers td:last-child, .mapping td:last-child { width: 40px; }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  padding: 36px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  background: rgba(255,255,255,0.5);
}
.dropzone:hover { border-color: var(--accent); color: var(--fg); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }

.upload-status {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--warn-soft);
  border: 1px solid rgba(180, 83, 9, 0.25);
  border-radius: 10px;
  color: var(--warn);
  font-size: 13px;
}
.upload-status ul { margin: 6px 0 0; padding-left: 20px; }
.upload-status li { margin-bottom: 2px; }
.upload-status code { background: rgba(255,255,255,0.7); border-color: rgba(180, 83, 9, 0.2); }
.upload-status .meta { color: rgba(180, 83, 9, 0.75); }

.filelist {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.filelist li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  transition: border-color 0.15s;
}
.filelist li:hover { border-color: var(--border-strong); }
.filelist li .meta { color: var(--muted); }
.filelist li select, .filelist li input { min-width: 0; padding: 5px 8px; font-size: 12px; }
.filelist .filemeta { flex: 1 1 220px; }
.filelist .filecontrols { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
label.inline { font-size: 10px; gap: 3px; letter-spacing: 0.04em; text-transform: uppercase; }
label.inline input { width: 80px; }
label.inline select { width: 110px; }
.calc-summary { margin: 4px 0 10px; font-size: 13px; }
.calc-summary strong { color: var(--fg); }

.totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.totals > div {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: 10px;
}
.totals .lbl {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 4px;
}
.totals strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.totals .big {
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.10) 0%, rgba(13, 148, 136, 0.05) 100%);
  border-color: rgba(13, 148, 136, 0.25);
}
.totals .big strong { color: var(--good); font-size: 28px; font-weight: 700; }

.breakdown-merchant { margin-top: 22px; }
.breakdown-merchant h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.breakdown-merchant .platform-tag {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}
.breakdown-merchant table { margin-top: 6px; }
.breakdown-merchant td.num, .breakdown-merchant th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-total td { font-weight: 600; background: var(--bg); }
.row-na td { color: var(--muted); }
.row-warn td { background: var(--warn-soft); }
.warn { color: var(--warn); margin: 6px 0; font-size: 13px; font-weight: 500; }
.methods input[type="text"] { width: 100%; min-width: 0; }
.methods input[type="number"] { width: 90px; }
.methods td:first-child { width: 35%; }
.txassign code { font-size: 12px; }
.txassign select { min-width: 220px; }
.tx-tag { display: block; font-size: 11px; margin-top: 2px; color: var(--muted); }
.warn-inline { color: var(--warn); }

footer {
  text-align: center;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 12px;
}

code { font-size: 0.9em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* explainer ("How is this calculated?") */
.explainer { padding: 0; }
.explainer summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  user-select: none;
}
.explainer summary::-webkit-details-marker { display: none; }
.explainer summary h2 { margin: 0; font-size: 16px; }
.explainer .chevron {
  color: var(--muted);
  font-size: 14px;
  transition: transform 0.2s;
}
.explainer[open] .chevron { transform: rotate(180deg); }
.explainer[open] summary { border-bottom: 1px solid var(--border); }
.explainer > *:not(summary) { padding-left: 24px; padding-right: 24px; }
.explainer > *:last-child { padding-bottom: 20px; }
.explainer-intro { margin: 16px 0 12px; color: var(--fg); font-size: 14px; }
.explainer-intro strong { font-weight: 600; }

.calc-steps {
  list-style: none;
  counter-reset: step;
  padding-left: 24px;
  padding-right: 24px;
  margin: 8px 0 18px;
  position: relative;
}
.calc-steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 22px 56px;
  min-height: 48px;
}
.calc-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  z-index: 1;
}
.calc-steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 36px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}
.calc-steps li h4 {
  margin: 6px 0 4px;
  font-size: 14px;
  font-weight: 600;
}
.calc-steps li p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.example {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.example strong { color: var(--accent); font-weight: 600; }
.example-final {
  background: rgba(15, 118, 110, 0.07);
  border-color: rgba(15, 118, 110, 0.25);
}
.example-final strong { color: var(--good); font-size: 14px; }

.tier-ref {
  width: auto;
  margin: 4px 0 16px;
  font-size: 13px;
}
.tier-ref th, .tier-ref td { padding: 6px 14px 6px 0; }
.tier-ref td:first-child { color: var(--muted); }
.explainer-foot {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
}
.explainer-foot strong { color: var(--fg); }
code {
  font-size: 0.88em;
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
}
