:root {
  --bg: var(--tg-theme-bg-color, #f3f5f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-2: #edf2f7;
  --surface-3: #f8fafc;
  --text: var(--tg-theme-text-color, #111827);
  --muted: var(--tg-theme-hint-color, #6b7a8c);
  --line: rgba(105, 120, 140, 0.18);
  --blue: var(--tg-theme-button-color, #2481cc);
  --blue-2: #176fb6;
  --blue-soft: rgba(36, 129, 204, 0.12);
  --green: #18a36f;
  --green-soft: rgba(24, 163, 111, 0.13);
  --amber: #c47b12;
  --amber-soft: rgba(196, 123, 18, 0.14);
  --red: #df4545;
  --red-soft: rgba(223, 69, 69, 0.12);
  --shadow: 0 12px 28px rgba(17, 24, 39, 0.08);
  --radius: 8px;
  color-scheme: light dark;
}

body.dark,
body[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #0f1419);
  --surface: var(--tg-theme-secondary-bg-color, #17212b);
  --surface-2: #202b36;
  --surface-3: #111a23;
  --text: var(--tg-theme-text-color, #f4f7fb);
  --muted: var(--tg-theme-hint-color, #96a6b8);
  --line: rgba(150, 166, 184, 0.18);
  --blue-soft: rgba(74, 170, 255, 0.16);
  --green-soft: rgba(24, 163, 111, 0.18);
  --amber-soft: rgba(196, 123, 18, 0.18);
  --red-soft: rgba(223, 69, 69, 0.17);
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.app {
  width: min(100%, 900px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 12px calc(98px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 8px 0 10px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 10px 22px rgba(36, 129, 204, 0.22);
  flex: 0 0 auto;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
}

.brand strong {
  display: block;
  font-size: 17px;
  line-height: 1.15;
  font-weight: 760;
}

.brand small {
  display: block;
  max-width: 260px;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 40;
  width: min(calc(100% - 20px), 680px);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
  box-shadow: 0 14px 36px rgba(17, 24, 39, 0.14);
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
}

.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 50px;
  flex-direction: column;
  gap: 3px;
  border: 0;
  border-radius: 7px;
  padding: 6px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

.tab-btn.active {
  background: var(--blue-soft);
  color: var(--blue-2);
}

body.dark .tab-btn.active,
body[data-theme="dark"] .tab-btn.active {
  color: #7fc4ff;
}

.tab-btn svg,
.astra-icon,
.icon-btn svg,
.primary-btn svg,
.ghost-btn svg,
.danger-btn svg,
.pill-btn svg,
.quick-action svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.1;
}

.astra-icon {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.astra-icon .tone {
  fill: currentColor;
  opacity: 0.16;
}

.content {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page {
  display: grid;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  margin: 2px 0;
}

.section-title h1,
.section-title h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.18;
  font-weight: 780;
}

.section-title h2 {
  font-size: 16px;
}

.wallet-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
  box-shadow: 0 16px 34px rgba(36, 129, 204, 0.24);
}

.wallet-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.wallet-eyebrow {
  display: block;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 700;
}

.wallet-balance {
  display: block;
  margin-top: 4px;
  font-size: clamp(28px, 6vw, 42px);
  line-height: 1.05;
  font-weight: 820;
  overflow-wrap: anywhere;
}

.wallet-caption {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

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

.wallet-stat {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.wallet-stat span {
  display: block;
  color: rgba(255, 255, 255, 0.76);
  font-size: 11px;
  font-weight: 700;
}

.wallet-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

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

.quick-action {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 740;
  text-align: center;
}

.quick-action .action-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue-2);
}

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

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric.blue {
  background: var(--blue-soft);
  border-color: color-mix(in srgb, var(--blue) 28%, var(--line));
}

.metric.green {
  background: var(--green-soft);
  border-color: color-mix(in srgb, var(--green) 28%, var(--line));
}

.metric.amber {
  background: var(--amber-soft);
  border-color: color-mix(in srgb, var(--amber) 28%, var(--line));
}

.metric.red {
  background: var(--red-soft);
  border-color: color-mix(in srgb, var(--red) 28%, var(--line));
}

.panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 170px;
}

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

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

.list {
  display: grid;
  gap: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.item-row.compact {
  grid-template-columns: minmax(0, 1fr);
}

.item-main {
  min-width: 0;
}

.item-main strong {
  display: block;
  font-size: 15px;
  line-height: 1.22;
  font-weight: 760;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-main small,
.item-meta-line {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.money-stack {
  min-width: 122px;
  display: grid;
  gap: 2px;
  justify-items: end;
  color: var(--muted);
  font-size: 12px;
}

.money-stack strong {
  color: var(--text);
  font-size: 15px;
}

.money-stack .positive {
  color: var(--green);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chip.blue {
  background: var(--blue-soft);
  color: var(--blue-2);
}

.chip.green {
  background: var(--green-soft);
  color: var(--green);
}

.chip.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.chip.red {
  background: var(--red-soft);
  color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: color-mix(in srgb, var(--surface) 88%, var(--bg));
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

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

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.span-2 {
  grid-column: span 2;
}

.form-submit {
  display: flex;
  align-items: end;
}

.form-submit .primary-btn {
  width: 100%;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.pill-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.primary-btn {
  background: var(--blue);
  color: var(--tg-theme-button-text-color, #ffffff);
}

.ghost-btn,
.pill-btn {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}

.danger-btn {
  background: var(--red-soft);
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 28%, var(--line));
}

.icon-btn {
  width: 38px;
  flex: 0 0 auto;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.pill-btn.active {
  background: var(--blue-soft);
  color: var(--blue-2);
  border-color: color-mix(in srgb, var(--blue) 34%, var(--line));
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.mini-table th,
.mini-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.mini-table th {
  color: var(--muted);
  font-weight: 750;
}

.mini-table td:last-child,
.mini-table th:last-child {
  text-align: right;
}

.state-screen {
  min-height: 60vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
}

.state-screen h1 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.state-screen p {
  width: min(100%, 360px);
  margin: 0;
}

.lock-screen {
  min-height: calc(100vh - 130px);
}

.lock-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  border: 1px solid color-mix(in srgb, var(--blue) 28%, var(--line));
}

.lock-mark svg {
  width: 26px;
  height: 26px;
}

.lock-form {
  width: min(100%, 360px);
  display: grid;
  gap: 10px;
}

.lock-passkey {
  width: min(100%, 360px);
  display: grid;
  gap: 8px;
}

.security-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.security-tile {
  min-width: 0;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 84%, var(--bg));
}

.security-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.security-tile strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.security-actions {
  margin-top: 10px;
}

.loader {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-radius: 50%;
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 18px 12px calc(18px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(100%, 720px);
  max-height: min(88vh, 820px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-head {
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.modal-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.preview-cell {
  min-width: 0;
}

.preview-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.preview-cell strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.toast-host {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 80;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
}

.empty {
  padding: 22px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.prebox {
  max-height: 360px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 82%, var(--bg));
  font-family: "SF Mono", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

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

.money-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.money-line:last-child {
  border-bottom: 0;
}

@media (max-width: 760px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

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

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

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

  .item-actions {
    justify-content: flex-start;
  }

  .money-stack {
    justify-items: start;
  }

  .mini-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .app {
    padding-top: 6px;
  }

  .brand small {
    max-width: 170px;
  }

  .wallet-card {
    padding: 14px;
  }

  .wallet-top {
    display: grid;
    gap: 6px;
  }

  .wallet-caption {
    white-space: normal;
  }

  .wallet-stats,
  .metrics,
  .grid-3,
  .modal-preview {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .quick-action {
    min-height: 66px;
    font-size: 11px;
  }

  .quick-action .action-icon {
    width: 30px;
    height: 30px;
  }

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

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

  .span-2 {
    grid-column: span 1;
  }

  .toolbar input,
  .toolbar select {
    min-width: 100%;
  }

  .tabs {
    width: calc(100% - 16px);
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .tab-btn {
    min-height: 48px;
    font-size: 10px;
  }
}
