/* ==========================================================================
   CSS Variables & Theming Structure
   ========================================================================== */
:root {
    /* Color Palette */
    --bg-dark: #0f111a;
    --bg-panel: #1a1d29;
    --bg-panel-hover: #222634;

    --primary-color: #6c5ce7;
    --primary-color-hover: #8073ea;
    --accent-color: #00d2d3;

    --text-main: #f5f6fa;
    --text-muted: #8395a7;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-focus: rgba(108, 92, 231, 0.5);

    --success-border: #1dd1a1;
    --success-bg: rgba(29, 209, 161, 0.1);

    --error-border: #ff6b6b;
    --error-bg: rgba(255, 107, 107, 0.1);

    /* Typography */
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Shadows & Effects */
    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glow-primary: 0 0 20px rgba(108, 92, 231, 0.4);

    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    /* Subtle background gradient */
    background-image:
        radial-gradient(circle at 15% 50%, rgba(108, 92, 231, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(0, 210, 211, 0.05) 0%, transparent 50%);

    /* Anti-FOUT: Hide body until fonts are ready */
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

body.fonts-loaded {
    opacity: 1;
}

.file-input-hidden {
    display: none;
}

/* ==========================================================================
   Layout Architecture
   ========================================================================== */
.app-container {
    display: flex;
    height: 100vh;
}

/* --- Sidebar Navigation --- */
.sidebar {
    width: 280px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    z-index: 1001;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform var(--transition-smooth);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.sidebar-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    color: var(--text-muted);
}

.sidebar-close-btn:hover {
    color: var(--error-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
    cursor: pointer;
}

.sidebar .brand {
    margin-top: 15px;
}

.brand i {
    font-size: 2rem;
    color: var(--primary-color);
    filter: drop-shadow(0 0 8px var(--primary-color));
}

.brand h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--text-main), var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-links li {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 18px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.nav-links li i {
    font-size: 1.4rem;
    transition: color var(--transition-fast);
}

.nav-links li:hover {
    background-color: var(--bg-panel-hover);
    color: var(--text-main);
}

.nav-links li.active {
    background-color: rgba(108, 92, 231, 0.15);
    color: var(--primary-color);
    border-right: 4px solid var(--primary-color);
}

.nav-links li.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(108, 92, 231, 0.05));
    pointer-events: none;
}

/* --- Main Content Area --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.app-header {
    height: 90px;
    padding: 0 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(15, 17, 26, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 5;
}

.app-header .brand {
    margin-bottom: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.menu-icon-btn {
    background: transparent;
    color: var(--text-main);
    font-size: 2rem;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast);
}

.menu-icon-btn:hover {
    color: var(--primary-color);
}

.header-titles h2 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-main);
}

.header-titles p {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.user-profile img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    transition: border-color var(--transition-fast);
}

.user-profile img:hover {
    border-color: var(--primary-color);
}

/* --- Workspace Area --- */
.workspace-area {
    flex: 1;
    padding: 3rem;
    overflow-y: auto;
    position: relative;
}

.tool-view {
    display: none;
    animation: fadeIn var(--transition-smooth) forwards;
    flex-direction: column;
    gap: 2rem;
    max-width: 900px;
    margin: 0 auto;
    height: 100%;
}

.tool-view.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Components
   ========================================================================== */
/* --- Upload Zone --- */
.upload-zone {
    background-color: var(--bg-panel);
    border: 2px dashed var(--border-color);
    border-radius: 20px;
    padding: 4rem 2rem;
    text-align: center;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    position: relative;
    overflow: hidden;
}

/* Glassmorphism subtle overlay on upload zone */
.upload-zone::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
    pointer-events: none;
}

.upload-zone:hover,
.upload-zone.drag-active {
    border-color: var(--primary-color);
    background-color: rgba(108, 92, 231, 0.03);
    box-shadow: var(--glow-primary);
}

.upload-icon {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    transition: transform var(--transition-fast);
}

.upload-zone:hover .upload-icon,
.upload-zone.drag-active .upload-icon {
    transform: translateY(-8px);
}

.upload-zone h3 {
    font-size: 1.4rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.upload-zone p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* --- Buttons --- */
button {
    font-family: var(--font-family);
    cursor: pointer;
    border: none;
    outline: none;
    transition: all var(--transition-fast);
}

.btn-primary {
    background-color: var(--border-color);
    color: var(--text-main);
    padding: 12px 28px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

.btn-primary:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.action-panel {
    display: flex;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    padding-bottom: 2rem;
    /* Added strict bottom padding */
}

.btn-execute {
    background: linear-gradient(135deg, var(--primary-color), #4834d4);
    color: white;
    padding: 16px 36px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
}

.btn-execute:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.6);
}

.btn-execute:active:not(:disabled) {
    transform: translateY(1px);
}

.btn-execute:disabled {
    background: var(--bg-panel-hover);
    color: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-execute i {
    font-size: 1.4rem;
}

/* --- File List Items (Merge View) --- */
.file-list-container {
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2rem;
    min-height: 300px;
}

.file-list-container::-webkit-scrollbar {
    width: 6px;
}

.file-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.file-list-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.file-item {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.file-item:hover {
    border-color: var(--border-color-focus);
}

.file-item.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.file-item.drag-over {
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.2);
    transform: scale(1.02);
}

.file-item-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.drag-handle:active {
    cursor: grabbing;
}

.file-item-icon {
    width: 40px;
    height: 40px;
    background-color: rgba(108, 92, 231, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-item-icon i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.file-meta h4 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 2px;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.file-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: transparent;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: var(--error-bg);
    color: var(--error-border);
}

.btn-icon i {
    font-size: 1.2rem;
}

/* --- Single File Preview (Split/Compress) --- */
.file-preview-container {
    display: none;
    /* Shown via JS when file selected */
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2rem;
    min-height: 300px;
    flex-direction: column;
    justify-content: center;
}

.file-preview-container.has-file {
    display: flex;
}

.single-file-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--primary-color);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-soft);
}

/* Info Box */
.compression-info {
    background-color: rgba(0, 210, 211, 0.1);
    border: 1px solid rgba(0, 210, 211, 0.2);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    color: #81ecec;
    font-size: 0.95rem;
}

.compression-info i {
    font-size: 1.5rem;
}

/* Split Options */
.split-options {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.page-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    font-weight: 500;
    font-size: 1.1rem;
}

.page-info i {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.range-inputs {
    display: flex;
    gap: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.input-group label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.input-group input {
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 16px;
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.input-group input:focus {
    border-color: var(--primary-color);
}

/* ==========================================================================
   Overlay & Notifications
   ========================================================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 17, 26, 0.9);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-right-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    font-size: 1.2rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    background: linear-gradient(90deg, var(--text-main), var(--primary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 999;
}

.toast {
    background-color: var(--bg-panel);
    color: var(--text-main);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 15px;
    transform: translateX(120%);
    transition: transform var(--transition-smooth);
    border-left: 4px solid var(--primary-color);
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left-color: var(--success-border);
}

.toast.error {
    border-left-color: var(--error-border);
}

.toast i {
    font-size: 1.5rem;
}

.toast-success i {
    color: var(--success-border);
}

.toast-error i {
    color: var(--error-border);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .app-header {
        padding: 0 1.5rem;
        height: 75px;
    }

    .workspace-area {
        padding: 1.5rem;
    }
}

/* --- Tool Content Header --- */
.tool-content-header {
    text-align: center;
    margin-bottom: 2.5rem;
    animation: fadeIn var(--transition-smooth) forwards;
}

.tool-content-header h2 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.tool-content-header p {
    font-size: 1.1rem;
    color: var(--text-muted);
}

/* --- Tools Dashboard Grid --- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    width: 100%;
}

@media (max-width: 1200px) {
    .tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .tools-grid {
        grid-template-columns: 1fr;
    }
}

.tool-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px 24px;
    text-decoration: none;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: all var(--transition-smooth);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.tool-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(108, 92, 231, 0.2);
    background-color: var(--bg-panel-hover);
}

.tool-card .tool-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background-color: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 20px;
    transition: transform var(--transition-smooth), background-color var(--transition-smooth);
}

.tool-card:hover .tool-icon {
    transform: scale(1.1) rotate(5deg);
    background-color: var(--primary-color);
    color: white;
}

.tool-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.tool-card p {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
}