/* ============================================
   MD2XMind - Style Sheet
   Clean, fresh, responsive design
   ============================================ */

:root {
    /* Color Palette - Soft & Fresh */
    --primary: #4A90D9;
    --primary-dark: #3A7BC8;
    --primary-light: #6FAEE6;
    --secondary: #50C878;
    --accent: #7EC8E3;
    --bg-main: #F0F4F8;
    --bg-card: #FFFFFF;
    --bg-soft: #E8F0F7;
    --text-main: #2C3E50;
    --text-light: #7F8C8D;
    --text-muted: #95A5A6;
    --border-color: #D5DDE5;
    --success: #27AE60;
    --error: #E74C3C;
    --warning: #F39C12;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.10);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --max-width: 960px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --font-mono: "SF Mono", "Fira Code", "Consolas", "Courier New", monospace;
}

/* RTL Support */
html[lang="ar"] {
    direction: rtl;
}
html[lang="ar"] body {
    direction: rtl;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    color: var(--text-main);
    background-color: var(--bg-main);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%234A90D9' stroke-opacity='0.06' stroke-width='1.5'%3E%3Ccircle cx='20' cy='20' r='8'/%3E%3Ccircle cx='60' cy='15' r='6'/%3E%3Ccircle cx='95' cy='30' r='5'/%3E%3Ccircle cx='40' cy='55' r='7'/%3E%3Ccircle cx='80' cy='65' r='6'/%3E%3Ccircle cx='25' cy='90' r='5'/%3E%3Ccircle cx='65' cy='95' r='7'/%3E%3Ccircle cx='100' cy='85' r='4'/%3E%3Cpath d='M20 20 Q40 38 60 15'/%3E%3Cpath d='M60 15 Q72 48 95 30'/%3E%3Cpath d='M20 20 Q30 38 40 55'/%3E%3Cpath d='M40 55 Q60 60 80 65'/%3E%3Cpath d='M80 65 Q88 75 95 30'/%3E%3Cpath d='M40 55 Q33 73 25 90'/%3E%3Cpath d='M80 65 Q72 80 65 95'/%3E%3Cpath d='M65 95 Q83 90 100 85'/%3E%3C/g%3E%3C/svg%3E");
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Screen Reader Only */
.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;
}

/* ============================================
   Header / Navigation
   ============================================ */
.site-header {
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-main);
    font-size: 1.25rem;
    font-weight: 700;
}

.logo-icon {
    flex-shrink: 0;
}

.logo-text {
    letter-spacing: -0.5px;
}

.logo-accent {
    color: var(--primary);
}

.lang-select {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color var(--transition);
}

.lang-select:hover,
.lang-select:focus {
    border-color: var(--primary);
    outline: none;
}

/* ============================================
   Hero Section
   ============================================ */
.hero {
    text-align: center;
    padding: 2.5rem 1.25rem 1.5rem;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
}

.hero h1 {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.hero-subtitle {
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    color: var(--text-light);
    max-width: 640px;
    margin: 0 auto;
}

/* ============================================
   Instructions Section
   ============================================ */
.instructions {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1rem 1.25rem;
    width: 100%;
}

.instructions h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.instr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.instr-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

.instr-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.instr-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
}

.instr-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-main);
}

.instr-card p {
    font-size: 0.85rem;
    color: var(--text-light);
    line-height: 1.5;
}

.md-example {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-sm);
    margin-top: 0.5rem;
}

.md-example summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    padding: 0.25rem 0;
}

.md-example-code {
    margin-top: 0.75rem;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-main);
    white-space: pre;
}

/* ============================================
   Tool Section
   ============================================ */
.tool-section {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1rem 1.25rem 2rem;
    width: 100%;
}

.input-block,
.format-block,
.convert-block,
.output-block,
.error-block,
.preview-block {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.input-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.md-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-main);
    background: var(--bg-card);
    resize: vertical;
    min-height: 180px;
    transition: border-color var(--transition);
}

.md-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.12);
}

.md-input::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}

.btn-secondary {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.char-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Upload hint text */
.upload-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
    padding: 0.4rem;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

/* Drag-over visual feedback */
.input-block.drag-over {
    border-color: var(--primary);
    background: var(--bg-soft);
}

.input-block.drag-over .md-input {
    border-color: var(--primary);
    background: var(--bg-soft);
}

.input-block.drag-over .upload-hint {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(74, 144, 217, 0.05);
}

/* ============================================
   Ad Slot
   ============================================ */
.ad-slot {
    margin: 1rem 0;
    min-height: 90px;
    text-align: center;
    overflow: hidden;
}

/* ============================================
   Format Selection
   ============================================ */
.format-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
}

.format-option {
    cursor: pointer;
}

.format-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.format-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.75rem 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition);
    text-align: center;
}

.format-option input:checked + .format-card {
    border-color: var(--primary);
    background: var(--bg-soft);
}

.format-option:hover .format-card {
    border-color: var(--primary-light);
}

.format-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.format-ext {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.image-sub-options {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.image-type-options {
    display: flex;
    gap: 1rem;
}

.image-type-option {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-main);
}

.image-type-option input[type="radio"] {
    accent-color: var(--primary);
}

/* ============================================
   Convert Button
   ============================================ */
.convert-block {
    text-align: center;
    padding: 1rem;
}

.btn-convert {
    display: inline-block;
    padding: 0.7rem 2.5rem;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-md);
}

.btn-convert:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-convert:active {
    transform: translateY(0);
}

.btn-convert:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   Loading
   ============================================ */
.loading-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    color: var(--text-light);
    font-size: 0.9rem;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Output / Download
   ============================================ */
.output-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.output-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--success);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
}

.output-info {
    flex: 1;
    min-width: 160px;
}

.output-status {
    font-weight: 600;
    color: var(--success);
    font-size: 0.95rem;
}

.output-filename {
    font-size: 0.85rem;
    color: var(--text-main);
    font-family: var(--font-mono);
}

.output-timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-download {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--secondary);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-download:hover {
    background: #45B567;
}

/* ============================================
   Error
   ============================================ */
.error-block {
    background: #FDEDEC;
    border: 1px solid #F5B7B1;
    color: var(--error);
    font-size: 0.875rem;
    padding: 0.75rem 1rem;
}

/* ============================================
   Preview
   ============================================ */
.preview-block h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.preview-canvas-wrapper {
    overflow: auto;
    text-align: center;
    max-height: 500px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    padding: 0.5rem;
}

#previewCanvas {
    max-width: 100%;
    height: auto;
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
    margin-top: auto;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 1.25rem;
}

.footer-content {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.footer-info p {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 0.2rem;
}

.footer-copy a {
    color: var(--primary);
    text-decoration: none;
}

.footer-copy a:hover {
    text-decoration: underline;
}

.footer-links {
    display: flex;
    gap: 1rem;
}

.footer-links a {
    font-size: 0.85rem;
    color: var(--text-main);
    text-decoration: none;
    transition: color var(--transition);
}

.footer-links a:hover {
    color: var(--primary);
}

/* ============================================
   RTL Adjustments
   ============================================ */
html[lang="ar"] .char-count {
    margin-left: 0;
    margin-right: auto;
}

html[lang="ar"] .footer-content {
    flex-direction: row-reverse;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 640px) {
    .navbar {
        padding: 0.6rem 1rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .hero {
        padding: 1.5rem 1rem 1rem;
    }

    .instr-grid {
        grid-template-columns: 1fr;
    }

    .tool-section {
        padding: 0.75rem 1rem 1.5rem;
    }

    .input-block,
    .format-block,
    .convert-block,
    .output-block,
    .error-block,
    .preview-block {
        padding: 1rem;
    }

    .md-input {
        min-height: 150px;
        font-size: 0.82rem;
    }

    .format-options {
        grid-template-columns: repeat(2, 1fr);
    }

    .btn-convert {
        width: 100%;
        padding: 0.7rem 1.5rem;
    }

    .output-card {
        flex-direction: column;
        text-align: center;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 400px) {
    .format-options {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .site-header,
    .ad-slot,
    .convert-block,
    .site-footer {
        display: none;
    }
}
