/* =====================================================================
 * JR ATS — Billing Stylesheet (Phase 1.4 + Phase 2.10)
 *
 * Brand color: #5277ba
 *
 * Used by:
 *   [jr_current_subscription]   (Phase 1.3)
 *   [jr_employee_orders]         (Phase 1.4)
 *   [jr_employer_orders]         (Phase 1.4)
 *   [jr_referral_points]         (Phase 2.5) — embedded in Rewards tab
 *   [jr_coupons]                 (Phase 2.5) — embedded in Rewards tab
 *
 * Design notes:
 *   - Mobile-first, single-column up to 640px.
 *   - Uses CSS custom properties so future tabs / orders table can
 *     inherit the same palette without duplication.
 *   - All selectors are namespaced under .jrats-billing-* to avoid
 *     theme conflicts.
 *   - Orders table converts to stacked card layout below 640px.
 *   - Phase 2.10: Rewards tab embeds Phase 2.5 shortcodes seamlessly.
 * ===================================================================== */

.jrats-billing-card,
.jrats-billing-page {
    --jrats-brand: #5277ba;
    --jrats-brand-dark: #3f5d96;
    --jrats-brand-light: #eaf0fa;
    --jrats-text: #1f2937;
    --jrats-text-muted: #6b7280;
    --jrats-border: #e5e7eb;
    --jrats-bg: #ffffff;
    --jrats-success: #10b981;
    --jrats-success-bg: #d1fae5;
    --jrats-warning: #f59e0b;
    --jrats-warning-bg: #fef3c7;
    --jrats-danger: #ef4444;
    --jrats-danger-bg: #fee2e2;
    --jrats-muted: #9ca3af;
    --jrats-muted-bg: #f3f4f6;
    --jrats-reward-gold: #f59e0b;
    --jrats-reward-gold-bg: #fef3c7;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--jrats-text);
}

.jrats-billing-card *,
.jrats-billing-page *,
.jrats-billing-card *::before,
.jrats-billing-page *::before,
.jrats-billing-card *::after,
.jrats-billing-page *::after {
    box-sizing: border-box;
}

/* =========================================================================
 * Card (Phase 1.3) — used standalone and embedded inside page Subscription tab
 * ========================================================================= */

.jrats-billing-card {
    box-sizing: border-box;
    width: 100%;
    max-width: 540px;
    margin: 1rem 0;
    background: var(--jrats-bg);
    border: 1px solid var(--jrats-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.jrats-billing-card--compact {
    max-width: 380px;
}

.jrats-billing-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    background: var(--jrats-brand-light);
    border-bottom: 1px solid var(--jrats-border);
}

.jrats-billing-card__title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--jrats-brand-dark);
    letter-spacing: 0.01em;
}

.jrats-billing-card__body {
    padding: 1.25rem;
}

.jrats-billing-card__body > p {
    margin: 0 0 0.75rem;
}

.jrats-billing-card__body > p:last-child {
    margin-bottom: 0;
}

/* ---------- Status badges ---------- */

.jrats-billing-status {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.4;
}

.jrats-billing-status--active {
    color: var(--jrats-success);
    background: var(--jrats-success-bg);
}

.jrats-billing-status--expiring {
    color: #92400e;
    background: var(--jrats-warning-bg);
}

.jrats-billing-status--expired {
    color: var(--jrats-danger);
    background: var(--jrats-danger-bg);
}

.jrats-billing-status--cancelled {
    color: var(--jrats-text-muted);
    background: var(--jrats-muted-bg);
}

.jrats-billing-status--free {
    color: var(--jrats-brand-dark);
    background: #ffffff;
    border: 1px solid var(--jrats-border);
}

/* ---------- Plan label/value ---------- */

.jrats-billing-plan {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--jrats-border);
}

.jrats-billing-plan__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--jrats-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.jrats-billing-plan__value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--jrats-brand-dark);
}

.jrats-billing-plan__value small {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--jrats-text-muted);
    margin-left: 0.25rem;
}

/* ---------- Meta rows ---------- */

.jrats-billing-meta {
    margin: 0 0 1rem;
    padding: 0;
    display: grid;
    gap: 0.5rem;
}

.jrats-billing-meta__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0;
}

.jrats-billing-meta__row + .jrats-billing-meta__row {
    border-top: 1px solid var(--jrats-border);
}

.jrats-billing-meta dt {
    margin: 0;
    font-size: 0.85rem;
    color: var(--jrats-text-muted);
    font-weight: 500;
}

.jrats-billing-meta dd {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--jrats-text);
    text-align: right;
}

/* ---------- Card variants (Phase 1.3) ---------- */

.jrats-billing-expired-msg {
    margin: 0 0 0.5rem;
}

.jrats-billing-expired-date {
    margin: 0 0 1rem;
    font-size: 0.85rem;
    color: var(--jrats-text-muted);
}

.jrats-billing-upsell {
    margin: 0.5rem 0 1rem;
    color: var(--jrats-text-muted);
    font-size: 0.9rem;
}

.jrats-billing-card--active .jrats-billing-card__header {
    background: linear-gradient(
        135deg,
        var(--jrats-brand-light) 0%,
        #ffffff 100%
    );
}

.jrats-billing-card--expired .jrats-billing-card__header {
    background: var(--jrats-danger-bg);
}

.jrats-billing-card--expired .jrats-billing-card__title {
    color: var(--jrats-danger);
}

.jrats-billing-card--free .jrats-billing-card__header,
.jrats-billing-card--logged-out .jrats-billing-card__header {
    background: var(--jrats-muted-bg);
}

/* ---------- Buttons ---------- */

.jrats-billing-actions {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.jrats-billing-btn {
    display: inline-block;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.2;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease,
        color 0.15s ease, transform 0.05s ease;
}

.jrats-billing-btn:focus {
    outline: 2px solid var(--jrats-brand);
    outline-offset: 2px;
}

.jrats-billing-btn:active {
    transform: translateY(1px);
}

.jrats-billing-btn--primary {
    background: var(--jrats-brand);
    color: #ffffff;
    border-color: var(--jrats-brand);
}

.jrats-billing-btn--primary:hover,
.jrats-billing-btn--primary:focus {
    background: var(--jrats-brand-dark);
    border-color: var(--jrats-brand-dark);
    color: #ffffff;
}

.jrats-billing-btn--secondary {
    background: #ffffff;
    color: var(--jrats-brand);
    border-color: var(--jrats-brand);
}

.jrats-billing-btn--secondary:hover,
.jrats-billing-btn--secondary:focus {
    background: var(--jrats-brand-light);
}

/* =========================================================================
 * Page wrapper (Phase 1.4) — contains tabs, body, orders, account, rewards
 * ========================================================================= */

.jrats-billing-page {
    box-sizing: border-box;
    width: 100%;
    max-width: 900px;
    margin: 1rem 0;
    background: var(--jrats-bg);
    border: 1px solid var(--jrats-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ---------- Tabs ---------- */

.jrats-billing-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    background: var(--jrats-muted-bg);
    border-bottom: 1px solid var(--jrats-border);
}

.jrats-billing-tab {
    flex: 1 1 auto;
    min-width: 120px;
    padding: 0.85rem 1rem;
    text-align: center;
    text-decoration: none;
    color: var(--jrats-text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 3px solid transparent;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.jrats-billing-tab:hover,
.jrats-billing-tab:focus {
    color: var(--jrats-brand-dark);
    background: #ffffff;
}

.jrats-billing-tab--active {
    color: var(--jrats-brand);
    background: #ffffff;
    border-bottom-color: var(--jrats-brand);
}

.jrats-billing-page__body {
    padding: 1.25rem;
}

/* When the embedded subscription card lives inside a page body,
   strip its top margin to avoid double spacing. */
.jrats-billing-page__body > .jrats-billing-card {
    margin-top: 0;
}

/* ---------- Orders table ---------- */

.jrats-billing-orders__summary {
    font-size: 0.85rem;
    color: var(--jrats-text-muted);
    margin-bottom: 0.75rem;
}

.jrats-billing-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--jrats-border);
    border-radius: 8px;
    background: #ffffff;
}

.jrats-billing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.jrats-billing-table th,
.jrats-billing-table td {
    padding: 0.7rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--jrats-border);
    vertical-align: middle;
}

.jrats-billing-table th {
    background: var(--jrats-brand-light);
    color: var(--jrats-brand-dark);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.jrats-billing-table tbody tr:last-child td {
    border-bottom: 0;
}

.jrats-billing-table tbody tr:hover {
    background: #fafbfc;
}

/* ---------- Pagination ---------- */

.jrats-billing-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1rem;
}

.jrats-billing-pagination__link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--jrats-border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--jrats-text);
    background: #ffffff;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s ease, border-color 0.15s ease,
        color 0.15s ease;
}

.jrats-billing-pagination__link:hover,
.jrats-billing-pagination__link:focus {
    background: var(--jrats-brand-light);
    border-color: var(--jrats-brand);
    color: var(--jrats-brand-dark);
}

.jrats-billing-pagination__link--active {
    background: var(--jrats-brand);
    border-color: var(--jrats-brand);
    color: #ffffff;
    cursor: default;
}

.jrats-billing-pagination__link--active:hover {
    background: var(--jrats-brand);
    color: #ffffff;
}

/* ---------- Empty state ---------- */

.jrats-billing-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--jrats-text-muted);
}

.jrats-billing-empty p {
    margin: 0 0 0.5rem;
}

.jrats-billing-empty .jrats-billing-actions {
    justify-content: center;
}

/* ---------- Notice (audience mismatch) ---------- */

.jrats-billing-notice {
    padding: 0.75rem 1rem;
    margin: 0 0 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.jrats-billing-notice--warning {
    background: var(--jrats-warning-bg);
    border-color: #fcd34d;
    color: #92400e;
}

/* ---------- Account tab ---------- */

.jrats-billing-account .jrats-billing-meta {
    margin-bottom: 1.25rem;
}

/* =========================================================================
 * REWARDS TAB (Phase 2.10) — Coupons & Rewards
 * ========================================================================= */

.jrats-billing-rewards {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.jrats-billing-rewards__section {
    margin: 0 0 0.5rem 0;
    padding: 0;
}

.jrats-billing-rewards__section--referral {
    /* Specific section overrides if needed in the future. */
}

.jrats-billing-rewards__section--coupons {
    /* Specific section overrides if needed in the future. */
}

.jrats-billing-rewards__title {
    margin: 0 0 0.4rem;
    padding: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--jrats-brand-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.jrats-billing-rewards__icon {
    display: inline-block;
    font-size: 1.2rem;
    line-height: 1;
}

.jrats-billing-rewards__intro {
    margin: 0 0 1rem;
    font-size: 0.875rem;
    color: var(--jrats-text-muted);
    line-height: 1.5;
}

.jrats-billing-rewards__embed {
    /* The embedded shortcode keeps its own internal styles.
       We just guarantee it sits flush inside the section. */
    margin: 0;
}

/* Strip outer margins from embedded shortcodes so they nest cleanly. */
.jrats-billing-rewards__embed > div:first-child,
.jrats-billing-rewards__embed > section:first-child,
.jrats-billing-rewards__embed > article:first-child {
    margin-top: 0;
}

.jrats-billing-rewards__embed > div:last-child,
.jrats-billing-rewards__embed > section:last-child,
.jrats-billing-rewards__embed > article:last-child {
    margin-bottom: 0;
}

/* Divider between Rewards and Coupons sections. */
.jrats-billing-rewards__divider {
    height: 1px;
    margin: 1.5rem 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--jrats-border) 20%,
        var(--jrats-border) 80%,
        transparent 100%
    );
    border: 0;
}

/* =========================================================================
 * Responsive — orders table → stacked cards on small screens
 * ========================================================================= */

@media (max-width: 640px) {
    .jrats-billing-table thead {
        display: none;
    }

    .jrats-billing-table,
    .jrats-billing-table tbody,
    .jrats-billing-table tr,
    .jrats-billing-table td {
        display: block;
        width: 100%;
    }

    .jrats-billing-table tr {
        border: 1px solid var(--jrats-border);
        border-radius: 8px;
        margin-bottom: 0.5rem;
        padding: 0.5rem;
    }

    .jrats-billing-table td {
        border: 0;
        padding: 0.35rem 0.5rem;
        display: flex;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .jrats-billing-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--jrats-text-muted);
        text-transform: uppercase;
        font-size: 0.7rem;
        letter-spacing: 0.04em;
    }
}

@media (max-width: 480px) {
    .jrats-billing-card {
        margin: 0.75rem 0;
        border-radius: 10px;
    }

    .jrats-billing-card__header,
    .jrats-billing-card__body,
    .jrats-billing-page__body {
        padding: 1rem;
    }

    .jrats-billing-plan__value {
        font-size: 1.1rem;
    }

    .jrats-billing-actions {
        flex-direction: column;
    }

    .jrats-billing-btn {
        width: 100%;
        text-align: center;
    }

    .jrats-billing-tab {
        flex: 1 1 100%;
        border-bottom: 1px solid var(--jrats-border);
    }

    .jrats-billing-tab--active {
        border-bottom-color: var(--jrats-brand);
    }

    /* Rewards section on small screens. */
    .jrats-billing-rewards__title {
        font-size: 1rem;
    }

    .jrats-billing-rewards__divider {
        margin: 1rem 0;
    }
}

/* =========================================================================
 * RTL support
 * ========================================================================= */

.rtl .jrats-billing-meta dd,
[dir="rtl"] .jrats-billing-meta dd {
    text-align: left;
}

.rtl .jrats-billing-table th,
.rtl .jrats-billing-table td,
[dir="rtl"] .jrats-billing-table th,
[dir="rtl"] .jrats-billing-table td {
    text-align: right;
}

.rtl .jrats-billing-plan__value small,
[dir="rtl"] .jrats-billing-plan__value small {
    margin-left: 0;
    margin-right: 0.25rem;
}

/* RTL for Rewards tab */
.rtl .jrats-billing-rewards__title,
[dir="rtl"] .jrats-billing-rewards__title {
    flex-direction: row-reverse;
    justify-content: flex-end;
}