:root {
  --bg: var(--tg-theme-bg-color, #0e1621);
  --card: var(--tg-theme-secondary-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --hint: var(--tg-theme-hint-color, #8b9aa7);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --btn: var(--tg-theme-button-color, #2aabee);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --ok: #1aa36a;
  --warn: #c4921a;
  --bad: #d14b4b;
  --stroke: color-mix(in srgb, var(--text) 12%, transparent);
  --surface: color-mix(in srgb, var(--text) 6%, var(--card));
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: calc(72px + var(--safe-bottom));
  --chart-bid: var(--ok);
  --chart-ask: var(--btn);
  --chart-grid: color-mix(in srgb, var(--text) 12%, transparent);
  --chart-text: var(--hint);
  --chart-empty: var(--hint);
}

html { color-scheme: dark light; }
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; padding-bottom: var(--tab-h); }

.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;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}
.load-bar {
  position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: transparent; overflow: hidden; pointer-events: none;
}
.topbar.is-loading .load-bar::after {
  content: ""; display: block; height: 100%; width: 40%;
  background: var(--btn);
  animation: load-slide 1s ease-in-out infinite;
}
@keyframes load-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(350%); }
}
.eyebrow { font-size: 11px; letter-spacing: 0.12em; color: var(--hint); font-weight: 700; }
h1 { margin: 2px 0 0; font-size: 20px; font-weight: 800; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; }
.icon-btn {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px; border-radius: 12px;
  background: var(--card); color: var(--text); font-size: 18px;
  display: grid; place-items: center;
}
.icon-btn svg { display: block; }
.hidden { display: none !important; }
.view { padding: 8px 16px 24px; display: grid; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 14px;
}
.card h2 { margin: 0 0 8px; font-size: 13px; color: var(--hint); letter-spacing: 0.06em; text-transform: uppercase; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row + .row { margin-top: 8px; }
.muted { color: var(--hint); }
.mono { font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.status-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--stroke);
  font-weight: 650;
}
.status-row .chev { margin-left: auto; color: var(--hint); }
.compact-summary {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 4px 2px 2px; font-size: 13px; color: var(--hint);
}

.hero {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.stat {
  background: var(--surface);
  border-radius: 12px; padding: 10px 12px;
}
.stat b { display: block; font-size: 20px; font-weight: 800; }
.stat span { color: var(--hint); font-size: 12px; }

.hero-price {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin: 10px 0 6px;
}
.hero-price .bid {
  font-size: 32px; font-weight: 800; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.hero-price .delta { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meta-grid { display: grid; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--hint); }

.list { display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 12px; border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--stroke);
  text-align: left; width: 100%; min-height: 44px;
}
.item .q {
  font-weight: 650; font-size: 14px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.item .meta { font-size: 12px; color: var(--hint); margin-top: 4px; }
.item .price { font-variant-numeric: tabular-nums; }
.item .delta {
  font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap; text-align: right;
}
.alert-item { grid-template-columns: 1fr; }
.alert-label { font-weight: 650; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 11px; padding: 4px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--link) 14%, transparent); color: var(--link);
}

.filters { display: flex; gap: 6px; overflow: auto; padding-bottom: 2px; }
.filters button, .seg button, .toggle {
  border: 1px solid var(--stroke); border-radius: 999px;
  min-height: 44px; padding: 8px 14px; background: var(--card); color: var(--hint); white-space: nowrap;
}
.filters button.on, .seg button.on, .toggle.on {
  background: var(--btn); color: var(--btn-text); border-color: transparent;
}

.search {
  width: 100%; border: 1px solid var(--stroke); border-radius: 12px;
  background: var(--card); padding: 12px; min-height: 44px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions button, .primary {
  flex: 1; min-width: 90px; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  background: var(--btn); color: var(--btn-text); font-weight: 700;
}
.actions .ghost { background: transparent; color: var(--link); border: 1px solid var(--stroke); }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { width: 100%; height: 220px; display: block; background: transparent; }
.chart-legend {
  display: flex; gap: 14px; align-items: center; margin: 8px 0 6px;
  font-size: 12px; color: var(--hint);
}
.chart-legend i {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px;
  vertical-align: -1px;
}
.chart-legend .bid i { background: var(--chart-bid); }
.chart-legend .ask i { background: var(--chart-ask); }
.chart-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; color: var(--chart-empty); font-size: 13px; padding: 16px;
}

.empty, .error, .banner {
  text-align: center; color: var(--hint); padding: 20px 12px;
}
.error-card { text-align: left; }
.error-card p { margin: 0 0 12px; color: var(--text); }
.banner { font-size: 13px; }

.skeleton { display: grid; gap: 8px; }
.skel {
  height: 18px; border-radius: 8px;
  background: color-mix(in srgb, var(--text) 8%, var(--card));
  animation: pulse 1.2s ease-in-out infinite;
}
.skel.line { height: 14px; width: 72%; }
.skel.row { height: 64px; }
.skel.hero { height: 72px; }
@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--stroke); min-height: 44px; }
.setting:last-child { border-bottom: 0; }
.switch {
  width: 48px; height: 28px; border-radius: 999px;
  background: color-mix(in srgb, var(--text) 22%, var(--card));
  position: relative; flex-shrink: 0;
}
.switch.on { background: var(--ok); }
.switch i { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--btn-text); transition: left .16s; }
.switch.on i { left: 25px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, var(--card));
  border-top: 1px solid var(--stroke);
  padding: 6px 6px var(--safe-bottom);
  max-width: 520px; margin: 0 auto;
}
.tabs button {
  display: grid; justify-items: center; gap: 2px;
  color: var(--hint); font-size: 11px; padding: 8px 0; min-height: 44px;
}
.tabs button svg { display: block; }
.tabs button span { font-weight: 650; }
.tabs button.on { color: var(--btn); }

.sending { margin: 10px 0 0; font-size: 13px; color: var(--hint); line-height: 1.4; }
.fold { border-bottom: 1px solid var(--stroke); padding: 2px 0; }
.fold:last-of-type { border-bottom: 0; }
.fold summary {
  min-height: 44px; display: flex; align-items: center; gap: 8px;
  font-weight: 650; cursor: pointer; list-style: none;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after {
  content: "›"; margin-left: auto; color: var(--hint); font-size: 18px; line-height: 1;
}
.fold[open] summary::after { transform: rotate(90deg); }
.fold > div { padding: 0 0 8px; }

.orig { font-size: 12px; color: var(--hint); margin-top: 6px; }
.pager { display: flex; justify-content: space-between; align-items: center; color: var(--hint); font-size: 13px; gap: 8px; }
.pager button { min-height: 44px; min-width: 44px; padding: 8px 12px; color: var(--link); }

@media (max-width: 360px) {
  .hero { grid-template-columns: 1fr; }
  h1 { font-size: 18px; }
  .hero-price .bid { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .topbar.is-loading .load-bar { background: var(--btn); }
  .topbar.is-loading .load-bar::after { display: none; }
}
