/* ==========================
   المتغيرات الأساسية للثيم
   ========================== */
:root {
    --header-offset: clamp(24px, 3.2vh, 40px); /* تعويض الرأس الثابت (نسبي) */
    --main-vpad: 2vh;      /* حشوة عمودية (نسبي) */

    --header-h: 90px;
    --footer-h: 78px;

    --primary-light: #4f7eb3;
    --primary: #2c5a8c;
    --primary-dark: #1a3a5c;
    --accent: #e6b31e;
    --accent-light: #f0c45a;
    --gray-50: #f9fafb;
    --gray-100: #f0f3f7;
    --gray-200: #e2e8f0;
    --gray-600: #475569;
    --gray-800: #1e293b;
    --shadow-sm: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --font-sans: 'Cairo', 'Tajawal', sans-serif;
    --border-radius: 20px;
    --transition: all 0.3s ease;
}

/* ==========================
   إعادة تعيين القيم الأساسية
   ========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, #f0f9ff 0%, #cfe3f0 100%);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================
   الرأس الثابت
   ========================== */
header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    padding: 1rem 2rem;
    box-shadow: var(--shadow-md);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
    backdrop-filter: blur(8px);
    border-bottom: 3px solid var(--accent);
}

[dir="rtl"] header {
    left: auto;
    right: 0;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    max-width: 1400px;
    margin: 0 auto;
}

.logo {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(135deg, white, var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-links a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
    position: relative;
    padding: 0.5rem 0;
}

.nav-links a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: var(--accent);
    transition: var(--transition);
}

.nav-links a:hover::after {
    width: 100%;
}

.nav-links select {
    padding: 0.5rem 1rem;
    border-radius: 30px;
    border: 2px solid var(--accent);
    background-color: white;
    color: var(--primary-dark);
    font-weight: bold;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: var(--transition);
}

.nav-links select:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* ==========================
   المحتوى الرئيسي (تعويض الرأس الثابت)
   ========================== */
main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.2vh 2vw;
    padding-bottom: 1rem;
    width: 100%;
    margin-top: var(--header-offset);
    min-height: calc(100vh - var(--header-h) - var(--footer-h));
}


/* ==========================
   الحاوية الأساسية
   ========================== */
.container {
    max-width: 1200px;
    width: 100%;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 1.75rem 2rem;
    margin: 0 auto;
    border: 1px solid rgba(255,255,255,0.3);
    max-height: calc(100vh - var(--header-h) - var(--footer-h) - 2rem);
    overflow: hidden;
}


h2 {
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
    font-weight: 800;
    font-size: 1.9rem;
    border-right: 5px solid var(--accent);
    padding-right: 1rem;
}


[dir="ltr"] h2 {
    border-right: none;
    border-left: 5px solid var(--accent);
    padding-left: 1rem;
    font-size: 1.55rem;
    line-height: 1.2;
    white-space: nowrap;
}


.description {
    margin-bottom: 2rem;
    color: var(--gray-600);
    font-size: 1.1rem;
}



/* ==========================
   تخطيط الأعمدة (إدخال + أزرار + إخراج)
   - الإدخال 38% + الإخراج 38% + الأزرار 18%
   - فراغ بين الأعمدة: 3% + 3% (إجمالي 6%)
   ========================== */
.main-layout {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 3%;
}


.main-layout .input-area,
.main-layout .output-area{
    flex: 0 0 38%;
    max-width: 38%;
    margin: 0;
}

.main-layout .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.85rem;
    margin: 0;
    align-content: start;
}


.main-layout .actions .btn{
    width: 100%;
}
/* ==========================
   منطقة الإدخال
   ========================== */
.input-area {
    margin-bottom: 2rem;
}

.input-area > div {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: 15px;
    margin-bottom: 0.8rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 1.1rem;
}

.input-area a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
}

.input-area a:hover {
    color: var(--accent);
}

textarea {
    width: 100%;
    min-height: 240px;
    padding: 1.5rem;
    border: 2px solid var(--gray-200);
    border-radius: 15px;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    resize: vertical;
    transition: var(--transition);
    background: white;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(44, 90, 140, 0.2), inset 0 2px 4px rgba(0,0,0,0.05);
}

/* ==========================
   الأزرار (تصميم شبكي متجاوب)
   ========================== */
.actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 0.9rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 2px solid transparent;
    background-size: 200% 200%;
}

.btn:hover {
    background-position: right center;
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--gray-600), var(--gray-800));
}

.btn-secondary:hover {
    background: linear-gradient(135deg, var(--gray-800), var(--gray-600));
}

/* ==========================
   صندوق التعليمات
   ========================== */
.toggle-instructions {
    margin: 1.5rem 0 1rem;
    text-align: center;
}

.toggle-instructions a {
    color: var(--primary-dark);
    text-decoration: underline;
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    transition: var(--transition);
}

.toggle-instructions a:hover {
    color: var(--accent);
}

.instructions {
    background: linear-gradient(135deg, var(--gray-50), white);
    border-radius: 20px;
    padding: var(--main-vpad) 2vw;
    margin-top: 1.5rem;
    border-right: 6px solid var(--accent);
    box-shadow: var(--shadow-sm);
}

.instructions.hidden {
    display: none;
}

.instructions h3 {
    color: var(--primary-dark);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.instructions ul {
    list-style: none;
    padding-right: 0;
}

.instructions li {
    margin-bottom: 0.75rem;
    padding-right: 2rem;
    position: relative;
    font-size: 1.1rem;
}

.instructions li::before {
    content: "✨";
    color: var(--accent);
    font-weight: bold;
    position: absolute;
    right: 0;
    font-size: 1.2rem;
}

.instructions button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary);
    padding: 0 0.5rem;
    transition: transform 0.2s;
}

.instructions button:hover {
    transform: scale(1.2);
    color: var(--accent);
}

.instructions:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent);
}

code {
    background-color: var(--gray-200);
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    color: var(--primary-dark);
    font-size: 0.95rem;
    font-weight: 600;
}

/* ==========================
   التذييل
   ========================== */
footer {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    text-align: center;
    padding: 1rem;
    font-size: 1rem;
    margin-top: 0;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.1);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 999;
    border-top: 3px solid var(--accent);
}


.footer-content p {
    margin: 0.5rem 0;
}

.footer-content a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.footer-content a:hover {
    text-decoration: underline;
    color: white;
}

/* ==========================
   تعديلات RTL
   ========================== */
[dir="rtl"] .navbar {
    flex-direction: row-reverse;
    justify-content: space-between;
}


[dir="rtl"] .nav-links {
    padding-right: 0;
}

[dir="rtl"] .instructions {
    border-right: 6px solid var(--accent);
    border-left: none;
}

[dir="rtl"] .instructions li::before {
    right: 0;
    left: auto;
}


/* ==========================
   توزيع الإدخال/الأزرار/الإخراج
   ========================== */
.input-area{
    flex: 0 0 38%;
    max-width: 38%;
    margin-bottom: 0;
}
.output-area{
    flex: 0 0 38%;
    max-width: 38%;
    margin-top: 0;
}
.actions{
    flex: 0 0 18%;
    max-width: 18%;
}

/* ==========================
   تصميم متجاوب للجوال
   ========================== */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-links {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .container {
        padding: 1.5rem;
    }

    h2 {
        font-size: 1.6rem;
    }

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

    .btn {
        width: 100%;
        justify-content: center;
    }

    textarea {
        min-height: 250px;
    }

    .main-layout{
        align-items: center;
        justify-content: center;

        flex-direction: column;
        gap: 1.5rem;
    }

    .main-layout .input-area,
    .main-layout .actions,
    .main-layout .output-area{
        flex: 0 0 100%;
        max-width: 100%;
    }

}


/* ==========================
   منطقة الإخراج
   ========================== */
.output-area {
    margin-top: 1.5rem;
}

/* زر إغلاق التعليمات */
#close-instructions {
    float: left;
}
[dir="ltr"] #close-instructions {
    float: right;
}


body.guide-mode main {
    margin-top: 0 !important;
    min-height: 100vh;
    align-items: center;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

body.guide-mode h2,
body.guide-mode .main-layout,
body.guide-mode form#export-form {
    display: none !important;
}

body.guide-mode #instructions-box {
    display: block !important;
}



/* ==========================
   وضع النوافذ (دليل الاستخدام / حول)
   - الرأس والتذييل يظلان ظاهرين
   - يُخفى محتوى الصفحة ويظهر صندوق واحد فقط
   ========================== */
.modal-box {
    border: 2px solid var(--gray-200);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid var(--gray-200);
    background: white;
    color: var(--primary-dark);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

[dir="ltr"] .modal-close {
    right: 12px;
    left: auto;
}

.modal-close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

a.link-close {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body.modal-mode .page-content {
    display: none !important;
}

body.modal-mode #instructions-box,
body.modal-mode #about-box {
    display: none;
}

body.modal-mode[data-modal="guide"] #instructions-box {
    display: block !important;
}

body.modal-mode[data-modal="about"] #about-box {
    display: block !important;
}



/* ==========================
   توسيع مناطق النص (نسبي)
   ========================== */
#input-text,
#output-text {
    min-height: 52vh; /* استثمار الفراغ بزيادة الارتفاع */


    .input-area,
    .actions,
    .output-area {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    #input-text,
    #output-text {
        min-height: 42vh;
    }
}



/* تصغير عنوان الصفحة (50%) */
.hero-title {
    font-size: clamp(1rem, 1.4vw, 1.1rem);
}

[dir="ltr"] .navbar { flex-direction: row; justify-content: space-between; }


/* ==========================
   التذييل: شريط ذهبي علوي + توزيع ثلاثي
   ========================== */
.site-footer {
    border-top: 3px solid var(--accent);
}

.footer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.footer-left, .footer-center, .footer-right {
    flex: 1;
}

.footer-left { text-align: right; }
.footer-center { text-align: center; }
.footer-right { text-align: left; }

[dir="ltr"] .footer-left { text-align: left; }
[dir="ltr"] .footer-right { text-align: right; }

/* عكس مواضع اليسار/اليمين بين RTL و LTR */
[dir="rtl"] .footer-left { order: 1; }
[dir="rtl"] .footer-center { order: 2; }
[dir="rtl"] .footer-right { order: 3; }

[dir="ltr"] .footer-left { order: 3; }
[dir="ltr"] .footer-center { order: 2; }
[dir="ltr"] .footer-right { order: 1; }

.footer-contact {
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}
.footer-contact:hover {
    text-decoration: underline;
}



/* Hero title: reduce size ~50% */
h2.hero-title{font-size:1rem !important;}

html[dir="rtl"] .navbar{flex-direction:row-reverse !important;}
html[dir="ltr"] .navbar{flex-direction:row !important;}

html[dir="rtl"] .footer-bar{flex-direction:row-reverse !important;}
html[dir="ltr"] .footer-bar{flex-direction:row !important;}
