:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --radius: 14px;
  --green: #2eaf5f;
  --red: #e0533d;
}

* { 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: 16px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

#view {
  flex: 1;
  padding: 12px 14px calc(80px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* ─── Tab bar ─────────────────────────────────────────── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 22%, transparent);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.tab {
  flex: 1; border: 0; background: none; color: var(--hint);
  padding: 8px 0 7px; font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: color .15s;
}
.tab .ico { font-size: 21px; line-height: 1; filter: grayscale(.4); opacity: .75; }
.tab.active { color: var(--link); }
.tab.active .ico { filter: none; opacity: 1; }

/* ─── Generic ─────────────────────────────────────────── */
.center { text-align: center; padding: 40px 16px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.h1 { font-size: 20px; font-weight: 700; margin: 4px 0 14px; }
.section-title { font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .4px; margin: 18px 4px 8px; }
.spacer { height: 10px; }
.hidden { display: none !important; }

/* ─── Cards ───────────────────────────────────────────── */
.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card.tappable:active { transform: scale(.985); }
.card.tappable { transition: transform .08s; cursor: pointer; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row + .row { margin-top: 6px; }
.col { display: flex; flex-direction: column; gap: 2px; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px;
}
.badge.sell { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.badge.buy  { background: color-mix(in srgb, var(--link) 16%, transparent); color: var(--link); }
.badge.status { background: color-mix(in srgb, var(--hint) 18%, transparent); color: var(--hint); }
.badge.status.active { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.badge.status.warn { background: color-mix(in srgb, #f0a020 20%, transparent); color: #c8821a; }
.badge.status.bad  { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }

.amount { font-size: 19px; font-weight: 700; }
.price { color: var(--hint); font-size: 14px; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-bottom: 1px solid color-mix(in srgb, var(--hint) 12%, transparent); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--hint); }
.kv .v { font-weight: 600; text-align: right; }
.creator { display: flex; align-items: center; gap: 6px; color: var(--hint); font-size: 13px; margin-top: 8px; }
.comment { margin-top: 8px; font-size: 14px; color: var(--text); opacity: .85; word-break: break-word; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }

/* ─── Filters ─────────────────────────────────────────── */
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: flex; background: var(--secondary-bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--hint); padding: 6px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ─── Forms ───────────────────────────────────────────── */
label.field { display: block; margin: 14px 2px 6px; font-size: 14px; color: var(--hint); }
input, select, textarea {
  width: 100%; padding: 13px 14px; font-size: 16px;
  background: var(--secondary-bg); color: var(--text);
  border: 1px solid transparent; border-radius: 12px; outline: none;
  font-family: inherit;
}
input:focus, textarea:focus { border-color: var(--link); }
textarea { resize: vertical; min-height: 70px; }
.hint-text { font-size: 12px; color: var(--hint); margin: 6px 2px 0; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  display: block; width: 100%; text-align: center;
  padding: 14px; border: 0; border-radius: 12px; font-size: 16px; font-weight: 600;
  cursor: pointer; margin-top: 12px;
}
.btn.primary { background: var(--button); color: var(--button-text); }
.btn.secondary { background: var(--secondary-bg); color: var(--link); }
.btn.danger { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.btn.ghost { background: none; color: var(--link); }
.btn:active { opacity: .85; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 12px; }

/* ─── Timeline ────────────────────────────────────────── */
.timeline { margin-top: 10px; padding-left: 6px; }
.tl-item { position: relative; padding: 0 0 14px 18px; border-left: 2px solid color-mix(in srgb, var(--hint) 25%, transparent); }
.tl-item:last-child { border-left-color: transparent; }
.tl-item::before { content: ""; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--link); }
.tl-item .t { font-size: 12px; color: var(--hint); }
.tl-item .s { font-weight: 600; font-size: 14px; }

/* ─── Banner / notice ─────────────────────────────────── */
.notice { background: color-mix(in srgb, var(--link) 10%, transparent); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }
.notice.warn { background: color-mix(in srgb, #f0a020 14%, transparent); }

/* ─── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #303030; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; max-width: 88%; text-align: center; z-index: 100;
  box-shadow: 0 6px 22px rgba(0,0,0,.3);
}
.toast.err { background: var(--red); }

/* ─── Skeleton / empty ────────────────────────────────── */
.empty { text-align: center; padding: 50px 20px; color: var(--hint); }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.pager { display: flex; justify-content: center; gap: 14px; align-items: center; margin: 14px 0 4px; color: var(--hint); }
.pager button { background: var(--secondary-bg); border: 0; color: var(--text); width: 40px; height: 36px; border-radius: 9px; font-size: 16px; cursor: pointer; }
.pager button:disabled { opacity: .4; }

/* ─── Review stars ─────────────────────────────────────── */
.stars { display: flex; gap: 6px; margin: 4px 0 10px; }
.star {
  background: var(--secondary-bg); border: 0; border-radius: 10px;
  width: 48px; height: 44px; font-size: 22px; color: var(--hint); cursor: pointer;
}
.star.on { color: #f5a623; }
