:root {
    --primary: #6366f1;
    --dark: #0f172a;
    --toolbar-height: 70px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--dark);
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100dvh; /* Dynamic height fixes mobile address bar issues */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* DESKTOP SIDEBAR */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; background: white; z-index: 50;
    padding: 20px; display: flex; flex-direction: column; gap: 15px;
    box-shadow: 2px 0 15px rgba(0,0,0,0.2);
}
.sidebar .logo { font-size: 1.5rem; font-weight: 800; color: var(--dark); margin-bottom: 20px; }
.sidebar h3 { margin: 0 0 10px 0; color: #64748b; font-size: 0.8rem; text-transform: uppercase; }

.btn-upload {
    padding: 14px; border-radius: 8px; text-align: center;
    cursor: pointer; font-weight: 600; font-size: 0.95rem;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: 0.2s;
}
.btn-upload.primary { background: var(--primary); color: white; }
.btn-upload.secondary { background: #e0e7ff; color: var(--primary); }
.btn-upload:hover { transform: translateY(-2px); }

.desktop-controls { margin-top: auto; border-top: 1px solid #eee; padding-top: 20px; }
.desktop-controls label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; color: #475569; }
.desktop-controls input { width: 100%; margin-bottom: 15px; cursor: pointer; }

/* CANVAS AREA */
.canvas-wrapper {
    flex: 1;
    margin-left: 280px; /* Offset for sidebar */
    background: #1e293b;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

canvas {
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    max-width: 90%;
    max-height: 90%;
    /* No border radius on canvas to keep edges sharp */
}

/* EMPTY STATE (The Screen you see first) */
.empty-state {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: #0f172a;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 40; /* Above canvas, below controls */
    color: white;
}
.empty-state.hidden { display: none; } /* Crucial: Hides it completely */

.upload-circle {
    width: 90px; height: 90px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.5rem; margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
    animation: pulse 2s infinite;
}
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* The giant invisible input */
.fullscreen-input {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; cursor: pointer; z-index: 50;
}

/* MOBILE TOOLBAR */
.mobile-toolbar {
    display: none; /* Hidden on desktop */
}

/* SETTINGS DRAWER */
.settings-drawer {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 20px; padding-bottom: 90px; /* Space for toolbar */
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 90;
}
.settings-drawer.active { transform: translateY(0); }
.settings-drawer h4 { margin: 0 0 15px 0; color: #1e293b; }

.control-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.control-row span { font-weight: 600; color: #64748b; font-size: 0.9rem; }
.control-row input { width: 65%; accent-color: var(--primary); }

.btn-delete {
    width: 100%; padding: 12px; border: none; border-radius: 8px;
    background: #fee2e2; color: #dc2626; font-weight: 700;
}

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .canvas-wrapper { margin-left: 0; height: calc(100dvh - var(--toolbar-height)); }
    
    .mobile-toolbar {
        position: fixed; bottom: 0; left: 0; width: 100%;
        height: var(--toolbar-height);
        background: white;
        border-top: 1px solid #e2e8f0;
        display: flex; justify-content: space-around; align-items: center;
        z-index: 100;
        padding-bottom: env(safe-area-inset-bottom); /* Fix for iPhone bar */
    }

    .tool-btn {
        display: flex; flex-direction: column; align-items: center; gap: 4px;
        color: #64748b; font-size: 0.75rem; font-weight: 500;
        width: 25%; position: relative;
    }
    .tool-btn i { font-size: 1.2rem; margin-bottom: 2px; }
    .tool-btn.active { color: var(--primary); }
    
    /* Make the file inputs inside buttons cover the whole button area */
    .tool-btn input[type="file"] {
        position: absolute; top: 0; left: 0; width: 100%; height: 100%;
        opacity: 0; cursor: pointer;
    }
}
/* --- DASHBOARD STYLES (index.php) --- */
.dashboard-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px 20px;
    text-align: center;
}

.hero-section { margin-bottom: 50px; }
.logo-large { font-size: 3rem; font-weight: 900; color: white; margin-bottom: 10px; }
.hero-section p { color: #94a3b8; font-size: 1.1rem; }

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.tool-card {
    background: #1e293b;
    border-radius: 16px;
    padding: 30px;
    text-align: left;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #334155;
    position: relative;
    overflow: hidden;
}
.tool-card:hover { transform: translateY(-5px); box-shadow: 0 10px 30px rgba(0,0,0,0.3); border-color: var(--primary); }
.tool-card.disabled { opacity: 0.6; pointer-events: none; filter: grayscale(1); }

.icon-box {
    width: 50px; height: 50px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; margin-bottom: 20px;
}
.icon-box.purple { background: rgba(99, 102, 241, 0.2); color: #818cf8; }
.icon-box.green { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.icon-box.gray { background: rgba(148, 163, 184, 0.2); color: #94a3b8; }

.tool-card h3 { margin: 0 0 10px 0; color: white; font-size: 1.2rem; }
.tool-card p { margin: 0; color: #94a3b8; font-size: 0.9rem; line-height: 1.5; }

.badge {
    position: absolute; top: 15px; right: 15px;
    font-size: 0.7rem; font-weight: bold; padding: 4px 8px; border-radius: 20px;
    text-transform: uppercase;
}
.badge.popular { background: #4f46e5; color: white; }
.badge.new { background: #10b981; color: white; }
.badge.coming-soon { background: #334155; color: #94a3b8; }

/* --- COMPRESSOR SPECIFIC --- */
.back-link {
    color: #94a3b8; text-decoration: none; font-weight: 600;
    margin-bottom: 20px; display: inline-block; font-size: 0.9rem;
}
.back-link:hover { color: white; }

.stats-box {
    background: #f8fafc; border-radius: 8px; padding: 15px;
    margin: 20px 0; border: 1px solid #e2e8f0;
}
.stat-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.9rem; color: #64748b; }
.stat-row.highlight { color: #1e293b; font-weight: bold; }
.stat-row.savings { margin-top: 10px; border-top: 1px solid #e2e8f0; padding-top: 10px; font-weight: 900; font-size: 1.1rem; color: #10b981; }

.styled-select {
    width: 100%; padding: 10px; border-radius: 8px; border: 1px solid #cbd5e1;
    margin-bottom: 15px; background: white; cursor: pointer;
}

.compare-container {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    position: relative; padding: 20px; box-sizing: border-box;
}
.compare-container img {
    max-width: 100%; max-height: 100%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border-radius: 4px;
    transition: opacity 0.2s;
}

#loadingIndicator {
    position: absolute; color: white; font-size: 1.2rem;
    background: rgba(0,0,0,0.7); padding: 15px 30px; border-radius: 30px;
    z-index: 50;
}

.hidden { display: none !important; }

/* --- MERGE TOOL STYLES --- */

/* The Grid */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
    padding: 20px;
    width: 100%;
    max-width: 1200px;
    padding-bottom: 120px; /* Extra space for the button stack */
    align-content: start;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

/* The Card */
.pdf-card {
    background: white;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    position: relative;
    cursor: grab;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    border: 2px solid transparent; /* Prepare for green/red border */
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.pdf-card.uploading { opacity: 0.8; border-color: #cbd5e1; background: #f8fafc; }
.pdf-card.ready { border-color: #10b981 !important; background: #f0fdf4; }
.pdf-card.error { border-color: #ef4444 !important; background: #fef2f2; }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Thumbnail */
.pdf-thumb {
    width: 100%; height: 180px;
    background: #f1f5f9; border-radius: 8px;
    overflow: hidden; margin-bottom: 10px;
    position: relative;
}
.pdf-thumb canvas { width: 100%; height: 100%; object-fit: contain; }

/* Card Info */
.file-name { font-size: 0.85rem; font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.75rem; color: #94a3b8; margin-top: 2px; }

/* Status & Remove Icons */
.status-icon { position: absolute; bottom: 10px; right: 10px; font-size: 1.2rem; }
.spin { animation: spin 1s linear infinite; color: var(--primary); }
@keyframes spin { 100% { transform: rotate(360deg); } }

.btn-remove {
    position: absolute; top: -8px; right: -8px;
    width: 24px; height: 24px;
    background: #ef4444; color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 20;
}

/* --- FLOATING ACTION BUTTONS (The Fix) --- */

.fab-container {
    position: fixed; bottom: 30px; right: 30px;
    display: flex; flex-direction: column; /* Stack them vertically */
    align-items: end; gap: 15px;
    z-index: 100;
}
.fab-container.hidden { display: none; }

/* The Merge Button */
.fab-merge {
    /* CRITICAL FIX: position: static lets it stack inside the container */
    position: static; 
    background: var(--primary); color: white;
    border: none; border-radius: 50px;
    padding: 15px 30px;
    font-size: 1.1rem; font-weight: 700;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    transition: transform 0.2s;
}
.fab-merge:active { transform: scale(0.95); }

/* The Add Button */
.fab-mini {
    width: 50px; height: 50px;
    border-radius: 50%; border: none;
    background: white; color: var(--primary);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
}
.fab-mini:active { transform: scale(0.9); }

/* --- MOBILE SPECIFIC FIXES (Replace the bottom section) --- */
@media (max-width: 768px) {
    /* 1. Reset Grid Layout */
    .file-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* 2. Horizontal Card Layout */
    .pdf-card {
        flex-direction: row;
        height: 80px;
        align-items: center;
        padding: 10px;
        width: 100%;
        padding-right: 80px; /* INCREASED: Space for TWO icons now */
        box-sizing: border-box;
    }

    /* 3. Smaller Thumbnail */
    .pdf-thumb {
        width: 60px; height: 60px;
        margin-bottom: 0; margin-right: 15px;
        flex-shrink: 0;
    }

    /* 4. Text Truncation */
    .file-info {
        flex: 1; 
        width: 0; 
        min-width: 0; 
        margin-right: 5px;
    }
    
    .file-name {
        width: 100%;
        display: block;
    }

    /* 5. Pin X Button (Far Right) */
    .btn-remove {
        position: absolute;
        top: 50%; 
        right: 15px; /* Pinned to edge */
        transform: translateY(-50%);
        z-index: 20;
    }

    /* 6. Pin Status/Checkmark Icon (To the LEFT of the X button) */
    .status-icon {
        position: absolute;
        top: 50%;
        bottom: auto; /* Remove the "bottom" rule from desktop */
        right: 50px;  /* 50px from right (Next to the X) */
        transform: translateY(-50%);
    }

    /* 7. Center Buttons on Mobile */
    .fab-container {
        bottom: 20px; right: 50%; transform: translateX(50%);
        align-items: center; width: 100%;
        pointer-events: none;
    }
    .fab-merge { width: 90%; justify-content: center; pointer-events: auto; }
    .fab-mini { pointer-events: auto; background: var(--dark); color: white; }
}