/* === Balance Mini App — style === */
:root {
  --bg: var(--tg-theme-bg-color, #f4f4f7);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --text2: var(--tg-theme-hint-color, #6c6c70);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --success: #34c759;
  --danger: #ff3b30;
  --warn: #ff9500;
  --border: #e5e5ea;
  --input-bg: #f2f2f7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  padding-bottom: 40px;
}

/* Block overlay — khi không mở từ Telegram */
.block-overlay {
  position: fixed; inset: 0;
  background: #1c1c1e;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  z-index: 9999;
}
.block-overlay[hidden] { display: none; }
.block-icon { font-size: 56px; }
.block-overlay h2 { margin: 12px 0 6px; }
.block-desc { color: #999; font-size: 14px; line-height: 1.5; }

.app[hidden] { display: none; }

/* Header */
.tg-header {
  background: var(--card);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.tg-back {
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
}
.tg-title { flex: 1; font-weight: 600; font-size: 17px; }
.tg-title small { display: block; color: var(--text2); font-weight: 500; font-size: 14px; margin-top: 2px; }

/* User card */
.user-card {
  background: linear-gradient(135deg, var(--accent) 0%, #1f8dd9 100%);
  color: #fff;
  padding: 16px;
  margin: 14px 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(31,141,217,0.22);
  position: relative;
}
.user-name { font-size: 15px; font-weight: 600; opacity: 0.95; }
.user-fund { font-size: 26px; font-weight: 700; margin-top: 4px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.25); }
.user-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; opacity: 0.9; }
.btn-deposit-fund {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(255,255,255,0.25);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.5);
  padding: 10px 16px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  font-family: inherit;
  backdrop-filter: blur(10px);
  -webkit-appearance: none;
  appearance: none;
  z-index: 3;
  min-height: 38px;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn-deposit-fund > * { pointer-events: none; }
.btn-deposit-fund:active { transform: scale(0.95); background: rgba(255,255,255,0.4); }

/* Tabs (wrap 2 hàng nếu hẹp) */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--card);
  margin: 0 12px 14px;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid var(--border);
}
.tab {
  flex: 1 1 30%;
  min-width: 88px;
  padding: 12px 10px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  border-radius: 7px;
  transition: all 0.15s;
  border: none;
  background: transparent;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.tab.active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

/* Card */
.card {
  background: var(--card);
  margin: 0 12px 14px;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 10px 0; }
.card-hint { font-size: 12px; color: var(--text2); margin: 0 0 10px 0; line-height: 1.4; }

/* Inputs */
.input {
  background: var(--input-bg);
  border: 1.5px solid rgba(46,166,255,0.35);
  border-radius: 9px;
  padding: 11px 12px;
  font-size: 15px;
  width: 100%;
  outline: none;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.input:focus { border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px rgba(46,166,255,0.15); }
.input-cid { font-family: "SF Mono", Menlo, monospace; letter-spacing: 0.5px; }

/* Textarea paste + nút Dán */
.paste-area { min-height: 120px; padding-right: 76px; font-family: "SF Mono", Menlo, monospace; font-size: 13px; resize: vertical; }
.textarea-wrap { position: relative; }
.textarea-wrap .btn-pill { position: absolute; top: 8px; right: 8px; }

.btn-pill {
  border: 1px solid var(--accent);
  background: rgba(255,255,255,0.9);
  color: var(--accent);
  padding: 5px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  backdrop-filter: blur(4px);
}
.btn-pill:active { transform: scale(0.95); }

/* Preview list */
.parse-preview {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: none;
  max-height: 240px;
  overflow-y: auto;
}
.parse-preview.show { display: block; }
.parse-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 2px;
  font-size: 13px;
  border-bottom: 1px solid #f2f2f5;
  gap: 10px;
}
.parse-row:last-child { border-bottom: none; }
.pr-cid { font-family: "SF Mono", Menlo, monospace; }
.pr-amt { font-family: "SF Mono", Menlo, monospace; font-weight: 600; color: var(--text); }
.pr-amt.err { font-family: inherit; color: var(--danger); font-weight: 500; font-size: 12px; }

/* Summary */
.summary {
  background: #f8f8fa;
  border-radius: 9px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 13px;
}
.summary-row { display: flex; justify-content: space-between; margin: 3px 0; }
.summary-row.total { font-weight: 700; font-size: 15px; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }

/* Error banner */
.error-banner {
  background: #ffecec;
  border-left: 3px solid var(--danger);
  color: var(--danger);
  padding: 8px 10px;
  border-radius: 8px;
  margin: 8px 0;
  font-size: 13px;
  font-weight: 500;
  display: none;
  line-height: 1.5;
}
.error-banner.show { display: block; }

/* Main button */
.btn-main {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 13px;
  border-radius: 10px;
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  margin-top: 10px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(46,166,255,0.3);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.btn-main:active { transform: translateY(1px); }
.btn-main.red { background: var(--danger); box-shadow: 0 2px 6px rgba(255,59,48,0.3); }
.btn-main.green { background: var(--success); box-shadow: 0 2px 6px rgba(52,199,89,0.3); }
.btn-main:disabled {
  background: #c7c7cc !important;
  box-shadow: none !important;
  cursor: not-allowed;
  opacity: 0.7;
}

/* Balance list */
.balance-list { margin-top: 12px; border-top: 1px solid var(--border); }
.balance-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 10px;
}
.bl-cid { font-family: "SF Mono", Menlo, monospace; }
.bl-val { font-weight: 600; font-family: "SF Mono", Menlo, monospace; }
.bl-val.ok { color: var(--success); }
.bl-val.bad { color: var(--danger); font-size: 12px; font-weight: 500; font-family: inherit; }

/* Views */
.view { display: none; }
.view.active { display: block; }

/* Mode buttons (chuyển tiền) */
.mode-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px;
}
.mode-btn {
  flex: 1 1 calc(50% - 3px);
  min-width: 120px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  transition: all 0.15s;
}
.mode-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(46,166,255,0.25);
}
.mode-info { margin-top: 4px; }
.mode-info .lbl {
  font-size: 12px;
  color: var(--text2);
  margin: 10px 0 4px;
  font-weight: 500;
}
.mode-info .input { margin-bottom: 2px; }
.mode-info .arrow-down {
  text-align: center;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  margin: 10px 0;
  letter-spacing: 1px;
}
.mode-note {
  font-size: 11px;
  color: var(--text2);
  margin: 8px 0 0;
  padding: 7px 10px;
  background: #f8f8fa;
  border-radius: 7px;
  line-height: 1.4;
}

/* Wallet carousel */
.carousel-wrap { position: relative; }
.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-size: 22px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  z-index: 2;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.carousel-nav.prev { left: -4px; }
.carousel-nav.next { right: -4px; }
.carousel-nav:active { transform: translateY(-50%) scale(0.9); }
.carousel-nav:disabled { opacity: 0.3; cursor: not-allowed; }
.wallet-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  margin: 0 -14px 6px;
  padding: 0 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.wallet-carousel::-webkit-scrollbar { display: none; }
.wallet-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  background: linear-gradient(180deg, #fff8e1 0%, #fef7e0 100%);
  border: 1px solid #f2d48a;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin-right: 8px;
}
.wallet-slide:last-child { margin-right: 0; }
.wallet-label { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.wallet-qr {
  width: 100%;
  max-width: 240px;
  height: auto;
  background: #fff;
  padding: 6px;
  border-radius: 8px;
  margin: 4px auto;
  display: block;
  object-fit: contain;
}
.wallet-addr {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  margin: 8px 6px 4px;
  word-break: break-all;
  background: rgba(255,255,255,0.6);
  padding: 6px 8px;
  border-radius: 6px;
}
.wallet-copy {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 7px 14px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.wallet-copy:active { transform: scale(0.95); }
.wallet-note { font-size: 11px; color: var(--text2); margin-top: 6px; }
.wallet-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 4px 0 0;
}
.wallet-dots .dot {
  width: 6px; height: 6px;
  background: var(--border);
  border-radius: 50%;
  transition: all 0.2s;
}
.wallet-dots .dot.active {
  background: var(--accent);
  width: 18px;
  border-radius: 3px;
}

/* Loading state */
.loader {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}
.loader-spin {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1c1e;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  max-width: 85%;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Responsive: desktop preview */
@media (min-width: 520px) {
  body { max-width: 480px; margin: 0 auto; }
}
