/* The account page. Phone first: one column, the tabs at the bottom where a
   thumb reaches them. A tablet (640px and up) moves the tabs under the header;
   a computer (1024px and up) puts the header and the tabs in a sidebar and lets
   the cards sit side by side. Inside Telegram the colours are Telegram's own
   (app.js sets these tokens from its theme). */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eceff4;
  --text: #16202c;
  --muted: #5b6877;
  --line: #dce2e9;
  --accent: #2458d6;
  --accent-text: #ffffff;
  --link: #2458d6;
  --ok: #1d7a49;
  --ok-bg: #e3f4ea;
  --warn: #8f5600;
  --warn-bg: #fdf1dc;
  --info-bg: #e7eefc;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 2px 8px rgba(15, 23, 42, 0.05);
  --tabs-h: 64px;
  --gutter: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b;
    --surface: #17202a;
    --surface-2: #1f2a36;
    --text: #e8edf3;
    --muted: #97a4b3;
    --line: #2a3643;
    --accent: #5b8cff;
    --accent-text: #0b1220;
    --link: #7aa2ff;
    --ok: #57c48a;
    --ok-bg: #173226;
    --warn: #f0b35a;
    --warn-bg: #3a2a12;
    --info-bg: #1b2a44;
    --bad: #ff8a80;
    --bad-bg: #3d1c1a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --surface: #17202a; --surface-2: #1f2a36; --text: #e8edf3; --muted: #97a4b3;
  --line: #2a3643; --accent: #5b8cff; --accent-text: #0b1220; --link: #7aa2ff; --ok: #57c48a;
  --ok-bg: #173226; --warn: #f0b35a; --warn-bg: #3a2a12; --info-bg: #1b2a44; --bad: #ff8a80;
  --bad-bg: #3d1c1a; --shadow: none; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; }
a { color: var(--link); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ shell */
.shell { min-height: 100dvh; }
.side { display: contents; }
.brand {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-id > div { min-width: 0; }
.brand-name { font-weight: 650; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-person { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mark { width: 32px; height: 32px; flex: none; border-radius: 10px; background: var(--accent); color: var(--accent-text);
        display: grid; place-items: center; }
.mark svg { width: 18px; height: 18px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 550; min-height: 44px;
}
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 10px; }

.main {
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 20px var(--gutter) calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  display: flex; flex-direction: column; gap: 16px;
}
.page-title { font-size: 1.5rem; font-weight: 700; }
.grid-2 { display: flex; flex-direction: column; gap: 16px; }
.lead { max-width: 60ch; }

/* ------------------------------------------------------------------ tablet */
@media (min-width: 640px) {
  :root { --gutter: 24px; }
  /* The header and the tabs stick together, as one block. */
  .side { display: block; position: sticky; top: 0; z-index: 20; }
  .brand { position: static; }
  .tabs {
    position: static; height: auto; padding: 8px var(--gutter);
    display: flex; gap: 8px; border-top: 0; border-bottom: 1px solid var(--line);
  }
  .tab { flex-direction: row; gap: 8px; font-size: 0.9rem; padding: 8px 14px; border-radius: 999px; }
  .tab svg { width: 18px; height: 18px; }
  .tab.on { background: var(--surface-2); }
  .main { padding: 28px var(--gutter) 40px; gap: 20px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
}

/* ------------------------------------------------------------------ computer */
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); }
  .side {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .brand { position: static; flex-direction: column; align-items: stretch; gap: 16px; border-bottom: 0; padding: 24px 20px 12px; }
  .tabs { position: static; flex-direction: column; gap: 4px; padding: 8px 12px; border: 0; }
  .tab { justify-content: flex-start; font-size: 0.95rem; padding: 10px 14px; border-radius: 12px; }
  .tab:hover { background: var(--surface-2); color: var(--text); }
  .signout { align-self: flex-start; }
  .main { max-width: 1000px; padding: 40px 48px 56px; }
  .grid-2 { gap: 24px; }
}

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
@media (min-width: 640px) { .card { padding: 22px; } }
.card > h2 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.stat { font-size: 2.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat.sm { font-size: 1.4rem; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; align-self: flex-start;
  padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

.alerts { display: flex; flex-direction: column; gap: 10px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-bg); font-size: 0.95rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.plain { background: var(--surface-2); color: var(--muted); }
.notice a { color: inherit; font-weight: 600; }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rows li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; padding-top: 0; }
.rows strong { font-variant-numeric: tabular-nums; text-align: right; min-width: 5ch; }

/* ------------------------------------------------------------------ buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none; cursor: pointer; align-self: flex-start;
  background: var(--surface-2); color: var(--text); transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn.link { background: none; border: 0; padding: 6px 0; min-height: 32px; color: var(--link); font-weight: 550; }
.btn.link.danger { color: var(--bad); }
.btn.wide { align-self: stretch; width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

label { font-weight: 600; font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 6px; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; font-size: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.amount-row { display: flex; align-items: center; gap: 10px; }
.amount-row input { max-width: 200px; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-row .cur { color: var(--muted); font-weight: 600; }
.gets { font-weight: 600; color: var(--ok); min-height: 1.5em; }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }

/* ------------------------------------------------------------------ plans */
.tiers { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.tier.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.tier-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tier-head h2 { font-size: 1.1rem; }
.tier-price { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ticks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ticks li { padding-left: 24px; position: relative; }
.ticks li::before { content: ""; position: absolute; left: 4px; top: 0.45em; width: 10px; height: 6px;
  border-left: 2px solid var(--ok); border-bottom: 2px solid var(--ok); transform: rotate(-45deg); }

/* ------------------------------------------------------------------ payments */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; align-items: center; }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
.facts dd span { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.copy { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 4px 10px; font-size: 0.8rem; cursor: pointer; color: var(--muted); }
.pending { border-color: var(--accent); }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; padding-top: 0; }
.history .what { font-weight: 600; }
.history .amt { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.history .when { color: var(--muted); font-size: 0.85rem; }
.history .inv { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; }
@media (min-width: 1024px) {
  .history li { grid-template-columns: 9rem 1fr auto auto; align-items: center; }
  .history .when { order: -1; }
  .history .inv { grid-column: auto; justify-content: flex-end; }
}

/* ------------------------------------------------------------------ keys */
.keys { display: grid; gap: 16px; }
@media (min-width: 1024px) { .keys { grid-template-columns: 1fr 1fr; } }
.key.missing { border-color: var(--warn); }
.key-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.key-head h2 { font-size: 1rem; }
.mask code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem;
  background: var(--surface-2); padding: 3px 8px; border-radius: 6px; }
.key-form { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 640px) { .key-form { flex-direction: row; } .key-form select { max-width: 13rem; } .key-form .btn { flex: none; } }

/* ------------------------------------------------------------------ sign in */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.signin-card { width: 100%; max-width: 420px; text-align: center; align-items: center; gap: 16px; padding: 28px 24px; }
.signin-card h1 { font-size: 1.5rem; }
.signin-card .mark { width: 52px; height: 52px; border-radius: 16px; }
.signin-card .btn { align-self: center; }
.signin-card .btn.wide { align-self: stretch; }
.signin-card .mark svg { width: 28px; height: 28px; }
.code { font-size: 2.5rem; font-weight: 750; letter-spacing: 0.3em; padding-left: 0.3em; font-variant-numeric: tabular-nums; }
.qr { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr img { background: #fff; border-radius: 12px; padding: 8px; width: 208px; height: 208px; }
/* A phone opens Telegram itself; the code to scan is for a computer beside one. */
@media (max-width: 639px), (pointer: coarse) and (max-width: 1023px) { .qr { display: none; } }
.wait { display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ------------------------------------------------------------------ feedback */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 50;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  max-width: min(92vw, 480px); padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 550; font-size: 0.95rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 640px) { .toast { bottom: 24px; } }
.noscript { padding: 24px; text-align: center; }
.strong { font-weight: 600; }
body.busy { cursor: progress; }
body.busy .btn { pointer-events: none; }
