/* ===================================================
   Billing Portal – Frontend Portal Styles
   CSS-variables driven, theme-compatible, minimal
   =================================================== */

/* Variables are injected inline by PHP from the Portal Appearance color
   registry; these are fallbacks used only if the inline block is missing.
   Every portal color is now an explicit, admin-configurable setting — nothing
   is pulled from the theme's accent anymore. */
:root {
    /* Surfaces */
    --bp-bg: #f9fafb;
    --bp-wrapper-border: #e5e7eb;
    --bp-surface: #ffffff;
    --bp-border: #e5e7eb;
    /* Text */
    --bp-text: #111827;
    --bp-muted: #6b7280;
    --bp-heading: #111827;
    --bp-link: #2563eb;
    /* Navigation */
    --bp-nav-bg: #ffffff;
    --bp-nav-text: #374151;
    --bp-nav-active-bg: #eff6ff;
    --bp-nav-active-text: #1d4ed8;
    /* Buttons */
    --bp-btn-bg: #111827;
    --bp-btn-text: #ffffff;
    --bp-btn-hover-bg: #374151;
    --bp-btn-hover-text: #ffffff;
    /* Inputs */
    --bp-input-bg: #ffffff;
    --bp-input-text: #111827;
    --bp-input-border: #d1d5db;
    /* Signup options + order summary */
    --bp-option-bg: #ffffff;
    --bp-option-text: #111827;
    --bp-summary-bg: #f0f9ff;
    --bp-summary-text: #0c4a6e;
    /* Derived (also injected inline) */
    --bp-divider: rgba(17, 24, 39, 0.1);
    --bp-hover: rgba(17, 24, 39, 0.07);
    --bp-radius: 8px;
    --bp-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --bp-spacing: 20px;
    --bp-btn-style: solid;
}

/* ── Portal wrapper ────────────────────────────────── */
.bp-portal *, .bp-portal *::before, .bp-portal *::after {
    box-sizing: border-box;
}

/* The OUTERMOST portal wrapper paints the Background color; the cards inside
   use Surface. A nested .bp-portal — e.g. a page-builder text block that
   hand-wraps the shortcode in its own <div class="bp-portal"> — stays
   transparent so the backdrop isn't painted twice. Same for a .bp-portal that
   the builder nests inside a card shell. */
.bp-portal {
    background: var(--bp-bg);
    border: 1px solid var(--bp-wrapper-border);
    padding: var(--bp-spacing);
    border-radius: var(--bp-radius);
}
.bp-portal .bp-portal,
.bp-portal-card .bp-portal {
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

/* ── Portal Navigation ─────────────────────────────── */
.bp-portal-nav {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: calc(var(--bp-spacing) * 1.5);
    background: var(--bp-nav-bg);
    border: 1px solid var(--bp-border);
    border-radius: var(--bp-radius);
    padding: 4px;
    overflow: hidden;
}

.bp-portal-nav__item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--bp-nav-text);
    text-decoration: none;
    border-radius: calc(var(--bp-radius) - 2px);
    white-space: nowrap;
    transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}

.bp-portal-nav__item:hover {
    color: var(--bp-nav-active-text);
    background: var(--bp-nav-active-bg);
    text-decoration: none;
}

.bp-portal-nav__item--active {
    color: var(--bp-nav-active-text);
    background: var(--bp-nav-active-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

.bp-portal-nav__item--active:hover {
    background: var(--bp-nav-active-bg);
    color: var(--bp-nav-active-text);
}

.bp-portal-nav__item--logout {
    margin-left: auto;
    color: var(--bp-nav-text);
    font-weight: 400;
}

.bp-portal-nav__item--logout:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* ── Account Status Banner ─────────────────────────── */
.bp-status-banner {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 24px;
    border-radius: var(--bp-radius);
    margin-bottom: var(--bp-spacing);
}

.bp-status-banner__icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}

.bp-status-banner__content {
    flex: 1;
    min-width: 0;
}

.bp-status-banner__label {
    display: block;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.bp-status-banner__message {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
    opacity: 0.85;
}

.bp-status-banner__link {
    display: inline-block;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: underline;
}

/* Status banners use translucent tints of a semantic color so they read on
   both light and dark backgrounds. The label/message inherit the theme text
   color; the icon and link carry the vivid semantic color. */

/* Green — Active */
.bp-status-banner--green {
    background: color-mix(in srgb, #16a34a 12%, transparent);
    border: 1px solid color-mix(in srgb, #16a34a 30%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--green .bp-status-banner__icon {
    background: color-mix(in srgb, #16a34a 22%, transparent);
    color: #16a34a;
}
.bp-status-banner--green .bp-status-banner__link {
    color: #16a34a;
}

/* Yellow — Late Payment */
.bp-status-banner--yellow {
    background: color-mix(in srgb, #d97706 12%, transparent);
    border: 1px solid color-mix(in srgb, #d97706 30%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--yellow .bp-status-banner__icon {
    background: color-mix(in srgb, #d97706 22%, transparent);
    color: #d97706;
}
.bp-status-banner--yellow .bp-status-banner__link {
    color: #d97706;
}

/* Orange — Jeopardy */
.bp-status-banner--orange {
    background: color-mix(in srgb, #ea580c 12%, transparent);
    border: 1px solid color-mix(in srgb, #ea580c 30%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--orange .bp-status-banner__icon {
    background: color-mix(in srgb, #ea580c 22%, transparent);
    color: #ea580c;
}
.bp-status-banner--orange .bp-status-banner__link {
    color: #ea580c;
}

/* Red — Suspended */
.bp-status-banner--red {
    background: color-mix(in srgb, #dc2626 12%, transparent);
    border: 1px solid color-mix(in srgb, #dc2626 30%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--red .bp-status-banner__icon {
    background: color-mix(in srgb, #dc2626 22%, transparent);
    color: #dc2626;
}
.bp-status-banner--red .bp-status-banner__link {
    color: #dc2626;
}

/* Black — Inactive (neutral tint) */
.bp-status-banner--black {
    background: color-mix(in srgb, var(--bp-text) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--bp-text) 22%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--black .bp-status-banner__icon {
    background: color-mix(in srgb, var(--bp-text) 15%, transparent);
    color: var(--bp-text);
}
.bp-status-banner--black .bp-status-banner__link {
    color: var(--bp-link);
}

/* ── Cards ─────────────────────────────────────────── */
.bp-portal-card {
    background: var(--bp-surface);
    border: 1px solid var(--bp-border);
    border-radius: var(--bp-radius);
    padding: var(--bp-spacing);
    box-shadow: var(--bp-card-shadow);
    margin-bottom: var(--bp-spacing);
    color: var(--bp-text);
}

/* Flatten "shell" cards so every portal page is exactly ONE background wrapper
   (the outer .bp-portal) + the real cards inside — matching the dashboard.

   Two kinds of shell get neutralized:
   1. A page-builder text block that hand-wraps the shortcode in its own
      <div class="bp-portal-card"> — it always CONTAINS a .bp-portal, so it's a
      pass-through, not a real card. (This is the extra surface frame that made
      signup look double-wrapped.)
   2. The signup layout container (.bp-signup), which holds the real cards
      (plan box, order summary, accordions) and must never be a card itself.

   A genuine card never contains a .bp-portal, so real cards are untouched.
   The login form card (.bp-portal-card--auth) is a real card and stays. */
.bp-portal-card:has(.bp-portal),
.bp-portal-card.bp-signup {
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
    margin: 0;
    border-radius: 0;
}

/* ── Signup: collapsible add-on group accordions ─────── */
.bp-signup-accordion {
    border: 1px solid var(--bp-border);
    border-radius: var(--bp-radius);
    background: var(--bp-surface);
    margin-bottom: 12px;
    overflow: hidden;
}
.bp-signup-accordion__summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 700;
    color: var(--bp-text);
    -webkit-user-select: none;
    user-select: none;
}
.bp-signup-accordion__summary::-webkit-details-marker { display: none; }
.bp-signup-accordion__summary:hover { background: var(--bp-hover); }
.bp-signup-accordion__summary::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--bp-muted);
    border-bottom: 2px solid var(--bp-muted);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-left: auto;
    flex: 0 0 auto;
}
.bp-signup-accordion[open] > .bp-signup-accordion__summary::after {
    transform: rotate(-135deg);
}
.bp-signup-accordion__body {
    padding: 4px 16px 12px;
}

/* Signup option cards (plan + add-on choices) use their own configurable
   background/text so they can stand apart from the surrounding surface. */
.bp-addon-item {
    background: var(--bp-option-bg);
    color: var(--bp-option-text);
}
.bp-addon-item label,
.bp-addon-item p,
.bp-addon-item span {
    color: var(--bp-option-text);
}

/* ── Signup: two-column layout with sticky order summary ── */
.bp-signup-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 28px;
    align-items: start;
}
/* Order-summary table: keep the money columns from touching */
.bp-order-summary table { border-spacing: 0; }
.bp-order-summary th + th,
.bp-order-summary td + td { padding-left: 22px !important; }
.bp-order-summary td,
.bp-order-summary th { white-space: nowrap; }
.bp-order-summary td:first-child,
.bp-order-summary th:first-child { white-space: normal; }
/* Money amounts stay on one line, but the small grey sub-notes (coupon
   breakdown, discount duration) are allowed to wrap so they don't blow out
   the column widths. */
.bp-order-summary span { white-space: normal; }
.bp-signup-main { min-width: 0; }
.bp-signup-aside {
    position: -webkit-sticky;
    position: sticky;
    top: 20px;
}
.bp-order-summary {
    background: var(--bp-summary-bg);
    color: var(--bp-summary-text);
    border: 1px solid var(--bp-border);
    border-radius: var(--bp-radius);
    padding: 18px 20px;
}
.bp-order-summary h2,
.bp-order-summary h3,
.bp-order-summary h4 {
    color: var(--bp-summary-text);
}
.bp-signup-step[hidden] { display: none !important; }

.bp-signup-nav {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 28px;
}

/* Step indicator */
.bp-signup-steps {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 600;
}
.bp-signup-steps__item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--bp-muted);
    white-space: nowrap;
}
.bp-signup-steps__item.is-active { color: var(--bp-link); }
.bp-signup-steps__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bp-divider);
    color: var(--bp-muted);
    font-size: 13px;
    font-weight: 700;
}
.bp-signup-steps__item.is-active .bp-signup-steps__num {
    background: var(--bp-link);
    color: #fff;
}
.bp-signup-steps__item.is-complete .bp-signup-steps__num {
    background: #16a34a;
    color: #fff;
}
.bp-signup-steps__line {
    flex: 1 1 auto;
    height: 2px;
    max-width: 64px;
    background: var(--bp-border);
}

@media (max-width: 860px) {
    .bp-signup-grid { grid-template-columns: 1fr; gap: 16px; }
    .bp-signup-aside { position: static; order: -1; margin-bottom: 8px; }
}

.bp-portal-card h2,
.bp-portal-card h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--bp-heading);
}

.bp-portal h1,
.bp-portal h2,
.bp-portal h3,
.bp-portal h4 {
    color: var(--bp-heading);
}

.bp-portal-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--bp-spacing);
    margin-bottom: var(--bp-spacing);
}

.bp-portal-card__label {
    font-size: 13px;
    color: var(--bp-muted);
    margin-bottom: 4px;
}

.bp-portal-card__value {
    font-size: 22px;
    font-weight: 600;
    color: var(--bp-text);
}

/* ── Tables ────────────────────────────────────────── */
.bp-portal-table {
    width: 100%;
    border-collapse: collapse;
}

.bp-portal-table th {
    padding: 8px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--bp-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid var(--bp-border);
}

.bp-portal-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--bp-divider);
    vertical-align: middle;
    font-size: 14px;
}

.bp-portal-table tbody tr:last-child td {
    border-bottom: none;
}

.bp-portal-table a {
    color: var(--bp-link);
    text-decoration: none;
}

.bp-portal-table a:hover {
    text-decoration: underline;
}

/* ── Chips ─────────────────────────────────────────── */
.bp-portal-chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.bp-portal-chip--success {
    background: #dcfce7;
    color: #166534;
}

.bp-portal-chip--warning {
    background: #fef3c7;
    color: #92400e;
}

.bp-portal-chip--danger {
    background: #fee2e2;
    color: #991b1b;
}

.bp-portal-chip--info {
    background: #dbeafe;
    color: #1e40af;
}

.bp-portal-chip--neutral {
    background: #f3f4f6;
    color: #4b5563;
}

/* ── Buttons ───────────────────────────────────────── */
.bp-portal-btn {
    display: inline-block;
    padding: 10px 20px;
    border: 2px solid transparent;
    border-radius: var(--bp-radius);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    text-align: center;
}

.bp-portal-btn:hover {
    text-decoration: none;
}

.bp-portal-btn--primary {
    background: var(--bp-btn-bg);
    color: var(--bp-btn-text);
    border-color: var(--bp-btn-bg);
}

.bp-portal-btn--primary:hover {
    background: var(--bp-btn-hover-bg);
    border-color: var(--bp-btn-hover-bg);
    color: var(--bp-btn-hover-text);
}

.bp-portal-btn--secondary {
    background: transparent;
    color: var(--bp-btn-bg);
    border-color: var(--bp-btn-bg);
}

.bp-portal-btn--secondary:hover {
    background: var(--bp-btn-bg);
    color: var(--bp-btn-text);
}

.bp-portal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bp-portal-btn--sm {
    padding: 5px 12px;
    font-size: 13px;
    border-width: 1px;
}

/* ── Forms ─────────────────────────────────────────── */
.bp-portal-form-group {
    margin-bottom: 16px;
}

.bp-portal-form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--bp-text);
}

.bp-portal-form-group small {
    color: var(--bp-muted);
    font-weight: 400;
}

.bp-portal-input {
    width: 100%;
    background: var(--bp-input-bg) !important;
    color: var(--bp-input-text) !important;
    border: 1px solid var(--bp-input-border) !important;
    border-radius: var(--bp-radius);
    padding: 9px 12px;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bp-portal-input:focus {
    outline: none;
    border-color: var(--bp-link);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bp-link) 20%, transparent);
}

.bp-portal textarea.bp-portal-input {
    resize: vertical;
    min-height: 100px;
}

/* ── Alerts ────────────────────────────────────────── */
.bp-portal-alert {
    padding: 12px 16px;
    border-radius: var(--bp-radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.bp-portal-alert--success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.bp-portal-alert--error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.bp-portal-alert--info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.bp-portal-alert--warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* ── Login tabs ────────────────────────────────────── */
.bp-portal-tabs {
    display: flex;
    border-bottom: 2px solid var(--bp-border);
    margin-bottom: var(--bp-spacing);
}

.bp-portal-tab, .bp-portal-tabs__tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--bp-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.15s;
}

.bp-portal-tab:hover, .bp-portal-tabs__tab:hover {
    color: var(--bp-text);
}

.bp-portal-tab--active, .bp-portal-tabs__tab--active {
    color: var(--bp-link);
    border-bottom-color: var(--bp-link);
}

.bp-portal-tab-content {
    display: none;
}

.bp-portal-tab-content--active {
    display: block;
}

/* ── Invoice detail ────────────────────────────────── */
.bp-portal-invoice-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 14px;
}

.bp-portal-invoice-summary dt {
    color: var(--bp-muted);
    font-weight: 500;
}

.bp-portal-invoice-summary dd {
    margin: 0;
    text-align: right;
    font-weight: 600;
}

.bp-portal-total-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 2px solid var(--bp-border);
    font-weight: 700;
    font-size: 16px;
}

/* ── Stripe Elements container ─────────────────────── */
#bp-card-element {
    padding: 12px;
    border: 1px solid var(--bp-input-border);
    border-radius: var(--bp-radius);
    background: var(--bp-input-bg);
    min-height: 44px;
}

#bp-card-element.StripeElement--focus {
    border-color: var(--bp-link);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bp-link) 20%, transparent);
}

/* ── Message ───────────────────────────────────────── */
.bp-portal-message {
    padding: 40px 20px;
    color: var(--bp-muted);
}

.bp-portal-message a {
    color: var(--bp-link);
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 600px) {
    .bp-portal {
        padding: 12px;
    }

    .bp-portal-cards {
        grid-template-columns: 1fr;
    }

    .bp-portal-nav {
        flex-wrap: wrap;
    }

    .bp-portal-nav__item {
        padding: 7px 12px;
        font-size: 13px;
    }

    .bp-portal-nav__item--logout {
        margin-left: 0;
    }

    .bp-portal-invoice-summary {
        grid-template-columns: 1fr;
    }

    .bp-portal-invoice-summary dd {
        text-align: left;
        margin-bottom: 8px;
    }
}
