/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: var(--tg-theme-bg-color, #1a1a2e);
    --text: var(--tg-theme-text-color, #e0e0e0);
    --hint: var(--tg-theme-hint-color, #8888a0);
    --link: var(--tg-theme-link-color, #6c9eff);
    --btn: var(--tg-theme-button-color, #6c9eff);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #16213e);
    --section-bg: var(--tg-theme-section-bg-color, var(--secondary-bg));
    --section-header: var(--tg-theme-section-header-text-color, var(--hint));
    --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
    --accent: var(--tg-theme-accent-text-color, var(--link));
    --destructive: var(--tg-theme-destructive-text-color, #e53935);
    --header-bg: var(--tg-theme-header-bg-color, var(--btn));
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 60px;
    --max-width: 600px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: calc(var(--nav-height) + 16px);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ─── Top Bar (browser only) ────────────────────────────────── */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--section-bg);
    border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.top-bar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.top-bar-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.btn-logout {
    background: none;
    border: 1px solid rgba(128, 128, 128, 0.3);
    color: var(--hint);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.btn-logout:hover {
    color: var(--destructive);
    border-color: var(--destructive);
}

/* ─── Navigation ────────────────────────────────────────────── */
.nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--section-bg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid rgba(128, 128, 128, 0.15);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--hint);
    font-size: 10px;
    padding: 6px 12px;
    cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--accent); }
.nav-btn:active { opacity: 0.7; }

/* ─── Pages ─────────────────────────────────────────────────── */
.page {
    display: none;
    padding: 16px;
    max-width: var(--max-width);
    margin: 0 auto;
    animation: fadeIn 0.2s ease;
}

.page.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 24px; font-weight: 700; }
.subtitle { color: var(--subtitle); font-size: 14px; margin-top: 4px; }

/* ─── Stats Grid ────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 12px;
    color: var(--hint);
    margin-top: 4px;
}

/* ─── Sections ──────────────────────────────────────────────── */
.section { margin-bottom: 24px; }
.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--section-header);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

/* ─── VPN Cards ─────────────────────────────────────────────── */
.vpn-list { display: flex; flex-direction: column; gap: 10px; }

.vpn-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vpn-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vpn-name { font-size: 16px; font-weight: 600; }

.vpn-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}

.vpn-badge.active { background: rgba(76, 175, 80, 0.15); color: #4caf50; }
.vpn-badge.expired { background: rgba(229, 57, 53, 0.15); color: var(--destructive); }

.vpn-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--subtitle);
}

.vpn-meta-row { display: flex; justify-content: space-between; }

.vpn-actions { display: flex; gap: 8px; margin-top: 4px; }
.vpn-actions .btn { flex: 1; font-size: 13px; padding: 8px; }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { opacity: 0.75; }
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-secondary { background: var(--section-bg); color: var(--text); }
.btn-outline { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn-block { width: 100%; margin-top: 16px; padding: 14px; font-size: 16px; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.buy-note {
    color: var(--hint, #8888a0);
    font-size: 12px;
    text-align: center;
    margin-top: 8px;
}

/* ─── Server List ───────────────────────────────────────────── */
.server-list { display: flex; flex-direction: column; gap: 8px; }

.server-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: outline 0.15s;
    border: 2px solid transparent;
    -webkit-tap-highlight-color: transparent;
}

.server-card:active { opacity: 0.8; }
.server-card.selected { border-color: var(--accent); }
.server-card.unavailable { opacity: 0.5; pointer-events: none; }

.server-name { font-weight: 600; font-size: 15px; }

.server-status {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 20px;
    font-weight: 600;
}

.server-status.online { background: rgba(76, 175, 80, 0.15); color: #4caf50; }
.server-status.offline { background: rgba(229, 57, 53, 0.15); color: var(--destructive); }

/* ─── Tariff List ───────────────────────────────────────────── */
.tariff-list { display: flex; flex-direction: column; gap: 8px; }

.tariff-card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.tariff-card:active { opacity: 0.8; }
.tariff-card.selected { border-color: var(--accent); }

.tariff-name { font-weight: 600; font-size: 15px; }
.tariff-price { font-weight: 700; font-size: 16px; color: var(--accent); }

/* ─── Device Selector ───────────────────────────────────────── */
.device-selector { display: flex; gap: 8px; }

.device-btn {
    flex: 1;
    background: var(--section-bg);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.device-btn:active { opacity: 0.8; }
.device-btn.active { border-color: var(--accent); color: var(--accent); }

/* ─── Buy Summary ───────────────────────────────────────────── */
.buy-summary {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}

.summary-row.total {
    border-top: 1px solid rgba(128, 128, 128, 0.15);
    margin-top: 8px;
    padding-top: 12px;
    font-size: 16px;
    font-weight: 700;
}

/* ─── Referrals ─────────────────────────────────────────────── */
.ref-link-box {
    display: flex;
    align-items: center;
    background: var(--section-bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    gap: 8px;
}

.ref-link-text {
    flex: 1;
    font-size: 13px;
    word-break: break-all;
    color: var(--link);
}

.copy-status {
    font-size: 12px;
    color: var(--accent);
    text-align: center;
    margin-top: 6px;
    min-height: 18px;
}

/* ─── Empty & Loading ───────────────────────────────────────── */
.loading { text-align: center; color: var(--hint); padding: 32px 0; font-size: 14px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--hint); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { margin-bottom: 16px; font-size: 15px; }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    background: var(--destructive);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 200;
    text-align: center;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ═══════════════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════════════ */
.login-body {
    background: linear-gradient(135deg, #0f0c29, #1a1a2e, #16213e);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.login-logo {
    margin-bottom: 32px;
}

.login-icon {
    font-size: 64px;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 32px;
    font-weight: 800;
    color: #ffffff;
    margin-bottom: 8px;
}

.login-subtitle {
    color: #8888a0;
    font-size: 15px;
    line-height: 1.5;
}

.login-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 32px 24px;
    margin-bottom: 32px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.login-hint {
    color: #8888a0;
    font-size: 13px;
}

.login-features {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
    text-align: left;
}

.feature-item {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.feature-icon {
    font-size: 28px;
    flex-shrink: 0;
    margin-top: 2px;
}

.feature-item strong {
    color: #ffffff;
    font-size: 14px;
    display: block;
    margin-bottom: 2px;
}

.feature-item p {
    color: #8888a0;
    font-size: 13px;
    line-height: 1.4;
}

.login-footer {
    color: #5a5a78;
    font-size: 13px;
}

.login-footer a {
    color: #6c9eff;
    text-decoration: none;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — DESKTOP (> 600px)
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 601px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .page {
        padding: 24px 16px;
    }

    .vpn-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .server-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .tariff-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .nav {
        top: 0;
        bottom: auto;
        border-top: none;
        border-bottom: 1px solid rgba(128, 128, 128, 0.15);
        justify-content: center;
        gap: 8px;
        padding-bottom: 0;
    }

    .nav-btn {
        flex-direction: row;
        gap: 6px;
        font-size: 13px;
        padding: 12px 16px;
    }

    .nav-btn .nav-icon { font-size: 16px; }

    body {
        padding-bottom: 16px;
        padding-top: calc(var(--nav-height) + 16px);
    }
}

/* ═══════════════════════════════════════════════════════════════
   TELEGRAM BUTTON (login page)
   ═══════════════════════════════════════════════════════════════ */
.btn-telegram {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #2AABEE;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.btn-telegram:hover { background: #229ED9; }
.btn-telegram:active { opacity: 0.85; }

.btn-telegram-sm {
    padding: 10px 20px;
    font-size: 14px;
    margin-top: 12px;
}

/* ─── Spinner ───────────────────────────────────────────────── */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: #6c9eff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.login-waiting {
    text-align: center;
    color: #e0e0e0;
}

.login-waiting p {
    margin-bottom: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   MODALS (QR, Renew)
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-card {
    background: var(--section-bg, #16213e);
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    overflow: hidden;
    animation: fadeIn 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--hint, #8888a0);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--destructive, #e53935); }

.modal-body {
    padding: 20px;
}

.modal-hint {
    color: var(--hint, #8888a0);
    font-size: 14px;
    margin-bottom: 12px;
}

.qr-img {
    max-width: 280px;
    width: 100%;
    border-radius: 12px;
    background: #fff;
    padding: 8px;
}

.qr-hint {
    color: var(--hint, #8888a0);
    font-size: 13px;
    margin-top: 12px;
}

/* ─── Success toast ─────────────────────────────────────────── */
.toast-success {
    background: #2e7d32;
}

/* ═══════════════════════════════════════════════════════════════
   GUIDE / INSTRUCTIONS PAGE
   ═══════════════════════════════════════════════════════════════ */
.guide-section {
    background: var(--section-bg, rgba(255,255,255,0.05));
    border-radius: var(--radius, 12px);
    padding: 16px 18px;
    margin-bottom: 12px;
}

.guide-step-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text, #e0e0e0);
}

.guide-text {
    font-size: 14px;
    color: var(--subtitle, #b0b0c0);
    line-height: 1.6;
    margin-bottom: 8px;
}

.guide-hint {
    font-size: 12px;
    color: var(--hint, #8888a0);
    font-style: italic;
    margin-top: 8px;
}

.guide-list {
    font-size: 14px;
    color: var(--subtitle, #b0b0c0);
    line-height: 1.7;
    padding-left: 20px;
    margin: 0 0 8px 0;
}

.guide-list code {
    background: rgba(108, 158, 255, 0.15);
    color: var(--accent, #6c9eff);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.guide-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guide-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(108, 158, 255, 0.08);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text, #e0e0e0);
    transition: background 0.2s;
}

.guide-link:hover { background: rgba(108, 158, 255, 0.15); }

.guide-link-icon {
    font-size: 22px;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
}

.guide-link div {
    display: flex;
    flex-direction: column;
}

.guide-link strong {
    font-size: 14px;
    font-weight: 600;
}

.guide-link span {
    font-size: 12px;
    color: var(--hint, #8888a0);
}
