/* NurVPN Mini App. Colours come from Telegram.WebApp.themeParams (set by
   app.js with a 4.5:1 contrast check); these are the fallbacks. */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #ececf3;
  --text: #15171c;
  --hint: #5c6070;
  --line: rgba(20, 22, 30, .1);
  --accent: #5a49d6;
  --accent-text: #4a3bc2;
  --on-accent: #ffffff;
  --accent-soft: rgba(90, 73, 214, .12);
  --ok: #1b7a4b;
  --warn: #8a5800;
  --danger: #b42318;
  --radius: 18px;
  --tabs-h: 64px;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #1a1d26;
    --surface-2: #232734;
    --text: #f3f4f8;
    --hint: #a4a8b8;
    --line: rgba(255, 255, 255, .1);
    --accent: #6d5cf0;
    --accent-text: #b2a6ff;
    --accent-soft: rgba(141, 125, 255, .16);
    --ok: #6fd8a4;
    --warn: #f0c46c;
    --danger: #ff9d94;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, input, a { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-text); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.ic.sm { width: 18px; height: 18px; }
.ic.big { width: 40px; height: 40px; }

.app {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
}
.top { display: flex; align-items: center; justify-content: space-between; height: 44px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand .ic { color: var(--accent-text); }
.brand b { color: var(--accent-text); font-weight: 700; }
.view { display: grid; gap: 12px; }

h1.title { font-size: 24px; line-height: 1.2; letter-spacing: -.02em; margin-top: 4px; }
.intro, .hint { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 17px; line-height: 1.3; }
.card > * + * { margin-top: 10px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; margin: 8px 4px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 0; border-radius: 13px; background: var(--surface-2); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer; text-align: center;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--accent-text); min-height: 40px; }
.btn:disabled, .busy .btn { opacity: .55; pointer-events: none; }
.btn:active { transform: scale(.98); }
.btns { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.btns.one { grid-template-columns: 1fr; }
.row > .btn { width: auto; flex: none; }
.icon-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface-2); }
.pill.ok { color: var(--ok); }
.pill.trial { color: var(--accent-text); }
.pill.bad { color: var(--danger); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; }

/* Subscription card with the progress ring */
.sub { display: grid; grid-template-columns: 104px 1fr; gap: 14px; align-items: center; }
.ring { position: relative; width: 104px; height: 104px; }
.ring > svg { width: 104px; height: 104px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--surface-2); }
.ring .value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring-label b { font-size: 26px; letter-spacing: -.02em; }
.ring-label span { font-size: 12px; color: var(--hint); }
.sub-info > * + * { margin-top: 4px; }
.sub-info h2 { font-size: 18px; }

.banner { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.notice { display: flex; gap: 10px; align-items: flex-start; }
.notice .ic { color: var(--accent-text); margin-top: 1px; }

.tile { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; text-align: left; cursor: pointer; }
.tile .ic { color: var(--accent-text); }
.tile-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); display: grid; place-items: center; flex: none; }
.amount { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }

/* Tariffs */
.plans { display: grid; gap: 10px; }
.plan { position: relative; display: block; width: 100%; padding: 16px; border: 2px solid transparent; border-radius: var(--radius); background: var(--surface); text-align: left; cursor: pointer; }
.plan.selected { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--surface); }
.plan .badge { position: absolute; top: -9px; right: 14px; }
.plan-price { font-size: 20px; font-weight: 700; white-space: nowrap; }
.plan-month { color: var(--hint); font-size: 13px; }
.plan .radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.plan.selected .radio { border: 7px solid var(--accent); }

/* History */
.list { background: var(--surface); border-radius: var(--radius); padding: 4px 16px; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 0; }
.item + .item { border-top: 1px solid var(--line); }
.item .tile-icon { width: 36px; height: 36px; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item-sum { text-align: right; white-space: nowrap; font-weight: 600; }
.plus { color: var(--ok); }

/* Help */
.steps { counter-reset: step; display: grid; gap: 12px; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 10px; }
.step::before { counter-increment: step; content: counter(step); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-weight: 700; }
.links { display: grid; gap: 8px; }
details { background: var(--surface); border-radius: var(--radius); padding: 4px 16px; }
summary { list-style: none; cursor: pointer; padding: 12px 0; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; font-size: 20px; color: var(--hint); }
details[open] summary::after { content: "−"; }
details > div { padding-bottom: 12px; display: grid; gap: 8px; }
.app-name { font-weight: 600; margin-top: 6px; }
video { width: 100%; border-radius: 12px; background: #000; }

/* Profile */
.avatar { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-size: 22px; font-weight: 700; flex: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 12px; color: var(--hint); }
.code { display: block; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font: 13px/1.4 ui-monospace, Menlo, monospace; word-break: break-all; }

/* Empty states, errors, skeletons */
.empty { text-align: center; padding: 28px 16px; }
.empty .ic { color: var(--hint); margin: 0 auto 8px; display: block; }
.empty p { color: var(--hint); }
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; border-radius: var(--radius); }
.sk-card { height: 150px; }
.sk-block { height: 110px; }
.sk-line { height: 18px; border-radius: 9px; width: 80%; }
.sk-line.short { width: 50%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Shown by CSS alone if the app never started: no endless loading. */
.boot-fail { display: none; text-align: center; padding: 40px 8px; }
.boot-fail h1 { font-size: 22px; margin: 10px 0 8px; }
.boot-fail p { color: var(--hint); margin-bottom: 18px; }
.boot-fail .ic { color: var(--accent-text); }
body:not(.started) .boot-fail { display: block; visibility: hidden; animation: reveal .2s 12s forwards; }
body:not(.started) .view { animation: hide .2s 12s forwards; }
@keyframes reveal { to { visibility: visible; } }
@keyframes hide { to { visibility: hidden; height: 0; } }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding: 6px max(4px, env(safe-area-inset-left)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-right));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab { border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 3px; color: var(--hint); font-size: 11px; font-weight: 600; cursor: pointer; min-width: 0; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-current="page"] { color: var(--accent-text); }
body:not(.started) .tabs, .nodata .tabs { display: none; }

/* Bottom sheet and toast */
.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card { position: relative; width: min(100%, 520px); max-height: 90vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 12px; animation: up .2s ease-out; }
.sheet-card h2 { font-size: 19px; padding-right: 40px; }
.sheet-close { position: absolute; top: 14px; right: 14px; }
#sheet-body { display: grid; gap: 12px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.qr { width: min(100%, 280px); margin: 0 auto; padding: 12px; background: #fff; border-radius: 16px; }
.qr svg { display: block; width: 100%; height: auto; }
.amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.amounts .btn.selected { background: var(--accent); color: var(--on-accent); }
.field { width: 100%; min-height: 46px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 13px; background: var(--surface); }
.field:focus { outline: none; border-color: var(--accent); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 20;
  width: max-content; max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: .2s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 359px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .sub { grid-template-columns: 88px 1fr; gap: 12px; }
  .ring, .ring > svg { width: 88px; height: 88px; }
  .ring-label b { font-size: 22px; }
  .btns { grid-template-columns: 1fr; }
  h1.title { font-size: 22px; }
  .tab { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, .skeleton { animation-duration: .01s !important; transition: none !important; }
}
