/* ==========================================================================
   Search Wrapper CSS - Pro Coding Unified Search Overlay
   ========================================================================== */

/* Completely hide cards-wrapper and prevent ghosting when search is active */
body.search-active .cards-wrapper,
.cards-wrapper.search-hidden,
.cards-wrapper[style*="display: none"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.search-wrapper-overlay {
    position: fixed !important;
    top: 70px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: calc(100dvh - 70px) !important;
    display: none !important;
    flex-direction: column;
    align-items: center;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 30px 40px 80px;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    z-index: 9999 !important;
    background: var(--bg-primary, #0c101d);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-wrapper-overlay.active {
    display: flex !important;
    opacity: 1;
    transform: translateY(0);
}

/* Custom Scrollbar for Search Wrapper */
.search-wrapper-overlay::-webkit-scrollbar {
    width: 8px;
}
.search-wrapper-overlay::-webkit-scrollbar-track {
    background: transparent;
}
.search-wrapper-overlay::-webkit-scrollbar-thumb {
    background: var(--dynamic-nav-border, rgba(255, 255, 255, 0.2));
    border-radius: 8px;
}
@media (hover: hover) {
    .search-wrapper-overlay::-webkit-scrollbar-thumb:hover {
        background: var(--dynamic-nav-hover, rgba(255, 255, 255, 0.35));
    }
}

/* Header summary inside search wrapper */
.search-wrapper-header {
    width: 100%;
    max-width: 1280px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding: 0 4px;
}

.search-results-count {
    font-size: 15px;
    font-weight: 600;
    color: var(--dynamic-text-secondary, rgba(255, 255, 255, 0.75));
    letter-spacing: 0.3px;
}

.search-clear-btn {
    background: var(--dynamic-nav-bg, rgba(255, 255, 255, 0.1));
    border: 1px solid var(--dynamic-nav-border, rgba(255, 255, 255, 0.2));
    color: var(--dynamic-text-primary, #ffffff);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}
@media (hover: hover) {
    .search-clear-btn:hover {
        background: var(--dynamic-nav-hover, rgba(255, 255, 255, 0.2));
        transform: translateY(-1px);
    }
}

/* Results Grid - Responsive Multi-Column */
.search-results-grid {
    width: 100%;
    max-width: 1280px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    box-sizing: border-box;
}

/* Search Result Card */
.search-result-card {
    background: var(--dynamic-nav-bg, rgba(255, 255, 255, 0.08));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--dynamic-nav-border, rgba(255, 255, 255, 0.15));
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.25s ease, background 0.25s ease;
    text-decoration: none;
    user-select: none;
    box-sizing: border-box;
}

@media (hover: hover) {
    .search-result-card:hover {
        transform: translateY(-4px) scale(1.015);
        border-color: rgba(255, 255, 255, 0.4);
        box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
        background: var(--dynamic-nav-hover, rgba(255, 255, 255, 0.14));
    }
}

.search-result-card:active {
    transform: scale(0.985);
}

/* Thumbnail Area */
.search-card-thumb-wrap {
    position: relative;
    width: 100%;
    height: 150px;
    border-radius: 14px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.search-card-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 12px;
    transition: transform 0.35s ease;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.25));
}

@media (hover: hover) {
    .search-result-card:hover .search-card-thumb {
        transform: scale(1.08);
    }
}

/* Type Badge overlay on card top-right with high contrast */
.search-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
    border: none;
    z-index: 2;
    line-height: 1.3;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Vibrant High-Contrast Badge Themes (Readable in Light and Dark Mode) */
.badge-byte {
    background: #0284c7 !important; /* Deep Sky Blue */
}
.badge-control_statement {
    background: #059669 !important; /* Rich Emerald */
}
.badge-mini_project {
    background: #d97706 !important; /* Warm Amber */
}
.badge-course_section, .badge-language_section {
    background: #4f46e5 !important; /* Royal Indigo */
}
.badge-course {
    background: #7c3aed !important; /* Vibrant Purple */
}
.badge-language {
    background: #e11d48 !important; /* Rich Rose */
}
.badge-category {
    background: #ca8a04 !important; /* Golden Ochre */
}

/* Card Text Content */
.search-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.search-card-parent {
    font-size: 12px;
    font-weight: 600;
    color: var(--dynamic-text-secondary, rgba(255, 255, 255, 0.7));
    display: flex;
    align-items: center;
    gap: 5px;
    text-transform: capitalize;
}

.search-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--dynamic-text-primary, #ffffff);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}

.search-card-action {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.search-card-btn {
    font-size: 12px;
    font-weight: 600;
    color: var(--dynamic-text-primary, #ffffff);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    opacity: 0.85;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) {
    .search-result-card:hover .search-card-btn {
        opacity: 1;
        transform: translateX(3px);
    }
}

/* Skeleton Loading State */
.search-skeleton-card {
    background: var(--dynamic-nav-bg, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--dynamic-nav-border, rgba(255, 255, 255, 0.1));
    border-radius: 20px;
    padding: 16px;
    height: 230px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.skeleton-shimmer {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.12) 50%, rgba(255, 255, 255, 0.04) 75%);
    background-size: 200% 100%;
    animation: searchShimmer 1.5s infinite;
    border-radius: 10px;
}

@keyframes searchShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-thumb {
    width: 100%;
    height: 140px;
}
.skeleton-line-sm {
    width: 40%;
    height: 14px;
}
.skeleton-line-lg {
    width: 80%;
    height: 20px;
}

/* Empty State */
.search-empty-state {
    width: 100%;
    max-width: 500px;
    margin: 60px auto;
    text-align: center;
    padding: 40px 30px;
    background: var(--dynamic-nav-bg, rgba(255, 255, 255, 0.06));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--dynamic-nav-border, rgba(255, 255, 255, 0.15));
    border-radius: 24px;
    box-sizing: border-box;
}

.search-empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 20px;
    background: var(--dynamic-nav-bg, rgba(255, 255, 255, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dynamic-text-primary, #ffffff);
    opacity: 0.8;
}

.search-empty-icon svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
}

.search-empty-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--dynamic-text-primary, #ffffff);
    margin-bottom: 8px;
}

.search-empty-desc {
    font-size: 14px;
    color: var(--dynamic-text-secondary, rgba(255, 255, 255, 0.7));
    line-height: 1.5;
}

/* ==========================================================================
   Responsive Grid Breakdown:
   - Tablets / Medium screens: At least 3 cards per row
   - Small screens / Mobile: At least 2 cards per row
   ========================================================================== */

/* Tablets / Medium devices (641px to 1024px) -> At least 3 columns */
@media (max-width: 1024px) and (min-width: 641px) {
    .search-wrapper-overlay {
        top: 60px !important;
        height: calc(100dvh - 60px) !important;
        padding: 24px 20px 70px;
    }
    .search-results-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 14px;
    }
    .search-result-card {
        padding: 13px;
        border-radius: 16px;
    }
    .search-card-thumb-wrap {
        height: 120px;
        margin-bottom: 10px;
    }
    .search-card-title {
        font-size: 15px;
    }
    .search-skeleton-card {
        height: 200px;
    }
    .skeleton-thumb {
        height: 120px;
    }
}

/* Small screens / Phones / Mobile landscape (max-width: 640px) -> At least 2 columns */
@media (max-width: 640px) {
    .search-wrapper-overlay {
        top: 55px !important;
        height: calc(100dvh - 55px) !important;
        padding: 14px 10px 60px;
    }
    .search-wrapper-header {
        margin-bottom: 12px;
        padding: 0 2px;
    }
    .search-results-count {
        font-size: 13px;
    }
    .search-clear-btn {
        padding: 4px 10px;
        font-size: 11px;
    }
    .search-results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    .search-result-card {
        padding: 10px;
        border-radius: 14px;
    }
    .search-card-thumb-wrap {
        height: 95px;
        border-radius: 10px;
        margin-bottom: 8px;
    }
    .search-card-thumb {
        padding: 6px;
    }
    .search-card-badge {
        top: 6px;
        right: 6px;
        padding: 2px 7px;
        font-size: 9.5px;
        border-radius: 12px;
        letter-spacing: 0.3px;
    }
    .search-card-parent {
        font-size: 10px;
    }
    .search-card-title {
        font-size: 13px;
        line-height: 1.25;
    }
    .search-card-action {
        margin-top: 6px;
        padding-top: 6px;
    }
    .search-card-btn {
        font-size: 11px;
    }
    .search-skeleton-card {
        height: 165px;
        padding: 10px;
        border-radius: 14px;
        gap: 8px;
    }
    .skeleton-thumb {
        height: 95px;
    }
}
