/* ===== RESET & VARIABLES ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-surface: #F8F7FF;
    --success: #22C55E;
    --success-hover: #16A34A;
    --success-light: #F0FDF4;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --error: #EF4444;
    --error-light: #FEF2F2;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --bg-primary: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-input: #F8FAFC;
    --border-color: #E2E8F0;
    --border-hover: #C7D2FE;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.10);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 1.5rem;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0 1rem 0;
    flex-shrink: 0;
}

.app-header .logo {
    width: 40px;
    height: 40px;
    color: var(--primary);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.app-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 400;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0 1rem 0;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.toolbar-link {
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.toolbar-link:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.toolbar-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== MAIN LAYOUT ===== */
.main-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* ===== LEFT: CONTENT SECTION ===== */
.content-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* ===== DROP ZONE ===== */
.drop-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-surface);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.drop-zone-content {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.drop-icon {
    width: 40px;
    height: 40px;
    color: var(--primary);
}

.drop-zone h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.browse-link {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    pointer-events: all;
    transition: var(--transition);
}

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

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.loading-overlay:not(.is-hidden) {
    opacity: 1;
    pointer-events: auto;
}

.loading-overlay .loading-content {
    text-align: center;
    color: white;
    max-width: 500px;
    transform: scale(0.95);
    transition: transform 0.4s ease;
}

.loading-overlay:not(.is-hidden) .loading-content {
    transform: scale(1);
}

.loading-overlay .loading-content .spinner {
    display: inline-block;
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

.loading-overlay .loading-content h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-overlay .loading-content p {
    font-size: 1rem;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.loading-overlay .loading-content .loading-sub {
    font-size: 0.85rem;
    opacity: 0.5;
}

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

/* ===== ORIGINAL INFO ===== */
.original-info {
    display: flex;
    gap: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    align-items: center;
    flex-wrap: wrap;
}

.original-info .original-thumb {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}

.original-info .original-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.original-info .original-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.05rem 0.75rem;
    flex: 1;
}

.original-info .original-meta strong {
    color: var(--text-primary);
}

.original-info .original-meta #qualityScore {
    font-weight: 700;
}

.original-info .original-meta #qualityScore.good {
    color: var(--success);
}
.original-info .original-meta #qualityScore.ok {
    color: var(--warning);
}
.original-info .original-meta #qualityScore.bad {
    color: var(--error);
}

/* ===== TABS ===== */
.tabs-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.tab {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.tab:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.tab.active {
    background: var(--primary);
    color: white;
}

.tab-content {
    display: none;
    padding-top: 0.5rem;
}

.tab-content.active {
    display: block;
}

.tab-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* ===== REPORT GRID ===== */
.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.report-card {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.report-card:hover {
    border-color: var(--border-hover);
}

.report-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.report-card .card-header .format-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.report-card .card-header .quality-badge {
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
}

.report-card .card-header .quality-badge.best {
    background: var(--success-light);
    color: var(--success);
}

.report-card .preview-wrapper {
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.report-card .preview-wrapper img {
    width: 100%;
    height: auto;
    max-height: 150px;
    object-fit: contain;
    display: block;
}

.report-card .card-meta {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.25rem 0;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.report-card .card-meta span {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.report-card .card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.report-card .card-actions .btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.report-card .card-actions .btn-download {
    background: var(--primary-light);
    color: var(--primary);
}

.report-card .card-actions .btn-download:hover {
    background: var(--primary);
    color: white;
}

.report-card .card-actions .btn-copy {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.report-card .card-actions .btn-copy:hover {
    background: var(--border-color);
}

.report-card .savings {
    font-weight: 600;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* ===== UPSCALE ===== */
.upscale-controls {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.upscale-controls .control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.upscale-controls .control-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.upscale-controls select {
    padding: 0.4rem 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--bg-input);
}

.upscale-result {
    margin-top: 1rem;
}

.upscale-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.compare-item {
    text-align: center;
}

.compare-item h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.compare-item img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-input);
}

.compare-item span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

/* ===== BACKGROUND ===== */
.background-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.bg-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.bg-quality-note {
    background: #fff3cd;
    color: #664d03;
    border: 1px solid #ffe69c;
    border-radius: 8px;
    padding: 0.65rem 0.9rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.bg-transparent-preview {
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.bg-transparent-preview img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: contain;
    background: transparent;
    border: none;
    border-radius: 0;
}

/* ===== METADATA ===== */
.metadata-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.exif-table {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.exif-table table {
    width: 100%;
    border-collapse: collapse;
}

.exif-table td {
    padding: 0.2rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.exif-table td:first-child {
    font-weight: 600;
    color: var(--text-secondary);
    width: 30%;
}

/* ===== TAB FOOTER ===== */
.tab-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn svg {
    flex-shrink: 0;
    height: 1.2rem;
    width: auto;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.30);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.30);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
}

/* ===== RIGHT: CONTROLS ===== */
.controls-section {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-group label {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
}

/* ===== IMAGE INFO PANEL ===== */
#imageInfoPanel {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    line-height: 1.6;
}

#imageInfoPanel strong {
    color: var(--text-primary);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateX(-50%) translateY(20px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.modal-overlay:not(.is-hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay:not(.is-hidden) .modal-content {
    transform: scale(1);
}

.modal-image {
    max-width: 90vw;
    max-height: 90vh;
}

.modal-image .modal-body {
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.modal-image .modal-body img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: var(--transition);
    line-height: 1;
    padding: 0 0.25rem;
}

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

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

/* ===== FOOTER ===== */
.app-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1.5rem;
    flex-shrink: 0;
}

.app-footer .row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.app-footer svg {
    height: 1.5rem;
    width: auto;
    flex-shrink: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: var(--transition);
}

.app-footer a:hover {
    color: var(--primary);
}

/* ===== UTILITIES ===== */
.is-hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .controls-section {
        width: 260px;
    }
}

@media (max-width: 820px) {
    .app {
        min-height: auto;
    }

    .main-layout {
        flex-direction: column;
        gap: 1rem;
    }

    .controls-section {
        width: 100%;
    }

    .report-grid {
        grid-template-columns: 1fr 1fr;
    }

    .upscale-comparison,
    .bg-comparison {
        grid-template-columns: 1fr;
    }

    body {
        padding: 1rem;
    }

    .app-footer {
        margin-top: 1rem;
    }

    .original-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .original-info .original-thumb {
        width: 100%;
        height: auto;
        max-width: 100px;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.25rem;
    }
    .app-header .subtitle {
        font-size: 0.75rem;
    }
    .controls-card {
        padding: 1rem;
    }
    .toolbar-link {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }
    .report-grid {
        grid-template-columns: 1fr;
    }
    .tabs {
        gap: 0.25rem;
    }
    .tab {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }
}

.badge svg,
.btn svg {
    flex-shrink: 0;
    height: 1.2rem;
    width: auto;
}

.badge.badge-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
}

.ads {
    margin-top: 1em;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    text-align: center;
}
