/* CSS Variables - Dark Mode (Default) */
:root {
    --bg-primary: #121214;
    --bg-secondary: #1a1a1e;
    --bg-tertiary: #25252d;
    --bg-accent: rgba(85, 88, 230, 0.05);
    --text-primary: #e3e3e6;
    --text-secondary: #a1a1a6;
    --text-muted: #73737a;
    --border-color: #2a2a30;
    --border-hover: #36363e;
    
    --accent-color: #5558e6;
    --accent-hover: #4649cc;
    --accent-glow: rgba(85, 88, 230, 0.1);
    --accent-gradient: linear-gradient(135deg, #5558e6 0%, #4649cc 100%);
    
    --success-color: #10b981;
    --danger-color: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --danger-hover: #dc2626;
    
    --card-bg: #1e1e24;
    --card-hover-bg: #25252d;
    
    --sidebar-width: 360px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* CSS Variables - Light Mode */
body.light-mode {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-accent: rgba(79, 70, 229, 0.05);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --accent-color: #4f46e5;
    --accent-hover: #4338ca;
    --accent-glow: rgba(79, 70, 229, 0.1);
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    
    --success-color: #059669;
    --danger-color: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.05);
    --danger-hover: #b91c1c;
    
    --card-bg: #ffffff;
    --card-hover-bg: #f8fafc;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* App Container */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar Scrolling & Constraint Fix */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    flex-shrink: 0;
    z-index: 10;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.sidebar-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.logo svg {
    width: 20px;
    height: 20px;
    color: var(--accent-color);
}

/* System settings */
.system-settings-card {
    margin: 16px 16px 0 16px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.field-row {
    display: flex;
    gap: 12px;
}

.field-group {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: none !important;
}

label svg {
    width: 14px;
    height: 14px;
}

select.form-select, input[type="text"], input[type="password"] {
    width: 100%;
    height: 38px;
    padding: 8px 12px;
    font-size: 0.85rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    font-family: inherit;
}

select.form-select:focus, input[type="text"]:focus, input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Queue summary */
.queue-summary-card {
    margin: 12px 16px 0 16px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.summary-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.summary-actions {
    display: flex;
    gap: 8px;
}

.summary-actions button {
    flex: 1;
}

/* Accordion Settings & Scroll Trap Fix */
.control-accordion {
    flex: 1;
    overflow-y: auto !important;
    min-height: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tool-tabs {
    display: flex;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 4px;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-group {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    overflow: hidden;
    transition: var(--transition);
    flex-shrink: 0;
}

.setting-group-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.setting-group-header span[class*="-icon-container"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.setting-group-header span[data-i18n] {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    text-align: left;
}

.setting-group-header svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.setting-group-header.no-toggle {
    cursor: default;
}

.setting-group-body {
    padding: 0 16px 16px 16px;
    transition: max-height 0.25s ease-out, opacity 0.2s ease-out;
    max-height: 500px;
    opacity: 1;
}

/* Global Collapsed Utility Rule */
.collapsed {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
    transition: var(--transition);
}

/* Switch Toggles */
.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-primary);
    transition: .3s;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-secondary);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

input:checked + .slider:before {
    transform: translateX(14px);
    background-color: white;
}

/* Switch Label Aligner */
.switch-label {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
    cursor: pointer;
    flex: 1;
    margin-right: 12px;
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
}

.color-picker-wrapper input[type="color"] {
    border: none;
    background: none;
    width: 24px;
    height: 24px;
    cursor: pointer;
    border-radius: 4px;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.color-picker-wrapper span {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Range Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-primary);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.range-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: right;
    margin-top: -2px;
}

/* Split radio cards & hide native checkbox button */
.split-mode-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.radio-card {
    display: block;
    cursor: pointer;
}

.radio-card input[type="radio"] {
    display: none;
}

.radio-card-content {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.radio-card-content svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.radio-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.radio-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.radio-card input[type="radio"]:checked + .radio-card-content {
    border-color: var(--accent-color);
    background: var(--accent-glow);
}

.radio-card input[type="radio"]:checked + .radio-card-content svg {
    color: var(--accent-color);
}

.range-status-indicator {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.range-status-indicator svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.range-status-indicator.invalid {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.05);
}

.range-status-indicator.valid {
    color: var(--success-color);
    border-color: rgba(16, 185, 129, 0.2);
    background: rgba(16, 185, 129, 0.05);
}

.mt-1 { margin-top: 4px; }
.mt-3 { margin-top: 12px; }

/* Warnings Alerts */
.compress-warning-alert {
    color: #f59e0b;
    font-size: 0.72rem;
    line-height: 1.4;
    font-weight: 500;
    border: 1px dashed rgba(245, 158, 11, 0.3);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: rgba(245, 158, 11, 0.05);
    text-align: center;
}

body.light-mode .compress-warning-alert {
    color: #d97706;
    border-color: rgba(217, 119, 6, 0.3);
    background: rgba(217, 119, 6, 0.03);
}

/* Sidebar Footer & Link Button */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.footer-privacy-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.footer-privacy-badge svg {
    width: 12px;
    height: 12px;
}

.security-link-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    transition: var(--transition);
}

.security-link-btn:hover {
    color: var(--accent-hover);
}

/* Buttons UI */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    line-height: 1.2;
    text-align: center;
}

.btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 0.95rem;
    border-radius: var(--radius-md);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

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

.btn-primary:disabled {
    background: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none !important;
}

.btn-outline {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background-color: var(--danger-bg);
    color: var(--danger-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
    transform: translateY(-1px);
}

.btn-danger:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn-ghost {
    background: none;
    border: none;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn-block {
    width: 100%;
}

/* Main Content Workspace Layout */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
    transition: var(--transition);
    padding: 0;
    border: 2px solid transparent;
}

/* Top Toolbar */
.top-toolbar {
    height: 64px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    flex-shrink: 0;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.divider {
    width: 1px;
    height: 20px;
    background-color: var(--border-color);
}

.queue-meta-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.bullet {
    margin: 0 4px;
    color: var(--text-muted);
}

/* Workspace Body */
.workspace-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}

/* Drop uploader empty state */
.empty-state {
    max-width: 640px;
    margin: 60px auto 0 auto;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 48px 32px;
    text-align: center;
    background: var(--bg-secondary);
    transition: var(--transition);
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

.empty-state:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-lg), 0 0 15px rgba(99, 102, 241, 0.05);
    background: var(--bg-accent);
}

.empty-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.icon-glow {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent-glow);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    transition: var(--transition);
}

.icon-glow svg {
    width: 32px;
    height: 32px;
}

.empty-state h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 460px;
}

.upload-actions {
    margin-top: 8px;
}

.onboarding-demo {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.demo-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#load-demo-btn {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-color);
    background: none;
    border: none;
    cursor: pointer;
}

#load-demo-btn:hover {
    color: var(--accent-hover);
}

/* Page Grid */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 24px;
    width: 100%;
}

/* Page Card */
.page-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: var(--transition);
    cursor: grab;
    box-shadow: var(--shadow-sm);
}

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

.page-card:active {
    cursor: grabbing;
}

.page-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 6px;
    z-index: 5;
    box-shadow: var(--shadow-sm);
}

.match-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--success-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    box-shadow: var(--shadow-sm);
    transform: scale(0);
    transition: var(--transition);
}

.page-card.is-matched .match-badge {
    transform: scale(1);
}

.page-card.is-matched {
    border-color: var(--success-color);
    box-shadow: 0 0 0 1px var(--success-color), var(--shadow-md);
}

.page-card.has-extract-active:not(.is-matched) {
    opacity: 0.45;
}

/* Thumbnail Container */
.page-preview-container {
    width: 100%;
    aspect-ratio: 1 / 1.414; 
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.page-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.2s;
}

/* Action Overlay on Hover */
.page-actions-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 42px; 
    background: rgba(11, 15, 25, 0.75);
    backdrop-filter: blur(2px);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    border-radius: var(--radius-sm);
    z-index: 4;
}

.page-card:hover .page-actions-overlay {
    opacity: 1;
}

.action-round-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.action-round-btn svg {
    width: 14px;
    height: 14px;
}

.action-round-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.action-round-btn.btn-delete:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

/* Card footer details */
.page-info-footer {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 2px;
}

.info-file-name {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
}

/* Sortable JS Styles */
.sortable-ghost {
    opacity: 0.2;
    border: 2px dashed var(--accent-color);
    background: var(--accent-glow) !important;
}

.sortable-drag {
    opacity: 0.8;
    transform: rotate(2deg) scale(1.05);
    box-shadow: var(--shadow-lg);
}

/* Drag over highlights for workspace */
.main-content.drag-over .empty-state {
    border-color: var(--accent-color);
    background-color: var(--accent-glow);
    transform: scale(1.01);
}
.main-content.drag-over .icon-glow {
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--accent-glow);
}

/* Modal styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(3, 7, 18, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transform: scale(0.95);
    transition: var(--transition);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.visible .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.modal-icon {
    color: var(--accent-color);
    width: 24px;
    height: 24px;
}

.modal h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-body p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.error-text {
    color: var(--danger-color);
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: 4px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

/* Loading Spinner */
.dark-overlay {
    background-color: rgba(3, 7, 18, 0.85) !important;
}

.loader-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 90%;
    max-width: 340px;
    box-shadow: var(--shadow-lg);
}

.loader-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.loader-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.spinner-spinner {
    width: 40px;
    height: 40px;
    position: relative;
    margin-bottom: 8px;
}

.double-bounce1, .double-bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--accent-color);
    opacity: 0.6;
    position: absolute;
    top: 0;
    left: 0;
    animation: sk-bounce 2.0s infinite ease-in-out;
}

.double-bounce2 {
    animation-delay: -1.0s;
}

@keyframes sk-bounce {
    0%, 100% { transform: scale(0.0) }
    50% { transform: scale(1.0) }
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
    border: 1px solid var(--border-color);
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.15s ease-out;
}

.loading-warning-text {
    font-size: 0.72rem;
    color: #f59e0b;
    margin-top: 12px;
    line-height: 1.4;
    text-align: center;
    border: 1px dashed rgba(245, 158, 11, 0.3);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: rgba(245, 158, 11, 0.05);
    font-weight: 500;
}

body.light-mode .loading-warning-text {
    color: #d97706;
    border-color: rgba(217, 119, 6, 0.3);
    background: rgba(217, 119, 6, 0.03);
}

.loading-ad-container {
    width: 100%;
    height: 0;
    overflow: hidden;
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 0;
}

.loading-ad-container.expanded {
    height: 90px;
    margin-top: 16px;
}

.loading-ad-wrapper {
    width: 100%;
    height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    position: relative;
    padding: 8px;
}

.ad-placeholder-label {
    position: absolute;
    top: 2px;
    right: 6px;
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.ad-placeholder-frame {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Toast Container */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    max-width: 380px;
    animation: toast-in 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.toast svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.toast-success {
    border-left: 4px solid var(--success-color);
}
.toast-success svg {
    color: var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--danger-color);
}
.toast-error svg {
    color: var(--danger-color);
}

.toast-info {
    border-left: 4px solid var(--accent-color);
}
.toast-info svg {
    color: var(--accent-color);
}

@keyframes toast-in {
    from {
        transform: translateY(20px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.toast.toast-out {
    animation: toast-out 0.25s ease-in forwards;
}

@keyframes toast-out {
    from {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    to {
        transform: translateY(10px) scale(0.9);
        opacity: 0;
    }
}

/* Skeletons */
.rendering-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 100%;
}

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

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

/* Visual Rotations */
.rot-90 { transform: rotate(90deg); }
.rot-180 { transform: rotate(180deg); }
.rot-270 { transform: rotate(270deg); }

/* General helpers */
.hidden { display: none !important; }
.file-name-highlight {
    color: var(--accent-color);
    font-weight: 600;
}

/* Responsive */
@media (max-width: 1024px) {
    body {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
    }
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .main-content {
        height: calc(100vh - 64px);
    }
    .app-container {
        flex-direction: column;
    }
}

/* Privacy, Terms, and About Modal Cards & Bodies */
.privacy-card, .terms-card, .about-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transform: scale(0.95);
    transition: var(--transition);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.visible .privacy-card,
.modal-overlay.visible .terms-card,
.modal-overlay.visible .about-card {
    transform: scale(1);
}

.privacy-body, .terms-body, .about-body {
    max-height: 60vh !important;
    overflow-y: auto !important;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    padding-right: 8px;
    text-align: left;
}
