:root {
  --bg: #0d0d0f;
  --bg2: #121215;
  --card: #18181c;
  --card2: #202025;
  --card3: #2a2a30;
  --line: #2a2a30;
  --text: #ededf0;
  --muted: #8f8f99;
  --dim: #5e5e67;
  --silver: linear-gradient(135deg, #ffffff 0%, #cfcfd6 55%, #8d8d96 100%);
  --ok: #62d48e;
  --bad: #ff6b6b;
  --r: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --vh: var(--tg-viewport-stable-height, 100dvh);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ───────── Экран загрузки ───────── */
.splash {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.splash-center { display: flex; flex-direction: column; align-items: center; z-index: 2; margin-top: -60px; }
.splash-logo { display: flex; align-items: center; gap: 10px; height: 64px; }
.splash-mark { opacity: 0; transform: translateX(var(--shift, 0px)); animation: fadeIn .35s ease-out forwards;
  filter: drop-shadow(0 6px 24px rgba(255,255,255,.18)); }
.splash-text {
  font-size: 30px; font-weight: 800; letter-spacing: -.5px; white-space: nowrap; opacity: 0;
  transform: translateX(-20px);
  background: linear-gradient(180deg, #fff 0%, #b9b9c2 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.splash.finishing .splash-mark { animation: logoSplit .6s cubic-bezier(.4,0,.2,1) forwards; }
.splash.finishing .splash-text { animation: textReveal .6s cubic-bezier(.4,0,.2,1) forwards; }
@keyframes fadeIn { to { opacity: 1; } }
@keyframes logoSplit { from { opacity: 1; transform: translateX(var(--shift, 0px)); } to { opacity: 1; transform: translateX(0); } }
@keyframes textReveal { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }

.splash-bar { margin-top: 18px; width: 191px; height: 8px; border-radius: 24px; overflow: hidden; position: relative;
  background: hsla(0,0%,100%,.12); }
.splash-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 24px;
  background: linear-gradient(90deg, #7d7d86 0%, #e9e9ee 70%, #ffffff 100%);
  transition: width 1.6s cubic-bezier(.4,0,.2,1); box-shadow: 0 0 12px rgba(255,255,255,.35); }
.splash-note { margin-top: 14px; color: var(--muted); font-size: 14px; text-align: center; max-width: 260px; min-height: 20px; }
.splash.fade { opacity: 0; transition: opacity .5s ease-out; pointer-events: none; }

.splash-glow { position: absolute; bottom: -170px; left: 50%; transform: translateX(-50%); width: 503px; height: 503px; z-index: 1; }
/* свечение градиентом, без filter: blur (на iOS blur даёт тёмный прямоугольник) */
.glow-outer { position: absolute; inset: -130px; border-radius: 50%;
  background: radial-gradient(closest-side, hsla(240,4%,62%,.55) 40%, hsla(240,4%,62%,0) 100%); }
.glow-inner { position: absolute; width: 300px; height: 300px; bottom: 20px; left: 50%; border-radius: 50%;
  transform: translateX(-50%) scale(2);
  background: radial-gradient(closest-side, hsla(0,0%,96%,.55) 25%, hsla(0,0%,96%,0) 100%); }

.orbit { position: absolute; bottom: -130px; left: 50%; width: 260px; height: 260px; transform: translateX(-50%); z-index: 1; }
.orbit-card {
  position: absolute; top: 50%; left: 50%; width: 76px; height: 76px; margin: -38px 0 0 -38px;
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  background: hsla(0,0%,100%,.10); border: .8px solid hsla(0,0%,100%,.16);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  animation: orbit 20s linear infinite; color: #fff;
}
.orbit-card svg.i { width: 34px; height: 34px; stroke-width: 1.6; animation: pulse 2.4s ease-in-out infinite; }
@keyframes orbit {
  0%   { transform: rotate(0deg)   translateY(-130px) rotate(0deg); }
  25%  { transform: rotate(90deg)  translateY(-130px) rotate(-75deg); }
  50%  { transform: rotate(180deg) translateY(-130px) rotate(-180deg); }
  75%  { transform: rotate(270deg) translateY(-130px) rotate(-285deg); }
  100% { transform: rotate(360deg) translateY(-130px) rotate(-360deg); }
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.12); opacity: 1; } }

/* ───────── Каркас ───────── */
.app { height: var(--vh); display: flex; flex-direction: column; overflow: hidden; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 8px; flex: none; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 17px; letter-spacing: -.2px; }
.balance-pill { padding: 7px 13px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line);
  font-weight: 650; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabs { flex: 1; min-height: 0; position: relative; }
.tab { position: absolute; inset: 0; display: none; flex-direction: column; }
.tab.active { display: flex; }
.page { flex: 1; overflow-y: auto; padding: 4px 16px 24px; -webkit-overflow-scrolling: touch; }

.tabbar { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(13,13,15,.92); border-top: 1px solid var(--line); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--dim);
  font-size: 11px; font-weight: 600; transition: color .15s; }
.tabbar button.active { color: var(--text); }
body.typing .tabbar { display: none; }

/* ───────── Чат ───────── */
.chatbar { display: flex; align-items: center; gap: 8px; padding: 2px 12px 8px; flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); flex: none; }
.icon-btn:active { background: var(--card2); }
.model-chip { flex: 1; min-width: 0; height: 40px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650; padding: 0 12px; }
.model-chip span:not(.dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-3px); flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 8px rgba(98,212,142,.6); }
.dot.down { background: var(--bad); box-shadow: 0 0 8px rgba(255,107,107,.6); }

.messages { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.msg-user { align-self: flex-end; max-width: 86%; background: var(--card2); border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 18px 18px 6px 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg-ai { align-self: stretch; word-wrap: break-word; }
.msg-ai > .md > :first-child { margin-top: 0; }
.msg-ai > .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3 { margin: 16px 0 8px; line-height: 1.25; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md a { color: #cfd3ff; }
.md blockquote { margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--card3); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 10px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md :not(pre) > code { background: var(--card2); padding: 1px 6px; border-radius: 6px; font-size: 13.5px; }
.code { margin: 0 0 10px; border-radius: 14px; overflow: hidden; background: #0a0a0c; border: 1px solid var(--line); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 8px 6px 12px;
  background: var(--card); font-size: 12px; color: var(--muted); }
.code-head .btns { display: flex; gap: 6px; }
.code pre { margin: 0; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
.code pre code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre; }
.code:not(.file).collapsed pre { max-height: 190px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.show-more { display: block; width: 100%; padding: 9px; font-size: 13px; font-weight: 600; color: var(--muted); border-top: 1px solid var(--line); }
.code.file { background: var(--card); }
.code.file.collapsed pre { display: none; }
.code.file pre { border-top: 1px solid var(--line); background: #0a0a0c; }
.file-head { display: flex; align-items: center; gap: 11px; padding: 12px 12px 8px; }
.file-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--card3); flex: none; }
.file-meta { min-width: 0; }
.file-meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { font-size: 12px; color: var(--muted); }
.file-btns { display: flex; gap: 6px; padding: 0 12px 12px; }
.file-btns .mini-btn { flex: 1; padding: 8px 6px; font-size: 13px; }
.mini-btn.primary { background: var(--silver); color: #0d0d0f; }
.files-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 12px; margin: 0 0 10px; border-radius: 14px;
  background: var(--card2); border: 1px solid var(--line); }
.files-bar span { flex: 1; display: flex; align-items: center; gap: 6px; font-weight: 650; min-width: 90px; }
.files-bar svg.i { width: 18px; height: 18px; }
.mini-btn { padding: 5px 10px; border-radius: 8px; background: var(--card3); font-size: 12px; font-weight: 600; color: var(--text); }
.mini-btn:active { opacity: .7; }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--dim); }
.msg-meta button { color: var(--dim); display: flex; }
.msg-meta svg.i { width: 16px; height: 16px; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 8px; background: var(--card3);
  font-size: 12px; color: var(--muted); max-width: 100%; }
.file-chip svg.i { width: 14px; height: 14px; }
.thinking { display: flex; gap: 5px; padding: 6px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; } .thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }
.err-box { border: 1px solid rgba(255,107,107,.35); background: rgba(255,107,107,.08); border-radius: 14px; padding: 12px 14px; }
.err-box p { margin: 0 0 10px; }

.empty { margin: auto 0; text-align: center; padding: 10px 0 20px; }
.empty svg { width: 58px; height: 58px; }
.empty h2 { margin: 12px 0 4px; font-size: 22px; letter-spacing: -.3px; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 300px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.suggest button { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; font-size: 13.5px; line-height: 1.3; }
.suggest button b { display: block; font-size: 14px; margin-bottom: 2px; }
.suggest button span { color: var(--muted); }

.composer { flex: none; padding: 8px 12px calc(10px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); }
body:not(.typing) .composer { padding-bottom: 10px; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-height: 40px; max-height: 160px; resize: none; border-radius: 14px; padding: 9px 14px;
  background: var(--card); border: 1px solid var(--line); outline: none; line-height: 1.4; }
.composer textarea:focus { border-color: #44444c; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--silver); color: #0d0d0f; flex: none; }
.send-btn:disabled { opacity: .35; }
.send-btn svg.i { stroke-width: 2.4; width: 20px; height: 20px; }
.attachments { display: flex; gap: 6px; overflow-x: auto; }
.attachments:not(:empty) { padding-bottom: 8px; }
.att { position: relative; flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 28px 6px 8px; border-radius: 10px;
  background: var(--card2); border: 1px solid var(--line); font-size: 12px; max-width: 180px; }
.att img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; display: grid; place-items: center; color: var(--muted); }
.att button svg.i { width: 14px; height: 14px; }

/* ───────── Карточки, списки ───────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.card p { margin: 0 0 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 8px; font-weight: 700; font-size: 15px; }
.link-btn { color: var(--text); font-weight: 650; font-size: 14px; padding: 4px 10px; border-radius: 10px; background: var(--card2); }
.copy-field { display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 8px 12px; }
.copy-field code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; }

.hero-card { position: relative; overflow: hidden; border-radius: 20px; padding: 18px 16px 16px; margin: 4px 0 6px;
  background: radial-gradient(120% 90% at 100% 0%, #3a3a42 0%, #1b1b20 55%, #141417 100%); border: 1px solid #33333a; }
.hero-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.hero-card h1 { margin: 6px 0 6px; font-size: 22px; line-height: 1.2; letter-spacing: -.4px; }
.hero-card p { margin: 0 0 14px; color: #b7b7c0; font-size: 14px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-stats div { background: rgba(255,255,255,.06); border-radius: 12px; padding: 8px 10px; }
.hero-stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: 11.5px; color: var(--muted); }

.vendor-head { margin: 18px 2px 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.model-row { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); margin-bottom: 8px; }
.model-row.selected { border-color: #8a8a94; background: var(--card2); }
.model-row.is-down { opacity: .55; }
.model-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--card3); font-weight: 800; font-size: 13px; flex: none; color: #fff; }
.model-body { flex: 1; min-width: 0; }
.model-name { display: flex; align-items: center; gap: 6px; font-weight: 650; }
.model-desc { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-price { text-align: right; font-size: 13px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.model-price span { display: block; font-size: 11px; color: var(--dim); font-weight: 500; }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--card3); color: var(--muted); }

.key-card .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.key-card .hint { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--muted); }
.bar { height: 6px; border-radius: 6px; background: var(--card3); margin: 10px 0 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--silver); border-radius: 6px; }
.key-actions { display: flex; gap: 8px; margin-top: 10px; }
.key-actions button { flex: 1; padding: 8px; border-radius: 10px; background: var(--card2); font-size: 13px; font-weight: 600; }
.key-actions .danger { color: var(--bad); }
.empty-note { text-align: center; color: var(--muted); padding: 18px 10px; font-size: 14px; }
.seg { display: flex; gap: 4px; background: var(--bg2); padding: 3px; border-radius: 11px; margin-bottom: 10px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card3); color: var(--text); }

.balance-card { border-radius: 20px; padding: 18px 16px; margin: 4px 0 4px; text-align: center;
  background: radial-gradient(100% 120% at 50% 0%, #34343b 0%, #19191d 70%); border: 1px solid #36363d; }
.balance-big { font-size: 40px; font-weight: 800; letter-spacing: -1px; margin: 2px 0; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff, #b9b9c2); -webkit-background-clip: text; background-clip: text; color: transparent; }
.packs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pack { position: relative; padding: 14px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: left; }
.pack:active { background: var(--card2); }
.pack b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.pack span { font-size: 12.5px; color: var(--muted); }
.pack .bonus { position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 7px; background: var(--silver); color: #0d0d0f; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }
.list-row .sub { font-size: 12px; color: var(--dim); }
.spend-bar { height: 4px; border-radius: 4px; background: var(--card3); margin-top: 5px; overflow: hidden; }
.spend-bar i { display: block; height: 100%; background: #b9b9c2; }

/* ───────── Шторка ───────── */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fadeIn .2s forwards; opacity: 0; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 86%; overflow-y: auto; background: var(--bg2);
  border-radius: 22px 22px 0 0; border-top: 1px solid var(--line); padding: 6px 16px calc(18px + var(--safe-b));
  animation: slideUp .26s cubic-bezier(.2,.8,.2,1); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--card3); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input { width: 100%; padding: 11px 13px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); outline: none; }
.field input:focus { border-color: #55555e; }
.btn { width: 100%; padding: 13px; border-radius: 14px; font-weight: 700; background: var(--silver); color: #0d0d0f; }
.btn.ghost { background: var(--card2); color: var(--text); margin-top: 8px; }
.btn:disabled { opacity: .5; }
.dialog-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.dialog-row .t { flex: 1; min-width: 0; }
.dialog-row .t b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-row .t span { font-size: 12px; color: var(--dim); }
.dialog-row button.del { color: var(--dim); padding: 6px; }
.dialog-row.current b { color: #fff; }
.key-reveal { word-break: break-all; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 8px 0 12px; }
.warn { font-size: 13px; color: #e8c37a; margin-bottom: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 200;
  background: #f1f1f4; color: #0d0d0f; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
