/* AdFlex Network — Mini App */
:root {
  --bg: #0b0e14;
  --bg-soft: #10141d;
  --surface: #151a26;
  --surface-2: #1a2130;
  --border: rgba(255,255,255,.07);
  --text: #eef1f6;
  --muted: #8b95a7;
  --accent: #22c55e;
  --accent-2: #14b8a6;
  --accent-dark: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #38bdf8;
  --gradient: linear-gradient(135deg, #22c55e 0%, #14b8a6 100%);
  --radius: 18px;
  --nav-height: 76px;
}

/* Telegram theme adaptation (light themes) */
body.tg-light {
  --bg: #ffffff;
  --bg-soft: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: rgba(0,0,0,.08);
  --text: #17212b;
  --muted: #707a89;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding-bottom: calc(var(--nav-height) + 24px + env(safe-area-inset-bottom)); }
.page { padding: 16px 16px 8px; animation: pageIn .28s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Header ---------- */
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 6px; position: sticky; top: 0; z-index: 40; background: linear-gradient(var(--bg) 78%, transparent); }
.app-header .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 16.5px; letter-spacing: -.01em; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.brand-icon { width: 28px; height: 28px; border-radius: 9px; background: var(--gradient); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; }
.balance-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); padding: 7px 13px; border-radius: 100px; font-weight: 700; font-size: 14px; }
.balance-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: all .2s; }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- Auth ---------- */
.auth-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 82vh; padding: 32px 22px; text-align: center; }
.auth-logo { width: 84px; height: 84px; border-radius: 26px; background: var(--gradient); display: flex; align-items: center; justify-content: center; font-size: 34px; margin-bottom: 26px; box-shadow: 0 14px 44px rgba(34,197,94,.35); }
.auth-wrap h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 10px; }
.auth-wrap p { color: var(--muted); font-size: 15.5px; max-width: 300px; margin-bottom: 34px; }
.auth-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; max-width: 320px; padding: 16px; border-radius: 16px; background: var(--gradient); color: #fff; font-size: 16.5px; font-weight: 700; border: none; cursor: pointer; font-family: inherit; box-shadow: 0 10px 30px rgba(34,197,94,.3); transition: transform .15s; }
.auth-btn:active { transform: scale(.97); }
.auth-btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: none; margin-top: 12px; font-weight: 600; }
.auth-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; padding: 11px 15px; border-radius: 12px; font-size: 14px; margin-bottom: 18px; max-width: 320px; }
body.tg-light .auth-error { color: #b91c1c; }
.spinner { width: 20px; height: 20px; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Home ---------- */
.hero-card { position: relative; overflow: hidden; border-radius: 22px; padding: 24px 22px 20px; background: linear-gradient(140deg, rgba(34,197,94,.16), rgba(20,184,166,.07) 55%, transparent), var(--surface); border: 1px solid rgba(34,197,94,.22); margin-bottom: 14px; }
.hero-card::before { content: ''; position: absolute; top: -70px; right: -70px; width: 190px; height: 190px; border-radius: 50%; background: radial-gradient(circle, rgba(34,197,94,.22), transparent 70%); }
.hero-greet { font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.hero-balance { font-size: clamp(34px, 9vw, 42px); font-weight: 800; letter-spacing: -.03em; background: var(--gradient); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; line-height: 1.1; }
.hero-balance small { font-size: 16px; font-weight: 700; margin-left: 6px; -webkit-text-fill-color: var(--muted); }
.hero-actions { display: flex; gap: 10px; margin-top: 16px; position: relative; }
.hero-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 10px; border-radius: 14px; font-weight: 700; font-size: 14.5px; cursor: pointer; border: none; font-family: inherit; transition: transform .15s; }
.hero-btn:active { transform: scale(.97); }
.hero-btn.primary { background: var(--gradient); color: #fff; box-shadow: 0 8px 22px rgba(34,197,94,.28); }
.hero-btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.quick-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.qstat { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 13px 12px; text-align: center; }
.qstat .v { font-size: 16.5px; font-weight: 800; }
.qstat .l { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.section-title { display: flex; align-items: center; justify-content: space-between; font-size: 15px; font-weight: 700; margin: 4px 2px 12px; }
.section-title .see-all { color: var(--accent); font-size: 13.5px; font-weight: 600; cursor: pointer; }

/* Chart */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px 12px; margin-bottom: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.chart-head .t { font-weight: 700; font-size: 14.5px; }
.chart-head .s { font-size: 12px; color: var(--muted); }
.chart-svg { width: 100%; height: 130px; display: block; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-bar { width: 100%; border-radius: 7px 7px 3px 3px; background: linear-gradient(180deg, var(--accent), rgba(34,197,94,.25)); min-height: 3px; position: relative; transition: filter .15s; }
.chart-col.today .chart-bar { background: linear-gradient(180deg, #4ade80, rgba(34,197,94,.3)); box-shadow: 0 0 14px rgba(34,197,94,.4); }
.chart-bar:hover { filter: brightness(1.25); }
.chart-col .d { font-size: 10px; color: var(--muted); }
.chart-col.today .d { color: var(--accent); font-weight: 700; }

/* Activity list */
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .ic { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 17px; background: var(--surface-2); flex-shrink: 0; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .s { font-size: 12px; color: var(--muted); }
.list-item .amt { font-weight: 800; font-size: 14.5px; white-space: nowrap; }
.amt.pos { color: var(--accent); }
.amt.neg { color: var(--danger); }
.empty { text-align: center; padding: 36px 20px; color: var(--muted); font-size: 14.5px; }
.empty .e-ic { font-size: 34px; margin-bottom: 10px; opacity: .6; }

/* ---------- Bottom nav ---------- */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; display: flex; justify-content: center; padding: 0 14px calc(10px + env(safe-area-inset-bottom)); pointer-events: none; }
.nav-pill { pointer-events: auto; display: flex; align-items: center; gap: 2px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 24px; padding: 8px 10px; box-shadow: 0 12px 40px rgba(0,0,0,.45); width: 100%; max-width: 430px; justify-content: space-around; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px; border-radius: 16px; color: var(--muted); cursor: pointer; transition: all .18s; border: none; background: transparent; font-family: inherit; position: relative; }
.nav-item svg { width: 22px; height: 22px; }
.nav-item span { font-size: 10.5px; font-weight: 600; }
.nav-item.active { color: var(--accent); background: rgba(34,197,94,.1); }
.nav-item.active svg { filter: drop-shadow(0 0 8px rgba(34,197,94,.6)); }
.nav-item:active { transform: scale(.92); }
.nav-item.center .nav-orb { width: 52px; height: 52px; border-radius: 50%; background: var(--gradient); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 8px 26px rgba(34,197,94,.45); margin-top: -26px; border: 4px solid var(--bg); transition: transform .18s; }
.nav-item.center.active .nav-orb { transform: scale(1.08) rotate(8deg); }
.nav-item.center .nav-orb svg { width: 24px; height: 24px; }
.nav-item.center span { margin-top: 1px; }
.nav-badge { position: absolute; top: 2px; right: 12%; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 9.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.input { width: 100%; padding: 14px 16px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 15.5px; font-family: inherit; outline: none; transition: border-color .2s; }
.input:focus { border-color: var(--accent); }
.input:disabled { opacity: .55; }
select.input { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b95a7' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 42px; }
textarea.input { resize: none; min-height: 90px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hint.warn { color: var(--warning); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px; margin-bottom: 14px; }
.card-title { font-size: 15.5px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 15px; border-radius: 15px; font-size: 16px; font-weight: 700; border: none; cursor: pointer; font-family: inherit; transition: transform .15s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--gradient); color: #fff; box-shadow: 0 8px 24px rgba(34,197,94,.28); }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: rgba(239,68,68,.12); color: #f87171; border: 1px solid rgba(239,68,68,.3); }
body.tg-light .btn.danger { color: #dc2626; }
.btn.sm { padding: 9px 14px; font-size: 13.5px; width: auto; }

/* ---------- Withdraw ---------- */
.wd-hero { display: flex; flex-direction: column; align-items: center; padding: 22px 16px 18px; }
.wd-available { font-size: 13px; color: var(--muted); }
.wd-amount { font-size: 34px; font-weight: 800; background: var(--gradient); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.wd-min { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.progress { width: 100%; height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin-top: 14px; }
.progress-fill { height: 100%; background: var(--gradient); border-radius: 6px; transition: width .5s ease; }
.wd-conv { display: flex; justify-content: space-between; background: var(--surface-2); border-radius: 12px; padding: 12px 16px; font-size: 14px; margin-top: 12px; }
.wd-conv b { color: var(--accent); }

.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 100px; font-size: 12px; font-weight: 700; }
.status-pending { background: rgba(245,158,11,.13); color: #fbbf24; }
.status-processing { background: rgba(56,189,248,.13); color: #38bdf8; }
.status-completed { background: rgba(34,197,94,.13); color: #4ade80; }
.status-failed { background: rgba(239,68,68,.13); color: #f87171; }
.status-rejected { background: rgba(239,68,68,.13); color: #f87171; }
.status-open { background: rgba(56,189,248,.13); color: #38bdf8; }
.status-answered { background: rgba(34,197,94,.13); color: #4ade80; }
.status-closed { background: rgba(139,149,167,.15); color: var(--muted); }

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--nav-height) - 60px - env(safe-area-inset-bottom)); }
.chat-msgs { flex: 1; overflow-y: auto; padding: 6px 2px; display: flex; flex-direction: column; gap: 9px; overscroll-behavior: contain; }
.msg { max-width: 78%; background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 16px 5px; padding: 10px 14px; }
.msg.own { align-self: flex-end; background: linear-gradient(135deg, rgba(34,197,94,.18), rgba(20,184,166,.12)); border-color: rgba(34,197,94,.25); border-radius: 16px 16px 5px 16px; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--accent-2); margin-bottom: 2px; }
.msg.own .who { display: none; }
.msg .txt { font-size: 14.5px; word-break: break-word; white-space: pre-wrap; }
.msg .time { font-size: 10.5px; color: var(--muted); margin-top: 3px; text-align: right; }
.chat-input-bar { display: flex; gap: 9px; padding: 12px 2px 6px; }
.chat-input-bar .input { flex: 1; padding: 13px 16px; }
.chat-send { width: 50px; height: 50px; border-radius: 15px; background: var(--gradient); color: #fff; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; box-shadow: 0 6px 18px rgba(34,197,94,.3); }
.chat-send:active { transform: scale(.93); }
.chat-send svg { width: 21px; height: 21px; }
.mute-banner { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: #fbbf24; border-radius: 14px; padding: 11px 15px; font-size: 13.5px; margin-bottom: 10px; }
.chat-sys { text-align: center; color: var(--muted); font-size: 12.5px; padding: 30px 16px; }

/* ---------- Tickets ---------- */
.ticket-item { cursor: pointer; transition: background .15s; }
.ticket-item:active { background: var(--surface-2); }
.msg-bubble { max-width: 88%; padding: 11px 15px; border-radius: 16px; margin-bottom: 10px; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.msg-bubble.user { background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px 16px 16px 5px; }
.msg-bubble.admin { background: linear-gradient(135deg, rgba(34,197,94,.16), rgba(20,184,166,.08)); border: 1px solid rgba(34,197,94,.25); border-radius: 16px 16px 5px 16px; margin-left: auto; }
.msg-bubble .meta { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ---------- Settings ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.set-row:last-child { border-bottom: none; }
.set-row .l { font-weight: 600; font-size: 14.5px; }
.set-row .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lang-switch { display: flex; background: var(--surface-2); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.lang-switch button { padding: 8px 18px; border: none; background: transparent; color: var(--muted); font-weight: 700; font-size: 13.5px; cursor: pointer; font-family: inherit; }
.lang-switch button.active { background: var(--gradient); color: #fff; }
.token-box { display: flex; gap: 8px; align-items: center; }
.token-box code { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 11.5px; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.avatar { width: 52px; height: 52px; border-radius: 17px; object-fit: cover; background: var(--surface-2); }
.avatar-fallback { width: 52px; height: 52px; border-radius: 17px; background: var(--gradient); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 21px; font-weight: 800; }

/* ---------- Toasts ---------- */
#toast-container { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 380px); }
.toast { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 13px 17px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: 0 14px 40px rgba(0,0,0,.4); animation: toastIn .3s ease; display: flex; gap: 9px; align-items: center; }
.toast.success { border-color: rgba(34,197,94,.4); }
.toast.success::before { content: '✓'; color: var(--accent); font-weight: 800; }
.toast.error { border-color: rgba(239,68,68,.4); }
.toast.error::before { content: '!'; color: var(--danger); font-weight: 800; font-size: 16px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateY(-10px); transition: all .3s; }

/* ---------- Skeletons ---------- */
.skel { border-radius: var(--radius); background: linear-gradient(100deg, var(--surface) 40%, var(--surface-2) 50%, var(--surface) 60%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Watch page ---------- */
.watch-body { padding: 0; }
.watch-header { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
.watch-back { width: 38px; height: 38px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.watch-title { font-weight: 800; font-size: 16.5px; flex: 1; }
.watch-user { font-size: 13px; color: var(--muted); max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
.watch-note { margin-top: 14px; font-size: 12.5px; color: var(--muted); text-align: center; }
.watch-setup { text-align: center; padding: 60px 24px; }
.watch-setup-icon { font-size: 52px; margin-bottom: 18px; }
.watch-setup h2 { font-size: 21px; margin-bottom: 10px; }
.watch-setup p { color: var(--muted); font-size: 14.5px; }
.watch-setup .watch-setup-ru { margin-top: 8px; opacity: .8; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
