/* Affiliate Marketing — merchant dashboard, affiliate portal, join page.
   Built on the storefront's existing tokens (--ss-primary / --ss-accent from
   storefront.css) so these screens read as part of the same product rather than
   a bolt-on. Everything here is prefixed .af- and cannot collide with the
   .ss-/.co-/.od- families already in use. */

:root {
    --af-ink: #1c2230;
    --af-ink-soft: #5a6478;
    --af-ink-faint: #8a93a6;
    --af-line: #e7eaf0;
    --af-bg: #f6f7fb;
    --af-radius: 12px;
    --af-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --af-shadow-lift: 0 10px 28px rgba(16, 24, 40, .10);
}

.af-wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 16px 64px;
}

/* ---- page header -------------------------------------------------------- */
.af-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.af-head h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--af-ink);
    margin: 0 0 4px;
    letter-spacing: -.01em;
}
.af-head p {
    margin: 0;
    color: var(--af-ink-soft);
    font-size: 14px;
    max-width: 62ch;
    line-height: 1.5;
}
.af-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- buttons ------------------------------------------------------------ */
.af-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 15px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
    transition: background .15s ease, box-shadow .15s ease, border-color .15s ease;
    white-space: nowrap;
}
.af-btn:focus-visible { outline: 2px solid var(--ss-primary, #3f51b5); outline-offset: 2px; }
.af-btn-primary { background: var(--ss-primary, #3f51b5); color: #fff; }
.af-btn-primary:hover { background: var(--ss-primary-dark, #2c3a94); color: #fff; text-decoration: none; }
.af-btn-ghost { background: #fff; color: var(--af-ink); border-color: var(--af-line); }
.af-btn-ghost:hover { background: #f3f5f9; color: var(--af-ink); text-decoration: none; }
.af-btn-danger { background: #fff; color: #b42318; border-color: #f2c9c4; }
.af-btn-danger:hover { background: #fef3f2; color: #912018; }
.af-btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.af-btn[disabled], .af-btn.is-busy { opacity: .55; cursor: not-allowed; pointer-events: none; }

/* ---- stat tiles --------------------------------------------------------- */
.af-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.af-tile {
    background: #fff;
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius);
    padding: 16px 16px 14px;
    box-shadow: var(--af-shadow);
}
.af-tile-l {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--af-ink-faint);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.af-tile-v {
    font-size: 26px;
    font-weight: 700;
    color: var(--af-ink);
    line-height: 1.1;
    letter-spacing: -.02em;
}
.af-tile-s { font-size: 12.5px; color: var(--af-ink-faint); margin-top: 5px; }
/* The one number that is money the shop owes someone. */
.af-tile-owed .af-tile-v { color: #b54708; }
.af-tile-action { border-color: #c7d7fe; background: #f5f8ff; }

/* ---- cards & sections --------------------------------------------------- */
.af-card {
    background: #fff;
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius);
    box-shadow: var(--af-shadow);
    margin-bottom: 18px;
    overflow: hidden;
}
.af-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 16px;
    border-bottom: 1px solid var(--af-line);
}
.af-card-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--af-ink);
}
.af-card-head .af-card-sub { font-size: 12.5px; color: var(--af-ink-faint); margin-top: 2px; }
.af-card-body { padding: 16px; }
.af-card-body-flush { padding: 0; }

/* ---- filters ------------------------------------------------------------ */
.af-filters {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.af-input, .af-select, .af-textarea {
    border: 1px solid var(--af-line);
    border-radius: 9px;
    padding: 9px 11px;
    font-size: 14px;
    color: var(--af-ink);
    background: #fff;
    min-width: 0;
}
.af-input:focus, .af-select:focus, .af-textarea:focus {
    outline: none;
    border-color: var(--ss-primary, #3f51b5);
    box-shadow: 0 0 0 3px rgba(63, 81, 181, .12);
}
.af-search { flex: 1 1 220px; max-width: 340px; }
.af-textarea { width: 100%; resize: vertical; min-height: 88px; line-height: 1.5; }

/* ---- tables ------------------------------------------------------------- */
.af-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.af-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.af-table th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--af-ink-faint);
    padding: 11px 14px;
    border-bottom: 1px solid var(--af-line);
    background: #fbfcfe;
    white-space: nowrap;
}
.af-table td {
    padding: 13px 14px;
    border-bottom: 1px solid #f1f3f7;
    color: var(--af-ink);
    vertical-align: middle;
}
.af-table tbody tr:last-child td { border-bottom: none; }
.af-table tbody tr:hover { background: #fafbfd; }
.af-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.af-strong { font-weight: 650; }

.af-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.af-avatar {
    width: 34px; height: 34px; flex: 0 0 34px;
    border-radius: 50%;
    background: var(--ss-primary, #3f51b5);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    text-transform: uppercase;
}
.af-person-n { min-width: 0; }
.af-person-n a { color: var(--af-ink); font-weight: 600; text-decoration: none; }
.af-person-n a:hover { color: var(--ss-primary, #3f51b5); text-decoration: underline; }
.af-person-s {
    font-size: 12.5px; color: var(--af-ink-faint);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px;
}

/* ---- pills -------------------------------------------------------------- */
.af-pill {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .03em;
    padding: 3px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    white-space: nowrap;
}
.af-pill-active   { background: #e7f6ec; color: #106b33; }
.af-pill-pending  { background: #fff4e5; color: #93500b; }
.af-pill-suspended{ background: #feecea; color: #a32316; }
.af-pill-approved { background: #e8f1ff; color: #1a4fa0; }
.af-pill-paid     { background: #e7f6ec; color: #106b33; }
.af-pill-reversed { background: #feecea; color: #a32316; }
.af-pill-void     { background: #f0f1f4; color: #667085; }

/* ---- code / share link -------------------------------------------------- */
.af-code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .09em;
    background: #f2f4f8;
    border: 1px solid var(--af-line);
    border-radius: 7px;
    padding: 3px 8px;
    color: var(--af-ink);
    white-space: nowrap;
}
.af-linkbox {
    display: flex;
    gap: 8px;
    align-items: stretch;
    flex-wrap: wrap;
}
.af-linkbox input {
    flex: 1 1 260px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    background: #f8f9fc;
}

/* ---- empty & loading ---------------------------------------------------- */
.af-empty { text-align: center; padding: 52px 20px; color: var(--af-ink-soft); }
.af-empty-ico {
    width: 56px; height: 56px; margin: 0 auto 14px;
    border-radius: 50%; background: var(--af-bg);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: var(--af-ink-faint);
}
.af-empty h3 { font-size: 16px; font-weight: 700; color: var(--af-ink); margin: 0 0 6px; }
.af-empty p { font-size: 14px; margin: 0 auto 16px; max-width: 46ch; line-height: 1.55; }
.af-loading { text-align: center; padding: 40px; color: var(--af-ink-faint); font-size: 14px; }

/* ---- alerts ------------------------------------------------------------- */
.af-alert {
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    margin-bottom: 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.af-alert i { margin-top: 2px; }
.af-alert-info { background: #eef4ff; color: #1a4fa0; }
.af-alert-warn { background: #fff8ec; color: #93500b; }
.af-alert-err  { background: #fef3f2; color: #a32316; }
.af-alert-ok   { background: #ecfdf3; color: #106b33; }

/* ---- forms -------------------------------------------------------------- */
.af-field { margin-bottom: 14px; }
.af-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--af-ink);
    margin-bottom: 6px;
}
.af-field .af-input, .af-field .af-select, .af-field .af-textarea { width: 100%; }
.af-hint { font-size: 12.5px; color: var(--af-ink-faint); margin-top: 5px; line-height: 1.5; }
.af-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .af-row2 { grid-template-columns: 1fr; } }

.af-toggle {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 13px 0;
    border-top: 1px solid var(--af-line);
    cursor: pointer;
}
.af-toggle:first-of-type { border-top: none; }
.af-toggle input { margin-top: 3px; width: 16px; height: 16px; flex: 0 0 16px; cursor: pointer; }
.af-toggle-t { font-size: 14px; font-weight: 600; color: var(--af-ink); }
.af-toggle-s { font-size: 12.5px; color: var(--af-ink-faint); margin-top: 3px; line-height: 1.5; }

/* ---- modals ------------------------------------------------------------- */
.af-modal .modal-content { border: none; border-radius: 14px; overflow: hidden; box-shadow: var(--af-shadow-lift); }
.af-modal .modal-header {
    background: var(--ss-primary, #3f51b5);
    color: #fff;
    border-bottom: none;
    padding: 14px 18px;
}
.af-modal .modal-header h4 { font-size: 16px; font-weight: 700; margin: 0; color: #fff; }
.af-modal .modal-header .close { color: #fff; opacity: .9; text-shadow: none; font-weight: 400; }
.af-modal .modal-body { padding: 18px; }

/* ---- affiliate portal (public) ------------------------------------------ */
.af-portal { background: var(--af-bg); min-height: 100vh; }
.af-portal-bar {
    background: var(--ss-primary, #3f51b5);
    color: #fff;
    padding: 16px 0;
}
.af-portal-bar .af-wrap { padding-top: 0; padding-bottom: 0; }
.af-portal-bar h1 { font-size: 18px; font-weight: 700; margin: 0; color: #fff; }
.af-portal-bar p { font-size: 13px; margin: 3px 0 0; color: rgba(255, 255, 255, .82); }

.af-hero {
    background: linear-gradient(135deg, var(--ss-primary, #3f51b5), #5b6abd);
    color: #fff;
    border-radius: var(--af-radius);
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: var(--af-shadow);
}
.af-hero h2 { font-size: 14px; font-weight: 600; margin: 0 0 6px; color: rgba(255, 255, 255, .88); }
.af-hero .af-hero-v { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.af-hero .af-hero-s { font-size: 13px; color: rgba(255, 255, 255, .82); margin-top: 7px; line-height: 1.5; }
.af-hero .af-linkbox input { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .28); color: #fff; }
.af-hero .af-linkbox input::placeholder { color: rgba(255, 255, 255, .6); }

.af-share-row { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 12px; }
.af-share-btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .26);
    color: #fff;
    border-radius: 9px;
    padding: 9px 14px;
    font-size: 13.5px; font-weight: 600;
    text-decoration: none; cursor: pointer;
}
.af-share-btn:hover { background: rgba(255, 255, 255, .26); color: #fff; text-decoration: none; }

/* ---- join page ---------------------------------------------------------- */
.af-join { max-width: 520px; margin: 0 auto; padding: 28px 16px 64px; }
.af-join-card {
    background: #fff;
    border: 1px solid var(--af-line);
    border-radius: 16px;
    box-shadow: var(--af-shadow-lift);
    padding: 26px;
}
.af-join-rate {
    text-align: center;
    padding: 18px;
    background: linear-gradient(135deg, var(--ss-primary, #3f51b5), #5b6abd);
    border-radius: 12px;
    color: #fff;
    margin-bottom: 20px;
}
.af-join-rate .n { font-size: 38px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.af-join-rate .l { font-size: 13.5px; margin-top: 7px; color: rgba(255, 255, 255, .9); }
.af-terms {
    max-height: 170px; overflow-y: auto;
    background: var(--af-bg);
    border: 1px solid var(--af-line);
    border-radius: 9px;
    padding: 12px;
    font-size: 12.5px; line-height: 1.6; color: var(--af-ink-soft);
    white-space: pre-wrap; word-break: break-word;
    margin-bottom: 12px;
}

/* ---- small screens ------------------------------------------------------ */
@media (max-width: 720px) {
    .af-head h1 { font-size: 20px; }
    .af-tile-v { font-size: 22px; }
    .af-card-body { padding: 14px; }
    .af-table th, .af-table td { padding: 10px 11px; }
    .af-person-s { max-width: 150px; }
}
