/* Design System & Core Styles */
:root {
    /* Fonts */
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Colors - Dark Theme (Default) */
    --bg-primary: #0b0c10;
    --bg-secondary: #141722;
    --bg-sidebar: rgba(20, 23, 34, 0.75);
    --bg-header: rgba(11, 12, 16, 0.75);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-focus: rgba(74, 108, 247, 0.4);
    
    --text-main: #f1f3f9;
    --text-muted: #8c9ba5;
    --text-light: #526270;
    
    --accent: #4a6cf7;
    --accent-hover: #3b5bdb;
    --accent-glow: rgba(74, 108, 247, 0.15);
    --accent-glow-strong: rgba(74, 108, 247, 0.35);
    
    --card-bg: rgba(20, 23, 34, 0.65);
    --card-hover-bg: rgba(29, 33, 48, 0.85);
    --card-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    --card-hover-shadow: 0 12px 40px rgba(74, 108, 247, 0.15);
    
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.15);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.15);

    --backdrop-blur: blur(16px);
}

[data-theme="light"] {
    /* Colors - Light Theme */
    --bg-primary: #f6f8fa;
    --bg-secondary: #ffffff;
    --bg-sidebar: rgba(255, 255, 255, 0.75);
    --bg-header: rgba(246, 248, 250, 0.75);
    --border-color: rgba(0, 0, 0, 0.08);
    --border-color-focus: rgba(74, 108, 247, 0.5);
    
    --text-main: #1f2328;
    --text-muted: #57606a;
    --text-light: #8c959f;
    
    --accent: #4a6cf7;
    --accent-hover: #3b5bdb;
    --accent-glow: rgba(74, 108, 247, 0.08);
    --accent-glow-strong: rgba(74, 108, 247, 0.2);
    
    --card-bg: rgba(255, 255, 255, 0.7);
    --card-hover-bg: #ffffff;
    --card-shadow: 0 8px 30px rgba(140, 152, 164, 0.12);
    --card-hover-shadow: 0 12px 40px rgba(74, 108, 247, 0.15);
    
    --success: #1a7f37;
    --success-glow: rgba(26, 127, 55, 0.08);
    --danger: #cf222e;
    --danger-glow: rgba(207, 34, 46, 0.08);
}

/* Reset and Layout */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    font-family: var(--font-body);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Gradient decorative background */
.bg-gradient-glow {
    position: absolute;
    top: -20vh;
    right: -20vw;
    width: 70vw;
    height: 70vh;
    background: radial-gradient(circle, var(--accent-glow-strong) 0%, transparent 70%);
    z-index: -1;
    pointer-events: none;
    filter: blur(80px);
    border-radius: 50%;
    transition: background 0.3s ease;
}

/* Header/Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    height: 70px;
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 20px;
    color: var(--text-main);
    user-select: none;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.search-bar-container {
    position: relative;
    width: 480px;
    max-width: 40vw;
    transition: width 0.3s ease;
}

.search-bar-container input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.search-bar-container input:focus {
    border-color: var(--border-color-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--bg-secondary);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* App Container Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar Navigation */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 24px 16px;
    overflow-y: auto;
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.3s ease;
}

.sidebar-header h3 {
    font-family: var(--font-heading);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding-left: 12px;
    font-weight: 600;
}

.category-item {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    border-radius: 10px;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
    user-select: none;
}

.category-item:hover {
    background: var(--card-bg);
    color: var(--text-main);
}

.category-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px var(--border-color-focus);
}

.item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.hidden {
    display: none !important;
}

/* General Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
    user-select: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow-strong);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--card-hover-bg);
    border-color: var(--border-color-focus);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 8px;
}

.btn-with-icon {
    gap: 8px;
}

.btn-icon {
    width: 16px;
    height: 16px;
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

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

/* Theme Icons Logic */
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

/* Admin Ingestion Portal */
.admin-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.admin-header h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
}

.admin-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.close-icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s ease;
}

.close-icon-btn:hover {
    color: var(--text-main);
}

/* Upload Options Forms */
.upload-options {
    background: rgba(0, 0, 0, 0.1);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

[data-theme="light"] .upload-options {
    background: rgba(0, 0, 0, 0.02);
}

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

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.hint code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--accent);
}

/* Mode toggler layout */
.mode-toggle-group {
    margin-bottom: 0;
}

.radio-toggle-container {
    display: inline-flex;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 4px;
    border-radius: 10px;
    width: fit-content;
}

.radio-toggle-option {
    cursor: pointer;
    user-select: none;
}

.radio-toggle-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-button-label {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.radio-toggle-option input:checked + .toggle-button-label {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.25);
}

/* Manual Form Transition */
.manual-meta-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: fadeIn 0.25s ease;
}

.hidden-form {
    display: none !important;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.combobox-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.combobox-container select, .text-field {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.combobox-container select:focus, .text-field:focus {
    border-color: var(--border-color-focus);
}

.hidden-input {
    display: none;
}

/* Dropzone styling */
.dropzone {
    border: 2px dashed var(--border-color);
    background: rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

[data-theme="light"] .dropzone {
    background: rgba(0, 0, 0, 0.01);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.dropzone-icon-container {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    transition: transform 0.25s ease;
}

.dropzone:hover .dropzone-icon-container, 
.dropzone.dragover .dropzone-icon-container {
    color: var(--accent);
    transform: translateY(-4px);
}

.dropzone-text {
    font-weight: 500;
    font-size: 14px;
}

.dropzone-text .browse {
    color: var(--accent);
    text-decoration: underline;
    font-weight: 600;
}

.dropzone-subtext {
    font-size: 12px;
    color: var(--text-light);
}

/* Upload Progress Container */
.upload-progress-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.progress-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.progress-bar-wrapper {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.error { background: var(--danger); }

/* Explorer Header */
.explorer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    user-select: none;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
}

.breadcrumb-item {
    color: var(--text-main);
}

.breadcrumb-item.clickable {
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.breadcrumb-item.clickable:hover {
    color: var(--accent);
}

.breadcrumb-separator {
    color: var(--text-light);
    font-size: 14px;
    font-weight: 400;
}

.count-indicator {
    font-size: 13px;
    color: var(--text-muted);
}

/* Explorer Grid */
.explorer-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    align-content: start;
}

/* Card Designs */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    user-select: none;
}

.card:hover {
    background: var(--card-hover-bg);
    transform: translateY(-4px);
    border-color: var(--border-color-focus);
    box-shadow: var(--card-hover-shadow);
}

.card:active {
    transform: translateY(-2px);
}

.card-icon-container {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease;
}

.card:hover .card-icon-container {
    transform: scale(1.1);
}

/* Folder Card Specifics */
.folder-icon {
    width: 100%;
    height: 100%;
    color: var(--accent);
    filter: drop-shadow(0 4px 6px var(--accent-glow));
}

.folder-title {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    word-break: break-word;
    line-clamp: 2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* File Card Specifics */
.file-icon {
    width: 100%;
    height: 100%;
    color: var(--danger);
    filter: drop-shadow(0 4px 6px var(--danger-glow));
}

.file-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    word-break: break-all;
    line-clamp: 2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.file-meta {
    font-size: 11px;
    color: var(--text-light);
    margin-top: -4px;
}

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    flex: 1;
    color: var(--text-muted);
    animation: fadeIn 0.3s ease;
}

.empty-icon-container {
    width: 80px;
    height: 80px;
    color: var(--text-light);
    margin-bottom: 16px;
}

.empty-state h4 {
    font-family: var(--font-heading);
    font-size: 18px;
    color: var(--text-main);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    max-width: 320px;
}

/* Native Dialog PDF Modal Styles */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 85%;
    height: 85%;
    max-width: 1200px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    outline: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.modal[open] {
    display: flex;
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.modal::backdrop {
    background-color: rgba(11, 12, 16, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: backdropFadeIn 0.3s ease forwards;
}

.modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.modal-header {
    padding: 16px 24px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-title-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 60%;
}

.modal-title-icon {
    width: 20px;
    height: 20px;
    color: var(--danger);
    flex-shrink: 0;
}

#modal-filename {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-body {
    flex: 1;
    position: relative;
    background: #000; /* Backdrop for PDFs */
    overflow: hidden;
}

#pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
}

/* Spinner / Loader Inside Iframe */
.iframe-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Keyframes */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes backdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Responsive Grid Adaptation */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        min-width: unset;
        height: auto;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 16px;
    }

    .sidebar nav ul {
        display: flex;
        overflow-x: auto;
        gap: 8px;
        padding-bottom: 4px;
    }

    .category-item {
        margin-bottom: 0;
        white-space: nowrap;
    }
    
    .search-bar-container {
        max-width: 30vw;
    }
}

@media (max-width: 600px) {
    .navbar {
        padding: 0 16px;
    }

    .logo span {
        display: none;
    }

    .search-bar-container {
        max-width: unset;
        flex: 1;
        margin: 0 12px;
    }

    .btn-with-icon span {
        display: none;
    }

    .btn-with-icon {
        padding: 10px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Admin Auth Modal Specifics */
.auth-modal {
    max-width: 400px;
    height: auto;
    max-height: 90%;
    transform: translate(-50%, -50%) scale(0.95);
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.auth-modal[open] {
    transform: translate(-50%, -50%) scale(1);
}

.auth-modal-content {
    padding: 0;
}

.auth-modal-body {
    background: var(--bg-secondary) !important;
    padding: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-instruction {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-input-wrapper input {
    padding-right: 44px;
}

.password-toggle-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: color 0.2s ease, transform 0.1s ease;
    outline: none;
}

.password-toggle-btn:hover {
    color: var(--text-main);
}

.password-toggle-btn:active {
    transform: scale(0.92);
}

.password-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.auth-error {
    font-size: 12px;
    color: var(--danger);
    font-weight: 500;
    margin-top: 4px;
    display: block;
}

.auth-submit-btn {
    width: 100%;
    margin-top: 8px;
}

/* Shake Animation for incorrect password */
@keyframes shake {
    0%, 100% { transform: translate(-50%, -50%) scale(1) translateX(0); }
    20%, 60% { transform: translate(-50%, -50%) scale(1) translateX(-8px); }
    40%, 80% { transform: translate(-50%, -50%) scale(1) translateX(8px); }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

