/**
 * TESTIFY CANVAS SYSTEM - Ultra Premium Drawing Experience
 * =========================================================
 * Microsoft Whiteboard'un ötesinde, YKS odaklı çizim sistemi
 */

/* ═══════════════════════════════════════════════════════════════════════════
   CSS VARIABLES
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Canvas Colors */
    --canvas-bg: #ffffff;
    --canvas-grid: rgba(0, 0, 0, 0.04);
    --canvas-grid-major: rgba(0, 0, 0, 0.08);
    /* Toolbar */
    --toolbar-bg: rgba(255, 255, 255, 0.95);
    --toolbar-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    --toolbar-border: rgba(0, 0, 0, 0.06);
    /* Tools */
    --tool-active: var(--primary, #4f46e5);
    --tool-hover: rgba(79, 70, 229, 0.1);
    --tool-icon: #374151;
    /* Colors Palette */
    --ink-black: #1f2937;
    --ink-blue: #3b82f6;
    --ink-red: #ef4444;
    --ink-green: #10b981;
    --ink-purple: #8b5cf6;
    --ink-orange: #f59e0b;
    --ink-pink: #ec4899;
    --ink-cyan: #06b6d4;
    /* Brush Sizes */
    --brush-xs: 2;
    --brush-sm: 4;
    --brush-md: 8;
    --brush-lg: 16;
    --brush-xl: 32;
    /* Animation */
    --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
    --canvas-bg: #0f172a;
    --canvas-grid: rgba(255, 255, 255, 0.04);
    --canvas-grid-major: rgba(255, 255, 255, 0.08);
    --toolbar-bg: rgba(15, 23, 42, 0.95);
    --toolbar-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --toolbar-border: rgba(255, 255, 255, 0.08);
    --tool-icon: #e5e7eb;
    --ink-black: #f9fafb;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CANVAS CONTAINER
   ═══════════════════════════════════════════════════════════════════════════ */

.testify-canvas-container {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    background: var(--canvas-bg);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: all 0.3s var(--ease-out-expo);
}

    .testify-canvas-container.is-open {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
    }

    .testify-canvas-container.is-minimized {
        inset: auto 1rem 1rem auto;
        width: 320px;
        height: 240px;
        border-radius: 1rem;
        box-shadow: var(--toolbar-shadow);
        overflow: hidden;
    }

/* ═══════════════════════════════════════════════════════════════════════════
   TOP TOOLBAR
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-top-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--toolbar-border);
    z-index: 10;
}

.canvas-toolbar-left,
.canvas-toolbar-center,
.canvas-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.canvas-toolbar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.canvas-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.canvas-title-icon {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
}

/* Toolbar Buttons */
.canvas-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--tool-icon);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

    .canvas-btn:hover {
        background: var(--tool-hover);
        color: var(--tool-active);
    }

    .canvas-btn.is-active {
        background: var(--tool-active);
        color: white;
    }

    .canvas-btn:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    .canvas-btn i {
        font-size: 1.1rem;
    }

/* Button with text */
.canvas-btn-text {
    width: auto;
    padding: 0 0.75rem;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CANVAS AREA
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-main-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.canvas-wrapper {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* SVG Canvas */
#testifyDrawCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

.canvas-wrapper.is-panning #testifyDrawCanvas {
    cursor: grab;
}

.canvas-wrapper.is-panning.is-dragging #testifyDrawCanvas {
    cursor: grabbing;
}

/* Grid Background */
.canvas-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

    .canvas-grid.is-hidden {
        opacity: 0;
    }

/* ═══════════════════════════════════════════════════════════════════════════
   LEFT TOOLBAR (TOOLS)
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-tools-panel {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    box-shadow: var(--toolbar-shadow);
    border: 1px solid var(--toolbar-border);
    z-index: 5;
}

.tool-divider {
    height: 1px;
    background: var(--toolbar-border);
    margin: 0.25rem 0;
}

/* Tool Button */
.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--tool-icon);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

    .tool-btn:hover {
        background: var(--tool-hover);
        color: var(--tool-active);
        transform: scale(1.05);
    }

    .tool-btn.is-active {
        background: var(--tool-active);
        color: white;
        box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
    }

    .tool-btn i {
        font-size: 1.2rem;
    }

    /* Tool Tooltip */
    .tool-btn::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%) translateX(-4px);
        padding: 0.4rem 0.6rem;
        background: var(--bg-primary);
        color: var(--text-primary);
        font-size: 0.75rem;
        font-weight: 500;
        white-space: nowrap;
        border-radius: 6px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        opacity: 0;
        visibility: hidden;
        transition: all 0.15s ease;
        pointer-events: none;
        z-index: 100;
    }

    .tool-btn:hover::after {
        opacity: 1;
        visibility: visible;
        transform: translateY(-50%) translateX(0);
    }

/* ═══════════════════════════════════════════════════════════════════════════
   RIGHT PANEL (OPTIONS)
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-options-panel {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: var(--toolbar-shadow);
    border: 1px solid var(--toolbar-border);
    z-index: 5;
    min-width: 200px;
    max-height: 70vh;
    overflow-y: auto;
}

.options-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.options-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.35rem;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

    .color-swatch:hover {
        transform: scale(1.1);
    }

    .color-swatch.is-active {
        border-color: var(--text-primary);
        box-shadow: 0 0 0 2px var(--canvas-bg), 0 0 0 4px var(--text-primary);
    }

        .color-swatch.is-active::after {
            content: '✓';
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.9rem;
            font-weight: 700;
            color: white;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
        }

/* Custom Color Picker */
.color-picker-wrapper {
    position: relative;
}

.color-picker-btn {
    width: 100%;
    height: 32px;
    border-radius: 8px;
    border: 2px dashed var(--toolbar-border);
    background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
    cursor: pointer;
    transition: all 0.15s ease;
}

    .color-picker-btn:hover {
        border-color: var(--tool-active);
    }

.color-picker-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* Brush Size Slider */
.brush-size-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.brush-size-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    background: var(--canvas-bg);
    border-radius: 8px;
    border: 1px solid var(--toolbar-border);
}

.brush-preview-dot {
    border-radius: 50%;
    background: var(--ink-black);
    transition: all 0.1s ease;
}

.brush-size-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--toolbar-border);
    outline: none;
    cursor: pointer;
}

    .brush-size-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: var(--tool-active);
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(79, 70, 229, 0.4);
        transition: transform 0.1s ease;
    }

        .brush-size-slider::-webkit-slider-thumb:hover {
            transform: scale(1.15);
        }

.brush-size-value {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Opacity Control */
.opacity-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.opacity-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, transparent, var(--ink-black));
    outline: none;
    cursor: pointer;
}

    .opacity-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: white;
        border: 2px solid var(--tool-active);
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

.opacity-value {
    min-width: 36px;
    text-align: right;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BRUSH PRESETS
   ═══════════════════════════════════════════════════════════════════════════ */

.brush-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.brush-preset {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid var(--toolbar-border);
    border-radius: 10px;
    background: var(--canvas-bg);
    cursor: pointer;
    transition: all 0.15s ease;
}

    .brush-preset:hover {
        border-color: var(--tool-active);
        transform: scale(1.05);
    }

    .brush-preset.is-active {
        border-color: var(--tool-active);
        background: var(--tool-hover);
    }

    .brush-preset svg {
        width: 24px;
        height: 24px;
    }

/* ═══════════════════════════════════════════════════════════════════════════
   BOTTOM INFO BAR
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--toolbar-border);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.canvas-info-left,
.canvas-info-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.canvas-info-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

    .canvas-info-item i {
        font-size: 0.9rem;
        opacity: 0.7;
    }

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--canvas-bg);
    border-radius: 6px;
    padding: 0.15rem;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--tool-icon);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .zoom-btn:hover {
        background: var(--tool-hover);
        color: var(--tool-active);
    }

.zoom-value {
    min-width: 48px;
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   STROKE STYLES
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-stroke {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.canvas-stroke-filled {
    fill: currentColor;
    stroke: none;
}

/* Eraser cursor */
.eraser-cursor {
    position: fixed;
    pointer-events: none;
    border: 2px solid var(--tool-active);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    z-index: 10001;
    display: none;
}

.canvas-wrapper.eraser-active .eraser-cursor {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYERS PANEL
   ═══════════════════════════════════════════════════════════════════════════ */

.layers-panel {
    position: absolute;
    right: 1rem;
    bottom: 4rem;
    width: 200px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    box-shadow: var(--toolbar-shadow);
    border: 1px solid var(--toolbar-border);
    z-index: 5;
    display: none;
}

    .layers-panel.is-open {
        display: block;
        animation: slideUp 0.2s var(--ease-out-expo);
    }

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.layers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--toolbar-border);
}

.layers-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.layers-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
}

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

    .layer-item:hover {
        background: var(--tool-hover);
    }

    .layer-item.is-active {
        background: var(--tool-active);
        color: white;
    }

.layer-visibility {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

    .layer-visibility:hover {
        opacity: 1;
    }

.layer-name {
    flex: 1;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SHAPE RECOGNITION FEEDBACK
   ═══════════════════════════════════════════════════════════════════════════ */

.shape-recognition-hint {
    position: absolute;
    padding: 0.5rem 0.75rem;
    background: var(--tool-active);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: all 0.2s ease;
    z-index: 100;
}

    .shape-recognition-hint.is-visible {
        opacity: 1;
        transform: translateY(0);
    }

/* ═══════════════════════════════════════════════════════════════════════════
   TOUCH OPTIMIZATIONS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    .canvas-tools-panel {
        left: 0.5rem;
        padding: 0.35rem;
    }

    .tool-btn {
        width: 48px;
        height: 48px;
    }

        .tool-btn i {
            font-size: 1.4rem;
        }

    .canvas-options-panel {
        right: 0.5rem;
        padding: 0.75rem;
        min-width: 180px;
    }

    .color-swatch {
        width: 40px;
        height: 40px;
    }

    .canvas-btn {
        width: 44px;
        height: 44px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE LAYOUT – PC İLE AYNI ARAYÜZ
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Fullscreen canvas: kalem arayüzü (tools + options + bottom bar) mobilde de açık */
    .testify-canvas-container:not(.quiz-mode) .canvas-tools-panel,
    .testify-canvas-container:not(.quiz-mode) .canvas-options-panel,
    .testify-canvas-container:not(.quiz-mode) .canvas-bottom-bar {
        display: flex;
    }

    .canvas-tools-panel {
        left: 0.5rem;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        flex-direction: column;
        max-width: none;
        overflow-x: visible;
    }

    .tool-divider {
        width: 100%;
        height: 1px;
        margin: 0.25rem 0;
    }

    .canvas-options-panel {
        right: 0.5rem;
        top: 50%;
        bottom: auto;
        left: auto;
        transform: translateY(-50%);
        border-radius: 12px;
        max-height: 65vh;
    }

    .canvas-toolbar-center {
        position: static;
        transform: none;
    }

    .canvas-title {
        font-size: 0.8rem;
    }

    .canvas-bottom-bar {
        padding: 0.35rem 0.75rem;
        font-size: 0.7rem;
    }

    .zoom-controls {
        padding: 0.1rem;
    }

    .zoom-btn {
        width: 26px;
        height: 26px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   QUIZ INTEGRATION MINI MODE
   ═══════════════════════════════════════════════════════════════════════════ */

.testify-canvas-container.quiz-mode {
    position: absolute;
    inset: auto;
    width: 100%;
    height: 300px;
    margin-top: 1rem;
    border-radius: 1rem;
    box-shadow: var(--toolbar-shadow);
    border: 1px solid var(--toolbar-border);
}

    .testify-canvas-container.quiz-mode .canvas-tools-panel {
        left: 0.5rem;
        top: 0.5rem;
        transform: none;
        flex-direction: row;
        padding: 0.25rem;
        gap: 0.15rem;
    }

    .testify-canvas-container.quiz-mode .tool-btn {
        width: 32px;
        height: 32px;
    }

        .testify-canvas-container.quiz-mode .tool-btn i {
            font-size: 1rem;
        }

    .testify-canvas-container.quiz-mode .canvas-options-panel {
        display: none;
    }

    .testify-canvas-container.quiz-mode .canvas-bottom-bar {
        display: none;
    }

    .testify-canvas-container.quiz-mode .canvas-top-toolbar {
        padding: 0.25rem 0.5rem;
    }

/* ═══════════════════════════════════════════════════════════════════════════
   ANIMATION CLASSES
   ═══════════════════════════════════════════════════════════════════════════ */

.animate-fadeIn {
    animation: fadeIn 0.3s var(--ease-out-expo);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.animate-scaleIn {
    animation: scaleIn 0.2s var(--ease-spring);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
    .testify-canvas-container {
        position: static;
        box-shadow: none;
    }

    .canvas-top-toolbar,
    .canvas-tools-panel,
    .canvas-options-panel,
    .canvas-bottom-bar {
        display: none !important;
    }

    .canvas-main-area {
        position: static;
    }
}
