/* Insert Text Module Styles */

/* Input Modal Styles */
.text-input-modal-content {
    max-width: 360px;
    min-width: 280px;
    width: 85%;
    padding: 18px;
}

.text-input-area {
    width: 100%;
    min-height: 64px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.text-input-area:focus {
    outline: none;
    border-color: var(--theme-color);
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.text-input-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.text-control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.text-control-group label {
    font-size: 13px;
    color: #333;
    font-weight: 500;
}

.text-decoration-settings {
    display: none;
    flex-direction: column;
    gap: 8px;
}

.text-decoration-color-input {
    width: 100%;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 2px;
    background-color: #fff;
    cursor: pointer;
}

/* Font selection row with upload button */
.font-selection-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.font-selection-row .format-select {
    flex: 1;
    min-height: 36px;
    font-size: 14px;
    padding: 6px 10px;
}

.font-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: var(--theme-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
}

.font-upload-btn:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.font-upload-btn:active {
    transform: scale(0.95);
}

.font-upload-btn svg {
    stroke: white;
}

/* Text style buttons (bold, italic, underline, etc.) */
.text-style-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.text-style-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background-color: #f5f5f5;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #333;
}

.text-style-btn:hover {
    border-color: var(--theme-color);
    background-color: #e8e8e8;
}

.text-style-btn.active {
    border-color: var(--theme-color);
    background-color: var(--theme-color);
    color: white;
}

.text-style-btn.active svg {
    stroke: white;
}

/* Touch-friendly slider */
.touch-friendly-slider {
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: #ddd;
    border-radius: 4px;
    outline: none;
    touch-action: none;
}

.touch-friendly-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--theme-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.touch-friendly-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--theme-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Touch targets for better touchscreen support */
.touch-target {
    min-width: 40px;
    min-height: 40px;
}

.text-input-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.text-input-buttons .confirm-btn {
    min-height: 32px;
    padding: 6px 16px;
    font-size: 13px;
}

@media (min-width: 1600px) {
    .text-input-modal-content {
        max-width: 420px;
    }

    .text-input-area {
        min-height: 90px;
        font-size: 15px;
    }
}

/* Overlay */
#insert-text-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1600;
    pointer-events: none;
}

/* Control Box */
#insert-text-box {
    position: absolute;
    border: 1px dashed rgba(0, 122, 255, 0.5);
    pointer-events: all;
    cursor: move;
    transform-origin: center center;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    white-space: pre-wrap;
    padding: 4px;
    --resize-handle-size: 16px;
    --resize-handle-offset: -8px;
    --floating-control-size: 44px;
    --floating-control-icon-size: 20px;
    --handle-connector-top: 44px;
    --handle-connector-height: 20px;
    --toolbar-button-size: 36px;
    --toolbar-gap: 8px;
    --toolbar-padding-y: 8px;
    --toolbar-padding-x: 8px;
}

/* Internal text element to hold the content */
#insert-text-content {
    width: 100%;
    height: 100%;
    pointer-events: none;
    user-select: none;
    line-height: 1.2;
}

/* Resize Handles */
#insert-text-box .resize-handle {
    position: absolute;
    background-color: var(--theme-color);
    border: 2px solid white;
    width: var(--resize-handle-size);
    height: var(--resize-handle-size);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: all;
    z-index: 10;
}

#insert-text-box .resize-handle.top-left { top: var(--resize-handle-offset); left: var(--resize-handle-offset); cursor: nw-resize; }
#insert-text-box .resize-handle.top-right { top: var(--resize-handle-offset); right: var(--resize-handle-offset); cursor: ne-resize; }
#insert-text-box .resize-handle.bottom-left { bottom: var(--resize-handle-offset); left: var(--resize-handle-offset); cursor: sw-resize; }
#insert-text-box .resize-handle.bottom-right { bottom: var(--resize-handle-offset); right: var(--resize-handle-offset); cursor: se-resize; }

/* Rotation Handle */
#insert-text-box .rotate-handle {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: var(--floating-control-size);
    height: var(--floating-control-size);
    background-color: var(--theme-color);
    border-radius: 50%;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    pointer-events: all;
    z-index: 10;
}

#insert-text-box .rotate-handle:hover {
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#insert-text-box .rotate-handle:active {
    cursor: grabbing;
}

#insert-text-box .rotate-handle::after {
    content: '';
    position: absolute;
    top: var(--handle-connector-top);
    left: 50%;
    width: 2px;
    height: var(--handle-connector-height);
    background-color: var(--theme-color);
    transform: translateX(-50%);
    pointer-events: none;
}

/* Toolbar */
#insert-text-box .text-controls-toolbar {
    position: absolute;
    bottom: calc(var(--toolbar-button-size) * -1.45);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--toolbar-gap);
    padding: var(--toolbar-padding-y) var(--toolbar-padding-x);
    background-color: white;
    border-radius: calc(var(--toolbar-button-size) * 0.25);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: all;
    z-index: 10;
    max-width: calc(100% - 8px);
    box-sizing: border-box;
}

#insert-text-box .text-control-btn {
    width: var(--toolbar-button-size);
    height: var(--toolbar-button-size);
    border: none;
    border-radius: calc(var(--toolbar-button-size) * 0.22);
    background-color: #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: #333;
}

#insert-text-box .rotate-handle svg,
#insert-text-box .text-control-btn svg {
    width: var(--floating-control-icon-size);
    height: var(--floating-control-icon-size);
}

#insert-text-box .text-control-btn:hover {
    background-color: #e0e0e0;
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

#insert-text-box .text-done-btn {
    background-color: #34C759;
    color: white;
}

#insert-text-box .text-done-btn:hover {
    background-color: #28A745;
}

#insert-text-box .text-cancel-btn {
    background-color: #FF3B30;
    color: white;
}

#insert-text-box .text-cancel-btn:hover {
    background-color: #E02020;
}

#insert-text-box .text-edit-btn {
    background-color: #007AFF;
    color: white;
}

#insert-text-box .text-edit-btn:hover {
    background-color: #005ecb;
}

/* High-resolution touchscreen optimizations - consolidated media query */
@media (min-width: 1200px) and (min-resolution: 150dpi),
       (min-width: 1200px) and (-webkit-min-device-pixel-ratio: 1.5),
       (min-width: 1200px) and (min-resolution: 1.5dppx) {
    .text-input-area {
        min-height: 100px;
        padding: 14px;
        font-size: 17px;
    }
    
    .touch-friendly-slider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
    
    .touch-friendly-slider::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }
    
    .touch-target {
        min-width: 44px;
        min-height: 44px;
    }
    
    .text-style-btn {
        width: 44px;
        height: 44px;
    }
    
    .font-upload-btn {
        width: 44px;
        height: 44px;
    }
    
    .font-selection-row .format-select {
        min-height: 44px;
        font-size: 16px;
    }
    
    .text-input-buttons .confirm-btn {
        min-height: 44px;
        padding: 10px 24px;
        font-size: 16px;
    }
    
    #insert-text-box {
        --resize-handle-size: 20px;
        --resize-handle-offset: -10px;
        --floating-control-size: 52px;
        --floating-control-icon-size: 22px;
        --handle-connector-top: 52px;
        --handle-connector-height: 24px;
        --toolbar-button-size: 40px;
        --toolbar-gap: 8px;
        --toolbar-padding-y: 10px;
        --toolbar-padding-x: 10px;
    }
}
