:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --surface-soft: #f8faf5;
  --line: #dfe5d7;
  --text: #17211b;
  --text-soft: #607064;
  --muted: #839184;
  --green: #127b5f;
  --green-soft: #e3f3ec;
  --blue: #2867b2;
  --blue-soft: #e6eef8;
  --amber: #a86800;
  --amber-soft: #fff1d6;
  --red: #b63e35;
  --red-soft: #fae4e1;
  --ink: #101615;
  --shadow: 0 18px 44px rgba(28, 39, 31, 0.1);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #111714;
  --surface: #18211d;
  --surface-soft: #202a25;
  --line: #304038;
  --text: #edf3ed;
  --text-soft: #b5c1b7;
  --muted: #89978b;
  --green: #58c797;
  --green-soft: #183d31;
  --blue: #76a9e6;
  --blue-soft: #1b324e;
  --amber: #e0a846;
  --amber-soft: #443117;
  --red: #eb7b71;
  --red-soft: #4a2422;
  --ink: #eef5ef;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(23, 33, 27, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 33, 27, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 26px 26px;
  font-family: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  margin-bottom: 18px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, #127b5f, #2867b2 62%, #a86800);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand span:not(.brand-mark) {
  display: block;
  margin-top: 4px;
  color: var(--text-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.health-chip,
.icon-button,
.tool-entry-button,
.ghost-button,
.solid-button,
.primary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}

.health-chip {
  padding: 0 11px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.health-chip.ok {
  color: var(--green);
  background: var(--green-soft);
  border-color: color-mix(in srgb, var(--green) 35%, var(--line));
}

.health-chip.bad {
  color: var(--red);
  background: var(--red-soft);
  border-color: color-mix(in srgb, var(--red) 35%, var(--line));
}

.health-chip.pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.tool-entry-button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--green);
  background: var(--green-soft);
  border-color: color-mix(in srgb, var(--green) 34%, var(--line));
  font-weight: 800;
  white-space: nowrap;
}

.icon-button.small {
  width: 40px;
  min-height: 40px;
}

.ghost-button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--text-soft);
  background: transparent;
}

.solid-button,
.primary-button,
.danger-button {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
}

.solid-button {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: color-mix(in srgb, var(--blue) 36%, var(--line));
}

.primary-button {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.danger-button {
  color: var(--red);
  background: var(--red-soft);
  border-color: color-mix(in srgb, var(--red) 38%, var(--line));
}

.icon-button:hover,
.tool-entry-button:hover,
.ghost-button:hover,
.solid-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 880px);
  gap: 18px;
  align-items: start;
  justify-content: center;
  max-width: 980px;
  margin: 0 auto;
}

.center-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel,
.hero-strip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 12px;
}

.panel-head span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
}

.panel-head em {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-style: normal;
  white-space: nowrap;
}

.panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.tools-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(16, 22, 21, 0.28);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 160ms ease;
}

.tools-drawer {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 31;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(430px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 22px 70px rgba(16, 22, 21, 0.2);
  opacity: 0;
  transform: translateX(18px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.tools-overlay[hidden],
.tools-drawer[hidden] {
  display: none;
}

body.tools-open {
  overflow: hidden;
}

body.tools-open .tools-overlay,
body.tools-open .tools-drawer {
  opacity: 1;
}

body.tools-open .tools-drawer {
  transform: translateX(0);
}

.tools-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.tools-drawer-head h2 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.1;
}

.tools-drawer-body {
  display: grid;
  gap: 14px;
  min-height: 0;
  padding: 16px;
  overflow: auto;
}

.tools-drawer .panel {
  box-shadow: none;
}

.tool-meter {
  width: 100%;
  grid-template-columns: repeat(12, 1fr);
  margin-bottom: 12px;
}

.stock-grid {
  display: grid;
  gap: 10px;
}

.stock-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.stock-card.selected {
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
}

.stock-name {
  min-width: 0;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-tier {
  justify-self: end;
  align-self: start;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 800;
}

.stock-tier.empty,
.stock-tier.bad {
  color: var(--red);
  background: var(--red-soft);
}

.stock-tier.low {
  color: var(--amber);
  background: var(--amber-soft);
}

.stock-meta {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.hero-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 116px;
  padding: 18px;
  overflow: hidden;
}

.eyebrow {
  color: var(--blue);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

.hero-strip h2 {
  margin: 6px 0 0;
  font-size: 32px;
  line-height: 1.1;
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(12, 12px);
  grid-auto-rows: 28px;
  gap: 5px;
  flex: 0 0 auto;
}

.meter-cell {
  border-radius: 4px;
  background: var(--line);
}

.meter-cell.ready {
  background: var(--green);
}

.meter-cell.low {
  background: var(--amber);
}

.meter-cell.empty {
  background: var(--red);
}

.step-flow-panel {
  display: grid;
  gap: 14px;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stepper-item {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-soft);
  background: var(--surface-soft);
  text-align: left;
}

.stepper-item b {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
}

.stepper-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.stepper-item.active {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 42%, var(--line));
  background: var(--green-soft);
}

.stepper-item.active b,
.stepper-item.done b {
  color: #ffffff;
  background: var(--green);
}

.stepper-item.done {
  color: var(--text);
}

.stepper-item.locked {
  color: var(--muted);
  opacity: 0.72;
}

.step-card {
  display: none;
  gap: 16px;
  min-height: 352px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.step-card.active {
  display: grid;
}

.step-card.locked {
  opacity: 0.82;
}

.step-card-head {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: start;
}

.step-index {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid color-mix(in srgb, var(--green) 30%, var(--line));
  font-family: "IBM Plex Mono", monospace;
  font-weight: 800;
}

.step-card-head h3 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.2;
}

.step-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.step-title-row h3 {
  min-width: 0;
  margin: 0;
}

.session-link-button {
  min-height: 34px;
  padding: 0 11px;
  color: var(--blue);
  background: var(--blue-soft);
  border-color: color-mix(in srgb, var(--blue) 36%, var(--line));
  font-weight: 700;
  white-space: nowrap;
}

.session-copy-hint,
.session-warning-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.session-copy-hint {
  border: 1px solid color-mix(in srgb, var(--blue) 30%, var(--line));
  color: var(--blue);
  background: var(--blue-soft);
}

.session-warning-hint {
  border: 1px solid color-mix(in srgb, var(--amber) 42%, var(--line));
  color: var(--amber);
  background: var(--amber-soft);
}

.session-copy-hint svg,
.session-warning-hint svg {
  margin-top: 1px;
}

.step-card-head p {
  margin: 0;
  color: var(--text-soft);
}

.redeem-form {
  display: grid;
  gap: 16px;
}

.field-block {
  display: grid;
  gap: 8px;
}

.field-block label,
.label-row label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
}

.input-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.action-line {
  grid-template-columns: minmax(0, 1fr) minmax(136px, 168px);
}

.inline-action {
  width: auto;
  white-space: nowrap;
}

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

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 16%, transparent);
}

input {
  min-height: 40px;
  padding: 0 12px;
  font-family: "IBM Plex Mono", monospace;
}

textarea {
  min-height: 220px;
  max-height: 360px;
  padding: 12px;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  line-height: 1.45;
}

.compact-textarea {
  min-height: 112px;
  max-height: 220px;
  margin-bottom: 10px;
}

.compact-textarea.tall {
  min-height: 150px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mini-actions {
  display: flex;
  gap: 8px;
}

.form-footer {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 220px);
  gap: 12px;
  align-items: center;
}

.selected-plan {
  display: grid;
  gap: 2px;
  min-height: 50px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.selected-plan span {
  color: var(--muted);
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
  overflow-wrap: anywhere;
}

.selected-plan b {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.selected-plan b svg {
  width: 19px;
  height: 19px;
}

.selected-plan.ok {
  border-style: solid;
  border-color: color-mix(in srgb, var(--green) 48%, var(--line));
  background: var(--green-soft);
  box-shadow: inset 5px 0 0 var(--green);
}

.selected-plan.ok b {
  color: var(--green);
}

.selected-plan.bad {
  border: 2px solid color-mix(in srgb, var(--red) 74%, var(--line));
  background: var(--red-soft);
  box-shadow: inset 7px 0 0 var(--red), 0 0 0 3px color-mix(in srgb, var(--red) 12%, transparent);
}

.selected-plan.bad span,
.selected-plan.bad b {
  color: var(--red);
}

.selected-plan.bad b {
  font-weight: 900;
  overflow-wrap: anywhere;
  white-space: normal;
}

.task-lookup-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(132px, 160px);
  gap: 10px;
  align-items: end;
}

.task-query-button {
  width: auto;
}

.task-history-panel {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 58%, var(--surface-soft));
}

.task-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.task-history-head span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
}

.task-history-list {
  display: grid;
  gap: 7px;
}

.task-history-empty {
  min-height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.task-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-soft);
  text-align: left;
}

.task-history-main,
.task-history-side {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.task-history-main b,
.task-history-main em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-history-main b {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.task-history-main em,
.task-history-side time {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-style: normal;
}

.task-history-side {
  justify-items: end;
}

.task-history-side strong {
  font-size: 12px;
}

.task-history-side strong.success {
  color: var(--green);
}

.task-history-side strong.error {
  color: var(--red);
}

.task-history-side strong.pending {
  color: var(--amber);
}

.task-panel {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.task-body {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 88px;
}

.task-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-soft);
}

.task-icon.success {
  color: var(--green);
  background: var(--green-soft);
}

.task-icon.error {
  color: var(--red);
  background: var(--red-soft);
}

.task-icon.pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.task-body h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.task-body p {
  margin: 0;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}

.task-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.task-meta span,
.query-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--text-soft);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.confirm-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin: 2px 0 10px;
  color: var(--text-soft);
  font-weight: 700;
}

.confirm-line input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--red);
}

.result-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 310px;
  overflow: auto;
}

.result-item {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.result-item.ok {
  border-color: color-mix(in srgb, var(--green) 36%, var(--line));
}

.result-item.bad {
  border-color: color-mix(in srgb, var(--red) 36%, var(--line));
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.result-title em {
  color: var(--muted);
  font-style: normal;
  white-space: nowrap;
}

.result-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.copy-code {
  justify-self: start;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-soft);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-soft);
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 270px;
  overflow: auto;
}

.log-line {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 12px;
}

.log-line time {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  max-width: min(560px, calc(100vw - 32px));
  transform: translate(-50%, 16px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.ok {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 36%, var(--line));
}

.toast.bad {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 36%, var(--line));
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(0, 880px);
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

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

  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .tools-drawer {
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }

  .workspace {
    display: grid;
  }

  .hero-strip,
  .form-footer,
  .action-line,
  .task-lookup-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .inline-action,
  .task-query-button {
    width: 100%;
  }

  .step-title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-link-button {
    width: 100%;
  }

  .meter-row {
    grid-template-columns: repeat(12, 1fr);
    width: 100%;
  }
}
