/* ============ السمات ============ */
:root {
  --font-ui: "Segoe UI", system-ui, Tahoma, "Noto Sans Arabic", "Noto Sans", sans-serif;
  --font-text: "Segoe UI", system-ui, Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", sans-serif;
  --font-mono: "Cascadia Code", Consolas, "JetBrains Mono", "Courier New", monospace;
  --ribbon-w: 44px;
  --left-w: 260px;
  --right-w: 280px;
  --radius: 6px;
  --text-size: 16px;
  --line-h: 1.75;
}
[data-theme="dark"] {
  --bg-primary: #1e1f22;
  --bg-secondary: #26272b;
  --bg-tertiary: #2e3035;
  --bg-hover: #34363c;
  --bg-active: #3b3e46;
  --border: #3a3c42;
  --text-normal: #dcddde;
  --text-muted: #9a9ca3;
  --text-faint: #6c6f77;
  --accent: #2bbbad;
  --accent-soft: rgba(43, 187, 173, .16);
  --accent-text: #5fd9cc;
  --link: #5fd9cc;
  --link-unresolved: #8b8f98;
  --tag-bg: rgba(43, 187, 173, .14);
  --code-bg: #2a2c31;
  --mark-bg: rgba(255, 208, 0, .35);
  --danger: #e5534b;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --graph-node: #a6a9b0;
  --graph-unresolved: #5d6068;
  --graph-tag: #7fbf6e;
  --graph-attach: #d4a85a;
  --graph-line: #4a4d55;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f6f7;
  --bg-tertiary: #ececef;
  --bg-hover: #e8e8eb;
  --bg-active: #dfe0e4;
  --border: #e0e0e4;
  --text-normal: #222326;
  --text-muted: #6b6e76;
  --text-faint: #a0a3aa;
  --accent: #14897e;
  --accent-soft: rgba(20, 137, 126, .12);
  --accent-text: #0f766c;
  --link: #0f766c;
  --link-unresolved: #8d9099;
  --tag-bg: rgba(20, 137, 126, .1);
  --code-bg: #f3f3f5;
  --mark-bg: rgba(255, 208, 0, .45);
  --danger: #d1242f;
  --shadow: 0 10px 40px rgba(0, 0, 0, .15);
  --graph-node: #6e727b;
  --graph-unresolved: #c4c6cc;
  --graph-tag: #4c9a3c;
  --graph-attach: #b7862d;
  --graph-line: #d3d4d9;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-normal);
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
kbd {
  font-family: var(--font-mono); font-size: 11px; padding: 1px 5px; border-radius: 4px;
  background: var(--bg-tertiary); border: 1px solid var(--border); color: var(--text-muted);
  direction: ltr; display: inline-block;
}
.scroll { overflow: auto; }
.scroll::-webkit-scrollbar, textarea::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb, textarea::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }

/* ============ التخطيط ============ */
#app { flex: 1; display: flex; min-height: 0; }
#ribbon {
  width: var(--ribbon-w); flex: none; background: var(--bg-secondary);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px;
}
.rb, .ib {
  border: 0; background: transparent; cursor: pointer; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius);
}
.rb { width: 32px; height: 32px; }
.ib { width: 26px; height: 26px; }
.rb:hover, .ib:hover { background: var(--bg-hover); color: var(--text-normal); }
.rb.active, .ib.active { color: var(--accent-text); background: var(--accent-soft); }
.rb-sep { width: 20px; height: 1px; background: var(--border); margin: 6px 0; }
.rb-spacer { flex: 1; }

.sidebar {
  flex: none; background: var(--bg-secondary); display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
#left { width: var(--left-w); }
#right { width: var(--right-w); border-inline-start: 1px solid var(--border); overflow: auto; }
#app.left-hidden #left, #app.left-hidden .resizer[data-side="left"] { display: none; }
#app.right-hidden #right, #app.right-hidden .resizer[data-side="right"] { display: none; }
.resizer { width: 4px; flex: none; cursor: col-resize; background: var(--border); opacity: .4; transition: opacity .15s, background .15s; }
.resizer:hover, .resizer.dragging { opacity: 1; background: var(--accent); }
.resizer[data-side="right"] { width: 3px; background: transparent; margin-inline-end: -3px; z-index: 2; }
.resizer[data-side="right"]:hover { background: var(--accent); }

.pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 6px;
  font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: none;
}
.pane-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-actions { display: inline-flex; gap: 2px; }
#tree { flex: 1; padding: 2px 6px 40px; }

/* شجرة الملفات */
.tree-item {
  display: flex; align-items: center; gap: 4px; height: 27px; padding-inline-end: 8px;
  border-radius: var(--radius); cursor: pointer; color: var(--text-muted); user-select: none; white-space: nowrap;
}
.tree-item:hover { background: var(--bg-hover); color: var(--text-normal); }
.tree-item.active { background: var(--bg-active); color: var(--text-normal); }
.tree-item.drop-target { outline: 1px dashed var(--accent); background: var(--accent-soft); }
.tree-item .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-item .ext {
  font-size: 10px; padding: 0 4px; border-radius: 3px; background: var(--bg-tertiary); color: var(--text-faint); text-transform: uppercase;
}
.chev, .chev-space { width: 16px; height: 16px; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--text-faint); }
.chev svg { width: 12px; height: 12px; transition: transform .12s; transform: rotate(180deg); }
.chev.open svg { transform: rotate(90deg); }
#tree.root-drop { background: var(--accent-soft); }

/* البحث */
.search-box { padding: 4px 10px 8px; }
.search-box input, .modal input[type="text"] {
  width: 100%; padding: 7px 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-primary); outline: none;
}
.search-box input:focus, .modal input:focus { border-color: var(--accent); }
#search-info { padding: 0 12px 6px; }
#search-results { flex: 1; padding: 0 6px 40px; }
.sr-file { margin-bottom: 6px; }
.sr-title {
  padding: 4px 8px; font-weight: 600; cursor: pointer; border-radius: var(--radius); display: flex; justify-content: space-between; gap: 8px;
}
.sr-title:hover { background: var(--bg-hover); }
.sr-title .count { color: var(--text-faint); font-weight: 400; font-size: 12px; }
.sr-match {
  margin: 2px 8px 2px 4px; padding: 4px 8px; font-size: 12.5px; color: var(--text-muted); border-radius: var(--radius);
  cursor: pointer; background: var(--bg-primary); line-height: 1.6; word-break: break-word;
}
.sr-match:hover { color: var(--text-normal); }
mark, .sr-match mark { background: var(--mark-bg); color: inherit; border-radius: 2px; padding: 0 1px; }

/* الوسوم */
#tags-list { padding: 0 6px 40px; }
.tag-row { display: flex; justify-content: space-between; padding: 5px 10px; border-radius: var(--radius); cursor: pointer; color: var(--text-muted); }
.tag-row:hover { background: var(--bg-hover); color: var(--text-normal); }
.tag-row .count { font-size: 12px; color: var(--text-faint); }

/* ============ المنطقة الرئيسية ============ */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-primary); }
#tabbar {
  display: flex; align-items: flex-end; gap: 2px; height: 38px; padding: 6px 8px 0; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; flex: none;
}
#tabbar::-webkit-scrollbar { height: 0; }
.tab {
  display: flex; align-items: center; gap: 6px; height: 31px; padding: 0 10px; max-width: 220px; min-width: 90px;
  border-radius: 8px 8px 0 0; cursor: pointer; color: var(--text-muted); flex: none; position: relative; user-select: none;
}
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--bg-primary); color: var(--text-normal); box-shadow: 0 1px 0 var(--bg-primary); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tab .tab-close { width: 18px; height: 18px; border-radius: 4px; border: 0; background: none; cursor: pointer; color: var(--text-faint); display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.tab .tab-close:hover { background: var(--bg-active); color: var(--text-normal); }
.tab .tab-close svg { width: 13px; height: 13px; }
.tab.dirty .tab-name::after { content: " •"; color: var(--accent); }
.tab-new { border: 0; background: none; height: 28px; width: 28px; border-radius: 6px; cursor: pointer; color: var(--text-muted); flex: none; margin-bottom: 2px; }
.tab-new:hover { background: var(--bg-hover); }

#view { flex: 1; min-height: 0; position: relative; display: flex; }
#view > div { flex: 1; min-width: 0; }

#empty { display: flex; align-items: center; justify-content: center; }
.empty-inner { text-align: center; }
.logo { font-size: 44px; font-weight: 700; color: var(--accent-text); margin-bottom: 4px; letter-spacing: 1px; }
.empty-actions { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 14px; }
.link-btn {
  border: 0; background: none; color: var(--link); cursor: pointer; padding: 4px 8px; border-radius: var(--radius);
  display: inline-flex; gap: 8px; align-items: center;
}
.link-btn:hover { background: var(--bg-hover); }

/* عرض الملاحظة */
#note-view { display: flex; flex-direction: column; min-height: 0; }
.note-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px; height: 36px; flex: none; }
.crumbs { color: var(--text-faint); font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.crumbs span { cursor: default; }
.crumbs .sep { margin: 0 6px; }
.mode-switch { display: inline-flex; gap: 2px; }
.note-body { flex: 1; display: flex; min-height: 0; }
.pane-editor, .pane-preview { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane-editor { padding: 0; }
#note-view.mode-split .pane-preview { border-inline-start: 1px solid var(--border); }
#note-view.mode-edit .pane-preview { display: none; }
#note-view.mode-preview .pane-editor { display: none; }
#note-view:not(.mode-preview) #preview-title { display: none; }

.inline-title {
  font-size: 28px; font-weight: 700; border: 0; outline: none; background: transparent; padding: 18px 48px 6px;
  width: 100%; color: var(--text-normal); font-family: var(--font-text);
}
.inline-title.static { padding: 18px 0 6px; }
#editor {
  flex: 1; width: 100%; border: 0; outline: none; resize: none; background: transparent;
  padding: 8px 48px 50vh; font-family: var(--font-text); font-size: var(--text-size); line-height: var(--line-h);
  tab-size: 4; color: var(--text-normal); caret-color: var(--accent);
}
#editor::placeholder { color: var(--text-faint); }
.pane-preview { padding: 0 48px; }
#note-view.mode-preview .pane-preview > * { max-width: 780px; width: 100%; margin-inline: auto; }
#note-view.mode-edit #editor, #note-view.mode-edit .inline-title { max-width: 860px; margin-inline: auto; }

/* ============ عرض Markdown ============ */
.markdown { font-family: var(--font-text); font-size: var(--text-size); line-height: var(--line-h); padding-bottom: 40vh; word-wrap: break-word; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { line-height: 1.35; margin: 1.3em 0 .5em; font-weight: 700; }
.markdown h1 { font-size: 1.75em; }
.markdown h2 { font-size: 1.45em; }
.markdown h3 { font-size: 1.22em; }
.markdown h4 { font-size: 1.08em; }
.markdown h5, .markdown h6 { font-size: 1em; color: var(--text-muted); }
.markdown > :first-child { margin-top: .4em; }
.markdown p { margin: .6em 0; }
.markdown a { color: var(--link); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.markdown a.wikilink.unresolved { color: var(--link-unresolved); opacity: .85; text-decoration: underline dotted; }
.markdown a.external::after { content: "↗"; font-size: .75em; margin-inline-start: 2px; opacity: .7; }
.markdown a.tag {
  background: var(--tag-bg); color: var(--accent-text); padding: 1px 8px; border-radius: 999px; font-size: .88em; text-decoration: none;
}
.markdown code { font-family: var(--font-mono); font-size: .86em; background: var(--code-bg); padding: 2px 5px; border-radius: 4px; direction: ltr; unicode-bidi: isolate; }
.markdown .code-block { position: relative; margin: .9em 0; }
.markdown pre { background: var(--code-bg); padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; text-align: left; margin: 0; }
.markdown pre code { background: none; padding: 0; font-size: .85em; line-height: 1.6; }
.markdown .code-lang { position: absolute; top: 6px; left: 64px; font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }
.markdown .copy-code {
  position: absolute; top: 6px; left: 8px; font-size: 11px; border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-muted); border-radius: 4px; cursor: pointer; padding: 1px 8px; opacity: 0; transition: opacity .15s;
}
.markdown .code-block:hover .copy-code { opacity: 1; }
.tk-k { color: #c678dd; } .tk-s { color: #98c379; } .tk-n { color: #d19a66; } .tk-c { color: #7f848e; font-style: italic; } .tk-f { color: #61afef; }
[data-theme="light"] .tk-k { color: #a626a4; } [data-theme="light"] .tk-s { color: #50a14f; } [data-theme="light"] .tk-n { color: #986801; } [data-theme="light"] .tk-c { color: #a0a1a7; } [data-theme="light"] .tk-f { color: #4078f2; }
.markdown .math, .markdown .math-block { font-family: "Cambria Math", "Times New Roman", serif; font-style: italic; }
.markdown .math-block { text-align: center; margin: 1em 0; padding: 8px; background: var(--bg-secondary); border-radius: var(--radius); white-space: pre-wrap; }
.markdown blockquote { margin: .8em 0; padding: 2px 16px; border-inline-start: 3px solid var(--accent); color: var(--text-muted); }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.markdown ul, .markdown ol { padding-inline-start: 1.7em; margin: .5em 0; }
.markdown li { margin: .15em 0; }
.markdown li::marker { color: var(--text-muted); }
.markdown li.task { list-style: none; margin-inline-start: -1.4em; }
.markdown li.task > input { margin: 0 0 0 .5em; vertical-align: middle; accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }
[dir="ltr"] .markdown li.task > input, .markdown li.task[dir="ltr"] > input { margin: 0 .5em 0 0; }
.markdown li.task.done > span { color: var(--text-faint); text-decoration: line-through; }
.markdown img, .markdown video { max-width: 100%; border-radius: var(--radius); }
.markdown .table-wrap { overflow-x: auto; margin: 1em 0; }
.markdown table { border-collapse: collapse; min-width: 50%; font-size: .95em; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; text-align: start; }
.markdown th { background: var(--bg-secondary); font-weight: 600; }
.markdown mark { background: var(--mark-bg); }
.markdown del { color: var(--text-muted); }

.frontmatter { background: var(--bg-secondary); border-radius: var(--radius); padding: 8px 12px; margin: .6em 0 1.2em; font-size: .9em; }
.fm-title { font-size: 11px; color: var(--text-faint); margin-bottom: 4px; }
.frontmatter table { border: 0; min-width: 0; }
.frontmatter th, .frontmatter td { border: 0; padding: 3px 8px 3px 0; background: none; vertical-align: top; }
.frontmatter th { color: var(--text-muted); font-weight: 500; padding-inline-end: 18px; white-space: nowrap; }
.pill { background: var(--bg-tertiary); padding: 1px 8px; border-radius: 999px; margin-inline-end: 4px; }

.embed { border-inline-start: 3px solid var(--accent); background: var(--bg-secondary); border-radius: var(--radius); padding: 6px 16px; margin: 1em 0; }
.embed-title { font-size: 12px; margin-bottom: -4px; }
.embed-body .markdown, .embed-body { padding-bottom: 0; }

/* التنبيهات */
.callout { --c: 70, 140, 230; border-radius: var(--radius); background: rgba(var(--c), .1); border-inline-start: 3px solid rgb(var(--c)); padding: 10px 14px; margin: 1em 0; }
.callout-title { font-weight: 600; color: rgb(var(--c)); display: flex; align-items: center; gap: 8px; }
details.callout > summary { cursor: pointer; list-style: none; }
details.callout > summary::-webkit-details-marker { display: none; }
details.callout > summary::after { content: "‹"; margin-inline-start: auto; transition: transform .15s; }
details.callout[open] > summary::after { transform: rotate(-90deg); }
.callout-content > :first-child { margin-top: .4em; }
.callout-content > :last-child { margin-bottom: 0; }
.callout[data-callout="tip"], .callout[data-callout="hint"], .callout[data-callout="important"] { --c: 0, 175, 160; }
.callout[data-callout="success"], .callout[data-callout="check"], .callout[data-callout="done"] { --c: 70, 180, 90; }
.callout[data-callout="question"], .callout[data-callout="help"], .callout[data-callout="faq"], .callout[data-callout="warning"], .callout[data-callout="caution"], .callout[data-callout="attention"] { --c: 230, 150, 30; }
.callout[data-callout="failure"], .callout[data-callout="fail"], .callout[data-callout="missing"], .callout[data-callout="danger"], .callout[data-callout="error"], .callout[data-callout="bug"] { --c: 230, 80, 80; }
.callout[data-callout="example"] { --c: 150, 110, 230; }
.callout[data-callout="quote"], .callout[data-callout="cite"] { --c: 150, 150, 150; }
.callout[data-callout="abstract"], .callout[data-callout="summary"], .callout[data-callout="tldr"], .callout[data-callout="todo"] { --c: 40, 170, 220; }

/* ============ الشريط الأيمن ============ */
.rsec { border-bottom: 1px solid var(--border); }
.rsec-head {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 6px; font-size: 12px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; user-select: none;
}
.rsec-head .count { background: var(--bg-tertiary); border-radius: 999px; padding: 0 7px; font-weight: 500; font-size: 11px; }
.rsec.collapsed .rsec-body { display: none; }
.rsec-body { padding: 0 8px 10px; }
.rs-item { padding: 5px 8px; border-radius: var(--radius); cursor: pointer; }
.rs-item:hover { background: var(--bg-hover); }
.rs-item .rs-name { font-weight: 600; font-size: 13px; }
.rs-item .rs-name.unresolved { color: var(--link-unresolved); font-weight: 400; }
.rs-item .rs-ctx { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.5; word-break: break-word; }
.rs-ctx a { color: var(--link); text-decoration: none; }
.rs-ctx a.tag { background: var(--tag-bg); padding: 0 6px; border-radius: 999px; }
.rs-ctx ul, .rs-ctx ol { margin: 0; padding-inline-start: 1.1em; }
.rs-ctx input { display: none; }
.rs-ctx h1, .rs-ctx h2, .rs-ctx h3, .rs-ctx h4, .rs-ctx h5, .rs-ctx h6, .rs-ctx p { font-size: inherit; margin: 0; font-weight: 400; }
.rs-empty { color: var(--text-faint); font-size: 12.5px; padding: 4px 8px; }
.ol-item { padding: 3px 8px; border-radius: var(--radius); cursor: pointer; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ol-item:hover { background: var(--bg-hover); color: var(--text-normal); }

/* ============ الرسم البياني ============ */
#graph-view { position: relative; }
#graph-canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.graph-controls {
  position: absolute; top: 12px; inset-inline-start: 12px; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; box-shadow: var(--shadow); min-width: 170px;
}
.graph-controls label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.graph-controls label.range { flex-direction: column; align-items: stretch; gap: 2px; color: var(--text-muted); }
.graph-controls input[type="checkbox"], .graph-controls input[type="range"] { accent-color: var(--accent); }
.graph-stats { position: absolute; bottom: 10px; inset-inline-start: 14px; }

#file-view { display: flex; align-items: center; justify-content: center; overflow: auto; }
.file-view-inner { padding: 24px; text-align: center; }
.file-view-inner img, .file-view-inner video { max-width: 100%; max-height: 80vh; border-radius: var(--radius); }

/* ============ شريط الحالة ============ */
#statusbar {
  height: 24px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 12px; font-size: 11.5px;
  color: var(--text-muted); background: var(--bg-secondary); border-top: 1px solid var(--border);
}
.st-spacer { flex: 1; }

/* ============ النوافذ والقوائم ============ */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.modal { width: min(620px, 92vw); background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.modal.small { width: min(420px, 92vw); padding: 18px; }
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn { border: 1px solid var(--border); background: var(--bg-tertiary); padding: 6px 14px; border-radius: var(--radius); cursor: pointer; }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.palette input { border: 0 !important; border-bottom: 1px solid var(--border) !important; border-radius: 0 !important; padding: 14px 16px !important; font-size: 15px; background: transparent !important; }
.palette-list { max-height: 50vh; overflow: auto; padding: 6px; }
.p-item { padding: 8px 12px; border-radius: var(--radius); cursor: pointer; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.p-item.sel { background: var(--bg-active); }
.p-item .p-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-item .p-hint { color: var(--text-faint); font-size: 12px; white-space: nowrap; flex: none; }
.p-empty { padding: 12px; color: var(--text-faint); }
.palette-foot { border-top: 1px solid var(--border); padding: 6px 12px; font-size: 11.5px; color: var(--text-faint); display: flex; gap: 14px; }

#ctxmenu {
  position: fixed; z-index: 60; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 4px; min-width: 180px;
}
.cm-item { padding: 6px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.cm-item:hover { background: var(--bg-hover); }
.cm-item.danger { color: var(--danger); }
.cm-sep { height: 1px; background: var(--border); margin: 4px 2px; }

#suggest {
  position: fixed; z-index: 55; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 4px; width: 300px; max-height: 280px; overflow: auto;
}
.sg-item { padding: 6px 10px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.sg-item.sel { background: var(--bg-active); }
.sg-item .sg-path { font-size: 11px; color: var(--text-faint); display: block; }

#toasts { position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast { background: var(--bg-tertiary); border: 1px solid var(--border); padding: 8px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; animation: toastIn .2s ease; }
.toast.error { border-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  #right { display: none; }
  .resizer[data-side="right"] { display: none; }
  #editor, .inline-title { padding-inline: 20px; }
  .pane-preview { padding: 0 20px; }
}

/* ============ الهاتف ============ */
#md-toolbar, #drawer-backdrop { display: none; }
@media (max-width: 700px) {
  body { font-size: 15px; }
  #app { padding-bottom: calc(52px + env(safe-area-inset-bottom)); }
  #statusbar { display: none; }
  .resizer { display: none !important; }

  /* شريط الأيقونات يصبح شريط تنقل سفلي */
  #ribbon {
    position: fixed; bottom: 0; left: 0; right: 0; width: auto; height: calc(52px + env(safe-area-inset-bottom));
    flex-direction: row; justify-content: space-around; padding: 0 4px env(safe-area-inset-bottom); z-index: 40;
    border-inline-end: 0; border-top: 1px solid var(--border);
  }
  .rb-sep, .rb-spacer { display: none; }
  .rb { width: 40px; height: 40px; }
  .rb svg { width: 21px; height: 21px; }

  /* الأشرطة الجانبية تصبح أدراجاً منزلقة */
  .sidebar {
    position: fixed; top: 0; bottom: calc(52px + env(safe-area-inset-bottom)); width: min(86vw, 360px) !important; z-index: 35;
    box-shadow: var(--shadow); transition: transform .2s ease;
  }
  #left { inset-inline-start: 0; }
  #right { inset-inline-end: 0; display: flex !important; flex-direction: column; border: 0; }
  #app.left-hidden #left { display: flex !important; transform: translateX(110%); }
  #app.right-hidden #right { transform: translateX(-110%); }
  [dir="ltr"] #app.left-hidden #left { transform: translateX(-110%); }
  [dir="ltr"] #app.right-hidden #right { transform: translateX(110%); }
  #drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  #app:not(.left-hidden) #drawer-backdrop, #app:not(.right-hidden) #drawer-backdrop { display: block; }
  .tree-item, .tag-row, .ol-item { min-height: 38px; height: auto; }
  .pane-head .ib { width: 34px; height: 34px; }

  /* المحرر */
  #tabbar { height: 40px; }
  .tab { min-width: 0; max-width: 150px; }
  .crumbs { display: none; }
  .note-toolbar { justify-content: flex-end; }
  .mode-switch .ib { width: 36px; height: 34px; }
  .mode-switch [data-mode="split"] { display: none; }
  #note-view.mode-split .pane-preview { display: none; }
  .inline-title { font-size: 22px; padding: 10px 16px 4px; }
  .inline-title.static { padding: 10px 0 4px; }
  #editor { padding: 6px 16px 40vh; font-size: 16px; }
  .pane-preview { padding: 0 16px; }
  .markdown { font-size: 16px; }

  /* شريط التنسيق فوق لوحة المفاتيح */
  #note-view:not(.mode-preview) #md-toolbar {
    display: flex; gap: 2px; overflow-x: auto; padding: 4px 6px; border-top: 1px solid var(--border);
    background: var(--bg-secondary); flex: none; scrollbar-width: none;
  }
  #md-toolbar::-webkit-scrollbar { display: none; }
  #md-toolbar button {
    flex: none; min-width: 40px; height: 36px; border: 0; border-radius: 6px; background: transparent;
    color: var(--text-normal); font-size: 15px; font-family: var(--font-mono);
  }
  #md-toolbar button:active { background: var(--bg-active); }

  /* الرسم البياني */
  .graph-controls { top: 8px; inset-inline-start: 8px; padding: 8px 10px; min-width: 0; font-size: 12px; }
  .graph-controls label.range { display: none; }
  #graph-canvas { touch-action: none; }

  .overlay { padding-top: 6vh; }
  #suggest { width: min(300px, 90vw); }
  .markdown .copy-code { opacity: 1; }
}
