/* Global Resets and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(216, 196, 196, 0.1) 100%);
    background-attachment: fixed;
    transition: background-color 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), color 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    scroll-behavior: smooth;
    min-height: 100vh;
}

/* CSS Custom Properties for Themes */
:root {
    --bg-primary: #efeae5;
    --bg-secondary: rgba(255, 255, 255, 0.8);
    --text-primary: #2a435b;
    --text-secondary: #d8c4c4;
    --accent: #a55d34;
    --border: rgba(216, 196, 196, 0.3);
    --shadow: 0 4px 20px rgba(42, 67, 91, 0.1);
    --error: #e74c3c;
    --success: #27ae60;
    --warning: #f39c12;
    --glass-bg: rgba(239, 234, 229, 0.1);
    --glass-border: rgba(216, 196, 196, 0.2);
}

.dark {
    --bg-primary: #2a435b;
    --bg-secondary: rgba(26, 26, 46, 0.8);
    --text-primary: #efeae5;
    --text-secondary: #d8c4c4;
    --border: rgba(58, 63, 90, 0.3);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --glass-bg: rgba(42, 67, 91, 0.1);
    --glass-border: rgba(216, 196, 196, 0.2);
}

body.dark {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Header */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

#theme-toggle:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}

#theme-toggle .moon-icon {
    display: none;
}

.dark #theme-toggle .sun-icon {
    display: none;
}

.dark #theme-toggle .moon-icon {
    display: block;
}

/* Toggles Container */
.toggles {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#language-toggle {
    background: none;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

#language-toggle:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}

#language-toggle .en-icon {
    display: none;
}

body[data-lang="en"] #language-toggle .en-icon {
    display: block;
}

body[data-lang="en"] #language-toggle .es-icon {
    display: none;
}

body[data-lang="es"] #language-toggle .en-icon {
    display: none;
}

body[data-lang="es"] #language-toggle .es-icon {
    display: block;
}

/* Main Layout - Mobile First */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

section {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--glass-border);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

section:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(42, 67, 91, 0.15);
}

/* Upload Section */
.privacy-notice {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    font-family: inherit;
}

.upload-zone.processing .upload-content,
.upload-zone.results .upload-content {
    display: none;
}

.upload-zone.processing .progress-container,
.upload-zone.results .results-container {
    display: block;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background-color: rgba(165, 93, 52, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(165, 93, 52, 0.1);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.upload-zone:hover .upload-icon {
    opacity: 1;
}

.file-list {
    list-style: none;
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.file-list li {
    background: var(--accent);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.file-list .remove-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.file-list .remove-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Controls Section */
fieldset {
    border: 1px solid var(--border);
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

legend {
    font-weight: 600;
    color: var(--text-primary);
    padding: 0 0.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

input[type="radio"],
input[type="checkbox"] {
    margin-right: 0.5rem;
    accent-color: var(--accent);
}

/* Fancy Toggle Switches for Group Checkboxes */
.toggle-switch {
    appearance: none;
    -webkit-appearance: none;
    width: 44px;
    height: 24px;
    background: rgba(142, 142, 147, 0.24);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-left: auto;
    margin-right: 0;
}

.toggle-switch::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch:checked {
    background: #a55d34;
}

.toggle-switch:checked::before {
    transform: translateX(20px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.toggle-switch:hover {
    background: rgba(142, 142, 147, 0.36);
}

.toggle-switch:checked:hover {
    background: #a55d34bb;
}

.toggle-switch:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

input[type="range"] {
    width: 100%;
    margin: 0.5rem 0;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

#quality-value,
#dpi-value {
    font-weight: 600;
    color: var(--accent);
}

.custom-settings {
    transition: max-height 0.3s ease;
    overflow: hidden;
}

.custom-settings[aria-expanded="true"] {
    max-height: 300px; /* Adjust based on content */
}

/* Basic Settings - Always Visible */
.basic-settings {
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(216, 196, 196, 0.1);
}

.basic-settings h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Fancy Color Mode Radio Buttons */
.basic-settings fieldset {
    border: none;
    padding: 0;
    margin: 1rem 0;
    display: flex;
    gap: 0.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 0.25rem;
    box-shadow: 0 2px 8px rgba(165, 93, 52, 0.1);
}

.basic-settings fieldset legend {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.basic-settings fieldset label {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-align: center;
    position: relative;
    border: 1px solid transparent;
}

.basic-settings fieldset label:hover {
    background: rgba(165, 93, 52, 0.05);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.basic-settings fieldset input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.basic-settings fieldset input[type="radio"]:checked + label {
    background: #007AFF;
    color: white;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-color: #007AFF;
    font-weight: 700;
    transform: scale(1.02);
}

.basic-settings fieldset input[type="radio"]:checked + label::after {
    content: '●';
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    opacity: 0.9;
}

.basic-settings fieldset input[type="radio"]:focus + label {
    outline: none;
    box-shadow: 0 0 0 3px rgba(165, 93, 52, 0.3);
}

/* Details/Summary Styling for Collapsible Settings */
details.settings-group {
    margin-bottom: 1rem;
}

details.settings-group summary {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    list-style: none;
    position: relative;
    box-shadow: 0 2px 8px rgba(165, 93, 52, 0.1);
}

details.settings-group summary:hover {
    background: rgba(165, 93, 52, 0.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(165, 93, 52, 0.15);
}

details.settings-group summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(165, 93, 52, 0.3);
}

details.settings-group summary::after {
    content: '▶';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s ease;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

details.settings-group[open] summary::after {
    transform: translateY(-50%) rotate(90deg);
}

details.settings-group > div {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(216, 196, 196, 0.1);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    border-radius: 22px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-right: 1rem;
    min-height: 44px; /* Touch-friendly */
    box-shadow: 0 2px 8px rgba(165, 93, 52, 0.2);
}

button:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(165, 93, 52, 0.3);
    background: linear-gradient(135deg, var(--accent), rgba(165, 93, 52, 0.8));
}

button:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px rgba(165, 93, 52, 0.2);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#dry-run-btn {
    background: var(--text-secondary);
    box-shadow: 0 2px 8px rgba(216, 196, 196, 0.2);
}

#dry-run-btn:hover {
    box-shadow: 0 6px 20px rgba(216, 196, 196, 0.3);
    background: linear-gradient(135deg, var(--text-secondary), rgba(216, 196, 196, 0.8));
}

/* Output Section */
.progress-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

progress {
    width: 100%;
    height: 20px;
    border-radius: 10px;
    background: var(--border);
}

progress::-webkit-progress-bar {
    background: var(--border);
    border-radius: 10px;
}

progress::-webkit-progress-value {
    background: var(--accent);
    border-radius: 10px;
}

.file-progresses {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-progress {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background: rgba(74, 144, 226, 0.05);
    border-radius: 4px;
}

.file-progress label {
    flex: 1;
    font-size: 0.9rem;
}

.results-container .size-summary {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.download-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.download-links a {
    display: inline-block;
    background: var(--success);
    color: white;
    padding: 0.875rem 2rem;
    text-decoration: none;
    border-radius: 22px;
    font-weight: 600;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-align: center;
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.2);
}

.download-links a:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(39, 174, 96, 0.3);
    background: linear-gradient(135deg, var(--success), rgba(39, 174, 96, 0.8));
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--error);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 4px;
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: fadeInOut 3s ease forwards;
}

.toast.success {
    background: var(--success);
}

.toast.warning {
    background: var(--warning);
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(100%) scale(0.95); }
    10% { opacity: 1; transform: translateX(0) scale(1); }
    90% { opacity: 1; transform: translateX(0) scale(1); }
    100% { opacity: 0; transform: translateX(100%) scale(0.95); }
}

/* Error Container */
.error-container {
    color: var(--error);
    text-align: center;
    padding: 1rem;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 4px;
    border: 1px solid var(--error);
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    color: var(--text-secondary);
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

/* Responsive Design - Mobile First */
@media (min-width: 768px) {
    main {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .upload-section,
    .controls-section {
        flex: 1 1 45%;
        margin-right: 2%;
    }

    .output-section {
        flex: 1 1 100%;
        margin-top: 1rem;
    }

    .file-progresses {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-around;
    }

    .file-progress {
        flex: 1 1 200px;
    }
}

@media (min-width: 1024px) {
    .upload-section,
    .controls-section {
        flex: 1 1 30%;
        margin-right: 3.33%;
    }

    .output-section {
        flex: 1 1 60%;
    }

    header {
        padding: 1rem 4rem;
    }

    h1 {
        font-size: 2.2rem;
    }
}

/* Accessibility Enhancements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(165, 93, 52, 0.3);
}

.upload-zone:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(165, 93, 52, 0.3);
}

/* Fade-in Animation for Sections */
section {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
