/* CSS Variables - Modern Design System */
:root {
    /* Primary Colors - Gradient Blue-Purple (Indigo) */
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    
    /* Accent Color - Purple */
    --accent-400: #a78bfa;
    --accent-500: #8b5cf6;
    --accent-600: #7c3aed;
    
    /* Legacy primary colors (for backward compatibility) */
    --primary-color: var(--primary-500);
    --primary-hover: var(--primary-600);
    
    /* Neutrals - Warm Gray */
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --gray-900: #171717;
    
    /* Legacy colors mapping */
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background-color: var(--gray-50);
    --surface-color: #ffffff;
    --border-color: var(--gray-200);
    --text-primary: var(--gray-800);
    --text-secondary: var(--gray-600);
    --text-muted: var(--gray-400);
    
    /* Semantic Colors */
    --success-color: #10b981;
    --success-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    
    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    
    /* Shadows - Multiple levels */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Legacy radius mapping */
    --radius-sm-legacy: 4px;
    --radius-md-legacy: 8px;
    --radius-lg-legacy: 12px;
    
    /* Transitions */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 60px;
    --header-height: 60px;
    --toolbar-height: 48px;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary-400: #a5b4fc;
    --primary-500: #818cf8;
    --primary-600: #6366f1;
    
    --accent-400: #c4b5fd;
    --accent-500: #a78bfa;
    
    --gray-50: #18181b;
    --gray-100: #27272a;
    --gray-200: #3f3f46;
    --gray-300: #52525b;
    --gray-400: #71717a;
    --gray-500: #a1a1aa;
    --gray-600: #d4d4d8;
    --gray-700: #e4e4e7;
    --gray-800: #f4f4f5;
    --gray-900: #fafafa;
    
    --background-color: #09090b;
    --surface-color: #18181b;
    --border-color: #27272a;
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    
    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    touch-action: manipulation;
    overscroll-behavior: contain;
}

/* Smooth scrolling for touch */
@media (pointer: coarse) {
    html {
        scroll-behavior: smooth;
    }
    
    /* Improve touch scrolling */
    .sidebar,
    .pdf-container {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Larger touch targets for coarse pointers */
    .tool-btn,
    .btn,
    .toolbar-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Prevent text selection on touch */
    .tool-btn,
    .btn,
    .sidebar-section {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Touch action improvements */
.canvas-wrapper {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Improve modal touch experience */
.modal {
    touch-action: manipulation;
}

.modal-content {
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    gap: 10px;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-primary);
    flex-shrink: 0;
}

.menu-toggle:hover {
    background: var(--background-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    flex: 1;
    min-width: 0;
}

.logo span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Theme Toggle Button */
.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--gray-100);
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--gray-200);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle svg {
    position: absolute;
    transition: var(--transition-slow);
}

.sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
    color: var(--warning-color);
}

.moon-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0);
    color: var(--accent-500);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="dark"] .theme-toggle {
    background: var(--gray-800);
}

[data-theme="dark"] .theme-toggle:hover {
    background: var(--gray-700);
}

/* Buttons - Enhanced Modern Style */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn:focus {
    outline: 2px solid var(--primary-400);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-400) 0%, var(--primary-500) 100%);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color) 0%, var(--success-hover) 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.btn-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #34d399 0%, var(--success-color) 100%);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-hover) 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(100, 116, 139, 0.3);
}

.btn-secondary:hover:not(:disabled) {
    background: linear-gradient(135deg, #94a3b8 0%, var(--secondary-color) 100%);
    box-shadow: 0 4px 8px rgba(100, 116, 139, 0.4);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, var(--danger-hover) 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #f87171 0%, var(--danger-color) 100%);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

/* Dark mode button adjustments */
[data-theme="dark"] .btn-primary {
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.5);
}

[data-theme="dark"] .btn-success {
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.5);
}

[data-theme="dark"] .btn-secondary {
    box-shadow: 0 2px 8px rgba(100, 116, 139, 0.5);
}

[data-theme="dark"] .btn-danger {
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* Sidebar - Enhanced Modern Style */
.sidebar {
    width: 240px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 100;
    pointer-events: auto;
    position: relative;
    transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.sidebar-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-section h3::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

/* Collapsed sidebar state */
.sidebar.collapsed {
    width: 60px;
    padding: 12px 8px;
}

.sidebar.collapsed .sidebar-section {
    padding: 0;
    border: none;
    margin-bottom: 8px;
}

.sidebar.collapsed .sidebar-section h3,
.sidebar.collapsed .tool-buttons,
.sidebar.collapsed .text-options,
.sidebar.collapsed .color-palette,
.sidebar.collapsed .stroke-options,
.sidebar.collapsed .selection-tools,
.sidebar.collapsed .page-tools,
.sidebar.collapsed .action-buttons {
    display: none;
}

.sidebar.collapsed .tool-btn {
    width: 40px;
    height: 40px;
    padding: 8px;
}

/* Tool Buttons */
.tool-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--background-color);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

.tool-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.tool-btn:focus {
    outline: 2px solid var(--primary-400);
    outline-offset: 2px;
    background: var(--bg-tertiary);
}

.tool-btn:focus-visible {
    outline: 2px solid var(--primary-400);
    outline-offset: 2px;
}

.tool-btn.active {
    background: var(--primary-500);
    color: white;
    border-color: var(--primary-600);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.tool-btn.active:hover {
    background: var(--primary-600);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn,
    .tool-btn,
    .toolbar-btn {
        border: 2px solid currentColor;
    }
    
    .tool-btn.active {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary-400);
    outline-offset: 2px;
}

/* Skip to content link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* Screen reader only text */
.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;
}

.tool-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-hover);
}

.tool-btn span {
    font-size: 11px;
    font-weight: 500;
}

/* Tool Groups - Visual Separators */
.tool-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 8px;
}

/* Add spacing before each group */
.tool-buttons .tool-btn[data-tool="pencil"],
.tool-buttons .tool-btn[data-tool="rectangle"],
.tool-buttons .tool-btn[data-tool="text"],
.tool-buttons .tool-btn[data-tool="comment"] {
    margin-top: 8px;
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.custom-color {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.custom-color label {
    font-size: 12px;
    color: var(--text-secondary);
}

.custom-color input[type="color"] {
    width: 40px;
    height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* Stroke Options */
.stroke-options {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stroke-options input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.stroke-options input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.stroke-options span {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 35px;
}

/* Text Options */
.text-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.text-options select,
.text-options input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--surface-color);
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}

.text-options select:focus,
.text-options input:focus {
    border-color: var(--primary-color);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-buttons .btn {
    justify-content: center;
}

/* PDF Viewer */
.pdf-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--background-color);
}

/* Upload Area */
.upload-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    cursor: pointer;
    z-index: 10;
    position: relative;
    pointer-events: auto;
}

.upload-content {
    text-align: center;
    padding: 60px;
    border: 3px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--surface-color);
    transition: var(--transition);
    cursor: pointer;
}

.upload-content:hover {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

.upload-content svg {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.upload-content h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* PDF Container */
.pdf-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* PDF Toolbar - Enhanced Modern Style */
.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
}

.toolbar-btn:hover {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.toolbar-btn:active {
    transform: translateY(0);
}

.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.toolbar-btn:disabled:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Page indicator */
.pdf-toolbar .page-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 120px;
    justify-content: center;
}

.pdf-toolbar .page-info input {
    width: 50px;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 14px;
    background: var(--surface-color);
    color: var(--text-primary);
}

/* Zoom controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.zoom-controls .toolbar-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
}

.zoom-controls .zoom-level {
    min-width: 50px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.toolbar-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.close-btn {
    margin-left: auto;
    color: var(--danger-color);
}

.close-btn:hover {
    background: #fee2e2;
    color: var(--danger-hover);
}

.page-info {
    font-size: 14px;
    color: var(--text-secondary);
    min-width: 100px;
    text-align: center;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
    padding-left: 20px;
    border-left: 1px solid var(--border-color);
}

.zoom-controls span {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
    position: relative;
    min-height: 200px;
    box-sizing: border-box;
}

.canvas-wrapper canvas {
    position: relative;
    box-shadow: var(--shadow-lg);
    margin: auto;
}

#pdfCanvas {
    z-index: 1;
    background: white;
    position: absolute;
    top: 0;
    left: 0;
}

#annotationCanvas {
    z-index: 2;
    cursor: crosshair;
    background: transparent;
    position: absolute;
    top: 0;
    left: 0;
}

/* Pan cursor when using select tool */
.select-pan #annotationCanvas {
    cursor: grab;
}

.select-pan #annotationCanvas:active {
    cursor: grabbing;
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}

/* Modal - Enhanced Modern Style */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content {
    background: var(--surface-color);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 400px;
    position: relative;
    animation: scaleIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .modal-content {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-color);
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--border-color);
}

.modal-content h3 {
    margin-bottom: 16px;
    font-size: 1.125rem;
}

.modal-content textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: var(--transition);
}

.modal-content textarea:focus {
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Pulse animation for loading */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Skeleton loading animation */
@keyframes skeleton-loading {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Bounce animation for interactive elements */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

/* Shake animation for errors */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Enhanced loading spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: relative;
}

.spinner::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 3px solid transparent;
    border-top-color: var(--accent-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite reverse;
}

/* Pulse effect on buttons */
.btn.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Shake on error input */
input.error,
select.error {
    animation: shake 0.4s ease-in-out;
    border-color: var(--danger-color);
}

/* Toast/Notification Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Notification Toast Styles */
.notification {
    position: fixed;
    bottom: 70px;
    right: 20px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 320px;
    word-wrap: break-word;
}

.notification.success {
    background: var(--success-color);
    border-left: 4px solid #34d399;
}

.notification.error {
    background: var(--danger-color);
    border-left: 4px solid #f87171;
}

.notification.warning {
    background: var(--warning-color);
    border-left: 4px solid #fbbf24;
}

.notification.info {
    background: var(--info-color);
    border-left: 4px solid #60a5fa;
}

/* Dark mode notification adjustments */
[data-theme="dark"] .notification {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .notification.success {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
}

[data-theme="dark"] .notification.error {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
}

.loading-overlay p {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }

    .tool-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .color-palette {
        grid-template-columns: repeat(4, 1fr);
    }

    .app-header {
        padding: 10px 16px;
    }

    .logo {
        font-size: 1rem;
    }

    .logo svg {
        width: 24px;
        height: 24px;
    }

    .header-actions .btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .header-actions .btn svg {
        width: 14px;
        height: 14px;
    }
}

/* Responsive - Mobile */
@media (max-width: 640px) {
    .menu-toggle {
        display: flex;
    }

    /* Show sidebar by default on mobile - tools always visible */
    .sidebar {
        position: fixed;
        left: 0;
        top: 56px;
        bottom: 0;
        width: 200px;
        z-index: 50;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: var(--surface-color);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-backdrop {
        display: none;
    }

    /* Adjust main content to account for sidebar */
    .main-content {
        margin-left: 200px;
    }

    .app-header {
        padding: 8px 12px;
        min-height: 56px;
    }

    .logo {
        font-size: 0.95rem;
        gap: 6px;
    }

    .logo svg {
        width: 22px;
        height: 22px;
    }

    .logo span {
        max-width: 120px;
    }

    .header-actions {
        gap: 4px;
    }

    .header-actions .btn {
        padding: 8px 10px;
        font-size: 12px;
        border-radius: 6px;
    }

    .header-actions .btn svg {
        display: none;
    }

    .header-actions .btn span {
        display: none;
    }

    /* Show text only on Import button */
    .header-actions #importBtn span,
    .header-actions #saveBtn span,
    .header-actions #exportBtn span,
    .header-actions #printBtn span {
        display: inline;
    }

    /* Hide Print button text on mobile to save space */
    .header-actions #printBtn span {
        display: none;
    }

    /* Make Print button smaller icon only */
    .header-actions #printBtn {
        padding: 8px;
        min-width: 36px;
    }

    /* Sidebar sections improvements */
    .sidebar-section {
        margin-bottom: 16px;
    }

    .sidebar-section h3 {
        font-size: 11px;
        margin-bottom: 8px;
    }

    /* Tool buttons - larger touch targets */
    .tool-buttons {
        gap: 6px;
        padding: 6px;
    }

    .tool-btn {
        padding: 14px 8px;
        min-height: 60px;
    }

    .tool-btn svg {
        width: 24px;
        height: 24px;
    }

    .tool-btn span {
        font-size: 10px;
    }

    /* Color palette */
    .color-palette {
        gap: 6px;
    }

    .color-btn {
        min-height: 36px;
    }

    /* Custom color */
    .custom-color {
        padding-top: 10px;
        margin-top: 10px;
    }

    .custom-color input[type="color"] {
        width: 50px;
        height: 36px;
    }

    /* Stroke options */
    .stroke-options input[type="range"] {
        height: 8px;
    }

    .stroke-options input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    /* Text options */
    .text-options select,
    .text-options input {
        padding: 10px 12px;
        font-size: 14px;
    }

    /* Action buttons */
    .action-buttons .btn {
        padding: 12px 16px;
        font-size: 13px;
    }

    /* PDF Toolbar */
    .pdf-toolbar {
        gap: 8px;
        padding: 8px 12px;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .toolbar-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .toolbar-btn svg {
        width: 20px;
        height: 20px;
    }

    .page-info {
        font-size: 13px;
        min-width: auto;
        order: 3;
        width: 100%;
        text-align: center;
        padding: 4px 0;
    }

    .zoom-controls {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        gap: 6px;
    }

    .zoom-controls span {
        font-size: 12px;
        min-width: 40px;
    }

    .close-btn {
        margin-left: 0;
    }

    /* Canvas wrapper */
    .canvas-wrapper {
        padding: 10px;
    }

    /* Upload area */
    .upload-area {
        padding: 20px;
    }

    .upload-content {
        padding: 30px 20px;
    }

    .upload-content svg {
        width: 48px;
        height: 48px;
    }

    .upload-content h2 {
        font-size: 1rem;
    }

    .upload-content p {
        font-size: 13px;
    }

    /* Status bar */
    .status-bar {
        padding: 6px 12px;
        font-size: 12px;
    }

    /* Modal */
    .modal-content {
        padding: 20px;
        margin: 16px;
        width: calc(100% - 32px);
    }

    .modal-content h3 {
        font-size: 1rem;
    }

    .modal-content textarea {
        padding: 10px;
        font-size: 14px;
        min-height: 100px;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }

    /* Loading overlay */
    .loading-overlay {
        padding: 20px;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    .loading-overlay p {
        font-size: 13px;
    }
}

/* Floating Action Button for Mobile */
.fab-container {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 900;
    flex-direction: column;
    gap: 12px;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

.fab:active {
    transform: scale(0.95);
}

.fab svg {
    width: 24px;
    height: 24px;
}

.fab-secondary {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-hover) 100%);
}

.fab-label {
    position: absolute;
    right: 100%;
    margin-right: 12px;
    background: var(--gray-900);
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.fab:hover .fab-label {
    opacity: 1;
}

@media (max-width: 768px) {
    .fab-container {
        display: flex;
    }
    
    /* Hide less important buttons on mobile header */
    .header-actions #printBtn,
    .header-actions #exportBtn {
        display: none;
    }
    
    /* Increase touch targets for better mobile experience */
    .tool-btn {
        min-height: 56px;
    }
    
    /* Better mobile modal */
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 16px;
        padding: 20px;
    }
}

/* Bottom Sheet for Mobile */
.bottom-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-color);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-2xl);
    z-index: 950;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 70vh;
    overflow-y: auto;
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--surface-color);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--gray-300);
    border-radius: 2px;
    margin: 0 auto 12px;
}

.bottom-sheet-content {
    padding: 20px;
}

@media (max-width: 768px) {
    .bottom-sheet {
        display: block;
    }
}

/* Extra small screens */
@media (max-width: 380px) {
    .header-actions .btn-primary span,
    .header-actions .btn-success span,
    .header-actions .btn-secondary span {
        display: none;
    }

    .logo span {
        max-width: 80px;
    }

    .pdf-toolbar {
        justify-content: center;
    }

    .zoom-controls {
        display: none;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .app-container {
        height: 100vh;
    }

    .sidebar {
        top: 50px;
    }

    .canvas-wrapper {
        padding: 8px;
    }

    .upload-content {
        padding: 20px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .tool-btn,
    .btn,
    .toolbar-btn,
    .color-btn {
        -webkit-transform: translateZ(0);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #0f172a;
        --surface-color: #1e293b;
        --border-color: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .app-header,
    .sidebar,
    .pdf-toolbar,
    .status-bar {
        display: none;
    }

    .pdf-viewer {
        display: block;
    }

    .canvas-wrapper {
        padding: 0;
    }
}

/* Selection Tools */
.selection-tools,
.page-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Image Preview */
.image-preview {
    width: 100%;
    min-height: 100px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    overflow: hidden;
}

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
}

.image-preview:empty::before {
    content: 'No image selected';
    color: var(--text-muted);
}

/* Page List */
.page-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.page-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.page-item:hover {
    background: var(--background-color);
}

.page-item.active {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

.page-item .page-number {
    font-weight: 500;
}

.page-item .page-actions {
    display: flex;
    gap: 8px;
}

.page-item .page-actions button {
    padding: 4px 8px;
    font-size: 12px;
}

/* Selection Handles */
.selection-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 2px;
    z-index: 100;
    cursor: pointer;
}

.selection-handle.nw { cursor: nw-resize; }
.selection-handle.ne { cursor: ne-resize; }
.selection-handle.sw { cursor: sw-resize; }
.selection-handle.se { cursor: se-resize; }
.selection-handle.n { cursor: n-resize; }
.selection-handle.s { cursor: s-resize; }
.selection-handle.e { cursor: e-resize; }
.selection-handle.w { cursor: w-resize; }

.selection-box {
    position: absolute;
    border: 2px dashed var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    pointer-events: none;
    z-index: 99;
}

/* Form Group */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

/* Ruler Tool */
.ruler-display {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    z-index: 100;
    pointer-events: none;
}

/* Stamp Preview */
.stamp-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.stamp-option {
    width: 60px;
    height: 60px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    transition: var(--transition);
}

.stamp-option:hover {
    border-color: var(--primary-color);
    background: var(--background-color);
}

.stamp-option.selected {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

/* Image Input Styling */
#imageInput {
    margin-bottom: 16px;
}

/* Tooltip */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--text-primary);
    color: white;
    font-size: 12px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.tooltip:hover::after {
    opacity: 1;
}

/* Multi-select */
.multi-select .selection-box {
    border-color: var(--success-color);
    background: rgba(22, 163, 74, 0.1);
}

.multi-select .selection-handle {
    background: var(--success-color);
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 150px;
    z-index: 1000;
    overflow: hidden;
}

.context-menu.hidden {
    display: none;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
}

.context-menu-item:hover {
    background: var(--background-color);
}

.context-menu-item.danger {
    color: var(--danger-color);
}

.context-menu-item.danger:hover {
    background: rgba(220, 38, 38, 0.1);
}

.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-menu.hidden {
    display: none;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text-primary);
    text-align: left;
}

.dropdown-item:hover {
    background: var(--background-color);
}

.dropdown-item svg {
    flex-shrink: 0;
}

.dropdown-item:active {
    background: var(--border-color);
}

/* Page Manager Toolbar Dropdown */
.page-manager-toolbar .dropdown {
    display: inline-block;
}

.page-manager-toolbar .dropdown .btn {
    position: relative;
}

/* Tool Dropdown Styles */
.tool-dropdown {
    position: relative;
    display: inline-block;
}

.tool-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-dropdown-btn .dropdown-arrow {
    font-size: 10px;
    margin-left: 2px;
}

.tool-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100;
    min-width: 160px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    margin-top: 4px;
}

.tool-dropdown:hover .tool-dropdown-content,
.tool-dropdown.active .tool-dropdown-content {
    display: block;
}

.tool-dropdown-content .tool-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.tool-dropdown-content .tool-btn:hover {
    background: var(--background-color);
}

.tool-dropdown-content .tool-btn span {
    font-size: 13px;
}
