/* Drawing Canvas Styles */
/* Drawing overlay, toolbar, and drawing-related UI elements */

.drawing-annotation-file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

/* Drawing Overlay — artboard-style surface */
.drawing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ffffff;
    z-index: 100200;
    display: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.drawing-canvas {
    position: absolute;
    /* width / height / left / top are set by JS to maintain 11:8 ratio centered in viewport */
    cursor: crosshair;
    touch-action: none;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 2px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.14);
}

/* Drawing Toolbar — single horizontal row; scrolls on very narrow viewports */
.drawing-toolbar {
    position: fixed;
    top: max(10px, env(safe-area-inset-top, 10px));
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100vw - 12px);
    background: rgba(255, 255, 255, 0.97);
    border-radius: 10px;
    padding: 5px 6px;
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0;
    justify-content: flex-start;
    z-index: 10000;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.drawing-toolbar::-webkit-scrollbar {
    height: 5px;
}

.drawing-toolbar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 3px;
}

.drawing-view-group .drawing-zoom-label {
    font-size: 10px;
    font-weight: 700;
    color: #64748b;
    min-width: 2.25rem;
    text-align: center;
    user-select: none;
    line-height: 1;
}

.drawing-zoom-btn {
    min-width: 26px;
    width: 26px;
    height: 28px;
    padding: 0;
    font-weight: 700;
    font-size: 13px;
}

.tool-group {
    display: flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 3px;
    padding: 0 5px;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.tool-group:last-child {
    border-right: none;
    padding-right: 3px;
}

.tool-group:first-child {
    padding-left: 3px;
}

/* Tool Buttons */
.tool-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    border: 2px solid transparent;
    flex-shrink: 0;
}

.tool-btn:hover {
    background: rgba(102, 126, 234, 0.1);
}

.tool-btn.active {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
    color: #667eea;
}

/* Action Buttons */
.action-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.action-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.action-btn[data-action="clear"]:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Mode Toggle (inline in toolbar) */
.mode-toggle {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: rgba(102, 126, 234, 0.2);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    color: #667eea;
    flex-shrink: 0;
    margin-left: 1px;
}

.mode-toggle:hover {
    background: rgba(102, 126, 234, 0.32);
}

/* Color Picker */
.color-picker {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: none;
    padding: 0;
    flex-shrink: 0;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Stroke color + swatches + width — one row */
.drawing-color-group {
    flex-wrap: nowrap;
    gap: 4px;
}

.drawing-swatch-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 2px;
    align-items: center;
}

.color-swatch {
    width: 15px;
    height: 15px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    background: var(--swatch, #000);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.color-swatch:hover {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.color-swatch.active {
    border-color: #667eea;
    box-shadow: 0 0 0 1.5px rgba(102, 126, 234, 0.45);
}

/* Brush Size Slider */
.brush-size {
    width: 52px;
    height: 4px;
    border-radius: 2px;
    background: #e5e7eb;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    flex-shrink: 0;
}

.brush-size::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.brush-size::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.brush-size-label {
    font-size: 9px;
    font-weight: 600;
    color: #6b7280;
    min-width: 22px;
    text-align: center;
    line-height: 1;
    flex-shrink: 0;
}

/* Mode Toggle Button (Main Canvas) */
.mode-toggle-btn {
    position: fixed;
    bottom: 20px;
    left: 80px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    z-index: 1000;
}

.mode-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.15);
}

/* Drawing Mode Indicators */
.drawing-mode-indicator {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 10000;
    animation: slideInRight 0.3s ease;
}

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

/* Drawing Block Type */
.content-block.drawing {
    background: rgba(255, 255, 255, 0.95);
    border-left: 4px solid #8b5cf6;
}

.content-block.drawing::before {
    content: "🎨";
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 12px;
    opacity: 0.7;
}

/* Drawing Tools Panel */
.drawing-tools-panel {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tool-panel-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-panel-group h4 {
    margin: 0;
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Drawing Canvas Grid */
.drawing-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    opacity: 0.3;
}

.drawing-grid.active {
    opacity: 0.5;
}

/* Drawing Rulers */
.drawing-ruler-h {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 10px;
    color: #6b7280;
}

.drawing-ruler-v {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    font-size: 10px;
    color: #6b7280;
}

/* Drawing Status Bar */
.drawing-status-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 10000;
    display: flex;
    gap: 16px;
    align-items: center;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-label {
    color: #9ca3af;
}

.status-value {
    font-weight: 600;
}

/* Drawing Mini-map */
.drawing-minimap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 150px;
    height: 100px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.minimap-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Drawing Layer Panel */
.drawing-layer-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    min-width: 200px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.layer-item:hover {
    background: rgba(102, 126, 234, 0.1);
}

.layer-item.active {
    background: rgba(102, 126, 234, 0.2);
}

.layer-visibility {
    width: 16px;
    height: 16px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    cursor: pointer;
}

.layer-visibility.visible {
    background: #667eea;
    border-color: #667eea;
}

/* Drawing Responsive Design */
@media (max-width: 768px) {
    .drawing-toolbar {
        top: max(10px, env(safe-area-inset-top, 10px));
        left: max(10px, env(safe-area-inset-left, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
        transform: none;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
        overflow-x: visible;
    }

    .tool-group {
        padding: 0 4px;
        border-right: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.1);
        padding-bottom: 8px;
    }

    .tool-group:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .tool-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
        touch-action: manipulation;
    }

    .action-btn {
        width: 44px;
        height: 44px;
        font-size: 16px;
        touch-action: manipulation;
    }

    .drawing-zoom-btn {
        width: 44px;
        height: 44px;
        font-size: 15px;
        touch-action: manipulation;
    }

    .color-swatch {
        width: 22px;
        height: 22px;
        /* Expand touch target with transparent padding */
        padding: 11px;
        box-sizing: content-box;
    }

    .mode-toggle-btn {
        bottom: max(15px, env(safe-area-inset-bottom, 15px));
        left: max(15px, env(safe-area-inset-left, 15px));
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    /* Side panels hidden on mobile — use bottom sheet (#drawingPanelSheet) instead */
    .drawing-tools-panel,
    .drawing-layer-panel {
        display: none;
    }

    .drawing-status-bar {
        bottom: max(10px, env(safe-area-inset-bottom, 10px));
        left: max(10px, env(safe-area-inset-left, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
        transform: none;
        font-size: 11px;
    }

    .drawing-minimap {
        bottom: max(10px, env(safe-area-inset-bottom, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
        width: 120px;
        height: 80px;
    }
}

/* Touch active states for drawing buttons */
.tool-btn:active {
    background: rgba(102, 126, 234, 0.2);
}
.action-btn:active {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}
.action-btn[data-action="clear"]:active {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Bottom sheet for drawing tools on mobile */
.drawing-panel-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100300;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    padding: 12px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    transform: translateY(100%);
    transition: transform 0.28s ease;
    backdrop-filter: blur(12px);
}

.drawing-panel-sheet.open {
    display: block;
    transform: translateY(0);
}

.drawing-panel-sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 2px;
    margin: 0 auto 12px;
}

.drawing-panel-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100299;
    background: rgba(0, 0, 0, 0.3);
}

.drawing-panel-sheet-backdrop.open {
    display: block;
}

.drawing-sheet-trigger {
    display: none;
}

@media (max-width: 768px) {
    .drawing-sheet-trigger {
        display: flex;
    }
}

/* Dark Theme Support for Drawing */
@media (prefers-color-scheme: dark) {
    .drawing-overlay {
        background: rgba(17, 24, 39, 0.95);
    }
    
    .drawing-toolbar {
        background: rgba(31, 41, 55, 0.95);
        border-color: rgba(75, 85, 99, 0.3);
    }
    
    .tool-btn,
    .action-btn {
        background: rgba(55, 65, 81, 0.8);
        color: #d1d5db;
    }
    
    .tool-btn:hover {
        background: rgba(102, 126, 234, 0.2);
    }
    
    .tool-btn.active {
        background: rgba(102, 126, 234, 0.3);
        border-color: #667eea;
        color: #667eea;
    }
    
    .action-btn:hover {
        background: rgba(16, 185, 129, 0.2);
        color: #10b981;
    }
    
    .mode-toggle {
        background: rgba(102, 126, 234, 0.3);
        color: #667eea;
    }
    
    .mode-toggle:hover {
        background: rgba(102, 126, 234, 0.4);
    }
    
    .brush-size {
        background: #4b5563;
    }
    
    .brush-size-label {
        color: #9ca3af;
    }
    
    .drawing-tools-panel,
    .drawing-layer-panel {
        background: rgba(31, 41, 55, 0.95);
        border-color: rgba(75, 85, 99, 0.3);
    }
    
    .drawing-status-bar {
        background: rgba(0, 0, 0, 0.9);
    }
    
    .drawing-minimap {
        background: rgba(31, 41, 55, 0.9);
        border-color: rgba(75, 85, 99, 0.3);
    }
    
    .layer-item:hover {
        background: rgba(102, 126, 234, 0.2);
    }
    
    .layer-item.active {
        background: rgba(102, 126, 234, 0.3);
    }
    
    .layer-visibility {
        border-color: #4b5563;
    }
}

/* Accessibility Improvements for Drawing */
@media (prefers-reduced-motion: reduce) {
    .drawing-toolbar,
    .tool-btn,
    .action-btn,
    .mode-toggle,
    .mode-toggle-btn {
        transition: none;
    }
    
    .drawing-mode-indicator {
        animation: none;
    }
}

/* High Contrast Mode for Drawing */
@media (prefers-contrast: high) {
    .drawing-toolbar {
        border-width: 2px;
    }
    
    .tool-btn,
    .action-btn {
        border: 1px solid #000;
    }
    
    .tool-btn.active {
        border-width: 2px;
    }
    
    .drawing-grid {
        opacity: 0.7;
    }
}

/* Print Styles for Drawing */
@media print {
    .drawing-overlay {
        position: static;
        background: white;
    }
    
    .drawing-toolbar,
    .mode-toggle-btn,
    .drawing-tools-panel,
    .drawing-layer-panel,
    .drawing-status-bar,
    .drawing-minimap {
        display: none !important;
    }
    
    .drawing-canvas {
        position: static;
        width: 100%;
        height: auto;
        max-height: 500px;
    }
}

/* Drawing Canvas Focus Indicators */
.tool-btn:focus,
.action-btn:focus,
.mode-toggle:focus,
.mode-toggle-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Drawing Canvas Loading States */
.drawing-canvas.loading {
    opacity: 0.5;
    pointer-events: none;
}

.drawing-canvas.loading::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
}

/* Drawing Canvas Error States */
.drawing-canvas.error {
    border: 2px solid #ef4444;
}

.drawing-canvas.error::after {
    content: "Drawing error";
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ef4444;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* Drawing Gallery */
.drawing-gallery {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.gallery-header h3 {
    margin: 0;
    color: #374151;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.gallery-content {
    padding: 20px;
    overflow-y: auto;
    max-height: 60vh;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.gallery-item {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
}

.gallery-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: #f3f4f6;
}

.gallery-item-info {
    padding: 12px;
}

.gallery-item-info h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #374151;
    font-weight: 600;
}

.gallery-item-info p {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gallery-item-date {
    font-size: 11px;
    color: #9ca3af;
}

/* Drawing Gallery Responsive */
@media (max-width: 768px) {
    .drawing-gallery {
        max-width: 95vw;
        max-height: 90vh;
    }
    
    .gallery-content {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
        padding: 15px;
    }
    
    .gallery-item img {
        height: 120px;
    }
    
    .gallery-item-info {
        padding: 10px;
    }
    
    .gallery-item-info h4 {
        font-size: 13px;
    }
    
    .gallery-item-info p {
        font-size: 11px;
    }
}

/* Dark Theme for Drawing Gallery */
@media (prefers-color-scheme: dark) {
    .drawing-gallery {
        background: #1f2937;
        border: 1px solid #374151;
    }
    
    .gallery-header {
        background: #111827;
        border-bottom-color: #374151;
    }
    
    .gallery-header h3 {
        color: #d1d5db;
    }
    
    .close-btn {
        color: #9ca3af;
    }
    
    .close-btn:hover {
        background: #374151;
        color: #d1d5db;
    }
    
    .gallery-item {
        background: #1f2937;
        border-color: #374151;
    }
    
    .gallery-item:hover {
        border-color: #667eea;
    }
    
    .gallery-item img {
        background: #111827;
    }
    
    .gallery-item-info h4 {
        color: #d1d5db;
    }
    
    .gallery-item-info p {
        color: #9ca3af;
    }
    
    .gallery-item-date {
        color: #6b7280;
    }
} 