:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}

/* Navbar */
.navbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 2rem; background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.nav-brand a { font-size: 1.5rem; font-weight: bold; color: var(--primary); text-decoration: none; }
.nav-links a { margin-left: 1.5rem; text-decoration: none; color: var(--text); font-weight: 500; }
.nav-links a:hover { color: var(--primary); }

/* Layout */
.container { max-width: 1000px; margin: 0 auto; padding: 3rem 1rem; text-align: center; }

/* Hero & Grid */
.hero { margin-bottom: 3rem; }
.hero h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.hero p { color: var(--text-light); font-size: 1.1rem; }

.card-grid {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); 
    gap: 1.5rem; margin-top: 2rem;
}

.tool-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 2rem; text-decoration: none; color: var(--text); display: block;
    transition: transform 0.2s, box-shadow 0.2s;
}
.tool-card:hover { 
    transform: translateY(-4px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); 
    border-color: var(--primary); 
}
.card-icon { font-size: 3rem; margin-bottom: 1rem; display: block; }
.tool-card h3 { margin-bottom: 0.5rem; color: var(--primary); }

/* Tool Zone */
.tool-layout {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 3rem; max-width: 600px; margin: 0 auto;
}
.upload-zone { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; margin-top: 1.5rem; }
.file-input { border: 2px dashed var(--border); padding: 2rem; border-radius: 8px; width: 100%; cursor: pointer;}

/* Buttons */
.btn-primary {
    background: var(--primary); color: white; border: none; padding: 0.875rem 2rem;
    border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: 0.2s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Loader */
.loader-spinner {
    border: 4px solid var(--border); border-top: 4px solid var(--primary);
    border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 1rem auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Split Screen Results Mode */
.tool-layout { transition: max-width 0.3s ease; }
.tool-layout.result-mode { max-width: 900px; padding: 2rem; }

.output-split {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
}

.action-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.subtitle { color: var(--text-light); margin-bottom: 1rem; }

.preview-panel {
    width: 100%;
    height: 500px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden; box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.05);
}

.pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Desktop Side-by-Side */
@media (min-width: 768px) {
    .output-split { flex-direction: row; }
    .action-panel { 
        flex: 1; 
        border-right: 1px solid var(--border); padding-right: 2rem; 
    }
    .preview-panel { flex: 1.5; height: 600px; }
}

/* ====== PREMIUM CTAs ====== */

.btn-download-premium {
    display: inline-flex;
    align-items: center;
    justify-content: center; background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 1.2rem 2.5rem;
    border-radius: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px; text-decoration: none;
    font-size: 1.2rem;
    margin: 1.5rem 0;
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.4), 0 4px 6px -2px rgba(16, 185, 129, 0.2); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
}

.btn-download-premium:hover {
    transform: translateY(-3px) scale(1.02); box-shadow: 0 20px 25px -5px rgba(16, 185, 129, 0.5), 0 10px 10px -5px rgba(16, 185, 129, 0.3); }

.btn-download-premium:active {
    transform: translateY(1px) scale(0.98);
}

.btn-icon {
    font-size: 1.4rem;
    margin-right: 0.75rem; }

/* Premium Secondary CTAs */
.cross-sell-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem; }

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--text);
    padding: 0.875rem 1.5rem; border: 2px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02); }

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.1); }

/* Canvas PDF Preview Styling */
.preview-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #cbd5e1; /* Darker background to make the white page pop */
    overflow: auto;
    padding: 1rem;
    min-height: 400px; }

.pdf-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background: white; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.preview-placeholder {
    color: var(--text-light);
    font-weight: 500; }

/* Persistent Canvas Styling */
.preview-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #cbd5e1;
    overflow: hidden; padding: 1rem;
    min-height: 450px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.05); }

.pdf-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background: white; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.preview-placeholder {
    color: var(--text-light);
    font-weight: 500; font-size: 1.1rem;
}

/* ====== 3-PHASE UI STYLES ====== */

/* Massive Clickable Upload Zone */
.upload-zone.interactive {
    border: 3px dashed var(--primary); background: rgba(37, 99, 235, 0.03);
    padding: 4rem 2rem;
    cursor: pointer;
    transition: all 0.2s ease; }
.upload-zone.interactive:hover {
    background: rgba(37, 99, 235, 0.08);
    transform: scale(1.02);
    border-color: var(--primary-hover); }
.upload-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* Staging Area File List */
.file-list {
    display: flex; flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    margin: 1.5rem 0;
    max-height: 250px;
    overflow-y: auto;
    text-align: left;
    padding-right: 0.5rem; }
.file-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 0.875rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    color: var(--text); white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02); }

/* Staging Area Action Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: center;
    margin-top: 1rem; }

.error-text {
    color: #ef4444;
    font-weight: 600;
    margin-top: 1rem; }

/* ====== 3-PHASE GALLERY STYLES ====== */

.upload-zone.interactive {
    border: 3px dashed var(--primary);
    background: rgba(37, 99, 235, 0.03); padding: 6rem 2rem;
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.2s ease; }
.upload-zone.interactive:hover {
    background: rgba(37, 99, 235, 0.08);
    transform: scale(1.02); }

/* Staging Area */
.staging-area {
    width: 100%;
}
.staging-header {
    display: flex;
    justify-content: space-between; align-items: center;
    margin-bottom: 2rem;
    padding: 0 1rem;
}

/* The Horizontal Gallery */
.thumbnail-gallery {
    display: flex;
    align-items: center; gap: 1rem;
    overflow-x: auto;
    padding: 2rem 1rem;
    background: #f1f5f9;
    border-radius: 12px;
    border: 1px solid var(--border);
    min-height: 250px; }

.gallery-item-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pdf-card {
    flex-shrink: 0;
    width: 160px; height: 220px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    display: flex; flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s;
}
.pdf-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }

.canvas-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8fafc; border-bottom: 1px solid var(--border);
}

.thumb-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; }

.file-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    padding: 0.75rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}

.plus-divider {
    font-size: 2rem;
    color: #94a3b8;
    font-weight: 800; }

.add-more-card {
    border: 2px dashed #cbd5e1;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    justify-content: center;
    align-items: center; color: var(--primary);
}
.add-more-card:hover {
    background: rgba(37, 99, 235, 0.05);
    border-color: var(--primary); }
    
.add-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}
.add-text {
    font-weight: 600; }

/* Page Count in Thumbnails */
.page-count {
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
    padding-bottom: 0.5rem;
    font-weight: 500; }

/* Scrollable Full PDF Viewer */
.full-view-panel {
    padding: 0; /* Let the scrollbar sit flush against the edge */
    background: #cbd5e1; }

.scrollable-pdf-container {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem; padding: 1rem;
}

.full-pdf-page {
    max-width: 100%;
    height: auto;
    background: white; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    flex-shrink: 0;
    border: 1px solid var(--border); }

/* === UI FIXES: Thumbnails & Scrollable Viewer === */
.pdf-card {
    height: 250px !important; /* Give the card more vertical space */
}
.canvas-container {
    height: 160px !important; /* Lock the image height */
    flex: none !important; /* Stop the image from pushing the text out */
    padding: 0.5rem; }
.thumb-canvas {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.file-name {
    padding: 0.75rem 0.5rem 0.2rem 0.5rem !important;
    font-weight: 600 !important; }
.page-count {
    padding-bottom: 0.75rem !important;
    display: block !important; /* Ensure visibility */
}

/* Force the Scrollbar on the Final Output Panel */
.preview-panel.full-view-panel {
    max-height: 70vh !important; /* Restrict height to 70% of the user's screen */
    overflow: hidden !important; }
.scrollable-pdf-container {
    height: 100% !important;
    max-height: 70vh !important;
    overflow-y: auto !important; /* Force the vertical scrollbar */
    padding: 2rem !important;
    background: #cbd5e1; }
.full-pdf-page {
    margin-bottom: 1.5rem !important; /* Add space between pages */
}

/* === Text Wrapping Override === */
.file-name {
    white-space: normal !important; /* Allow wrapping */
    word-wrap: break-word !important; /* Break long words if necessary */
    line-height: 1.2 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important; /* Limit to exactly 2 lines */
    -webkit-box-orient: vertical !important;
    overflow: hidden !important; padding: 0.5rem 0.5rem 0.2rem 0.5rem !important;
    font-size: 0.75rem !important;
    text-align: center !important; }

/* === UI FIXES 2: Taller Thumbnails & Tighter Text === */
.pdf-card { height: 250px !important; }
.canvas-container {
    height: 180px !important; /* Increased image height! */
    flex: none !important; padding: 0.5rem;
    background: #f8fafc;
}
.file-name {
    white-space: normal !important;
    word-wrap: break-word !important;
    line-height: 1.1 !important; display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    padding: 0.4rem 0.5rem 0.1rem 0.5rem !important; /* Tighter padding */
    font-size: 0.75rem !important;
    text-align: center !important; }
.page-count {
    padding-bottom: 0.4rem !important; /* Tighter padding */
    font-size: 0.7rem !important; display: block !important;
}

/* === GLOBAL AD LAYOUT === */
.page-layout {
    display: flex;
    flex-direction: column;
    max-width: 1200px; margin: 0 auto;
    padding: 2rem 1rem;
    gap: 2rem;
}
@media (min-width: 900px) {
    .page-layout {
        flex-direction: row; align-items: flex-start;
    }
}

.main-content {
    flex: 1;
    min-width: 0; /* Prevents large elements from blowing out the flex grid */
    text-align: center; }

/* Vertical AdSense Sidebar */
.ad-sidebar-right {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center; }
@media (min-width: 900px) {
    .ad-sidebar-right {
        width: 300px;
        flex-shrink: 0; position: sticky; /* Keeps the ad visible as they scroll down */
        top: 2rem; }
}
.ad-slot-vertical {
    width: 300px;
    height: 600px;
    background: #e2e8f0;
    border: 2px dashed #94a3b8;
    display: flex;
    align-items: center; justify-content: center;
    color: #64748b;
    font-weight: bold;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05); }

/* Horizontal AdSense Banner */
.ad-slot-bottom-container {
    max-width: 1200px;
    margin: 0 auto 3rem auto;
    padding: 0 1rem; display: flex;
    justify-content: center;
}
.ad-slot-horizontal {
    width: 100%;
    max-width: 728px;
    height: 90px;
    background: #e2e8f0; border: 2px dashed #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-weight: bold;
    border-radius: 8px; }

/* === OVERRIDE: Shrink the Tool Layout Width === */
.tool-layout {
    max-width: 480px !important; /* Shrunk from 600px to make it compact */
    margin: 0 auto; }
.tool-layout.result-mode {
    max-width: 100% !important; /* Allow the gallery & split screen to use all available space */
}

/* === PREMIUM APP STRUCTURE & NAV === */
.app-wrapper {
    display: flex; flex-direction: column;
    min-height: 100vh;
}
.app-main { flex: 1; }
.tool-page-container {
    max-width: 1200px; margin: 0 auto;
    padding-top: 2rem;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 800; color: var(--text);
    text-decoration: none;
}
.logo-icon { font-size: 1.8rem; }
.logo-text-blue { color: var(--primary); }

.nav-btn {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary) !important;
    padding: 0.5rem 1rem;
    border-radius: 6px; font-weight: 700 !important;
}
.nav-btn:hover { background: rgba(37, 99, 235, 0.2); }

/* === MARKETING HOME PAGE === */
.home-page { width: 100%; }
.hero-section {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    padding: 6rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border); }
.hero-title {
    font-size: 3.5rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 1rem;
    letter-spacing: -0.02em; }
.hero-subtitle {
    font-size: 1.25rem;
    color: #475569;
    max-width: 600px;
    margin: 0 auto 2.5rem auto; }

.tools-section {
    max-width: 1200px;
    margin: -3rem auto 4rem auto;
    padding: 0 1rem; }
.tools-section .tool-card {
    background: white;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05); }

.features-section {
    max-width: 1000px;
    margin: 4rem auto;
    padding: 0 1rem;
    text-align: center; }
.features-section h2 {
    font-size: 2.2rem;
    margin-bottom: 3rem;
}
.features-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}
.feature-item {
    padding: 2rem;
    background: white;
    border-radius: 12px; border: 1px solid var(--border);
}
.feature-icon {
    font-size: 3rem;
    margin-bottom: 1rem; }

/* === DARK MODE FOOTER === */
.site-footer {
    background: #0f172a;
    color: #94a3b8;
    padding: 4rem 2rem 1.5rem 2rem; margin-top: 4rem;
}
.footer-grid {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 3rem; margin-bottom: 3rem;
}
@media (max-width: 768px) {
    .footer-grid { grid-template-columns: 1fr; }
}
.footer-col h4 {
    color: white;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}
.footer-col a {
    display: block; color: #94a3b8;
    text-decoration: none;
    margin-bottom: 0.75rem;
    transition: color 0.2s;
}
.footer-col a:hover { color: white; }
.footer-bottom {
    max-width: 1200px;
    margin: 0 auto;
    border-top: 1px solid #1e293b;
    padding-top: 1.5rem;
    text-align: center;
    font-size: 0.9rem; }

/* === COMPILATION FIXES === */
.hero-btn { margin: 0 !important; }

/* === SCROLLBAR UI === */
.scrollable-pdf-container {
    padding: 1rem 0.5rem !important; /* Make room for the scrollbar */
    box-shadow: inset 0px 10px 15px -10px rgba(0,0,0,0.1), inset 0px -10px 15px -10px rgba(0,0,0,0.1); }

.scrollable-pdf-container::-webkit-scrollbar { width: 14px; }
.scrollable-pdf-container::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 8px; }
.scrollable-pdf-container::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 8px;
    border: 3px solid #e2e8f0;
}
.scrollable-pdf-container::-webkit-scrollbar-thumb:hover { background-color: var(--primary-hover); }

/* === MOBILE OPTIMIZATIONS === */
@media (max-width: 899px) {
    .page-layout { padding: 1rem 0.5rem; }
    .output-split { flex-direction: column !important; }
    .action-panel {
        border-right: none !important; padding-right: 0 !important;
        border-bottom: 1px solid var(--border);
        padding-bottom: 2rem;
        margin-bottom: 1rem; }
    .preview-panel { height: 400px !important; }
    .ad-slot-vertical { width: 100% !important; max-width: 336px; height: 280px !important; margin: 0 auto; }
    .ad-slot-horizontal { height: 50px !important; }
    .hero-title { font-size: 2.2rem; }
}

@keyframes pulse-bg { 0% { background-color: #f1f5f9; } 50% { background-color: #e2e8f0; } 100% { background-color: #f1f5f9; } }
.loading-canvas { animation: pulse-bg 1.5s infinite ease-in-out; }

/* ====================================================
   📱 COMPREHENSIVE MOBILE RESPONSIVENESS (Max 768px)
   ==================================================== */
@media (max-width: 768px) {
    .navbar { flex-direction: column; gap: 1rem; padding: 1rem; text-align: center; }
    .nav-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; margin-left: 0 !important; }
    .nav-links a { margin: 0 !important; font-size: 0.9rem; }
    .nav-btn { width: 100%; margin-top: 0.5rem; }
    .hero-section { padding: 3rem 1rem !important; }
    .hero-title { font-size: 2.2rem !important; line-height: 1.2; }
    .hero-subtitle { font-size: 1rem !important; margin-bottom: 1.5rem !important; }
    .tools-section { margin-top: -1.5rem !important; }
    .card-grid { grid-template-columns: 1fr !important; }
    .upload-zone.interactive { padding: 3rem 1rem !important; }
    .upload-icon { font-size: 3rem !important; }
    .output-split { flex-direction: column !important; }
    .action-panel { padding-right: 0 !important; border-right: none !important; border-bottom: 1px solid var(--border); padding-bottom: 2rem !important; margin-bottom: 1rem; }
    .preview-panel.full-view-panel { height: 50vh !important; }
    .ad-slot-vertical { width: 100% !important; max-width: 300px !important; height: 250px !important; margin: 0 auto; font-size: 0.9rem; }
    .ad-slot-horizontal { width: 100% !important; max-width: 320px !important; height: 50px !important; margin: 0 auto; font-size: 0.8rem; }
    .ad-slot-bottom-container { margin-bottom: 1.5rem !important; }
    .site-footer { padding: 2rem 1rem 1rem 1rem !important; margin-top: 2rem !important; }
    .footer-grid { gap: 2rem !important; text-align: center; }
    .footer-col h4 { margin-bottom: 1rem !important; }
}

/* === 📱 MOBILE AD REORDERING FIX === */
.tool-page-container { display: flex; flex-direction: column; }
@media (max-width: 768px) {
    .ad-slot-bottom-container { order: -1 !important; margin-top: -1rem !important; margin-bottom: 0.5rem !important; }
    .ad-sidebar-right { margin-top: 1rem !important; padding-bottom: 2rem !important; }
    .action-panel { border-bottom: none !important; padding-bottom: 1rem !important; }
}

/* ====================================================
   📱 FINAL RESPONSIVE UX (Mobile, Tab Wide, Desktop)
   ==================================================== */
@media (min-width: 768px) {
    .page-layout { flex-direction: row !important; align-items: flex-start !important; }
    .ad-sidebar-right { width: 300px !important; position: sticky !important; top: 2rem; flex-shrink: 0; display: flex !important; }
    .output-split { flex-direction: row !important; }
    .action-panel { border-right: 1px solid var(--border) !important; border-bottom: none !important; padding-right: 2rem !important; padding-bottom: 0 !important; }
}
@media (max-width: 767px) {
    .tool-page-container { display: flex; flex-direction: column; }
    .ad-slot-bottom-container { order: -1 !important; margin-top: 0 !important; margin-bottom: 0.5rem !important; }
    .page-layout { order: 2 !important; display: flex; flex-direction: column; padding: 0.5rem !important; gap: 1rem !important; }
    .ad-sidebar-right { order: 3 !important; margin-top: 1.5rem !important; padding-bottom: 2rem !important; }
    .ad-slot-vertical { width: 100% !important; max-width: 300px !important; height: 250px !important; margin: 0 auto; }
    .ad-slot-horizontal { width: 100% !important; max-width: 320px !important; height: 50px !important; margin: 0 auto; }
    .staging-header { flex-direction: column !important; gap: 1rem !important; align-items: stretch !important; }
    .staging-header h2 { text-align: center; font-size: 1.5rem; margin: 0; }
    .staging-header .btn-primary { width: 100% !important; padding: 1rem !important; font-size: 1.1rem; }
    .thumbnail-gallery { padding: 1rem !important; min-height: 180px !important; }
    .pdf-card { width: 110px !important; height: 170px !important; }
    .canvas-container { height: 100px !important; padding: 0.25rem !important; }
    .file-name { font-size: 0.65rem !important; padding: 0.25rem !important; }
    .page-count { font-size: 0.6rem !important; padding-bottom: 0.25rem !important; }
    .plus-divider { font-size: 1.5rem !important; }
    .add-more-card .add-icon { font-size: 1.8rem !important; margin-bottom: 0.2rem !important; }
    .add-more-card .add-text { font-size: 0.7rem !important; }
    .output-split { flex-direction: column !important; }
    .action-panel { border-right: none !important; border-bottom: 1px solid var(--border) !important; padding-right: 0 !important; padding-bottom: 1.5rem !important; margin-bottom: 1rem; }
    .preview-panel.full-view-panel { height: 55vh !important; }
}

@media (max-width: 767px) {
    .thumbnail-gallery { flex-direction: column !important; justify-content: flex-start !important; align-items: center !important; padding: 2rem 1rem !important; overflow-x: hidden !important; overflow-y: auto !important; max-height: 60vh !important; }
    .gallery-item-wrapper { flex-direction: column !important; width: 100% !important; }
    .plus-divider { margin: 0.5rem 0 !important; }
    .tool-page-container { display: flex !important; flex-direction: column !important; }
    .ad-slot-bottom-container { order: -1 !important; margin: 0 auto 1rem auto !important; width: 100% !important; }
    .page-layout { order: 2 !important; flex-direction: column !important; }
    .ad-sidebar-right { order: 3 !important; margin-top: 2rem !important; width: 100% !important; }
    .ad-slot-vertical { font-size: 0 !important; height: 250px !important; max-width: 300px !important; }
    .ad-slot-vertical::after { content: "Mobile Ad (300x250)"; font-size: 1rem; color: #64748b; }
    .ad-slot-horizontal { font-size: 0 !important; height: 50px !important; max-width: 320px !important; }
    .ad-slot-horizontal::after { content: "Mobile Ad (320x50)"; font-size: 1rem; color: #64748b; }
    .output-split { flex-direction: column !important; }
    .action-panel { border-right: none !important; border-bottom: 1px solid var(--border) !important; padding-right: 0 !important; padding-bottom: 2rem !important; }
    .preview-panel.full-view-panel { height: 55vh !important; width: 100% !important; }
    .btn-primary { width: 100% !important; }
}

@media (min-width: 768px) {
    .thumbnail-gallery { flex-direction: row !important; }
    .gallery-item-wrapper { flex-direction: row !important; }
    .output-split { flex-direction: row !important; }
    .action-panel { border-right: 1px solid var(--border) !important; border-bottom: none !important; padding-right: 2rem !important; padding-bottom: 0 !important; }
    .ad-slot-vertical { font-size: 0 !important; }
    .ad-slot-vertical::after { content: "Desktop Ad (300x600)"; font-size: 1rem; color: #64748b; }
    .ad-slot-horizontal { font-size: 0 !important; }
    .ad-slot-horizontal::after { content: "Desktop Ad (728x90)"; font-size: 1rem; color: #64748b; }
}

@media (max-width: 767px) {
    .thumbnail-gallery { flex-direction: row !important; flex-wrap: wrap !important; justify-content: center !important; align-items: center !important; padding: 1.5rem 0.5rem !important; overflow-x: hidden !important; overflow-y: auto !important; max-height: 60vh !important; gap: 0.5rem !important; }
    .gallery-item-wrapper { flex-direction: row !important; align-items: center !important; width: auto !important; margin: 0 !important; }
    .pdf-card { width: 120px !important; height: 180px !important; }
    .canvas-container { height: 110px !important; padding: 0.25rem !important; }
    .file-name { font-size: 0.7rem !important; padding: 0.25rem !important; }
    .page-count { font-size: 0.65rem !important; padding-bottom: 0.25rem !important; }
    .plus-divider { margin: 0 0.25rem !important; font-size: 1.5rem !important; display: block !important; }
    .add-more-card { width: 120px !important; height: 180px !important; }
    .add-more-card .add-icon { font-size: 1.8rem !important; margin-bottom: 0.2rem !important; }
    .add-more-card .add-text { font-size: 0.75rem !important; }
}
.mobile-only-ad { display: none !important; }
@media (max-width: 767px) { .mobile-only-ad { display: flex !important; } }

/* ====================================================
   🚀 FIX: OPTIMIZED AD SPACING (NEW & SAFE)
   ==================================================== */
.tool-page-container > div[style*="margin-top: 1rem"],
.tool-page-container > div[style*="margin-top"] {
    margin-top: 0.25rem !important;
    margin-bottom: 0.75rem !important;
}
.ad-slot-bottom-container {
    margin-top: 0.25rem !important;
    margin-bottom: 0.75rem !important;
}
.tool-page-container {
    padding-top: 0.5rem !important; /* Pulls the entire grid up globally */
}

/* ====================================================
   🚀 FIX: CORRECT MOBILE DOM ORDER & FULL PAGE PREVIEW
   ==================================================== */
@media (max-width: 767px) {
    /* Remove artificial ordering to let natural HTML flow take over */
    .ad-slot-bottom-container { order: unset !important; }
    .page-layout { order: unset !important; }
    .ad-sidebar-right { order: unset !important; }
    .seo-hero { order: unset !important; }
    .seo-content { order: unset !important; }
    
    /* Ensure preview is massive enough for a full page */
    .preview-panel.full-view-panel {
        height: 80vh !important;
        min-height: 650px !important;
    }
}

/* Cross-Tool Routing Buttons */
.cross-tool-btn {
    font-size: 0.85rem !important;
    padding: 0.4rem 0.75rem !important;
    border-radius: 6px !important;
    margin: 0 !important;
    text-decoration: none !important;
}
