:root {
    --bg-color: #09090b;
    --sidebar-bg: #09090b;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --gradient-main: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --sidebar-width: 260px;
    --header-height: 64px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    overflow-x: hidden;
    background-image: radial-gradient(circle at 10% 10%, rgba(99, 102, 241, 0.05) 0%, transparent 40%);
}

/* Auth Pages (Login/Register) */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: rgba(20, 20, 25, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo {
    font-size: 2rem;
    font-weight: 800;
    background: var(--gradient-main);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
    display: block;
}

.auth-title {
    font-size: 1.1rem;
    color: var(--text-main);
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

select.form-control option {
    background-color: #1a1a20;
    color: var(--text-main);
}

.btn-block {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: var(--gradient-main);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-block:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--card-border);
    position: fixed;
    height: 100vh;
    height: 100dvh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    font-size: 1.4rem;
    font-weight: 800;
    color: white;
    margin-bottom: 32px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    letter-spacing: 0.5px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
}

.menu-item {
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

.menu-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
    border-color: rgba(99, 102, 241, 0.2);
}

.menu-item i {
    font-size: 1.3rem;
    opacity: 0.9;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 30px;
}

/* Top Header in Dashboard */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

/* User Profile Dropdown */
.user-profile-wrapper {
    position: relative;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 99px;
    border: 1px solid var(--card-border);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.user-profile:hover, .user-profile.active {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 220px;
    background: #18181b;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 8px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
}

.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 8px;
}

.dropdown-username {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

.dropdown-email {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 500;
}

.dropdown-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-main);
}

.dropdown-item.danger {
    color: #f87171;
}

.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.dropdown-divider {
    height: 1px;
    background: var(--card-border);
    margin: 8px 0;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gradient-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
}

.card-header {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(145deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    border-color: rgba(255,255,255,0.15);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

.stat-title {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: white;
}

/* API Key Section */
.api-key-box {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--card-border);
}

.api-key-wrapper {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.api-key-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.95rem;
    transition: all 0.2s;
    letter-spacing: 1px;
}

.api-key-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
    color: var(--text-main);
    outline: none;
}

.api-key-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.api-key-tip {
    font-size: 0.85rem;
    color: var(--warning-color);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 4px;
}

.btn-danger-outline {
    padding: 6px 14px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.05);
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
    color: var(--danger-color);
}


/* Tables */
.table-scroll-container {
    max-height: 320px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--card-border) transparent;
}

.table-scroll-container::-webkit-scrollbar {
    width: 6px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background-color: var(--card-border);
    border-radius: 3px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: 16px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--card-border);
}

.table td {
    padding: 16px;
    border-bottom: 1px solid var(--card-border);
    color: var(--text-main);
}

.badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* Mobile Menu Button */
.mobile-menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    padding: 4px;
    margin-right: 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Recharge & Feedback Grids */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.plan-grid {
    margin-bottom: 30px;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.pay-methods-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { 
        transform: translateX(-100%); 
        transition: transform 0.3s;
        box-shadow: 5px 0 15px rgba(0,0,0,0.5);
        z-index: 1000; /* Ensure sidebar is on top */
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 16px; } /* Reduced padding for mobile */
    
    .mobile-menu-btn {
        display: block;
    }

    /* Mobile Grid Adjustments */
    .content-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .plan-grid {
        grid-template-columns: 1fr;
    }

    .pay-methods-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-card {
        padding: 16px;
        gap: 15px;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
    
    .card {
        padding: 16px; /* Further reduce card padding on mobile */
    }

    /* Mobile Header Adjustments */
    .user-profile span:nth-of-type(1),
    .user-profile .mdi-chevron-down {
        display: none;
    }
    
    .user-profile {
        padding: 4px;
        border: none;
        background: transparent;
    }
    
    .user-profile:hover, .user-profile.active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .user-dropdown {
        width: 200px; /* Reduce dropdown width on mobile */
    }

    /* Mobile API Key Section Adjustments */
    .card-header {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .api-key-box {
        padding: 12px; /* Reduce box padding */
    }
    
    .api-key-wrapper {
        gap: 8px; /* Reduce gap between input and buttons */
    }
    
    .api-key-input {
        min-width: 0; /* Allow input to shrink below default width */
        font-size: 0.8rem;
        padding: 8px 10px;
        letter-spacing: 0; /* Remove letter spacing to save space */
    }
    
    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .pay-methods-grid {
        grid-template-columns: 1fr;
    }
}

/* Fix Layui Popup Visibility - Ensure text is dark on white backgrounds */
.layui-layer {
    color: #333 !important;
}
.layui-layer-content {
    color: #333 !important;
}
.layui-layer-title {
    color: #333 !important;
    border-bottom-color: #eee !important;
}
.layui-layer-btn .layui-layer-btn0 {
    border-color: var(--primary-color) !important;
    background-color: var(--primary-color) !important;
    color: #fff !important;
}
.layui-layer-btn .layui-layer-btn1 {
    border-color: #dedede !important;
    background-color: #fff !important;
    color: #333 !important;
}