/* CryptoTrader Mini App — dark graphite, Telegram theme aware, mobile first. */

:root {
  --bg: #16181d;
  --surface: #1e2128;
  --surface-2: #242832;
  --border: #2c313c;
  --text: #e8eaf0;
  --muted: #9aa1ad;
  --green: #3ddc84;
  --green-dim: rgba(61, 220, 132, 0.14);
  --yellow: #f5c542;
  --yellow-dim: rgba(245, 197, 66, 0.14);
  --red: #ff5c5c;
  --red-dim: rgba(255, 92, 92, 0.14);
  --accent: #5aa2ff;
  --radius: 14px;
  --pad: 14px;
}

body {
  margin: 0;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--tg-theme-hint-color, var(--muted)); font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar {
  padding: calc(env(safe-area-inset-top, 0px) + 12px) var(--pad) 10px;
  background: var(--tg-theme-secondary-bg-color, var(--surface));
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.2px; }
.top-flags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.top-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.top-meta .muted { margin-left: auto; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.3px;
}
.badge-paper { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }

.flag {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.4px;
  padding: 3px 8px; border-radius: 6px;
}
.flag-off { background: var(--green-dim); color: var(--green); }
.flag-blocked { background: var(--red-dim); color: var(--red); }

.icon-btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  width: 34px; height: 30px; font-size: 16px; cursor: pointer;
}
.icon-btn.spin { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px var(--pad);
  background: var(--tg-theme-secondary-bg-color, var(--surface));
  border-bottom: 1px solid var(--border);
  scrollbar-width: none; position: sticky; top: 0; z-index: 4;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 999px;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; font-size: 13px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- layout / cards ---------- */
main { padding: 12px var(--pad) 24px; max-width: 560px; margin: 0 auto; }
.card {
  background: var(--tg-theme-secondary-bg-color, var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--pad); margin-bottom: 10px;
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card h3 {
  margin: 0 0 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric .k { font-size: 11.5px; color: var(--muted); }
.metric .v { font-size: 21px; font-weight: 700; margin-top: 2px; }
.metric .v.small { font-size: 16px; }
.up { color: var(--green); } .down { color: var(--red); } .warn { color: var(--yellow); }

.row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 14px; }
.row .k { color: var(--muted); }
.row .v { text-align: right; font-weight: 600; }

.kv-list { margin: 0; }

/* ---------- skeleton / error ---------- */
.skel { position: relative; overflow: hidden; min-height: 64px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skel-hero { min-height: 110px; }

.error { border-color: var(--red); }
.err-title { font-weight: 700; color: var(--red); margin-bottom: 6px; }

/* ---------- controls ---------- */
.btn {
  display: inline-block; padding: 10px 18px; margin-top: 10px;
  border-radius: 11px; border: none; font-size: 14px; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn-danger { background: var(--red); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: default; }

.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.switch {
  position: relative; width: 44px; height: 26px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer;
  transition: background 0.15s;
}
.switch.on { background: var(--green-dim); border-color: var(--green); }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.switch.on::after { transform: translateX(18px); background: var(--green); }

/* ---------- sheet / toast ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  width: 100%; max-width: 532px;
  background: var(--tg-theme-secondary-bg-color, var(--surface));
  border-radius: 18px 18px 0 0; padding: 20px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 18px);
  animation: slide-up 0.2s ease-out;
}
@keyframes slide-up { from { transform: translateY(40px); opacity: 0.4; } }
.sheet-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; margin-top: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 16px; font-size: 13.5px; z-index: 30; max-width: 86vw;
  animation: rise 0.2s ease-out;
}
.toast.ok { border-color: var(--green); }
.toast.fail { border-color: var(--red); }

.foot {
  text-align: center; padding: 14px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--border);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
}
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 13.5px; }

/* ---------- CSP-friendly helpers (no inline styles from app.js) ---------- */
.note-top { margin-top: 8px; }
.strong { font-weight: 600; }
.btn-gap { margin-left: 8px; }
