/* For better font rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Default settings for Material Symbols */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Toast animation */
.toast {
    animation: toast-in 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both, 
               toast-out 0.5s cubic-bezier(0.550, 0.085, 0.680, 0.530) 2.5s both;
}

@keyframes toast-in {
    0% {
        transform: translateX(100%);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    0% {
        transform: translateX(0);
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Command Palette Animations */
.animate-fade-in {
    animation: fade-in 0.2s ease-out;
}

.animate-slide-down {
    animation: slide-down 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slide-down {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Command Palette Result Item Hover */
.command-palette-item {
    transition: all 0.15s ease;
}

.command-palette-item:hover,
.command-palette-item.selected {
    background-color: rgba(var(--primary-rgb), 0.1);
}

.dark .command-palette-item:hover,
.dark .command-palette-item.selected {
    background-color: rgba(var(--primary-rgb), 0.2);
}

/* PDF Viewer Fullscreen Styles */
#pdf-panel:fullscreen {
    background-color: #f6f7f8; /* Light mode background */
}

.dark #pdf-panel:fullscreen {
    background-color: #101922; /* Dark mode background */
}

/* Ensure canvas container takes full height in fullscreen */
#pdf-panel:fullscreen #pdf-canvas-container {
    max-height: calc(100vh - 60px); /* Subtract toolbar height */
}

/* PDF Text Layer for Text Selection */
#pdf-text-layer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 1;
    line-height: 1.0;
    z-index: 2;
    /* Use PDF.js default text layer class */
}

#pdf-text-layer > span,
#pdf-text-layer > br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

#pdf-text-layer .endOfContent {
    display: block;
    position: absolute;
    left: 0;
    top: 100%;
    right: 0;
    bottom: 0;
    z-index: -1;
    cursor: default;
    user-select: none;
}

#pdf-text-layer .endOfContent.active {
    top: 0;
}

/* Highlighted selected text should be visible */
#pdf-text-layer ::selection {
    background: rgba(0, 123, 255, 0.3);
}

#pdf-text-layer br::selection {
    background: transparent;
}

/* Dark mode selection */
.dark #pdf-text-layer ::selection {
    background: rgba(96, 165, 250, 0.4);
}

/* PDF Annotations Layer */
#pdf-annotations-layer {
    z-index: 3; /* Above text layer */
}

/* ==================== MOBILE & TOUCH OPTIMIZATIONS ==================== */

/* Touch manipulation for better mobile performance */
.touch-manipulation {
    touch-action: manipulation; /* Prevents 300ms tap delay */
    -webkit-tap-highlight-color: transparent; /* Removes iOS tap highlight */
    user-select: none; /* Prevents text selection on buttons */
}

/* Ensure all inputs and interactive elements are at least 44x44px (Apple HIG) */
input[type="number"],
input[type="text"],
select,
button {
    min-height: 44px;
}

/* PDF Canvas Container - Touch Scrolling */
#pdf-canvas-container {
    -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling on iOS */
    overscroll-behavior: contain; /* Prevents page bounce on iOS */
}

/* Prevent zoom on input focus (iOS Safari) */
@media screen and (max-width: 640px) {
    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="search"],
    input[type="url"],
    input[type="tel"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents iOS zoom when < 16px */
    }
}

/* Mobile-friendly tag suggestion buttons */
@media screen and (max-width: 640px) {
    #tag-suggestions button {
        min-height: 36px;
        padding: 0.5rem 0.75rem;
        font-size: 14px;
    }
    
    /* Larger tap targets for file upload */
    #file-upload-dropzone {
        padding: 2rem 1rem;
        min-height: 120px;
    }
    
    /* Stack batch operation controls vertically on small screens */
    #batch-action-toolbar .flex-col.sm\\:flex-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    #batch-action-toolbar .flex-col.sm\\:flex-row > div {
        width: 100%;
    }
}

/* Command Palette - Mobile Optimizations */
@media screen and (max-width: 640px) {
    #command-palette-modal {
        max-width: calc(100% - 1rem);
        margin: 0.5rem;
    }
    
    #command-palette-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        min-height: 44px;
    }
    
    .command-palette-item {
        padding: 1rem !important;
        min-height: 60px;
    }
    
    .command-palette-item .text-sm {
        font-size: 14px !important;
    }
}

/* Prevent horizontal overflow on mobile */
* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

/* Ensure header and main content don't overflow */
header {
    max-width: 100%;
    overflow-x: hidden;
    width: 100%;
}

main {
    max-width: 100%;
    overflow-x: hidden;
    width: 100%;
}

/* Main container */
.flex.min-h-screen {
    max-width: 100%;
    overflow-x: hidden;
    width: 100%;
}

/* Main content area */
.flex-1.flex.flex-col {
    max-width: 100%;
    overflow-x: hidden;
    width: 100%;
    min-width: 0;
}

/* Mobile header specific fixes */
@media screen and (max-width: 640px) {
    header {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    #search-input {
        max-width: 100%;
        min-width: 0;
    }
}