/* ===========================================================================
   IMAGE COMPRESSOR — the tool's own interface.

   Same rules as background-remover-styling.css next door: every colour is a
   site token or derived from one, so the panel follows the reader's theme
   instead of carrying a palette of its own. --ic-* below are only for values
   that stay fixed regardless of theme — the transparency checkerboard on the
   preview stage is the one deliberate exception, same reasoning as br's.
   =========================================================================== */

.ic-app {
    --ic-surface: var(--color-primary-a10);
    --ic-surface-raised: var(--color-primary-a20);
    --ic-border: var(--color-card-border);
    --ic-border-strong: var(--color-primary-a20);

    --ic-checker-a: #4a4a4a;
    --ic-checker-b: #5c5c5c;

    --ic-mono: "JetBrains Mono", "Fira Mono", "Consolas", ui-monospace, monospace;
    --ic-sans: "Circular Spotify", "Inter", sans-serif;

    font-family: var(--ic-sans);
    color: var(--color-text-1);

    display: flex;
    flex-direction: column;
    background: var(--ic-surface);
    border: 1px solid var(--ic-border);
    border-radius: 16px;
    overflow: hidden;
}

.ic-app :is(button, input, select, a):focus-visible {
    outline: 2px solid var(--color-selected-3);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   Toolbar
   --------------------------------------------------------------------------- */

.ic-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--ic-surface-raised);
    border-bottom: 1px solid var(--ic-border);
}

.ic-toolbar-spacer { margin-left: auto; }

.ic-file-count {
    font-family: var(--ic-mono);
    font-size: 12px;
    color: var(--color-text-2);
}

.ic-sep {
    width: 1px;
    align-self: stretch;
    min-height: 22px;
    background: var(--ic-border-strong);
    margin: 0 2px;
}

/* ---------------------------------------------------------------------------
   Buttons — identical contract to .br-btn next door.
   --------------------------------------------------------------------------- */

.ic-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--ic-border-strong);
    background: transparent;
    color: var(--color-text-2);
    font-family: var(--ic-sans);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color var(--dur-hover) var(--ease-soft),
        border-color var(--dur-hover) var(--ease-soft),
        color var(--dur-hover) var(--ease-soft),
        transform var(--dur-hover) var(--ease-pop);
}

@media (hover: hover) {
    .ic-btn:hover:not(:disabled) {
        background: var(--color-primary-a20);
        border-color: var(--color-primary-a30);
        color: var(--color-text-1);
    }
}

.ic-btn:active:not(:disabled) {
    transform: scale(0.97);
    transition-duration: var(--dur-press);
}

.ic-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ic-btn--primary {
    background: var(--color-selected-2);
    border-color: var(--color-selected-2);
    color: #ffffff;
    padding: 8px 18px;
    font-size: 13px;
}

@media (hover: hover) {
    .ic-btn--primary:hover:not(:disabled) {
        background: var(--color-selected-3);
        border-color: var(--color-selected-3);
        color: #06121e;
    }
}

.ic-btn--accent { color: var(--color-accent-text); border-color: var(--color-selected-1); }

@media (hover: hover) {
    .ic-btn--accent:hover:not(:disabled) {
        background: rgba(91, 148, 198, 0.14);
        border-color: var(--color-selected-2);
        color: var(--color-accent-text);
    }
}

.ic-btn--wide { width: 100%; }

/* ---------------------------------------------------------------------------
   Choice pills — format and resize-mode radios, same idiom as .br-choice.
   --------------------------------------------------------------------------- */

.ic-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.ic-choice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--ic-border-strong);
    font-family: var(--ic-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-2);
    cursor: pointer;
    transition:
        border-color var(--dur-hover) var(--ease-soft),
        background-color var(--dur-hover) var(--ease-soft),
        color var(--dur-hover) var(--ease-soft);
}

.ic-choice input { accent-color: var(--color-selected-2); margin: 0; }
.ic-choice input:disabled { cursor: not-allowed; }

.ic-choice-hint { color: var(--color-primary-a30); font-weight: 400; font-size: 11px; }

.ic-choice:has(input:checked) {
    border-color: var(--color-selected-2);
    background: rgba(91, 148, 198, 0.16);
    color: var(--color-text-1);
}

/* :has() fallback — the script mirrors checked state onto .is-checked. */
.ic-choice.is-checked {
    border-color: var(--color-selected-2);
    background: rgba(91, 148, 198, 0.16);
    color: var(--color-text-1);
}

.ic-choice:has(input:disabled) { opacity: 0.45; }

.ic-app.is-busy .ic-choices { opacity: 0.5; pointer-events: none; }

/* ---------------------------------------------------------------------------
   Drop zone
   --------------------------------------------------------------------------- */

.ic-drop {
    margin: 12px;
    padding: 28px 20px;
    border: 2px dashed var(--ic-border-strong);
    border-radius: 12px;
    text-align: center;
    color: var(--color-text-2);
    font-size: 13px;
    line-height: 1.6;
    transition:
        border-color var(--dur-hover) var(--ease-soft),
        background-color var(--dur-hover) var(--ease-soft);
}

.ic-app.is-dragging .ic-drop {
    border-color: var(--color-selected-2);
    background: rgba(91, 148, 198, 0.1);
}

.ic-drop strong { display: block; color: var(--color-text-1); font-size: 15px; margin-bottom: 6px; }
.ic-drop-hint { display: block; margin-top: 10px; font-size: 12px; color: var(--color-primary-a30); }

/* ---------------------------------------------------------------------------
   Layout — preview + queue on the left, settings on the right. One column
   below 900px, same threshold as background-remover's.
   --------------------------------------------------------------------------- */

.ic-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 12px; padding: 12px; align-items: start; }

@media (max-width: 900px) {
    .ic-body { grid-template-columns: 1fr; }
}

.ic-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.ic-panel { background: var(--color-primary-a0); border: 1px solid var(--ic-border); border-radius: 12px; padding: 14px; }

.ic-panel-title {
    display: block;
    margin: 0 0 12px;
    font-family: var(--ic-sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-primary-a30);
}

.ic-panel-hint { margin: 10px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--color-primary-a30); }

/* ---------------------------------------------------------------------------
   Preview stage — original and compressed layered with a draggable divider.
   Sized off the photo's own aspect ratio, same --stage-ratio trick as br.
   --------------------------------------------------------------------------- */

.ic-stage {
    --ic-stage-ratio: 4 / 3;
    --ic-split: 50%;
    position: relative;
    width: 100%;
    aspect-ratio: var(--ic-stage-ratio);
    max-height: 70vh;
    border-radius: 8px;
    overflow: hidden;
    touch-action: none; /* a drag on the handle shouldn't also scroll the page on touch */
    /* A pointerdown-drag anywhere on the stage is how the comparator moves,
       not a text/image selection gesture — without this, dragging across the
       badges or the photo itself paints a blue selection highlight over
       everything the drag crossed, same as it would over any other text. */
    user-select: none;
    -webkit-user-select: none;
    background-image:
        linear-gradient(45deg, var(--ic-checker-a) 25%, transparent 25%),
        linear-gradient(-45deg, var(--ic-checker-a) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--ic-checker-a) 75%),
        linear-gradient(-45deg, transparent 75%, var(--ic-checker-a) 75%);
    background-color: var(--ic-checker-b);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.ic-app.has-active-result .ic-stage { cursor: ew-resize; }

.ic-compare-layer { position: absolute; inset: 0; }
.ic-compare-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    -webkit-user-drag: none; /* stops a slow drag on the handle from picking the photo up as an OS-level image drag instead */
}

/* The "after" layer sits on top and is clipped to the right of the split —
   the "before" layer underneath is only actually visible on the left of it,
   never redrawn or repositioned itself. Dragging the split is therefore just
   one CSS custom property changing; nothing here re-renders per frame. */
.ic-layer-after { clip-path: inset(0 0 0 var(--ic-split)); }

.ic-app:not(.has-active-result) .ic-layer-after,
.ic-app:not(.has-active-result) .ic-compare-handle,
.ic-app:not(.has-active-result) .ic-badge-after {
    display: none;
}

.ic-compare-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--ic-split);
    width: 40px;
    margin-left: -20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    cursor: ew-resize;
}

.ic-compare-handle::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: #ffffff;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
    transform: translateX(-50%);
    pointer-events: none;
}

.ic-compare-grip {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ffffff;
    color: #1d1d1d;
    display: grid;
    place-items: center;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.ic-compare-handle:focus-visible {
    outline: none;
}

.ic-compare-handle:focus-visible .ic-compare-grip {
    outline: 2px solid var(--color-selected-3);
    outline-offset: 2px;
}

.ic-compare-badge {
    position: absolute;
    top: 10px;
    z-index: 2;
    padding: 4px 10px;
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    font-family: var(--ic-sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    pointer-events: none;
}

.ic-badge-before { left: 10px; }
.ic-badge-after { right: 10px; }

.ic-app:not(.has-active) .ic-compare-badge { display: none; }

.ic-stage-empty-hint {
    display: none;
    margin: 0;
    padding: 40px 20px;
    text-align: center;
    font-size: 13px;
    color: var(--color-text-2);
}

.ic-app.has-image:not(.has-active) .ic-stage { display: none; }
.ic-app.has-image:not(.has-active) .ic-stage-empty-hint { display: block; }

/* ---------------------------------------------------------------------------
   Busy overlay — shown only for the multi-photo Compress-all run. Live
   preview's own per-photo recompute deliberately stays quiet (see
   image-compressor.js) so dragging a slider never flashes this.
   --------------------------------------------------------------------------- */

.ic-stage-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.55);
    text-align: center;
}

.ic-app.is-busy .ic-stage-overlay { display: flex; }

.ic-spinner {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #ffffff;
    animation: ic-spin 0.8s linear infinite;
}

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

.ic-stage-overlay-text { font-family: var(--ic-sans); font-size: 12.5px; font-weight: 600; color: #ffffff; max-width: 44ch; }

.ic-progress { display: none; width: min(260px, 100%); height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
.ic-progress.is-active { display: block; }
.ic-progress-bar { width: 0%; height: 100%; background: var(--color-selected-3); border-radius: inherit; transition: width 0.15s linear; }

/* ---------------------------------------------------------------------------
   Actions under the stage
   --------------------------------------------------------------------------- */

.ic-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------------------------------------------------------------------------
   Queue — every photo that's been added, click to preview, × to drop it.
   --------------------------------------------------------------------------- */

.ic-queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }

.ic-queue-empty { margin: 0; font-size: 12.5px; color: var(--color-primary-a30); }

.ic-queue-item {
    display: flex;
    align-items: stretch;
    border-radius: 10px;
    background: var(--color-primary-a0);
    border: 1px solid var(--ic-border);
    overflow: hidden;
}

.ic-queue-item.is-active { border-color: var(--color-selected-2); box-shadow: inset 0 0 0 1px var(--color-selected-2); }
.ic-queue-item.is-error { border-color: var(--color-warning-2); }

.ic-queue-select {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 6px 8px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font-family: var(--ic-sans);
}

.ic-queue-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--color-primary-a10); }

.ic-queue-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ic-queue-name { font-size: 12px; font-weight: 600; color: var(--color-text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic-queue-stat { font-size: 11px; color: var(--color-text-2); }
.ic-queue-item.is-error .ic-queue-stat { color: var(--color-warning-2); }

.ic-queue-remove {
    width: 32px;
    flex-shrink: 0;
    border: none;
    border-left: 1px solid var(--ic-border);
    background: none;
    color: var(--color-primary-a30);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--dur-hover) var(--ease-soft), color var(--dur-hover) var(--ease-soft);
}

@media (hover: hover) {
    .ic-queue-remove:hover { color: var(--color-warning-2); background: rgba(231, 140, 140, 0.1); }
}

.ic-queue-foot { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---------------------------------------------------------------------------
   Presets
   --------------------------------------------------------------------------- */

.ic-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.ic-preset-btn {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--ic-border-strong);
    background: var(--color-primary-a0);
    cursor: pointer;
    text-align: left;
    transition:
        border-color var(--dur-hover) var(--ease-soft),
        background-color var(--dur-hover) var(--ease-soft),
        transform var(--dur-hover) var(--ease-pop);
}

@media (hover: hover) {
    .ic-preset-btn:hover { border-color: var(--color-selected-2); background: rgba(91, 148, 198, 0.1); }
}

.ic-preset-btn:active { transform: scale(0.97); transition-duration: var(--dur-press); }

.ic-preset-name { font-size: 12.5px; font-weight: 700; color: var(--color-text-1); font-family: var(--ic-sans); }
.ic-preset-hint { font-size: 10.5px; color: var(--color-primary-a30); font-family: var(--ic-sans); }

/* ---------------------------------------------------------------------------
   Fields — labelled sliders, number inputs, checkboxes and the flatten
   colour swatch. One idiom shared by every setting in the Format/Advanced
   panels rather than a different layout per control.
   --------------------------------------------------------------------------- */

.ic-field { margin-bottom: 12px; }
.ic-field:last-child { margin-bottom: 0; }

.ic-field-label {
    display: block;
    margin-bottom: 6px;
    font-family: var(--ic-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-2);
}

.ic-field-row { display: flex; align-items: center; gap: 8px; }

.ic-range {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--ic-border-strong);
    cursor: pointer;
}

.ic-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-selected-2);
    border: 2px solid var(--ic-surface);
    cursor: pointer;
}

.ic-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-selected-2);
    border: 2px solid var(--ic-surface);
    cursor: pointer;
}

.ic-range:disabled { opacity: 0.4; cursor: not-allowed; }

/* Bigger grab target on touch. A 16px thumb is sized for a mouse cursor,
   not a fingertip, and a slider is the one control on this page where a
   slightly-off tap can't just be retried like a mis-tapped button can, it
   drags to the wrong value instead. */
@media (pointer: coarse) {
    .ic-range {
        height: 8px;
    }

    .ic-range::-webkit-slider-thumb {
        width: 26px;
        height: 26px;
    }

    .ic-range::-moz-range-thumb {
        width: 26px;
        height: 26px;
    }
}

.ic-number {
    width: 56px;
    flex-shrink: 0;
    padding: 5px 6px;
    border-radius: 6px;
    border: 1px solid var(--ic-border-strong);
    background: var(--color-primary-a0);
    color: var(--color-text-1);
    font-family: var(--ic-mono);
    font-size: 12px;
    text-align: center;
}

.ic-number--wide { width: 76px; }
.ic-output { display: inline-flex; align-items: center; justify-content: center; }
.ic-unit { font-size: 11px; color: var(--color-primary-a30); }

.ic-exact-pair { }
.ic-exact-x { color: var(--color-primary-a30); font-size: 12px; }

.ic-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--ic-sans);
    font-size: 12.5px;
    color: var(--color-text-2);
    cursor: pointer;
    margin-bottom: 10px;
}

.ic-checkbox-row:last-child { margin-bottom: 0; }
.ic-checkbox-row input[type="checkbox"] { accent-color: var(--color-selected-2); width: 15px; height: 15px; margin: 0; flex-shrink: 0; }
.ic-checkbox-row input[type="checkbox"]:disabled { cursor: not-allowed; }
.ic-checkbox-row:has(input:disabled) { opacity: 0.55; }

.ic-swatch-btn {
    position: relative;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 8px;
    border: 2px solid var(--ic-border-strong);
    overflow: hidden;
    cursor: pointer;
    display: inline-block;
}

.ic-swatch { display: block; width: 100%; height: 100%; }

.ic-swatch-btn input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: none;
    opacity: 0;
    cursor: pointer;
}

/* ---------------------------------------------------------------------------
   Conditional visibility — every "only relevant when…" control keys off one
   of these attributes/classes on .ic-app rather than JS toggling inline
   styles, so the rule and its reason live in one readable place.
   --------------------------------------------------------------------------- */

.ic-app:not([data-resize-mode="fit"]) .ic-fit-row { display: none; }
.ic-app:not([data-resize-mode="exact"]) .ic-exact-row { display: none; }
.ic-app:not([data-resize-mode="percent"]) .ic-percent-row { display: none; }

/* PNG has no quality dial and Target size has nothing continuous to search
   over for it — Colours (its own lever) is the only one PNG shows. */
.ic-app[data-format="png"] .ic-quality-row,
.ic-app[data-format="png"] .ic-target-row {
    display: none;
}
.ic-app:not([data-format="png"]) .ic-colors-row { display: none; }

/* Target size drives quality itself once it's on — the manual slider stays
   visible for context but stops being the thing in control. */
.ic-app.target-on .ic-quality-row { opacity: 0.45; pointer-events: none; }

.ic-app:not(.adv-open) .ic-advanced-body { display: none; }

.ic-advanced-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px dashed var(--ic-border-strong);
    background: none;
    color: var(--color-text-2);
    font-family: var(--ic-sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--dur-hover) var(--ease-soft), color var(--dur-hover) var(--ease-soft);
}

@media (hover: hover) {
    .ic-advanced-toggle:hover { background: var(--color-primary-a10); color: var(--color-text-1); }
}

.ic-advanced-body { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--ic-border); }

/* ---------------------------------------------------------------------------
   Status, caution and the status bar — identical contract to br's.
   --------------------------------------------------------------------------- */

.ic-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 24px;
    font-size: 11.5px;
    font-weight: 600;
}

.ic-status:empty { display: none; }

.ic-status[data-tone="ok"] { background: rgba(74, 222, 128, 0.14); color: #38b869; }
:root:not([data-theme="light"]) .ic-status[data-tone="ok"] { color: #4ade80; }

.ic-status[data-tone="error"] { background: rgba(231, 140, 140, 0.16); color: var(--color-warning-2); }
:root:not([data-theme="light"]) .ic-status[data-tone="error"] { color: var(--color-warning-1); }

.ic-status[data-tone="info"] { background: rgba(91, 148, 198, 0.16); color: var(--color-accent-text); }

.ic-caution {
    margin: 12px 0 0;
    padding: 9px 11px;
    border-radius: 8px;
    border-left: 3px solid var(--color-warning-2);
    background: rgba(231, 140, 140, 0.1);
    font-size: 11.5px;
    line-height: 1.55;
    color: var(--color-text-2);
}

.ic-caution strong { color: var(--color-text-1); }
.ic-caution[hidden] { display: none; }

.ic-statusbar {
    padding: 9px 12px;
    border-top: 1px solid var(--ic-border);
    background: var(--ic-surface-raised);
    font-size: 12px;
    color: var(--color-text-2);
}

/* ---------------------------------------------------------------------------
   Loaded / busy state gates — same pattern as background-remover's.
   --------------------------------------------------------------------------- */

.ic-app:not(.has-image) [data-needs-image] { display: none; }
.ic-app.has-image .ic-drop { display: none; }

.ic-app.is-busy #ic-open,
.ic-app.is-busy #ic-drop-open,
.ic-app.is-busy #ic-run,
.ic-app.is-busy #ic-download,
.ic-app.is-busy #ic-download-all,
.ic-app.is-busy .ic-preset-btn {
    opacity: 0.5;
    pointer-events: none;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 700px) {
    .ic-file-count { width: 100%; order: 1; }
}

@media (max-width: 480px) {
    .ic-presets { grid-template-columns: 1fr; }
}
