/* --- Global Styles & Variables --- */
:root {
    --font-family: 'Tajawal', sans-serif; /* A modern Arabic font, fallback to sans-serif */

    /* Light Mode */
    --bg-light: #f4f7f9;
    --surface-light: #ffffff;
    --text-primary-light: #2c3e50;
    --text-secondary-light: #7f8c8d;
    --border-light: #e0e6ed;
    --accent-light: #3498db;
    --accent-hover-light: #2980b9;
    --danger-light: #e74c3c;
    --danger-hover-light: #c0392b;

    /* Dark Mode */
    --bg-dark: #2c3e50;
    --surface-dark: #34495e;
    --text-primary-dark: #ecf0f1;
    --text-secondary-dark: #bdc3c7;
    --border-dark: #4a627a;
    --accent-dark: #3498db;
    --accent-hover-dark: #5dade2;
    --danger-dark: #e74c3c;
    --danger-hover-dark: #f1948a;
}

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    transition: background-color 0.3s, color 0.3s;
}

.light-mode {
    background-color: var(--bg-light);
    color: var(--text-primary-light);
}

.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-primary-dark);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background-color: var(--surface-light);
    border-bottom: 1px solid var(--border-light);
}

.dark-mode header {
    background-color: var(--surface-dark);
    border-bottom: 1px solid var(--border-dark);
}

.theme-switcher {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-secondary-light);
}
.dark-mode .theme-switcher { color: var(--text-secondary-dark); }

/* --- Drop Zone --- */
#drop-zone {
    border: 3px dashed var(--border-light);
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--surface-light);
}
.dark-mode #drop-zone { 
    border-color: var(--border-dark);
    background-color: var(--surface-dark);
}
#drop-zone:hover, #drop-zone.drag-over {
    border-color: var(--accent-light);
    background-color: #e9f5ff;
}
.dark-mode #drop-zone:hover, .dark-mode #drop-zone.drag-over {
    border-color: var(--accent-dark);
    background-color: #3b5269;
}
#drop-zone i {
    font-size: 4rem;
    color: var(--accent-light);
}
.dark-mode #drop-zone i { color: var(--accent-dark); }
#drop-zone p {
    margin-top: 15px;
    font-size: 1.2rem;
    color: var(--text-secondary-light);
}
.dark-mode #drop-zone p { color: var(--text-secondary-dark); }
.hidden { display: none !important; }

/* --- Preview Container --- */
#preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.preview-card {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    background-color: var(--surface-light);
    border: 1px solid var(--border-light);
    transition: transform 0.2s, box-shadow 0.2s;
    height: 220px;
    display: flex;
    flex-direction: column;
}
.dark-mode .preview-card {
    background-color: var(--surface-dark);
    border-color: var(--border-dark);
}
.preview-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.preview-card .drag-handle {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    cursor: grab;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-move"><polyline points="5 9 2 12 5 15"></polyline><polyline points="9 5 12 2 15 5"></polyline><polyline points="15 19 12 22 9 19"></polyline><polyline points="19 9 22 12 19 15"></polyline><line x1="2" y1="12" x2="22" y2="12"></line><line x1="12" y1="2" x2="12" y2="22"></line></svg>');
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.2;
    z-index: 10;
}
.preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
}
.preview-card .card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    color: white;
    padding: 10px;
    opacity: 0;
    transition: opacity 0.3s;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}
.preview-card:hover .card-overlay {
    opacity: 1;
}
.card-title {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.card-actions {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 8px;
}
.card-actions button {
    background: rgba(0,0,0,0.5);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
}
.card-actions button:hover { background: var(--accent-light); }

/* OCR Toggle */
.ocr-toggle {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 5px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 34px; height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc; transition: .4s; border-radius: 20px;
}
.slider:before {
  position: absolute; content: ""; height: 14px; width: 14px;
  left: 3px; bottom: 3px; background-color: white;
  transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent-light); }
input:checked + .slider:before { transform: translateX(14px); }


/* --- Settings Panel --- */
#settings-panel {
    background-color: var(--surface-light);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 25px;
    margin-top: 30px;
}
.dark-mode #settings-panel {
    background-color: var(--surface-dark);
    border-color: var(--border-dark);
}
#settings-panel h2 {
    margin-bottom: 20px;
    text-align: center;
}
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}
.setting-card {
    background-color: var(--bg-light);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 20px;
}
.dark-mode .setting-card {
    background-color: var(--bg-dark);
    border-color: var(--border-dark);
}
.setting-card h3 {
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
    font-size: 1.1rem;
}
.dark-mode .setting-card h3 { border-color: var(--border-dark); }
.form-group {
    margin-bottom: 15px;
}
.form-group:last-child { margin-bottom: 0; }
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: var(--text-secondary-light);
}
.dark-mode .form-group label { color: var(--text-secondary-dark); }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-light);
    border-radius: 5px;
    background-color: var(--surface-light);
    color: var(--text-primary-light);
}
.dark-mode .form-group input, .dark-mode .form-group select {
    background-color: var(--surface-dark);
    border-color: var(--border-dark);
    color: var(--text-primary-dark);
}
.header-footer-inputs { display: flex; gap: 5px; }
.presets-controls { display: flex; gap: 10px; }
.presets-controls select { flex-grow: 1; }

/* --- Buttons --- */
.button-primary, .button-secondary, .button-danger {
    padding: 12px 25px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s;
    font-family: var(--font-family);
}
.button-primary { background-color: var(--accent-light); color: white; }
.button-primary:hover:not(:disabled) { background-color: var(--accent-hover-light); }
.dark-mode .button-primary { background-color: var(--accent-dark); }
.dark-mode .button-primary:hover:not(:disabled) { background-color: var(--accent-hover-dark); }

.button-danger { background-color: var(--danger-light); color: white; }
.button-danger:hover:not(:disabled) { background-color: var(--danger-hover-light); }
.dark-mode .button-danger { background-color: var(--danger-dark); }
.dark-mode .button-danger:hover:not(:disabled) { background-color: var(--danger-hover-dark); }

.button-secondary { 
    background-color: #bdc3c7;
    color: #2c3e50;
}
.button-secondary:hover:not(:disabled) { background-color: #95a5a6; }
.dark-mode .button-secondary {
    background-color: #7f8c8d;
    color: white;
}
.dark-mode .button-secondary:hover:not(:disabled) { background-color: #95a5a6; }

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.main-actions {
    margin-top: 25px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* --- Progress Bar --- */
#progress-bar-container { margin: 20px 0; }
#progress-text { display: block; text-align: center; margin-bottom: 8px; }
.progress-bar-bg {
    height: 10px;
    background-color: var(--border-light);
    border-radius: 5px;
    overflow: hidden;
}
.dark-mode .progress-bar-bg { background-color: var(--border-dark); }
#progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--accent-light);
    border-radius: 5px;
    transition: width 0.3s;
}
.dark-mode #progress-bar { background-color: var(--accent-dark); }

/* --- Modals (Editor & Lightbox) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    justify-content: center;
    align-items: center;
}
.modal-content {
    background-color: var(--surface-light);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    gap: 20px;
    max-width: 90vw;
    max-height: 90vh;
}
.dark-mode .modal-content { background-color: var(--surface-dark); }

/* Editor Modal */
.editor-container { flex: 3; max-width: 70vw; }
#editor-image { max-width: 100%; max-height: 75vh; display: block; }
.editor-controls { flex: 1; min-width: 250px; }
.modal-actions { margin-top: 20px; display: flex; gap: 10px; }

/* Lightbox Modal */
#lightbox-modal { align-items: center; justify-content: center; }
.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}
#lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    display: block;
    border-radius: 5px;
}
#lightbox-caption {
    position: absolute;
    bottom: -40px;
    left: 0;
    width: 100%;
    text-align: center;
    color: white;
    font-size: 1.1rem;
}
.lightbox-control {
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    color: white;
    user-select: none;
    padding: 10px;
    transition: background 0.2s;
    z-index: 1001;
}
.lightbox-control:hover { background: rgba(0,0,0,0.3); }
#lightbox-close { top: 15px; right: 35px; font-size: 4rem; }
#lightbox-prev { right: 10px; } /* In RTL */
#lightbox-next { left: 10px; } /* In RTL */


/* --- Responsive Design --- */
@media (max-width: 768px) {
    header {
        padding: 10px 15px;
    }
    h1 { font-size: 1.5rem; }
    
    #preview-container {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 15px;
    }
    .preview-card { height: 180px; }

    .modal-content {
        flex-direction: column;
        padding: 15px;
        max-width: 95vw;
        max-height: 95vh;
    }
    .editor-container { max-width: 100%; }
    #editor-image { max-height: 60vh; }
    
    .settings-grid {
        grid-template-columns: 1fr;
    }
    
    .main-actions {
        flex-direction: column;
        gap: 10px;
    }
}

footer {
    text-align: center;
    padding: 20px;
    margin-top: 20px; /* Pushes footer away from content */
    background-color: var(--surface-light);
    border-top: 1px solid var(--border-light);
    color: var(--text-secondary-light);
    font-size: 0.9rem;
}
.dark-mode footer {
    background-color: var(--surface-dark);
    border-top: 1px solid var(--border-dark);
    color: var(--text-secondary-dark);
}
footer p {
    margin: 5px 0;
}
footer a {
    color: var(--accent-light);
    text-decoration: none;
    font-weight: bold;
}
.dark-mode footer a {
    color: var(--accent-dark);
}
footer a:hover {
    text-decoration: underline;
}