/* =====================================================================
 * ceASAP — CE Courses Page Styling
 *
 * Scoped to #ce-courses to avoid collisions with theme styles.
 * Companion file to ceASAP CE Courses Shortcode (registers [ce_courses]).
 * Companion file to filters.js (handles tab/filter/search interaction).
 *
 * Palette:
 *   #2b6cb0  brand blue (active states, ADD TO CART)
 *   #1b4f7a  darker navy (hover, course-number)
 *   #e5e7eb  borders
 *   #6b7280  muted gray
 *   #374151  body text
 * ===================================================================== */

#ce-courses {
    color: #374151;
    font-family: inherit;
}

#ce-courses *,
#ce-courses *::before,
#ce-courses *::after {
    box-sizing: border-box;
}

#ce-courses .container {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
}

/* =====================================================================
 * SVG SIZE GUARDRAILS — caps any SVG so it can never balloon.
 * Belt-and-suspenders fix for the "giant black circle" bug.
 * ===================================================================== */
#ce-courses svg {
    max-width: 100%;
    max-height: 100%;
}
#ce-courses .icon {
    width: 18px !important;
    height: 18px !important;
}

/* =====================================================================
 * SIDEBAR — matched to staging screenshot
 *
 * Pale blue background, centered dark-navy header, white search box and
 * filter pills with no borders, blue active pill, quiet reset button.
 * ===================================================================== */
#ce-courses .sidebar {
    flex: 0 0 290px;
    background: #d9e7f3;
    border-radius: 16px;
    padding: 26px 22px;
    /* Sticky to follow scroll. No height constraint or overflow rule
       so it grows naturally and never shows an internal scrollbar. */
    position: sticky;
    top: 60px;
    align-self: flex-start;
}

#ce-courses .sidebar-header {
    text-align: center;
    margin: 0 0 22px 0;
    font-size: 1.7rem;             /* large header to match screenshot */
    font-weight: 800;
    color: #1b4f7a;
    line-height: 1.2;
    letter-spacing: 0;
}

#ce-courses .search-box {
    margin-bottom: 18px;
}

#ce-courses .search {
    width: 100%;
    padding: 10px 15px;
    background: #fff;
    border: none;
    border-radius: 5px;
    font-size: 0.92rem;
    color: #374151;
    outline: none;
    box-shadow: none;
    transition: box-shadow 0.15s;
}
#ce-courses .search::placeholder {
    color: #9ca3af;
}
#ce-courses .search:focus {
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.18);
}

/* Filter group: only the active one renders */
#ce-courses .filter-group {
    display: none;
}
#ce-courses .filter-group.active {
    display: block;
}

#ce-courses .filter {
    display: block;
    background: #fff;
    border: none;
    border-radius: 5px;
    padding: 10px 15px;
    margin: 10px 0;
    font-size: 0.92rem;
    font-weight: 500;
    color: #000;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: none;
}
#ce-courses .filter:hover {
    background: #1b4f7a;
    color: #fff;
}
#ce-courses .filter.active {
    background: #1b4f7a;            /* match original */
    color: #fff;
    font-weight: 700;
}

#ce-courses .reset-btn {
    width: 100%;
    margin-top: 14px;
    padding: 10px 15px;
    background: #fff;
    border: 1px solid #c2d4e6;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
}
#ce-courses .reset-btn:hover {
    background: #f3f7fb;
    color: #1b4f7a;
    border-color: #a8bfd4;
}

/* =====================================================================
 * MAIN AREA
 * ===================================================================== */
#ce-courses .main {
    flex: 1;
    min-width: 0; /* prevents flex children from overflowing */
}

/* Sticky H1 + tabs wrapper */
#ce-courses .head_main {
    position: sticky;
    top: 32px; /* matches WP admin bar offset for logged-in users */
    z-index: 50;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 14px 0;
    margin-bottom: 18px;
}
body:not(.admin-bar) #ce-courses .head_main {
    top: 0;
}

#ce-courses .main h1,
#ce-courses .head_main h1 {
    text-align: center;
    margin: 0 0 14px 0;
    font-size: 2.1rem !important;
    font-weight: 700 !important;
    color: #1b4f7a !important;
    line-height: 1.25 !important;
}

/* =====================================================================
 * TABS (Live | Self-Paced)
 * ===================================================================== */
#ce-courses .tabs {
    display: flex;
    gap: 0;
    background: #e5e7eb;
    border-radius: 999px;
    padding: 4px;
    margin: 0 auto;
    max-width: 520px;
}

#ce-courses .tab {
    flex: 1;
    text-align: center;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #6b7280;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
#ce-courses .tab.active {
    background: #2b6cb0;
    color: #fff;
}

/* =====================================================================
 * TAB CONTENT (cards container)
 *
 * Baseline rule prevents flash of all cards on first load:
 * only the active tab's cards render until JS swaps.
 * ===================================================================== */
#ce-courses .tabs_cards {
    display: none;
}
#ce-courses .tabs_cards.active {
    display: block;
}

/* =====================================================================
 * CARDS GRID
 * ===================================================================== */
#ce-courses .cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding-top: 25px;
}

#ce-courses .card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: transform 0.15s, box-shadow 0.15s;
}
#ce-courses .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* Card image area — fixed 250px height to match original */
#ce-courses .card-img {
    position: relative;
}
#ce-courses .card-img img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    object-position: top;
    display: block;
}

/* Category badge — top-left, with curved bottom-right corner */
#ce-courses .badge {
    position: absolute;
    top: 0;
    left: 0;
    padding: 5px 15px;
    background: #2b6cb0;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border-radius: 0 0 15px 0;
}

/* Per-category badge tints — match original simple class names */
#ce-courses .badge.Agency    { background: #1e3a5f; }    /* dark blue */
#ce-courses .badge.Contracts { background: #3b82f6; }    /* blue */
#ce-courses .badge.Ethics    { background: #d851e2; }    /* purple */
#ce-courses .badge.Risk      { background: #f59e0b; }    /* orange */
#ce-courses .badge.Property  { background: #4bb549; }    /* green */
#ce-courses .badge.General   { background: #f57547; }    /* red */
#ce-courses .badge.Law       { background: #1f2937; }    /* almost black */
#ce-courses .badge.Broker    { background: #6366f1; }    /* indigo */
#ce-courses .badge.Business  { background: #475569; }    /* slate */

/* Hours circle — bottom-left, 50x50 to match original */
#ce-courses .hours {
    position: absolute;
    bottom: -20px;
    left: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #0F5EAA;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.1;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
#ce-courses .hours span {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}
#ce-courses .hours small {
    font-size: 10px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
}

/* Card body — match original padding and typography */
#ce-courses .card-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

#ce-courses .card-body h4 {
    margin: 0;
    color: #0F5EAA;
    font-size: 18px;
    font-weight: 600;
    padding-top: 15px;
    line-height: 1.3;
}
#ce-courses .card-body h4 .course-number {
    color: #0F5EAA;
    font-weight: 600;
}

#ce-courses .course-date {
    font-size: 14px;
    font-weight: 700;
    color: #000;
    margin: 6px 0 0 0;
}

#ce-courses .card-body h3 {
    margin: 10px 0 10px 0;
    font-size: 20px;
    font-weight: 600;
    line-height: 26px;
    color: #111827;
}
/* Date line above the title — same h3 styling but smaller breathing room */
#ce-courses .card-body h3 .card-date {
    display: block;
    margin-bottom: 10px;
}
/* Course title — block element with no top margin (date span handles spacing) */
/* Clamps to 2 lines max with ellipsis if longer. Universal for Live and Self-Paced cards. */
#ce-courses .card-body h3 .card-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
#ce-courses .tabs_cards .card-body h3 {
    min-height: 52px;
}

#ce-courses .price {
    font-size: 18px;
    font-weight: 600;
    color: #1b4f7a;
    margin: auto 0 14px 0;
}

/* Buttons */
#ce-courses .btns {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

#ce-courses .btns a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.15s;
    text-align: center;
    line-height: 1.2;
    width: 50%;
}

#ce-courses .btns .primary {
    background: #2b6cb0;
    color: #fff;
}
#ce-courses .btns .primary:hover {
    background: #1b4f7a;
}
#ce-courses .btns .primary svg {
    fill: #fff;
}

#ce-courses .btns .secondary {
    background: #fff;
    color: #2b6cb0;
    border: 1px solid #2b6cb0;
}
#ce-courses .btns .secondary:hover {
    background: #f3f7fb;
    color: #1b4f7a;
    border-color: #1b4f7a;
}
#ce-courses .btns .secondary svg {
    fill: currentColor;
}

/* =====================================================================
 * MOBILE FILTER TOGGLE BUTTON + OVERLAY
 * Hidden on desktop; visible at <=991px viewport.
 * ===================================================================== */
#ce-courses .filter-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    padding: 12px 18px;
    background: #2b6cb0;
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#ce-courses .overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}
#ce-courses .overlay.active {
    display: block;
}

/* =====================================================================
 * RESPONSIVE BREAKPOINTS
 * ===================================================================== */

/* Tablet: 2-col cards */
@media (max-width: 1100px) {
    #ce-courses .cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: drawer-style sidebar, sticky off, single-col cards */
@media (max-width: 991px) {
    /* Hide " CE" suffix in tabs to keep labels on one line */
    #ce-courses .tabs .ce-suffix {
        display: none;
    }

    #ce-courses .container {
        flex-direction: column;
        padding: 0 12px;
        gap: 0;
    }

    /* Sidebar becomes a slide-in drawer */
    #ce-courses .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 320px !important;
        max-width: 90vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        z-index: 1000 !important;
        border-radius: 0 !important;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2) !important;
        align-self: auto !important;
        overflow-y: auto !important;
        transition: left 0.25s ease;
    }
    #ce-courses .sidebar.active {
        left: 0 !important;
    }
    body.admin-bar #ce-courses .sidebar {
        top: 46px !important;
        height: calc(100vh - 46px) !important;
    }

    /* Add ✕ close button to sidebar header (handled in filters.js) */
    #ce-courses .sidebar-header {
        position: relative;
        padding-right: 36px;
    }
    #ce-courses .sidebar-header::after {
        content: "✕";
        position: absolute;
        right: 4px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 28px;
        line-height: 28px;
        text-align: center;
        font-size: 18px;
        color: #6b7280;
        cursor: pointer;
        border-radius: 50%;
    }

    /* Show the mobile filter button */
    #ce-courses .filter-toggle {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    /* Drop sticky behavior on mobile (saves vertical space) */
    #ce-courses .head_main {
        position: static !important;
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        padding: 12px 0;
    }

    #ce-courses .main h1,
    #ce-courses .head_main h1 {
        font-size: 1.55rem !important;
    }

    #ce-courses .main {
        width: 100%;
    }

    #ce-courses .tab {
        padding: 10px 8px;
        font-size: 0.85rem;
    }
}

/* Small phones: 1-col cards */
@media (max-width: 600px) {
    #ce-courses .cards {
        grid-template-columns: 1fr;
    }
}

/* =====================================================================
/* =====================================================================
 * CREDITS BANNER (injected by filters.js INSIDE .head_main, right
 * after the toggle, when a logged-in student has Live/ZOOM credits
 * AND the Live tab is active).
 *
 * Behaviorally:
 *   - Hidden by default (no .visible class)
 *   - JS adds .visible when credits > 0 AND Live tab is active
 *   - Lives inside the sticky .head_main group so it stays pinned
 *     under the toggle as the user scrolls
 * ===================================================================== */
#ce-courses .ce-sticky-credits {
    /* Hidden default — JS toggles .visible based on credits + active tab */
    display: none;
    margin: 12px 0 0 0;
    background: #1b4f7a;
    color: #fff;
    border-radius: 10px;
    padding: 10px 16px;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 4px 14px rgba(27, 79, 122, 0.18);
}
#ce-courses .ce-sticky-credits.visible {
    display: block;
}
#ce-courses .ce-sticky-credits__inner {
    max-width: 800px;
    margin: 0 auto;
}
#ce-courses .ce-sticky-credits__name {
    font-weight: 700;
}
#ce-courses .ce-sticky-credits__count {
    font-weight: 800;
    font-size: 1.1em;
    color: #ffd166;
}
/* Mobile: tighter padding */
@media (max-width: 600px) {
    #ce-courses .ce-sticky-credits {
        padding: 10px 12px;
        font-size: 0.88rem;
    }
}

/* =====================================================================
 * ENROLLMENT STATE (Currently Enrolled / Course Completed)
 *
 * Per-user state is fetched by filters.js after page load via
 * /wp-json/ce/v1/enrollment-status. Until that fetch resolves, the
 * #ce-courses root has no .user-state-resolved class. We use that
 * gate to hide the price + buttons strip during the brief moment
 * between HTML render and REST response — preventing button-text flicker.
 *
 * For logged-out users, the fetch is skipped entirely and
 * .user-state-resolved is added immediately, so they see the default
 * state with no perceptible delay.
 *
 * State rules:
 *   .card.is-enrolled   → hide price; ADD TO CART → "Enrolled" (status only),
 *                          COURSE INFO → "Go to Course"
 *   .card.is-completed  → hide price; ADD TO CART → "Completed" (status only),
 *                          COURSE INFO → "View Certificate" (links to cert)
 *   default (no class)  → price visible; ADD TO CART + COURSE INFO normal
 * ===================================================================== */

/* Hide price + buttons during the brief moment before user state is known.
   Cards, images, badges, hours, titles, dates all render normally. */
#ce-courses:not(.user-state-resolved) .price,
#ce-courses:not(.user-state-resolved) .btns {
    visibility: hidden;
}

/* When the user state is resolved (or it was a guest), reveal price+buttons. */
#ce-courses.user-state-resolved .price,
#ce-courses.user-state-resolved .btns {
    visibility: visible;
}

/* ----- Currently Enrolled ----- */
#ce-courses .card.is-enrolled .price {
    display: none;
}
#ce-courses .card.is-enrolled .primary {
    /* Becomes a non-clickable status label. */
    pointer-events: none;
    cursor: default;
}
#ce-courses .card.is-enrolled .primary .btn-label::before {
    content: "ENROLLED";
}
#ce-courses .card.is-enrolled .secondary .btn-label::before {
    content: "GO TO COURSE";
}

/* ----- Course Completed ----- */
#ce-courses .card.is-completed .price {
    display: none;
}
#ce-courses .card.is-completed .primary {
    pointer-events: none;
    cursor: default;
    /* Slightly different shade to distinguish from enrolled state */
    background: #1b4f7a;
}
#ce-courses .card.is-completed .primary .btn-label::before {
    content: "COMPLETED";
}
#ce-courses .card.is-completed .secondary .btn-label::before {
    content: "VIEW CERTIFICATE";
}

/* When .btn-label::before sets content via the state classes above,
   we hide the original label text. The shortcode renders each button
   label inside a .btn-label span so we can target it cleanly. */
#ce-courses .card.is-enrolled .btn-label,
#ce-courses .card.is-completed .btn-label {
    font-size: 0; /* hide the original "ADD TO CART" / "COURSE INFO" text */
}
#ce-courses .card.is-enrolled .btn-label::before,
#ce-courses .card.is-completed .btn-label::before {
    font-size: 0.85rem; /* but show the ::before pseudo-element label */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Hide the SVG icons (cart, book) when card has enrolled/completed state */
#ce-courses .card.is-enrolled .btns .icon,
#ce-courses .card.is-completed .btns .icon {
    display: none;
}

/* =====================================================================
 * USES-CREDIT button text swap (Live/ZOOM cards in default state when
 * user has Live/ZOOM credits).
 *
 * JS adds .uses-credit class to qualifying cards. CSS then:
 *   - Swaps the .primary button label from "ADD TO CART" to "ADD TO CE PACKAGE"
 *   - Hides the original cart icon
 *   - Adds a plus-sign icon via SVG background (data URI)
 *   - Hides the price (the credit covers it)
 *   - Click handler in filters.js intercepts and runs redeem flow
 * ===================================================================== */

/* Hide the price — credit covers the cost, no $ needed. */
#ce-courses .card.uses-credit .price {
    display: none;
}

#ce-courses .card.uses-credit .primary .btn-label {
    font-size: 0; /* hide original label text */
}
#ce-courses .card.uses-credit .primary .btn-label::before {
    content: "ADD TO CE PACKAGE";
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}
/* Force the entire ADD TO CE PACKAGE primary button to stay on one line
 * (icon + label). Tightens padding and reduces letter-spacing to fit
 * within the 50%-width button slot. */
#ce-courses .card.uses-credit .primary {
    white-space: nowrap;
    padding-left: 6px;
    padding-right: 6px;
    gap: 0;
}
/* Hide the cart SVG icon — we'll add a plus icon instead via ::before. */
#ce-courses .card.uses-credit .primary .icon {
    display: none;
}
/* Plus-sign icon: rendered via SVG data URI on .primary::before so it
   sits on the LEFT of the label (matching the original cart-icon position). */
#ce-courses .card.uses-credit .primary::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-right: 2px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round'><path d='M12 5v14M5 12h14'/></svg>") center/contain no-repeat;
    flex-shrink: 0;
}

/* =====================================================================
 * TOAST (confirm/cancel + auto-dismiss for credit redemption)
 * Slides up from bottom-right on desktop, bottom-center on mobile.
 * ===================================================================== */
.ce-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    padding: 16px 20px;
    max-width: 380px;
    min-width: 280px;
    font-family: inherit;
    color: #1f2937;
    line-height: 1.5;
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.25s ease-out, opacity 0.2s ease-out;
}
.ce-toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.ce-toast--error {
    border-color: #fecaca;
    background: #fff5f5;
    color: #991b1b;
}

.ce-toast__msg {
    font-size: 14px;
    margin-bottom: 12px;
}
.ce-toast__msg:last-child {
    margin-bottom: 0;
}

.ce-toast__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ce-toast__btn {
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: inherit;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ce-toast__btn:hover {
    background: #f3f4f6;
}
.ce-toast__btn--confirm {
    background: #1b4f7a;
    border-color: #1b4f7a;
    color: #fff;
}
.ce-toast__btn--confirm:hover {
    background: #143957;
    border-color: #143957;
}

/* Mobile: bottom-center, full-width-ish */
@media (max-width: 600px) {
    .ce-toast {
        right: 12px;
        left: 12px;
        bottom: 12px;
        max-width: none;
        min-width: 0;
    }
}