/*
 * compress.css - Squoosh style image compressor
 * Two column workbench: an image queue on the left, the before and after
 * comparison plus the encoder settings on the right.
 */

/* ========== workbench shell ========== */
.compress-workbench {
    display: grid;
    grid-template-columns: minmax(300px, 350px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.compress-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--box-shadow);
    padding: 1.25rem;
}

/* ========== left column: queue ========== */
.compress-queue {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 5.5rem;
}

.queue-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.75rem 1.25rem;
    background: var(--surface-muted);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    text-align: center;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.queue-dropzone.is-dragging {
    border-color: var(--primary-color);
    background: var(--primary-soft);
}

.queue-dropzone > i {
    font-size: 1.9rem;
    color: var(--primary-color);
}

.queue-dropzone h3 {
    font-size: 1rem;
    font-weight: 700;
}

.queue-dropzone p {
    color: var(--light-text);
    font-size: 0.85rem;
}

.queue-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.queue-actions .btn {
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
}

.queue-note {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.4rem;
    color: var(--light-text);
    font-size: 0.78rem;
}

.queue-panel {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--box-shadow);
    overflow: hidden;
}

.queue-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.queue-panel-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

.queue-panel-header h3 span {
    color: var(--primary-color);
}

.queue-panel-header p {
    color: var(--light-text);
    font-size: 0.8rem;
}

.queue-panel-header .btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
}

.queue-list {
    max-height: 46vh;
    overflow-y: auto;
    list-style: none;
}

.queue-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid transparent;
    transition: background-color 0.15s ease;
}

.queue-row:last-child {
    border-bottom: none;
}

.queue-row:hover {
    background: var(--surface-muted);
}

.queue-row.is-selected {
    background: var(--primary-soft);
    border-left-color: var(--primary-color);
}

.queue-item {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: none;
    border: none;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.queue-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    background-color: var(--surface-muted);
    background-image: linear-gradient(45deg, #eef1f6 25%, transparent 25%, transparent 75%, #eef1f6 75%),
        linear-gradient(45deg, #eef1f6 25%, transparent 25%, transparent 75%, #eef1f6 75%);
    background-size: 12px 12px;
    background-position: 0 0, 6px 6px;
    border-radius: 8px;
}

.queue-info {
    min-width: 0;
}

.queue-name {
    display: block;
    overflow: hidden;
    font-size: 0.85rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-meta {
    display: block;
    color: var(--light-text);
    font-size: 0.75rem;
}

.queue-saved {
    color: var(--secondary-hover);
    font-weight: 700;
}

.queue-error {
    color: var(--primary-hover);
}

.queue-item-actions {
    display: flex;
    gap: 0.25rem;
    padding-right: 0.6rem;
}

.queue-item-actions button {
    width: 30px;
    height: 30px;
    color: var(--light-text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.queue-item-actions button:hover {
    color: var(--primary-color);
    background: var(--surface);
    border-color: var(--border-color);
}

.queue-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--border-color);
}

.queue-footer .btn {
    flex: 1 1 auto;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
}

/* ========== right column ========== */
.compress-main {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;
}

.compare-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
}

.compare-file strong {
    display: block;
    overflow: hidden;
    max-width: 340px;
    font-size: 0.95rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compare-file span {
    color: var(--light-text);
    font-size: 0.8rem;
}

.compare-zoom {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.compare-zoom button {
    min-width: 38px;
    height: 34px;
    padding: 0 0.55rem;
    color: var(--light-text);
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.compare-zoom button:hover,
.compare-zoom button.is-active {
    color: var(--primary-hover);
    background: var(--primary-soft);
    border-color: rgba(239, 68, 68, 0.35);
}

.compare-zoom output {
    min-width: 56px;
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
}

/* ========== before and after comparison ========== */
.compare-viewport {
    position: relative;
    display: block;
    max-height: min(62vh, 620px);
    padding: 0.5rem;
    overflow: auto;
    background-color: #f1f4f9;
    background-image: linear-gradient(45deg, #e4e9f1 25%, transparent 25%, transparent 75%, #e4e9f1 75%),
        linear-gradient(45deg, #e4e9f1 25%, transparent 25%, transparent 75%, #e4e9f1 75%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    text-align: center;
}

.compare-stage {
    position: relative;
    display: none;
    width: 100%;
    margin: 0 auto;
    touch-action: pan-y;
    user-select: none;
}

.compare-stage.is-visible {
    display: inline-block;
}

.compare-image {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.compare-clip {
    position: absolute;
    inset: 0;
    clip-path: inset(0 calc(100% - var(--compare-position, 50%)) 0 0);
}

.compare-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--compare-position, 50%);
    width: 2px;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25);
    cursor: ew-resize;
    touch-action: none;
    transform: translateX(-1px);
}

.compare-divider::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -14px;
    width: 30px;
}

.compare-grip {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--text-color);
    background: #ffffff;
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.28);
    transform: translate(-50%, -50%);
}

.compare-grip i {
    font-size: 0.8rem;
}

.compare-divider:focus-visible {
    outline: none;
}

.compare-divider:focus-visible .compare-grip {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.35);
}

.compare-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 0.85rem;
    padding: 0.7rem 0.85rem;
    background: var(--primary-soft);
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 0.82rem;
    line-height: 1.55;
}

.compare-notice i {
    margin-top: 0.15rem;
    color: var(--primary-color);
}

.compare-hint {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.6rem;
    color: var(--light-text);
    font-size: 0.78rem;
}

.compare-hint i {
    color: var(--primary-color);
}

.compare-tag {
    position: absolute;
    top: 0.6rem;
    padding: 0.2rem 0.6rem;
    color: #fff;
    background: rgba(15, 23, 42, 0.72);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.compare-tag--left {
    left: 0.6rem;
}

.compare-tag--right {
    right: 0.6rem;
}

.compare-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    color: var(--light-text);
    font-size: 0.9rem;
}

.compare-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 1.4rem;
    margin-top: 0.75rem;
    color: var(--light-text);
    font-size: 0.85rem;
}

.compare-status.is-error {
    color: var(--primary-hover);
    font-weight: 600;
}

/* ========== settings ========== */
.settings-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    font-weight: 700;
}

.settings-heading i {
    color: var(--primary-color);
}

.format-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1.1rem;
}

.format-chip {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.6rem 0.7rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    text-align: left;
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.format-chip strong {
    font-size: 0.88rem;
}

.format-chip span {
    color: var(--light-text);
    font-size: 0.74rem;
}

.format-chip:hover {
    border-color: rgba(239, 68, 68, 0.4);
}

.format-chip.is-active {
    color: var(--primary-hover);
    background: var(--primary-soft);
    border-color: var(--primary-color);
}

.format-chip.is-active span {
    color: var(--primary-hover);
}

.setting-row {
    margin-bottom: 1.1rem;
}

.setting-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.4rem;
    font-size: 0.88rem;
}

.setting-label output {
    color: var(--primary-color);
    font-weight: 700;
}

.setting-row input[type='range'] {
    width: 100%;
    height: 6px;
    margin: 0;
    background: var(--border-color);
    border-radius: 999px;
    appearance: none;
    cursor: pointer;
}

.setting-row input[type='range']::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
    appearance: none;
    cursor: pointer;
}

.setting-row input[type='range']::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
}

.setting-row .range-labels,
.setting-row small {
    display: block;
    color: var(--light-text);
    font-size: 0.76rem;
}

.setting-row .range-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.3rem;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.check-line input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
}

.resize-fields {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.75rem;
    padding: 0.85rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.resize-inline {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.resize-inline input[type='range'] {
    flex: 1;
    accent-color: var(--primary-color);
}

.resize-inline output {
    min-width: 48px;
    color: var(--primary-color);
    font-weight: 700;
    text-align: right;
}

.resize-fields select {
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.82rem;
}

.resize-target {
    color: var(--light-text);
    font-size: 0.78rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.6rem;
    margin: 1.1rem 0;
}

.stat {
    padding: 0.7rem 0.8rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.stat span {
    display: block;
    color: var(--light-text);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat strong {
    font-size: 0.92rem;
}

.stat-highlight {
    background: var(--primary-soft);
    border-color: rgba(239, 68, 68, 0.28);
}

.stat-highlight strong {
    color: var(--primary-hover);
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.settings-actions .btn {
    flex: 1 1 160px;
}

.compress-credits {
    margin-top: 0.9rem;
    color: var(--light-text);
    font-size: 0.76rem;
    line-height: 1.5;
}

.compress-credits a {
    color: var(--light-text);
    text-decoration: underline;
}

/* ========== responsive ========== */
@media (max-width: 1080px) {
    .compress-workbench {
        grid-template-columns: 1fr;
    }

    .compress-queue {
        position: static;
    }

    .queue-list {
        max-height: 340px;
    }
}

@media (max-width: 620px) {
    .compare-file strong {
        max-width: 200px;
    }

    .settings-actions .btn {
        flex: 1 1 100%;
    }
}
