/* ==========================================================================
   AffiliateHub — Affiliate Portal (frontend) Design System
   Same tokens as admin, but standalone (portal runs inside the theme, not
   wp-admin) with a mobile-first nav that collapses to a bottom bar —
   prioritizing balance, referral link, and payout request on small screens.
   ========================================================================== */

:root {
    --ah-primary: #3323CD;
    --ah-primary-dark: #271AA0;
    --ah-primary-light: #EEF0FF;
    --ah-bg: #F8F9FF;
    --ah-surface: #FFFFFF;
    --ah-border: #E7E8F5;
    --ah-text: #1F2333;
    --ah-text-muted: #6B7080;
    --ah-text-faint: #9498A8;
    --ah-success: #17A366;
    --ah-success-bg: #E9FBF3;
    --ah-warning: #C6820B;
    --ah-warning-bg: #FFF6E4;
    --ah-danger: #DC3545;
    --ah-danger-bg: #FDEEEF;
    --ah-info: #2563EB;
    --ah-info-bg: #EAF1FE;
    --ah-radius-sm: 8px;
    --ah-radius: 12px;
    --ah-radius-lg: 16px;
    --ah-shadow: 0 1px 2px rgba(16,24,40,.04), 0 2px 8px rgba(16,24,40,.05);
}

.ah-portal * { box-sizing: border-box; }
.ah-portal {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    color: var(--ah-text);
    max-width: 1080px;
    margin: 0 auto;
    padding-bottom: 32px;
}

/* ---------- Top nav (desktop) ---------- */
.ah-portal-topnav {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--ah-surface); border: 1px solid var(--ah-border); border-radius: var(--ah-radius);
    padding: 10px 18px; margin-bottom: 20px; position: sticky; top: 10px; z-index: 20;
    box-shadow: var(--ah-shadow);
}
.ah-portal-brand { font-weight: 700; font-size: 15px; color: var(--ah-primary); }
.ah-portal-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ah-portal-tabs a {
    padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
    color: var(--ah-text-muted); text-decoration: none;
}
.ah-portal-tabs a.active { background: var(--ah-primary-light); color: var(--ah-primary); }
.ah-portal-tabs a:hover:not(.active) { background: var(--ah-bg); }

/* ---------- Banner ---------- */
.ah-banner {
    background: linear-gradient(135deg, var(--ah-primary), #6C5CE7);
    color: #fff; border-radius: var(--ah-radius-lg);
    padding: 22px 24px; margin-bottom: 18px;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px;
}
.ah-banner h2 { margin: 0 0 4px; font-size: 19px; }
.ah-banner p { margin: 0; opacity: .85; font-size: 13px; }

/* ---------- Referral link card ---------- */
.ah-referral-card {
    background: var(--ah-surface); border: 1px solid var(--ah-border); border-radius: var(--ah-radius);
    box-shadow: var(--ah-shadow); padding: 18px 20px; margin-bottom: 18px;
}
.ah-referral-card .ah-label { font-size: 12px; color: var(--ah-text-muted); font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .03em; }
.ah-referral-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ah-referral-row input {
    flex: 1; min-width: 200px; padding: 10px 14px; border: 1px solid var(--ah-border);
    border-radius: var(--ah-radius-sm); font-size: 13px; background: var(--ah-bg); color: var(--ah-text);
}
.ah-referral-row .ah-btn { flex-shrink: 0; }

/* ---------- Stat cards ---------- */
.ah-cards { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.ah-card {
    background: var(--ah-surface); border: 1px solid var(--ah-border); border-radius: var(--ah-radius);
    box-shadow: var(--ah-shadow); padding: 16px 18px;
}
.ah-stat-card { flex: 1 1 160px; min-width: 150px; }
.ah-stat-card.highlight { background: linear-gradient(135deg, var(--ah-primary), #6C5CE7); border-color: transparent; color: #fff; }
.ah-stat-card.highlight .ah-stat-label { color: rgba(255,255,255,.75); }
.ah-stat-card.highlight .ah-stat-value { color: #fff; }
.ah-stat-label { font-size: 11.5px; color: var(--ah-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; margin-bottom: 6px; }
.ah-stat-value { font-size: 22px; font-weight: 700; }
.ah-stat-sub { font-size: 11.5px; color: var(--ah-text-faint); margin-top: 4px; }

/* ---------- Panels / tables ---------- */
.ah-panel { background: var(--ah-surface); border: 1px solid var(--ah-border); border-radius: var(--ah-radius); box-shadow: var(--ah-shadow); padding: 20px; margin-bottom: 20px; }
.ah-panel h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
table.ah-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ah-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--ah-text-faint); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--ah-border); white-space: nowrap; }
table.ah-table td { padding: 12px; border-bottom: 1px solid var(--ah-border); }
table.ah-table tr:last-child td { border-bottom: none; }

.ah-badge {
    display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
    padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.ah-badge.success, .ah-badge.active, .ah-badge.paid, .ah-badge.approved, .ah-badge.converted { color: var(--ah-success); background: var(--ah-success-bg); }
.ah-badge.pending, .ah-badge.clicked { color: var(--ah-warning); background: var(--ah-warning-bg); }
.ah-badge.rejected, .ah-badge.failed, .ah-badge.cancelled, .ah-badge.reversed { color: var(--ah-danger); background: var(--ah-danger-bg); }
.ah-badge.processing, .ah-badge.registered { color: var(--ah-info); background: var(--ah-info-bg); }

.ah-btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    font-size: 13px; font-weight: 600; padding: 10px 16px; border-radius: var(--ah-radius-sm);
    border: 1px solid var(--ah-border); background: var(--ah-surface); color: var(--ah-text);
    cursor: pointer; text-decoration: none; line-height: 1.2;
}
.ah-btn.primary { background: var(--ah-primary); border-color: var(--ah-primary); color: #fff; }
.ah-btn.primary:hover { background: var(--ah-primary-dark); }
.ah-btn.block { width: 100%; }
.ah-btn:disabled { opacity: .5; cursor: not-allowed; }

.ah-form-row { margin-bottom: 16px; }
.ah-form-row label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ah-text-muted); margin-bottom: 6px; }
.ah-form-row input, .ah-form-row select, .ah-form-row textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--ah-border); border-radius: var(--ah-radius-sm);
    font-size: 13.5px; background: var(--ah-surface); color: var(--ah-text);
}
.ah-form-row input:focus, .ah-form-row select:focus, .ah-form-row textarea:focus { outline: none; border-color: var(--ah-primary); }
.ah-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.ah-notice { background: var(--ah-primary-light); border: 1px solid #D9DCFA; color: var(--ah-primary-dark); padding: 10px 14px; border-radius: var(--ah-radius-sm); margin-bottom: 16px; font-size: 13px; }
.ah-notice.warn { background: var(--ah-warning-bg); border-color: #F0DCA8; color: var(--ah-warning); }

.ah-empty { text-align: center; padding: 40px 16px; color: var(--ah-text-muted); font-size: 13.5px; }

.ah-payout-balance { font-size: 30px; font-weight: 700; margin: 6px 0 14px; }

.ah-masked { letter-spacing: 2px; }

/* ==========================================================================
   Mobile — cards instead of tables, bottom tab bar, balance-first layout
   ========================================================================== */
@media (max-width: 720px) {
    .ah-portal { padding: 0 12px 84px; }
    .ah-portal-topnav { display: none; }

    .ah-mobile-topbar {
        display: flex; align-items: center; justify-content: space-between;
        padding: 14px 4px; position: sticky; top: 0; background: var(--ah-bg); z-index: 20;
    }
    .ah-mobile-topbar .ah-portal-brand { font-size: 15px; }

    .ah-banner { padding: 18px; flex-direction: column; align-items: flex-start; }
    .ah-banner .ah-referral-box { width: 100%; }

    .ah-cards { gap: 10px; }
    .ah-stat-card { flex: 1 1 calc(50% - 5px); min-width: 0; padding: 12px 14px; }
    .ah-stat-value { font-size: 18px; }

    /* Tables become stacked cards */
    table.ah-table, table.ah-table thead, table.ah-table tbody, table.ah-table th, table.ah-table td, table.ah-table tr { display: block; width: 100%; }
    table.ah-table thead { display: none; }
    table.ah-table tr {
        border: 1px solid var(--ah-border); border-radius: var(--ah-radius); margin-bottom: 10px;
        padding: 10px 4px; background: var(--ah-surface);
    }
    table.ah-table td {
        border: none; display: flex; justify-content: space-between; align-items: center; gap: 10px;
        padding: 6px 12px;
    }
    table.ah-table td::before {
        content: attr(data-label); font-weight: 600; color: var(--ah-text-faint); font-size: 11px;
        text-transform: uppercase; letter-spacing: .02em;
    }

    .ah-form-grid { grid-template-columns: 1fr; }

    /* Bottom tab bar replaces the top nav */
    .ah-mobile-tabbar {
        position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
        background: var(--ah-surface); border-top: 1px solid var(--ah-border);
        display: flex; justify-content: space-around; padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 10px rgba(16,24,40,.06);
    }
    .ah-mobile-tabbar a {
        display: flex; flex-direction: column; align-items: center; gap: 2px;
        color: var(--ah-text-faint); text-decoration: none; font-size: 10.5px; font-weight: 600;
        padding: 4px 8px; border-radius: var(--ah-radius-sm); flex: 1;
    }
    .ah-mobile-tabbar a .dashicons { font-size: 20px; width: 20px; height: 20px; }
    .ah-mobile-tabbar a.active { color: var(--ah-primary); }
}

@media (min-width: 721px) {
    .ah-mobile-tabbar, .ah-mobile-topbar { display: none; }
}
