/* ============================================
   PDF to JPG Converter — Mobile-First Dark Theme
   ============================================ */

/* --- CSS Variables --- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242836;
    --bg-hover: #2a2e3d;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #6b7280;
    --accent: #4f8cff;
    --accent-hover: #6ba0ff;
    --accent-dim: rgba(79, 140, 255, 0.15);
    --error: #ef4444;
    --error-dim: rgba(239, 68, 68, 0.15);
    --success: #22c55e;
    --success-dim: rgba(34, 197, 94, 0.15);
    --border: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(79, 140, 255, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

/* --- Focus States (Accessibility) --- */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.logo span {
    color: var(--accent);
}

.page-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* --- Main Content --- */
.converter {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* --- Sections --- */
.section {
    width: 100%;
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Drop Zone --- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg-secondary);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.drop-zone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.drop-zone-icon {
    color: var(--accent);
    margin-bottom: 1rem;
    opacity: 0.8;
}

.drop-zone-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.drop-zone-sub {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.drop-zone-limit {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- Error Message --- */
.error-msg {
    background: var(--error-dim);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    font-size: 0.9rem;
    text-align: center;
}

/* --- Settings Bar --- */
.settings-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.quality-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.quality-slider {
    flex: 1;
    min-width: 120px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

.quality-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.quality-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

/* --- Page Count --- */
.page-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* --- Thumbnails Grid --- */
.thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.thumb-card {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: border-color var(--transition);
}

.thumb-card:hover,
.thumb-card:focus-within {
    border-color: var(--accent);
}

.thumb-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.thumb-card input[type="checkbox"] {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
    z-index: 2;
}

.thumb-preview {
    width: 100%;
    aspect-ratio: 0.707;
    /* Checkerboard pattern for transparent areas */
    background-image:
        linear-gradient(45deg, #2a2e3d 25%, transparent 25%),
        linear-gradient(-45deg, #2a2e3d 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2e3d 75%),
        linear-gradient(-45deg, transparent 75%, #2a2e3d 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-color: #1e2230;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.thumb-preview canvas,
.thumb-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.thumb-label {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
}

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

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

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

/* --- Action Bar --- */
.action-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* --- Progress --- */
.progress-container {
    text-align: center;
    padding: 2rem 0;
}

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    margin: 0 auto 1rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

/* --- Download Results --- */
.download-results {
    text-align: center;
}

.success-icon {
    width: 64px;
    height: 64px;
    background: var(--success-dim);
    color: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    margin: 0 auto 1rem;
}

.download-results h2 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
}

.download-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.download-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: border-color var(--transition);
}

.download-item:hover {
    border-color: var(--accent);
}

.download-item img {
    width: 100%;
    aspect-ratio: 0.707;
    object-fit: contain;
    border-radius: 4px;
    background: var(--bg-tertiary);
}

.download-item-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.download-item-btn {
    font-size: 0.75rem;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    font-family: var(--font);
    padding: 0;
}

.download-item-btn:hover {
    color: var(--accent-hover);
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (min-width: 600px) {
    .converter {
        padding: 2rem;
    }

    .thumbnails {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .download-list {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

@media (min-width: 768px) {
    .drop-zone {
        padding: 4rem 3rem;
    }

    .app-header {
        padding: 1rem 2rem;
    }
}

@media (max-width: 400px) {
    .settings-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .action-bar {
        flex-direction: column;
    }

    .action-bar .btn {
        width: 100%;
    }

    .thumbnails {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

/* --- Print --- */
@media print {
    .app-header, .app-footer, .settings-bar, .action-bar {
        display: none;
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- High Contrast --- */
@media (prefers-contrast: high) {
    :root {
        --border: rgba(255, 255, 255, 0.3);
    }
    .drop-zone {
        border-width: 3px;
    }
}
