/* =========================================================
   Image Compressor
   Light / Clean / Commercial
========================================================= */

:root {
    color-scheme: light;

    --page-bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;

    --text-primary: #172033;
    --text-secondary: #667085;
    --text-muted: #98a2b3;

    --border: #e6eaf0;
    --border-strong: #d7dee8;

    --primary: #3568e8;
    --primary-hover: #2857ce;
    --primary-soft: #edf3ff;

    --success: #16875d;
    --success-soft: #eaf8f1;

    --danger: #d92d20;
    --danger-soft: #fff0ee;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --shadow:
        0 2px 8px rgba(16, 24, 40, 0.025),
        0 12px 36px rgba(16, 24, 40, 0.035);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-height: 100%;
    background: var(--page-bg);
}

body {
    margin: 0;
    min-height: 100vh;

    color: var(--text-primary);
    background: var(--page-bg);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "PingFang SC",
        "Microsoft YaHei",
        sans-serif;

    font-size: 14px;
    line-height: 1.6;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
.upload-area:focus-visible {
    outline: 3px solid rgba(53, 104, 232, 0.2);
    outline-offset: 3px;
}

.image-tool {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 36px 40px 24px;
}


/* =========================================================
   Header
========================================================= */

.tool-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;

    margin-bottom: 28px;
}

.header-copy {
    min-width: 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    margin-bottom: 18px;

    color: var(--text-secondary);
    text-decoration: none;

    transition: color 0.18s ease;
}

.back-link:hover {
    color: var(--primary);
}

.back-link span {
    font-size: 19px;
    line-height: 1;
}

.tool-header h1 {
    margin: 0;

    font-size: clamp(28px, 3vw, 36px);
    font-weight: 750;
    letter-spacing: -1px;
    line-height: 1.25;
}

.tool-header p {
    max-width: 660px;
    margin: 12px 0 0;

    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.8;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    flex-shrink: 0;

    padding: 9px 13px;

    color: #43536b;
    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 999px;

    font-size: 12px;
    white-space: nowrap;
}

.badge-dot {
    width: 7px;
    height: 7px;

    background: #27ae79;
    border-radius: 50%;
}


/* =========================================================
   Workspace
========================================================= */

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
    align-items: start;
    gap: 22px;
}

.preview-panel,
.settings-panel,
.status-panel,
.result-panel {
    min-width: 0;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);

    box-shadow: var(--shadow);
}

.preview-panel,
.settings-panel {
    padding: 24px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    margin-bottom: 22px;
}

.panel-heading h2 {
    margin: 0;

    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.panel-heading p {
    margin: 5px 0 0;

    color: var(--text-secondary);
    font-size: 12px;
}


/* =========================================================
   Upload Area
========================================================= */

.upload-area {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 360px;
    padding: 32px 20px;

    background:
        linear-gradient(135deg,
            rgba(247, 250, 255, 0.9),
            rgba(250, 252, 255, 0.95));

    border: 1px dashed #cbd5e5;
    border-radius: var(--radius-md);

    cursor: pointer;

    transition:
        border-color 0.2s ease,
        background 0.2s ease,
        transform 0.2s ease;
}

.upload-area:hover,
.upload-area.dragging {
    background: #f0f5ff;
    border-color: var(--primary);
}

.upload-area.dragging {
    transform: scale(0.995);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    text-align: center;
}

.upload-icon {
    display: grid;
    place-items: center;

    width: 72px;
    height: 72px;

    margin-bottom: 20px;

    color: var(--primary);
    background: #eaf0ff;
    border-radius: 20px;
}

.upload-icon svg {
    width: 42px;
    height: 42px;
}

.upload-content h3 {
    margin: 0;

    font-size: 17px;
    font-weight: 700;
}

.upload-content p {
    margin: 8px 0 20px;

    color: var(--text-secondary);
    font-size: 13px;
}

.upload-hint {
    display: block;
    margin-top: 16px;

    color: var(--text-muted);
    font-size: 12px;
}


/* =========================================================
   Buttons
========================================================= */

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    min-height: 42px;
    padding: 10px 18px;

    border: 1px solid transparent;
    border-radius: var(--radius-sm);

    font-size: 13px;
    font-weight: 650;

    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
}

.primary-button {
    color: #ffffff;
    background: var(--primary);
}

.primary-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.primary-button:active:not(:disabled) {
    transform: translateY(1px);
}

.secondary-button {
    color: var(--text-primary);
    background: #ffffff;
    border-color: var(--border-strong);
}

.secondary-button:hover:not(:disabled) {
    background: var(--surface-soft);
}

.text-button {
    padding: 6px 0;

    color: var(--primary);
    background: transparent;
    border: 0;

    font-size: 12px;
    font-weight: 600;
}

.text-button:hover {
    color: var(--primary-hover);
}


/* =========================================================
   Original Preview
========================================================= */

.preview-container {
    width: 100%;
}

.preview-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 280px;
    max-height: 470px;

    padding: 16px;

    overflow: hidden;

    background-color: #f8fafc;

    background-image:
        linear-gradient(45deg, #edf0f4 25%, transparent 25%),
        linear-gradient(-45deg, #edf0f4 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #edf0f4 75%),
        linear-gradient(-45deg, transparent 75%, #edf0f4 75%);

    background-size: 20px 20px;
    background-position:
        0 0,
        0 10px,
        10px -10px,
        -10px 0;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.preview-image-wrap img {
    display: block;

    max-width: 100%;
    max-height: 430px;

    object-fit: contain;
}

.image-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 18px;

    margin-top: 16px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 5px;

    min-width: 0;
    padding: 12px 0;

    border-bottom: 1px solid #f0f2f5;
}

.meta-label {
    color: var(--text-muted);
    font-size: 12px;
}

.meta-value {
    overflow: hidden;

    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.filename-value {
    overflow-wrap: anywhere;
}


/* =========================================================
   Settings
========================================================= */

.form-group {
    margin-bottom: 28px;
}

.form-label {
    display: block;
    margin-bottom: 12px;

    color: #344054;
    font-size: 13px;
    font-weight: 650;
}

.format-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}

.format-option {
    min-width: 0;
    cursor: pointer;
}

.format-option input {
    position: absolute;

    width: 1px;
    height: 1px;

    opacity: 0;
    pointer-events: none;
}

.format-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;

    min-height: 76px;
    padding: 12px 5px;

    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);

    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

.format-card strong {
    font-size: 14px;
    font-weight: 750;
}

.format-card small {
    color: var(--text-muted);
    font-size: 11px;
}

.format-option:hover .format-card {
    border-color: #b5c7fa;
}

.format-option input:checked+.format-card {
    color: var(--primary);
    background: var(--primary-soft);
    border-color: var(--primary);

    box-shadow: 0 0 0 1px var(--primary);
}

.format-option input:checked+.format-card small {
    color: #5875c8;
}


/* =========================================================
   Quality Slider
========================================================= */

.label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.label-row .form-label {
    margin-bottom: 12px;
}

.range-value {
    margin-bottom: 12px;

    color: var(--primary);
    font-size: 14px;
    font-weight: 750;
}

.quality-slider {
    display: block;

    width: 100%;
    height: 6px;
    margin: 4px 0 12px;

    accent-color: var(--primary);
    cursor: pointer;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    gap: 12px;

    color: var(--text-muted);
    font-size: 11px;
}

.field-hint {
    margin: 10px 0 0;

    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.7;
}


/* =========================================================
   Dimensions
========================================================= */

.dimension-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 14px minmax(0, 1fr);
    align-items: end;
    gap: 8px;
}

.dimension-input {
    min-width: 0;
}

.dimension-input>label {
    display: block;
    margin-bottom: 7px;

    color: var(--text-secondary);
    font-size: 12px;
}

.input-with-unit {
    display: flex;
    align-items: center;

    min-width: 0;
    height: 43px;

    overflow: hidden;

    background: #ffffff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);

    transition: border-color 0.18s ease;
}

.input-with-unit:focus-within {
    border-color: var(--primary);
}

.input-with-unit input {
    width: 100%;
    min-width: 0;
    height: 100%;

    padding: 0 10px;

    color: var(--text-primary);
    background: transparent;
    border: 0;
    outline: none;

    font-size: 13px;
    font-weight: 600;
}

.input-with-unit input:focus-visible {
    outline: none;
}

.input-with-unit span {
    flex-shrink: 0;
    padding-right: 10px;

    color: var(--text-muted);
    font-size: 11px;
}

.dimension-times {
    padding-bottom: 12px;

    color: var(--text-muted);
    text-align: center;
}


/* =========================================================
   Compress Button
========================================================= */

.compress-button {
    width: 100%;
    min-height: 48px;

    margin-top: 2px;

    font-size: 14px;
}

.processing-note {
    margin: 13px 0 0;

    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.7;
    text-align: center;
}

.loading-spinner {
    width: 15px;
    height: 15px;

    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #ffffff;
    border-radius: 50%;

    animation: spin 0.7s linear infinite;
}

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


/* =========================================================
   Status
========================================================= */

.status-panel {
    display: flex;
    align-items: flex-start;
    gap: 14px;

    margin-top: 22px;
    padding: 18px 22px;

    box-shadow: none;
}

.status-icon {
    display: grid;
    place-items: center;

    flex-shrink: 0;

    width: 34px;
    height: 34px;

    color: var(--success);
    background: var(--success-soft);
    border-radius: 50%;

    font-size: 16px;
    font-weight: 800;
}

.status-panel.error .status-icon {
    color: var(--danger);
    background: var(--danger-soft);
}

.status-content {
    min-width: 0;
}

.status-content h3 {
    margin: 0;

    font-size: 14px;
    font-weight: 700;
}

.status-content p {
    margin: 5px 0 0;

    color: var(--text-secondary);
    font-size: 12px;
    overflow-wrap: anywhere;
}


/* =========================================================
   Result
========================================================= */

.result-panel {
    margin-top: 22px;
    padding: 26px;
}

.result-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    margin-bottom: 24px;
}

.eyebrow {
    color: var(--primary);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.4px;
}

.result-heading h2 {
    margin: 5px 0 0;

    font-size: 22px;
    font-weight: 750;
    letter-spacing: -0.5px;
}

.result-heading p {
    margin: 7px 0 0;

    color: var(--text-secondary);
    font-size: 12px;
}

.download-button {
    flex-shrink: 0;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;

    margin-bottom: 24px;
}

.result-stat {
    display: flex;
    flex-direction: column;
    gap: 10px;

    min-width: 0;
    padding: 18px;

    background: var(--surface-soft);
    border: 1px solid #edf0f4;
    border-radius: var(--radius-md);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 12px;
}

.stat-value {
    overflow-wrap: anywhere;

    color: var(--text-primary);
    font-size: clamp(16px, 2vw, 23px);
    font-weight: 750;
    letter-spacing: -0.5px;
}

.highlight-stat {
    background: #f0f7ff;
    border-color: #e0ebff;
}

.highlight-stat .stat-value {
    color: var(--primary);
}

.result-preview {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.result-image-card {
    min-width: 0;
    overflow: hidden;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.result-image-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    padding: 13px 15px;

    background: #ffffff;
    border-bottom: 1px solid var(--border);
}

.result-image-heading span:first-child {
    font-size: 12px;
    font-weight: 700;
}

.result-image-heading span:last-child {
    color: var(--text-muted);
    font-size: 11px;
}

.result-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 220px;
    max-height: 380px;

    padding: 16px;
    overflow: hidden;

    background-color: #f8fafc;

    background-image:
        linear-gradient(45deg, #edf0f4 25%, transparent 25%),
        linear-gradient(-45deg, #edf0f4 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #edf0f4 75%),
        linear-gradient(-45deg, transparent 75%, #edf0f4 75%);

    background-size: 20px 20px;
    background-position:
        0 0,
        0 10px,
        10px -10px,
        -10px 0;
}

.result-image-wrap img {
    display: block;

    max-width: 100%;
    max-height: 340px;

    object-fit: contain;
}

.result-notice {
    margin-top: 18px;
    padding: 12px 15px;

    color: #7b5b13;
    background: #fff8e7;
    border: 1px solid #f4e7bd;
    border-radius: var(--radius-sm);

    font-size: 12px;
    line-height: 1.7;
}


/* =========================================================
   Footer
========================================================= */

.tool-footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;

    padding: 24px 4px 0;

    color: var(--text-muted);
    font-size: 11px;
}


/* =========================================================
   Responsive
========================================================= */

@media (max-width: 1050px) {
    .image-tool {
        padding: 28px 24px 22px;
    }

    .workspace {
        grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
        gap: 16px;
    }

    .preview-panel,
    .settings-panel {
        padding: 20px;
    }

    .result-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .image-tool {
        padding: 22px 16px;
    }

    .tool-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 16px;
    }

    .tool-header h1 {
        font-size: 29px;
    }

    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .upload-area {
        min-height: 290px;
    }

    .preview-image-wrap {
        min-height: 230px;
    }

    .result-panel {
        padding: 20px;
    }

    .result-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .result-preview {
        grid-template-columns: minmax(0, 1fr);
    }

    .result-image-wrap {
        min-height: 200px;
    }
}

@media (max-width: 420px) {

    .preview-panel,
    .settings-panel {
        padding: 16px;
    }

    .image-meta {
        grid-template-columns: minmax(0, 1fr);
    }

    .format-options {
        gap: 6px;
    }

    .format-card {
        min-height: 70px;
    }

    .result-stats {
        gap: 8px;
    }

    .result-stat {
        padding: 13px;
    }

    .stat-value {
        font-size: 18px;
    }

    .tool-footer {
        flex-direction: column;
        gap: 5px;
    }
}