:root {
    --primary: #6941c6;
    --primary-dark: #4b2a99;
    --primary-darker: #3c2178;
    --primary-light: #f9f5ff;
    --primary-border: #e9d7fe;
    --bg: #f6f5fb;
    --surface: #ffffff;
    --text: #181228;
    --text-muted: #6b7280;
    --text-faint: #98a2b3;
    --border: #e7e4f2;
    --success-bg: #e6f7ed; --success-fg: #0f7a45;
    --error-bg: #fdecea; --error-fg: #b3261e;
    --info-bg: #e8f0fe; --info-fg: #1a56db;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --shadow-sm: 0 1px 3px rgba(24,18,40,.06);
    --shadow-md: 0 6px 20px rgba(24,18,40,.08);
    --shadow-lg: 0 16px 40px rgba(76,41,153,.16);
    --sidebar-w: 264px;
    --bottomnav-h: 66px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }

/* ============ Flash messages (toasts) ============ */
.flashes {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 380px;
    pointer-events: none;
}
.flash {
    padding: 13px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in .25s ease-out;
}
.flash.toast-out { animation: toast-out .2s ease-in forwards; }
.flash-success { background: var(--success-bg); color: var(--success-fg); }
.flash-error { background: var(--error-bg); color: var(--error-fg); }
.flash-info { background: var(--info-bg); color: var(--info-fg); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

@media (min-width: 900px) {
    .flashes { left: auto; right: 24px; top: 24px; transform: none; width: 100%; }
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    text-align: center;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 13px 18px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
    box-shadow: 0 2px 8px rgba(105,65,198,.25);
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); box-shadow: none; }
.btn.secondary:hover { background: var(--primary-light); }
.btn.danger { background: #d92d20; box-shadow: 0 2px 8px rgba(217,45,32,.25); }
.btn.danger:hover { background: #b3261e; }
.btn.small { width: auto; padding: 9px 16px; font-size: 13px; }

form.inline { display: inline; }

/* ============ Form fields ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: #344054; margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(105,65,198,.12);
}
.field input[type="file"] { padding: 9px 10px; }

/* ============ Auth pages ============ */
body.auth-page {
    background: radial-gradient(circle at top left, #efe8fc, var(--bg) 55%);
}
body.auth-page .app-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.auth-wrap {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px;
}
.auth-wrap h1 { font-size: 26px; margin-bottom: 6px; font-weight: 800; }
.auth-wrap .sub { color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }
.auth-switch { text-align: center; margin-top: 22px; font-size: 14px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 700; }

@media (max-width: 480px) {
    .auth-wrap { padding: 32px 22px; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
}

/* ============ Dashboard shell (user portal) ============ */
body.dashboard-page { background: var(--bg); }

.layout {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 100vh;
}

/* Sidebar: desktop only */
.sidebar {
    display: none;
    flex-direction: column;
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--primary-darker), var(--primary-dark) 60%, var(--primary));
    color: #fff;
    padding: 28px 20px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 26px; padding: 0 4px; }
.sidebar-balance {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    margin-bottom: 24px;
}
.sidebar-balance .lbl { font-size: 12px; opacity: .8; display: block; margin-bottom: 4px; }
.sidebar-balance .amt { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.sidebar-links { list-style: none; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-md);
    font-size: 14.5px;
    font-weight: 600;
    color: rgba(255,255,255,.82);
    transition: background .15s ease, color .15s ease;
}
.sidebar-links a .icon { font-size: 17px; width: 20px; text-align: center; }
.sidebar-links a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-links a.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.sidebar-logout {
    display: block;
    text-align: center;
    padding: 11px 14px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255,255,255,.3);
    font-size: 13.5px;
    font-weight: 600;
    color: #fff;
    margin-top: 12px;
}
.sidebar-logout:hover { background: rgba(255,255,255,.1); }

/* Topbar: mobile only */
.topbar-mobile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(120deg, var(--primary), var(--primary-dark));
    color: #fff;
    width: 100%;
}
.back-link { font-size: 20px; opacity: .95; }
.balance-box { flex: 1; }
.balance-label { display: block; font-size: 12px; opacity: 0.85; }
.balance-amount { display: block; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.logout-link { font-size: 12.5px; opacity: 0.95; border: 1px solid rgba(255,255,255,0.45); padding: 7px 12px; border-radius: var(--radius-sm); font-weight: 600; }

/* Main content */
.main-content {
    flex: 1;
    min-width: 0;
    padding-bottom: calc(var(--bottomnav-h) + 24px);
}
.content-inner { max-width: 760px; margin: 0 auto; padding: 24px 18px; }

/* Bottom nav: mobile only */
.bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(24,18,40,.06);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    z-index: 40;
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-faint);
    padding: 4px 2px;
    border-radius: var(--radius-sm);
}
.bottom-nav a .icon { font-size: 19px; }
.bottom-nav a.active { color: var(--primary); }

@media (min-width: 900px) {
    .layout { flex-direction: row; }
    .sidebar { display: flex; }
    .topbar-mobile { display: none; }
    .bottom-nav { display: none; }
    .main-content { padding-bottom: 24px; }
    .content-inner { padding: 40px 48px; max-width: 900px; }
}

/* ============ Section headers / generic content ============ */
.section h2 { font-size: 20px; margin-bottom: 18px; font-weight: 800; }
.section h3 { font-size: 15px; margin: 26px 0 12px; font-weight: 700; color: var(--text); }
.section > p { color: var(--text-muted); font-size: 13.5px; }

/* ============ Dashboard menu grid ============ */
.menu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.menu-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.menu-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary-border); }
.menu-tile .icon {
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin: 0 auto 10px;
    background: var(--primary-light);
    border-radius: 50%;
}
.menu-tile .label { font-size: 13.5px; font-weight: 700; color: #42307d; }

@media (min-width: 620px) {
    .menu-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ============ Plan cards ============ */
.plan-card {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color .15s ease;
}
.plan-card.current { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 3px rgba(105,65,198,.08); }
.plan-name { font-weight: 800; font-size: 17px; }
.plan-meta { font-size: 13px; color: var(--text-muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.plan-meta span { white-space: nowrap; }

.direct-pay-form.open { display: block !important; }

/* ============ Tables / history ============ */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
table.history { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
table.history th {
    padding: 12px 14px;
    text-align: left;
    background: #faf9fd;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
}
table.history td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.history tr:last-child td { border-bottom: none; }

.badge { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-pending { background: #fef0c7; color: #93700a; }
.badge-approved { background: #d1fadf; color: #067647; }
.badge-rejected { background: #fdecea; color: #b3261e; }
.badge-active { background: #d1fadf; color: #067647; }
.badge-blocked { background: #fdecea; color: #b3261e; }

/* ============ Recharge / referral info blocks ============ */
.recharge-info {
    background: #faf9fd;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 14px;
}
.recharge-info .row { display: flex; justify-content: space-between; padding: 4px 0; gap: 12px; }
.recharge-info .row b { user-select: all; text-align: right; }

.help-card {
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    margin-bottom: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color .15s ease, transform .15s ease;
}
.help-card:hover { border-color: #25D366; transform: translateY(-1px); }
.help-card .icon {
    font-size: 22px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e7f9ee;
    border-radius: 50%;
}

.referral-box {
    background: linear-gradient(135deg, var(--primary-light), #fff);
    border: 1.5px dashed var(--primary);
    border-radius: var(--radius-lg);
    padding: 26px 20px;
    text-align: center;
    margin-bottom: 20px;
}
.referral-code { font-size: 28px; font-weight: 800; letter-spacing: 4px; color: var(--primary-darker); margin: 10px 0; }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-box {
    flex: 1 1 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-box .num { font-size: 19px; font-weight: 800; }
.stat-box .lbl { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============ Admin portal ============ */
body.admin-page { background: var(--bg); }
.admin-shell {
    max-width: 1160px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--surface);
    box-shadow: var(--shadow-md);
}
@media (min-width: 1200px) {
    .admin-shell { margin: 24px auto; min-height: calc(100vh - 48px); border-radius: var(--radius-xl); overflow: hidden; }
}

.admin-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 14px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.admin-brand { font-weight: 800; font-size: 16px; color: var(--primary-darker); margin-right: 14px; }
.admin-nav a {
    font-size: 13px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    transition: background .15s ease, color .15s ease;
}
.admin-nav a:hover { background: var(--primary-light); color: var(--primary-darker); }
.admin-nav a.active { background: var(--primary); color: #fff; }
.admin-nav a.logout-link-admin { margin-left: auto; color: var(--error-fg); }
.admin-nav a.logout-link-admin:hover { background: var(--error-bg); }

.admin-shell .section { padding: 26px 22px; }
.admin-shell .flashes { padding: 18px 22px 0; }

@media (min-width: 700px) {
    .admin-shell .section { padding: 32px 36px; }
}
.payment-qr-card {
    width: min(100%, 420px);
    margin: 0 auto 20px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #fff;
    text-align: center;
}

.payment-qr-title {
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.payment-qr-image {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}
