:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --ink: #18202a;
  --muted: #65717f;
  --line: #d9dee5;
  --line-strong: #bac3ce;
  --accent: #0b6f5c;
  --accent-hover: #075849;
  --accent-soft: #e5f3ef;
  --blue: #235f9f;
  --blue-soft: #e8f0f8;
  --warning: #8a5a08;
  --warning-soft: #fff5d8;
  --danger: #b52b31;
  --danger-hover: #932229;
  --danger-soft: #fae9ea;
  --success: #14734e;
  --success-soft: #e3f3eb;
  --shadow: 0 12px 32px rgba(25, 38, 52, 0.09);
  --header-height: 64px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

input,
select,
textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 92px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 111, 92, 0.12);
}

input::placeholder,
textarea::placeholder {
  color: #98a2ae;
}

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: #17232d;
  color: #f5f8fa;
  border-bottom: 3px solid var(--accent);
}

.brand-block,
.header-status,
.section-heading,
.summary-header,
.wallet-toolbar,
.toolbar-actions,
.dialog-header,
.dialog-actions,
.dialog-note,
.check-row {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 11px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #9fe0cf;
  border: 1px solid #52616d;
  border-radius: 6px;
}

.brand-mark svg {
  width: 19px;
}

h1,
h2,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 17px;
  line-height: 1.15;
  font-weight: 650;
}

.brand-meta,
.eyebrow {
  margin-top: 3px;
  color: #8593a1;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0;
}

.header-status {
  gap: 8px;
  color: #c8d0d7;
  font-size: 12px;
}

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

.status-dot.connected {
  background: #54d5a9;
  box-shadow: 0 0 0 3px rgba(84, 213, 169, 0.14);
}

.status-dot.error {
  background: #ef777c;
}

.header-divider {
  width: 1px;
  height: 18px;
  margin: 0 5px;
  background: #485661;
}

.workspace {
  min-height: calc(100vh - var(--header-height));
  display: grid;
  grid-template-columns: minmax(286px, 330px) minmax(580px, 1fr) minmax(290px, 340px);
  align-items: stretch;
}

.config-pane,
.activity-pane {
  min-width: 0;
  background: var(--surface);
}

.config-pane {
  border-right: 1px solid var(--line);
}

.activity-pane {
  border-left: 1px solid var(--line);
}

.pane-section,
.execution-section,
.log-section {
  padding: 20px;
  border-top: 1px solid var(--line);
}

.section-first {
  border-top: 0;
}

.section-heading {
  min-height: 30px;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

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

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

.segmented-control {
  height: 36px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: #e9edf1;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.compact-segments {
  margin-bottom: 3px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-note {
  margin: 7px 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.merkle-check-row {
  align-self: end;
  min-height: 38px;
  margin-top: 12px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface-muted);
}

.merkle-check-row input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.merkle-check-row span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.segment {
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}

.segment.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(22, 31, 40, 0.13);
}

.stepper {
  display: grid;
  grid-template-columns: 34px minmax(42px, 1fr) 34px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  overflow: hidden;
}

.stepper input {
  height: 36px;
  padding: 0 3px;
  text-align: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: 0;
  appearance: textfield;
}

.stepper button {
  display: grid;
  place-items: center;
  border: 0;
  background: var(--surface-muted);
  color: var(--muted);
}

.stepper svg,
.icon-button svg,
button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.input-suffix {
  position: relative;
}

.input-suffix input {
  padding-right: 30px;
}

.input-suffix span {
  position: absolute;
  top: 10px;
  right: 10px;
  color: var(--muted);
  font-size: 12px;
}

.compact-textarea {
  min-height: 72px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
}

.primary-button,
.danger-button {
  padding: 0 14px;
  color: white;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--accent);
}

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

.danger-button {
  background: var(--danger);
}

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

.secondary-button {
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.secondary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  background: var(--surface-muted);
  border-color: #98a4b0;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.danger-icon {
  color: var(--danger);
}

.full-width {
  width: 100%;
  margin-top: 14px;
}

.main-pane {
  min-width: 0;
  padding: 0 24px 28px;
}

.risk-strip {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -24px 20px;
  padding: 0 24px;
  color: #66460a;
  background: var(--warning-soft);
  border-bottom: 1px solid #ead89b;
  font-size: 11px;
}

.risk-strip svg {
  width: 16px;
  flex: 0 0 auto;
}

.risk-spacer {
  flex: 1;
}

.contract-summary,
.wallet-workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.contract-summary {
  margin-bottom: 18px;
  padding: 19px 20px 20px;
}

.summary-header,
.wallet-toolbar {
  justify-content: space-between;
  gap: 16px;
}

.summary-header h2,
.wallet-toolbar h2,
.dialog-header h2 {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 680;
}

.status-badge,
.row-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 4px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.neutral,
.row-status.neutral {
  color: #596675;
  background: #edf0f3;
}

.status-badge.success,
.row-status.success {
  color: var(--success);
  background: var(--success-soft);
}

.status-badge.warning,
.row-status.warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-badge.danger,
.row-status.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-badge.info,
.row-status.info {
  color: var(--blue);
  background: var(--blue-soft);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}

.metric {
  min-width: 0;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 13px;
  background: var(--surface-muted);
  border-left: 1px solid var(--line);
}

.metric:first-child {
  border-left: 0;
}

.metric span,
.execution-totals span {
  color: var(--muted);
  font-size: 10px;
}

.metric strong {
  margin-top: 6px;
  overflow: hidden;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-workspace {
  overflow: hidden;
}

.wallet-toolbar {
  min-height: 76px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
}

.wallet-toolbar h2 span {
  color: var(--muted);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.toolbar-actions {
  gap: 8px;
}

.wallet-table-wrap {
  width: 100%;
  min-height: 315px;
  overflow: auto;
}

.wallet-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  table-layout: fixed;
}

.wallet-table th,
.wallet-table td {
  height: 49px;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #e8ebef;
  font-size: 11px;
}

.wallet-table th {
  height: 38px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 10px;
  font-weight: 700;
}

.wallet-table th:nth-child(1) { width: 42px; }
.wallet-table th:nth-child(2) { width: 190px; }
.wallet-table th:nth-child(3) { width: 100px; }
.wallet-table th:nth-child(4) { width: 70px; }
.wallet-table th:nth-child(5) { width: 104px; }
.wallet-table th:nth-child(6) { width: 112px; }
.wallet-table th:nth-child(7) { width: 46px; }

.row-quantity {
  width: 54px;
  height: 29px;
  padding: 0 5px;
  text-align: center;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
}

.address-cell,
.numeric-cell {
  font-family: "Cascadia Mono", Consolas, monospace;
}

.address-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-row td {
  height: 275px;
  color: #8a96a2;
  text-align: center;
  border: 0;
}

.empty-row td svg {
  display: block;
  width: 28px;
  height: 28px;
  margin: 0 auto 9px;
}

.row-action {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #87929d;
  background: transparent;
  border: 0;
}

.row-action:hover {
  color: var(--danger);
}

.row-action svg {
  width: 15px;
}

.execution-section {
  border-top: 0;
}

.execution-totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}

.execution-totals div {
  min-width: 0;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 9px 11px;
  background: var(--surface-muted);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.execution-totals div:nth-child(2n) {
  border-right: 0;
}

.execution-totals div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.execution-totals strong {
  margin-top: 5px;
  overflow: hidden;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.execution-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.progress-track {
  flex: 1;
  height: 6px;
  overflow: hidden;
  background: #e2e6ea;
  border-radius: 3px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.execution-progress span {
  color: var(--muted);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
}

.log-section {
  min-height: 360px;
}

.activity-log {
  height: calc(100vh - 450px);
  min-height: 300px;
  overflow: auto;
  padding-right: 4px;
}

.log-entry {
  display: grid;
  grid-template-columns: 55px 1fr;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid #e8ebef;
  font-size: 10px;
  line-height: 1.45;
}

.log-time {
  color: #929da8;
  font-family: "Cascadia Mono", Consolas, monospace;
}

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

.log-entry.error .log-message { color: var(--danger); }
.log-entry.success .log-message { color: var(--success); }
.log-entry.info .log-message { color: var(--blue); }
.log-entry.warning .log-message { color: var(--warning); }

.log-message a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(16, 25, 33, 0.56);
}

.dialog-shell {
  padding: 20px;
}

.dialog-header {
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 18px;
}

.secret-input-wrap {
  position: relative;
}

.secret-textarea {
  min-height: 190px;
  padding-right: 45px;
  -webkit-text-security: disc;
}

.secret-textarea.revealed {
  -webkit-text-security: none;
}

.secret-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--surface);
}

.dialog-note {
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px;
  color: #43655c;
  background: var(--accent-soft);
  border: 1px solid #c4e0d8;
  border-radius: 5px;
  font-size: 11px;
  line-height: 1.45;
}

.dialog-note svg {
  width: 16px;
  flex: 0 0 auto;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 9px;
  margin-top: 20px;
}

.confirm-summary {
  padding: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.check-row {
  align-items: flex-start;
  gap: 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.check-row input {
  width: 15px;
  height: 15px;
  margin: 1px 0 0;
  accent-color: var(--danger);
  flex: 0 0 auto;
}

.danger-text {
  color: var(--danger);
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  padding: 11px 13px;
  color: white;
  background: #27343e;
  border-radius: 5px;
  box-shadow: var(--shadow);
  font-size: 11px;
  line-height: 1.45;
  animation: toast-in 160ms ease-out;
}

.toast.error { background: #8f272c; }
.toast.success { background: #126346; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

  .activity-pane {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 330px 1fr;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .log-section {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .activity-log {
    height: 300px;
  }

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

  .metric:nth-child(4) {
    border-left: 0;
  }

  .metric:nth-child(n + 4) {
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  :root { --header-height: 58px; }

  .app-header {
    padding: 0 13px;
  }

  .brand-mark { display: none; }
  .brand-block h1 { font-size: 15px; }
  .brand-meta { display: none; }
  .header-status { font-size: 10px; }
  .header-divider { display: none; }

  .workspace {
    display: block;
  }

  .config-pane,
  .activity-pane {
    border: 0;
  }

  .config-pane {
    border-bottom: 1px solid var(--line);
  }

  .main-pane {
    padding: 0 12px 18px;
  }

  .risk-strip {
    margin: 0 -12px 14px;
    padding: 8px 12px;
    align-items: flex-start;
    line-height: 1.4;
  }

  .risk-spacer,
  #security-origin {
    display: none;
  }

  .contract-summary {
    padding: 15px;
  }

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

  .metric:nth-child(odd) {
    border-left: 0;
  }

  .metric:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .metric:nth-child(4) {
    border-left: 1px solid var(--line);
  }

  .wallet-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .secondary-button {
    flex: 1;
  }

  .activity-pane {
    display: block;
  }

  .log-section {
    border-left: 0;
  }

  .activity-log {
    height: 320px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}
