/* ============================================================
   OmniToolkit — Image Category Styles
   ============================================================ */

/* ============================================================
   Dropzone
   ============================================================ */
.image-dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 180px;
}

.image-dropzone:hover,
.image-dropzone.is-dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.image-dropzone.has-file {
    padding: 0.5rem;
    border-style: solid;
    border-color: var(--border-color);
    background: var(--bg-card);
    cursor: default;
}

.image-dropzone-icon {
    font-size: 2.5rem;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
    line-height: 1;
    transition: color 0.15s ease;
}

.image-dropzone:hover .image-dropzone-icon,
.image-dropzone.is-dragover .image-dropzone-icon {
    color: var(--accent);
}

.image-dropzone-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.image-dropzone-hint {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.image-dropzone input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   Preview
   ============================================================ */
.image-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-height: 320px;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
}

.image-preview img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.image-file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    margin-top: 0.6rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.image-file-info .image-file-name {
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.image-file-info .image-file-size {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.image-file-info .btn-remove {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    line-height: 1;
    font-size: 1rem;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.image-file-info .btn-remove:hover {
    background: var(--red-light);
    color: var(--red);
}

/* ============================================================
   Result
   ============================================================ */
.image-result {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.image-result-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    max-height: 300px;
    overflow: hidden;
}

.image-result-preview img {
    display: block;
    max-width: 100%;
    max-height: 280px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.image-result-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ============================================================
   Compare
   ============================================================ */
.image-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 575.98px) {
    .image-compare {
        grid-template-columns: 1fr;
    }
}

.image-compare-side {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.image-compare-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    text-align: center;
}

.image-compare-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    min-height: 140px;
}

.image-compare-thumb img {
    display: block;
    max-width: 100%;
    max-height: 200px;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* ============================================================
   Gallery
   ============================================================ */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.image-gallery-item {
    position: relative;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-gallery-item .btn-remove {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    transition: background 0.15s ease;
}

.image-gallery-item .btn-remove:hover {
    background: var(--red);
}

[dir="rtl"] .image-gallery-item .btn-remove {
    right: auto;
    left: 0.35rem;
}

/* ============================================================
   Dimensions row
   ============================================================ */
.image-dimensions {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 0.5rem;
}

.image-dimensions .dimension-separator {
    padding-bottom: 0.65rem;
    color: var(--text-tertiary);
    font-size: 1.1rem;
    text-align: center;
}

.image-lock-ratio {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    margin-top: 0.5rem;
}

.image-lock-ratio input[type="checkbox"] {
    cursor: pointer;
}

/* ============================================================
   Size limit
   ============================================================ */
.image-size-limit {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin-top: 0.4rem;
}

.image-size-limit.is-over {
    color: var(--red);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 575.98px) {
    .image-dropzone {
        padding: 1.75rem 1rem;
        min-height: 150px;
    }

    .image-dropzone-icon {
        font-size: 2rem;
    }

    .image-preview,
    .image-preview img {
        max-height: 220px;
    }

    .image-result-preview,
    .image-result-preview img {
        max-height: 200px;
    }
}

/* ============================================================
   Crop Tool
   ============================================================ */
.crop-stage-wrapper {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.crop-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    line-height: 0;
    background: #1a1a1a;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.crop-image {
    display: block;
    max-width: 100%;
    height: auto;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.crop-overlay {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.crop-box {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    cursor: move;
    outline: 1px solid rgba(255, 255, 255, 0.9);
    outline-offset: -1px;
    box-sizing: border-box;
}

.crop-box.dragging {
    cursor: grabbing;
}

.crop-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, rgba(255,255,255,0.35) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.35) 1px, transparent 1px);
    background-size: 33.333% 33.333%;
    background-position: -1px -1px;
}

.crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid var(--accent, #0d6efd);
    border-radius: 3px;
    box-sizing: border-box;
    z-index: 2;
    touch-action: none;
}

.crop-handle-nw { top: -7px;  left: -7px;   cursor: nwse-resize; }
.crop-handle-n  { top: -7px;  left: 50%;    margin-left: -7px; cursor: ns-resize; }
.crop-handle-ne { top: -7px;  right: -7px;  cursor: nesw-resize; }
.crop-handle-e  { top: 50%;   right: -7px;  margin-top: -7px;  cursor: ew-resize; }
.crop-handle-se { bottom: -7px; right: -7px; cursor: nwse-resize; }
.crop-handle-s  { bottom: -7px; left: 50%;  margin-left: -7px; cursor: ns-resize; }
.crop-handle-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.crop-handle-w  { top: 50%;   left: -7px;   margin-top: -7px;  cursor: ew-resize; }

.crop-readout {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    margin-top: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

@media (max-width: 575.98px) {
    .crop-handle {
        width: 18px;
        height: 18px;
    }
    .crop-handle-nw { top: -9px;  left: -9px; }
    .crop-handle-n  { top: -9px;  margin-left: -9px; }
    .crop-handle-ne { top: -9px;  right: -9px; }
    .crop-handle-e  { right: -9px; margin-top: -9px; }
    .crop-handle-se { bottom: -9px; right: -9px; }
    .crop-handle-s  { bottom: -9px; margin-left: -9px; }
    .crop-handle-sw { bottom: -9px; left: -9px; }
    .crop-handle-w  { left: -9px; margin-top: -9px; }
}

/* ============================================================
   Remove Background
   ============================================================ */
.rb-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    margin-bottom: 0.75rem;
    background: var(--amber-light, #fef3c7);
    border-left: 3px solid var(--amber, #d97706);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.rb-warning i {
    color: var(--amber, #d97706);
    flex-shrink: 0;
    margin-top: 0.15rem;
}

[data-theme="dark"] .rb-warning {
    background: #2b2013;
    color: #fcd34d;
}

[data-theme="dark"] .rb-warning i {
    color: #fbbf24;
}

.rb-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 60vh;
    min-height: 320px;
    max-height: 640px;
    background-color: #f0f0f0;
    background-image:
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
        linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.rb-canvas-wrapper.rb-panning {
    cursor: grabbing;
}

.rb-canvas-wrapper.rb-canvas-pick {
    cursor: crosshair;
}

.rb-canvas-wrapper.rb-canvas-pick.rb-panning {
    cursor: grabbing;
}

.rb-canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    transform-origin: 0 0;
    will-change: transform;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
    image-rendering: auto;
}

.rb-zoom-controls {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    display: flex;
    align-items: stretch;
    gap: 0;
    background: rgba(0, 0, 0, 0.72);
    border-radius: var(--radius-sm);
    padding: 0.15rem;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.rb-zoom-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.rb-zoom-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.rb-zoom-level {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
    color: #fff;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    min-width: 3.25rem;
    user-select: none;
}

[data-theme="dark"] .rb-canvas-wrapper {
    background-color: #2a2a2a;
    background-image:
        linear-gradient(45deg, #1a1a1a 25%, transparent 25%),
        linear-gradient(-45deg, #1a1a1a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #1a1a1a 75%),
        linear-gradient(-45deg, transparent 75%, #1a1a1a 75%);
}

.rb-regions-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.rb-regions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary, #6c757d);
}

.rb-regions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    max-height: 12rem;
    overflow-y: auto;
}

.rb-region-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.4rem 0.3rem 0.35rem;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    font-size: 0.78rem;
    color: var(--text-primary);
    transition: border-color 0.15s;
}

.rb-region-chip:hover {
    border-color: var(--accent, #0d6efd);
}

.rb-region-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}

.rb-region-dot-auto {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent, #0d6efd);
    color: #fff;
    font-size: 0.6rem;
    border: none;
    line-height: 1;
}

.rb-region-label {
    max-width: 9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: ltr;
}

.rb-region-remove {
    background: transparent;
    border: none;
    color: var(--text-tertiary, #999);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.2rem;
    border-radius: 50%;
    transition: all 0.15s;
}

.rb-region-remove:hover {
    color: #ef4444;
    background: #fee2e2;
}

[data-theme="dark"] .rb-region-chip {
    background: #1a1a1a;
}

[data-theme="dark"] .rb-region-remove:hover {
    background: #2b1010;
}

/* ============================================================
   AI — Model storage section
   ============================================================ */
.model-storage-section {
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

#model-status-badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

#directory-picker-section {
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border-color);
}

/* ============================================================
   AI — Custom progress bar (bulletproof, overrides Bootstrap)
   ============================================================ */
.ai-progress {
    display: block !important;
    width: 100% !important;
    height: 16px !important;
    background-color: #e5e7eb !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    position: relative !important;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08) !important;
}

.ai-progress-fill {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    height: 100% !important;
    width: 0;
    border-radius: 8px !important;
    transition: width 0.35s ease, background-color 0.3s ease !important;
    background-color: #3b82f6;
    background-image: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.28) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255, 255, 255, 0.28) 50%,
        rgba(255, 255, 255, 0.28) 75%,
        transparent 75%,
        transparent
    );
    background-size: 1rem 1rem;
    animation: aiProgressStripes 1s linear infinite;
}

/* State: preparing (blue, striped, animated) */
.ai-progress-fill[data-state="preparing"] {
    background-color: #3b82f6 !important;
}

/* State: processing (green, striped, animated) */
.ai-progress-fill[data-state="processing"] {
    background-color: #22c55e !important;
}

/* State: done (green, solid) */
.ai-progress-fill[data-state="done"] {
    background-color: #22c55e !important;
    background-image: none !important;
    animation: none !important;
}

/* State: error (red, solid) */
.ai-progress-fill[data-state="error"] {
    background-color: #ef4444 !important;
    background-image: none !important;
    animation: none !important;
}

/* State: cancelled (gray, solid) */
.ai-progress-fill[data-state="cancelled"] {
    background-color: #9ca3af !important;
    background-image: none !important;
    animation: none !important;
}

@keyframes aiProgressStripes {
    0%   { background-position-x: 1rem; }
    100% { background-position-x: 0; }
}

/* Dark theme adjustments */
[data-theme="dark"] .ai-progress {
    background-color: #1f2937 !important;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .ai-progress-fill[data-state="preparing"] {
    background-color: #3b82f6 !important;
}

[data-theme="dark"] .ai-progress-fill[data-state="processing"],
[data-theme="dark"] .ai-progress-fill[data-state="done"] {
    background-color: #16a34a !important;
}

[data-theme="dark"] .ai-progress-fill[data-state="error"] {
    background-color: #dc2626 !important;
}

[data-theme="dark"] .ai-progress-fill[data-state="cancelled"] {
    background-color: #6b7280 !important;
}

/* ============================================================
   AI — WASM warning box
   ============================================================ */
.ai-wasm-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.9rem;
    margin-top: 0.85rem;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-left: 4px solid #d97706;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.55;
    color: #78350f;
    animation: aiWasmFadeIn 0.3s ease;
}

.ai-wasm-warning i {
    color: #d97706;
    flex-shrink: 0;
    margin-top: 0.15rem;
    font-size: 1rem;
}

.ai-wasm-warning strong {
    color: #92400e;
    font-weight: 600;
}

.ai-wasm-warning div {
    flex: 1;
    min-width: 0;
}

@keyframes aiWasmFadeIn {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: translateY(0); }
}

[data-theme="dark"] .ai-wasm-warning {
    background: #2b2013;
    border-color: #78350f;
    border-left-color: #f59e0b;
    color: #fcd34d;
}

[data-theme="dark"] .ai-wasm-warning i {
    color: #fbbf24;
}

[data-theme="dark"] .ai-wasm-warning strong {
    color: #fbbf24;
}


/* ============================================================
   AI — Hub category badge
   ============================================================ */
.ai-cat-count {
    display: inline-block;
    padding: 0.35em 0.75em;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    border-radius: 999px;
    background: var(--accent-light, #e7f0ff);
    color: var(--accent, #0d6efd);
    border: 1px solid transparent;
}

[data-theme="dark"] .ai-cat-count {
    background: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
    border-color: rgba(96, 165, 250, 0.3);
}