/**
 * Telegram Mini App CSS - VIPSO1VN
 * 
 * Áp dụng khi website được mở trong Telegram Mini App
 * Nhận biết qua class "tg-webapp" trên <html>
 * 
 * @version 1.0.0
 */

/* ==========================================
   TELEGRAM MINI APP - BASE STYLES
   ========================================== */

html.tg-webapp {
    /* Dùng màu từ Telegram theme */
    --tg-bg: var(--tg-theme-bg-color, #0f172a);
    --tg-text: var(--tg-theme-text-color, #f1f5f9);
    --tg-hint: var(--tg-theme-hint-color, #94a3b8);
    --tg-link: var(--tg-theme-link-color, #7c3aed);
    --tg-btn-bg: var(--tg-theme-button-color, #7c3aed);
    --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #1e293b);
}

/* ==========================================
   HIDE SITE HEADER/FOOTER IN TELEGRAM
   ========================================== */

html.tg-webapp .header-top,
html.tg-webapp nav.navbar,
html.tg-webapp .nav-wrapper,
html.tg-webapp footer,
html.tg-webapp .footer-modern,
html.tg-webapp .hotline-phone-ring-wrap,
html.tg-webapp .zalo-chat-widget,
html.tg-webapp .backtop,
html.tg-webapp .backdrop {
    display: none !important;
}

/* ==========================================
   TELEGRAM BOTTOM NAVIGATION BAR
   ========================================== */

.tg-bottom-nav {
    display: none; /* Ẩn mặc định */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--tg-secondary-bg, #1e293b);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

html.tg-webapp .tg-bottom-nav {
    display: flex !important;
}

.tg-bottom-nav-items {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    width: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0;
}

.tg-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 0;
    cursor: pointer;
    text-decoration: none;
    color: var(--tg-hint, #94a3b8);
    transition: color 0.2s ease;
    gap: 3px;
    min-height: 48px;
}

.tg-nav-item:hover,
.tg-nav-item.active {
    color: var(--tg-btn-bg, #7c3aed);
}

.tg-nav-item i {
    font-size: 20px;
    line-height: 1;
}

.tg-nav-item span {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Badge số lượng trên nav icon */
.tg-nav-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 18px);
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

.tg-nav-item-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

/* ==========================================
   TELEGRAM HEADER BAR (thay thế nav cũ)
   ========================================== */

.tg-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--tg-secondary-bg, #1e293b);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 10px 16px;
    align-items: center;
    justify-content: space-between;
}

html.tg-webapp .tg-header {
    display: flex;
}

.tg-header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.tg-header-logo img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
}

.tg-header-logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--tg-text, #f1f5f9);
}

.tg-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tg-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    color: var(--tg-text, #f1f5f9);
    text-decoration: none;
    font-size: 16px;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.tg-header-btn:hover {
    background: rgba(255,255,255,0.15);
    color: var(--tg-text, #f1f5f9);
}

.tg-header-balance {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid rgba(124, 58, 237, 0.4);
    color: #a78bfa;
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    text-decoration: none;
}

/* ==========================================
   ADJUST BODY PADDING IN TELEGRAM MODE
   ========================================== */

html.tg-webapp body {
    padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important;
    background: var(--tg-bg, #0f172a) !important;
}

html.tg-webapp .section,
html.tg-webapp .feature-part,
html.tg-webapp main {
    padding-top: 10px !important;
}

/* ==========================================
   TELEGRAM HERO BANNER (trang chủ)
   ========================================== */

.tg-hero {
    display: none;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
    padding: 20px 16px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

html.tg-webapp .tg-hero {
    display: block;
}

.tg-hero::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(124,58,237,0.3) 0%, transparent 60%);
    pointer-events: none;
}

.tg-hero-title {
    font-size: 20px;
    font-weight: 800;
    color: #fff;
    margin-bottom: 4px;
    position: relative;
}

.tg-hero-subtitle {
    font-size: 13px;
    color: rgba(255,255,255,0.7);
    margin-bottom: 12px;
    position: relative;
}

.tg-hero-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    position: relative;
}

.tg-hero-stat {
    text-align: center;
}

.tg-hero-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #a78bfa;
}

.tg-hero-stat-label {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
}

/* ==========================================
   TOP USER & RECENT TRANSACTIONS WIDGET
   ========================================== */

.tg-widgets-row {
    display: none;
    gap: 10px;
    padding: 0 12px 12px;
}

html.tg-webapp .tg-widgets-row {
    display: flex;
}

.tg-widget-box {
    flex: 1;
    background: var(--tg-secondary-bg, #1e293b);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.06);
    min-width: 0;
}

.tg-widget-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--tg-hint, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.tg-top-user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.tg-top-user-rank {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(124,58,237,0.3);
    color: #a78bfa;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tg-top-user-info {
    flex: 1;
    min-width: 0;
}

.tg-top-user-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--tg-text, #f1f5f9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-top-user-amount {
    font-size: 11px;
    color: #22c55e;
    font-weight: 600;
}

.tg-recent-tx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.tg-recent-tx-icon {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: rgba(34,197,94,0.15);
    color: #22c55e;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tg-recent-tx-info {
    flex: 1;
    min-width: 0;
}

.tg-recent-tx-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--tg-text, #f1f5f9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-recent-tx-time {
    font-size: 10px;
    color: var(--tg-hint, #94a3b8);
    margin-top: 1px;
}

/* ==========================================
   SELECT GAME SECTION
   ========================================== */

.tg-select-game {
    display: none;
    padding: 0 12px 20px;
}

html.tg-webapp .tg-select-game {
    display: block;
}

.tg-select-game-title {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
}

.tg-select-game-title span {
    color: #a78bfa;
}

.tg-game-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.tg-game-item {
    background: var(--tg-secondary-bg, #1e293b);
    border-radius: 10px;
    padding: 10px 8px;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.06);
    transition: all 0.2s;
}

.tg-game-item:hover {
    border-color: rgba(124,58,237,0.5);
    background: rgba(124,58,237,0.1);
}

.tg-game-item img {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    object-fit: cover;
    margin-bottom: 6px;
}

.tg-game-item-name {
    font-size: 10px;
    color: var(--tg-text, #f1f5f9);
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================
   RESPONSIVE ADJUSTMENTS
   ========================================== */

@media (max-width: 480px) {
    html.tg-webapp .container {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    html.tg-webapp .product-card {
        border-radius: 10px;
    }
}

/* Loading spinner for Telegram */
.tg-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.tg-loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid rgba(124,58,237,0.3);
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: tg-spin 0.8s linear infinite;
}

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