:root {
  color-scheme: dark;
  --ink: #edf4f0;
  --muted: #9eada6;
  --line: #33423d;
  --panel: #17201d;
  --paper: #0d1210;
  --sidebar: #111916;
  --field: #101714;
  --subtle: #1d2925;
  --warm-subtle: #262117;
  --notice: #291b18;
  --topbar: rgba(13, 18, 16, 0.94);
  --button-bg: #e6efeb;
  --button-text: #101714;
  --button-hover: #cfdcd6;
  --receipt: #080b0a;
  --receipt-ink: #e7f2ed;
  --receipt-muted: #abd4c9;
  --teal: #31afa3;
  --green: #52b968;
  --coral: #ee7866;
  --amber: #e0ad4f;
  --focus: rgba(49, 175, 163, 0.2);
  --coral-soft: rgba(238, 120, 102, 0.14);
  --green-soft: rgba(82, 185, 104, 0.14);
  --teal-soft: rgba(49, 175, 163, 0.12);
  --teal-line: rgba(49, 175, 163, 0.34);
  --coral-line: rgba(238, 120, 102, 0.4);
  --green-line: rgba(82, 185, 104, 0.4);
  --backdrop: rgba(4, 8, 7, 0.76);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #1d2525;
  --muted: #65706c;
  --line: #d7ddd6;
  --panel: #ffffff;
  --paper: #f6f7f2;
  --sidebar: #eef4ed;
  --field: #ffffff;
  --subtle: #edf2ed;
  --warm-subtle: #fffaf0;
  --notice: #fff5f1;
  --topbar: rgba(246, 247, 242, 0.94);
  --button-bg: #1d2525;
  --button-text: #ffffff;
  --button-hover: #273231;
  --receipt: #172020;
  --receipt-ink: #e7f2ed;
  --receipt-muted: #b7d8d0;
  --teal: #087f7a;
  --green: #2f8f46;
  --coral: #c65343;
  --amber: #9e7018;
  --focus: rgba(8, 127, 122, 0.14);
  --coral-soft: rgba(198, 83, 67, 0.12);
  --green-soft: rgba(47, 143, 70, 0.12);
  --teal-soft: rgba(8, 127, 122, 0.08);
  --teal-line: rgba(8, 127, 122, 0.28);
  --coral-line: rgba(198, 83, 67, 0.4);
  --green-line: rgba(47, 143, 70, 0.4);
  --backdrop: rgba(23, 32, 32, 0.55);
  --shadow: 0 18px 45px rgba(29, 37, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  transition:
    transform 140ms ease,
    background 140ms ease,
    opacity 140ms ease;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
}

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

.compact-button {
  min-height: 34px;
  padding: 0 12px;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--button-hover);
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--focus);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

code,
pre {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  align-content: start;
  gap: 18px;
  height: 100vh;
  min-width: 0;
  max-width: 100%;
  padding: 24px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.network-visual {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  background: var(--subtle);
}

.brand-block {
  display: grid;
  gap: 5px;
}

.brand-mark {
  color: var(--teal);
  font-size: 2.8rem;
  font-weight: 850;
  line-height: 0.9;
}

.brand-subtitle {
  color: var(--muted);
}

.language-control,
.theme-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 1.35fr);
  align-items: center;
  gap: 10px;
}

.language-control select {
  min-width: 0;
}

.theme-control > span {
  color: var(--muted);
  font-size: 0.9rem;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 3px;
}

.segmented-control button {
  min-height: 34px;
  min-width: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.segmented-control button:hover:not(:disabled) {
  background: var(--subtle);
  color: var(--ink);
}

.segmented-control button.is-active {
  background: var(--teal);
  color: #ffffff;
}

.node-form,
.wallet-summary,
.surface {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 1px 0 var(--teal-soft);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.inline-control > * {
  min-width: 0;
}

.node-form .inline-control {
  grid-template-columns: 1fr;
}

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

.connection-line {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.88rem;
}

.connection-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 4px var(--coral-soft);
}

.connection-dot.is-online {
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.status-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--warm-subtle);
  padding: 12px;
}

.status-grid span,
.wallet-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-grid strong,
.wallet-summary strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-summary code {
  display: block;
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.76rem;
}

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

.summary-actions button:last-child {
  grid-column: 1 / -1;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  padding: 14px 24px;
  backdrop-filter: blur(12px);
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  min-width: 92px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  white-space: nowrap;
}

.tab:hover:not(:disabled) {
  background: var(--field);
  color: var(--ink);
}

.tab.is-active {
  background: var(--teal);
  color: #ffffff;
}

.toast {
  max-width: 360px;
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 12px;
  text-align: center;
}

.toast.is-error {
  border-color: var(--coral-line);
  color: var(--coral);
}

.toast.is-ok {
  border-color: var(--green-line);
  color: var(--green);
}

.panel {
  display: none;
  gap: 24px;
  padding: 28px 32px 44px;
}

.panel.is-active {
  display: grid;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-head > div {
  display: grid;
  gap: 6px;
}

.section-head p,
.surface p {
  color: var(--muted);
}

.wallet-grid,
.token-layout,
.market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.balance-surface {
  grid-column: 1 / -1;
}

.balance-number {
  color: var(--teal);
  font-size: 3rem;
  font-weight: 820;
  line-height: 1;
  overflow-wrap: anywhere;
}

.balance-number small {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.balance-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.balance-meta div {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.balance-meta dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.balance-meta dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.transaction-form,
.liquidity-form {
  max-width: 760px;
}

.receipt {
  display: grid;
  gap: 9px;
  max-height: 300px;
  overflow: auto;
  border-radius: 8px;
  background: var(--receipt);
  color: var(--receipt-ink);
  padding: 16px;
}

.receipt code {
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
  color: var(--receipt-muted);
}

.two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.fee-line {
  border-left: 4px solid var(--amber);
  color: var(--muted);
  padding: 8px 0 8px 12px;
}

.token-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.token-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.token-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.token-card code {
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.76rem;
}

.pill {
  border: 1px solid var(--teal-line);
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  padding: 8px 12px;
  white-space: nowrap;
}

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

.security-notice {
  display: grid;
  gap: 10px;
  border: 1px solid var(--coral-line);
  border-left: 5px solid var(--coral);
  border-radius: 8px;
  background: var(--notice);
  padding: 16px;
}

.security-notice span,
.empty-state {
  color: var(--muted);
}

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

.history-list {
  display: grid;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 18px;
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.history-item:first-child {
  border-top: 0;
}

.history-item > div {
  display: grid;
  gap: 3px;
}

.history-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-item code {
  grid-column: 1 / -1;
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.72rem;
}

.is-outgoing {
  color: var(--coral);
}

.is-incoming {
  color: var(--green);
}

.network-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.network-details > div {
  display: grid;
  gap: 5px;
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.network-details span {
  color: var(--muted);
  font-size: 0.82rem;
}

.network-details strong {
  overflow-wrap: anywhere;
}

.service-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 6px 12px;
  white-space: nowrap;
}

.service-status.is-online {
  border-color: var(--green-line);
  color: var(--green);
}

.service-status.is-offline {
  border-color: var(--coral-line);
  color: var(--coral);
}

.trade-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  align-items: start;
  gap: 18px;
}

.trade-form,
.trade-order {
  min-width: 0;
}

.trade-side-control {
  margin-bottom: 2px;
}

.trade-quote {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 2px 0 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.trade-quote > div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 13px 0;
}

.trade-quote > div + div {
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.trade-quote dt {
  color: var(--muted);
  font-size: 0.8rem;
}

.trade-quote dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.trade-notice {
  min-height: 44px;
  border-left: 4px solid var(--amber);
  padding-left: 12px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.trade-payout-field {
  display: grid;
  gap: 7px;
}

.trade-wallet-hint {
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.trade-order {
  position: sticky;
  top: 90px;
}

.trade-order-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.trade-order-actions > :only-child {
  grid-column: 1 / -1;
}

.trade-detail-list {
  display: grid;
  gap: 0;
  margin: 0;
}

.trade-detail-list > div {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 11px 0;
}

.trade-detail-list > div:first-child {
  border-top: 0;
}

.trade-detail-list dt {
  color: var(--muted);
}

.trade-detail-list dd {
  margin: 0;
  direction: ltr;
  text-align: right;
  overflow-wrap: anywhere;
}

.trade-status {
  color: var(--teal);
  font-weight: 750;
}

.trade-warning {
  border-left: 4px solid var(--coral);
  color: var(--muted);
  padding: 8px 0 8px 12px;
  line-height: 1.45;
}

.confirm-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: var(--backdrop);
}

.confirm-dialog form {
  display: grid;
  gap: 20px;
  padding: 22px;
}

.confirm-details {
  display: grid;
  gap: 0;
  margin: 0;
}

.confirm-details div {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 11px 0;
}

.confirm-details dt {
  color: var(--muted);
}

.confirm-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

[dir="rtl"] .sidebar {
  border-right: 0;
  border-left: 1px solid var(--line);
}

[dir="rtl"] .fee-line {
  border-right: 4px solid var(--amber);
  border-left: 0;
  padding: 8px 12px 8px 0;
}

[dir="rtl"] .trade-notice,
[dir="rtl"] .trade-warning {
  border-right: 4px solid var(--amber);
  border-left: 0;
  padding-right: 12px;
  padding-left: 0;
}

[dir="rtl"] .trade-warning {
  border-right-color: var(--coral);
}

[dir="rtl"] .trade-quote > div + div {
  border-right: 1px solid var(--line);
  border-left: 0;
  padding-right: 16px;
  padding-left: 0;
}

[dir="rtl"] .security-notice {
  border-right: 5px solid var(--coral);
  border-left: 1px solid var(--coral-line);
}

[dir="rtl"] .network-details {
  border-right: 1px solid var(--line);
  border-left: 0;
}

[dir="rtl"] .network-details > div {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (min-width: 981px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid > div:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

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

  .trade-layout {
    grid-template-columns: 1fr;
  }

  .trade-order {
    position: static;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 720px) {
  .sidebar {
    gap: 12px;
    padding: 16px;
  }

  .network-visual {
    display: none;
  }

  .brand-mark {
    font-size: 2.2rem;
  }

  .language-control {
    grid-template-columns: minmax(80px, 0.6fr) minmax(0, 1fr);
  }

  .theme-control {
    grid-template-columns: minmax(80px, 0.6fr) minmax(0, 1fr);
  }

  .node-form,
  .wallet-summary {
    gap: 10px;
    padding: 12px;
  }

  .status-grid > div {
    padding: 10px;
  }

  .panel {
    padding: 24px 16px 36px;
  }

  .topbar {
    gap: 10px;
    padding: 12px 16px;
  }

  .tabs {
    gap: 6px;
  }

  .tab {
    min-width: 82px;
    padding: 0 8px;
  }

  .wallet-grid,
  .token-layout,
    .market-grid,
    .trade-quote,
    .two-columns,
    .balance-meta {
    grid-template-columns: 1fr;
  }

  .trade-quote > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
    padding-left: 0;
  }

  [dir="rtl"] .trade-quote > div + div {
    border-right: 0;
    padding-right: 0;
  }

  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-item code {
    grid-column: 1;
  }

  .confirm-details div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .inline-control {
    grid-template-columns: 1fr;
  }

  .trade-detail-list > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .trade-detail-list dd {
    text-align: left;
  }

}

@media (max-width: 360px) {
  .language-control,
  .theme-control {
    grid-template-columns: 1fr;
  }

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

  .status-grid > div:last-child {
    grid-column: 1 / -1;
  }
}
