:root {
  --ink: #17211b;
  --muted: #647067;
  --line: #d9dfda;
  --line-strong: #bcc7bf;
  --surface: #ffffff;
  --surface-subtle: #f5f7f5;
  --green: #17633a;
  --green-hover: #104d2c;
  --green-soft: #e7f2eb;
  --amber: #936316;
  --amber-soft: #fff4d8;
  --red: #a33a31;
  --red-soft: #fbeceb;
  --charcoal: #253029;
  --shadow: 0 14px 35px rgba(23, 33, 27, 0.08);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #edf1ed; }

body {
  margin: 0;
  color: var(--ink);
  background: #edf1ed;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

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

.app-shell {
  width: min(1180px, calc(100% - 40px));
  min-height: calc(100vh - 40px);
  margin: 20px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.brand-block, .wallet-actions, .section-heading, .address-preview,
.connection-detail div, .activity-header, .summary-row, .toggle-row,
.confirmation-row { display: flex; align-items: center; }

.brand-block { gap: 11px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; border-radius: 5px; background: var(--surface-subtle); }
.product-name { margin: 0; font-size: 15px; line-height: 1.35; font-weight: 700; }
.product-context { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.wallet-actions { gap: 10px; flex-shrink: 0; }

.network-badge {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface-subtle);
  font-size: 12px;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa39c; }
.network-badge[data-state="connected"] { color: var(--green); border-color: #b9d8c4; background: var(--green-soft); }
.network-badge[data-state="connected"] .status-dot { background: #2c8b55; }
.network-badge[data-state="wrong"] { color: var(--amber); border-color: #e1c887; background: var(--amber-soft); }
.network-badge[data-state="wrong"] .status-dot { background: #c18a26; }

.button {
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
  transition: background 150ms ease, border-color 150ms ease, transform 100ms ease;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button-dark { background: var(--charcoal); color: #fff; }
.button-dark:hover { background: #111a14; }
.button-secondary { color: var(--ink); border-color: var(--line-strong); background: #fff; }
.button-secondary:hover { background: var(--surface-subtle); }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover:not(:disabled) { background: var(--green-hover); }
.button-primary:disabled { color: #929a94; background: #e4e8e5; }
.button-full { width: 100%; }

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  min-height: 670px;
}
.config-panel { padding: 26px 24px; background: var(--surface-subtle); border-right: 1px solid var(--line); }
.approval-panel { min-width: 0; padding: 26px 30px 32px; }
.section-heading { justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.section-heading h1, .section-heading h2 { margin: 2px 0 0; font-size: 20px; line-height: 1.25; }
.main-heading { margin-bottom: 22px; }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; line-height: 1.3; font-weight: 750; text-transform: uppercase; }
.icon-button {
  width: 36px; height: 36px; flex: 0 0 36px;
  border: 1px solid var(--line); border-radius: 5px;
  color: var(--ink); background: #fff; font-size: 21px; line-height: 1;
}
.icon-button:hover { background: #eef2ef; }

.field-stack { margin-bottom: 19px; }
.field-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; color: #39443c; }
.field-control {
  width: 100%; height: 41px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: 5px;
  outline: none; color: var(--ink); background: #fff;
}
.field-control:focus, .amount-control:focus-within { border-color: #43825d; box-shadow: 0 0 0 3px rgba(42, 119, 70, 0.10); }
.address-input { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.field-stack .button { margin-top: 9px; }
.field-error { min-height: 16px; margin: 4px 0 0; color: var(--red); font-size: 11px; line-height: 1.4; }

.address-preview { gap: 11px; margin: 2px 0 18px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.address-preview canvas { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 4px; background: #e8ece9; }
.address-preview-text { min-width: 0; }
.address-preview-text span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.address-preview-text strong { display: block; overflow: hidden; text-overflow: ellipsis; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; white-space: nowrap; }
.connection-detail { padding-top: 14px; border-top: 1px solid var(--line); }
.connection-detail div { justify-content: space-between; gap: 12px; min-height: 27px; }
.connection-detail span { color: var(--muted); font-size: 11px; }
.connection-detail strong { max-width: 170px; overflow: hidden; text-overflow: ellipsis; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; white-space: nowrap; }

.data-state { padding: 5px 8px; border-radius: 4px; color: var(--muted); background: var(--surface-subtle); font-size: 11px; white-space: nowrap; }
.data-state[data-state="ready"] { color: var(--green); background: var(--green-soft); }
.data-state[data-state="loading"] { color: var(--amber); background: var(--amber-soft); }
.data-state[data-state="error"] { color: var(--red); background: var(--red-soft); }

.balance-strip {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.25fr;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.metric { min-width: 0; padding: 16px 17px; border-right: 1px solid var(--line); background: #fff; }
.metric:last-child { border-right: 0; }
.metric-emphasis { background: var(--green-soft); }
.metric span, .metric small { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin: 7px 0 3px; overflow: hidden; text-overflow: ellipsis; font-size: 17px; white-space: nowrap; }
.metric-emphasis strong { color: var(--green); }

.approval-form { max-width: 650px; padding-top: 26px; }
.form-section { margin-bottom: 20px; }
.segmented-control { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-subtle); }
.segmented-control button { min-height: 36px; padding: 0 8px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-weight: 650; }
.segmented-control button[aria-pressed="true"] { color: var(--ink); background: #fff; box-shadow: 0 1px 4px rgba(23, 33, 27, 0.12); }

.amount-control { height: 49px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; overflow: hidden; }
.amount-control input { width: 100%; min-width: 0; height: 100%; padding: 0 13px; border: 0; outline: 0; color: var(--ink); font-size: 17px; font-weight: 650; }
.amount-control > span { max-width: 100px; overflow: hidden; padding: 0 10px; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.amount-control button { height: 31px; margin-right: 8px; padding: 0 9px; border: 1px solid #bdd4c5; border-radius: 4px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 700; }

.toggle-row { justify-content: space-between; gap: 20px; margin: 2px 0 20px; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { font-size: 12px; }
.toggle-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.switch { position: relative; flex: 0 0 40px; width: 40px; height: 23px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: absolute; inset: 0; border-radius: 12px; background: #cbd2cc; transition: background 150ms ease; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 150ms ease; }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { outline: 3px solid rgba(42, 119, 70, 0.18); }

.authorization-summary { padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-subtle); }
.summary-row { justify-content: space-between; gap: 18px; min-height: 27px; }
.summary-row span { color: var(--muted); font-size: 11px; }
.summary-row strong { max-width: 66%; overflow: hidden; text-align: right; text-overflow: ellipsis; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; white-space: nowrap; }
.confirmation-row { align-items: flex-start; gap: 9px; margin: 16px 0 13px; color: #39443c; font-size: 12px; line-height: 1.5; }
.confirmation-row input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--green); }
.approval-button { min-height: 47px; }
.form-note { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.activity-section { margin-top: 30px; padding-top: 21px; border-top: 1px solid var(--line); }
.activity-header { justify-content: space-between; margin-bottom: 11px; }
.activity-header h3 { margin: 0; font-size: 13px; }
.text-button { padding: 3px; border: 0; color: var(--muted); background: transparent; font-size: 11px; }
.text-button:hover { color: var(--ink); }
.activity-log { display: grid; gap: 8px; }
.activity-empty { padding: 15px; border: 1px dashed var(--line-strong); border-radius: 5px; color: var(--muted); text-align: center; font-size: 12px; }
.activity-item { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; }
.activity-item::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9ba49d; }
.activity-item[data-state="pending"]::before { background: #d29324; }
.activity-item[data-state="success"]::before { background: #2c8b55; }
.activity-item[data-state="error"]::before { background: #bd4a40; }
.activity-copy { min-width: 0; }
.activity-copy strong, .activity-copy span { display: block; }
.activity-copy strong { margin-bottom: 2px; font-size: 12px; }
.activity-copy span { overflow: hidden; color: var(--muted); font-family: "Cascadia Mono", Consolas, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.activity-item a { color: var(--green); font-size: 11px; text-decoration: none; }
.activity-item a:hover { text-decoration: underline; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 10; display: grid; gap: 8px; width: min(370px, calc(100% - 36px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); background: #fff; box-shadow: var(--shadow); font-size: 12px; line-height: 1.5; }
.toast[data-state="error"] { border-color: #dfb0ac; background: var(--red-soft); }
.toast[data-state="success"] { border-color: #b9d8c4; background: var(--green-soft); }

.is-hidden { display: none !important; }

@media (max-width: 820px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .workspace { grid-template-columns: 1fr; }
  .config-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .approval-panel { padding: 24px; }
  .approval-form { max-width: none; }
}

@media (max-width: 560px) {
  .topbar { align-items: flex-start; padding: 13px 16px; }
  .product-context, .network-badge { display: none; }
  .wallet-actions .button { min-height: 40px; padding: 0 12px; }
  .config-panel, .approval-panel { padding: 21px 16px; }
  .balance-strip { grid-template-columns: 1fr 1fr; }
  .metric { padding: 14px; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:last-child { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .segmented-control { grid-template-columns: 1fr; }
  .segmented-control button { min-height: 38px; }
  .summary-row { align-items: flex-start; padding: 3px 0; }
  .summary-row strong { max-width: 61%; white-space: normal; word-break: break-all; }
  .activity-item { grid-template-columns: 10px minmax(0, 1fr); }
  .activity-item a { grid-column: 2; }
}
