:root {
    --app-primary: #0d6efd;
    --app-sidebar-bg: #111827;
    --app-sidebar-text: #d1d5db;
    --app-sidebar-active: #ffffff;
    --app-body-bg: #f3f4f6;
}

body {
    background: var(--app-body-bg);
    font-size: 14px;
}

.app-wrapper {
    min-height: 100vh;
    display: flex;
}

.app-sidebar {
    width: 260px;
    min-height: 100vh;
    background: var(--app-sidebar-bg);
    color: var(--app-sidebar-text);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
}

.app-sidebar .brand {
    padding: 20px;
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.app-sidebar .brand small {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: #9ca3af;
    margin-top: 4px;
}

.app-sidebar .nav-section {
    padding: 16px 16px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #9ca3af;
}

.app-sidebar a {
    display: block;
    padding: 10px 18px;
    color: var(--app-sidebar-text);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.app-sidebar a:hover,
.app-sidebar a.active {
    background: rgba(255,255,255,0.08);
    color: var(--app-sidebar-active);
    border-left-color: var(--app-primary);
}

.app-main {
    margin-left: 260px;
    width: calc(100% - 260px);
    min-height: 100vh;
}

.app-topbar {
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-content {
    padding: 24px;
}

.stat-card {
    border: 0;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

.stat-card .label {
    color: #6b7280;
    font-size: 13px;
}

.stat-card .value {
    font-size: 26px;
    font-weight: 700;
}

.card {
    border: 0;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

.table th {
    background: #f9fafb;
    font-size: 13px;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
}

.badge-soft-pending {
    background: #fff7ed;
    color: #c2410c;
}

.badge-soft-active,
.badge-soft-approved,
.badge-soft-paid {
    background: #ecfdf5;
    color: #047857;
}

.badge-soft-rejected,
.badge-soft-suspended {
    background: #fef2f2;
    color: #b91c1c;
}

.badge-soft-default {
    background: #f3f4f6;
    color: #374151;
}

@media (max-width: 991px) {
    .app-sidebar {
        position: relative;
        width: 100%;
        min-height: auto;
    }

    .app-wrapper {
        display: block;
    }

    .app-main {
        margin-left: 0;
        width: 100%;
    }
}

/*
|--------------------------------------------------------------------------
| Phase 4: Mobile-Friendly Collapsible Sidebar
|--------------------------------------------------------------------------
*/

.sidebar-brand {
    padding: 20px;
    color: #ffffff;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand .brand-title {
    font-size: 20px;
    font-weight: 700;
}

.sidebar-brand .brand-subtitle {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
}

.sidebar-user {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user .user-name {
    color: #ffffff;
    font-weight: 600;
}

.sidebar-user .user-code {
    color: #9ca3af;
    font-size: 12px;
    margin-top: 2px;
}

.sidebar-menu {
    padding: 10px 0 20px;
}

.sidebar-group {
    margin: 4px 10px;
}

.sidebar-group-toggle {
    width: 100%;
    border: 0;
    background: transparent;
    color: #e5e7eb;
    padding: 11px 10px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.02em;
}

.sidebar-group-toggle:hover,
.sidebar-group-toggle:not(.collapsed) {
    background: rgba(255,255,255,0.08);
    color: #ffffff;
}

.sidebar-icon {
    display: inline-block;
    width: 22px;
    margin-right: 4px;
}

.sidebar-chevron {
    transition: transform 0.2s ease;
    color: #9ca3af;
}

.sidebar-group-toggle:not(.collapsed) .sidebar-chevron {
    transform: rotate(180deg);
    color: #ffffff;
}

.sidebar-group-items {
    padding: 3px 0 7px;
}

.app-sidebar .sidebar-link {
    margin: 2px 0 2px 14px;
    padding: 9px 12px;
    border-radius: 9px;
    border-left: 3px solid transparent;
    font-size: 13px;
}

.app-sidebar .sidebar-link.active {
    font-weight: 700;
}

@media (max-width: 991px) {
    .app-sidebar {
        max-height: 48vh;
        overflow-y: auto;
        border-bottom: 1px solid rgba(255,255,255,0.12);
    }

    .sidebar-brand,
    .app-sidebar .brand {
        padding: 14px 18px;
    }

    .sidebar-user {
        padding: 10px 18px;
    }

    .sidebar-menu {
        padding-bottom: 12px;
    }

    .sidebar-group-toggle {
        padding: 10px 12px;
    }

    .app-topbar {
        padding: 12px 16px;
        gap: 10px;
        align-items: flex-start;
    }

    .app-topbar > div:last-child {
        font-size: 12px;
    }

    .app-content {
        padding: 16px;
    }
}

/*
|--------------------------------------------------------------------------
| Phase 5A: App-like Loading Overlay
|--------------------------------------------------------------------------
*/

.page-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.82);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.page-loading-overlay.show {
    display: flex;
}

.page-loading-box {
    width: min(320px, 92vw);
    background: #ffffff;
    border-radius: 18px;
    padding: 24px 20px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}

.page-loading-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--app-primary);
    border-radius: 50%;
    animation: pageLoadingSpin 0.8s linear infinite;
    margin: 0 auto 14px;
}

.page-loading-title {
    font-weight: 800;
    color: #111827;
    margin-bottom: 4px;
}

.page-loading-text {
    color: #6b7280;
    font-size: 13px;
}

@keyframes pageLoadingSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@media (max-width: 991px) {
    .page-loading-box {
        border-radius: 20px;
        padding: 26px 20px;
    }
}



/*
|--------------------------------------------------------------------------
| Phase 5B: Distributor Native-Style Mobile Menu
|--------------------------------------------------------------------------
*/

.user-mobile-topbar {
    display: none;
}

.user-mobile-offcanvas {
    background: var(--app-sidebar-bg);
    color: var(--app-sidebar-text);
    width: min(88vw, 340px);
}

.user-mobile-offcanvas .offcanvas-header {
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.user-mobile-offcanvas .offcanvas-title {
    color: #ffffff;
    font-weight: 800;
}

.mobile-menu-subtitle {
    color: #9ca3af;
    font-size: 12px;
    margin-top: 2px;
}

.mobile-menu-user-card {
    padding: 12px 14px;
    margin-bottom: 10px;
    border-radius: 14px;
    background: rgba(255,255,255,0.07);
}

.mobile-menu-user-name {
    color: #ffffff;
    font-weight: 700;
}

.mobile-menu-user-meta {
    color: #9ca3af;
    font-size: 12px;
    margin-top: 2px;
}

.user-top-logout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 12px;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    text-decoration: none;
    font-weight: 800;
    font-size: 12px;
    white-space: nowrap;
}

.user-top-logout-button:hover {
    background: #fecaca;
    color: #7f1d1d;
}

@media (max-width: 991px) {
    .user-desktop-sidebar,
    .user-desktop-topbar {
        display: none !important;
    }

    .user-mobile-topbar {
        position: sticky;
        top: 0;
        z-index: 1010;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 12px;
        background: #ffffff;
        border-bottom: 1px solid #e5e7eb;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    }

    .user-mobile-menu-button {
        border: 0;
        border-radius: 999px;
        background: var(--app-primary);
        color: #ffffff;
        padding: 8px 13px;
        font-weight: 800;
        font-size: 13px;
        white-space: nowrap;
    }

    .user-mobile-title {
        min-width: 0;
        flex: 1;
        text-align: center;
    }

    .user-mobile-page-title {
        color: #111827;
        font-weight: 800;
        font-size: 14px;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-mobile-member-code {
        color: #6b7280;
        font-size: 11px;
        margin-top: 1px;
    }

    .user-app-main {
        margin-left: 0;
        width: 100%;
    }

    .user-mobile-offcanvas .sidebar-menu {
        padding: 0 0 20px;
    }

    .user-mobile-offcanvas .sidebar-group {
        margin-left: 0;
        margin-right: 0;
    }

    .user-mobile-offcanvas .sidebar-link {
        margin-left: 12px;
    }
}


/*
|--------------------------------------------------------------------------
| Phase 5C: Distributor Dashboard App-Style Quick Actions
|--------------------------------------------------------------------------
*/

.app-quick-actions-card {
    overflow: hidden;
}

.app-quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
}

.app-quick-action {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 104px;
    padding: 14px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    background: #ffffff;
    color: #111827 !important;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.app-quick-action:hover,
.app-quick-action:focus {
    color: #111827 !important;
    transform: translateY(-2px);
    border-color: var(--app-primary);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.10);
}

.app-quick-action-icon {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    background: rgba(13, 110, 253, 0.09);
    font-size: 22px;
    margin-bottom: 8px;
}

.app-quick-action-label {
    font-weight: 800;
    font-size: 13px;
    line-height: 1.1;
}

.app-quick-action-subtitle {
    color: #6b7280;
    font-size: 11px;
    margin-top: 4px;
    text-align: center;
    line-height: 1.2;
}

.app-quick-action-anchor {
    cursor: pointer;
}

#qualification-reserve-wallet {
    scroll-margin-top: 18px;
}

@media (max-width: 1199px) {
    .app-quick-actions-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 575px) {
    .app-quick-actions-card .card-header {
        align-items: flex-start !important;
        gap: 8px;
    }

    .app-quick-actions-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .app-quick-action {
        min-height: 98px;
        padding: 12px 8px;
        border-radius: 16px;
    }

    .app-quick-action-icon {
        width: 38px;
        height: 38px;
        border-radius: 14px;
        font-size: 20px;
        margin-bottom: 7px;
    }
}

/*
|--------------------------------------------------------------------------
| Phase 8A / Phase 8G-1: Distributor 5x3 Placement Tree
|--------------------------------------------------------------------------
*/

.placement-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.placement-tree-card {
    overflow: hidden;
}

.placement-tree-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    padding: 22px 18px 28px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    background:
        radial-gradient(circle at top left, rgba(13, 110, 253, 0.08), transparent 28%),
        linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

/*
|--------------------------------------------------------------------------
| Reachable Tree Canvas
|--------------------------------------------------------------------------
| Nested 5-wide branches are centered underneath their parent cards.
| Without side room, a deeply-expanded left branch can visually extend into
| negative horizontal space that a browser cannot scroll to.
|
| The side padding creates real, scrollable canvas space on both sides.
|--------------------------------------------------------------------------
*/

.placement-tree-stage {
    min-width: 1040px;
    box-sizing: content-box;
    padding-left: 420px;
    padding-right: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.placement-root-wrap {
    display: flex;
    justify-content: center;
}

.placement-member-card,
.placement-empty-card {
    width: 168px;
    min-height: 154px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 11px 9px;
    text-align: center;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    position: relative;
}

.placement-root-card {
    width: 198px;
    min-height: 166px;
    border-color: rgba(13, 110, 253, 0.35);
    background: linear-gradient(180deg, #ffffff 0%, #f0f7ff 100%);
    box-shadow: 0 12px 28px rgba(13, 110, 253, 0.14);
}

.placement-avatar,
.placement-empty-icon {
    width: 38px;
    height: 38px;
    margin: 0 auto 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 110, 253, 0.12);
    color: var(--app-primary);
    font-size: 19px;
    font-weight: 800;
}

.placement-avatar-root {
    width: 44px;
    height: 44px;
    background: rgba(13, 110, 253, 0.18);
    font-size: 21px;
}

.placement-member-code {
    font-size: 13px;
    font-weight: 900;
    color: #111827;
    line-height: 1.15;
}

.placement-member-name {
    margin-top: 3px;
    font-size: 11px;
    color: #374151;
    line-height: 1.2;
    min-height: 27px;
}

.placement-member-meta,
.placement-level-counts {
    margin-top: 5px;
    font-size: 10px;
    color: #6b7280;
    line-height: 1.3;
}

.placement-badges {
    margin-top: 6px;
    display: flex;
    gap: 3px;
    justify-content: center;
    flex-wrap: wrap;
}

.placement-badges .badge {
    font-size: 10px;
}

.placement-connector-line {
    width: 2px;
    height: 26px;
    background: #cbd5e1;
    margin: 0 auto;
}

.placement-connector-line-small {
    height: 22px;
}

.placement-slots-row {
    display: grid;
    grid-template-columns: repeat(5, 176px);
    gap: 18px;
    justify-content: center;
    align-items: start;
    position: relative;
}

.placement-slots-row::before {
    content: "";
    position: absolute;
    top: 0;
    left: 88px;
    right: 88px;
    height: 2px;
    background: #cbd5e1;
}

.placement-slots-row-nested {
    margin-top: 0;
    grid-template-columns: repeat(5, 168px);
    gap: 16px;
}

.placement-slot {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.placement-slot-line {
    width: 2px;
    height: 19px;
    background: #cbd5e1;
    margin-bottom: 5px;
}

.placement-slot-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    padding: 2px 7px;
    margin-bottom: 6px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-weight: 800;
    font-size: 10px;
}

.placement-slot-empty .placement-slot-label {
    background: #ecfdf5;
    color: #047857;
}

.placement-empty-card {
    min-height: 132px;
    border-style: dashed;
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.placement-empty-card .small {
    color: #047857 !important;
}

.placement-system-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: #4b5563;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.15;
}

.placement-expand-btn {
    margin-top: 8px;
    border-radius: 999px;
    font-weight: 700;
}

.placement-final-level {
    margin-top: 8px;
}

.placement-branch-container {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.18s ease;
    will-change: transform;
}

@media (max-width: 991px) {
    .placement-tree-scroll {
        padding: 16px 10px 24px;
    }

    .placement-tree-stage {
        min-width: 800px;
        padding-left: 300px;
        padding-right: 300px;
    }

    .placement-member-card,
    .placement-empty-card {
        width: 146px;
        min-height: 142px;
        border-radius: 14px;
        padding: 9px 7px;
    }

    .placement-empty-card {
        min-height: 118px;
    }

    .placement-root-card {
        width: 168px;
        min-height: 150px;
    }

    .placement-avatar,
    .placement-empty-icon {
        width: 34px;
        height: 34px;
        margin-bottom: 5px;
        font-size: 17px;
    }

    .placement-avatar-root {
        width: 39px;
        height: 39px;
        font-size: 19px;
    }

    .placement-member-code {
        font-size: 12px;
    }

    .placement-member-name {
        font-size: 10px;
        min-height: 24px;
    }

    .placement-member-meta,
    .placement-level-counts {
        font-size: 9px;
        margin-top: 4px;
    }

    .placement-badges {
        margin-top: 5px;
    }

    .placement-badges .badge {
        font-size: 9px;
        padding: 4px 6px;
    }

    .placement-slots-row {
        grid-template-columns: repeat(5, 154px);
        gap: 12px;
    }

    .placement-slots-row::before {
        left: 77px;
        right: 77px;
    }

    .placement-slots-row-nested {
        grid-template-columns: repeat(5, 146px);
        gap: 12px;
    }

    .placement-slot-label {
        min-width: 50px;
        font-size: 9px;
        margin-bottom: 5px;
    }

    .placement-expand-btn {
        margin-top: 7px;
        font-size: 10px;
        padding: 4px 9px;
    }

    .placement-system-only {
        font-size: 9px;
        padding: 4px 7px;
    }
}

@media (max-width: 575px) {
    .placement-toolbar {
        gap: 6px;
    }

    .placement-toolbar .btn {
        font-size: 11px;
        padding: 5px 8px;
    }

    .placement-tree-stage {
        min-width: 790px;
        padding-left: 300px;
        padding-right: 300px;
    }
}
