.ciw-crop-widget {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--ci-text-primary, #ffffff);

    /* Dark / hero-section theme (scoped so unit converters keep their light theme) */
    --ci-primary: #0058be;
    --ci-primary-dark: #004a9c;
    --ci-primary-light: #3b82f6;
    --ci-background: rgb(37, 47, 74);
    --ci-input-background: rgba(255, 255, 255, 0.05);
    --ci-surface: rgba(255, 255, 255, 0.05);
    --ci-border: rgba(255, 255, 255, 0.1);
    --ci-text-primary: #ffffff;
    --ci-text-secondary: rgba(255, 255, 255, 0.6);
    --ci-text-tertiary: rgba(255, 255, 255, 0.4);
    --ci-shadow-base: 0 3px 0 0 rgba(0, 0, 0, 0.15);
    --ci-shadow-lg: 0 3px 0 0 rgba(0, 0, 0, 0.15);
}

.ciw-crop-upload-area {
    margin-bottom: 0;
}

.ciw-crop-editor {
    display: none;
}

.ciw-crop-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    min-height: 400px;
}

.ciw-crop-preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--ci-background);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: var(--ci-radius-md, 12px);
    overflow: hidden;
}

.ciw-crop-preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--ci-surface, #f8fafc);
    position: relative;
    overflow: hidden;
    min-height: 300px;
    max-height: 560px;
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

.ciw-crop-preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    pointer-events: none;
}

.ciw-crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.ciw-crop-overlay-top,
.ciw-crop-overlay-bottom,
.ciw-crop-overlay-left,
.ciw-crop-overlay-right {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.ciw-crop-overlay-top {
    top: 0;
    left: 0;
    right: 0;
}

.ciw-crop-overlay-bottom {
    bottom: 0;
    left: 0;
    right: 0;
}

.ciw-crop-overlay-left {
    top: 0;
    left: 0;
    bottom: 0;
}

.ciw-crop-overlay-right {
    top: 0;
    right: 0;
    bottom: 0;
}

.ciw-crop-selection {
    position: absolute;
    border: 2px solid var(--ci-primary, #2563eb);
    cursor: move;
    z-index: 3;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.ciw-crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid var(--ci-primary, #2563eb);
    border-radius: 2px;
    z-index: 4;
}

.ciw-crop-handle[data-handle="nw"] {
    top: -6px;
    left: -6px;
    cursor: nw-resize;
}

.ciw-crop-handle[data-handle="n"] {
    top: -6px;
    left: 50%;
    margin-left: -6px;
    cursor: n-resize;
}

.ciw-crop-handle[data-handle="ne"] {
    top: -6px;
    right: -6px;
    cursor: ne-resize;
}

.ciw-crop-handle[data-handle="w"] {
    top: 50%;
    left: -6px;
    margin-top: -6px;
    cursor: w-resize;
}

.ciw-crop-handle[data-handle="e"] {
    top: 50%;
    right: -6px;
    margin-top: -6px;
    cursor: e-resize;
}

.ciw-crop-handle[data-handle="sw"] {
    bottom: -6px;
    left: -6px;
    cursor: sw-resize;
}

.ciw-crop-handle[data-handle="s"] {
    bottom: -6px;
    left: 50%;
    margin-left: -6px;
    cursor: s-resize;
}

.ciw-crop-handle[data-handle="se"] {
    bottom: -6px;
    right: -6px;
    cursor: se-resize;
}

.ciw-crop-image-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--ci-border, #e2e8f0);
    background: var(--ci-surface, #f8fafc);
    font-size: 0.75rem;
    color: var(--ci-text-secondary, #64748b);
}

.ciw-crop-settings-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    background: var(--ci-background);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: var(--ci-radius-md, 12px);
    overflow-y: auto;
    max-height: 600px;
    scrollbar-width: thin;
    scrollbar-color: var(--ci-primary, #2563eb) var(--ci-surface, #f8fafc);
}

.ciw-crop-settings-panel::-webkit-scrollbar {
    width: 6px;
}

.ciw-crop-settings-panel::-webkit-scrollbar-track {
    background: var(--ci-surface, #f8fafc);
    border-radius: 3px;
}

.ciw-crop-settings-panel::-webkit-scrollbar-thumb {
    background: var(--ci-primary, #2563eb);
    border-radius: 3px;
}

.ciw-crop-settings-panel::-webkit-scrollbar-thumb:hover {
    background: var(--ci-primary-dark, #1d4ed8);
}

.ciw-crop-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ciw-crop-settings-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ci-text-primary, #0f172a);
    margin: 0;
}

.ciw-crop-reset-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--ci-text-secondary, #64748b);
    background: var(--ci-surface, #f8fafc);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ciw-crop-reset-btn:hover {
    color: var(--ci-primary, #0058be);
    border-color: var(--ci-primary, #0058be);
    background: rgba(0, 88, 190, 0.2);
}

.ciw-crop-control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ciw-crop-control-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--ci-text-secondary, #64748b);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ciw-crop-control-hint {
    font-size: 0.75rem;
    color: var(--ci-text-tertiary, #94a3b8);
}

.ciw-crop-ratio-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ciw-crop-ratio-btn {
    padding: 6px 14px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--ci-text-secondary, #64748b);
    background: var(--ci-surface, #f8fafc);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ciw-crop-ratio-icon {
    display: inline-block;
    border: 2px solid currentColor;
    border-radius: 1px;
    flex-shrink: 0;
}

.ciw-crop-ratio-btn:hover {
    color: var(--ci-primary, #2563eb);
    border-color: var(--ci-primary, #2563eb);
}

.ciw-crop-ratio-btn:hover .ciw-crop-ratio-icon {
    border-color: var(--ci-primary, #2563eb);
}

.ciw-crop-ratio-active:hover .ciw-crop-ratio-icon {
    border-color: #fff;
}

.ciw-crop-ratio-btn.ciw-crop-ratio-active {
    color: #fff;
    background: var(--ci-primary, #2563eb);
    border-color: var(--ci-primary, #2563eb);
}

.ciw-crop-ratio-active .ciw-crop-ratio-icon {
    border-color: #fff;
}

.ciw-crop-invert-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--ci-surface, #f8fafc);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 6px;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.ciw-crop-invert-row.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.ciw-crop-invert-label {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ci-text-primary, #0f172a);
}

.ciw-crop-invert-label .ciw-crop-control-hint {
    font-size: 0.6875rem;
}

.ciw-crop-switch {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.ciw-crop-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.ciw-crop-switch-slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    transition: background 0.25s ease;
    cursor: pointer;
}

.ciw-crop-switch-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.ciw-crop-switch input:checked + .ciw-crop-switch-slider {
    background: var(--ci-primary, #2563eb);
}

.ciw-crop-switch input:checked + .ciw-crop-switch-slider::after {
    transform: translateX(16px);
}

.ciw-crop-switch input:disabled + .ciw-crop-switch-slider {
    cursor: not-allowed;
    opacity: 0.5;
}

.ciw-crop-dimensions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ciw-crop-dim-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--ci-text-primary, #0f172a);
    background-color: var(--ci-surface, #f8fafc);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
    -moz-appearance: textfield;
}

.ciw-crop-dim-input::-webkit-outer-spin-button,
.ciw-crop-dim-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ciw-crop-dim-input:focus {
    outline: none;
    border-color: var(--ci-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.ciw-crop-slider-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ciw-crop-quality-slider {
    flex: 1;
    height: 6px;
    appearance: none;
    background: var(--ci-border, #e2e8f0);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.ciw-crop-quality-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ci-primary, #2563eb);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
    transition: transform 0.15s ease;
}

.ciw-crop-quality-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.ciw-crop-quality-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ci-primary, #2563eb);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

.ciw-crop-slider-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ci-text-primary, #0f172a);
    min-width: 40px;
    text-align: right;
}

.ciw-crop-format-select {
    width: 100%;
    padding: 10px 36px 10px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--ci-text-primary, #0f172a);
    background-color: var(--ci-surface, #f8fafc);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 13px 13px;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.ciw-crop-format-select:focus {
    outline: none;
    border-color: var(--ci-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.ciw-crop-widget option {
    color: #0f172a;
    background: #ffffff;
}

.ciw-crop-convert-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 24px;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: var(--ci-primary, #2563eb);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    margin-top: 8px;
}

.ciw-crop-convert-btn:hover {
    background: var(--ci-primary-dark, #1d4ed8);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.ciw-crop-convert-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.ciw-crop-cancel-btn {
    width: 100%;
    padding: 10px 24px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--ci-text-secondary, #64748b);
    background: var(--ci-background);
    border: 1px solid var(--ci-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ciw-crop-cancel-btn:hover {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.1);
}

.ciw-crop-message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
}

.ciw-crop-message.is-error {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.ciw-crop-message.is-success {
    background: rgba(34, 197, 94, 0.1);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

@media (max-width: 768px) {
    .ciw-crop-widget {
        background-color: unset;
        border: unset;
        box-shadow: unset;
        padding: 0px;
    }

    .ciw-crop-widget:hover {
        box-shadow: unset;
    }

    .ciw-crop-layout {
        grid-template-columns: 1fr;
    }

    .ciw-crop-settings-panel {
        max-height: none;
    }
}

@media (max-width: 480px) {
    .ciw-crop-image-info {
        background: rgba(255, 255, 255, 0.05);
        font-size: 0.70rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .ciw-crop-preview-container {
        padding: 0px;
        min-height: 200px;
    }

    .ciw-crop-settings-panel {
        padding: 16px;
    }

    .ciw-crop-ratio-group {
        gap: 4px;
    }

    .ciw-crop-ratio-btn {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .ciw-crop-dimensions-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .ciw-crop-handle {
        width: 10px;
        height: 10px;
    }

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