/* ==========================================================================
   image-editor.css — Canvas image editor overlay styles.
   Uses CSS custom properties from agent.css (:root block).
   ========================================================================== */

/* ─── Editor Overlay ─── */
.image-editor-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

/* ─── Top Bar ─── */
.image-editor-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.image-editor-topbar::-webkit-scrollbar { display: none; }

.ie-filename {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.ie-dimensions {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.ie-topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

/* ─── Buttons ─── */
.ie-btn {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}
.ie-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.ie-btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}
.ie-btn.active {
    background: var(--accent-dim);
    border-color: rgba(0, 180, 216, 0.3);
    color: var(--accent);
}
.ie-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.ie-btn-primary:hover {
    filter: brightness(1.15);
}
.ie-btn-cancel {
    color: var(--text-muted);
    border-color: transparent;
}
.ie-btn-cancel:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}
.ie-btn-ai {
    border-color: rgba(192, 132, 252, 0.3);
    color: #c084fc;
}
.ie-btn-ai:hover {
    background: rgba(192, 132, 252, 0.12);
}

.ie-separator {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
}

.ie-zoom-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
    white-space: nowrap;
}

/* ─── Canvas Area ─── */
.ie-canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    background: var(--bg-tertiary, #111);
    /* Checkerboard for transparency */
    background-image:
        linear-gradient(45deg, rgba(255,255,255,0.03) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255,255,255,0.03) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.03) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.03) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.ie-canvas-area.cursor-crosshair { cursor: crosshair; }
.ie-canvas-area.cursor-grab { cursor: grab; }
.ie-canvas-area.cursor-grabbing { cursor: grabbing; }
.ie-canvas-area.cursor-text { cursor: text; }
.ie-canvas-area.cursor-crop { cursor: crosshair; }
.ie-canvas-area.cursor-move { cursor: move; }

#ie-canvas {
    position: absolute;
    transform-origin: 0 0;
    image-rendering: auto;
}

/* ─── Bottom Toolbar (tool palette) ─── */
.ie-toolbar-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.ie-tool {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
}
.ie-tool:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.ie-tool.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}
.ie-tool svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* ─── Options Panel ─── */
.ie-options-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 40px;
    overflow-x: auto;
    scrollbar-width: none;
}
.ie-options-panel::-webkit-scrollbar { display: none; }
.ie-options-panel:empty { display: none; }

.ie-opt-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ie-opt-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.ie-color-picker {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: none;
}
.ie-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.ie-color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }
.ie-color-picker::-moz-color-swatch { border: none; border-radius: 50%; }

.ie-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}
.ie-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
.ie-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.ie-slider-value {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 24px;
    text-align: right;
}

.ie-font-select {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 0.72rem;
    cursor: pointer;
    outline: none;
    max-width: 110px;
}
.ie-font-select:focus {
    border-color: var(--accent);
}

.ie-opt-btn {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.ie-opt-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.ie-opt-btn.active {
    background: var(--accent-dim);
    border-color: rgba(0, 180, 216, 0.3);
    color: var(--accent);
}

.ie-opt-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
}

/* ─── Crop Overlay ─── */
.ie-crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent);
    border: 1px solid #fff;
    z-index: 2;
}

/* ─── Text Box (Draggable Container) ─── */
.ie-text-box {
    position: absolute;
    z-index: 10;
    display: flex;
    flex-direction: column;
    min-width: 80px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.15);
    pointer-events: auto;
}
.ie-text-drag {
    height: 16px;
    cursor: move;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    opacity: 0.6;
    touch-action: none;
}
.ie-text-drag:active {
    opacity: 0.9;
}
.ie-text-input {
    background: transparent;
    border: none;
    color: inherit;
    font-family: sans-serif;
    padding: 4px 6px;
    outline: none;
    min-width: 60px;
    min-height: 1.4em;
    resize: none;
    overflow: hidden;
    line-height: 1.2;
}
.ie-text-resize {
    width: 12px;
    height: 12px;
    position: absolute;
    bottom: -2px;
    right: -2px;
    cursor: se-resize;
    background: var(--accent);
    border-radius: 2px;
    opacity: 0.6;
    touch-action: none;
}
.ie-text-resize:active {
    opacity: 0.9;
}

/* ─── Text Layer (follows canvas transform) ─── */
.ie-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    pointer-events: none;
}

/* When not in text mode, disable interaction on committed overlays */
.ie-text-layer.inactive .ie-text-committed {
    pointer-events: none;
}

/* ─── Committed Text Overlay ─── */
.ie-text-committed {
    position: absolute;
    pointer-events: auto;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 2px 4px;
    transition: border-color 0.15s;
}
.ie-text-committed:hover {
    border-color: var(--accent);
}
.ie-text-display {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.2;
}
.ie-text-actions {
    display: none;
    position: absolute;
    top: -30px;
    right: 0;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 4px;
    z-index: 20;
}
.ie-text-committed:hover .ie-text-actions {
    display: flex;
}
.ie-text-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    padding: 0;
}
.ie-text-action-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.ie-text-action-btn.delete:hover {
    color: var(--error, #ef4444);
}

/* ─── AI Dialog ─── */
.ie-ai-dialog {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.ie-ai-dialog-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 420px;
}
.ie-ai-dialog-content h3 {
    margin: 0 0 4px;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}
.ie-ai-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0 0 8px;
}
.ie-ai-prompt {
    width: 100%;
    min-height: 80px;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 0.88rem;
    margin: 8px 0 12px;
    box-sizing: border-box;
}
.ie-ai-prompt:focus {
    outline: none;
    border-color: var(--accent);
}
.ie-ai-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.ie-ai-progress {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 12px;
}
.ie-ai-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 30%;
    animation: ie-progress-pulse 2s ease-in-out infinite;
}
@keyframes ie-progress-pulse {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(300%); }
}
.ie-ai-error {
    color: var(--error, #ef4444);
    font-size: 0.82rem;
    margin-top: 8px;
}

/* ─── Edit Image button in normal image renderer ─── */
.ie-open-btn {
    margin-top: 8px;
    padding: 6px 16px;
    font-size: 0.82rem;
}
.ie-open-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}


/* ==========================================================================
   Responsive — 768px (Tablet / Large Phone)
   ========================================================================== */

@media (max-width: 768px) {
    .ie-tool {
        width: 44px;
        height: 44px;
    }
    .ie-toolbar-bottom {
        gap: 2px;
        padding: 6px 8px;
    }
    .ie-options-panel {
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 8px;
    }
    .ie-btn .ie-btn-text {
        display: none;
    }
    .ie-btn {
        padding: 6px 8px;
        min-height: 36px;
    }
    .ie-filename {
        max-width: 100px;
    }
    .ie-ai-dialog-content {
        max-width: 95vw;
    }
    .ie-ai-prompt,
    .ie-text-input {
        font-size: 16px !important; /* prevent iOS auto-zoom */
    }
}


/* ==========================================================================
   Responsive — 480px (Small Phone)
   ========================================================================== */

@media (max-width: 480px) {
    .ie-tool {
        width: 40px;
        height: 40px;
    }
    .image-editor-topbar {
        padding: 4px 8px;
        gap: 4px;
    }
    .ie-filename {
        max-width: 80px;
        font-size: 0.75rem;
    }
    .ie-dimensions {
        display: none;
    }
    .ie-separator {
        display: none;
    }
    .ie-zoom-label {
        display: none;
    }
    .ie-slider {
        width: 60px;
    }
}
