/* ===== محرّر الأكواد ===== */
/* الصفحة مقفولة على ارتفاع الشاشة: التمرير داخل الألواح وحدها */
html, body { height: 100%; margin: 0; overflow: hidden; }
.ed-page *, .ed-page *::before, .ed-page *::after { box-sizing: border-box; }
.ed-main, .ed-panes, .ed-pane { max-width: 100%; overflow: hidden; }
.ed-page {
    height: 100dvh; /* dvh يتجاهل شريط المتصفّح المتحرّك على الموبايل */
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--bg-main, #0d1117); color: var(--text-main, #c9d1d9);
}
@supports not (height: 100dvh) { .ed-page { height: 100vh; } }

.ed-bar {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    flex: 0 0 auto;
    padding: 12px 20px; border-bottom: 1px solid var(--border-color, #30363d);
    background: var(--bg-nav, #161b22);
}
.ed-bar h1 { font-size: 1.05rem; margin: 0; font-weight: 600; flex: 0 1 auto; min-width: 0; }
.ed-bar .ed-spacer { flex: 1 1 auto; }
.ed-home { color: var(--text-muted, #8b949e); text-decoration: none; font-size: 0.9rem; }
.ed-home:hover { color: var(--accent, #d5fa74); }

.ed-btn {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
    padding: 8px 15px; border-radius: 8px; font: inherit; font-size: 0.86rem; font-weight: 600;
    border: 1px solid var(--border-color, #30363d);
    background: transparent; color: var(--text-main, #c9d1d9);
    transition: background .18s, border-color .18s, transform .18s;
}
.ed-btn:hover { border-color: var(--accent, #d5fa74); transform: translateY(-1px); }
.ed-btn-primary { background: var(--accent, #d5fa74); color: #10140a; border-color: transparent; }
.ed-btn-primary:hover { opacity: .9; }

/* الحالة: تُقرأ بالصوت أيضاً عبر aria-live */
.ed-status { font-size: .8rem; color: var(--text-muted, #8b949e); min-height: 1em; }

/* الشبكة: تحرير | معاينة */
.ed-main { flex: 1 1 auto; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.ed-panes { display: flex; flex-direction: column; min-width: 0; border-inline-end: 1px solid var(--border-color, #30363d); }
.ed-pane { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; border-bottom: 1px solid var(--border-color, #30363d); }
.ed-pane:last-child { border-bottom: none; }
.ed-pane-head {
    display: flex; align-items: center; gap: 8px; padding: 7px 14px;
    font-size: .74rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--text-muted, #8b949e); background: rgba(255,255,255,.02);
    border-bottom: 1px solid var(--border-color, #30363d);
}
.ed-pane-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.ed-dot-html { background: #ff7b72; }
.ed-dot-css { background: #79c0ff; }
.ed-pane-head { flex: 0 0 auto; }
/* CodeMirror يقيس ارتفاعه عند الإنشاء، وـ height:100%
   داخل عنصر مرن قد لا ينحلّ؛ التحديد المطلق يعطيه صندوقاً قاطعاً */
.ed-editor { flex: 1 1 auto; min-height: 0; position: relative; direction: ltr; overflow: hidden; }
.ed-editor .CodeMirror {
    position: absolute; inset: 0; height: auto;
    font-size: 13.5px; direction: ltr; text-align: left;
}

/* المعاينة: خلفيّة بيضاء دائماً — كود الزائر يُكتب لصفحة عاديّة */
.ed-preview-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ed-preview { flex: 1 1 auto; width: 100%; min-height: 0; border: 0; background: #fff; }

/* على الموبايل الألواح الثلاثة فوق بعض: حبسها في شاشة واحدة
   يخلّي كلّ واحد منها قصيراً جدّاً، 
 فنرجع لتمرير الصفحة */
@media (max-width: 900px) {
    html, body { overflow-x: hidden; overflow-y: auto; }
    .ed-page { height: auto; min-height: 100dvh; overflow: visible; }
    .ed-main { grid-template-columns: 1fr; }
    .ed-panes { border-inline-end: none; border-bottom: 1px solid var(--border-color, #30363d); }
    /* الارتفاع يُضبط على صندوق المحرّر نفسه،
       لأنّ CodeMirror مُحدّد مطلقاً داخله ولا يدفع ارتفاع اللوح */
    .ed-pane { flex: 0 0 auto; }
    .ed-editor { height: 300px; }
    .ed-preview-wrap { flex: 0 0 auto; }
    .ed-preview { height: 420px; }
    /* شريط أضيق: حشوة أقلّ وخطّ أصغر، ويلتفّ عند الحاجة */
    .ed-bar { gap: 10px; padding: 10px 14px; }
    .ed-bar h1 { font-size: .95rem; }
}

/* ===== الفاحص: قياسات العنصر وهوامشه ===== */
.ed-btn.is-on { background: var(--accent, #d5fa74); color: #10140a; border-color: transparent; }

.ed-preview-wrap { position: relative; }
.ed-inspector {
    position: absolute; inset-inline-start: 0; inset-block-end: 0; width: min(330px, 100%);
    max-height: 72%; display: flex; flex-direction: column; z-index: 5;
    background: var(--bg-nav, #161b22); color: var(--text-main, #c9d1d9);
    border: 1px solid var(--border-color, #30363d); border-radius: 12px;
    margin: 12px; box-shadow: 0 12px 34px rgba(0,0,0,.45);
    direction: rtl;
}
.ed-inspector[hidden] { display: none; }
.ins-head {
    display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
    padding: 10px 14px; border-bottom: 1px solid var(--border-color, #30363d);
}
.ins-head strong { font-size: .84rem; }
.ins-hint { font-size: .7rem; opacity: .6; }
.ins-body { padding: 12px 14px; overflow-y: auto; font-size: .78rem; }
.ins-empty { opacity: .55; padding: 6px 0; }

.ins-sel {
    font-family: ui-monospace, Consolas, monospace; direction: ltr; text-align: left;
    color: var(--accent, #d5fa74); font-size: .8rem; word-break: break-all;
}
.ins-size { font-size: 1.05rem; margin: 2px 0 12px; direction: ltr; text-align: left; }
.ins-size span { opacity: .45; }
.ins-size small { font-size: .62rem; opacity: .5; }

/* مخطّط صندوق CSS: كل طبقة تحيط بالتي بعدها */
.ins-box { direction: ltr; margin-bottom: 12px; }
.ins-margin, .ins-border, .ins-padding {
    position: relative; border: 1px dashed rgba(255,255,255,.18);
    padding: 17px 8px 17px; text-align: center; border-radius: 4px;
}
.ins-margin  { background: rgba(255,168,117,.10); }
.ins-border  { background: rgba(200,180,255,.10); margin-top: 4px; }
.ins-padding { background: rgba(147,223,196,.10); margin-top: 4px; }
.ins-box i {
    position: absolute; inset-block-start: 2px; inset-inline-start: 6px;
    font-style: normal; font-size: .56rem; letter-spacing: .08em;
    text-transform: uppercase; opacity: .55;
}
.ins-box span { position: absolute; font-size: .62rem; font-family: ui-monospace, Consolas, monospace; }
.ins-box .bt { top: 3px; left: 50%; transform: translateX(-50%); }
.ins-box .bb { bottom: 3px; left: 50%; transform: translateX(-50%); }
.ins-box .bl { left: 4px; top: 50%; transform: translateY(-50%); }
.ins-box .br { right: 4px; top: 50%; transform: translateY(-50%); }
.ins-content {
    background: rgba(121,192,255,.16); border-radius: 3px;
    padding: 9px 6px; font-size: .68rem; font-family: ui-monospace, Consolas, monospace;
}

.ins-list { border-top: 1px solid var(--border-color, #30363d); padding-top: 8px; }
.ins-row { display: flex; gap: 10px; padding: 2.5px 0; align-items: baseline; }
.ins-k { flex: 0 0 34%; opacity: .58; font-size: .72rem; }
.ins-v {
    flex: 1 1 auto; direction: ltr; text-align: left; word-break: break-word;
    font-family: ui-monospace, Consolas, monospace; font-size: .72rem;
}

@media (max-width: 900px) {
    .ed-inspector { position: static; width: auto; max-height: none; margin: 0; border-radius: 0; border-inline: 0; }
}

/* ===== الثيم والاقتراحات ===== */
.ed-field { display: inline-flex; align-items: center; gap: 7px; }
.ed-field-label { font-size: .78rem; color: var(--text-muted, #8b949e); }
.ed-select {
    font: inherit; font-size: .82rem; padding: 7px 10px; border-radius: 8px;
    border: 1px solid var(--border-color, #30363d);
    background: var(--bg-main, #0d1117); color: var(--text-main, #c9d1d9);
    cursor: pointer; max-width: 150px;
}
.ed-select:focus-visible { outline: 2px solid var(--accent, #d5fa74); outline-offset: 1px; }
/* قائمة الخيارات ترسمها المنظومة: نثبّت ألوانها حتّى تُقرأ في الوضعين */
.ed-select option { background: #0d1117; color: #c9d1d9; }

/* قائمة الاقتراحات: تعلو على الألواح وعلى لوح الفاحص */
.CodeMirror-hints {
    z-index: 40; font-size: 13px; border-radius: 8px;
    font-family: ui-monospace, Consolas, monospace;
    border: 1px solid var(--border-color, #30363d);
    box-shadow: 0 10px 28px rgba(0,0,0,.45);
}
.CodeMirror-hint { padding: 3px 9px; }

/* الثيم الفاتح: الألواح تحتاج فصلاً واضحاً عن شريط الصفحة الغامق،
   وإلّا صار حدّ المحرّر غير مرئيّ تماماً */
.ed-light .ed-pane { border-color: #c8cdd6; }
.ed-light .ed-panes { border-inline-end-color: #c8cdd6; }
.ed-light .ed-pane-head {
    background: #eef1f6; color: #4a5160; border-bottom-color: #c8cdd6;
}
.ed-light .ed-editor { background: #fff; }

/* ===== روابط قسم تعلّم داخل شريط المحرّر ===== */
.ed-sec-nav { display: inline-flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.ed-sec-nav a {
    font-size: .82rem; text-decoration: none; white-space: nowrap;
    color: var(--text-muted, #8b949e);
}
.ed-sec-nav a:hover { color: var(--accent, #d5fa74); }
/* فاصل بين روابط القسم وعنوان الصفحة */
.ed-sec-nav::after {
    content: ''; width: 1px; height: 15px; margin-inline-start: 3px;
    background: var(--border-color, #30363d);
}
@media (max-width: 900px) { .ed-sec-nav { gap: 9px; } .ed-sec-nav a { font-size: .78rem; } }

/* ===== لوحة الإعدادات (ترس) =====
   بدل ستّة أزرار مبثوثة بالشريط، ترس واحد يفتح لوحة
   كلّ سطر فيها يشرح شنو يسوي الخيار. */
.ed-gear-wrap { position: relative; flex: 0 0 auto; }
.ed-gear { gap: 8px; }
.ed-gear-ico { font-size: 1.02rem; line-height: 1; transition: transform .35s ease; }
.ed-gear[aria-expanded="true"] { border-color: var(--accent, #d5fa74); }
.ed-gear[aria-expanded="true"] .ed-gear-ico { transform: rotate(90deg); }

.ed-settings {
    position: absolute; top: calc(100% + 9px); inset-inline-end: 0; z-index: 60;
    width: min(330px, calc(100vw - 28px));
    padding: 7px; border-radius: 12px;
    border: 1px solid var(--border-color, #30363d);
    /* اللوحة تطفو فوق المحرّر، فالخلفيّة معتمة تماماً لا شفّافة */
    background: #161b22;
    box-shadow: 0 18px 44px rgba(0, 0, 0, .5);
}
.ed-settings[hidden] { display: none; }

.ed-set-head {
    padding: 7px 10px 9px; font-size: .74rem; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; color: var(--text-muted, #8b949e);
}

/* السطر الواحد: نصّ يشرح على اليمين، ومفتاح أو قائمة على الطرف الثاني */
.ed-set-row {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 9px 10px; border-radius: 9px; text-align: start;
    font: inherit; color: var(--text-main, #c9d1d9);
    background: transparent; border: 0; cursor: pointer;
    transition: background .16s;
}
.ed-set-row:hover { background: rgba(255, 255, 255, .055); }
.ed-set-row:focus-visible { outline: 2px solid var(--accent, #d5fa74); outline-offset: -2px; }
.ed-set-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.ed-set-name { font-size: .87rem; font-weight: 600; }
.ed-set-note { font-size: .73rem; line-height: 1.5; color: var(--text-muted, #8b949e); }

.ed-set-row .ed-select { flex: 0 0 auto; max-width: 132px; }

/* المفتاح: أوضح من زرّ ملوّن، يبيّن المطفي والمشتغل بالشكل نفسه */
.ed-switch {
    position: relative; flex: 0 0 auto; width: 38px; height: 21px; border-radius: 999px;
    background: rgba(255, 255, 255, .13);
    border: 1px solid var(--border-color, #30363d);
    transition: background .2s, border-color .2s;
}
.ed-switch::after {
    content: ''; position: absolute; top: 2px; inset-inline-start: 2px;
    width: 15px; height: 15px; border-radius: 50%;
    background: #8b949e; transition: transform .2s, background .2s;
}
.ed-set-toggle[aria-pressed="true"] .ed-switch {
    background: var(--accent, #d5fa74); border-color: transparent;
}
.ed-set-toggle[aria-pressed="true"] .ed-switch::after { background: #10140a; }
/* الإبهام يمشي نحو الطرف المقابل، وفي RTL يكون لليسار */
[dir="rtl"] .ed-set-toggle[aria-pressed="true"] .ed-switch::after { transform: translateX(-17px); }
[dir="ltr"] .ed-set-toggle[aria-pressed="true"] .ed-switch::after { transform: translateX(17px); }

.ed-set-sep { height: 1px; margin: 5px 10px; background: var(--border-color, #30363d); }
/* «استرجاع المثال» ما عنده مفتاح، فسهمه ينلزق جنب النصّ
   بدل ما يبقى معلّق بالطرف الثاني من اللوحة */
.ed-set-act .ed-set-txt { flex: 0 1 auto; }
.ed-set-act .ed-set-go {
    flex: 0 0 auto; margin-inline-end: auto;
    font-size: 1.05rem; color: var(--text-muted, #8b949e);
    transition: color .16s;
}
.ed-set-act:hover .ed-set-go { color: var(--accent, #d5fa74); }

@media (max-width: 900px) {
    /* الشريط يلتفّ، فنثبّت اللوحة بحاشية الشاشة لا بالزرّ حتّى ما تطلع برّا */
    .ed-gear-txt { display: none; }
    .ed-settings { position: fixed; top: var(--ed-set-top, 64px); inset-inline: 14px; width: auto; }
}
