/* ==================== Base Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #e74c3c;
    --primary-dark: #c0392b;
    --primary-light: #f8d7da;
    --secondary: #2c3e50;
    --accent: #3498db;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #6c757d;
    --gray-600: #495057;
    --gray-700: #333;
    --gray-800: #222;
    --gray-900: #111;
    --white: #fff;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.3s ease;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--gray-100);
    min-height: 100vh;
}

/* ==================== Header ==================== */
.header {
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
}

.logo svg {
    width: 36px;
    height: 36px;
}

.nav-links {
    display: flex;
    gap: 24px;
    list-style: none;
}

.nav-links a {
    text-decoration: none;
    color: var(--gray-600);
    font-weight: 500;
    transition: var(--transition);
}

.nav-links a:hover {
    color: var(--primary);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.menu-toggle svg {
    width: 24px;
    height: 24px;
    color: var(--gray-700);
}

/* ==================== Hero Section ==================== */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 80px 20px;
    text-align: center;
}

.hero h1 {
    font-size: 2.5rem;
    margin-bottom: 16px;
    font-weight: 800;
}

.hero p {
    font-size: 1.2rem;
    opacity: 0.95;
    max-width: 600px;
    margin: 0 auto;
}

.hero-features {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.hero-feature {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
}

.hero-feature svg {
    width: 20px;
    height: 20px;
}

/* ==================== Container ==================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ==================== Section Titles ==================== */
.section-title {
    font-size: 1.75rem;
    color: var(--secondary);
    margin-bottom: 8px;
    font-weight: 700;
}

.section-desc {
    color: var(--gray-500);
    margin-bottom: 32px;
}

/* ==================== Feature Cards Grid ==================== */
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 48px;
}

.feature-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
    border: 2px solid transparent;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.feature-icon {
    width: 56px;
    height: 56px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.feature-icon svg {
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.feature-card h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: var(--secondary);
}

.feature-card p {
    font-size: 0.95rem;
    color: var(--gray-500);
    line-height: 1.5;
}

/* ==================== Tool Page Layout ==================== */
.tool-page {
    background: var(--gray-100);
}

.tool-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 48px 20px;
    text-align: center;
}

.tool-header h1 {
    font-size: 2rem;
    margin-bottom: 12px;
}

.tool-header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.tool-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ==================== Upload Zone ==================== */
.upload-zone {
    border: 3px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    background: var(--white);
    transition: var(--transition);
    cursor: pointer;
    margin-bottom: 24px;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone svg {
    width: 64px;
    height: 64px;
    color: var(--gray-400);
    margin-bottom: 16px;
}

.upload-zone h3 {
    font-size: 1.3rem;
    color: var(--gray-700);
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--gray-500);
    font-size: 0.95rem;
}

.upload-zone .file-types {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--gray-400);
}

.upload-input {
    display: none;
}

/* ==================== File List ==================== */
.file-list {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    gap: 16px;
}

.file-item:last-child {
    border-bottom: none;
}

.file-item .drag-handle {
    cursor: grab;
    color: var(--gray-400);
    flex-shrink: 0;
}

.file-item .file-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-item .file-icon svg {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.file-item .file-info {
    flex: 1;
    min-width: 0;
}

.file-item .file-name {
    font-weight: 600;
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item .file-size {
    font-size: 0.85rem;
    color: var(--gray-500);
}

.file-item .file-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ==================== Buttons ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
}

.btn svg {
    width: 20px;
    height: 20px;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ==================== Options Panel ==================== */
.options-panel {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.options-panel h3 {
    font-size: 1.1rem;
    color: var(--secondary);
    margin-bottom: 16px;
}

.option-group {
    margin-bottom: 20px;
}

.option-group:last-child {
    margin-bottom: 0;
}

.option-group label {
    display: block;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
}

.option-group .help-text {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-top: 4px;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--gray-200);
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

/* Checkbox & Radio */
.checkbox-group,
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.checkbox-item,
.radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ==================== Preview Area ==================== */
.preview-area {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.preview-area h3 {
    font-size: 1.1rem;
    color: var(--secondary);
    margin-bottom: 16px;
}

.preview-canvas-container {
    overflow: auto;
    max-height: 500px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

#pdf-preview {
    max-width: 100%;
    height: auto;
}

/* ==================== Page Thumbnails ==================== */
.page-thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.page-thumb {
    background: var(--white);
    border-radius: var(--radius-sm);
    padding: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    border: 3px solid transparent;
    position: relative;
}

.page-thumb:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.page-thumb.selected {
    border-color: var(--primary);
}

.page-thumb img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 8px;
}

.page-thumb .page-number {
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-600);
    font-weight: 600;
}

.page-thumb .page-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transition: var(--transition);
}

.page-thumb:hover .page-actions {
    opacity: 1;
}

.page-thumb .page-actions button {
    padding: 4px;
    background: var(--white);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: var(--shadow);
}

/* ==================== Result Area ==================== */
.result-area {
    background: var(--white);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    text-align: center;
    margin-bottom: 24px;
}

.result-area.success {
    border: 2px solid var(--success);
}

.result-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-icon svg {
    width: 40px;
    height: 40px;
    color: var(--white);
}

.result-area h3 {
    font-size: 1.5rem;
    color: var(--secondary);
    margin-bottom: 8px;
}

.result-area p {
    color: var(--gray-500);
    margin-bottom: 20px;
}

.result-info {
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 20px;
}

.result-info .info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-200);
}

.result-info .info-row:last-child {
    border-bottom: none;
}

.result-info .info-label {
    color: var(--gray-600);
}

.result-info .info-value {
    font-weight: 600;
    color: var(--gray-700);
}

/* ==================== Loading State ==================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.loading-text {
    font-size: 1.1rem;
    color: var(--gray-600);
}

/* ==================== Footer ==================== */
.footer {
    background: var(--secondary);
    color: var(--white);
    padding: 40px 20px;
    margin-top: 60px;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 40px;
}

.footer-section h4 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--white);
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 8px;
}

.footer-section a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: var(--transition);
}

.footer-section a:hover {
    color: var(--white);
    text-decoration: underline;
}

.footer-bottom {
    max-width: 1200px;
    margin: 32px auto 0;
    padding-top: 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
}

/* ==================== Toast Notifications ==================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--white);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.toast.success svg { color: var(--success); }
.toast.error svg { color: var(--danger); }
.toast.warning svg { color: var(--warning); }

.toast-message {
    flex: 1;
    color: var(--gray-700);
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--gray-400);
}

.toast-close:hover {
    color: var(--gray-600);
}

/* ==================== Progress Bar ==================== */
.progress-container {
    background: var(--gray-200);
    border-radius: 20px;
    height: 8px;
    overflow: hidden;
    margin-top: 16px;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 20px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ==================== Category Divider ==================== */
.category-section {
    margin-bottom: 48px;
}

.category-section:last-child {
    margin-bottom: 0;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.category-header h2 {
    font-size: 1.5rem;
    color: var(--secondary);
}

.category-header svg {
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.category-line {
    flex: 1;
    height: 2px;
    background: var(--gray-200);
}

/* ==================== Empty State ==================== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    color: var(--gray-300);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.2rem;
    color: var(--gray-600);
    margin-bottom: 8px;
}

/* ==================== Image Grid (for image-to-pdf) ==================== */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.image-item {
    position: relative;
    aspect-ratio: 1;
    background: var(--white);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: move;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-item .image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.image-item:hover .image-overlay {
    opacity: 1;
}

.image-item .image-actions {
    display: flex;
    gap: 8px;
}

.image-item .image-actions button {
    padding: 8px;
    background: var(--white);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.image-item .image-actions button:hover {
    background: var(--primary);
    color: var(--white);
}

/* ==================== PDF Page Editor (for reorder/rotate) ==================== */
.pdf-page-editor {
    display: flex;
    gap: 24px;
}

.page-list-sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    max-height: 600px;
    overflow-y: auto;
}

.page-list-sidebar h4 {
    font-size: 1rem;
    color: var(--secondary);
    margin-bottom: 12px;
}

.page-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 4px;
}

.page-list-item:hover {
    background: var(--gray-100);
}

.page-list-item.active {
    background: var(--primary-light);
}

.page-list-item .thumb {
    width: 40px;
    height: 56px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.page-list-item .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.page-list-item .info {
    flex: 1;
    font-size: 0.85rem;
    color: var(--gray-600);
}

.page-list-item .drag-handle {
    color: var(--gray-400);
    cursor: grab;
}

.page-preview-main {
    flex: 1;
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.page-preview-main h4 {
    font-size: 1rem;
    color: var(--secondary);
    margin-bottom: 16px;
}

.preview-canvas-wrapper {
    background: var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 20px;
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-canvas-wrapper canvas {
    max-width: 100%;
    max-height: 700px;
    box-shadow: var(--shadow-lg);
    background: var(--white);
}

/* ==================== Pagination / Range Input ==================== */
.range-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.range-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-input label {
    font-weight: 600;
    color: var(--gray-700);
}

.range-input input {
    width: 80px;
    text-align: center;
}

/* ==================== Utility Classes ==================== */
.hidden {
    display: none !important;
}

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

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

/* ==================== Responsive Design ==================== */
@media (max-width: 768px) {
    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 20px;
    }

    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 12px;
        padding: 16px 0;
    }

    .nav-links.active {
        display: flex;
    }

    .menu-toggle {
        display: block;
    }

    .hero {
        padding: 48px 20px;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .hero-features {
        flex-direction: column;
        gap: 16px;
    }

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

    .pdf-page-editor {
        flex-direction: column;
    }

    .page-list-sidebar {
        width: 100%;
        max-height: 300px;
    }

    .upload-zone {
        padding: 32px 20px;
    }

    .file-item {
        flex-wrap: wrap;
    }

    .file-item .file-actions {
        width: 100%;
        justify-content: flex-end;
        margin-top: 8px;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .footer-inner {
        grid-template-columns: 1fr;
    }

    .toast-container {
        left: 20px;
        right: 20px;
    }

    .toast {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 24px 16px;
    }

    .tool-content {
        padding: 24px 16px;
    }

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

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

    .option-group label {
        font-size: 0.95rem;
    }
}
