/* Location: /css/annotation.css */

/* 1. Style for the main "Annotate" button in the controls bar */
#controls button#annotate-btn.active {
    color: #0d6efd !important; /* Blue color to show it's active */
    transform: scale(1.1);
}

/* 2. Main Annotation Toolbar */
#annotation-toolbar {
    position: fixed;
    bottom: 45px; /* Position it above the main controls bar */
    left: 50%;
    transform: translateX(-50%);
    z-index: 50006;
    
    display: flex;
    gap: 1.5rem;
    align-items: center;
    
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    
    padding: 10px 20px;
    border-radius: 50px; /* Pill shape */
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    border: 1px solid rgba(0,0,0,0.1);
    
    transition: opacity 0.3s ease, bottom 0.3s ease;
    opacity: 0;
    pointer-events: none;
}
#annotation-toolbar:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}
#annotation-toolbar.hidden {
    bottom: 60px; /* Animate downwards when hiding */
}

/* This is the new wrapper for the main tools */
.toolbar-inner-content {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

/* --- START: NEW, CORRECTED STYLES FOR THE CLOSE BUTTON --- */
.tool-btn-close {
    position: absolute;
    
    /* --- THE FIX IS HERE --- */
    /* Position it relative to the top-right corner of the parent toolbar */
    top: 0;
    right: 0;
    
    /* Now, use a transform to push it outside */
    transform: translate(50%, -50%); /* Move it 50% of its own width right, and 50% of its own height up */

    /* Style it as a circular, icon-only button with a nice shadow */
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tool-btn-close:hover {
    background-color: #e9ecef;
    transform: translate(50%, -50%) scale(1.1); /* Add a grow effect on hover */
}
.tool-btn-close svg {
    width: 20px;
    height: 20px;
    color: #6c757d;
}
/* --- END: NEW STYLES --- */

/* --- START: NEW STYLES FOR THE UNDO BUTTON --- */

.tool-btn-undo {
    position: absolute;
    
    /* Position it relative to the top-LEFT corner of the parent toolbar */
    top: 0;
    left: 0;
    
    /* Use transform to push it outside, mirroring the close button */
    transform: translate(-50%, -50%); /* Move it 50% left and 50% up */

    /* Use the exact same styling as the close button for consistency */
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tool-btn-undo:hover {
    background-color: #e9ecef;
    transform: translate(-50%, -50%) scale(1.1);
}

.tool-btn-undo svg {
    width: 20px;
    height: 20px;
    color: #6c757d;
}
/* --- END: NEW STYLES --- */

/* 3. Groups of tools within the toolbar */
.tool-group {
    display: flex;
    align-items: center;
    gap: 10px;
}
.tool-group:not(:last-child) {
    border-right: 1px solid #dee2e6;
    padding-right: 1.5rem;
}

/* 4. Individual Tool Buttons */
.tool-btn {
    background-color: transparent;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tool-btn svg {
    width: 24px;
    height: 24px;
    color: #495057;
}
.tool-btn:hover {
    background-color: #e9ecef;
}
.tool-btn.active {
    border-color: #0d6efd;
    background-color: #e7f1ff;
}
.tool-btn.active svg {
    color: #0d6efd;
}
/* --- START: NEW STYLES FOR THE SAVE ICON BUTTON --- */

/* Style the save button to make it the primary action */
#save-annotation-btn {
    background-color: #198754; /* Green background */
    border-color: #198754;
}
#save-annotation-btn svg {
    color: #ffffff; /* White icon */
}

/* Add a hover effect */
#save-annotation-btn:hover {
    background-color: #157347;
}

/* Add a disabled state for when it's saving */
#save-annotation-btn:disabled {
    background-color: #6c757d;
    opacity: 0.6;
    cursor: not-allowed;
}
/* --- END: NEW STYLES --- */

/* 5. Color Picker and Select Dropdown */
.tool-color-picker {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 1px #ccc;
}
.tool-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}
.tool-select {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 6px 10px;
    border-radius: 5px;
    border: 1px solid #ced4da;
}

/* 6. The Drawing Canvas Overlay */
.annotation-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    /* --- THE FIX IS HERE --- */
    /* Give it the highest z-index within the .page stacking context */
    z-index: 13; 
    
    cursor: crosshair;
    touch-action: none;
}

/* 7. Style for the SAVED annotation image overlay */
.annotation-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 6;
    pointer-events: none;
    
    /* --- THIS IS THE FIX --- */
    display: none; /* Hide it completely by default */
}

/* NEW RULE: Show the overlay ONLY when annotation mode is active */
body.annotation-active .annotation-overlay {
    display: block;
}

/* ======================================================= */
/* --- V2: RESPONSIVE & COMPACT ANNOTATION TOOLBAR --- */
/* ======================================================= */

@media (max-width: 600px) {

    #annotation-toolbar {
        /* On mobile, use the full width with some padding */
        width: 90%;
        max-width: 400px; /* Max width to prevent it looking huge on wide phones */
        
        /* Reduce padding and gap for a tighter layout */
        padding: 8px 10px;
        gap: 0.75rem;
        
        /* Adjust position slightly higher */
        bottom: 48px;
    }
    
    #annotation-toolbar.hidden {
        bottom: 50px; /* Adjust hide animation */
    }

    /* Reduce the size of tool groups */
    .tool-group:not(:last-child) {
        padding-right: 0.75rem;
    }
    .tool-group {
        gap: 8px;
    }

    /* Make the SVG icons slightly smaller */
    .tool-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Make the color picker and select dropdown smaller */
    .tool-color-picker {
        width: 28px;
        height: 28px;
    }
    .tool-select {
        font-size: 0.8rem;
        padding: 4px 6px;
    }

    /* Make the action buttons smaller */
    .tool-btn.action-btn {
        font-size: 0.8rem;
        padding: 5px 12px;
    }
}

/* --- START: NEW STYLES FOR SAVE BUTTON LOADING STATE --- */

/* Add the spinning animation */
@keyframes spin {
    to { transform: rotate(360deg); }
}

#save-annotation-btn .icon-spinner {
    animation: spin 1s linear infinite;
}

/* --- END: NEW STYLES --- */
