/* Light Mode Theme */
.light {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: rgba(0, 0, 0, 0.1);
    --accent: #6366f1;
}

.light body {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

.light nav,
.light aside {
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.light .bg-dark-800,
.light .bg-dark-700,
.light .bg-dark-600 {
    background: var(--bg-secondary) !important;
}

.light .bg-dark-900,
.light .bg-dark-800\/50 {
    background: var(--bg-tertiary) !important;
}

.light .text-white {
    color: var(--text-primary) !important;
}

.light .text-gray-400,
.light .text-gray-300 {
    color: var(--text-secondary) !important;
}

.light .tool-btn {
    color: var(--text-secondary);
}

.light .tool-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.light .tool-btn.active {
    background: var(--accent);
    color: white;
}

.light .border-white\/5,
.light .border-white\/10 {
    border-color: var(--border-color) !important;
}

.light #mainContent {
    background: #e2e8f0 !important;
}

.light .page-wrapper {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.light input,
.light select,
.light textarea {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

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

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

.light .custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
}

.light .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

.light .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* Tool Button Styles */
.tool-btn {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: transparent;
    color: #9ca3af;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

/* Cursive font for Sign button */
.font-cursive {
    font-family: 'Brush Script MT', 'Segoe Script', 'Bradley Hand', cursive;
}

.tool-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: #a5b4fc;
}

.tool-btn.active {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.3);
}

/* Custom Tooltips */
.tool-btn::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tool-btn::before {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 4px;
    border: 4px solid transparent;
    border-right-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 100;
}

.tool-btn:hover::after,
.tool-btn:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Thumbnail Styles */
.thumbnail-item {
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.thumbnail-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.thumbnail-item.active {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.thumbnail-item img {
    width: 100%;
    display: block;
}

.thumbnail-item .page-number {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Thumbnail Action Buttons */
.thumb-actions {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 2px;
    padding: 4px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.thumbnail-item:hover .thumb-actions {
    opacity: 1;
}

.thumb-actions button {
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.thumb-actions button:hover {
    background: rgba(99, 102, 241, 0.8);
}

.thumb-actions button.delete:hover {
    background: rgba(239, 68, 68, 0.8);
}

/* Page Container (legacy) */
#pageContainer {
    background: white;
    border-radius: 4px;
    overflow: hidden;
    transition: transform 0.2s ease;
    margin-bottom: 50px;
}

/* Page Wrapper - Continuous Scroll */
.page-wrapper {
    background: white;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

/* Text layer for all pages */
.text-layer {
    line-height: 1;
    user-select: text;
    -webkit-user-select: text;
}

.text-layer span {
    position: absolute;
    color: transparent;
    white-space: pre;
    cursor: text;
    transform-origin: left top;
}

.text-layer span::selection {
    background: rgba(0, 120, 255, 0.35);
    color: transparent;
}

.text-layer span::-moz-selection {
    background: rgba(0, 120, 255, 0.35);
    color: transparent;
}

/* Text Input Overlay */
#textInputOverlay {
    z-index: 20;
}

#textInput {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Annotation Canvas Cursors */
.cursor-text {
    cursor: text;
}

.cursor-crosshair {
    cursor: crosshair;
}

.cursor-grab {
    cursor: grab;
}

/* Drawing Overlay */
.drawing-rect {
    position: absolute;
    pointer-events: none;
    border: 2px dashed rgba(99, 102, 241, 0.8);
}

.drawing-rect.highlight {
    background: rgba(255, 255, 0, 0.3);
    border-color: rgba(255, 200, 0, 0.8);
}

.drawing-rect.redact {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 0, 0, 0.8);
}

/* Glassmorphism Effects */
.glass {
    background: rgba(18, 18, 26, 0.8);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Sortable Ghost */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-chosen {
    opacity: 0.8;
}

/* Draggable Image */
#draggableImage {
    border: 2px dashed rgba(99, 102, 241, 0.8);
    background: rgba(99, 102, 241, 0.1);
    padding: 4px;
    border-radius: 4px;
}

#draggableImage img {
    pointer-events: none;
}

/* Animations */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.animate-pulse-slow {
    animation: pulse 2s ease-in-out infinite;
}

/* Drop Zone Active */
.drop-zone-active {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.5);
}

/* Keyboard Key Styling */
.kbd {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 11px;
    min-width: 20px;
    text-align: center;
    margin-right: 4px;
}

/* Text Selection Layer */
#textLayer {
    line-height: 1;
    user-select: text;
    -webkit-user-select: text;
}

#textLayer span {
    position: absolute;
    color: transparent;
    white-space: pre;
    cursor: text;
    transform-origin: left top;
}

#textLayer span::selection {
    background: rgba(0, 120, 255, 0.35);
    color: transparent;
}

#textLayer span::-moz-selection {
    background: rgba(0, 120, 255, 0.35);
    color: transparent;
}

/* Search Highlight */
.search-highlight {
    position: absolute;
    background: rgba(255, 230, 0, 0.5);
    pointer-events: none;
    border: 2px solid rgba(255, 180, 0, 0.8);
    border-radius: 2px;
}

.search-highlight.current {
    background: rgba(255, 150, 0, 0.6);
    border-color: rgba(255, 100, 0, 0.9);
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

/* Mobile sidebar toggle button */
#mobileSidebarToggle {
    display: none;
}

@media (max-width: 768px) {

    /* Show mobile toggle */
    #mobileSidebarToggle {
        display: flex;
    }

    /* Collapsible sidebar */
    aside {
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 200px !important;
    }

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

    /* Sidebar overlay */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 35;
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Hide left toolbar on mobile, show bottom bar */
    .desktop-toolbar {
        display: none !important;
    }

    .mobile-toolbar {
        display: flex !important;
    }

    /* Header adjustments */
    nav {
        padding: 0.5rem !important;
    }

    nav .gap-4 {
        gap: 0.5rem !important;
    }

    #filename {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Make tool buttons larger for touch */
    .tool-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px !important;
    }

    /* Main content full width */
    #mainContent {
        padding: 0.5rem !important;
    }

    .page-wrapper {
        margin: 0.5rem auto !important;
    }

    /* Text input overlay responsive */
    #textInputOverlay,
    #stickyNoteOverlay {
        max-width: 90vw !important;
    }

    #textInputOverlay textarea,
    #stickyNoteOverlay textarea {
        min-width: 200px !important;
        width: 100% !important;
    }

    /* Modal responsive */
    #signatureModal>div {
        width: 95vw !important;
        max-width: 500px;
        margin: 1rem;
    }

    #signatureCanvas {
        width: 100% !important;
        height: 150px !important;
    }

    /* Zoom controls compact */
    .zoom-controls {
        gap: 0.25rem !important;
    }

    /* Search bar compact */
    #searchBar input {
        width: 100px !important;
    }
}

/* Small mobile (phones) */
@media (max-width: 480px) {
    nav>.flex {
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }

    /* Stack header elements */
    #filename {
        order: 10;
        width: 100%;
        max-width: none;
        text-align: center;
        margin-top: 0.25rem;
    }

    /* Hide less important buttons */
    #closeFileBtn,
    #deleteFileBtn {
        display: none !important;
    }

    .tool-btn svg {
        width: 20px !important;
        height: 20px !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .tool-btn {
        min-width: 48px;
        min-height: 48px;
    }

    /* Remove hover effects that don't work on touch */
    .tool-btn:hover {
        background: transparent;
    }

    .tool-btn:active {
        background: rgba(99, 102, 241, 0.3);
    }

    /* Scrollbar hidden on touch devices */
    .custom-scrollbar::-webkit-scrollbar {
        display: none;
    }
}

/* Mobile bottom toolbar styles */
.mobile-toolbar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgb(30, 32, 40);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    z-index: 30;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-toolbar::-webkit-scrollbar {
    display: none;
}

/* Add bottom padding when mobile toolbar visible */
@media (max-width: 768px) {
    body {
        padding-bottom: 70px;
    }
}