/* Advanced Pixel Editor Admin Styles */

.aie-container {
    max-width: 100%;
    margin: 20px 0;
}

.aie-section {
    background: white;
    padding: 25px;
    margin-bottom: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border: 1px solid #ccd0d4;
}

.aie-section h2 {
    margin-top: 0;
    color: #1d2327;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.aie-section h3 {
    color: #2c3338;
    margin-bottom: 15px;
}

/* Compact Image Selection */
.aie-compact-section {
    padding: 15px;
}

.aie-image-selector {
    display: flex;
    align-items: center;
    gap: 15px;
}

.aie-button-small {
    padding: 8px 16px;
    font-size: 13px;
}

.aie-selected-image-name {
    font-weight: 600;
    color: #2271b1;
    font-size: 14px;
}

/* Editor Layout — 3-column: toolbar | preview | controls */
.aie-editor-layout {
    display: flex;
    gap: 0;
    margin-top: 20px;
}

/* Tool Sidebar */
.aie-toolbar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    background: #f6f7f7;
    border-right: 1px solid #dcdcde;
    border-radius: 4px 0 0 4px;
    flex-shrink: 0;
}

.aie-toolbar-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: #50575e;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2px;
}

.aie-toolbar-btn:hover,
.aie-toolbar-btn:focus-visible {
    background: #e0e0e0;
}

.aie-toolbar-btn:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: -2px;
}

.aie-toolbar-btn.is-active {
    background: #2271b1;
    color: #fff;
}

.aie-toolbar-btn .dashicons {
    font-size: 28px;
    width: 28px;
    height: 28px;
}

/* Locked Pro upsell buttons (free plugin only) */
.aie-toolbar-btn.aie-toolbar-btn--locked {
    flex-direction: column;
    height: auto;
    padding: 5px 0 3px;
    gap: 2px;
    opacity: 0.4;
    cursor: not-allowed;
}

.aie-toolbar-btn--locked .aie-pro-badge {
    display: block;
    font-size: 7px;
    line-height: 10px;
    padding: 0 3px;
}

/* Dimmed Pro upsell controls (shown when Pro is not installed) */
.aie-pro-upsell-controls {
    opacity: 0.45;
    pointer-events: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #dcdcde;
}

.aie-pro-upsell-controls .aie-pro-badge,
.aie-toolbar-btn--locked .aie-pro-badge {
    display: inline-block;
    padding: 1px 5px;
    background: #2271b1;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 2px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 14px;
    vertical-align: middle;
}

/* Tool controls visibility */
.aie-tool-controls {
    display: none;
}

.aie-tool-controls.is-active {
    display: block;
}

.aie-preview-panel {
    flex: 1;
    min-width: 300px;
    padding-left: 20px;
    padding-right: 20px;
}

.aie-controls-panel {
    flex: 1;
    min-width: 280px;
}

.aie-controls-panel h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #1d2327;
    font-size: 16px;
}

/* Controls */
.aie-control-group {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
}

.aie-control-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.aie-control-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #1d2327;
    font-size: 13px;
}

.aie-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 8px 0;
}

.aie-input-group input[type="number"] {
    width: 70px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
}

.aie-input-group input[type="range"] {
    flex: 1;
    height: 5px;
    -webkit-appearance: none;
    background: #f0f0f0;
    border-radius: 3px;
    outline: none;
}

.aie-control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.aie-control-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.aie-help-text {
    color: #646970;
    font-size: 12px;
    margin-top: 3px;
}

.aie-help-text small {
    font-size: 11px;
}

/* Preview */
.aie-preview-container {
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px dashed #dcdcde;
}

.aie-preview-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.aie-preview-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: #1d2327;
}

.aie-preview-toggle input[type="checkbox"] {
    margin: 0;
}

.aie-slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-width: 200px;
}

#aie-compare-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
}

#aie-compare-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#aie-compare-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.aie-slider-labels {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 11px;
    color: #646970;
}

.aie-preview-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 0 auto;
}

#aie-original-preview,
#aie-preview {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    display: none;
}

#aie-original-preview {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#aie-preview {
    position: relative;
    z-index: 2;
}

.aie-slider-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: white;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
    z-index: 3;
    cursor: ew-resize;
    opacity: 0.8;
}

.aie-slider-handle:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2271b1;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#aie-no-preview {
    margin: 20px 0;
}

/* Save Options (standalone box below editor) */
.aie-save-options {
    margin-top: 20px;
    padding: 20px;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    border-radius: 4px;
}

.aie-save-options-row {
    display: flex;
    gap: 20px;
}

.aie-save-options-row > .aie-control-group {
    flex: 1;
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.aie-save-options h3 {
    font-size: 14px;
    margin-bottom: 10px;
}

#aie-save-mode {
    width: 100%;
    padding: 6px 8px;
}

.aie-filename-input {
    display: flex;
    align-items: center;
    gap: 4px;
}

.aie-filename-input input[type="text"] {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

.aie-filename-input span {
    color: #646970;
    font-size: 13px;
    white-space: nowrap;
}

.aie-replace-info {
    padding: 8px 12px;
    background: #f0f6fc;
    border-left: 3px solid #2271b1;
    margin: 8px 0;
}

.aie-replace-info small {
    color: #2c3338;
}

.aie-restore-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fcf9e8;
    border-left: 3px solid #dba617;
    margin-bottom: 12px;
    border-radius: 2px;
    font-size: 13px;
}

/* Buttons */
.aie-button-group {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.aie-button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    transition: all 0.2s ease;
    flex: 1;
}

.aie-button:hover,
.aie-button:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.aie-button:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

.aie-button-success {
    background: #00a32a;
    color: white;
}

.aie-button-success:hover {
    background: #008a20;
}

.aie-button-secondary {
    background: #f0f0f0;
    color: #3c434a;
}

.aie-button-secondary:hover {
    background: #dcdcdc;
}

/* Loading Overlay */
#aie-loading {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 25px 35px;
    border-radius: 8px;
    z-index: 99999;
    font-size: 16px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    text-align: center;
    max-width: 300px;
}

#aie-loading:before {
    content: "";
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 12px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: aie-spin 1s ease-in-out infinite;
    vertical-align: middle;
}

#aie-loading-progress {
    margin-top: 15px;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

#aie-loading-progress-bar {
    height: 100%;
    background: #fff;
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
    animation: aie-progress 2s ease-in-out infinite;
}

@keyframes aie-spin {
    to { transform: rotate(360deg); }
}

@keyframes aie-progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* Button loading states */
.aie-button.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.aie-button.loading:before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: aie-spin 1s linear infinite;
}

.aie-button.loading.aie-button-secondary:before {
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: #3c434a;
}

/* Preview loading state — applied to wrapper since ::after doesn't work on <img> */
.aie-preview-wrapper.aie-loading #aie-preview,
.aie-preview-wrapper.aie-loading #aie-original-preview {
    opacity: 0.5;
    filter: blur(2px);
}

.aie-preview-wrapper.aie-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -15px 0 0 -15px;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    border-top-color: #2271b1;
    animation: aie-spin 1s linear infinite;
    z-index: 10;
}

/* How to Use Section */
.aie-section ol,
.aie-section ul {
    padding-left: 20px;
    margin: 15px 0;
}

.aie-section li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Tab Content */
.aie-tab-content {
    margin-top: 20px;
}

/* About Tab */
.aie-about-section {
    background: white;
    padding: 25px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border: 1px solid #ccd0d4;
    max-width: 800px;
}

.aie-about-section h2 {
    margin-top: 0;
    color: #1d2327;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.aie-about-section h3 {
    color: #2c3338;
    margin-bottom: 10px;
}

.aie-about-section ul {
    padding-left: 20px;
    margin: 15px 0;
}

.aie-about-section li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.aie-about-info-table {
    margin: 15px 0;
    border-collapse: collapse;
}

.aie-about-info-table th {
    text-align: left;
    padding: 6px 20px 6px 0;
    color: #646970;
    font-weight: 600;
}

.aie-about-info-table td {
    padding: 6px 0;
}

.aie-about-links {
    display: flex;
    gap: 8px;
}

.aie-imagick-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.aie-imagick-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 600;
}

.aie-imagick-status.available .aie-imagick-badge {
    background: #d4edda;
    color: #155724;
}

.aie-imagick-status.unavailable .aie-imagick-badge {
    background: #f8d7da;
    color: #721c24;
}

.aie-imagick-version {
    color: #646970;
    font-size: 13px;
}

.aie-about-opensource {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
}

.aie-about-resources {
    list-style: none;
    padding-left: 0 !important;
}

.aie-about-resources li {
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.aie-about-resources li:last-child {
    border-bottom: none;
}

/* ───── Crop Overlay ───── */

.aie-crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    cursor: crosshair;
}

.aie-crop-selection {
    position: absolute;
    border: 2px dashed #fff;
    background: transparent;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
}

.aie-crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 1px solid #2271b1;
    z-index: 11;
}

.aie-crop-handle[data-handle="nw"] { top: -5px; left: -5px; cursor: nw-resize; }
.aie-crop-handle[data-handle="n"]  { top: -5px; left: 50%; margin-left: -5px; cursor: n-resize; }
.aie-crop-handle[data-handle="ne"] { top: -5px; right: -5px; cursor: ne-resize; }
.aie-crop-handle[data-handle="w"]  { top: 50%; margin-top: -5px; left: -5px; cursor: w-resize; }
.aie-crop-handle[data-handle="e"]  { top: 50%; margin-top: -5px; right: -5px; cursor: e-resize; }
.aie-crop-handle[data-handle="sw"] { bottom: -5px; left: -5px; cursor: sw-resize; }
.aie-crop-handle[data-handle="s"]  { bottom: -5px; left: 50%; margin-left: -5px; cursor: s-resize; }
.aie-crop-handle[data-handle="se"] { bottom: -5px; right: -5px; cursor: se-resize; }

/* Crop controls */
.aie-crop-presets {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.aie-crop-presets button {
    padding: 3px 10px;
    font-size: 11px;
    border: 1px solid #dcdcde;
    background: #f6f7f7;
    border-radius: 3px;
    cursor: pointer;
}

.aie-crop-presets button.active {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.aie-crop-dims {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

.aie-crop-dims input[type="number"] {
    width: 65px;
    min-width: 0;
    text-align: center;
}

.aie-crop-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.aie-crop-actions button {
    padding: 4px 14px;
    font-size: 12px;
    cursor: pointer;
}

/* ───── Resize Controls ───── */

.aie-resize-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.aie-resize-group input[type="number"] {
    width: 80px;
    text-align: center;
}

.aie-aspect-lock {
    cursor: pointer;
    font-size: 16px;
    color: #2271b1;
    user-select: none;
}

.aie-aspect-lock.locked {
    color: #2271b1;
}

.aie-aspect-lock.unlocked {
    color: #787c82;
}

/* Responsive */
@media (max-width: 782px) {
    .aie-container {
        margin: 10px;
        max-width: 100%;
    }

    .aie-section {
        padding: 15px;
    }

    .aie-editor-layout {
        flex-direction: column;
        gap: 15px;
    }

    .aie-toolbar {
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid #dcdcde;
        border-radius: 4px 4px 0 0;
        justify-content: center;
    }

    .aie-preview-panel {
        padding-left: 0;
        padding-right: 0;
    }

    .aie-preview-panel,
    .aie-controls-panel {
        min-width: auto;
    }

    .aie-preview-controls {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .aie-slider-container {
        min-width: auto;
    }

    .aie-preview-wrapper {
        max-width: 100%;
    }

    .aie-save-options-row {
        flex-direction: column;
        gap: 10px;
    }

    .aie-image-selector {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .aie-input-group {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .aie-input-group input[type="number"] {
        width: 100%;
    }

    .aie-button-group {
        flex-direction: row;
        gap: 8px;
    }

    .aie-button {
        flex: 1;
        text-align: center;
    }

    .aie-restore-notice {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .aie-preview-controls {
        padding: 8px;
    }

    .aie-slider-labels {
        font-size: 10px;
    }

    .aie-preview-toggle {
        font-size: 13px;
    }
}