:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #4da3ff);
  --button: var(--tg-theme-button-color, #2ea6ff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: rgba(255, 255, 255, 0.08);
  --card: var(--bg-secondary);
  --up: #16c784;
  --down: #f6465d;
  --radius: 16px;
  --safe-top: max(env(safe-area-inset-top), 8px);
  --safe-bottom: max(env(safe-area-inset-bottom), 8px);

  /* Bảng màu phân loại (categorical) — thứ tự cố định, không tự sinh thêm màu.
     8 hue theo palette đã validate CVD; slot 9 + "Khác" dùng 2 sắc xám trung tính
     khác độ sáng (2 slice ít quan trọng nhất, luôn có legend chữ đi kèm để nhận diện). */
  --pie-1: #3987e5; --pie-2: #d95926; --pie-3: #199e70; --pie-4: #c98500;
  --pie-5: #d55181; --pie-6: #008300; --pie-7: #9085e9; --pie-8: #e66767;
  --pie-9: #7d7b74; --pie-other: #c7c5bb;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--tg-theme-bg-color, #f5f6f8);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #16181c);
    --hint: var(--tg-theme-hint-color, #6d7278);
    --separator: rgba(0, 0, 0, 0.08);
    --pie-1: #2a78d6; --pie-2: #eb6834; --pie-3: #1baf7a; --pie-4: #eda100;
    --pie-5: #e87ba4; --pie-6: #008300; --pie-7: #4a3aa7; --pie-8: #e34948;
    --pie-9: #8f8d86; --pie-other: #cac8be;
  }
}

/* Telegram cấp bg/text/hint/button qua themeParams (áp bằng JS), nhưng không có
   bảng màu phân loại — nên bộ --pie-* tự chọn theo tg.colorScheme (đặt qua
   data-theme ở app.js) thay vì prefers-color-scheme, để không bao giờ lệch với
   theme thật của Telegram. */
:root[data-theme="dark"] {
  --pie-1: #3987e5; --pie-2: #d95926; --pie-3: #199e70; --pie-4: #c98500;
  --pie-5: #d55181; --pie-6: #008300; --pie-7: #9085e9; --pie-8: #e66767;
  --pie-9: #7d7b74; --pie-other: #c7c5bb;
}
:root[data-theme="light"] {
  --pie-1: #2a78d6; --pie-2: #eb6834; --pie-3: #1baf7a; --pie-4: #eda100;
  --pie-5: #e87ba4; --pie-6: #008300; --pie-7: #4a3aa7; --pie-8: #e34948;
  --pie-9: #8f8d86; --pie-other: #cac8be;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }

.full-message {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 8px;
}
.full-message-icon { font-size: 40px; margin-bottom: 8px; }
.full-message-title { font-size: 17px; font-weight: 600; }
.full-message-text { color: var(--hint); font-size: 14px; max-width: 280px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 16px 10px;
  background: var(--bg);
}
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--button), #7c5cff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.hello { font-weight: 600; font-size: 15px; line-height: 1.3; }
.asof { color: var(--hint); font-size: 12px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: var(--bg-secondary); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s ease;
}
.icon-btn:active { transform: scale(0.9) rotate(90deg); }
.icon-btn.spinning svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.content { padding: 0 16px calc(var(--safe-bottom) + 24px); }

.hero-card {
  background: linear-gradient(160deg, var(--bg-secondary), var(--bg-secondary) 60%, rgba(46,166,255,0.08));
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.hero-label { color: var(--hint); font-size: 13px; margin-bottom: 6px; }
.hero-value { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.hero-chips { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 100px;
  background: rgba(255,255,255,0.06); color: var(--hint);
}
.chip.up { color: var(--up); background: rgba(22,199,132,0.14); }
.chip.down { color: var(--down); background: rgba(246,70,93,0.14); }

.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
}
.stat-label { color: var(--hint); font-size: 12.5px; margin-bottom: 6px; }
.stat-value { font-size: 16.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-value.up { color: var(--up); }
.stat-value.down { color: var(--down); }

.chart-card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; font-weight: 600; }
.range-picker { display: flex; gap: 4px; background: rgba(255,255,255,0.05); border-radius: 100px; padding: 3px; }
.range-picker button {
  border: none; background: transparent; color: var(--hint); font-size: 11.5px; font-weight: 600;
  padding: 5px 9px; border-radius: 100px;
}
.range-picker button.active { background: var(--button); color: var(--button-text); }
.chart-box { height: 180px; }
.chart-empty { color: var(--hint); font-size: 13px; text-align: center; padding: 40px 0; }

.tabs {
  display: flex; gap: 4px; margin-bottom: 12px; background: var(--card);
  border-radius: 100px; padding: 4px; position: sticky; top: 58px; z-index: 9;
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--hint);
  font-size: 12px; font-weight: 600; padding: 9px 0; border-radius: 100px;
  white-space: nowrap;
}
.tab.active { background: var(--button); color: var(--button-text); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-title { font-size: 14px; font-weight: 600; margin: 18px 0 10px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.card-row {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-left { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-symbol-row { display: flex; align-items: center; gap: 6px; }
.card-symbol { font-weight: 700; font-size: 15px; }
.card-tag {
  font-size: 10.5px; color: var(--hint); background: rgba(255,255,255,0.06);
  padding: 2px 6px; border-radius: 6px; font-weight: 600;
}
.card-sub { color: var(--hint); font-size: 12.5px; }
.card-right { text-align: right; flex-shrink: 0; }
.card-value { font-weight: 600; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.card-pct { font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.card-pct.up, .card-value.up { color: var(--up); }
.card-pct.down, .card-value.down { color: var(--down); }

.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px;
  font-size: 13.5px; color: var(--hint);
}
.summary-row span:last-child { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }

.empty {
  text-align: center; color: var(--hint); font-size: 13.5px; padding: 36px 16px; line-height: 1.6;
}
.empty code {
  background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 5px; font-size: 12.5px;
}

/* Donut / pie — phân bổ theo mã & theo tài khoản */
.donut-card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.donut-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.donut-body { display: flex; align-items: center; gap: 16px; }
.donut-ring {
  width: 116px; height: 116px; border-radius: 50%; flex-shrink: 0; position: relative;
}
.donut-hole {
  position: absolute; inset: 20%; border-radius: 50%; background: var(--card);
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.donut-hole-value { font-size: 12.5px; font-weight: 700; line-height: 1.25; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.legend-row { font-size: 12.5px; min-width: 0; }
.legend-row-head { display: flex; align-items: center; gap: 7px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 600; }
.legend-value { color: var(--hint); font-variant-numeric: tabular-nums; margin-left: 16px; }
.donut-empty { color: var(--hint); font-size: 13px; text-align: center; padding: 20px 0; }

/* Bộ lọc khoảng thời gian cho bảng lịch sử */
.filter-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
.filter-bar input[type="date"] {
  background: var(--card); color: var(--text); border: 1px solid var(--separator);
  border-radius: 10px; padding: 7px 8px; font-size: 12.5px; flex: 1; min-width: 118px;
  font-family: inherit; color-scheme: dark;
}
@media (prefers-color-scheme: light) { .filter-bar input[type="date"] { color-scheme: light; } }
.filter-bar span { color: var(--hint); font-size: 12.5px; }
.btn-ghost, .btn-export {
  border: none; border-radius: 10px; padding: 7px 12px; font-size: 12.5px; font-weight: 600;
  flex-shrink: 0;
}
.btn-ghost { background: var(--card); color: var(--text); }
.btn-export { background: var(--button); color: var(--button-text); display: flex; align-items: center; gap: 5px; }
.btn-export:disabled { opacity: 0.5; }

.txn-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.txn-type-badge {
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; flex-shrink: 0;
}
.txn-type-badge.buy, .txn-type-badge.deposit { background: rgba(22,199,132,0.14); color: var(--up); }
.txn-type-badge.sell, .txn-type-badge.withdraw { background: rgba(246,70,93,0.14); color: var(--down); }
.txn-type-badge.div { background: rgba(46,166,255,0.14); color: var(--link); }
.txn-type-badge.margin { background: rgba(237,161,0,0.16); color: #eda100; }

.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.09) 37%, rgba(255,255,255,0.04) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
