:root {
  --page: #f2f5f3;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --ink: #171b19;
  --muted: #68736d;
  --line: #d9e0dc;
  --line-strong: #bfc9c3;
  --green: #16724a;
  --green-dark: #0d5435;
  --green-soft: #e8f4ee;
  --blue: #315f91;
  --blue-soft: #e9f0f8;
  --amber: #9a5a09;
  --amber-soft: #fbf1df;
  --red: #a43a32;
  --red-soft: #faeae8;
  --shadow: 0 10px 28px rgba(25, 39, 31, 0.07);
}

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

html { min-width: 320px; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  color: #f7faf8;
  background: #171b19;
  border-bottom: 1px solid #2c332f;
}

.topbar-inner {
  width: min(1180px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  align-items: center;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; width: fit-content; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: #f1f5f2; color: #171b19; border-radius: 6px; font-weight: 800; font-size: 12px; }
.brand-name { font-size: 16px; font-weight: 750; }

.primary-tabs { height: 100%; display: flex; justify-content: center; gap: 4px; }
.tab-button { position: relative; min-width: 76px; border: 0; color: #aeb8b2; background: transparent; font-weight: 650; }
.tab-button:hover, .tab-button.is-active { color: #ffffff; }
.tab-button.is-active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 3px; background: #50b985; }

.environment { justify-self: end; display: inline-flex; align-items: center; gap: 8px; color: #b9c3bd; font-size: 12px; }
.admin-link { color: #b9c3bd; text-decoration: none; }
.admin-link:hover { color: #ffffff; }
.environment i { width: 8px; height: 8px; border-radius: 50%; background: #c28731; box-shadow: 0 0 0 4px rgba(194, 135, 49, 0.15); }
.environment i.is-online { background: #50b985; box-shadow: 0 0 0 4px rgba(80, 185, 133, 0.16); }
.environment.is-online i { background: #50b985; box-shadow: 0 0 0 4px rgba(80, 185, 133, 0.16); }
.environment.is-offline i { background: #d86459; box-shadow: 0 0 0 4px rgba(216, 100, 89, 0.15); }

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 64px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 26px; }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 30px; line-height: 1.2; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 0; font-size: 16px; }
.heading-meta { display: flex; gap: 8px; }
.heading-meta span { padding: 7px 10px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; font-size: 11px; }
.heading-meta b { margin-left: 4px; color: var(--ink); }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.metric { min-height: 82px; padding: 17px 20px; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 24px; line-height: 1; }

.view-section { display: none; }
.view-section.is-active { display: block; }
.workspace-grid { min-width: 0; display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr); gap: 18px; align-items: start; }
.tool-panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.order-form, .live-panel { min-height: 590px; padding: 24px; }
.panel-heading { min-height: 34px; margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-index { display: grid; place-items: center; width: 30px; height: 30px; color: var(--green); background: var(--green-soft); border-radius: 5px; font-size: 11px; font-weight: 800; }
.mode-badge, .status-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.mode-badge { color: var(--blue); background: var(--blue-soft); }
.mode-badge-short { display: none; }

.field-group { min-width: 0; margin: 0 0 19px; padding: 0; border: 0; display: block; }
.field-group > label, .field-group > span, .field-group legend, .label-row label { color: #303733; font-size: 12px; font-weight: 750; }
.label-row { margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.label-row > span { min-width: 0; max-width: 62%; overflow: hidden; color: var(--muted); font-size: 11px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.field-state.is-valid { color: var(--green); }
.field-state.is-invalid { color: var(--red); }

input, textarea, select { width: 100%; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 5px; outline: none; transition: border-color 130ms ease, box-shadow 130ms ease; }
input, select { height: 42px; padding: 0 12px; }
textarea { min-height: 128px; padding: 11px 12px; resize: vertical; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 114, 74, 0.11); }
.input-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 7px; }
.input-actions input { min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.quiet-button, .text-button, .secondary-button, .primary-button { border-radius: 5px; font-weight: 700; }
.quiet-button { min-width: 58px; height: 42px; padding: 0 10px; color: #3c4640; background: var(--surface-soft); border: 1px solid var(--line); }
.quiet-button:hover { color: var(--green-dark); border-color: #9bb5a7; }

.segmented-control { margin-top: 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.segment { min-height: 58px; padding: 9px 8px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 5px; }
.segment b { color: var(--ink); font-size: 13px; }
.segment span { margin-top: 3px; font-size: 11px; }
.segment:hover { border-color: #9fb1a7; }
.segment.is-selected { color: var(--green); background: var(--green-soft); border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.segment.is-selected b { color: var(--green-dark); }

.field-actions { margin-top: 7px; display: flex; justify-content: flex-end; gap: 14px; }
.text-button { padding: 3px 0; color: var(--green); background: transparent; border: 0; font-size: 12px; }
.text-button:hover { color: var(--green-dark); }
.session-summary { margin-top: 9px; padding: 10px 11px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; color: var(--muted); background: var(--surface-soft); border-left: 3px solid var(--green); font-size: 11px; }
.session-summary b { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.billing-section { padding-top: 1px; }
.billing-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.billing-field { min-width: 0; color: var(--muted); font-size: 10px; }
.billing-field input, .billing-field select { margin-top: 5px; height: 38px; padding: 0 10px; font-size: 12px; }
.billing-wide { grid-column: span 3; }
.field-row { display: grid; grid-template-columns: minmax(140px, 0.72fr) minmax(0, 1.28fr); gap: 12px; }
.field-row .field-group > span { display: block; margin-bottom: 8px; }
.stripe-card-shell { min-width: 0; }
.stripe-card-shell > .label-row { margin-bottom: 8px; }
.card-input-panel[hidden] { display: none; }
.card-fields-grid { display: grid; grid-template-columns: minmax(0, 1fr) 92px 78px; gap: 7px; }
.card-field { min-width: 0; display: block; }
.card-field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; }
.card-field-box, .card-field input { width: 100%; height: 42px; padding: 11px 10px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 5px; }
.card-field input { margin: 0; color: var(--ink); font-size: 13px; }
.renewal-policy { margin: -4px 0 18px; padding: 11px 12px; display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: start; color: var(--green-dark); background: var(--green-soft); border-left: 3px solid var(--green); font-size: 11px; line-height: 1.45; }
.renewal-policy b { white-space: nowrap; }
.renewal-policy span { color: #3f5b4c; }
.checkout-diagnostics { margin: -2px 0 18px; padding: 11px 0 2px; border-top: 1px solid var(--line); }
.diagnostic-list { margin-top: 9px; display: grid; gap: 7px; }
.diagnostic-row { min-height: 30px; display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; align-items: center; gap: 9px; font-size: 11px; }
.diagnostic-row i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.diagnostic-row span { overflow: hidden; color: #3d4742; text-overflow: ellipsis; white-space: nowrap; }
.diagnostic-row b { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; }

.primary-button { width: 100%; height: 48px; padding: 0 16px; display: flex; justify-content: space-between; align-items: center; color: #fff; background: var(--green); border: 1px solid var(--green); }
.primary-button:hover { background: var(--green-dark); border-color: var(--green-dark); }
.primary-button b { padding-left: 16px; border-left: 1px solid rgba(255,255,255,0.28); }
.secondary-button { min-height: 40px; padding: 0 15px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); }
.secondary-button:hover { color: var(--green-dark); border-color: var(--green); }
.secondary-button.compact { min-height: 36px; }

.status-idle { color: var(--muted); background: #edf0ee; }
.status-queued, .status-running { color: var(--amber); background: var(--amber-soft); }
.status-awaiting_payment { color: var(--amber); background: var(--amber-soft); }
.status-succeeded { color: var(--green); background: var(--green-soft); }
.status-failed { color: var(--red); background: var(--red-soft); }
.live-empty { min-height: 490px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-glyph { width: 58px; height: 58px; margin-bottom: 17px; display: grid; place-items: center; color: var(--green-dark); background: var(--green-soft); border: 1px solid #b9d7c8; border-radius: 7px; font-weight: 850; }
.live-empty p { margin: 7px 0 0; font-size: 12px; }
.order-identity { padding-bottom: 18px; display: flex; justify-content: space-between; align-items: end; border-bottom: 1px solid var(--line); }
.order-identity span, .order-facts span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.order-identity strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 16px; }
.order-facts { padding: 17px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.order-facts b { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.progress-header { margin: 8px 0 8px; display: flex; justify-content: space-between; font-size: 12px; }
.progress-header b { color: var(--green); }
.progress-track { height: 7px; overflow: hidden; background: #e7ece9; border-radius: 4px; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--green); transition: width 260ms ease; }
.step-list { margin: 23px 0 20px; padding: 0; list-style: none; }
.step-list li { position: relative; min-height: 39px; padding: 0 0 14px 27px; color: var(--muted); font-size: 12px; }
.step-list li::before { content: ""; position: absolute; left: 6px; top: 13px; bottom: -1px; width: 1px; background: var(--line); }
.step-list li:last-child::before { display: none; }
.step-list li i { position: absolute; left: 1px; top: 2px; width: 11px; height: 11px; background: var(--surface); border: 2px solid var(--line-strong); border-radius: 50%; }
.step-list li.is-active { color: var(--ink); font-weight: 700; }
.step-list li.is-active i { border-color: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }
.step-list li.is-done { color: var(--green-dark); }
.step-list li.is-done i { background: var(--green); border-color: var(--green); }
.step-list li.is-error { color: var(--red); }
.step-list li.is-error i { background: var(--red); border-color: var(--red); }
.live-result { margin-bottom: 12px; padding: 11px 12px; color: var(--green-dark); background: var(--green-soft); border-radius: 5px; font-size: 12px; word-break: break-word; }
.live-result.is-error { color: var(--red); background: var(--red-soft); }
.live-panel > .secondary-button { width: 100%; }
.live-action-link { width: 100%; margin-bottom: 9px; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.live-action-link[hidden] { display: none; }

.list-toolbar { margin-bottom: 16px; display: flex; justify-content: space-between; align-items: end; }
.toolbar-actions { display: flex; align-items: center; gap: 10px; }
.toolbar-actions > span { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.table-frame { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
table { width: 100%; min-width: 1180px; border-collapse: collapse; }
th, td { height: 54px; padding: 0 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { height: 43px; color: var(--muted); background: var(--surface-soft); font-size: 11px; font-weight: 750; }
td { font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfb; }
.order-key { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 700; }
.table-status { display: inline-flex; min-height: 24px; padding: 0 8px; align-items: center; border-radius: 4px; font-size: 10px; font-weight: 800; }
.row-action { padding: 4px 0; color: var(--green); background: transparent; border: 0; font-size: 11px; font-weight: 750; }
.table-empty { min-height: 180px; display: grid; place-items: center; color: var(--muted); }
.pagination { margin-top: 14px; display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.pagination > span { color: var(--muted); font-size: 12px; }

.order-detail-panel { padding: 24px; }
.order-detail-header { padding-bottom: 18px; display: flex; align-items: end; justify-content: space-between; border-bottom: 1px solid var(--line); }
.order-detail-header span, .order-detail-grid span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.order-detail-header strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 17px; }
.order-detail-header > .status-badge { margin-bottom: 0; }
.order-detail-grid { padding: 22px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px 24px; }
.order-detail-grid > div { min-width: 0; }
.order-detail-grid b { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.detail-progress-header { margin: 3px 0 8px; display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.detail-progress-header b { color: var(--green); }
.order-detail-panel .live-result { margin-top: 20px; }
.detail-timeline { margin-top: 20px; padding: 16px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.detail-timeline-header { margin-bottom: 12px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.detail-timeline-header b { color: var(--green); }
.detail-timeline ol { margin: 0; padding: 0; list-style: none; }
.detail-timeline li { padding: 8px 0; display: grid; grid-template-columns: 105px 90px 1fr; gap: 10px; border-top: 1px solid var(--line); font-size: 11px; }
.detail-timeline li:first-child { border-top: 0; }
.detail-timeline-stage { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 700; }
.detail-timeline-time { color: var(--green); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.detail-timeline-message { min-width: 0; color: var(--muted); overflow-wrap: anywhere; }

.integration-list { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.integration-row { min-height: 68px; padding: 13px 17px; display: grid; grid-template-columns: 50px 1fr auto; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); }
.integration-row:last-child { border-bottom: 0; }
.integration-code { width: 42px; height: 42px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); border-radius: 5px; font-size: 10px; font-weight: 850; text-transform: uppercase; }
.integration-copy b { display: block; margin-bottom: 4px; }
.integration-copy span { color: var(--muted); font-size: 11px; }
.integration-state { min-width: 74px; padding: 6px 9px; text-align: center; border-radius: 4px; font-size: 10px; font-weight: 800; }
.integration-state.ready { color: var(--green); background: var(--green-soft); }
.integration-state.staged { color: var(--amber); background: var(--amber-soft); }
.integration-state.missing { color: var(--red); background: var(--red-soft); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(360px, calc(100% - 32px)); padding: 11px 14px; color: #fff; background: #202622; border-radius: 5px; box-shadow: 0 12px 30px rgba(0,0,0,0.2); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 160ms ease, transform 160ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--red); }

@media (max-width: 880px) {
  .topbar-inner { grid-template-columns: 1fr auto; }
  .primary-tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: 58px; justify-content: space-around; background: #171b19; border-top: 1px solid #303833; }
  .tab-button { flex: 1; }
  .tab-button.is-active::after { top: 0; bottom: auto; }
  .environment { display: none; }
  .app-shell { padding-bottom: 88px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .order-form, .live-panel { min-height: 0; }
  .live-empty { min-height: 320px; }
  .order-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .topbar-inner, .app-shell { width: min(calc(100% - 24px), 1180px); }
  .app-shell { padding-top: 24px; }
  .page-heading { align-items: flex-start; gap: 14px; }
  .heading-meta { display: none; }
  h1 { font-size: 25px; }
  .order-detail-grid { grid-template-columns: 1fr; }
  .detail-timeline li { grid-template-columns: 90px 70px 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .order-form, .live-panel { padding: 18px; }
  .panel-heading { gap: 8px; }
  .panel-heading > div { min-width: 0; }
  .panel-heading h2 { white-space: nowrap; }
  .panel-heading .mode-badge { flex: 0 0 auto; max-width: none; padding-inline: 8px; white-space: nowrap; }
  .mode-badge-full { display: none; }
  .mode-badge-short { display: inline; }
  .input-actions { grid-template-columns: 1fr 58px; }
  .input-actions #copyApiKey { grid-column: 1; grid-row: 2; }
  .input-actions #generateApiKey { grid-column: 2; grid-row: 2; }
  .segmented-control { grid-template-columns: 1fr; }
  .segment { min-height: 48px; flex-direction: row; align-items: center; justify-content: space-between; }
  .segment span { margin-top: 0; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .billing-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .billing-wide { grid-column: span 2; }
  .card-fields-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-number-field { grid-column: 1 / -1; }
  .primary-button { min-width: 0; gap: 8px; }
  .primary-button span, .primary-button b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .list-toolbar { align-items: flex-start; gap: 16px; }
  .toolbar-actions > span { display: none; }
  .integration-row { grid-template-columns: 42px 1fr; }
  .integration-state { grid-column: 2; justify-self: start; }
  .toast { right: 16px; bottom: 76px; }
}
