:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --info: #0891b2;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); }

html, body { overflow-x: hidden; }

img, svg, canvas, video { max-width: 100%; height: auto; }

.bg-primary-gradient {
    background: linear-gradient(120deg, #1d4ed8, #2563eb 45%, #3b82f6);
}

.auth-bg {
    background: radial-gradient(circle at top left, #2563eb 0%, #0b1027 65%);
}
.auth-bg-admin {
    background: radial-gradient(circle at top left, #111827 0%, #030712 70%);
}
.auth-card { border-radius: 14px; }
.auth-logo {
    width: 72px; height: 72px; margin: 0 auto;
    border-radius: 18px;
    background: rgba(255,255,255,0.16);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}

.sidebar {
    width: 250px;
    min-height: calc(100vh - 56px);
    height: calc(100vh - 56px);
    max-height: calc(100vh - 56px);
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 1rem 0.75rem;
    position: sticky;
    top: 56px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}
.sidebar-nav { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-link {
    display: flex; align-items: center; gap: 0.75rem;
    text-decoration: none; padding: 0.62rem 0.75rem; border-radius: 10px;
    color: #334155; font-weight: 500; font-size: 0.92rem;
    transition: all 0.18s ease;
}
.sidebar-link:hover { background: #f1f5f9; color: #0f172a; }
.sidebar-link.active {
    background: linear-gradient(90deg, rgba(37,99,235,0.12), rgba(37,99,235,0.04));
    color: #1d4ed8;
    border: 1px solid rgba(37,99,235,0.2);
}
.sidebar-link i { width: 18px; text-align: center; }

.mobile-nav-list {
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 0.7rem;
}

.mobile-nav-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    max-height: 52vh;
    overflow-y: auto;
}

.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #e2e8f0;
    background: rgba(15, 23, 42, 0.28);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 9px;
    padding: 0.52rem 0.58rem;
    font-size: 0.84rem;
    font-weight: 500;
}

.mobile-nav-link:hover,
.mobile-nav-link:focus {
    color: #fff;
    background: rgba(15, 23, 42, 0.4);
}

.mobile-nav-link i {
    width: 16px;
    text-align: center;
}

.mobile-nav-link.active {
    border-color: rgba(147, 197, 253, 0.8);
    background: rgba(30, 64, 175, 0.36);
    color: #fff;
}

.mobile-nav-link-danger {
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.45);
    background: rgba(127, 29, 29, 0.34);
}

.main-content { min-height: calc(100vh - 56px - 57px); }

.stat-card {
    border-radius: 14px;
    color: #fff;
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
}
.stat-card-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
}
.stat-card-value { font-size: 1.25rem; font-weight: 700; }
.stat-card-label { font-size: 0.8rem; opacity: 0.88; }
.stat-card-sub { font-size: 0.75rem; }
.stat-card-primary { background: linear-gradient(135deg, #2563eb, #1e40af); }
.stat-card-success { background: linear-gradient(135deg, #22c55e, #15803d); }
.stat-card-info { background: linear-gradient(135deg, #06b6d4, #0e7490); }
.stat-card-warning { background: linear-gradient(135deg, #f59e0b, #b45309); }

.daily-earning-card {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: #111827;
}
.daily-earning-card .stat-card-icon {
    background: rgba(17, 24, 39, 0.08);
    color: #111827;
}
.daily-earning-card .stat-card-label,
.daily-earning-card .stat-card-value,
.daily-earning-card .stat-card-sub a {
    color: #111827;
}
.daily-earning-card .stat-card-sub a {
    opacity: 0.8;
}

.total-downline-card {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: #111827;
}
.total-downline-card .stat-card-icon {
    background: rgba(17, 24, 39, 0.08);
    color: #111827;
}
.total-downline-card .stat-card-label,
.total-downline-card .stat-card-value,
.total-downline-card .stat-card-sub a {
    color: #111827;
}
.total-downline-card .stat-card-sub a {
    opacity: 0.8;
}

.bg-primary-soft { background: rgba(37,99,235,0.12); }
.bg-success-soft { background: rgba(34,197,94,0.12); }
.bg-info-soft { background: rgba(14,165,233,0.12); }
.bg-warning-soft { background: rgba(245,158,11,0.18); }
.bg-danger-soft { background: rgba(220,38,38,0.12); }

.icon-badge {
    width: 26px; height: 26px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
}

.bv-card { background: #f8fafc; border: 1px solid #e2e8f0; }
.tree-grid { display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.tree-level { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }
.tree-node {
    min-width: 150px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0.6rem;
    background: #fff;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.tree-node.empty { border-style: dashed; color: #94a3b8; }

.card { border-radius: 14px; }
.card-header { border-bottom: 1px solid #e2e8f0; }

.table > :not(caption) > * > * { padding: 0.7rem 0.75rem; vertical-align: middle; }
.table thead th { font-size: 0.78rem; color: #64748b; text-transform: uppercase; letter-spacing: .02em; }

.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table-responsive .table {
    min-width: 640px;
}

.card {
    overflow: hidden;
}

.footer { background: #fff !important; }

@media (max-width: 991.98px) {
    .main-content { width: 100%; }
    .sidebar { display: none !important; }
}

@media (max-width: 1199.98px) {
    .sidebar {
        width: 228px;
    }
}

@media (max-width: 991.98px) {
    .navbar .navbar-brand {
        font-size: 1rem !important;
        max-width: calc(100vw - 100px);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .navbar .navbar-brand img {
        width: 32px;
        height: 32px;
    }

    #userNav {
        background: rgba(15, 23, 42, 0.32);
        margin-top: 0.6rem;
        border-radius: 12px;
        padding: 0.45rem;
        backdrop-filter: blur(4px);
    }

    #userNav .nav-link {
        padding: 0.58rem 0.7rem;
        border-radius: 8px;
    }

    #userNav .navbar-nav {
        gap: 0.2rem !important;
        margin-bottom: 0.5rem;
    }

    #userNav .dropdown-menu {
        width: 100%;
    }

    .main-content {
        padding: 0.9rem !important;
    }

    .container-fluid.px-3.pt-3 {
        padding-left: 0.8rem !important;
        padding-right: 0.8rem !important;
        padding-top: 0.8rem !important;
    }

    .stat-card {
        padding: 0.85rem;
        gap: 0.6rem;
    }

    .stat-card-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }

    .stat-card-value {
        font-size: 1.08rem;
    }

    .tree-node {
        min-width: 132px;
        padding: 0.5rem;
    }

    .card-header,
    .card-body {
        padding-left: 0.9rem;
        padding-right: 0.9rem;
    }

    .footer .container-fluid {
        padding-left: 0.9rem !important;
        padding-right: 0.9rem !important;
    }

    .footer .d-flex {
        justify-content: center !important;
        text-align: center;
    }
}

@media (max-width: 575.98px) {
    body {
        font-size: 0.94rem;
    }

    .navbar .navbar-brand {
        font-size: 0.95rem !important;
        gap: 0.4rem !important;
    }

    .main-content {
        padding: 0.75rem !important;
    }

    .card {
        border-radius: 12px;
    }

    .card-header {
        font-size: 0.9rem;
    }

    .table > :not(caption) > * > * {
        padding: 0.56rem 0.58rem;
        font-size: 0.84rem;
    }

    .badge,
    .btn,
    .form-control,
    .form-select {
        font-size: 0.9rem;
    }

    .stat-card {
        border-radius: 12px;
    }

    .stat-card-value {
        font-size: 1rem;
    }

    .tree-level {
        gap: 0.55rem;
    }

    .tree-node {
        min-width: 118px;
        font-size: 0.8rem;
    }

    .table-responsive .table {
        min-width: 560px;
    }

    .mobile-nav-grid {
        grid-template-columns: 1fr;
    }

    .table-responsive .table.table-mobile-stack {
        min-width: 100%;
        border-collapse: separate;
        border-spacing: 0;
    }

    .table-responsive .table.table-mobile-stack thead {
        display: none;
    }

    .table-responsive .table.table-mobile-stack tbody,
    .table-responsive .table.table-mobile-stack tr,
    .table-responsive .table.table-mobile-stack td {
        display: block;
        width: 100%;
    }

    .table-responsive .table.table-mobile-stack tbody tr {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        margin: 0 0 0.7rem;
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    .table-responsive .table.table-mobile-stack tbody td {
        border: 0;
        border-bottom: 1px dashed #e2e8f0;
        padding: 0.58rem 0.7rem;
        text-align: right;
        position: relative;
        white-space: normal;
        word-break: break-word;
    }

    .table-responsive .table.table-mobile-stack tbody td:last-child {
        border-bottom: 0;
    }

    .table-responsive .table.table-mobile-stack tbody td::before {
        content: attr(data-label);
        float: left;
        color: #64748b;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        margin-right: 0.65rem;
    }
}
