:root {
  --ink: #18201e;
  --ink-soft: #3a4642;
  --muted: #68756f;
  --canvas: #f5f7f4;
  --surface: #ffffff;
  --inset: #f0f3f1;
  --line: #dfe5e1;
  --brand: #176b5b;
  --brand-dark: #105648;
  --brand-soft: #dceee9;
  --success: #198754;
  --success-soft: #e1f4e9;
  --danger: #b42318;
  --danger-soft: #fee9e7;
  font-family: "Avenir Next", "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select { font: inherit; }
button, select, summary, input, a { outline: none; }
button:focus-visible, select:focus-visible, summary:focus-visible, input:focus-visible, a:focus-visible {
  box-shadow: 0 0 0 3px rgba(23, 107, 91, .2);
  border-color: var(--brand) !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 64px;
  padding: 10px max(24px, calc((100vw - 1160px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(245, 247, 244, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; padding: 7px; border-radius: 10px; background: var(--ink); display: grid; gap: 3px; }
.brand-mark i { display: block; height: 4px; border-radius: 3px; background: #fff; }
.brand-mark i:nth-child(2) { width: 70%; background: #70c7b1; }
.brand-mark i:nth-child(3) { width: 45%; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.mode-badge, .count-badge { padding: 6px 9px; color: var(--brand-dark); background: var(--brand-soft); border-radius: 999px; font-size: 10px; font-weight: 700; }

.token-settings { position: relative; }
.token-settings summary { list-style: none; cursor: pointer; padding: 7px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-size: 11px; }
.token-settings summary::-webkit-details-marker { display: none; }
.token-settings[open] { position: absolute; right: 0; top: 0; width: 250px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 36px rgba(24, 32, 30, .12); }
.token-settings[open] summary { margin-bottom: 10px; background: var(--inset); }
.token-settings label { display: block; margin-bottom: 5px; color: var(--ink-soft); font-size: 10px; font-weight: 650; }
.token-settings input { width: 100%; height: 38px; margin-bottom: 8px; padding: 0 10px; background: var(--inset); border: 1px solid var(--line); border-radius: 8px; font-size: 11px; }

.main-content { max-width: 1160px; margin: 0 auto; padding: 34px 24px 64px; }
.page-heading { margin-bottom: 18px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.page-heading h1 { margin: 0; font-size: clamp(26px, 3vw, 34px); line-height: 1.12; letter-spacing: -.035em; }
.page-heading p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.history-link { min-height: 40px; display: inline-flex; align-items: center; color: var(--brand-dark); font-size: 11px; font-weight: 700; text-decoration: none; }

.panel { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.panel-heading { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-heading h2 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 9px; }
.compact-heading { margin-bottom: 14px; }
.connection-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.connection-state strong { color: var(--ink-soft); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px #e6eae8; }
.status-dot.ready, .status-dot.succeeded { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-dot.running { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.status-dot.failed { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr 1.25fr 170px; gap: 12px; align-items: start; }
.field, .action-field { display: grid; gap: 7px; }
.field > span, .action-field > span { color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.field select { width: 100%; height: 42px; padding: 0 34px 0 11px; color: var(--ink); background: var(--inset); border: 1px solid var(--line); border-radius: 8px; font-size: 11px; }
.field select:disabled { color: var(--muted); cursor: wait; }
.field small { color: var(--muted); font-size: 8px; }
.button { min-height: 38px; border: 0; border-radius: 8px; cursor: pointer; font-weight: 750; transition: transform 120ms, background-color 160ms, opacity 160ms; }
.button:active { transform: scale(.98); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.primary { height: 42px; padding: 0 13px; display: flex; align-items: center; justify-content: space-between; color: #fff; background: var(--brand); }
.button.primary:hover:not(:disabled) { background: var(--brand-dark); }
.button.secondary { padding: 0 12px; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line); }
.button.compact { min-height: 34px; font-size: 10px; }
.selection-summary { margin-top: 15px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--ink-soft); background: var(--inset); border-radius: 9px; font-size: 10px; }
.selection-summary strong, .selection-summary small { display: block; }
.selection-summary small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.selection-summary > span:last-child { color: var(--brand-dark); font-weight: 700; text-align: right; }

.advanced-options { margin-top: 10px; border-top: 1px solid var(--line); }
.advanced-options summary { min-height: 42px; display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.advanced-options summary small { color: var(--muted); font-size: 8px; font-weight: 500; }
.advanced-options summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 16px; font-weight: 400; }
.advanced-options[open] summary::after { content: "−"; }
.advanced-content { padding: 2px 0 8px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.mode-fieldset { min-width: 430px; margin: 0; padding: 0; display: flex; gap: 8px; border: 0; }
.mode-fieldset legend { margin-bottom: 7px; padding: 0; color: var(--muted); font-size: 9px; }
.mode-option { min-width: 200px; padding: 10px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.mode-option:has(input:checked) { border-color: var(--brand); background: #f2f8f6; }
.mode-option:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.mode-option input { accent-color: var(--brand); }
.mode-option strong, .mode-option small { display: block; }
.mode-option strong { font-size: 10px; }
.mode-option small { margin-top: 2px; color: var(--muted); font-size: 8px; }
.toggle { min-height: 40px; display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 9px; font-weight: 650; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle > span { width: 34px; height: 20px; padding: 3px; background: #bdc7c2; border-radius: 999px; transition: background-color 160ms; }
.toggle > span::after { content: ""; display: block; width: 14px; height: 14px; background: #fff; border-radius: 50%; transition: transform 160ms; }
.toggle input:checked + span { background: var(--brand); }
.toggle input:checked + span::after { transform: translateX(14px); }
.toggle input:focus-visible + span { box-shadow: 0 0 0 3px rgba(23, 107, 91, .2); }
.toggle:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.form-error { min-height: 14px; padding-top: 4px; color: var(--danger); font-size: 9px; }

.progress-panel { margin-top: 16px; }
.job-state { display: flex; align-items: center; gap: 8px; font-size: 9px; }
progress { appearance: none; width: 100%; height: 4px; border: 0; overflow: hidden; border-radius: 999px; background: var(--inset); }
progress::-webkit-progress-bar { background: var(--inset); }
progress::-webkit-progress-value { background: var(--brand); transition: width 180ms; }
progress::-moz-progress-bar { background: var(--brand); }
.stage-rail { margin: 0; padding: 15px 0 0; display: grid; grid-template-columns: repeat(8, minmax(82px, 1fr)); gap: 7px; overflow-x: auto; list-style: none; }
.stage-card { min-height: 70px; padding: 10px; background: var(--inset); border: 1px solid transparent; border-radius: 9px; }
.stage-card .stage-index { display: block; color: var(--muted); font-size: 7px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stage-card strong { display: block; margin-top: 9px; font-size: 9px; }
.stage-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 7px; }
.stage-card.running { background: #f1f8f6; border-color: var(--brand); }
.stage-card.succeeded { background: var(--success-soft); }
.stage-card.failed { background: var(--danger-soft); border-color: #f5b9b3; }

.lower-grid { margin-top: 16px; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .75fr); gap: 16px; }
.text-button { min-height: 34px; padding: 0 4px; color: var(--brand-dark); background: transparent; border: 0; cursor: pointer; font-size: 9px; }
.terminal { min-height: 230px; max-height: 360px; overflow: auto; padding: 14px; color: #dce5e1; background: var(--ink); border-radius: 10px; font: 10px/1.6 "SFMono-Regular", Consolas, monospace; }
.terminal p { margin: 0 0 3px; overflow-wrap: anywhere; }
.terminal time { margin-right: 9px; color: #7d8d87; }
.terminal .log-success { color: #7fd6a5; }
.terminal .log-error { color: #ff9a90; }
.terminal-empty { color: #7d8d87; }
.history-list { display: grid; }
.history-row { padding: 11px 0; display: grid; gap: 5px; border-top: 1px solid #e9eeeb; font-size: 9px; }
.history-row:first-child { border-top: 0; }
.history-main strong, .history-main small { display: block; }
.history-main small { margin-top: 3px; color: var(--muted); }
.history-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.history-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.empty-state { margin: 0; padding: 34px 16px; color: var(--muted); background: var(--inset); border-radius: 9px; text-align: center; font-size: 9px; }

@media (max-width: 920px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .lower-grid { grid-template-columns: 1fr; }
  .advanced-content { align-items: start; flex-direction: column; }
}

@media (max-width: 620px) {
  .app-header { min-height: 58px; padding: 9px 16px; }
  .brand small, .mode-badge { display: none; }
  .main-content { padding: 26px 16px 48px; }
  .page-heading { align-items: start; }
  .page-heading h1 { font-size: 27px; }
  .history-link { display: none; }
  .panel { padding: 17px; }
  .field-grid { grid-template-columns: 1fr; }
  .selection-summary { align-items: start; flex-direction: column; }
  .selection-summary > span:last-child { text-align: left; }
  .advanced-content { gap: 12px; }
  .mode-fieldset { min-width: 0; width: 100%; display: grid; grid-template-columns: 1fr; }
  .mode-option { min-width: 0; }
  .stage-rail { grid-template-columns: repeat(8, 112px); }
  .token-settings[open] { right: 0; width: 240px; }
}

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