* {
  box-sizing: border-box;
}

:root {
  --bg: var(--tg-theme-bg-color, #f5f7fa);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-2: #eef2f6;
  --text: var(--tg-theme-text-color, #17202a);
  --muted: var(--tg-theme-hint-color, #6b7480);
  --accent: var(--tg-theme-button-color, #2377ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(23, 32, 42, 0.1);
  --shadow: 0 10px 24px rgba(23, 32, 42, 0.08);
  --green: #16834a;
  --green-bg: #e8f6ee;
  --red: #c53030;
  --red-bg: #fdecec;
  --amber: #9a6700;
  --amber-bg: #fff5d8;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(35, 119, 255, 0.08), transparent 210px),
    var(--bg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 800;
}

h2 {
  font-size: 20px;
  font-weight: 820;
}

h3 {
  font-size: 15px;
  font-weight: 780;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.eyebrow,
.label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.balance-pill {
  display: grid;
  gap: 1px;
  min-width: 118px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
  box-shadow: var(--shadow);
}

.balance-pill strong {
  font-size: 14px;
}

main {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 14px;
  padding-bottom: 108px;
}

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

.account-summary > div,
.balance-card,
.panel,
.list-card,
.notice,
.empty-state,
.checkout-panel,
.product-detail {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-summary > div,
.balance-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
}

.account-summary strong,
.balance-card strong {
  overflow-wrap: anywhere;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.notice {
  padding: 12px;
  border-color: #f0c36d;
  background: #fff7df;
  color: #6d4b00;
  font-weight: 650;
}

.tabs {
  position: sticky;
  top: 72px;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin: 12px 0 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
}

.tabs button {
  min-height: 38px;
  padding: 8px 6px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  box-shadow: none;
}

.tabs button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 12px;
}

.searchbar {
  margin-bottom: 10px;
}

.filter-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-size: 13px;
}

.chip.secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

.product-list,
.stack {
  display: grid;
  gap: 10px;
}

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

.mini-product {
  display: grid;
  gap: 4px;
  min-height: 92px;
  padding: 10px;
  text-align: left;
}

.mini-product span {
  font-size: 22px;
}

.mini-product strong,
.mini-product small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-product small {
  color: var(--muted);
}

.product {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  box-shadow: var(--shadow);
}

.product[disabled] {
  opacity: 0.55;
}

.product-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 26px;
}

.product-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.title {
  overflow: hidden;
  font-weight: 780;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price {
  color: var(--accent);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.stock-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--green-bg);
  color: var(--green);
  font-size: 12px;
  font-weight: 780;
  white-space: nowrap;
}

.stock-badge.empty,
.status-pill.danger {
  background: var(--red-bg);
  color: var(--red);
}

.status-pill.ok {
  background: var(--green-bg);
  color: var(--green);
}

.panel,
.list-card,
.empty-state {
  padding: 14px;
}

.list-card {
  width: 100%;
  color: inherit;
  text-align: left;
}

.product-detail {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  margin-bottom: 10px;
}

.product-detail .status-pill {
  grid-column: 1 / -1;
  width: max-content;
}

.checkout-panel {
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 18px 14px;
  text-align: center;
}

.payment-instructions {
  display: grid;
  width: 100%;
  gap: 6px;
  justify-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.payment-instructions span {
  color: var(--muted);
  font-size: 12px;
}

.qr-frame {
  width: min(360px, 100%);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

img {
  display: block;
  width: 100%;
  border-radius: 6px;
}

.payment-status {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 13px;
  font-weight: 700;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar,
.actions,
.amount-grid {
  display: grid;
  gap: 8px;
}

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

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

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.stepper button {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.stepper span {
  min-width: 42px;
  font-weight: 820;
  text-align: center;
}

.sticky-action {
  position: fixed;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 14px;
  z-index: 12;
  display: grid;
  gap: 8px;
  width: min(692px, calc(100% - 28px));
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(23, 32, 42, 0.16);
}

input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
}

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

input:focus,
textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 800;
}

button:active {
  transform: scale(0.985);
}

button[disabled] {
  opacity: 0.5;
}

.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.icon-button {
  width: 44px;
  padding: 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

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

.success {
  color: var(--green);
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

pre,
.account-content {
  width: 100%;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: left;
  user-select: all;
}

.account-content,
.copy-code,
.tiny-code {
  border-radius: 8px;
  background: var(--surface-2);
}

.account-content {
  padding: 12px;
  border: 1px solid var(--border);
}

.copy-code,
.tiny-code {
  display: inline-block;
  max-width: 100%;
  padding: 7px 9px;
  overflow-wrap: anywhere;
  user-select: all;
}

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

  main {
    padding: 10px;
    padding-bottom: 108px;
  }

  .app-header {
    padding: 12px;
  }

  .tabs {
    top: 66px;
  }

  .tabs button {
    font-size: 12px;
    padding-inline: 4px;
  }

  .product {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .product .stock-badge {
    grid-column: 2;
    width: max-content;
  }
}
