/* Motu DS v1.1 — MotuCloud SVG Batch Optimizer & Exporter */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--motu-font-ui);
    font-size: var(--motu-text-base);
    font-weight: 400;
    line-height: var(--motu-lh-normal);
    color: var(--motu-ink);
    background: transparent;
    font-synthesis: none;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* Page Loader */
.page-loader {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: var(--motu-z-toast);
}

.page-loader-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--motu-surface);
    padding: 8px 12px;
    border-radius: var(--motu-r-md);
    border: 1px solid var(--motu-line);
    box-shadow: var(--motu-shadow-float);
}

.page-loader-text {
    font-size: var(--motu-text-sm);
    color: var(--motu-muted);
}

.loader {
    width: 18px;
    height: 18px;
    border: 2px solid var(--motu-line);
    border-top-color: var(--motu-wine);
    border-radius: 50%;
    animation: svg-spin 0.9s linear infinite;
}

@keyframes svg-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Root Frame Container */
.svg-container {
    max-width: 960px;
    margin: 0 auto;
    background: var(--motu-surface, #FFFFFF);
    border: 1px solid var(--motu-line, #E5E5E5);
    border-radius: var(--motu-r-lg, 14px);
    padding: 28px;
    box-shadow: var(--motu-shadow-none);
}

/* Unified Typography */
.section-title {
    font-family: var(--motu-font-ui);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--motu-ink);
    margin-bottom: 6px;
}

.section-desc {
    font-size: 13px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--motu-muted);
    margin-bottom: 18px;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--motu-ink-2);
    margin-bottom: 6px;
}

/* Drop Zone */
.drop-zone {
    border: 1.5px dashed var(--motu-line-strong);
    border-radius: var(--motu-r-lg);
    padding: 34px 24px;
    text-align: center;
    background: var(--motu-surface-soft);
    transition: border-color var(--motu-dur) var(--motu-ease), background-color var(--motu-dur) var(--motu-ease);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--motu-wine);
    background: var(--motu-wine-soft);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone-content button {
    pointer-events: auto;
}

.upload-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--motu-wine);
    margin-bottom: 10px;
}

.drop-zone-title {
    font-family: var(--motu-font-ui);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--motu-ink);
    margin-bottom: 6px;
}

.drop-zone-desc {
    font-size: 13px;
    font-weight: 400;
    color: var(--motu-muted);
    margin-bottom: 16px;
}

.drop-zone-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

.drop-zone-hint {
    margin-top: 12px;
    font-size: 12px;
    font-weight: 400;
    color: var(--motu-muted);
}

.file-input {
    display: none;
}

/* Unified Controls (40px height, 14px font, 8px radius) */
.svg-btn {
    height: 40px;
    padding: 0 18px;
    border-radius: var(--motu-r-sm, 8px);
    font-family: var(--motu-font-ui);
    font-size: 14px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    transition: background-color var(--motu-dur) var(--motu-ease), border-color var(--motu-dur) var(--motu-ease), color var(--motu-dur) var(--motu-ease);
}

.svg-btn--primary {
    background: var(--motu-cta);
    color: var(--motu-on-cta);
    border: 1px solid var(--motu-cta);
}

.svg-btn--primary:hover:not(:disabled) {
    background: var(--motu-cta-hover);
    border-color: var(--motu-cta-hover);
}

.svg-btn--primary:disabled {
    background: var(--motu-surface-muted);
    border-color: var(--motu-line);
    color: var(--motu-faint);
    cursor: not-allowed;
}

.svg-btn--secondary {
    background: var(--motu-surface);
    color: var(--motu-ink);
    border: 1px solid var(--motu-line-strong);
}

.svg-btn--secondary:hover:not(:disabled) {
    background: var(--motu-surface-hover);
    border-color: var(--motu-ink);
}

.svg-btn--secondary:disabled {
    background: var(--motu-surface-muted);
    border-color: var(--motu-line);
    color: var(--motu-faint);
    cursor: not-allowed;
}

.svg-input,
.svg-select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--motu-line-strong);
    border-radius: var(--motu-r-sm, 8px);
    background-color: var(--motu-surface);
    color: var(--motu-ink);
    font-family: var(--motu-font-ui);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.2;
    transition: border-color var(--motu-dur) var(--motu-ease);
}

.svg-select {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23666666' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.svg-select:disabled,
.svg-input:disabled {
    background-color: var(--motu-surface-muted);
    color: var(--motu-faint);
    border-color: var(--motu-line);
    cursor: not-allowed;
}

input[type="number"].svg-input {
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}

input[type="number"].svg-input::-webkit-inner-spin-button,
input[type="number"].svg-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.svg-input:focus,
.svg-select:focus,
.svg-textarea:focus {
    outline: 2px solid var(--motu-ink);
    outline-offset: 1px;
    border-color: var(--motu-ink);
}

.svg-textarea {
    width: 100%;
    min-height: 120px;
    padding: 10px 12px;
    border: 1px solid var(--motu-line-strong);
    border-radius: var(--motu-r-sm, 8px);
    background: var(--motu-surface);
    color: var(--motu-ink);
    font-family: var(--motu-font-mono);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
    resize: vertical;
}

/* Paste SVG Panel */
.paste-panel {
    margin-top: 18px;
    background: var(--motu-surface-soft);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-lg);
    padding: 20px 22px;
}

.paste-panel-header .section-desc {
    margin-bottom: 14px;
}

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

.paste-name-field {
    max-width: 360px;
}

.paste-panel-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

/* File Queue */
.file-queue {
    margin-top: 18px;
    background: var(--motu-surface-soft);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-lg);
    padding: 18px 20px;
}

.file-queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.file-queue-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.file-queue-meta strong {
    font-size: 14px;
    font-weight: 400;
    color: var(--motu-ink);
}

.file-queue-size {
    font-size: 12px;
    color: var(--motu-muted);
    font-variant-numeric: tabular-nums;
}

.file-queue-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.file-queue-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 164px;
    overflow-y: auto;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--motu-surface);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-sm);
    padding: 6px 10px;
    font-size: 12px;
    color: var(--motu-ink-2);
    max-width: 100%;
}

.file-chip-name {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--motu-ink);
}

.file-chip-size {
    color: var(--motu-muted);
    font-variant-numeric: tabular-nums;
}

.file-chip-remove {
    border: 0;
    background: transparent;
    color: var(--motu-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--motu-r-xs);
}

.file-chip-remove:hover {
    color: var(--motu-danger);
    background: var(--motu-danger-soft);
}

/* Settings Panel */
.settings-panel {
    margin-top: 20px;
    background: var(--motu-surface-soft);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-lg);
    padding: 22px 24px;
}

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

.field-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Color Override Row */
.color-override-row {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--motu-line);
}

.color-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.color-input-wrap {
    position: relative;
    width: 168px;
    flex-shrink: 0;
}

.svg-input--color {
    padding-right: 44px;
    font-family: var(--motu-font-mono);
    text-transform: uppercase;
}

.color-swatch-trigger {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--motu-r-xs);
}

.color-swatch-preview {
    width: 24px;
    height: 24px;
    border-radius: var(--motu-r-xs);
    border: 1px solid var(--motu-line-strong);
    background-color: #0A0A0A;
    display: block;
}

.color-native-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.color-presets {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.color-preset-btn {
    padding: 0 12px;
}

.color-preset-btn.active {
    border-color: var(--motu-wine);
    color: var(--motu-wine);
    background: var(--motu-wine-soft);
}

.preset-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid var(--motu-line-strong);
    display: inline-block;
    flex-shrink: 0;
}

.preset-dot[data-dot="#0A0A0A"] {
    background-color: #0A0A0A;
}

.preset-dot[data-dot="#780000"] {
    background-color: #780000;
}

.preset-dot[data-dot="#333333"] {
    background-color: #333333;
}

/* Optimization Toggles */
.toggles-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--motu-line);
}

.toggles-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.toggle-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 14px;
    background: var(--motu-surface);
    border: 1px solid var(--motu-line-strong);
    border-radius: var(--motu-r-sm);
    font-size: 13px;
    font-weight: 400;
    color: var(--motu-ink);
    cursor: pointer;
    user-select: none;
    transition: border-color var(--motu-dur) var(--motu-ease), background-color var(--motu-dur) var(--motu-ease);
}

.toggle-item:hover {
    border-color: var(--motu-ink);
}

.toggle-checkbox {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.toggle-box {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid var(--motu-line-strong);
    background: var(--motu-surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color var(--motu-dur-fast) var(--motu-ease), border-color var(--motu-dur-fast) var(--motu-ease);
}

.toggle-checkbox:checked + .toggle-box {
    background: var(--motu-wine-fill);
    border-color: var(--motu-wine-fill);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2.5 6.2L4.8 8.5L9.5 3.5' stroke='%23FFFFFF' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 12px 12px;
}

.toggle-checkbox:focus-visible + .toggle-box {
    outline: 2px solid var(--motu-ink);
    outline-offset: 2px;
}

.toggle-text {
    line-height: 1.4;
}

.settings-footer {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--motu-line);
    display: flex;
    justify-content: flex-end;
}

.process-btn {
    min-width: 180px;
}

/* Progress */
.progress-container {
    margin-top: 20px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--motu-surface-muted);
    border-radius: var(--motu-r-pill);
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--motu-wine-fill);
    border-radius: var(--motu-r-pill);
    transition: width 0.2s var(--motu-ease);
}

.progress-text {
    font-size: 13px;
    color: var(--motu-muted);
    font-variant-numeric: tabular-nums;
}

/* Error Message */
.error-message {
    margin-top: 18px;
    padding: 12px 16px;
    background: var(--motu-danger-soft);
    border: 1px solid var(--motu-wine-line);
    border-left: 3px solid var(--motu-danger);
    border-radius: var(--motu-r-sm);
    color: var(--motu-danger);
    font-size: 13px;
    line-height: 1.5;
}

.error-message strong {
    font-weight: 400;
}

/* Results Panel */
.results-panel {
    margin-top: 22px;
    background: var(--motu-surface-soft);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-lg);
    padding: 22px 24px;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--motu-line);
}

.results-title {
    margin-bottom: 4px;
}

.batch-summary {
    font-size: 13px;
    color: var(--motu-muted);
    font-variant-numeric: tabular-nums;
}

/* 2-Column Result Cards */
.results-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.svg-result-card {
    background: var(--motu-surface);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    transition: border-color var(--motu-dur) var(--motu-ease);
}

.svg-result-card:hover {
    border-color: var(--motu-line-strong);
}

.svg-preview-box {
    width: 100%;
    height: 148px;
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-sm);
    background-color: #FFFFFF;
    background-image:
        linear-gradient(45deg, #F3F3F3 25%, transparent 25%),
        linear-gradient(-45deg, #F3F3F3 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #F3F3F3 75%),
        linear-gradient(-45deg, transparent 75%, #F3F3F3 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    cursor: pointer;
    overflow: hidden;
}

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

.svg-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.svg-card-filename {
    font-size: 14px;
    color: var(--motu-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.svg-card-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--motu-muted);
    font-variant-numeric: tabular-nums;
}

.svg-savings-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: var(--motu-r-xs);
    font-size: 12px;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.svg-savings-badge--ok {
    background: var(--motu-ok-soft);
    color: var(--motu-ok);
}

.svg-savings-badge--neutral {
    background: var(--motu-surface-muted);
    color: var(--motu-muted);
}

.svg-savings-badge--warn {
    background: var(--motu-wine-soft);
    color: var(--motu-wine);
}

.svg-card-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: auto;
}

.svg-card-actions .svg-btn {
    width: 100%;
    padding: 0 12px;
}

.svg-card-actions .svg-btn:first-child:nth-last-child(3) {
    grid-column: 1 / -1;
}

/* Modal Preview */
.modal {
    position: fixed;
    inset: 0;
    background: var(--motu-backdrop);
    z-index: var(--motu-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: pointer;
}

.modal-dialog {
    max-width: 88%;
    max-height: 88%;
    background: var(--motu-surface);
    border: 1px solid var(--motu-line);
    border-radius: var(--motu-r-lg);
    padding: 20px;
    box-shadow: var(--motu-shadow-modal);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: default;
}

.modal-content {
    max-width: 640px;
    max-height: 520px;
    width: auto;
    height: auto;
    min-width: 160px;
    min-height: 160px;
    object-fit: contain;
    border-radius: var(--motu-r-sm);
    border: 1px solid var(--motu-line);
    padding: 16px;
    background-color: #FFFFFF;
    background-image:
        linear-gradient(45deg, #F3F3F3 25%, transparent 25%),
        linear-gradient(-45deg, #F3F3F3 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #F3F3F3 75%),
        linear-gradient(-45deg, transparent 75%, #F3F3F3 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.modal-caption {
    font-size: 13px;
    color: var(--motu-muted);
    text-align: center;
    word-break: break-all;
}

/* Responsive */
@media (max-width: 860px) {
    .options-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .svg-container {
        padding: 18px;
    }
    .drop-zone {
        padding: 26px 16px;
    }
    .settings-panel,
    .results-panel,
    .paste-panel,
    .file-queue {
        padding: 16px;
    }
    .options-grid {
        grid-template-columns: 1fr;
    }
    .results-grid {
        grid-template-columns: 1fr;
    }
    .process-btn {
        width: 100%;
    }
    .color-input-wrap {
        width: 100%;
    }
}
