/* Base configuration and utilities */
:root {
    --sidebar-width: 280px;
}
/* Mobile-friendly viewport height */
body { 
    height: 100dvh; 
    width: 100vw; 
    overflow: hidden; 
    font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    touch-action: none; /* Prevent default browser pinch-zoom to allow custom canvas zooming */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Viewer & Canvas */
#viewer-container {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
    overflow: auto;
    display: block;
    box-sizing: border-box;
    overflow-anchor: none; 
    -webkit-overflow-scrolling: touch;
    background-color: transparent; 
}

#canvas-wrapper {
    position: relative;
    display: block;
    min-width: 100%;
    min-height: 100%;
}

#pdf-canvas {
    box-shadow: 0 4px 25px rgba(0,0,0,0.15);
    background-color: white;
    transform-origin: top left;
    position: absolute;
    margin: 0; 
    padding: 0;
    max-width: none !important;
    max-height: none !important;
    transition: none; 
}

/* Tool Button Active State & Micro-animations */
.tool-btn { 
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); 
}
.tool-btn:active {
    transform: scale(0.92);
}
.tool-btn.active { 
    background-color: #eff6ff; 
    color: #2563eb; 
    border-color: #bfdbfe; 
    box-shadow: inset 0 2px 4px rgba(37, 99, 235, 0.1);
}
.tool-btn.active-ocr { 
    background-color: #ecfdf5; 
    color: #10b981; 
    border-color: #a7f3d0; 
    box-shadow: inset 0 2px 4px rgba(16, 185, 129, 0.1);
}

/* Glassmorphism Utilities */
.glass-panel {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: var(--tw-shadow-glass);
}

/* Text Editor Overlay */
#text-editor {
    position: absolute;
    background: transparent;
    border: 2px dashed #2563eb;
    font-family: sans-serif;
    padding: 2px;
    resize: none;
    overflow: hidden;
    z-index: 10;
    line-height: 1.2;
    outline: none;
}

/* Sidebar styles & Text Selection Prevention for iPad */
#pdf-list li {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
#pdf-list li.sortable-ghost { opacity: 0.5; background: #f8fafc; border: 2px dashed #94a3b8; transform: scale(0.98); border-radius: 0.5rem; }
#pdf-list li.sortable-drag { cursor: grabbing !important; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1); transform: scale(1.02); z-index: 100; border: 1px solid #e2e8f0; background: white; border-radius: 0.5rem; }

/* Hide native file inputs */
.file-input-wrapper input[type="file"] {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}

/* Mobile & Tablet Layout Handling */
#menu-toggle { display: none; }
#sidebar {
    width: var(--sidebar-width);
    transition: transform 0.3s ease-in-out, visibility 0.3s ease-in-out;
}
#sidebar-overlay { display: none; }

@media (max-width: 1024px) {
    body.has-pdfs #sidebar {
        position: fixed; top: 0; left: 0; height: 100dvh; z-index: 50;
        transform: translateX(-100%);
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
        visibility: hidden;
        width: 320px;
        max-width: 85vw;
    }
    body.has-pdfs.sidebar-open #sidebar { transform: translateX(0); visibility: visible; }
    body.has-pdfs.sidebar-open #sidebar-overlay { display: block; }
    
    body:not(.has-pdfs) #sidebar {
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
        border-left: 1px solid #e2e8f0;
        box-shadow: 0 0 20px rgba(0,0,0,0.05);
    }
    body:not(.has-pdfs) #main-content {
        display: none !important;
    }
    body.has-pdfs #menu-toggle {
        display: block;
    }
    .desktop-only { display: none !important; }
}

/* Fullscreen Mode Styles */
body.is-fullscreen #sidebar,
body.is-fullscreen #menu-toggle {
    display: none !important;
}
body.is-fullscreen header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    transform: translateY(-100%);
    transition: transform 0.3s ease-in-out;
}
body.is-fullscreen.show-tools header {
    transform: translateY(0);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
body.is-fullscreen.show-tools #tuner-panel,
body.is-fullscreen.show-tools #floating-clock,
body.is-fullscreen.show-tools #hidden-page-warning,
body.is-fullscreen.show-tools #visual-metronome {
    margin-top: 115px;
}
#tuner-panel, #floating-clock, #hidden-page-warning {
    transition: margin-top 0.3s ease-in-out;
}
body.is-fullscreen #canvas-wrapper {
    padding: 10px; 
}

/* Premium Interface Themes via CSS Variables */
:root {
    --dark-bg-base: #09090b; /* Zinc 950 */
    --dark-bg-surface: #18181b; /* Zinc 900 */
    --dark-bg-hover: #27272a; /* Zinc 800 */
    --dark-border: #27272a;
    --dark-border-strong: #3f3f46;
    --dark-text-main: #f4f4f5; /* Zinc 100 */
    --dark-text-muted: #a1a1aa; /* Zinc 400 */
    
    --sepia-bg-base: #f4ecd8;
    --sepia-bg-surface: #fbf6ec;
    --sepia-bg-hover: #e4d8c0;
    --sepia-border: #e4d8c0;
    --sepia-border-strong: #d1c0a5;
    --sepia-text-main: #433422;
    --sepia-text-muted: #786854;
}

/* Dark Mode Overrides */
body.theme-dark { color: var(--dark-text-main) !important; background-color: var(--dark-bg-base) !important; }
body.theme-dark .bg-white, body.theme-dark .bg-slate-50, body.theme-dark .bg-slate-100 { background-color: var(--dark-bg-surface) !important; border-color: var(--dark-border) !important; }
body.theme-dark .bg-slate-200 { background-color: var(--dark-bg-hover) !important; border-color: var(--dark-border-strong) !important; }
body.theme-dark #main-content { background-color: var(--dark-bg-base) !important; }
body.theme-dark .text-slate-800, body.theme-dark .text-slate-700, body.theme-dark .text-slate-600 { color: var(--dark-text-main) !important; }
body.theme-dark .text-slate-500, body.theme-dark .text-slate-400 { color: var(--dark-text-muted) !important; }
body.theme-dark #pdf-canvas { filter: invert(1) hue-rotate(180deg) brightness(85%); }
body.theme-dark .hover\:bg-slate-100:hover, body.theme-dark .hover\:bg-slate-50:hover, body.theme-dark .hover\:bg-white:hover, body.theme-dark .hover\:bg-slate-200:hover { background-color: var(--dark-bg-hover) !important; }
body.theme-dark input:not([type="color"]):not([type="range"]):not([type="checkbox"]), body.theme-dark select, body.theme-dark textarea { background-color: var(--dark-bg-base) !important; color: var(--dark-text-main) !important; border-color: var(--dark-border-strong) !important; }
body.theme-dark .border-slate-200, body.theme-dark .border-slate-300, body.theme-dark .border-slate-100 { border-color: var(--dark-border) !important; }
body.theme-dark .tool-btn.active { background-color: rgba(99, 102, 241, 0.2) !important; color: #818cf8 !important; border-color: #6366f1 !important; }
body.theme-dark .tool-btn.active-ocr { background-color: rgba(16, 185, 129, 0.2) !important; color: #34d399 !important; border-color: #10b981 !important; }
body.theme-dark .glass-panel { background: rgba(24, 24, 27, 0.85) !important; border-color: rgba(255, 255, 255, 0.05) !important; box-shadow: var(--tw-shadow-glass-dark) !important; }

/* Sepia Mode Overrides */
body.theme-sepia { color: var(--sepia-text-main) !important; background-color: var(--sepia-bg-base) !important; }
body.theme-sepia .bg-white, body.theme-sepia .bg-slate-50, body.theme-sepia .bg-slate-100 { background-color: var(--sepia-bg-surface) !important; border-color: var(--sepia-border) !important; }
body.theme-sepia .bg-slate-200 { background-color: var(--sepia-bg-hover) !important; border-color: var(--sepia-border-strong) !important; }
body.theme-sepia #main-content { background-color: var(--sepia-bg-base) !important; }
body.theme-sepia .text-slate-800, body.theme-sepia .text-slate-700, body.theme-sepia .text-slate-600 { color: var(--sepia-text-main) !important; }
body.theme-sepia .text-slate-500, body.theme-sepia .text-slate-400 { color: var(--sepia-text-muted) !important; }
body.theme-sepia #pdf-canvas { filter: sepia(0.35) contrast(0.95) brightness(0.95); }
body.theme-sepia .hover\:bg-slate-100:hover, body.theme-sepia .hover\:bg-slate-50:hover, body.theme-sepia .hover\:bg-white:hover, body.theme-sepia .hover\:bg-slate-200:hover { background-color: var(--sepia-bg-hover) !important; }
body.theme-sepia input:not([type="color"]):not([type="range"]):not([type="checkbox"]), body.theme-sepia select, body.theme-sepia textarea { background-color: var(--sepia-bg-base) !important; color: var(--sepia-text-main) !important; border-color: var(--sepia-border-strong) !important; }
body.theme-sepia .border-slate-200, body.theme-sepia .border-slate-300, body.theme-sepia .border-slate-100 { border-color: var(--sepia-border) !important; }
body.theme-sepia .glass-panel { background: rgba(251, 246, 236, 0.85) !important; border-color: rgba(228, 216, 192, 0.5) !important; box-shadow: var(--tw-shadow-glass) !important; }

/* Dark mode specific button background fixes */
body.theme-dark .bg-indigo-50, body.theme-dark .bg-red-50, body.theme-dark .bg-blue-50, body.theme-dark .bg-purple-50, body.theme-dark .bg-emerald-50, body.theme-dark .bg-amber-50 { background-color: var(--dark-bg-surface) !important; border-color: var(--dark-border-strong) !important; }
body.theme-dark .hover\:bg-indigo-100:hover, body.theme-dark .hover\:bg-red-100:hover, body.theme-dark .hover\:bg-blue-100:hover, body.theme-dark .hover\:bg-purple-100:hover, body.theme-dark .hover\:bg-emerald-100:hover, body.theme-dark .hover\:bg-amber-100:hover { background-color: var(--dark-bg-hover) !important; }
body.theme-dark .text-indigo-600, body.theme-dark .text-indigo-800 { color: #818cf8 !important; }
body.theme-dark .text-red-500, body.theme-dark .text-red-700 { color: #f87171 !important; }
body.theme-dark .text-blue-600, body.theme-dark .text-blue-800 { color: #60a5fa !important; }
body.theme-dark .text-purple-600, body.theme-dark .text-purple-700 { color: #c084fc !important; }
body.theme-dark .text-emerald-600, body.theme-dark .text-emerald-700 { color: #34d399 !important; }
body.theme-dark .text-amber-600, body.theme-dark .text-amber-700 { color: #fbbf24 !important; }

body.theme-sepia .bg-indigo-50, body.theme-sepia .bg-red-50, body.theme-sepia .bg-blue-50, body.theme-sepia .bg-purple-50, body.theme-sepia .bg-emerald-50, body.theme-sepia .bg-amber-50 { background-color: var(--sepia-bg-surface) !important; border-color: var(--sepia-border-strong) !important; }
body.theme-sepia .hover\:bg-indigo-100:hover, body.theme-sepia .hover\:bg-red-100:hover, body.theme-sepia .hover\:bg-blue-100:hover, body.theme-sepia .hover\:bg-purple-100:hover, body.theme-sepia .hover\:bg-emerald-100:hover, body.theme-sepia .hover\:bg-amber-100:hover { background-color: var(--sepia-bg-hover) !important; }

/* Theme overrides for Toggle Switches */
body.theme-dark input[type="checkbox"].peer:not(:checked) + div { background-color: #475569 !important; }
body.theme-dark input[type="checkbox"].peer:checked + div { background-color: #3b82f6 !important; }
body.theme-dark input[type="checkbox"].peer + div::after { background-color: #94a3b8 !important; border-color: #94a3b8 !important; }
body.theme-dark input[type="checkbox"].peer:checked + div::after { background-color: #ffffff !important; border-color: #ffffff !important; }

body.theme-sepia input[type="checkbox"].peer:not(:checked) + div { background-color: #d1c0a5 !important; }
body.theme-sepia input[type="checkbox"].peer:checked + div { background-color: #3b82f6 !important; }
body.theme-sepia input[type="checkbox"].peer + div::after { background-color: #fbf6ec !important; border-color: #d1c0a5 !important; }
body.theme-sepia input[type="checkbox"].peer:checked + div::after { background-color: #ffffff !important; border-color: #ffffff !important; }

/* --- ChordPro Syntax Highlighting Styles --- */
.chordpro-sync {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.875rem; 
    line-height: 1.5;
    padding: 0.75rem; 
    margin: 0;
    border: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 4;
}
#chordProHighlight { color: #1e293b; -ms-overflow-style: none; scrollbar-width: none; overflow: hidden; }
#chordProHighlight::-webkit-scrollbar { display: none; }
#chordProTextarea { color: transparent !important; background: transparent !important; caret-color: #0f172a; overflow-y: auto; }
.cp-directive { color: #059669; font-weight: bold; } 
.cp-chord { color: #2563eb; font-weight: bold; } 

body.theme-dark #chordProHighlight { color: #f1f5f9 !important; }
body.theme-dark #chordProTextarea { caret-color: #f1f5f9; }
body.theme-dark .cp-directive { color: #34d399; } 
body.theme-dark .cp-chord { color: #60a5fa; } 

body.theme-sepia #chordProHighlight { color: #433422 !important; }
body.theme-sepia #chordProTextarea { caret-color: #433422; }

/* Neon Glow logo animation */
@keyframes neon-glow {
    0%, 100% { 
        filter: drop-shadow(0 0 4px rgba(34, 211, 238, 0.4)) hue-rotate(0deg); 
    }
    33% { 
        filter: drop-shadow(0 0 10px rgba(34, 211, 238, 0.8)) hue-rotate(25deg); 
    }
    66% { 
        filter: drop-shadow(0 0 8px rgba(167, 139, 250, 0.6)) hue-rotate(-20deg); 
    }
}
.animate-neon-glow {
    animation: neon-glow 4s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    will-change: filter;
    display: inline-block;
}

/* --- UX Enhancements: Micro-animations --- */
@keyframes popIn {
    0% { opacity: 0; transform: scale(0.95) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.35); }
    70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
@keyframes bounce-subtle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
@keyframes slide-up-fade {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

.tool-dropdown:not(.hidden) {
    animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform-origin: top center;
}

#text-format-panel:not(.hidden) {
    animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#library-modal > div, #pco-modal > div, #chordpro-editor-modal > div, #remote-modal > div, #settings-modal > div, #incoming-project-modal > div, #page-manager-modal > div, #confirm-modal > div {
    animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#library-modal:not(.hidden), #pco-modal:not(.hidden), #chordpro-editor-modal:not(.hidden), #remote-modal:not(.hidden), #settings-modal:not(.hidden), #incoming-project-modal:not(.hidden), #page-manager-modal:not(.hidden), #confirm-modal:not(.hidden) {
    animation: fadeIn 0.2s ease-out forwards;
}

/* --- Drag-over drop zone highlight --- */
body.drag-over #empty-state-main {
    border: 2.5px dashed #3b82f6;
    border-radius: 1rem;
    background: rgba(59, 130, 246, 0.05);
}
body.drag-over #empty-state-main i {
    color: #3b82f6 !important;
    animation: bounce-subtle 0.8s ease-in-out infinite;
}
/* Drop overlay covering full main area */
#drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    background: rgba(59, 130, 246, 0.08);
    border: 3px dashed #3b82f6;
    border-radius: 1rem;
    margin: 16px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
}
body.drag-over #drop-overlay { opacity: 1; pointer-events: none; }

/* --- Toast dismiss button --- */
.toast-dismiss {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0 0 0 8px;
    opacity: 0.7;
    transition: opacity 0.15s;
    line-height: 1;
    color: inherit;
    flex-shrink: 0;
}
.toast-dismiss:hover { opacity: 1; }

/* --- Toast progress bar --- */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255,255,255,0.4);
    border-radius: 0 0 8px 8px;
    animation: toast-shrink 4s linear forwards;
    width: 100%;
}
@keyframes toast-shrink {
    from { width: 100%; }
    to { width: 0%; }
}

/* --- Fullscreen tap-zone hint --- */
#fullscreen-hint {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 105;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15,23,42,0.65);
    color: #94a3b8;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
    white-space: nowrap;
}
body.is-fullscreen #fullscreen-hint.visible { opacity: 1; }

/* --- Sidebar active item pulse --- */
#pdf-list li.active-item {
    animation: pulse-ring 2s ease-out;
}

/* --- Sidebar item slide-in on add --- */
#pdf-list li.list-item-enter {
    animation: slide-up-fade 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* --- Kbd shortcut chips in tooltips / UI --- */
kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: ui-monospace, monospace;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    border: 1px solid #cbd5e1;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #f8fafc;
    color: #475569;
    white-space: nowrap;
}
