:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafb;
  --line: #d8dee5;
  --line-strong: #b7c0ca;
  --text: #17202a;
  --muted: #64717d;
  --accent: #166534;
  --accent-hover: #14532d;
  --accent-soft: #e8f5ec;
  --warn: #9a6700;
  --warn-soft: #fff7d6;
  --danger: #b42318;
  --danger-hover: #912018;
  --danger-soft: #fef0ed;
  --log: #161b22;
  --log-text: #d8dee6;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 700;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.status-chip {
  min-width: 92px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b98a5;
}

.status-chip[data-status="running"] .status-dot,
.status-chip[data-status="queued"] .status-dot,
.status-chip[data-status="stopping"] .status-dot {
  background: var(--warn);
}

.status-chip[data-status="success"] .status-dot {
  background: var(--accent);
}

.status-chip[data-status="failed"] .status-dot,
.status-chip[data-status="cancelled"] .status-dot {
  background: var(--danger);
}

.token-section,
.mode-section,
.stage,
.output-section,
.result-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.token-section {
  padding: 18px;
  margin-bottom: 14px;
}

.mode-section {
  padding: 14px 18px;
  margin-bottom: 14px;
}

.mode-heading {
  margin-bottom: 0;
}

.mode-switch {
  height: 36px;
  display: grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-subtle);
}

.mode-switch label {
  min-width: 0;
  position: relative;
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-switch span {
  height: 28px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.mode-switch input:checked + span {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.12);
}

.mode-switch input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.pix-tax-row {
  display: grid;
  grid-template-columns: minmax(0, 320px) auto;
  align-items: end;
  justify-content: end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.pix-tax-toggle {
  height: 40px;
}

.section-heading,
.output-header,
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading > div,
.output-header > div,
.result-header {
  display: flex;
  align-items: center;
  gap: 9px;
}

h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
  font-weight: 700;
}

.step-mark {
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: #e8edf2;
  color: #43505d;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.success-mark {
  background: var(--accent-soft);
  color: var(--accent);
}

.privacy-note,
.proxy-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stage {
  min-width: 0;
  padding: 18px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: 10px;
}

.field,
.compact-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #485563;
  font-size: 12px;
  font-weight: 600;
}

.field small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 174px;
  padding: 10px 11px;
  resize: vertical;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

input:disabled,
select:disabled,
textarea:disabled {
  color: #7d8994;
  background: #f0f3f5;
}

.country-meta {
  min-height: 29px;
  margin: 10px 0 8px;
  padding: 7px 9px;
  border-left: 3px solid #9aa6b2;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.proxy-field {
  margin-top: 0;
}

.runbar {
  display: grid;
  grid-template-columns: 170px 220px minmax(220px, 1fr);
  align-items: end;
  gap: 12px;
  padding: 16px 0 18px;
  border-bottom: 1px solid var(--line);
}

.run-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.primary-button,
.danger-button,
.quiet-button {
  height: 40px;
  border-radius: 5px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button {
  min-width: 116px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.danger-button {
  min-width: 88px;
  border: 1px solid #d9a29c;
  background: var(--surface);
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  border-color: var(--danger-hover);
  background: var(--danger-soft);
}

.quiet-button {
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: #4f5d69;
  font-weight: 600;
}

.quiet-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.token-toggle {
  height: 40px;
}

button:disabled {
  opacity: 0.48;
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid #efb7b0;
  border-radius: 5px;
  color: var(--danger);
  background: var(--danger-soft);
  line-height: 1.45;
}

.output-section,
.result-section {
  margin-top: 18px;
  overflow: hidden;
}

.output-header,
.result-header {
  min-height: 52px;
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.log-view {
  height: 318px;
  overflow: auto;
  padding: 10px 0;
  background: var(--log);
  color: var(--log-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  scrollbar-color: #4a535d var(--log);
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  color: #818b96;
}

.log-line {
  display: grid;
  grid-template-columns: 72px 86px minmax(0, 1fr);
  gap: 8px;
  padding: 3px 14px;
}

.log-line:hover {
  background: rgba(255, 255, 255, 0.04);
}

.log-time,
.log-stage {
  color: #8b949e;
}

.log-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.log-line[data-level="success"] .log-message {
  color: #7ee787;
}

.log-line[data-level="warn"] .log-message {
  color: #e3b341;
}

.log-line[data-level="error"] .log-message {
  color: #ff7b72;
}

.result-section {
  border-color: #b7d7bf;
}

.result-list {
  margin: 0;
}

.result-list > div {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  padding: 12px 14px;
  border-top: 1px solid #edf0f2;
}

.result-list > div:first-child {
  border-top: 0;
}

.result-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.result-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.result-list a {
  color: #0b57a4;
  text-underline-offset: 2px;
}

.result-list code {
  white-space: normal;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 620px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    margin-bottom: 14px;
  }

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

  .stage-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .run-actions {
    grid-column: 1 / -1;
  }

  .primary-button,
  .danger-button {
    flex: 1;
  }

  .log-line {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .log-stage {
    display: none;
  }

  .result-list > div {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }
}

@media (max-width: 440px) {
  .topbar p {
    display: none;
  }

  .status-chip {
    min-width: auto;
  }

  .token-section,
  .mode-section,
  .stage {
    padding: 14px;
  }

  .field-grid,
  .runbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .mode-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-switch,
  .pix-tax-row {
    width: 100%;
  }

  .run-actions {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
