/* Jomlak User Portal */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #06b6d4;
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e1b4b;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --error: #ef4444;
    --success: #10b981;
    --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --radius: 16px;
}

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

body {
    margin: 0;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 50%, #312e81 100%);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.6;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-dark);
}

/* Layout */
.user-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.user-header {
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 100;
}

.user-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.25rem;
}

.user-logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.user-header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-header-nav a,
.user-header-nav button {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.user-header-nav a:hover,
.user-header-nav button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.user-main {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
}

/* Auth Card */
.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem;
    animation: fadeUp 0.5s ease;
}

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

.auth-card-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-card-header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

.auth-card-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.auth-brand {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    font-size: 2rem;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

/* Form */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--surface-muted);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
    background: var(--surface);
}

.form-control.is-invalid {
    border-color: var(--error);
}

.invalid-feedback {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.form-check label {
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

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

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger-outline {
    background: transparent;
    border: 2px solid var(--error);
    color: var(--error);
}

.btn-danger-outline:hover {
    background: var(--error);
    color: #fff;
}

.alert {
    padding: 0.875rem 1rem;
    border-radius: 12px;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

/* Profile */
.profile-container {
    width: 100%;
    max-width: 720px;
}

.profile-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: fadeUp 0.5s ease;
}

.profile-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 2.5rem 2rem;
    text-align: center;
    color: #fff;
    position: relative;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.3);
    object-fit: cover;
    margin: 0 auto 1rem;
    display: block;
    background: rgba(255, 255, 255, 0.2);
}

.profile-avatar-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.3);
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    font-size: 2.5rem;
}

.profile-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
    font-weight: 700;
}

.profile-header .username {
    opacity: 0.85;
    font-size: 0.95rem;
}

.profile-body {
    padding: 2rem;
}

.profile-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border);
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}

@media (max-width: 600px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }
}

.profile-field {
    background: var(--surface-muted);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.profile-field-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.profile-field-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.profile-field-value.empty {
    color: var(--text-muted);
    font-weight: 400;
    font-style: italic;
}

.profile-about {
    margin-top: 1.5rem;
    background: var(--surface-muted);
    padding: 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.profile-actions {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.affiliate-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--accent), #0891b2);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.75rem;
}

.user-footer {
    text-align: center;
    padding: 1.5rem;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85rem;
}

.logout-form {
    display: inline;
}

.user-header-nav a.is-active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 8px;
}

.user-header-username {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
}

.user-nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.user-nav-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    margin: 0 auto;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

.user-nav-toggle.is-open .user-nav-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.user-nav-toggle.is-open .user-nav-toggle-bar:nth-child(2) {
    opacity: 0;
}

.user-nav-toggle.is-open .user-nav-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Dashboard */
.dashboard-container {
    width: 100%;
    max-width: 960px;
}

.dashboard-header {
    margin-bottom: 2rem;
    color: #fff;
}

.dashboard-header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
    font-weight: 700;
}

.dashboard-header p {
    margin: 0;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.95rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card-accent {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
}

.stat-card-accent .stat-label {
    color: rgba(255, 255, 255, 0.85);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.info-banner {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 0.875rem 1.25rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.dashboard-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    animation: fadeUp 0.5s ease;
}

.dashboard-section-title {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}

.dashboard-section-desc {
    margin: 0 0 1.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.base-report-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.base-report-card:last-child {
    margin-bottom: 0;
}

.base-report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}

.base-report-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.base-report-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

.base-report-badge {
    background: linear-gradient(135deg, var(--accent), #0891b2);
    color: #fff;
    padding: 0.4rem 0.875rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.chapter-table-wrap,
.referrals-table-wrap {
    overflow-x: auto;
}

.chapter-table,
.referrals-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.chapter-table th,
.chapter-table td,
.referrals-table th,
.referrals-table td {
    padding: 0.75rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.chapter-table th,
.referrals-table th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
}

.chapter-table tbody tr:last-child td,
.referrals-table tbody tr:last-child td {
    border-bottom: none;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    padding: 0.15rem 0.5rem;
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary-dark);
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.status-active {
    background: #ecfdf5;
    color: #047857;
}

.status-idle {
    background: #f1f5f9;
    color: #64748b;
}

.text-muted {
    color: var(--text-muted);
    font-style: italic;
}

.empty-state {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 3rem 2rem;
    text-align: center;
}

.empty-state-sm {
    padding: 1.5rem;
    box-shadow: none;
    border: 1px dashed var(--border);
    border-radius: 12px;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
}

.empty-state p {
    margin: 0;
    color: var(--text-muted);
}

.back-link {
    display: inline-block;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
}

.back-link:hover {
    color: #fff;
}

.stats-link {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}

.stats-link:hover {
    background: rgba(99, 102, 241, 0.18);
}

.count-badge-link {
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, transform 0.15s;
}

.count-badge-link:hover {
    background: rgba(99, 102, 241, 0.22);
    transform: scale(1.05);
}

.base-report-badge {
    border: none;
    cursor: default;
    font-family: inherit;
}

button.base-report-badge {
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

button.base-report-badge:hover {
    opacity: 0.92;
    transform: scale(1.02);
}

.base-report-badge-muted {
    background: #94a3b8;
}

.user-stats-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.user-stats-identity {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    flex: 1;
    min-width: 240px;
}

.user-stats-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
}

.user-stats-identity h2 {
    margin: 0 0 0.15rem;
    font-size: 1.2rem;
}

.user-stats-username {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.user-stats-total {
    min-width: 160px;
}

.user-modal-open {
    overflow: hidden;
}

.user-modal[hidden] {
    display: none;
}

.user-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.user-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

.user-modal-dialog {
    position: relative;
    width: min(480px, 100%);
    max-height: min(70vh, 520px);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    animation: fadeUp 0.25s ease;
}

.user-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.user-modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.user-modal-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
}

.user-modal-close:hover {
    color: var(--text);
}

.user-modal-body {
    padding: 1rem 1.25rem 1.25rem;
    overflow-y: auto;
}

.user-modal-loading,
.user-modal-empty,
.user-modal-error {
    margin: 0;
    text-align: center;
    color: var(--text-muted);
    padding: 1rem 0;
}

.user-modal-error {
    color: var(--error);
}

.player-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.player-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.player-list-item:last-child {
    border-bottom: none;
}

.player-list-name {
    font-weight: 500;
    color: var(--text);
}

.player-list-name:hover {
    color: var(--primary);
}

.player-username {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 0.1rem;
}

/* Referral tree */
.referral-tree-wrap {
    overflow-x: auto;
    padding: 0.5rem 0 1rem;
}

.referral-tree {
    display: inline-block;
    min-width: 100%;
    text-align: center;
}

.referral-tree ul {
    position: relative;
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    margin: 0;
    padding: 1rem 0 0;
    list-style: none;
}

.referral-tree > ul {
    padding-top: 0;
}

.referral-tree li {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.3rem 0;
    list-style: none;
}

.referral-tree li::before,
.referral-tree li::after {
    content: '';
    position: absolute;
    top: 0;
    width: 50%;
    height: 1rem;
    border-top: 2px solid #cbd5e1;
}

.referral-tree li::before {
    right: 50%;
    border-left: 2px solid #cbd5e1;
    border-radius: 0 8px 0 0;
}

.referral-tree li::after {
    left: 50%;
    border-right: 2px solid #cbd5e1;
    border-radius: 8px 0 0 0;
}

.referral-tree li:only-child::before,
.referral-tree li:only-child::after {
    display: none;
}

.referral-tree li:first-child::before,
.referral-tree li:last-child::after {
    border: none;
}

.referral-tree li:first-child::after {
    border-right: 2px solid #cbd5e1;
    border-top: 2px solid #cbd5e1;
    border-radius: 8px 0 0 0;
}

.referral-tree li:last-child::before {
    border-left: 2px solid #cbd5e1;
    border-top: 2px solid #cbd5e1;
    border-radius: 0 8px 0 0;
}

.referral-tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 0;
    height: 1rem;
    border-left: 2px solid #cbd5e1;
}

.referral-tree-node {
    position: relative;
    z-index: 1;
    min-width: 100px;
    max-width: 130px;
    padding: 0.45rem 0.55rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    text-align: center;
}

.referral-tree-node-root {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: transparent;
    color: #fff;
}

.referral-tree-node-root .referral-tree-node-meta,
.referral-tree-node-root .referral-tree-node-username {
    color: rgba(255, 255, 255, 0.85);
}

.referral-tree-node-active {
    border-color: rgba(16, 185, 129, 0.35);
    background: #ecfdf5;
}

.referral-tree-node-name {
    font-weight: 700;
    font-size: 0.78rem;
    margin-bottom: 0.2rem;
    line-height: 1.3;
    word-break: break-word;
}

.referral-tree-node-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    margin-bottom: 0.3rem;
}

.referral-tree-node-username {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.referral-tree-node-count {
    font-size: 0.65rem;
}

.referral-tree-node-link {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.1);
}

.referral-tree-node-link:hover {
    background: rgba(99, 102, 241, 0.18);
}

.referral-tree-node-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

@media (max-width: 700px) {
    .referral-tree-node {
        min-width: 90px;
        max-width: 115px;
        padding: 0.4rem 0.45rem;
    }

    .referral-tree li {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }
}

/* ── Responsive: Tablet (≤ 992px) ── */
@media (max-width: 992px) {
    .dashboard-container,
    .profile-container,
    .auth-container {
        max-width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid .stat-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }
}

/* ── Responsive: Mobile (≤ 768px) ── */
@media (max-width: 768px) {
    .user-header {
        padding: 0.875rem 1rem;
        flex-wrap: wrap;
    }

    .user-nav-toggle {
        display: flex;
        margin-right: auto;
    }

    .user-header-nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 0.35rem;
        padding: 0.75rem 0 0.25rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        margin-top: 0.25rem;
    }

    .user-header-nav.is-open {
        display: flex;
    }

    .user-header-nav a,
    .user-header-nav button {
        width: 100%;
        text-align: right;
        padding: 0.75rem 1rem;
    }

    .user-header-username {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .user-main {
        padding: 1.25rem 0.875rem 2rem;
        align-items: stretch;
    }

    .user-footer {
        padding: 1rem 0.875rem 1.25rem;
        font-size: 0.8rem;
        line-height: 1.5;
    }

    .auth-card {
        padding: 1.75rem 1.25rem;
        border-radius: 14px;
    }

    .auth-card-header h1 {
        font-size: 1.5rem;
    }

    .auth-brand {
        width: 56px;
        height: 56px;
        font-size: 1.75rem;
        border-radius: 16px;
    }

    .profile-header {
        padding: 2rem 1.25rem;
    }

    .profile-body {
        padding: 1.25rem;
    }

    .profile-header h1 {
        font-size: 1.3rem;
    }

    .profile-avatar,
    .profile-avatar-placeholder {
        width: 84px;
        height: 84px;
    }

    .profile-actions {
        flex-direction: column;
    }

    .profile-actions .btn,
    .profile-actions .logout-form,
    .profile-actions .logout-form button {
        width: 100%;
    }

    .dashboard-header h1 {
        font-size: 1.45rem;
    }

    .dashboard-header p,
    .dashboard-section-desc {
        font-size: 0.88rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .stats-grid .stat-card:last-child:nth-child(odd) {
        grid-column: auto;
    }

    .stat-card {
        padding: 1.15rem;
    }

    .stat-value {
        font-size: 1.65rem;
    }

    .dashboard-section {
        padding: 1.15rem;
        border-radius: 14px;
    }

    .dashboard-section-title {
        font-size: 1.05rem;
    }

    .base-report-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .base-report-badge,
    button.base-report-badge,
    .base-report-badge-muted {
        align-self: flex-start;
        white-space: normal;
        text-align: center;
    }

    .user-stats-summary {
        flex-direction: column;
        align-items: stretch;
    }

    .user-stats-identity,
    .user-stats-total {
        width: 100%;
        min-width: 0;
    }

    .user-stats-total {
        text-align: center;
    }

    .empty-state {
        padding: 2rem 1.25rem;
    }

    .info-banner {
        font-size: 0.88rem;
        padding: 0.75rem 1rem;
        word-break: break-word;
    }

    .player-list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .user-modal {
        padding: 0.75rem;
        align-items: flex-end;
    }

    .user-modal-dialog {
        width: 100%;
        max-height: 85vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }

    /* Tables → card layout */
    .chapter-table thead,
    .referrals-table thead {
        display: none;
    }

    .chapter-table tbody,
    .referrals-table tbody {
        display: block;
    }

    .chapter-table tr,
    .referrals-table tr {
        display: block;
        margin-bottom: 0.875rem;
        padding: 0.875rem;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface);
    }

    .chapter-table tr:last-child,
    .referrals-table tr:last-child {
        margin-bottom: 0;
    }

    .chapter-table td,
    .referrals-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.55rem 0;
        border-bottom: 1px solid var(--border);
        text-align: left;
    }

    .chapter-table td:last-child,
    .referrals-table td:last-child {
        border-bottom: none;
    }

    .chapter-table td::before,
    .referrals-table td::before {
        content: attr(data-label);
        flex: 0 0 42%;
        font-weight: 600;
        font-size: 0.78rem;
        color: var(--text-muted);
        text-align: right;
    }

    .chapter-table-wrap,
    .referrals-table-wrap {
        overflow-x: visible;
    }

    /* Referral tree → vertical list */
    .referral-tree-wrap {
        overflow-x: visible;
        padding-bottom: 0.5rem;
    }

    .referral-tree {
        display: block;
        text-align: right;
    }

    .referral-tree ul {
        flex-direction: column;
        align-items: stretch;
        padding-top: 0.75rem;
    }

    .referral-tree > ul {
        padding-top: 0;
    }

    .referral-tree li {
        align-items: stretch;
        padding: 0.35rem 0;
    }

    .referral-tree li::before,
    .referral-tree li::after,
    .referral-tree ul ul::before {
        display: none;
    }

    .referral-tree ul ul {
        margin-right: 1rem;
        padding-right: 0.75rem;
        border-right: 2px solid #e2e8f0;
    }

    .referral-tree-node {
        min-width: 0;
        max-width: none;
        width: 100%;
        text-align: right;
    }

    .referral-tree-node-meta {
        align-items: flex-start;
    }
}

/* ── Responsive: Small phones (≤ 480px) ── */
@media (max-width: 480px) {
    .user-logo-text {
        font-size: 1.05rem;
    }

    .user-logo-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
        border-radius: 10px;
    }

    .auth-card {
        padding: 1.5rem 1rem;
    }

    .form-control {
        padding: 0.8rem 0.875rem;
        font-size: 16px;
    }

    .btn {
        padding: 0.8rem 1.15rem;
    }

    .profile-field {
        padding: 0.875rem 1rem;
    }

    .affiliate-badge {
        font-size: 0.8rem;
        padding: 0.45rem 0.875rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .dashboard-header h1 {
        font-size: 1.25rem;
    }

    .back-link {
        font-size: 0.85rem;
    }

    .chapter-table td::before,
    .referrals-table td::before {
        flex-basis: 46%;
        font-size: 0.75rem;
    }

    .stats-link {
        white-space: normal;
        text-align: center;
    }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
    .user-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .user-main {
        padding-left: max(0.875rem, env(safe-area-inset-left));
        padding-right: max(0.875rem, env(safe-area-inset-right));
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }

    .user-footer {
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }
}
