@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&family=Tajawal:wght@400;500;700&family=Noto+Kufi+Arabic:wght@400;500;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #8b5cf6;
    --secondary-dark: #7c3aed;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark-bg: #1e293b;
    --light-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--gradient-bg);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--text-primary);
    direction: rtl;
    transition: all 0.4s ease;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

.header {
    text-align: center;
    padding: 2rem 1rem;
    color: white;
    position: relative;
}

.header h1 {
    font-size: 2.8rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    font-weight: 700;
    background: linear-gradient(120deg, #ffffff, #e0e7ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 1.3rem;
    opacity: 0.95;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
}

.settings-toggle {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: var(--glass-bg);
    border: 2px solid var(--glass-border);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 1.5rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: pulse 2s infinite;
}

.settings-toggle:hover {
    transform: rotate(90deg) scale(1.1);
    background: rgba(255, 255, 255, 0.2);
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 350px;
    height: 100vh;
    background: var(--card-bg);
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    overflow-y: auto;
}

.settings-panel:not(.hidden) {
    right: 0;
}

.settings-content {
    padding: 2rem;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.settings-header h3 {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.close-settings {
    background: var(--danger-color);
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.close-settings:hover {
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.setting-group select,
.setting-group input[type="range"] {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.setting-group select:focus,
.setting-group input[type="range"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.setting-group input[type="range"] {
    padding: 0;
    height: 8px;
    background: var(--border-color);
    cursor: pointer;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}

.setting-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.theme-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.theme-btn {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.theme-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.main-content {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    min-height: 500px;
    backdrop-filter: blur(10px);
    animation: slideUp 0.6s ease-out;
}

.upload-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.upload-area {
    text-align: center;
    padding: 3rem;
    border: 3px dashed var(--border-color);
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.upload-area::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
    opacity: 0;
    transform: translate(-50%, -50%);
    transition: all 0.6s ease;
}

.upload-area:hover::before {
    width: 400px;
    height: 400px;
    opacity: 0.1;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: var(--light-bg);
    transform: translateY(-5px) scale(1.02);
    box-shadow: var(--shadow-lg);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.upload-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite;
}

.upload-area h2 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    position: relative;
    z-index: 1;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 1;
}

.upload-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

.btn {
    padding: 0.85rem 1.8rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

.btn-primary:active {
    transform: translateY(-1px);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-dark) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-secondary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.5);
}

.btn-small {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
}

.editor-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    animation: fadeIn 0.5s ease-out;
}

.preview-area, .tools-area {
    background: var(--light-bg);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.preview-area:hover, .tools-area:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 700;
}

.preview-content {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    min-height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    max-height: 500px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.preview-content:hover {
    box-shadow: inset 0 2px 15px rgba(0, 0, 0, 0.08);
}

#pdfCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

#pdfCanvas:hover {
    transform: scale(1.02);
}

#imagePreview {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

#imagePreview:hover {
    transform: scale(1.02);
}

.text-section {
    margin-top: 1.5rem;
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    animation: slideDown 0.4s ease-out;
    transition: all 0.3s ease;
}

.text-section:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

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

.text-header h4 {
    color: var(--primary-color);
    font-size: 1.2rem;
    font-weight: 700;
}

.text-content {
    width: 100%;
    text-align: right;
    line-height: 1.8;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 16px;
    transition: all 0.3s ease;
    background: var(--light-bg);
    padding: 1.5rem;
    border-radius: 10px;
    min-height: 150px;
    max-height: 400px;
    overflow-y: auto;
}

.text-content:hover {
    background: #f1f5f9;
}

.text-content::selection {
    background: var(--primary-color);
    color: white;
}

.text-content::-moz-selection {
    background: var(--primary-color);
    color: white;
}

.page-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

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

.tools-area h3 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-weight: 700;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.tool-btn {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 15px;
    padding: 1.2rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.tool-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.1), transparent);
    transition: left 0.5s ease;
}

.tool-btn:hover::before {
    left: 100%;
}

.tool-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.3);
    background: linear-gradient(135deg, #ffffff 0%, #f0f4ff 100%);
}

.tool-btn:active {
    transform: translateY(-2px) scale(1.02);
}

.tool-icon {
    font-size: 2.5rem;
    transition: transform 0.3s ease;
}

.tool-btn:hover .tool-icon {
    transform: scale(1.2) rotate(5deg);
}

.tool-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.custom-prompt {
    margin-top: 1.5rem;
}

.custom-prompt textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
}

.custom-prompt textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.result-area {
    margin-top: 1.5rem;
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    animation: slideDown 0.4s ease-out;
}

.result-area h4 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.result-content {
    background: var(--light-bg);
    padding: 1.5rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
}

.result-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.spinner {
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 0.8s linear infinite;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.loading p {
    margin-top: 1.5rem;
    color: var(--text-secondary);
    font-size: 1.2rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.footer {
    text-align: center;
    padding: 2rem 1rem;
    color: white;
    margin-top: 2rem;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes animate-fade-in {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: animate-fade-in 0.8s ease-out;
}

.animate-fade-in-delay {
    animation: animate-fade-in 0.8s ease-out 0.3s both;
}

body.dark-theme {
    --gradient-bg: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --card-bg: #1e293b;
    --light-bg: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #475569;
}

body.light-theme {
    --gradient-bg: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    --card-bg: #ffffff;
    --light-bg: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
    }

    .header h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .settings-toggle {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    .main-content {
        padding: 1.5rem;
        border-radius: 20px;
    }

    .editor-section {
        grid-template-columns: 1fr;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .upload-area h2 {
        font-size: 1.3rem;
    }

    .upload-icon {
        font-size: 4rem;
    }

    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .tool-btn {
        padding: 1rem;
    }

    .tool-icon {
        font-size: 2rem;
    }

    .tool-label {
        font-size: 0.85rem;
    }

    .text-section {
        padding: 1rem;
    }

    .text-content {
        padding: 1rem;
        max-height: 300px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.6rem;
    }

    .upload-buttons {
        flex-direction: column;
        width: 100%;
    }

    .upload-buttons .btn {
        width: 100%;
    }

    .tools-grid {
        gap: 0.5rem;
    }

    .tool-btn {
        padding: 0.75rem;
    }

    .text-section {
        padding: 0.75rem;
    }

    .text-content {
        padding: 0.75rem;
        font-size: 14px;
        max-height: 250px;
    }
}

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