/* --- CSS Variables --- */
:root {
    --bg: #faf9f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e5e3df;
    --border-hover: #d4d1cb;
    --fg: #1a1817;
    --muted: #6b6560;
    --accent: #e34c26; /* PDF Red/Orange */
    --accent-light: #fbe8e3;
    --accent-glow: rgba(227, 76, 38, 0.15);
    --secondary: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --input-bg: #ffffff;
    --pattern-opacity: 0.3;
    --sidebar-width: 280px;
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --card: #16161f;
    --border: #2a2a3a;
    --border-hover: #3a3a4a;
    --fg: #e8e8ed;
    --muted: #6b6b7a;
    --accent: #ff6b4a;
    --accent-light: #ff6b4a20;
    --accent-glow: rgba(255, 107, 74, 0.2);
    --secondary: #3b82f6;
    --success: #34d399;
    --danger: #f87171;
    --input-bg: #0f0f14;
    --pattern-opacity: 0.05;
}

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

body {
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* --- Background --- */
.bg-decoration { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-pattern { position: absolute; inset: 0; background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px); background-size: 24px 24px; opacity: var(--pattern-opacity); }
.gradient-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.4; animation: float 20s ease-in-out infinite; }
.orb-1 { width: 500px; height: 500px; background: linear-gradient(135deg, #ff7e5f, #feb47b); top: -150px; right: -100px; }
.orb-2 { width: 400px; height: 400px; background: linear-gradient(135deg, #6a11cb, #2575fc); bottom: -100px; left: -100px; animation-delay: -5s; }
[data-theme="dark"] .orb-1 { background: var(--accent); opacity: 0.15; }
[data-theme="dark"] .orb-2 { background: var(--secondary); opacity: 0.15; }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(30px, 20px) scale(1.05); } }

/* --- App Layout --- */
.app-layout { display: flex; min-height: 100vh; }

/* --- Mobile Header --- */
.mobile-header {
    display: none; /* Hidden on desktop */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    z-index: 50;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}
.mobile-logo { font-weight: 700; font-size: 1.2rem; }
.mobile-logo span { color: var(--accent); }

/* Updated Menu Toggle Button with Text */
.menu-toggle {
    display: flex;
    align-items: center;
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.menu-toggle:hover {
    background: var(--accent);
    color: white;
}

.menu-toggle svg { 
    width: 16px; 
    height: 16px; 
    stroke: currentColor; 
    fill: none; 
    stroke-width: 2; 
    margin-left: 5px;
    transition: transform 0.2s;
}

/* Rotate arrow when sidebar is open */
.sidebar.open ~ .main-content .menu-toggle svg {
    /* Note: This selector won't work because of DOM structure. 
       We handle this via JS or simpler structure, but for CSS only, 
       it's better to just rely on hover or static state. */
}

/* --- Sidebar Backdrop --- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 15;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 20;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.close-sidebar { display: none; background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px; }
.close-sidebar svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }

.logo { font-size: 1.5rem; font-weight: 700; color: var(--fg); }
.logo span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
    position: relative;
    overflow: hidden;
}
.nav-item svg { width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; margin-bottom: 0.5rem; transition: stroke 0.2s; }
.nav-item span { font-weight: 600; color: var(--fg); font-size: 0.95rem; }
.nav-item small { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-light); }
.nav-item.active svg { stroke: var(--accent); }
.nav-item.active span { color: var(--accent); }
.nav-item.active::before { content: ''; position: absolute; left: 0; top: 15%; bottom: 15%; width: 4px; background: var(--accent); border-radius: 0 4px 4px 0; }

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.desktop-header { margin-bottom: 2rem; }
.desktop-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; }
.desktop-header p { color: var(--muted); }

/* --- Content Area --- */
.content-area {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0,0,0,0.02);
}
.tab-content { display: none; flex: 1; flex-direction: column; }
.tab-content.active { display: flex; }

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 3rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); background: var(--accent-light); }
.upload-icon { width: 48px; height: 48px; margin-bottom: 1rem; color: var(--muted); }
.upload-icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.5; }
.upload-zone h3 { font-size: 1.1rem; margin-bottom: 0.25rem; }
.upload-zone p { color: var(--muted); font-size: 0.9rem; }

/* --- File List --- */
.file-list { margin-bottom: 1rem; max-height: 200px; overflow-y: auto; display: grid; gap: 8px; }
.file-item { background: var(--bg); padding: 10px 14px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; }
.file-item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%; }
.file-item .size { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 0.8rem; }
.remove-btn { background: none; border: none; color: var(--danger); cursor: pointer; padding: 4px; display: flex; }
.remove-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; }

/* --- Options & Buttons --- */
.options-group { background: var(--bg); padding: 1.5rem; border-radius: 12px; margin-top: 1rem; }
.options-group label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.9rem; }
.input-field { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; background: var(--card); color: var(--fg); margin-bottom: 1rem; }

.btn-action {
    width: 100%; padding: 14px; background: var(--accent); color: white; border: none; border-radius: 12px;
    font-weight: 600; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
    gap: 8px; transition: all 0.2s; margin-top: auto;
}
.btn-action svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-action:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); filter: brightness(1.05); }

/* --- Stats --- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: var(--bg); border-radius: 12px; padding: 12px; text-align: center; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 1.25rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-top: 4px; }
.stat-value.accent { color: var(--accent); }
.stat-value.secondary { color: var(--secondary); }

/* --- Theme Toggle --- */
.theme-toggle {
    position: fixed; top: 1.5rem; right: 1.5rem; z-index: 100; width: 48px; height: 48px;
    border-radius: 50%; background: var(--card); border: 2px solid var(--border); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.theme-toggle:hover { transform: rotate(15deg) scale(1.1); border-color: var(--accent); background: var(--accent-light); }
.theme-toggle svg { width: 24px; height: 24px; stroke: var(--fg); fill: none; stroke-width: 2; }

/* --- Toast --- */
.toast {
    position: fixed; bottom: 2rem; right: 2rem; background: var(--card);
    border: 1px solid var(--accent); padding: 1rem 1.5rem; border-radius: 12px;
    display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    transform: translateY(100px); opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 1000;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; stroke-width: 2.5; }

/* Utility */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.6s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* --- RESPONSIVE STYLES --- */

@media (max-width: 900px) {
    :root { --sidebar-width: 0px; }
    
    /* Show Mobile Header */
    .mobile-header { display: flex; }
    
    /* Sidebar becomes an overlay */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 5px 0 20px rgba(0,0,0,0.1);
        z-index: 60;
    }
    .sidebar.open { transform: translateX(0); }
    
    /* Show close button inside sidebar */
    .close-sidebar { display: block; }
    
    /* Main Content takes full width */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 70px; /* Space for mobile header */
    }

    /* Hide Desktop Header */
    .desktop-header { display: none; }
    
    /* Adjust Content Area */
    .content-area {
        padding: 1.25rem;
        border-radius: 16px;
    }

    /* Theme toggle reposition */
    .theme-toggle {
        top: 0.75rem;
        right: 0.75rem;
        width: 40px;
        height: 40px;
    }
    
    /* Stats grid full width */
    .stat-row { grid-template-columns: 1fr; gap: 8px; }
    .stat-box { display: flex; justify-content: space-between; align-items: center; text-align: left; }
    .stat-value { margin-top: 0; font-size: 1rem; }

    /* Upload zone smaller */
    .upload-zone { padding: 2rem 1rem; }
}

@media (max-width: 480px) {
    .nav-item { padding: 0.8rem; }
    .nav-item small { display: none; }
    .btn-action { padding: 12px; font-size: 0.9rem; }
}