/**
 * iStaff Design System — Unified CSS for Telegram Mini App
 * 
 * Single source of truth for all visual components.
 * Pages include this file + optional page-specific CSS.
 *
 * Structure:
 *  1. CSS Variables (tokens)
 *  2. Reset & Base
 *  3. Body backgrounds & effects
 *  4. Layout
 *  5. Header
 *  6. Bottom Navigation
 *  7. Cards (panel, game-card, platform-card)
 *  8. Buttons
 *  9. Inputs & Forms
 * 10. Toast notifications
 * 11. Loading states
 * 12. Section titles
 * 13. Badges
 * 14. Animations (keyframes)
 * 15. Utilities
 */

/* ==========================================================================
   1. CSS VARIABLES
   ========================================================================== */
:root {
    /* Background */
    --bg: #050510;
    --panel-bg: rgba(15, 10, 40, 0.65);
    --panel-border: rgba(139, 92, 246, 0.2);

    /* Brand colors */
    --primary: #a855f7;
    --primary-glow: rgba(168, 85, 247, 0.6);
    --cyan: #06b6d4;
    --cyan-glow: rgba(6, 182, 212, 0.5);
    --magenta: #e040fb;
    --pink: #ff3366;

    /* Semantic */
    --success: #00ff88;
    --success-glow: rgba(0, 255, 136, 0.5);
    --danger: #ff3366;
    --warn: #fbbf24;
    --gold: #ffd700;
    --gold-glow: rgba(255, 215, 0, 0.4);

    /* Text */
    --text: #f0f0ff;
    --muted: #8b8ba7;

    /* Spacing */
    --page-pad: 14px;
    --nav-height: 64px;
    --header-height: 52px;
    --max-width: 480px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 20px;
}

/* ==========================================================================
   2. RESET & BASE
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ==========================================================================
   3. BODY BACKGROUNDS & EFFECTS
   ========================================================================== */
body {
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 20% 10%, rgba(168, 85, 247, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse 60% 80% at 80% 90%, rgba(6, 182, 212, 0.09) 0%, transparent 60%),
        radial-gradient(ellipse 50% 50% at 50% 50%, rgba(224, 64, 251, 0.06) 0%, transparent 50%);
    animation: meshShift 12s ease-in-out infinite alternate;
    z-index: 0;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(1px 1px at 10% 20%, rgba(255, 255, 255, 0.35) 0%, transparent 100%),
        radial-gradient(1px 1px at 30% 70%, rgba(168, 85, 247, 0.4) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 60% 15%, rgba(6, 182, 212, 0.4) 0%, transparent 100%),
        radial-gradient(1px 1px at 80% 50%, rgba(255, 215, 0, 0.3) 0%, transparent 100%),
        radial-gradient(1px 1px at 45% 85%, rgba(224, 64, 251, 0.3) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 90% 30%, rgba(0, 255, 136, 0.25) 0%, transparent 100%);
    animation: sparkleFloat 8s linear infinite;
    z-index: 0;
    pointer-events: none;
}

/* ==========================================================================
   4. LAYOUT
   ========================================================================== */
.page-wrap {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--page-pad);
    padding-bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom, 0px));
    position: relative;
    z-index: 1;
    width: 100%;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--page-pad);
    padding-bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom, 0px));
    position: relative;
    z-index: 5;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
}

/* ==========================================================================
   5. HEADER
   ========================================================================== */
.header {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--panel-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(5, 5, 16, 0.85);
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
}

.header-title {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--gold), #ffaa00, var(--magenta));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 6s ease infinite;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    filter: drop-shadow(0 0 10px var(--gold-glow));
}

.balance-badge {
    background: rgba(255, 215, 0, 0.06);
    border: 1px solid rgba(255, 215, 0, 0.2);
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    color: var(--gold);
    font-weight: 800;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 0 15px var(--gold-glow), inset 0 0 10px rgba(255, 215, 0, 0.04);
    animation: balancePulse 3s ease-in-out infinite;
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   6. BOTTOM NAVIGATION
   ========================================================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(5, 5, 16, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-around;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--muted);
    cursor: pointer;
    font-size: 9px;
    font-weight: 700;
    transition: all .2s ease;
    width: 20%;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .3px;
    padding: 4px 0;
    border-radius: var(--radius-sm);
    text-decoration: none;
    position: relative;
}

.nav-icon { font-size: 19px; transition: transform .2s ease; }

.nav-item.active { color: var(--pink); }
.nav-item.active .nav-icon {
    transform: translateY(-2px) scale(1.1);
    filter: drop-shadow(0 0 8px var(--pink));
}
.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--pink);
    border-radius: 3px;
    box-shadow: 0 0 10px var(--pink), 0 0 20px rgba(255, 51, 102, 0.3);
}

.nav-badge {
    position: absolute;
    top: 0;
    right: 50%;
    transform: translateX(14px);
    background: linear-gradient(135deg, var(--pink), var(--magenta));
    color: #fff;
    font-size: 8px;
    font-weight: 800;
    min-width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    border-radius: 7px;
    padding: 0 3px;
    display: none;
    box-shadow: 0 2px 8px rgba(255, 51, 102, 0.4);
}
.nav-badge.show { display: block; }

/* ==========================================================================
   7. CARDS
   ========================================================================== */

/* Base panel card */
.card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.card-title {
    font-weight: 800;
    font-size: 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-desc {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 12px;
}

/* Game card (casino grid) */
.game-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-xl);
    padding: 22px 14px 18px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: var(--radius-xl);
    padding: 1px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.4), transparent 40%, transparent 60%, rgba(6, 182, 212, 0.4));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    transition: opacity .3s;
    opacity: .5;
}

.game-card:active {
    transform: scale(0.96);
    border-color: rgba(168, 85, 247, 0.5);
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.25), 0 4px 24px rgba(0, 0, 0, 0.4);
}
.game-card:active::before { opacity: 1; }

@media (hover: hover) {
    .game-card:hover {
        transform: scale(1.02) translateY(-2px);
        border-color: rgba(168, 85, 247, 0.5);
        box-shadow: 0 0 30px rgba(168, 85, 247, 0.25), 0 8px 32px rgba(0, 0, 0, 0.4);
    }
    .game-card:hover::before { opacity: 1; }
}

.game-card-icon {
    font-size: 40px;
    margin-bottom: 4px;
    filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.4));
    transition: transform .3s, filter .3s;
    position: relative;
    z-index: 1;
}
.game-card:active .game-card-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 0 20px rgba(168, 85, 247, 0.6));
}

.game-card-name {
    font-weight: 800;
    font-size: 13px;
    text-align: center;
    letter-spacing: .5px;
    position: relative;
    z-index: 1;
}

.game-card-desc {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    line-height: 1.4;
    position: relative;
    z-index: 1;
}

/* Platform card (order page) */
.platform-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    padding: 22px 14px;
    text-align: center;
    cursor: pointer;
    transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.platform-card:active {
    transform: scale(0.96);
    border-color: rgba(168, 85, 247, 0.5);
}

@media (hover: hover) {
    .platform-card:hover {
        transform: translateY(-2px);
        border-color: rgba(168, 85, 247, 0.5);
        box-shadow: 0 0 25px rgba(168, 85, 247, 0.2), 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

.platform-card-icon {
    font-size: 38px;
    margin-bottom: 8px;
    filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.3));
}
.platform-card-name { font-weight: 800; font-size: 14px; letter-spacing: .3px; }
.platform-card-desc { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ==========================================================================
   8. BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, opacity .15s;
    color: #fff;
    text-align: center;
    width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--magenta));
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
}
.btn-gold {
    background: linear-gradient(135deg, #d4a017, #ffd700);
    color: #1a1a2e;
}
.btn-cyan {
    background: linear-gradient(135deg, #0891b2, #06b6d4);
}
.btn-green {
    background: linear-gradient(135deg, #059669, #10b981);
}
.btn-purple {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
}

.btn-sm { width: auto; padding: 10px 16px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }
.btn-block { width: 100%; }

.btn-link {
    background: none;
    border: none;
    color: var(--cyan);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    width: auto;
}
.btn-link:active { opacity: .7; }

/* ==========================================================================
   9. INPUTS & FORMS
   ========================================================================== */
.glass-input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.glass-input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
}
.glass-input::placeholder { color: var(--muted); font-weight: 400; }

.input-group { margin-bottom: 14px; }
.input-hint { font-size: 11px; color: var(--muted); margin-top: 4px; padding-left: 4px; }

.input-row { display: flex; gap: 8px; align-items: center; }

textarea.glass-input {
    resize: vertical;
    min-height: 50px;
    line-height: 1.5;
}

/* Preset chips */
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.preset-chip {
    padding: 8px 12px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    color: var(--text);
    background: rgba(255, 255, 255, 0.02);
    transition: border-color .15s, background .15s;
}
.preset-chip:active {
    border-color: var(--cyan);
    background: rgba(6, 182, 212, 0.05);
}

/* ==========================================================================
   10. TOAST NOTIFICATIONS
   ========================================================================== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-30px);
    background: rgba(10, 10, 26, 0.95);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s, visibility .3s, transform .3s;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}
.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
.toast.success {
    border-color: var(--success);
    color: var(--success);
    box-shadow: 0 0 20px var(--success-glow);
}
.toast.error {
    border-color: var(--danger);
    color: var(--danger);
    box-shadow: 0 0 20px rgba(255, 51, 102, 0.4);
}
.toast.warn {
    border-color: var(--warn);
    color: var(--warn);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
}

/* ==========================================================================
   11. LOADING STATES
   ========================================================================== */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    gap: 16px;
}

.loading-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
}
.loading-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    animation: dotBlink 1.4s infinite;
    box-shadow: 0 0 10px var(--primary-glow);
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }

.loading-text {
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Skeleton shimmer */
.skeleton {
    background: linear-gradient(90deg, var(--panel-bg) 25%, rgba(139, 92, 246, 0.08) 50%, var(--panel-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

/* ==========================================================================
   12. SECTION TITLES
   ========================================================================== */
.section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 12px;
    padding-left: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::before {
    content: '';
    width: 10px;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--cyan));
    border-radius: 2px;
}

/* ==========================================================================
   13. BADGES
   ========================================================================== */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
}
.badge-pending { background: rgba(251, 191, 36, 0.1); color: var(--warn); border: 1px solid rgba(251, 191, 36, 0.3); }
.badge-success { background: rgba(0, 255, 136, 0.08); color: var(--success); border: 1px solid rgba(0, 255, 136, 0.2); }
.badge-danger  { background: rgba(255, 51, 102, 0.08); color: var(--danger); border: 1px solid rgba(255, 51, 102, 0.2); }

.game-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, var(--pink), var(--magenta));
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(255, 51, 102, 0.5);
    animation: badgePulse 2s ease-in-out infinite;
    display: none;
    z-index: 2;
    letter-spacing: .5px;
    text-transform: uppercase;
}
.game-badge.show { display: block; }

/* ==========================================================================
   14. ANIMATIONS (KEYFRAMES)
   ========================================================================== */
@keyframes meshShift {
    0%  { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.05) rotate(.5deg); opacity: .85; }
    100%{ transform: scale(1) rotate(-.5deg); opacity: 1; }
}

@keyframes sparkleFloat {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-15px); }
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}

@keyframes balancePulse {
    0%, 100% { box-shadow: 0 0 15px var(--gold-glow), inset 0 0 10px rgba(255, 215, 0, 0.04); }
    50%      { box-shadow: 0 0 22px var(--gold-glow), inset 0 0 12px rgba(255, 215, 0, 0.06); }
}

@keyframes dotBlink {
    0%, 80%, 100% { opacity: .2; transform: scale(0.8); }
    40%           { opacity: 1; transform: scale(1.1); }
}

@keyframes badgePulse {
    0%, 100% { box-shadow: 0 2px 12px rgba(255, 51, 102, 0.5); transform: scale(1); }
    50%      { box-shadow: 0 2px 16px rgba(255, 51, 102, 0.7); transform: scale(1.05); }
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

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

@keyframes cardBorderPulse {
    0%, 100% { border-color: rgba(139, 92, 246, 0.2); }
    50%      { border-color: rgba(139, 92, 246, 0.35); }
}

/* ==========================================================================
   15. UTILITIES
   ========================================================================== */
.hidden { display: none !important; }
.fade-in { animation: fadeIn .3s ease; }
.text-gold { color: var(--gold); }
.text-cyan { color: var(--cyan); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.fw-900 { font-weight: 900; }
.fw-800 { font-weight: 800; }
.fw-700 { font-weight: 700; }
.font-display { font-family: 'Outfit', sans-serif; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-sm { gap: 6px; }
.gap-md { gap: 12px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 14px; }
.mb-lg { margin-bottom: 20px; }

@media (max-width: 360px) {
    .header-title {
        font-size: 17px;
        letter-spacing: .8px;
    }
    .balance-badge {
        padding: 6px 10px;
        font-size: 12px;
    }
    .nav-item {
        font-size: 8px;
        letter-spacing: 0;
    }
    .nav-icon {
        font-size: 18px;
    }
}
