/* ==========================================================================
   1. ROOT & BASE STYLES
   ========================================================================== */
:root {
    --primary: #ff6b6b;
    --primary-dark: #ee5253;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; font-size: 16px; }
body { margin: 0; padding: 0; font-family: 'Inter', system-ui, sans-serif; background-color: var(--bg-main); color: var(--text-main); line-height: 1.5; }
body.modal-open { overflow: hidden; } 
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; transition: var(--transition-fast); }
button, input, select { font-family: inherit; font-size: inherit; }

/* ==========================================================================
   2. REFINED LAYOUT
   ========================================================================== */
.main-header { height: 70px; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; position: sticky; top: 0; z-index: 1000; }
.header-container { width: 100%; max-width: 1300px; margin: 0 auto; padding: 0 24px; }
.brand a { font-weight: 900; font-size: 1.5rem; color: var(--primary); text-transform: uppercase; }

/* The search container is now the relative anchor for sidebars */
.search-container { 
    max-width: 800px; 
    margin: 0 auto; 
    padding: 0 24px; 
    position: relative; 
}

/* ==========================================================================
   3. SEARCH UI
   ========================================================================== */
.search-hero { padding: 60px 0 30px; text-align: center; transition: var(--transition-base); }
.search-hero.active { padding: 30px 0 20px; }
.logo { font-size: 3.5rem; margin: 0 0 30px 0; font-weight: 800; background: linear-gradient(135deg, var(--text-main) 0%, #475569 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.search-box-container { max-width: 700px; margin: 0 auto; position: relative; }
.search-box { position: relative; display: flex; align-items: center; filter: drop-shadow(var(--shadow-md)); }
.search-icon { position: absolute; left: 24px; width: 24px; height: 24px; color: var(--text-muted); }
#searchInput { width: 100%; padding: 20px 20px 20px 64px; border-radius: var(--radius-lg); border: 2px solid transparent; font-size: 1.15rem; background: var(--bg-card); outline: none; transition: var(--transition-base); }
#searchInput:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.1); }
.search-controls { display: flex; justify-content: center; align-items: center; gap: 24px; margin-top: 24px; flex-wrap: wrap; }
.sort-group { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text-muted); font-size: 0.95rem; }
.sort-group select { border: 1px solid var(--border-color); padding: 8px 12px; border-radius: var(--radius-sm); outline: none; }
.filter-toggle-btn { background: #fff; border: 1px solid var(--border-color); padding: 8px 16px; border-radius: var(--radius-md); font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.filter-panel { max-height: 0; overflow: hidden; opacity: 0; transition: var(--transition-base); }
.filter-panel.active { max-height: 1000px; opacity: 1; margin-top: 24px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; background: #fff; padding: 24px; border-radius: var(--radius-lg); border: 1px solid var(--border-color); }
.filter-group label { display: block; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }
.filter-group select { width: 100%; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); background: #f1f5f9; font-weight: 600; }
.search-stats { margin-top: 20px; font-size: 0.95rem; font-weight: 700; color: var(--text-muted); }

/* ==========================================================================
   4. TRADITIONAL SERP LAYOUT
   ========================================================================== */
.serp-list { display: flex; flex-direction: column; gap: 35px; max-width: 800px; margin: 20px auto 40px; opacity: 0; transform: translateY(20px); transition: var(--transition-base); }
.serp-list.visible { opacity: 1; transform: translateY(0); }
.serp-result { display: flex; gap: 20px; align-items: flex-start; }
.serp-img-col { flex-shrink: 0; padding-top: 4px; }
.serp-thumb { width: 110px; height: 110px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border-color); cursor: pointer; transition: var(--transition-fast); }
.serp-thumb:hover { box-shadow: var(--shadow-md); }
.serp-content-col { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.serp-cite { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: #4d5156; font-weight: 600; }
.serp-favicon { width: 16px; height: 16px; border-radius: 50%; }
.serp-title-link { text-decoration: none; display: inline-block; cursor: pointer; }
.serp-title { font-family: arial, sans-serif; font-size: 1.4rem; color: #1a0dab; font-weight: 400; margin: 0; line-height: 1.3; }
.serp-title-link:hover .serp-title { text-decoration: underline; }
.serp-snippet { font-family: arial, sans-serif; font-size: 0.95rem; color: #4d5156; line-height: 1.58; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.serp-meta-badge { font-weight: 700; color: var(--text-main); background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 0.8rem; }
.serp-actions { margin-top: 8px; }
.btn-preview { background: #f8fafc; border: 1px solid #cbd5e1; color: #475569; padding: 4px 12px; border-radius: 16px; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: var(--transition-fast); display: inline-flex; align-items: center; gap: 6px; }
.btn-preview:hover { background: #e2e8f0; color: #0f172a; }

.pagination-container { display: flex; justify-content: center; align-items: center; gap: 15px; margin: 40px 0; }
.page-btn { background: #fff; border: 1px solid var(--border-color); padding: 10px 20px; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; }

/* ==========================================================================
   5. MODAL PREVIEW OVERLAY
   ========================================================================== */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); z-index: 2000; display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: var(--transition-base); padding: 20px; }
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content { background: #fff; width: 100%; max-width: 800px; max-height: 90vh; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow-y: auto; position: relative; transform: translateY(20px) scale(0.95); transition: var(--transition-base); }
.modal-overlay.active .modal-content { transform: translateY(0) scale(1); }
.modal-close { position: absolute; top: 15px; right: 20px; background: #f1f5f9; border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #64748b; transition: var(--transition-fast); z-index: 10; }
.modal-close:hover { background: #e2e8f0; color: #0f172a; }

.preview-hero { width: 100%; height: 250px; object-fit: cover; border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg); }
.preview-body { padding: 30px; }
.preview-title { font-size: 1.8rem; margin: 0 0 10px; line-height: 1.2; }
.preview-domain { display: inline-block; background: #f1f5f9; padding: 4px 10px; border-radius: 8px; font-size: 0.8rem; font-weight: 700; color: #64748b; margin-bottom: 20px; text-transform: uppercase; }
.preview-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 30px; margin-bottom: 25px; }
.preview-section h4 { margin: 0 0 15px; font-size: 1.1rem; border-bottom: 2px solid #f1f5f9; padding-bottom: 8px; }
.preview-list { list-style: none; padding: 0; margin: 0; }
.preview-list li { padding: 8px 0; border-bottom: 1px solid #f8fafc; position: relative; padding-left: 20px; }
.preview-list li::before { content: "•"; position: absolute; left: 0; color: var(--primary); font-weight: bold; }

.blur-light { filter: blur(4px); opacity: 0.7; user-select: none; }
.blur-heavy { filter: blur(8px); opacity: 0.3; user-select: none; }
.preview-lock { background: #fdf2f2; border: 2px solid #ff6b6b; padding: 20px; border-radius: var(--radius-md); text-align: center; margin-top: 30px; grid-column: 1 / -1; }
.btn-source { display: inline-block; background: var(--primary); color: #fff; padding: 12px 24px; border-radius: var(--radius-sm); font-weight: 700; margin-top: 15px; }
.btn-source:hover { background: var(--primary-dark); }

/* ==========================================================================
   6. FDA NUTRITION FACTS LABEL
   ========================================================================== */
.nutrition-label { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; border: 2px solid #000; padding: 6px; width: 100%; background: #fff; color: #000; box-sizing: border-box; }
.nutrition-label h1 { margin: 0; font-size: 2.2rem; font-weight: 900; letter-spacing: -0.5px; border-bottom: 8px solid #000; line-height: 1; padding-bottom: 4px; }
.nutrition-calories { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 4px solid #000; padding: 4px 0; }
.nutrition-calories .cal-title { font-size: 1.2rem; font-weight: 900; margin: 0; line-height: 1; }
.nutrition-calories .cal-amount { font-size: 2.4rem; font-weight: 900; line-height: 0.9; }
.nutrition-row { display: flex; justify-content: space-between; border-bottom: 1px solid #000; padding: 4px 0; font-size: 0.9rem; }
.nutrition-row.thick { border-bottom: 4px solid #000; }
.nutrition-row.indent { padding-left: 16px; }
.nutrition-row b { font-weight: 900; }

/* ==========================================================================
   7. UX UPGRADES
   ========================================================================== */
.skeleton { background: #e2e8f0; border-radius: 4px; animation: pulse 1.5s infinite ease-in-out; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }
.skel-thumb { width: 110px; height: 110px; border-radius: 12px; }
.skel-cite { width: 120px; height: 14px; margin-bottom: 8px; border-radius: 20px; }
.skel-title { width: 60%; height: 22px; margin-bottom: 12px; }
.skel-desc { width: 100%; height: 14px; margin-bottom: 6px; }
.skel-desc.short { width: 80%; }
mark { background-color: rgba(255, 107, 107, 0.15); color: #1e293b; font-weight: bold; border-radius: 2px; padding: 0 2px; }
.serp-diet-badge { font-weight: 800; color: #166534; background: #dcfce7; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; text-transform: uppercase; border: 1px solid #bbf7d0; display: inline-block; }

/* ==========================================================================
   8. CLEAN AD SYSTEM (First-Party Style)
   ========================================================================== */
.ad-placeholder, .sponsored-ad-sidebar {
    background: #ffffff;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    text-align: center;
}

.ad-placeholder:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    background: #fdfdfd;
}

.ad-label { font-size: 0.65rem; position: absolute; top: 10px; right: 10px; color: var(--text-muted); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }

/* The sidebars use fixed positioning relative to the centered column */
.ad-floating { 
    display: none; 
    position: fixed; 
    top: 100px; 
    width: 160px; 
    height: 600px; 
    z-index: 50; 
}

@media (min-width: 1250px) {
    .ad-floating { display: flex; }
    
    /* Offset ads exactly 420px from the absolute center (Center + half-list-width + gap) */
    .ad-floating-left { 
        right: calc(50% + 420px); 
    }
    .ad-floating-right { 
        left: calc(50% + 420px); 
    }
}

/* Fix for the vertical text - Reset to normal horizontal readable text */
.ad-floating span, .ad-floating div {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    display: block;
    width: 100%;
}

.ad-headline-sidebar {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 20px 0;
    line-height: 1.2;
}

.ad-leaderboard { height: 100px; max-width: 800px; margin: 10px auto 30px; width: 100%; position: relative; }
.ad-infeed { height: 250px; max-width: 800px; margin: 10px auto 30px; width: 100%; position: relative; }
.ad-cta { display: block; font-size: 0.8rem; margin-top: auto; color: var(--primary); font-weight: 700; text-transform: none; }

/* ==========================================================================
   9. SPONSORED FOOTER GRID
   ========================================================================== */
.sponsored-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 800px;
    margin: 0 auto 40px;
}

.sponsored-grid-item {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    text-decoration: none;
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.sponsored-grid-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: #fdfdfd;
}

.grid-ad-badge { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; font-weight: 800; margin-bottom: 10px; letter-spacing: 0.5px; }
.grid-ad-title { font-size: 1.1rem; font-weight: 800; color: var(--text-main); margin: 0 0 8px; line-height: 1.3; }
.grid-ad-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 15px; line-height: 1.5; }
.grid-ad-cta { margin-top: auto; font-size: 0.8rem; font-weight: 700; color: var(--primary); }


@media (max-width: 768px) {
    .sponsored-grid { grid-template-columns: 1fr; gap: 15px; }
    .ad-leaderboard { height: 60px; } 
}