:root {
  --bg: var(--tg-theme-bg-color, #08101f);
  --surface: var(--tg-theme-secondary-bg-color, #101a2d);
  --surface-2: #162238;
  --text: var(--tg-theme-text-color, #f5f7fb);
  --muted: var(--tg-theme-hint-color, #93a0b5);
  --accent: var(--tg-theme-button-color, #6d7cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(255, 255, 255, .09);
  --success: #42d392;
  --danger: #ff6b78;
  --warning: #f5bd4f;
  --shadow: 0 18px 45px rgba(0, 0, 0, .24);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
body { -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; background:
  radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 34%),
  radial-gradient(circle at 100% 20%, rgba(62, 208, 183, .10), transparent 35%),
  var(--bg); }

.splash { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 18px; padding: 24px; text-align: center; color: var(--muted); }
.brand-mark { width: 42px; height: 42px; color: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-mark--large { width: 92px; height: 92px; }
.loader { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: max(14px, env(safe-area-inset-top)) 18px 12px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); border-bottom: 1px solid var(--border); }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 800; letter-spacing: -.02em; }
.brand-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }
.icon-btn { width: 40px; height: 40px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; }

.content { width: min(100%, 720px); margin: 0 auto; padding: 18px 16px calc(100px + env(safe-area-inset-bottom)); }
.screen { display: none; animation: screenIn .22s ease-out; }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.status-hero { position: relative; overflow: hidden; padding: 28px 20px 24px; border: 1px solid var(--border); border-radius: 28px; text-align: center; background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 94%, var(--accent) 6%), var(--surface)); box-shadow: var(--shadow); }
.status-hero::before { content: ""; position: absolute; inset: -80px auto auto 50%; width: 260px; height: 260px; transform: translateX(-50%); border-radius: 50%; background: var(--accent); opacity: .09; filter: blur(18px); }
.status-orbit { position: relative; width: 132px; height: 132px; margin: 0 auto 18px; display: grid; place-items: center; }
.status-ring { position: absolute; inset: 0; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent); box-shadow: inset 0 0 0 14px color-mix(in srgb, var(--accent) 5%, transparent); }
.status-core { position: relative; width: 86px; height: 86px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 17%, var(--surface)); color: var(--muted); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); }
.status-core svg { width: 48px; height: 48px; }
.status-hero--active .status-core { color: var(--success); background: color-mix(in srgb, var(--success) 15%, var(--surface)); }
.status-hero--active .status-ring { border-color: color-mix(in srgb, var(--success) 38%, transparent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); opacity: .68; } }
.status-label { position: relative; font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.status-hint { position: relative; color: var(--muted); margin: 8px auto 20px; max-width: 420px; line-height: 1.45; }

.primary-btn, .secondary-btn, .ghost-btn { min-height: 50px; border-radius: 16px; border: 0; padding: 12px 18px; font-weight: 750; display: inline-flex; align-items: center; justify-content: center; gap: 9px; transition: transform .15s ease, opacity .15s ease, background .15s ease; }
.primary-btn:active, .secondary-btn:active, .ghost-btn:active { transform: scale(.985); }
.primary-btn { background: var(--accent); color: var(--accent-text); box-shadow: 0 12px 28px color-mix(in srgb, var(--accent) 28%, transparent); }
.secondary-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.ghost-btn { background: transparent; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.full-width { width: 100%; }
button:disabled { opacity: .55; cursor: wait; }

.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 14px 0 22px; }
.metric-card { min-width: 0; display: flex; align-items: center; gap: 12px; padding: 15px; border-radius: 20px; border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); }
.metric-icon { width: 42px; height: 42px; flex: 0 0 42px; display: grid; place-items: center; border-radius: 14px; background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { margin-top: 3px; font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metrics-grid--admin { grid-template-columns: repeat(3, 1fr); }

.section-block { margin: 22px 0; }
.section-block.compact { margin-top: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 12px; }
.section-heading h2, .panel h2 { margin: 0; font-size: 17px; }
.section-badge { padding: 5px 9px; border-radius: 999px; font-size: 11px; color: var(--accent); background: color-mix(in srgb, var(--accent) 11%, transparent); }
.steps-list { display: grid; gap: 10px; }
.step-item { display: flex; align-items: center; gap: 13px; padding: 13px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; }
.step-item > span { flex: 0 0 34px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 12px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 850; }
.step-item b { display: block; font-size: 14px; }
.step-item small { display: block; margin-top: 3px; color: var(--muted); line-height: 1.35; }

.page-title { display: flex; gap: 13px; align-items: center; margin: 6px 2px 20px; }
.page-title h1 { margin: 0; font-size: 25px; letter-spacing: -.03em; }
.page-title p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.page-icon { width: 48px; height: 48px; flex: 0 0 48px; display: grid; place-items: center; border-radius: 16px; background: color-mix(in srgb, var(--accent) 13%, var(--surface)); border: 1px solid var(--border); font-size: 22px; }
.panel { padding: 18px; border-radius: 22px; border: 1px solid var(--border); background: var(--surface); }
.field-label, .form-grid label > span { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.promo-input-wrap { position: relative; }
input, select { width: 100%; min-height: 50px; border-radius: 15px; border: 1px solid var(--border); padding: 11px 14px; background: color-mix(in srgb, var(--bg) 72%, var(--surface)); color: var(--text); outline: none; }
input:focus, select:focus { border-color: color-mix(in srgb, var(--accent) 65%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
#promoInput { text-transform: uppercase; letter-spacing: .08em; font-weight: 800; padding-right: 44px; }
.input-clear { position: absolute; right: 9px; top: 8px; width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 9px 2px 15px; }
.info-card { display: flex; gap: 12px; align-items: flex-start; padding: 15px; margin-top: 14px; border: 1px solid color-mix(in srgb, var(--accent) 19%, var(--border)); border-radius: 19px; background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.info-card__icon { font-size: 22px; }
.info-card b { font-size: 14px; }
.info-card p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.locked-card { padding: 28px 20px; text-align: center; border-radius: 24px; background: var(--surface); border: 1px solid var(--border); }
.locked-icon { font-size: 42px; }
.locked-card h2 { margin: 12px 0 6px; }
.locked-card p { margin: 0 0 18px; color: var(--muted); }
.connection-card { padding: 17px; margin-bottom: 13px; border-radius: 22px; border: 1px solid color-mix(in srgb, var(--success) 22%, var(--border)); background: linear-gradient(135deg, color-mix(in srgb, var(--success) 8%, var(--surface)), var(--surface)); }
.connection-card__top { display: flex; align-items: center; gap: 11px; }
.server-flag { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-2); font-size: 22px; }
.connection-card__title { min-width: 0; flex: 1; }
.connection-card__title b, .connection-card__title span { display: block; }
.connection-card__title span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.online-dot { padding: 5px 8px; border-radius: 999px; color: var(--success); background: color-mix(in srgb, var(--success) 11%, transparent); font-size: 11px; }
.connection-card__details { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.connection-card__details span, .connection-card__details b { display: block; }
.connection-card__details span { color: var(--muted); font-size: 11px; }
.connection-card__details b { margin-top: 4px; font-size: 13px; }
#activeConnect > button + button { margin-top: 10px; }
.instruction-list { margin: 0; padding-left: 23px; color: var(--muted); line-height: 1.55; }
.instruction-list li + li { margin-top: 8px; }

.accordion-list { display: grid; gap: 10px; }
details { border: 1px solid var(--border); border-radius: 17px; background: var(--surface); overflow: hidden; }
summary { list-style: none; padding: 15px 42px 15px 15px; position: relative; font-weight: 700; font-size: 14px; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; position: absolute; right: 16px; top: 13px; font-size: 20px; color: var(--accent); }
details[open] summary::after { content: "−"; }
details p { margin: 0; padding: 0 15px 15px; color: var(--muted); font-size: 13px; line-height: 1.5; }
#supportBtn { margin-top: 16px; }
#diagnosticsBtn { margin-top: 10px; }
.diagnostics { margin-top: 10px; padding: 13px; border-radius: 15px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; line-height: 1.5; }

.admin-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; margin-bottom: 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.admin-tab { min-height: 38px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 13px; }
.admin-tab.active { background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); color: var(--text); }
.admin-pane { display: none; }
.admin-pane.active { display: block; }
.server-health-card { padding: 16px; border-radius: 19px; background: var(--surface); border: 1px solid var(--border); }
.server-health-card > div { display: flex; align-items: center; gap: 9px; }
.server-health-card p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warning) 10%, transparent); }
.server-health-card.ok .health-dot { background: var(--success); box-shadow: 0 0 0 5px color-mix(in srgb, var(--success) 10%, transparent); }
.server-health-card.bad .health-dot { background: var(--danger); box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 10%, transparent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 15px 0; }
.form-grid__full { grid-column: 1 / -1; }
.text-btn { border: 0; color: var(--accent); background: transparent; padding: 6px; }
.data-list { display: grid; gap: 10px; }
.data-item { padding: 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); }
.data-item__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.data-item__title { font-weight: 800; overflow-wrap: anywhere; }
.data-item__sub { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.data-item__meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.chip { padding: 5px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 11px; }
.chip.active { color: var(--success); background: color-mix(in srgb, var(--success) 10%, transparent); }
.chip.disabled { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.data-item__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.small-btn { min-height: 36px; padding: 7px 11px; border-radius: 11px; border: 1px solid var(--border); color: var(--text); background: var(--surface-2); font-size: 12px; }
.small-btn.danger { color: var(--danger); }
.search-wrap { margin-bottom: 12px; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 18px; }

.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; padding: 7px max(9px, env(safe-area-inset-left)) max(7px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(20px); border-top: 1px solid var(--border); }
.nav-item { flex: 1 1 0; max-width: 130px; min-width: 0; min-height: 54px; border: 0; border-radius: 15px; background: transparent; color: var(--muted); display: grid; justify-items: center; align-content: center; gap: 2px; }
.nav-item > span { font-size: 20px; line-height: 1; }
.nav-item small { font-size: 10px; }
.nav-item.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.toast { position: fixed; z-index: 100; left: 16px; right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); max-width: 520px; margin: auto; padding: 13px 15px; border-radius: 15px; background: #1d2a40; color: #fff; border: 1px solid rgba(255,255,255,.12); box-shadow: var(--shadow); text-align: center; font-size: 13px; animation: toastIn .18s ease-out; }
.toast.error { background: #48202a; }
.toast.success { background: #15392d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.modal { position: fixed; z-index: 90; inset: 0; display: grid; place-items: end center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.66); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(100%, 430px); padding: 22px; border-radius: 25px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-align: center; animation: modalIn .2s ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px); } }
.modal-card h2 { margin: 0; }
.modal-card > p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.modal-close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text); font-size: 23px; }
.qr-frame { width: min(100%, 280px); aspect-ratio: 1; margin: 15px auto; padding: 12px; border-radius: 20px; background: white; }
.qr-frame img { width: 100%; height: 100%; object-fit: contain; }
.security-note { color: var(--warning) !important; }

@media (max-width: 430px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .status-hero { border-radius: 24px; }
  .metrics-grid--admin { grid-template-columns: 1fr 1fr; }
  .metrics-grid--admin .metric-card:last-child { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid__full { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.connect-main-btn { min-height: 58px; font-size: 16px; }
.connect-caption { margin: 10px 8px 0; color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }
.apps-list { display: grid; gap: 10px; }
.app-choice { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 19px; border: 1px solid var(--border); background: var(--surface); }
.app-choice--recommended { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.app-choice--loading { color: var(--muted); justify-content: center; min-height: 72px; }
.app-choice__icon { width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center; border-radius: 15px; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); color: var(--accent); font-weight: 900; }
.app-choice__body { min-width: 0; flex: 1; }
.app-choice__title { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-weight: 800; }
.app-choice__text { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.viz-badge-lite { padding: 4px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-size: 10px; font-weight: 800; }
.small-connect-btn { min-height: 38px; padding: 8px 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 800; }
.advanced-methods { margin-top: 18px; }
.advanced-methods summary { color: var(--muted); }
.advanced-actions { display: grid; gap: 9px; padding: 0 14px 14px; }
