/* ScribePDF Premium Styling and Theme Engine */

:root {
    /* Fonts */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-logo: 'Lexend', sans-serif;
    --font-serif: 'Merriweather', serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Theme Variables - Default Dark Mode */
    --bg-app: #090d16;
    --bg-panel: rgba(20, 28, 47, 0.65);
    --bg-panel-solid: #131c2f;
    --bg-header: rgba(15, 23, 42, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #6366f1;
    
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;
    
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.25);
    
    --success: #10b981;
    --success-hover: #059669;
    --success-glow: rgba(16, 185, 129, 0.2);
    
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.2);
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    
    --glass-blur: 16px;
    --glass-bg: rgba(15, 23, 42, 0.55);
    --bg-pdf-viewport: #0d121f;
}

/* Light Theme Variable Overrides */
body.light-theme {
    --bg-app: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.75);
    --bg-panel-solid: #ffffff;
    --bg-header: rgba(248, 250, 252, 0.85);
    --border-color: rgba(15, 23, 42, 0.08);
    --border-focus: #4f46e5;
    
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #f8fafc;
    
    --accent: #4f46e5;
    --accent-hover: #3730a3;
    --accent-glow: rgba(79, 70, 229, 0.15);
    
    --glass-bg: rgba(255, 255, 255, 0.65);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --bg-pdf-viewport: #e2e8f0;
}

/* Basic Resets & Document styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

input, button, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: transparent;
    border: none;
}

/* App container and structure */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header Section */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--bg-header);
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
    height: 64px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.logo-text h1 {
    font-family: var(--font-logo);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-main) 30%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-subtitle {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: block;
    margin-top: -2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Buttons - Premium custom styling */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    user-select: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #ffffff;
    box-shadow: 0 4px 10px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px var(--accent-glow);
    filter: brightness(1.1);
}

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

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: var(--text-secondary);
}

.btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-success {
    background-color: var(--success);
    color: #ffffff;
    box-shadow: 0 4px 10px var(--success-glow);
}

.btn-success:hover {
    background-color: var(--success-hover);
    transform: translateY(-1px);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-icon:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.btn-icon:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-icon.active {
    background-color: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}

.btn-close:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.icon {
    width: 18px;
    height: 18px;
}

/* Workspace Layout */
.app-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Left Sidebar - Navigation & File History */
.workspace-sidebar {
    width: 320px;
    background-color: var(--bg-panel);
    backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease;
    z-index: 5;
}

.workspace-sidebar.collapsed {
    width: 0px;
    transform: translateX(-320px);
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0.5rem 0;
    gap: 0.25rem;
    background-color: rgba(0, 0, 0, 0.15);
}

.tab-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem;
    border-radius: 8px 8px 0 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: var(--accent);
    background-color: var(--bg-panel-solid);
    border-bottom-color: var(--accent);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.tab-panel {
    display: none;
    height: 100%;
    flex-direction: column;
}

.tab-panel.active {
    display: flex;
}

/* Sidebar Toggle Switch */
.sidebar-collapse-btn {
    position: absolute;
    top: 50%;
    right: -14px;
    transform: translateY(-50%);
    width: 28px;
    height: 48px;
    background-color: var(--bg-panel-solid);
    border: 1px solid var(--border-color);
    border-radius: 0 10px 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.15);
    z-index: 10;
    transition: color 0.2s, background-color 0.2s;
}

.sidebar-collapse-btn:hover {
    color: var(--text-main);
    background-color: var(--accent-glow);
}

.workspace-sidebar.collapsed .sidebar-collapse-btn {
    right: -28px;
    transform: translateX(320px) translateY(-50%);
}

.workspace-sidebar.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}

/* File Dropzone Section */
.upload-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

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

.dropzone-icon {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
}

.upload-dropzone:hover .dropzone-icon {
    color: var(--accent);
    transform: scale(1.05);
    transition: transform 0.2s;
}

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

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

/* Document & Bookmark Lists */
.document-history-section, .bookmarks-section {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.document-history-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.document-list, .bookmarks-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
}

.empty-list-msg {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.01);
}

.document-item, .bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.document-item:hover, .bookmark-item:hover {
    background-color: rgba(255, 255, 255, 0.06);
    border-color: var(--text-muted);
}

.document-item.active {
    background-color: var(--accent-glow);
    border-color: var(--accent);
}

.doc-info, .bookmark-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow: hidden;
    flex: 1;
}

.doc-name, .bookmark-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-meta, .bookmark-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.doc-actions, .bookmark-actions-btns {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-item-delete {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-item-delete:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.bookmark-actions {
    margin-bottom: 1rem;
}

.bookmark-actions button {
    width: 100%;
}

.bookmark-comment {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.25rem;
    border-left: 2px solid var(--accent);
    padding-left: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Center Viewport Component */
.viewport-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-app);
}

.viewer-toolbar {
    height: 52px;
    background-color: var(--bg-panel-solid);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
    z-index: 4;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    flex-wrap: nowrap;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    -webkit-overflow-scrolling: touch;
}

.viewer-toolbar::-webkit-scrollbar {
    height: 4px;
}

.viewer-toolbar::-webkit-scrollbar-track {
    background: transparent;
}

.viewer-toolbar::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    flex-shrink: 0;
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.page-indicator input {
    width: 44px;
    height: 28px;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 500;
}

.page-indicator input::-webkit-inner-spin-button, 
.page-indicator input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#zoom-level {
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 48px;
    text-align: center;
    color: var(--text-secondary);
}

/* Document Tabs Bar */
.doc-tabs-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem 0 1rem;
    gap: 0.35rem;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
}

.doc-tabs-bar::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.doc-tab {
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    padding: 0.5rem 0.85rem;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    max-width: 180px;
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
    position: relative;
}

.doc-tab:hover {
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
}

.doc-tab.active {
    background-color: var(--bg-pdf-viewport, #0d121f);
    border-color: var(--border-color);
    color: var(--accent);
    font-weight: 500;
}

.doc-tab.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.doc-tab-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.doc-tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    color: var(--text-muted);
    transition: background-color 0.15s, color 0.15s;
}

.doc-tab-close:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.doc-tab-close svg {
    width: 10px;
    height: 10px;
}

/* PDF Viewport Scroll area */
.pdf-viewer-viewport {
    flex: 1;
    overflow: auto;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-color: var(--bg-pdf-viewport, #0d121f);
    outline: none;
}

.pdf-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    max-width: 100%;
}

/* Welcome screen card */
.welcome-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80%;
    width: 100%;
}

.welcome-card {
    background-color: var(--bg-panel);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    max-width: 460px;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.brand-illustration {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background-color: var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.brand-illustration svg {
    width: 44px;
    height: 44px;
}

.welcome-card h2 {
    font-family: var(--font-logo);
    font-size: 1.5rem;
    font-weight: 600;
}

.welcome-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Individual PDF Page Containers */
.pdf-page-container {
    position: relative;
    box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.4), 0 4px 8px -2px rgba(0, 0, 0, 0.25);
    background-color: #ffffff;
    border-radius: 6px;
    overflow: hidden;
    transition: transform 0.2s ease;
}

.pdf-page-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 32px -8px rgba(0, 0, 0, 0.5);
}

.pdf-page-canvas {
    display: block;
    max-width: 100%;
}

/* PDF.js Text Layer overlay for native highlights */
.textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 1;
    line-height: 1.0;
    z-index: 2;
    pointer-events: auto;
}

.textLayer span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.textLayer ::selection {
    background-color: rgba(99, 102, 241, 0.3) !important;
    border-radius: 2px;
}

/* Canvas Selection overlay (for custom OCR crop drawing) */
.selection-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
    cursor: crosshair;
}

.pdf-page-container.crop-tool-active {
    cursor: crosshair;
}

.pdf-page-container.crop-tool-active .selection-overlay-canvas {
    pointer-events: auto;
}

/* Selection Box Overlay Div */
.selection-box {
    position: absolute;
    border: 2px dashed var(--accent);
    background-color: rgba(99, 102, 241, 0.12);
    box-shadow: 0 0 8px var(--accent-glow);
    z-index: 4;
    pointer-events: none;
    border-radius: 4px;
}

/* RIGHT SIDEBAR: OCR Status & Log Pane */
.ocr-status-panel {
    width: 320px;
    background-color: var(--bg-panel);
    backdrop-filter: blur(var(--glass-blur));
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 5;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease;
}

.ocr-status-panel.collapsed {
    width: 0px;
    transform: translateX(320px);
    border-left-width: 0px;
}

.right-panel-collapse-btn {
    position: absolute;
    top: 50%;
    left: -14px;
    transform: translateY(-50%);
    width: 28px;
    height: 48px;
    background-color: var(--bg-panel-solid);
    border: 1px solid var(--border-color);
    border-radius: 10px 0 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    box-shadow: -4px 0 10px rgba(0, 0, 0, 0.15);
    z-index: 10;
    transition: color 0.2s, background-color 0.2s, left 0.3s ease, transform 0.3s ease;
}

.right-panel-collapse-btn:hover {
    color: var(--text-main);
    background-color: var(--accent-glow);
}

.ocr-status-panel.collapsed .right-panel-collapse-btn {
    left: -28px;
    transform: translateX(-320px) translateY(-50%);
}

.ocr-status-panel.collapsed .right-panel-collapse-btn svg {
    transform: rotate(180deg);
}

.panel-header {
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* OCR Engine Loading indicators */
.ocr-engine-status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem;
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.idle {
    background-color: var(--text-muted);
}

.status-indicator.ready {
    background-color: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-indicator.loading {
    background-color: var(--warning);
    box-shadow: 0 0 6px var(--warning);
    animation: pulse 1.5s infinite;
}

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

/* OCR Progress Indicator block */
.ocr-progress-container {
    padding: 1rem;
    background-color: rgba(99, 102, 241, 0.05);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 500;
}

#ocr-progress-action {
    color: var(--text-secondary);
}

#ocr-progress-percent {
    color: var(--accent);
}

.progress-bar-bg {
    height: 6px;
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, #a855f7 100%);
    border-radius: 3px;
    transition: width 0.15s ease-out;
}

/* Snippet Preview Card */
.selection-details-card {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.selection-details-card h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.card-instruction {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.35;
}

.extracted-text-preview {
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    min-height: 120px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
    line-height: 1.45;
}

.preview-placeholder {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    margin-top: 2rem;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
}

.card-actions button {
    flex: 1;
}

/* Session stats details */
.indexing-stats {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    margin-top: auto;
}

.indexing-stats h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 0.35rem 0;
    color: var(--text-secondary);
}

.stat-row:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.stat-row span:last-child {
    font-weight: 600;
    color: var(--text-main);
}

/* EDIT AND FORMAT MODAL OVERLAY */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(2, 6, 23, 0.65);
    backdrop-filter: blur(10px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.25s ease-out;
}

/* Modal Card layout */
.modal-card {
    width: 88vw;
    max-width: 1600px;
    height: 88vh;
    background-color: var(--bg-panel-solid);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.modal-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 0.15rem;
}

/* Formatting toolbar in modal */
.editor-toolbar {
    background-color: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1.25rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

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

.toolbar-dropdown {
    height: 32px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0 0.5rem;
    cursor: pointer;
    transition: border-color 0.2s;
    outline: none;
}

.toolbar-dropdown:focus {
    border-color: var(--accent);
}

.toolbar-dropdown option {
    background-color: var(--bg-panel-solid);
    color: var(--text-main);
}

/* Content Editable block styling */
.modal-body {
    flex: 1;
    overflow: hidden;
    padding: 1.5rem;
    background-color: rgba(0, 0, 0, 0.05);
}

.editor-content-container {
    height: 100%;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-app);
    overflow-y: auto;
    transition: border-color 0.2s;
}

.editor-content-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.text-editor {
    min-height: 100%;
    padding: 1.5rem;
    outline: none;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-main);
    transition: all 0.15s ease;
}

/* Placeholder support for contenteditable */
.text-editor:empty:before {
    content: attr(placeholder);
    color: var(--text-muted);
    cursor: text;
    pointer-events: none;
    display: block;
}

/* Modal Footer Actions */
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-panel-solid);
}

.footer-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.footer-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-group {
    display: inline-flex;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.btn-group button {
    border-radius: 0;
}

.btn-group button:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.btn-group button:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
}

/* Toasts Container */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1000;
}

.toast {
    min-width: 280px;
    max-width: 380px;
    padding: 1rem;
    border-radius: 10px;
    background-color: var(--bg-panel-solid);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideInRight 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: all 0.2s;
}

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

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

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

.toast.info .toast-icon {
    color: var(--accent);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.warning .toast-icon {
    color: var(--warning);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.15rem;
}

.toast-message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.35;
}

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

@keyframes scaleUp {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* Screenreader text utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Custom Scrollbar for premium feeling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* PDF Merging Modal styles */
.merge-queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    gap: 1rem;
    transition: background-color 0.2s, border-color 0.2s;
}

.merge-queue-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--accent);
}

.merge-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    overflow: hidden;
}

.merge-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.merge-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.merge-item-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.merge-item-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 4px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.merge-item-actions button svg {
    width: 16px;
    height: 16px;
}

.merge-item-actions button:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.08);
}

.merge-item-actions button.btn-delete:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.08);
}

.merge-item-actions button:disabled {
    color: var(--text-muted);
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
}

/* Text Editor List and Toolbar Active States */
.text-editor ul, .text-editor ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.text-editor ul {
    list-style-type: disc;
}

.text-editor ol {
    list-style-type: decimal;
}

.text-editor li {
    margin-bottom: 0.25rem;
}

.editor-toolbar .btn.btn-icon.active {
    background-color: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.editor-toolbar .btn.btn-icon.active:hover {
    background-color: var(--accent);
    color: #ffffff;
}

/* Text Page Container (for DOCX, TXT, RTF) */
.pdf-page-container.text-page-container {
    background-color: #ffffff !important;
    color: #0d121f !important;
    box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.4) !important;
    border-radius: 6px;
    padding: 3.5rem 4.5rem;
    overflow-y: auto;
    max-width: 100%;
    height: auto !important;
    min-height: 1000px;
}

body.light-theme .pdf-page-container.text-page-container {
    box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.15) !important;
}

.text-page-content {
    font-family: var(--font-sans);
    font-size: 1.05rem;
    line-height: 1.6;
    color: #0d121f;
}

.text-page-content p {
    margin-bottom: 1.25rem;
}

.text-page-content h1, .text-page-content h2, .text-page-content h3 {
    margin-top: 1.75rem;
    margin-bottom: 0.85rem;
    font-weight: 600;
    color: #000000;
}

.text-page-content ul, .text-page-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
    padding-left: 1rem;
}

.text-page-content li {
    margin-bottom: 0.35rem;
}

/* Tool Cursors & Overlays */
.pdf-page-container.highlight-tool-active {
    cursor: cell;
}
.pdf-page-container.highlight-tool-active .selection-overlay-canvas {
    pointer-events: auto;
}

.pdf-page-container.pen-tool-active {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2'><path d='M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z'/></svg>") 2 22, crosshair;
}

.pdf-page-container.highlighter-tool-active {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23eab308' stroke-width='2.5'><path d='m9 11-6 6v3h3l6-6Z'/></svg>") 2 22, cell;
}

.pdf-page-container.eraser-tool-active {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ef4444' stroke-width='2'><path d='m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21'/><path d='M22 21H7'/></svg>"), pointer;
}
.pdf-page-container.eraser-tool-active .selection-overlay-canvas {
    pointer-events: none;
}

/* Freehand Annotation Canvas */
.drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.pdf-page-container.pen-tool-active .drawing-canvas,
.pdf-page-container.highlighter-tool-active .drawing-canvas,
.pdf-page-container.eraser-tool-active .drawing-canvas {
    pointer-events: auto;
}

/* Highlight Boxes */
.pdf-highlight-box {
    position: absolute;
    z-index: 20;
    cursor: pointer;
    border: 1.5px dashed transparent;
    transition: opacity 0.2s ease, border-color 0.2s ease;
}
.pdf-page-container.eraser-tool-active .pdf-highlight-box:hover {
    border-color: rgba(239, 68, 68, 0.8) !important;
    background-color: rgba(239, 68, 68, 0.3) !important;
}

/* Sticky Notes */
.sticky-note {
    position: absolute;
    z-index: 30;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -2px rgba(0,0,0,0.15);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: var(--font-sans);
    transition: transform 0.15s ease;
}
.sticky-note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    padding-bottom: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    user-select: none;
}
.sticky-note-textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 0.8rem;
    color: inherit;
    line-height: 1.4;
    min-height: 48px;
}
.sticky-note-minimized {
    position: absolute;
    z-index: 30;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.25);
    transition: transform 0.2s ease;
    border: 2px solid #ffffff;
}
.sticky-note-minimized:hover {
    transform: scale(1.15);
}
.sticky-note-minimized svg {
    width: 16px;
    height: 16px;
    color: #ffffff;
}

/* Sticky Note Color Themes */
.sticky-note.color-yellow, .sticky-note-minimized.color-yellow { background-color: #fef08a; border: 1px solid #fde047; color: #713f12; }
.sticky-note.color-green, .sticky-note-minimized.color-green { background-color: #a7f3d0; border: 1px solid #6ee7b7; color: #064e3b; }
.sticky-note.color-pink, .sticky-note-minimized.color-pink { background-color: #fbcfe8; border: 1px solid #f9a8d4; color: #831843; }
.sticky-note.color-blue, .sticky-note-minimized.color-blue { background-color: #bfdbfe; border: 1px solid #93c5fd; color: #1e3a8a; }
.sticky-note.color-violet, .sticky-note-minimized.color-violet { background-color: #ddd6fe; border: 1px solid #c4b5fd; color: #4c1d95; }

/* Sticky Note controls */
.sticky-note-header button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0 2px;
    font-size: 0.85rem;
    opacity: 0.7;
    transition: opacity 0.2s;
    color: inherit;
}
.sticky-note-header button:hover {
    opacity: 1;
}

/* Color dot picker on note */
.sticky-note-colors {
    display: flex;
    gap: 4px;
    border-t: 1px solid rgba(0,0,0,0.06);
    padding-top: 4px;
}
.sticky-note-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.1s;
}
.sticky-note-color-dot:hover {
    transform: scale(1.2);
}

/* Sticky Notes Wall List */
.sticky-wall-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: background-color 0.2s;
}
.sticky-wall-card:hover {
    background-color: var(--bg-input);
}
.sticky-wall-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.sticky-wall-card-header span {
    font-weight: 600;
}
.sticky-wall-card-body textarea {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    font-size: 0.75rem;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    padding: 2px;
}
.sticky-wall-card-body textarea:focus {
    border-color: var(--border-color);
    background: var(--bg-body);
    border-radius: 4px;
}
.sticky-wall-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 4px;
    font-size: 0.75rem;
}
.sticky-wall-card-dots {
    display: flex;
    gap: 4px;
}

/* Right Sidebar Tab Content Panel */
.panel-tab-content {
    display: none;
}
.panel-tab-content.active {
    display: flex !important;
}
.panel-header-tabs .tab-btn.active {
    border-bottom: 2px solid var(--accent) !important;
    color: var(--accent) !important;
    background-color: var(--accent-glow) !important;
}

/* Print Media styles */
@media print {
    body.print-document-mode {
        background: white !important;
    }
    body.print-document-mode .app-header,
    body.print-document-mode .workspace-sidebar,
    body.print-document-mode .ocr-status-panel,
    body.print-document-mode .viewer-toolbar,
    body.print-document-mode .doc-tabs-bar,
    body.print-document-mode .modal-overlay,
    body.print-document-mode .toast-container {
        display: none !important;
    }
    body.print-document-mode .pdf-viewer-viewport {
        background: white !important;
        padding: 0 !important;
        overflow: visible !important;
        display: block !important;
    }
    body.print-document-mode .pdf-pages-container {
        background: white !important;
        gap: 0 !important;
        display: block !important;
        overflow: visible !important;
    }
    body.print-document-mode .pdf-page-container {
        box-shadow: none !important;
        border: none !important;
        margin: 0 auto 2cm auto !important;
        page-break-after: always !important;
        display: block !important;
        transform: none !important;
    }
    body.print-document-mode .textLayer,
    body.print-document-mode .selection-overlay-canvas {
        display: none !important;
    }

    body.print-editor-mode {
        background: white !important;
    }
    body.print-editor-mode .app-container {
        display: none !important;
    }
    body.print-editor-mode .modal-overlay {
        position: static !important;
        background: white !important;
        display: block !important;
        z-index: auto !important;
        padding: 0 !important;
    }
    body.print-editor-mode .modal-card {
        width: 100% !important;
        height: auto !important;
        box-shadow: none !important;
        border: none !important;
        background: white !important;
        display: block !important;
        animation: none !important;
    }
    body.print-editor-mode .modal-header,
    body.print-editor-mode .editor-toolbar,
    body.print-editor-mode .modal-footer {
        display: none !important;
    }
    body.print-editor-mode .modal-body {
        padding: 0 !important;
        overflow: visible !important;
    }
    body.print-editor-mode .text-editor {
        border: none !important;
        background: white !important;
        color: black !important;
        box-shadow: none !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
}

/* Styling for active state of normal buttons (e.g. Draw Crop Box active in sidebar) */
.btn.active {
    background-color: var(--accent) !important;
    color: #ffffff !important;
    border-color: var(--accent) !important;
    box-shadow: 0 0 8px var(--accent-glow) !important;
}

/* --- Court Index Builder Interface Elements --- */
.index-file-item {
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.65rem;
    gap: 0.5rem;
    transition: background-color 0.2s, border-color 0.2s;
}

.index-file-item:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

.index-file-item.selected {
    border-color: var(--accent);
    background-color: rgba(99, 102, 241, 0.04);
}

.index-file-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.index-file-title-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 2px 4px;
    border-radius: 4px;
    flex: 1;
    width: 100%;
}

.index-file-title-input:focus {
    border-color: var(--border-color);
    background-color: var(--bg-input);
    outline: none;
}

.index-file-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.index-file-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.index-file-actions button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.index-file-actions button svg {
    width: 14px;
    height: 14px;
}

.index-file-actions button:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.index-file-actions button.btn-delete:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.08);
}

/* Live Index structures */
.index-tree-node {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.01);
    border: 1px solid var(--border-color);
}

.index-tree-node-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.index-tree-node-title {
    font-size: 0.8rem;
    color: var(--text-main);
    text-decoration: underline;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-align: left;
}

.index-tree-node-title:hover {
    color: var(--accent);
}

.index-tree-node-page {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: right;
}

.index-tree-subitems {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-left: 0.75rem;
    border-left: 1.5px dashed var(--border-color);
    margin-top: 0.25rem;
}

.index-tree-subitem-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 2px 0;
}

.index-tree-subitem-title-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 1px 3px;
    border-radius: 4px;
    flex: 1;
    width: 100%;
}

.index-tree-subitem-title-input:focus {
    border-color: var(--border-color);
    background-color: var(--bg-input);
    outline: none;
}

.index-tree-subitem-page-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.index-tree-subitem-page-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    width: 38px;
    text-align: center;
    padding: 1px;
    border-radius: 4px;
}

.index-tree-subitem-page-input:focus {
    border-color: var(--border-color);
    background-color: var(--bg-input);
    outline: none;
}

.btn-delete-subitem {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 2px;
    font-size: 0.85rem;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
}

.btn-delete-subitem:hover {
    opacity: 1;
    color: #ef4444;
}

/* Preliminary Roman Pages configuration styles */
.index-file-prelim-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 0.25rem;
}

.index-file-prelim-input {
    width: 48px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 4px;
    padding: 1px 4px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 500;
    transition: border-color 0.15s, background-color 0.15s;
}

.index-file-prelim-input:focus {
    border-color: var(--accent);
    background-color: rgba(99, 102, 241, 0.05);
    outline: none;
}

/* Preview OCR Selection Styles */
.index-preview-page-wrapper.crop-active {
    cursor: crosshair !important;
}

.index-preview-page-wrapper.crop-active * {
    pointer-events: none !important;
}

.preview-selection-box {
    position: absolute;
    border: 2px dashed var(--accent);
    background-color: rgba(99, 102, 241, 0.15);
    z-index: 100;
    pointer-events: none;
}

.ocr-flash-success {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(16, 185, 129, 0.15);
    border: 2px solid #10b981;
    z-index: 101;
    animation: ocrFadeOut 1s ease-out forwards;
    pointer-events: none;
}

@keyframes ocrFadeOut {
    0% { opacity: 1; transform: scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: scale(0.95); }
}

.upload-option-card:hover {
    border-color: var(--accent) !important;
    background-color: rgba(99, 102, 241, 0.05) !important;
}

/* CAMERA SCANNER THUMBNAILS */
.camera-thumbnail-item {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #000;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, border-color 0.2s;
}

.camera-thumbnail-item:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}

.camera-thumbnail-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-thumbnail-delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(239, 68, 68, 0.85);
    color: #fff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: background 0.15s;
    font-family: inherit;
    font-weight: bold;
    z-index: 5;
    padding: 0;
}

.camera-thumbnail-delete-btn:hover {
    background: rgb(220, 38, 38);
}

/* USER PROFILE BUTTON & AVATAR BADGES */
#profile-toggle-btn {
    position: relative;
    padding: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background-color: var(--bg-panel-solid);
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s, background-color 0.2s;
}

#profile-toggle-btn:hover {
    transform: scale(1.05);
    border-color: var(--accent);
    background-color: var(--accent-glow);
}

#profile-avatar-large {
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* ==========================================
   CAMERA SCANNER SPLIT SCREEN (DESKTOP)
   ========================================== */
#camera-modal .modal-card {
    width: 1000px !important;
    max-width: 95% !important;
    height: 80vh !important;
    max-height: 85vh !important;
    border-radius: 12px !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

#camera-modal .modal-body {
    flex: 1 !important;
    display: flex !important;
    flex-direction: row !important;
    padding: 0 !important;
    margin: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    background-color: var(--bg-app) !important;
    overflow: hidden !important;
}

/* Splits */
.camera-split-left {
    flex: 1.4 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #000 !important;
    border-right: 1px solid var(--border-color);
    position: relative !important;
    min-height: 0 !important;
    height: 100% !important;
    justify-content: center !important;
    align-items: center !important;
}

.camera-split-right {
    flex: 0.8 !important;
    display: flex !important;
    flex-direction: column !important;
    background-color: var(--bg-panel-solid) !important;
    padding: 1.5rem !important;
    gap: 1rem !important;
    overflow-y: auto !important;
    min-height: 0 !important;
    height: 100% !important;
    box-sizing: border-box !important;
}

.camera-viewport-container {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #000 !important;
}

#camera-video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important; /* Ensure video is not cropped */
    max-height: none !important;
}

/* Helper styles for split controls */
.camera-split-right .control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
}

.camera-split-right .control-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.camera-split-right .form-select,
.camera-split-right .form-input {
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
    border-radius: 4px;
    background: var(--bg-app);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    width: 100%;
    box-sizing: border-box;
}

.camera-thumbs-container {
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-panel);
    padding: 0.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 0.5rem;
    align-content: start;
}

/* ==========================================
   MOBILE & SMARTPHONE OPTIMIZATIONS
   ========================================== */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex !important;
    }

    /* Adjust header for horizontal swiping/scrolling of buttons */
    .app-header {
        height: auto !important;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.5rem 1rem !important;
        gap: 0.5rem !important;
    }

    .header-logo {
        justify-content: center !important;
        margin-bottom: 0.25rem;
    }

    .logo-subtitle {
        display: none !important;
    }

    .header-actions {
        display: flex !important;
        overflow-x: auto !important;
        gap: 0.5rem !important;
        padding-bottom: 0.25rem !important;
        width: 100% !important;
        justify-content: flex-start !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Custom thin scrollbar for header buttons row */
    .header-actions::-webkit-scrollbar {
        height: 3px;
    }
    .header-actions::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 2px;
    }

    /* Shrink-0 to keep buttons fully shaped when overflow scrolls */
    .header-actions .btn,
    .header-actions label,
    .header-actions button,
    .header-actions a {
        flex-shrink: 0 !important;
    }

    /* Hide desktop collapse handles */
    #sidebar-toggle, .right-panel-collapse-btn {
        display: none !important;
    }

    /* Left Sidebar Overlay (Files & Bookmarks) */
    .workspace-sidebar {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 85% !important;
        max-width: 320px !important;
        transform: translateX(-100%) !important;
        z-index: 1000 !important;
        box-shadow: 5px 0 15px rgba(0,0,0,0.5) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .workspace-sidebar.active-mobile {
        transform: translateX(0) !important;
    }

    /* Right Sidebar Overlay (OCR Log) */
    .ocr-status-panel {
        position: absolute !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 85% !important;
        max-width: 320px !important;
        transform: translateX(100%) !important;
        z-index: 1000 !important;
        box-shadow: -5px 0 15px rgba(0,0,0,0.5) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .ocr-status-panel.active-mobile {
        transform: translateX(0) !important;
    }

    /* Viewport takes 100% width */
    .viewport-container {
        width: 100% !important;
        flex: 1 !important;
    }

    /* General responsive modal styling */
    .modal-overlay {
        height: 100dvh !important;
        padding: 0.5rem !important;
        box-sizing: border-box !important;
    }

    .modal-card {
        width: 100% !important;
        max-width: 450px !important;
        height: auto !important;
        max-height: 90dvh !important;
        border-radius: 12px !important;
        margin: 0 auto !important;
    }

    /* Make camera modal full screen on mobile devices */
    #camera-modal {
        padding: 0 !important;
        height: 100dvh !important;
    }

    #camera-modal .modal-card {
        width: 100% !important;
        height: 100dvh !important;
        max-width: 100% !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #camera-modal .modal-body {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important; /* Stack vertically on mobile */
        overflow: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
        max-height: none !important;
    }

    .camera-split-left {
        flex: 1 !important; /* Take remaining vertical space */
        height: auto !important;
        min-height: 0 !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        background: #000 !important;
    }

    .camera-split-right {
        flex: 0 0 auto !important; /* Shrink to wrap contents */
        height: auto !important;
        overflow-y: auto !important;
        padding: 0.75rem !important;
        gap: 0.75rem !important;
        background-color: var(--bg-panel-solid) !important;
        box-sizing: border-box !important;
    }

    /* Thumbnail container scroll horizontally on mobile */
    .camera-thumbs-container {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        min-height: 75px !important;
        max-height: 75px !important;
        width: 100% !important;
        padding: 0.25rem !important;
        gap: 0.5rem !important;
        grid-template-columns: none !important;
        box-sizing: border-box !important;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        background: var(--bg-panel);
    }

    .camera-thumbnail-item {
        flex-shrink: 0 !important;
        height: 100% !important;
        width: auto !important;
        aspect-ratio: 3/4 !important;
    }

    /* Layout adjustments for controls on mobile to fit nicely */
    .camera-split-right .control-group {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0.5rem !important;
        margin-bottom: 0.25rem !important;
    }

    .camera-split-right .control-group label {
        white-space: nowrap !important;
        font-size: 0.75rem !important;
        margin: 0 !important;
    }

    .camera-split-right .control-group select,
    .camera-split-right .control-group input {
        width: auto !important;
        flex: 1 !important;
        max-width: 60% !important;
        padding: 0.25rem 0.4rem !important;
        font-size: 0.8rem !important;
    }

    /* Action buttons on mobile */
    .camera-split-right > div {
        gap: 0.35rem !important;
    }

    .camera-split-right button {
        padding: 0.45rem 0.25rem !important;
        font-size: 0.75rem !important;
    }

    #camera-video {
        max-height: none !important;
        height: 100% !important;
        width: 100% !important;
        object-fit: contain !important; /* Ensure video is not cropped */
    }
}

/* Responsive adjustments for header actions on medium-sized screens to prevent overflow */
@media (max-width: 1120px) {
    .header-logo .logo-text,
    .btn-text {
        display: none !important;
    }
    
    .header-actions .btn,
    .header-actions label,
    .header-actions button,
    #open-pdf-btn,
    #save-pdf-btn,
    #close-pdf-btn {
        padding: 0.5rem !important;
        margin: 0 !important;
        margin-left: 0.25rem !important;
        justify-content: center !important;
        gap: 0 !important;
    }
}

/* Annotation Styling Sub-Toolbar Active Styles */
.color-swatch {
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.color-swatch:hover {
    transform: scale(1.15);
}
.color-swatch.active {
    transform: scale(1.25);
    border-color: #ffffff !important;
    box-shadow: 0 0 0 2px var(--accent) !important;
}

.thickness-btn {
    transition: all 0.15s ease;
}
.thickness-btn:hover {
    background-color: var(--bg-hover) !important;
}
.thickness-btn.active {
    background-color: var(--accent) !important;
    color: #ffffff !important;
    border-color: var(--accent) !important;
}

