:root {
  --bg: var(--tg-theme-bg-color, #f2f2f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-soft: #f8f9fb;
  --text: var(--tg-theme-text-color, #111111);
  --muted: var(--tg-theme-hint-color, #6e6e73);
  --line: rgba(60, 60, 67, 0.16);
  --line-strong: rgba(60, 60, 67, 0.28);
  --button: var(--tg-theme-button-color, #007aff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --green: #1f8f5f;
  --orange: #b96800;
  --red: #c73e3e;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(20, 24, 31, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
a,
.button-link {
  -webkit-tap-highlight-color: transparent;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: var(--button);
  color: var(--button-text);
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, #ffffff);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 12px) 20px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: color-mix(in srgb, var(--button) 72%, #ffffff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--button) 18%, transparent);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.12;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
  line-height: 1.2;
}

.mini-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(92px + env(safe-area-inset-bottom));
}

.mini-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 2px 10px;
}

.product-mark,
.mini-header p,
.section-title span,
.group-title span,
.field span,
.metric-grid span,
.hero-balance span,
.task-meta,
.empty,
.ledger-sub,
.plan-meta,
.confirm-box p,
.status-line,
.setup-card p {
  color: var(--muted);
}

.product-mark {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.mini-header p {
  margin-top: 5px;
  font-size: 14px;
  line-height: 1.35;
}

.admin-link,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--button) 10%, #ffffff);
  color: var(--button);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  padding: 0 11px;
}

.text-button {
  width: auto;
  border: 1px solid color-mix(in srgb, var(--button) 16%, transparent);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  border-radius: var(--radius);
  background: var(--button);
  color: var(--button-text);
  font-weight: 800;
  text-decoration: none;
}

.button-link.secondary-link {
  border: 1px solid color-mix(in srgb, var(--button) 18%, transparent);
  background: color-mix(in srgb, var(--button) 10%, #ffffff);
  color: var(--button);
}

.setup-card,
.ledger-hero,
.grouped-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setup-card {
  display: none;
  gap: 10px;
  margin-bottom: 12px;
  padding: 13px;
}

.setup-card.connected {
  display: none;
}

.setup-card strong,
.confirm-box strong {
  display: block;
  margin-bottom: 4px;
}

.setup-card p,
.confirm-box p {
  font-size: 13px;
  line-height: 1.42;
}

.compact-field {
  margin: 0;
}

.technical-field,
.role-field {
  display: none !important;
}

.ledger-hero {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px;
}

.hero-topline,
.merchant-row,
.section-title,
.group-title,
.task-head,
.ledger-head,
.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.merchant-row label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.merchant-row select {
  max-width: 68%;
  min-height: 38px;
  border: 0;
  background-color: var(--surface-soft);
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.status-pill.ok {
  background: #e9f7ef;
  color: var(--green);
}

.status-pill.waiting {
  background: #f3f3f5;
  color: var(--muted);
}

.status-pill.warn {
  background: #fff4e4;
  color: var(--orange);
}

.hero-balance {
  display: grid;
  gap: 8px;
}

.hero-balance strong {
  font-size: clamp(34px, 10vw, 48px);
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric-grid article {
  display: grid;
  gap: 5px;
  min-width: 0;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px;
}

.metric-grid strong {
  align-self: end;
  font-size: 15px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.section-title {
  margin: 18px 2px 10px;
}

.section-title span,
.group-title span {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
  line-height: 1.35;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 800;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.action-list,
.task-list,
.ledger-list,
.plan-list,
.native-form {
  display: grid;
  gap: 10px;
}

.action-card,
.task-card,
.ledger-card,
.plan-card,
.empty {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.action-card,
.task-card,
.ledger-card,
.plan-card {
  display: grid;
  gap: 11px;
  padding: 13px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.action-card.priority {
  border-color: color-mix(in srgb, var(--button) 34%, var(--line));
}

.task-head strong,
.ledger-head strong,
.plan-card strong,
.action-card strong {
  display: block;
  min-width: 0;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.task-meta,
.ledger-sub,
.plan-meta,
.action-card p {
  font-size: 13px;
  line-height: 1.4;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.transaction-card {
  gap: 13px;
  border-color: color-mix(in srgb, var(--button) 18%, var(--line));
}

.transaction-context {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.context-only {
  background: color-mix(in srgb, var(--button) 5%, var(--surface));
}

.state-rail {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.state-rail li {
  display: grid;
  min-width: 0;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.state-rail li span {
  display: block;
  height: 5px;
  border-radius: 999px;
  background: #e5e7eb;
}

.state-rail li.done span,
.state-rail li.current span {
  background: var(--button);
}

.state-rail li.current b {
  color: var(--text);
}

.state-rail b {
  min-width: 0;
  overflow-wrap: anywhere;
}

.fact-list {
  display: grid;
  gap: 8px;
  margin: 0;
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px;
}

.fact-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.fact-list dd {
  max-width: 62%;
}

.next-hint {
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
  line-height: 1.4;
}

.task-actions {
  display: grid;
  gap: 8px;
}

.action-sheet-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--button) 6%, var(--surface-soft));
  padding: 10px 11px;
}

.action-sheet-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.action-sheet-title strong {
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
  text-align: right;
}

.next-owner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--button) 18%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--button) 7%, var(--surface));
  padding: 10px 11px;
}

.next-owner span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.next-owner strong {
  font-size: 14px;
  text-align: right;
}

.proof-note {
  min-height: 42px;
}

.grouped-section {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 13px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 13px;
  font-weight: 700;
}

.readonly-field p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.language-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(118, 118, 128, 0.14);
}

.language-buttons button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.language-buttons button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.check-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: start;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 1px;
  accent-color: var(--button);
}

details {
  border-top: 1px solid var(--line);
  padding-top: 11px;
}

details:first-of-type {
  border-top: 0;
  padding-top: 0;
}

summary {
  min-height: 42px;
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
  list-style-position: inside;
}

.confirm-box {
  margin-bottom: 10px;
  border: 1px solid #f0d2aa;
  border-radius: var(--radius);
  background: #fff8ef;
  padding: 11px;
}

.setup-guide {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 11px;
}

.setup-guide p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.form-note {
  border: 1px solid color-mix(in srgb, var(--button) 14%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--button) 5%, var(--surface-soft));
  color: var(--muted);
  padding: 10px 11px;
  font-size: 13px;
  line-height: 1.45;
}

.form-note.calm {
  border-color: var(--line);
  background: var(--surface-soft);
}

.intent-grid {
  display: grid;
  gap: 10px;
}

.intent-card {
  position: relative;
  display: grid;
  min-height: 76px;
  align-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px 40px 14px 14px;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.intent-card::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 17px;
  width: 8px;
  height: 8px;
  border-top: 2px solid color-mix(in srgb, var(--muted) 78%, transparent);
  border-right: 2px solid color-mix(in srgb, var(--muted) 78%, transparent);
  transform: translateY(-50%) rotate(45deg);
}

.intent-card strong {
  font-size: 17px;
  line-height: 1.22;
}

.intent-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.intent-card.primary {
  border-color: rgba(0, 122, 255, 0.28);
  background: #eef6ff;
}

.intent-card.primary::after {
  border-color: var(--button);
}

.intent-card:active {
  transform: scale(0.99);
}

.danger-zone {
  border-color: #ead4d4;
}

.status-line {
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  font-size: 13px;
}

.status-token {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 9px;
  background: #f0f3f7;
  color: var(--muted);
  font-weight: 800;
}

.status-token.requested {
  background: #fff4e4;
  color: var(--orange);
}

.status-token.finance_submitted {
  background: #e8f2ff;
  color: var(--button);
}

.status-token.confirmed,
.status-token.settled,
.status-token.active {
  background: #e9f7ef;
  color: var(--green);
}

.status-token.stopped {
  background: #f7eaea;
  color: var(--red);
}

.ledger-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.ledger-card dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
  overflow-wrap: anywhere;
}

.empty {
  padding: 18px 14px;
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 5px;
  color: var(--text);
}

.empty p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  width: min(100%, 520px);
  margin: 0 auto;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.bottom-nav button span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 52%, transparent);
  transition: width 0.16s ease, background 0.16s ease;
}

.bottom-nav button b {
  font-size: 11px;
  line-height: 1.1;
}

.bottom-nav button.active {
  background: color-mix(in srgb, var(--button) 10%, transparent);
  color: var(--button);
}

.bottom-nav button.active span {
  width: 22px;
  background: var(--button);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  max-width: 488px;
  margin: 0 auto;
  pointer-events: none;
  transform: translateY(18px);
  opacity: 0;
  border-radius: var(--radius);
  background: rgba(28, 28, 30, 0.94);
  color: #ffffff;
  padding: 12px 14px;
  text-align: center;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.active {
  transform: translateY(0);
  opacity: 1;
}

body.focus-mode .mini-shell {
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
}

body.focus-mode .bottom-nav,
body.focus-mode .admin-link {
  display: none;
}

body.focus-mode .mini-header {
  padding-bottom: 14px;
}

body.focus-mode .ledger-hero {
  display: none;
}

body.focus-mode[data-screen="home"] .ledger-hero,
body.focus-mode[data-screen="ledger"] .ledger-hero {
  display: grid;
}

body.focus-mode .ledger-hero .hero-topline,
body.focus-mode .ledger-hero .merchant-row {
  display: none;
}

body.focus-mode .section-title {
  margin-top: 6px;
}

body.focus-mode .native-form > button[type="submit"] {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 4;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--button) 22%, transparent);
}

body.focus-mode[data-screen="finance-submit"] #financeView > .section-title,
body.focus-mode[data-screen="merchant-confirm"] #merchantView > .section-title,
body.focus-mode[data-screen="transfer-card"] #homeView > .section-title,
body.focus-mode[data-screen="transfer-card"] #planList {
  display: none;
}

body.focus-mode[data-screen="merchant-confirm"] #merchantView .return-section,
body.focus-mode[data-screen="merchant-confirm"] #merchantView .plan-section,
body.focus-mode[data-screen="usdt-return"] #merchantView > .section-title,
body.focus-mode[data-screen="usdt-return"] #merchantTasks,
body.focus-mode[data-screen="usdt-return"] #merchantView .plan-section,
body.focus-mode[data-screen="return-plan"] #merchantView > .section-title,
body.focus-mode[data-screen="return-plan"] #merchantTasks,
body.focus-mode[data-screen="return-plan"] #merchantView .return-section {
  display: none;
}

body.focus-mode[data-screen="trade-start"] #settingsView > .grouped-section,
body.focus-mode[data-screen="buyer-start"] #settingsView > .grouped-section,
body.focus-mode[data-screen="seller-start"] #settingsView > .grouped-section,
body.focus-mode[data-screen="create-transfer"] #settingsView > .grouped-section,
body.focus-mode[data-screen="merchant-account"] #settingsView > .grouped-section,
body.focus-mode[data-screen="receive-address"] #settingsView > .grouped-section,
body.focus-mode[data-screen="fiat-method"] #settingsView > .grouped-section,
body.focus-mode[data-screen="crypto-address"] #settingsView > .grouped-section,
body.focus-mode[data-screen="group-profile"] #settingsView > .grouped-section,
body.focus-mode[data-screen="group-setup"] #settingsView > .grouped-section,
body.focus-mode[data-screen="finance-setup"] #settingsView > .grouped-section,
body.focus-mode[data-screen="finance-match"] #settingsView > .grouped-section,
body.focus-mode[data-screen="settings"] #settingsView > .grouped-section {
  display: none;
}

body.focus-mode[data-screen="trade-start"] #settingsView .trade-start-section,
body.focus-mode[data-screen="buyer-start"] #settingsView .buyer-start-section,
body.focus-mode[data-screen="seller-start"] #settingsView .seller-start-section,
body.focus-mode[data-screen="create-transfer"] #settingsView .transfer-section,
body.focus-mode[data-screen="merchant-account"] #settingsView .danger-zone,
body.focus-mode[data-screen="receive-address"] #settingsView .danger-zone,
body.focus-mode[data-screen="fiat-method"] #settingsView .fiat-method-section,
body.focus-mode[data-screen="crypto-address"] #settingsView .crypto-address-section,
body.focus-mode[data-screen="group-profile"] #settingsView .settings-section,
body.focus-mode[data-screen="group-setup"] #settingsView .group-setup-section,
body.focus-mode[data-screen="finance-setup"] #settingsView .finance-setup-section,
body.focus-mode[data-screen="finance-match"] #settingsView .matching-section,
body.focus-mode[data-screen="settings"] #settingsView .settings-section {
  display: grid;
}

body.focus-mode[data-screen="merchant-account"] #settingsView .address-details,
body.focus-mode[data-screen="receive-address"] #settingsView .account-details {
  display: none;
}

body.focus-mode[data-screen="merchant-account"] #settingsView .danger-zone > .group-title,
body.focus-mode[data-screen="receive-address"] #settingsView .danger-zone > .group-title {
  display: none;
}

@media (min-width: 720px) {
  .mini-shell {
    padding-top: 18px;
  }

  .bottom-nav {
    right: calc((100vw - 520px) / 2);
    left: calc((100vw - 520px) / 2);
  }
}

@media (max-width: 380px) {
  .mini-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 18px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .merchant-row {
    display: grid;
    gap: 7px;
  }

  .merchant-row select {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .group-title {
    display: grid;
    justify-content: stretch;
    gap: 4px;
  }
}
