/* --- VARIABLES --- */
:root {
    /* Light Mode */
    --cb-bg: #f5f5f7;
    --cb-sidebar-bg: #ffffff;
    --cb-header-bg: rgba(255, 255, 255, 0.85);
    
    --cb-text: #1d1d1f;
    --cb-text-sub: #86868b;
    --cb-border: #d2d2d7;
    
    --cb-card-bg: #ffffff;
    --cb-card-hover: #ffffff;
    
    --cb-btn-primary-bg: #0071e3;
    --cb-btn-primary-text: #ffffff;
    --cb-btn-primary-hover: #0077ED;
    
    --cb-btn-sec-bg: #e8e8ed;
    --cb-btn-sec-text: #1d1d1f;
    --cb-btn-sec-hover: #d2d2d7;

    --cb-input-bg: #e8e8ed;
    --cb-tag-bg: #f5f5f7;
    --cb-tag-text: #1d1d1f;

    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 10px 30px rgba(0, 0, 0, 0.12);
    
    --cb-accent: #0071e3;
    --cb-purple: #9d4edd; /* New AI Color */
    --cb-gold: #fbbf24;
    
    --radius-l: 18px;
    --radius-m: 12px;
    --radius-s: 8px;
    
    --sidebar-width: 260px;
    --header-height: 70px;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark Mode */
        --cb-bg: #000000;
        --cb-sidebar-bg: #1c1c1e;
        --cb-header-bg: rgba(28, 28, 30, 0.85);
        
        --cb-text: #f5f5f7;
        --cb-text-sub: #86868b;
        --cb-border: #38383a;
        
        --cb-card-bg: #1c1c1e;
        --cb-card-hover: #2c2c2e;
        
        --cb-btn-primary-bg: #0071e3;
        --cb-btn-primary-text: #ffffff;
        --cb-btn-primary-hover: #2fb4ff;
        
        --cb-btn-sec-bg: #2c2c2e;
        --cb-btn-sec-text: #ffffff;
        --cb-btn-sec-hover: #3a3a3c;

        --cb-input-bg: #2c2c2e;
        
        --cb-tag-bg: #2c2c2e;
        --cb-tag-text: #9aa0a6;

        --shadow-soft: 0 4px 12px rgba(0,0,0,0.3);
        --shadow-hover: 0 10px 40px rgba(0,0,0,0.6);
        
        --cb-accent: #2997ff;
        --cb-purple: #bb86fc;
    }
    .cb-sidebar-logo { filter: invert(1) !important; }
}

/* --- BASE --- */
html, body {
    margin: 0;
    padding: 0;
    background-color: var(--cb-bg);
    color: var(--cb-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    scrollbar-width: thin;
}

h1, h2, h3, h4 { font-family: 'Poppins', sans-serif; margin: 0; }
a { text-decoration: none; color: inherit; -webkit-tap-highlight-color: transparent;}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Algolia Highlight */
em {
    font-style: normal;
    background: rgba(0, 113, 227, 0.2);
    color: var(--cb-accent);
    border-radius: 2px;
}

/* --- LAYOUT SHELL --- */
.cb-shell {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR (Desktop) --- */
.cb-sidebar {
    width: var(--sidebar-width);
    background: var(--cb-sidebar-bg);
    border-right: 1px solid var(--cb-border);
    position: fixed;
    height: 100vh;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease;
}

.cb-sidebar-logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding-left: 10px;
    cursor: pointer;
}

.cb-sidebar-logo { height: 32px; width: auto; }
.cb-sidebar-title { font-size: 20px; font-weight: 400; letter-spacing: -0.5px; font-family: 'Poppins';}

.cb-nav-group { margin-bottom: 30px; }
.cb-nav-label { 
    font-size: 12px; 
    font-weight: 600; 
    color: var(--cb-text-sub); 
    text-transform: uppercase; 
    letter-spacing: 0.8px;
    margin-bottom: 12px;
    padding-left: 12px;
}

.cb-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-m);
    color: var(--cb-text-sub);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.cb-nav-item i { font-size: 20px; }

.cb-nav-item:hover { background: var(--cb-btn-sec-bg); color: var(--cb-text); }
.cb-nav-item.active { background: var(--cb-btn-sec-bg); color: var(--cb-accent); }

/* --- MAIN CONTENT AREA --- */
.cb-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    position: relative;
    width: calc(100% - var(--sidebar-width));
}

/* --- STICKY HEADER --- */
.cb-top-bar {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background: var(--cb-header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
}

.cb-search-wrapper {
    flex: 1;
    max-width: 600px;
    position: relative;
}

.cb-search-input-group {
    display: flex;
    align-items: center;
    background: var(--cb-input-bg);
    border-radius: 10px;
    padding: 0 16px;
    height: 40px;
    transition: all 0.2s;
}

.cb-search-input-group:focus-within {
    box-shadow: 0 0 0 2px var(--cb-accent);
    background: var(--cb-bg);
}

/* Magic AI Mode Style */
.cb-search-input-group.magic-mode {
    background: rgba(157, 78, 221, 0.05); /* Light purple tint */
    border: 1px solid rgba(157, 78, 221, 0.3);
}

.cb-search-input-group.magic-mode:focus-within {
    box-shadow: 0 0 0 2px var(--cb-purple);
    background: var(--cb-bg);
}

.cb-search-input-group i { color: var(--cb-text-sub); font-size: 18px; margin-right: 12px; }

.cb-search-input {
    border: none;
    background: transparent;
    flex: 1;
    font-size: 14px;
    color: var(--cb-text);
    outline: none;
}

.cb-loader {
    width: 16px; height: 16px;
    border: 2px solid var(--cb-text-sub);
    border-top-color: var(--cb-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

/* --- AI SWITCH TOGGLE --- */
.cb-ai-toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--cb-border);
    margin-left: 8px;
}

.cb-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
}

.cb-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.cb-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 18px;
}

.cb-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .cb-slider {
    background-color: var(--cb-purple); /* Purple for AI */
}

input:focus + .cb-slider {
    box-shadow: 0 0 1px var(--cb-purple);
}

input:checked + .cb-slider:before {
    transform: translateX(14px);
}

.cb-ai-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--cb-text-sub);
    text-transform: uppercase;
}
input:checked ~ .cb-ai-label {
    color: var(--cb-purple);
}

/* --- HEADER BUTTONS --- */
.cb-header-actions {
    display: flex;
    gap: 12px;
    margin-left: 20px;
}

.cb-btn {
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.cb-btn-primary { background: var(--cb-btn-primary-bg); color: var(--cb-btn-primary-text); }
.cb-btn-primary:hover { opacity: 0.9; transform: scale(1.02); }

.cb-btn-ghost { background: transparent; color: var(--cb-text); }
.cb-btn-ghost:hover { background: var(--cb-btn-sec-bg); }

/* --- CONTENT PADDING --- */
.cb-content {
    padding: 40px;
    max-width: 1600px;
    margin: 0 auto;
}

/* --- HERO BANNER (SPOTLIGHT) --- */
.cb-spotlight {
    width: 100%;
    height: 300px;
    border-radius: var(--radius-l);
    background: linear-gradient(135deg, #1e1e1e 0%, #3a3a3a 100%);
    margin-bottom: 40px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    padding: 0 60px;
    box-shadow: var(--shadow-soft);
}

.cb-spotlight-content {
    position: relative;
    z-index: 2;
    max-width: 500px;
    color: white;
}

.cb-spotlight-tag {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: rgba(255,255,255,0.7);
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.cb-spotlight h1 {
    font-size: 42px;
    font-weight: 600;
    line-height: 1.1;
    margin-bottom: 16px;
}

.cb-spotlight p {
    font-size: 16px;
    color: rgba(255,255,255,0.8);
    margin-bottom: 24px;
    line-height: 1.5;
}

.cb-spotlight-btn {
    background: white;
    color: black;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s;
}
.cb-spotlight-btn:hover { transform: scale(1.05); }

/* Background Decoration for Banner */
.cb-spotlight-visual {
    position: absolute;
    right: -50px;
    top: -50px;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--cb-accent) 0%, transparent 70%);
    opacity: 0.2;
    filter: blur(60px);
}

/* --- FEED HEADER --- */
.cb-feed-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.cb-section-title { font-size: 24px; font-weight: 600; color: var(--cb-text); }

.cb-sort-select {
    background: var(--cb-btn-sec-bg);
    color: var(--cb-text);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    outline: none;
}

/* --- GRID --- */
.cb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 32px 24px;
}

/* --- CARD DESIGN (APP STORE STYLE) --- */
.cb-card {
    background: var(--cb-card-bg);
    border-radius: var(--radius-l);
    padding: 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 1px solid transparent; /* Prepare for hover border */
    box-shadow: var(--shadow-soft);
}

.cb-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    z-index: 2;
}

.cb-card-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.cb-card-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--cb-input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.cb-card-icon img, .cb-card-icon svg { width: 32px; height: 32px; object-fit: contain; }

.cb-card-meta {
    flex: 1;
    min-width: 0;
}


.cb-card-title {
    font-size: 16px;
    font-weight: 600;
    margin: 4px 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--cb-text);
}

.cb-card-author {
    font-size: 13px;
    color: var(--cb-text-sub);
    margin-bottom: 8px;
}

/* The 'Get' Button positioned top right or inline */
.cb-card-action {
    background: var(--cb-btn-sec-bg);
    color: var(--cb-accent);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 16px;
    border-radius: 20px;
    text-transform: uppercase;
    transition: all 0.2s;
    display: inline-block;
    font-family: 'Poppins';
}
.cb-card:hover .cb-card-action {
    background: var(--cb-accent);
    color: white;
}

.cb-card-desc {
    font-size: 13px;
    color: var(--cb-text-sub);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 16px;
    min-height: 38px; /* Maintain height alignment */
}

/* Tags & Stats Footer */
.cb-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--cb-btn-sec-bg);
}

.cb-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--cb-text-sub);
}
.cb-rating i { color: var(--cb-text-sub); }
.cb-rating.high i { color: var(--cb-gold); } /* Gold star for high ratings */

.cb-stats-row {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--cb-text-sub);
}
.cb-stat-item { display: flex; align-items: center; gap: 4px; }

/* Featured Tag */
.cb-featured-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--cb-gold);
    color: #000;
    font-size: 10px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 5;
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Load More */
.cb-load-more {
    text-align: center;
    margin: 60px 0;
}
.cb-btn-load {
    background: var(--cb-card-bg);
    border: 1px solid var(--cb-border);
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--cb-text);
    transition: 0.2s;
}
.cb-btn-load:hover { border-color: var(--cb-text-sub); box-shadow: var(--shadow-soft); }

/* Utility */
.hidden { display: none !important; }

/* --- ANIMATIONS --- */
@keyframes spin { to { transform: rotate(360deg); } }

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
    .cb-sidebar {
        width: 80px;
        padding: 30px 10px;
        align-items: center;
    }
    .cb-sidebar-title, .cb-nav-label, .cb-nav-item span { display: none; }
    .cb-main { margin-left: 80px; width: calc(100% - 80px); }
    .cb-nav-item { justify-content: center; padding: 12px; }
    .cb-sidebar-logo-area { padding-left: 0; justify-content: center; }
}

@media (max-width: 768px) {
    .cb-shell { flex-direction: column; }
    .app-icon-bg {
    zoom: 0.8;
    }

    
    /* Hide Sidebar on mobile, create bottom nav or simpler nav */
    .cb-sidebar { display: none; }
    .cb-main { margin-left: 0; width: 100%; }
    
    .cb-top-bar { padding: 0 20px; height: 60px; }
    .cb-content { padding: 20px; }
    
    .cb-spotlight { height: auto; flex-direction: column; padding: 30px; text-align: center; }
    .cb-spotlight-content { max-width: 100%; }
    .cb-spotlight h1 { font-size: 28px; }
    .cb-spotlight-visual { display: none; }
    
    .cb-header-actions { display: none; } /* Simplify header */
    .cb-grid { grid-template-columns: 1fr; }
    
    .cb-card { flex-direction: row; align-items: center; padding: 16px; }
    .cb-card-header { margin-bottom: 0; gap: 12px; }
    .cb-card-icon { width: 52px; height: 52px; }
    .cb-card-desc, .cb-card-footer { display: none; } /* Minimalist list view on mobile */
    .cb-card-action { margin-left: auto; }
}

.cb-suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--cb-card-bg); /* Matches header/card bg */
    border: 1px solid var(--cb-border);
    border-top: none;
    border-radius: 0 0 16px 16px;
    box-shadow: var(--shadow-hover);
    z-index: 1000;
    overflow: hidden;
    margin-top: 4px; 
    padding: 8px 0;
    display: none; /* Hidden by default */
}

.cb-suggestions-dropdown.visible {
    display: block;
}

.cb-suggestion-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--cb-text);
    font-size: 14px;
    transition: background-color 0.1s ease;
}

.cb-suggestion-item:hover {
    background-color: var(--cb-input-bg);
}

.cb-suggestion-item i {
    color: var(--cb-text-sub);
    font-size: 16px;
}

/* Highlighted match text from Algolia */
.cb-suggestion-item em {
    font-style: normal;
    font-weight: 600;
    background: transparent;
    color: var(--cb-text); 
}

/* Styling the input container when dropdown is active */
.cb-search-input-group.has-suggestions {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    background-color: var(--cb-card-bg); /* White/Black instead of grey */
    box-shadow: 0 0 0 2px var(--cb-accent);
}

/* --- MODAL --- */
.cb-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.cb-modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
.cb-modal {
    background: var(--cb-card-bg);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-m);
    padding: 24px;
    box-shadow: var(--shadow-hover);
    transform: translateY(10px);
    transition: transform 0.2s ease;
    border: 1px solid var(--cb-border);
}
.cb-modal-overlay.visible .cb-modal {
    transform: translateY(0);
}
.cb-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.cb-modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: var(--cb-text);
}
.cb-btn-icon {
    background: none; border: none; cursor: pointer; font-size: 20px; 
    color: var(--cb-text-sub);
    padding: 4px; border-radius: 4px;
    transition: 0.2s;
}
.cb-btn-icon:hover { 
    background: var(--cb-btn-sec-bg);
    color: var(--cb-text);
}
.cb-modal-body p {
    color: var(--cb-text-sub);
    font-size: 14px;
    margin-bottom: 16px;
    line-height: 1.5;
}
.cb-textarea {
    width: 100%;
    border: 1px solid var(--cb-border);
    border-radius: var(--radius-s);
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    outline: none;
    margin-bottom: 24px;
    background: var(--cb-input-bg);
    color: var(--cb-text);
    transition: 0.2s;
}
.cb-textarea:focus { 
    border-color: var(--cb-accent);
    background: var(--cb-card-bg);
}
.cb-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}