/* =========================================
   Scratch Pad — Zoom Annotation Toolbar Replica
   White/Light Theme (Zoom Style)
   ========================================= */

/* Toggle Button (fixed, bottom-right, above back-to-top) */
.scratch-pad-toggle {
    position: fixed;
    bottom: 70px;
    right: 20px;
    z-index: 10002;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid #0B5CFF;
    background: #ffffff;
    color: #0B5CFF;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.15s ease;
}

.scratch-pad-toggle:hover {
    background: #f0f4ff;
    border-color: #0B5CFF;
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(11, 92, 255, 0.25);
}

.scratch-pad-toggle.active {
    background: #0B5CFF;
    color: #fff;
    border-color: #0B5CFF;
}

/* Inline Toggle Button */
.scratch-pad-inline-toggle {
    cursor: pointer;
    transition: all 0.15s ease;
}

.scratch-pad-inline-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(11, 92, 255, 0.25);
}

/* =========================================
   Horizontal Toolbar (Zoom-style)
   ========================================= */
.scratch-pad-toolbar {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 5px 8px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
    white-space: nowrap;
}

/* Drag handle for toolbar repositioning */
.sp-drag-handle {
    width: 14px;
    height: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: grab;
    flex-shrink: 0;
    padding: 0 2px;
    border-radius: 4px;
    transition: background 0.15s ease;
}

.sp-drag-handle:active {
    cursor: grabbing;
}

.sp-drag-handle:hover {
    background: #f0f0f0;
}

.sp-drag-handle-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #cccccc;
}

.sp-drag-handle:hover .sp-drag-handle-dot {
    background: #999999;
}

.scratch-pad-toolbar.visible {
    display: flex;
}

/* Group wrapper */
.sp-group {
    display: flex;
    gap: 2px;
    align-items: center;
}

/* Vertical separator */
.sp-sep {
    width: 1px;
    height: 24px;
    background: #e0e0e0;
    margin: 0 4px;
    flex-shrink: 0;
}

/* =========================================
   Toolbar Buttons
   ========================================= */
.sp-btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: #555555;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
    position: relative;
    flex-shrink: 0;
}

.sp-btn:hover {
    background: #f0f0f0;
    color: #333333;
}

.sp-btn.active {
    background: #0B5CFF;
    border-color: #0B5CFF;
    color: #ffffff;
    box-shadow: none;
}

.sp-icon-sm {
    font-size: 0.7rem;
}

.sp-btn.sp-btn-close:hover {
    background: rgba(255, 94, 87, 0.1);
    color: #ff5e57;
}

/* Dropdown caret */
.sp-btn .sp-caret {
    font-size: 0.55rem;
    margin-left: 1px;
    opacity: 0.5;
}

.sp-btn.active .sp-caret {
    opacity: 0.8;
}

/* Wider button for buttons with caret */
.sp-btn.sp-has-dropdown {
    width: 44px;
    gap: 1px;
}

/* =========================================
   Dropdown System
   ========================================= */
.sp-dropdown-wrap {
    position: relative;
    flex-shrink: 0;
}

.sp-dropdown {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: none;
    min-width: 150px;
    z-index: 10;
}

.sp-dropdown.open {
    display: block;
}

/* Arrow tip pointing down */
.sp-dropdown::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
}

/* Dropdown item */
.sp-dd-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #444444;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.sp-dd-item:hover {
    background: #f5f5f5;
    color: #222222;
}

.sp-dd-item.active {
    background: #e8f0fe;
    color: #0B5CFF;
}

.sp-dd-item i {
    width: 18px;
    text-align: center;
    font-size: 0.8rem;
}

/* Wide dropdown (format) */
.sp-dropdown-wide {
    min-width: 240px;
}

/* Dropdown sections */
.sp-dd-section {
    padding: 4px 2px;
}

.sp-dd-label {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #999999;
    margin-bottom: 6px;
    padding: 0 4px;
}

.sp-dd-divider {
    height: 1px;
    background: #eeeeee;
    margin: 4px 0;
}

/* =========================================
   Color Buttons (inside format dropdown)
   ========================================= */
.sp-color-row {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    padding: 0 2px;
}

.sp-btn-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #d0d0d0;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.sp-btn-color:hover {
    transform: scale(1.15);
    border-color: #888888;
}

.sp-btn-color.active {
    border-color: #0B5CFF;
    box-shadow: 0 0 0 2px rgba(11, 92, 255, 0.25);
    transform: scale(1.15);
}

.sp-btn-color[data-color="black"]  { background: #1a1a1a; }
.sp-btn-color[data-color="white"]  { background: #ffffff; }
.sp-btn-color[data-color="red"]    { background: #ff5e57; }
.sp-btn-color[data-color="orange"] { background: #ff9f43; }
.sp-btn-color[data-color="yellow"] { background: #ffe600; }
.sp-btn-color[data-color="green"]  { background: #00cc7e; }
.sp-btn-color[data-color="blue"]   { background: #409eff; }
.sp-btn-color[data-color="purple"] { background: #a855f7; }
.sp-btn-color[data-color="pink"]   { background: #f472b6; }
.sp-btn-color[data-color="gray"]   { background: #9ca3af; }

/* =========================================
   Thickness Buttons
   ========================================= */
.sp-thickness-row {
    display: flex;
    gap: 5px;
    padding: 0 2px;
}

.sp-btn-thickness {
    width: 34px;
    height: 34px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.sp-btn-thickness:hover {
    background: #f0f0f0;
    border-color: #cccccc;
}

.sp-btn-thickness.active {
    background: #e8f0fe;
    border-color: #0B5CFF;
}

.sp-thickness-dot {
    display: block;
    border-radius: 50%;
    background: #666666;
    flex-shrink: 0;
}

/* =========================================
   Font Family Buttons
   ========================================= */
.sp-font-family-row {
    display: flex;
    gap: 4px;
    padding: 0 2px;
}

.sp-btn-fontfamily {
    height: 30px;
    padding: 0 10px;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    color: #555555;
    font-size: 0.72rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.sp-btn-fontfamily:hover {
    background: #f0f0f0;
    color: #333333;
}

.sp-btn-fontfamily.active {
    background: #e8f0fe;
    border-color: #0B5CFF;
    color: #0B5CFF;
}

/* =========================================
   Font Style (Bold / Italic) Buttons
   ========================================= */
.sp-font-style-row {
    display: flex;
    gap: 4px;
    padding: 0 2px;
}

.sp-btn-fontstyle {
    width: 32px;
    height: 30px;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    color: #555555;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.sp-btn-fontstyle:hover {
    background: #f0f0f0;
    color: #333333;
}

.sp-btn-fontstyle.active {
    background: #e8f0fe;
    border-color: #0B5CFF;
    color: #0B5CFF;
}

/* =========================================
   Font Size (Input + Quick Picks)
   ========================================= */
.sp-fontsize-row {
    display: flex;
    gap: 4px;
    padding: 0 2px;
    align-items: center;
}

.sp-fontsize-input {
    width: 48px;
    height: 28px;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    color: #333333;
    font-size: 0.75rem;
    text-align: center;
    outline: none;
    padding: 0 4px;
    transition: border-color 0.15s ease;
}

.sp-fontsize-input:focus {
    border-color: #0B5CFF;
    box-shadow: 0 0 0 2px rgba(11, 92, 255, 0.15);
}

.sp-btn-fontsize {
    min-width: 32px;
    height: 28px;
    border-radius: 5px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    color: #555555;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0 4px;
}

.sp-btn-fontsize:hover {
    background: #f0f0f0;
    color: #333333;
}

.sp-btn-fontsize.active {
    background: #e8f0fe;
    border-color: #0B5CFF;
    color: #0B5CFF;
}

/* =========================================
   Stamp Grid
   ========================================= */
.sp-stamp-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 2px;
}

.sp-stamp-item {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
    color: #555555;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.sp-stamp-item:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.sp-stamp-item.active {
    background: #e8f0fe;
    border-color: #0B5CFF;
}

/* =========================================
   Floating Panel Mode
   ========================================= */
.scratch-pad-panel {
    position: fixed;
    bottom: 185px;
    right: 80px;
    z-index: 10000;
    width: 520px;
    display: none;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.scratch-pad-panel.visible {
    display: flex;
}

.scratch-pad-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    cursor: grab;
    user-select: none;
}

.scratch-pad-panel-header:active {
    cursor: grabbing;
}

.scratch-pad-panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #333333;
    letter-spacing: 0.3px;
}

.scratch-pad-panel-close {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: #f0f0f0;
    color: #666666;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.scratch-pad-panel-close:hover {
    background: rgba(255, 94, 87, 0.12);
    color: #ff5e57;
}

.scratch-pad-panel-canvas-wrap {
    padding: 0;
    background: #fff;
    position: relative;
}

.scratch-pad-panel-canvas-wrap canvas {
    display: block;
    width: 100%;
    touch-action: none;
}

/* =========================================
   Overlay Mode
   ========================================= */
.scratch-pad-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: none;
    background: rgba(255, 255, 255, 0.01);
}

.scratch-pad-overlay.visible {
    display: block;
}

.scratch-pad-overlay canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* =========================================
   Text Box (Zoom-style: movable, resizable, re-editable)
   ========================================= */
.sp-text-box {
    position: fixed;
    z-index: 10005;
    min-width: 60px;
    min-height: 28px;
    cursor: move;
    user-select: none;
}

.sp-text-box.editing {
    cursor: text;
    user-select: auto;
}

.sp-text-box.editing .sp-text-area {
    border: 2px solid #0B5CFF;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(11, 92, 255, 0.12), 0 2px 12px rgba(0, 0, 0, 0.1);
}

.sp-text-box:not(.editing) .sp-text-area {
    border: 2px solid transparent;
    background: transparent;
}

.sp-text-box:not(.editing):hover .sp-text-area {
    border-color: rgba(11, 92, 255, 0.3);
}

.sp-text-area {
    width: 100%;
    height: 100%;
    padding: 4px 6px;
    border-radius: 4px;
    font-family: sans-serif;
    outline: none;
    color: #1a1a1a;
    line-height: 1.3;
    resize: both;
    overflow: hidden;
    min-width: 60px;
    min-height: 28px;
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.sp-text-area:empty::before {
    content: 'Type here...';
    color: #ccc;
    pointer-events: none;
}

/* Legacy fallback - keep for compatibility */
.sp-text-input {
    position: fixed;
    z-index: 10005;
    background: rgba(255, 255, 255, 0.95);
    border: 2px dashed #0B5CFF;
    border-radius: 4px;
    padding: 4px 6px;
    font-family: sans-serif;
    outline: none;
    min-width: 80px;
    min-height: 28px;
    resize: both;
    color: #1a1a1a;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    line-height: 1.3;
}

.sp-text-input:focus {
    border-color: #0B5CFF;
    box-shadow: 0 0 0 3px rgba(11, 92, 255, 0.15), 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* =========================================
   Spotlight Cursor
   ========================================= */
.sp-spotlight {
    position: fixed;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10003;
    background: radial-gradient(circle, rgba(255, 40, 40, 0.7) 0%, rgba(255, 40, 40, 0.25) 40%, transparent 70%);
    transform: translate(-50%, -50%);
    display: none;
    transition: none;
}

.sp-spotlight.visible {
    display: block;
}

/* =========================================
   Spotlight Arrow
   ========================================= */
.sp-spotlight-arrow {
    position: fixed;
    pointer-events: none;
    z-index: 10003;
    display: none;
    transform: translate(-50%, -100%);
}

.sp-spotlight-arrow.visible {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sp-spotlight-arrow-icon {
    font-size: 24px;
    color: #ff4444;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.sp-spotlight-arrow-label {
    background: #ff4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    margin-top: 2px;
    white-space: nowrap;
}

/* =========================================
   Eraser Radius Cursor
   ========================================= */
.sp-eraser-cursor {
    position: fixed;
    border: 2px solid #ff6b6b;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10004;
    display: none;
    transform: translate(-50%, -50%);
    opacity: 0.7;
}

.sp-eraser-cursor.visible {
    display: block;
}

/* =========================================
   Select Tool — Selection Highlight
   ========================================= */
.sp-select-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.sp-select-box {
    position: absolute;
    border: 2px dashed #0B5CFF;
    background: rgba(11, 92, 255, 0.05);
    pointer-events: none;
}

.sp-select-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ffffff;
    border: 2px solid #0B5CFF;
    border-radius: 2px;
    pointer-events: auto;
    cursor: pointer;
}

.sp-select-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.sp-select-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.sp-select-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.sp-select-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* =========================================
   Mode Label
   ========================================= */
.sp-mode-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #999999;
    padding: 0 4px;
    flex-shrink: 0;
}

/* =========================================
   Vertical Toolbar Mode
   ========================================= */
.scratch-pad-toolbar.sp-vertical {
    flex-direction: column;
    white-space: normal;
    padding: 8px 5px;
    gap: 2px;
    left: auto;
    right: 80px;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    overflow: visible;
}

.scratch-pad-toolbar.sp-vertical .sp-sep {
    width: 80%;
    height: 1px;
    margin: 3px auto;
}

.scratch-pad-toolbar.sp-vertical .sp-group {
    flex-direction: column;
}

.scratch-pad-toolbar.sp-vertical .sp-drag-handle {
    width: 28px;
    height: 14px;
    flex-direction: row;
    gap: 3px;
}

/* Dropdowns open to the LEFT in vertical mode */
.scratch-pad-toolbar.sp-vertical .sp-dropdown {
    bottom: auto;
    top: 0;
    left: auto;
    right: calc(100% + 10px);
    transform: none;
}

.scratch-pad-toolbar.sp-vertical .sp-dropdown::after {
    bottom: auto;
    left: auto;
    right: -6px;
    top: 14px;
    transform: rotate(-45deg);
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 768px) {
    .scratch-pad-panel {
        width: calc(100vw - 30px);
        right: 15px;
        bottom: 185px;
    }

    .scratch-pad-toolbar {
        left: 10px;
        right: 70px;
        transform: none;
        overflow-x: auto;
        bottom: 126px;
        padding: 4px 6px;
        gap: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .scratch-pad-toolbar::-webkit-scrollbar {
        height: 0;
    }

    .scratch-pad-toggle {
        right: 15px;
        bottom: 65px;
        width: 44px;
        height: 44px;
    }

    .sp-btn {
        width: 32px;
        height: 32px;
        font-size: 0.78rem;
    }

    .sp-btn.sp-has-dropdown {
        width: 40px;
    }

    .sp-dropdown {
        min-width: 140px;
    }

    .sp-dropdown-wide {
        min-width: 200px;
    }
}
