/* shell.css — القشرة بحسب رؤية «دفتر القيادة» (S0، 2026-11-14؛ قرار المالك يغيّر A-29 وقائمة الأبواب A-14).
 * الجوال والآيباد (<1024): ترويسة (عنوان + دردشة + جرس + صورة) وشريط سفلي: الرئيسية · القطيع · «＋ سجّل» مرتفع · المال · السوق.
 * الحاسوب (≥1024): شريط جانبي أيمن ثابت 256 (العلامة، «＋ سجّل»، الأبواب وأقسامها، المستخدم) هو نفسه #tabs.
 * بلا ألوان حرفية: رموز system.css وحدها. تُحمَّل بعد frame.css وبمحدِّدات المعرّفات (#tabs/#bottombar) لتغلب قواعد القشرة الموروثة. */

/* ───────── الترويسة ───────── */
html[data-ui="copper"] body .topbar {
  position: sticky; top: 0; z-index: var(--z-chrome, 5);
  flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: var(--sp-2);
  min-height: 56px; height: auto; padding: calc(4px + env(safe-area-inset-top)) var(--sp-4) 4px;
  background: var(--bg); color: var(--ink); border: 0; box-shadow: none;
}
html[data-ui="copper"] body .topbar::before, html[data-ui="copper"] body .topbar::after { content: none; }
html[data-ui="copper"] body .topbar .who { flex: 0 0 auto; }
html[data-ui="copper"] body .topbar .brand-wordmark { display: none; }
html[data-ui="copper"] body .topbar .topbar-title:not([hidden]) { display: block; order: -1; min-width: 0; margin-inline-end: auto; }
html[data-ui="copper"] body .topbar .topbar-title h1 { margin: 0; font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600; line-height: 1.5; padding-block: 2px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[data-ui="copper"] body .topbar .topbar-title p { margin: 0; font-size: var(--fs-label); line-height: 1.5; padding-block: 2px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[data-ui="copper"] body .topbar .topbar-actions { gap: 2px; margin-inline-start: auto; }
html[data-ui="copper"] body .topbar #alerts-bell, html[data-ui="copper"] body .topbar #cart-button,
html[data-ui="copper"] body .topbar #chat-button, html[data-ui="copper"] body .topbar #settings-gear { order: 0; }
html[data-ui="copper"] body .topbar :is(.bell, .icon-btn) {
  position: relative; width: var(--touch); height: var(--touch); min-height: var(--touch); padding: 0;
  display: inline-grid; place-items: center; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink); box-shadow: none;
}
html[data-ui="copper"] body .topbar :is(.bell, .icon-btn):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
html[data-ui="copper"] body .topbar :is(.bell .badge, .chat-badge, .cart-badge) {
  position: absolute; top: 2px; inset-inline-end: 0; inset-inline-start: auto;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--danger); color: var(--on-danger); font-size: var(--fs-label); font-weight: 700; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px var(--bg);
}
html[data-ui="copper"] body .topbar #settings-gear .profile-avatar { box-shadow: none; border: 1px solid var(--accent); background: var(--surface-2); color: var(--accent-ink); }

/* ───────── الشريط السفلي (<1024) ───────── */
@media (max-width: 1023.98px) {
  html[data-ui="copper"] body #tabs { display: none; }
  html[data-ui="copper"] body #bottombar {
    position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-chrome, 5);
    display: grid; align-items: stretch; gap: 0; height: auto; min-height: 76px;
    padding: 6px var(--sp-2) calc(10px + env(safe-area-inset-bottom));
    background: var(--chrome); border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  html.kb-open[data-ui="copper"] body #bottombar { display: none; }   /* لوحة المفاتيح ظاهرة: الشريط مخفي (styles.css) ويغلب display:grid بمحدِّد المعرّف */
  html[data-ui="copper"] body #bottombar .tab {
    position: relative; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px;
    min-width: 0; min-height: var(--touch); height: auto; padding: 0 0 2px; border: 0; border-radius: 0; background: none; box-shadow: none; scale: none;
    color: var(--muted); font: inherit; font-size: var(--fs-label); font-weight: 500; line-height: 1.2;
  }
  html[data-ui="copper"] body #bottombar .tab .nav-icon-shell { position: relative; display: grid; place-items: center; width: auto; height: auto; margin: 0; padding: 0; background: none; }
  html[data-ui="copper"] body #bottombar .tab svg.ui-icon { width: 24px; height: 24px; }
  html[data-ui="copper"] body #bottombar .tab .ui-tone { opacity: 0; }
  html[data-ui="copper"] body #bottombar .tab .nav-label {
    position: static; display: block; width: auto; height: auto; margin: 0; padding: 0; overflow: hidden; clip: auto; clip-path: none; opacity: 1;
    max-width: 100%; font-size: var(--fs-label); font-weight: inherit; line-height: 1.5; white-space: nowrap; text-overflow: ellipsis; color: inherit;
  }
  html[data-ui="copper"] body #bottombar .tab:is(.is-active, [aria-current="page"]) { background: none; box-shadow: none; border: 0; color: var(--accent-ink); font-weight: 600; }
  html[data-ui="copper"] body #bottombar .tab:is(.is-active, [aria-current="page"]) .nav-icon-shell { background: none; }
  html[data-ui="copper"] body #bottombar .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-sm); }
  html[data-ui="copper"] body #bottombar .tab-add { color: var(--ink); font-weight: 600; }
  html[data-ui="copper"] body #bottombar .tab-add .record-fab {
    display: grid; place-items: center; width: 54px; height: 54px; margin-top: -30px; border-radius: 19px;
    background: var(--primary); color: var(--on-primary); box-shadow: 0 0 0 4px var(--bg);
  }
  html[data-ui="copper"] body #bottombar .tab-add .record-fab svg { width: 26px; height: 26px; stroke-width: 2.2; }
  html[data-ui="copper"] body #bottombar .tab-add:focus-visible .fab { outline: 2px solid var(--accent); outline-offset: 4px; }
  /* WAVE2 (H5): آخر عنصر يظهر كاملاً عند نهاية التمرير = ارتفاع الشريط السفلي الفعلي (--bar-h يقيسه core.js وفيه حشوة safe-area) + بروز زر ＋ (30) + 16 */
  html[data-ui="copper"] main, html[data-ui="copper"] body:not(:has(.chat-shell)) main#view { padding-bottom: calc(var(--bar-h, 76px) + 30px + 16px); }
}

/* ───────── الشريط الجانبي (≥1024): هو نفسه #tabs ───────── */
@media (min-width: 1024px) {
  html[data-ui="copper"] body #bottombar { display: none; }
  html[data-ui="copper"] body #tabs {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: var(--z-chrome, 5);
    display: flex; flex-direction: column; flex-wrap: nowrap; gap: 0; width: var(--sidebar-w, 256px); margin: 0;
    padding: 18px 14px 14px; overflow-y: auto; background: var(--chrome); color: var(--ink);
    border: 0; border-inline-end: 1px solid var(--line); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  html[data-ui="copper"] body #tabs .sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 16px; }
  html[data-ui="copper"] body #tabs .sidebar-brand b { display: block; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; line-height: 1.3; }
  html[data-ui="copper"] body #tabs .sidebar-brand small { display: block; font-size: var(--fs-label); color: var(--muted); }
  html[data-ui="copper"] body #tabs .side-logo { width: auto; height: 36px; flex: none; }
  html[data-ui="copper"] body #tabs .side-register {
    margin-bottom: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: var(--touch, 48px);
    border: 1px solid transparent; border-radius: var(--r-md); background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600; cursor: pointer;
  }
  html[data-ui="copper"] body #tabs .side-register:hover { filter: brightness(1.08); }
  html[data-ui="copper"] body #tabs .side-register:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  html[data-ui="copper"] body #tabs .nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
  html[data-ui="copper"] body #tabs .nav-item {
    display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
    background: none; box-shadow: none; color: var(--ink); font: inherit; font-size: var(--fs-body); font-weight: 500; text-align: start; text-decoration: none; cursor: pointer;
  }
  html[data-ui="copper"] body #tabs .nav-item svg.ui-icon { width: 22px; height: 22px; color: var(--muted); }
  html[data-ui="copper"] body #tabs .nav-item:hover { background: var(--surface-2); }
  html[data-ui="copper"] body #tabs .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  html[data-ui="copper"] body #tabs .nav-item.is-active { background: var(--surface-2); color: var(--accent-ink); font-weight: 600; }
  html[data-ui="copper"] body #tabs .nav-item.is-active svg.ui-icon { color: var(--accent-ink); }
  html[data-ui="copper"] body #tabs .nav-sub { margin: 0 0 6px; margin-inline-start: 20px; padding-inline-start: 8px; border-inline-start: 1px solid var(--line); }
  html[data-ui="copper"] body #tabs .nav-sub .nav-item { height: 44px; min-height: 44px; border-radius: 10px; font-size: var(--fs-label); font-weight: 400; color: var(--muted); }
  html[data-ui="copper"] body #tabs .nav-sub .nav-item.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-ink); font-weight: 600; }
  html[data-ui="copper"] body #tabs .sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 2px; border-top: 1px solid var(--line-soft); font-size: var(--fs-body); font-weight: 500; }
  html[data-ui="copper"] body #tabs .sidebar-user small { display: block; font-size: var(--fs-label); color: var(--muted); font-weight: 400; }
  html[data-ui="copper"] body #tabs .sidebar-user .side-account {
    margin-inline-start: auto; width: var(--touch); height: var(--touch); display: inline-grid; place-items: center; border: 0; border-radius: var(--r-md); background: none; color: var(--ink);
  }
  html[data-ui="copper"] body #tabs .sidebar-user .profile-avatar { border: 1px solid var(--accent); }
  /* المحتوى يترك مكان الشريط الجانبي (يمين الصفحة في RTL) */
  html[data-ui="copper"] body #app { padding-inline-start: var(--sidebar-w, 256px); }
  /* WAVE2 (C5): عنوان الترويسة وأزرارها يحاذيان حافتي عمود المحتوى (لا 24px خارجه) */
  html[data-ui="copper"] body .topbar { padding-inline: max(var(--sp-5), calc((100% - var(--page-max, 1120px)) / 2 + 16px)); min-height: 68px; }
  html[data-ui="copper"] body .topbar .who { display: none; }
  html[data-ui="copper"] body .topbar .topbar-title h1 { font-size: var(--fs-xl); }
  html[data-ui="copper"] main { padding-bottom: var(--sp-5); }
}

/* FX1 (V9): العنوان الفرعي في رأس الصفحة يلتف حتى سطرين بدل أن يُقصّ بنقاط */
@media (max-width: 767px) {
  html[data-ui="copper"] body .topbar .topbar-title p { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
}

/* WAVE2 (H4): مدخل التعريف ⓘ الصغير يسكن كتلة عنوان الترويسة بدل عنوان كبير مكرّر في المحتوى (setHeaderHelp في core.js) */
/* F7: مساحة ⓘ على سطر العنوان وحده فيبقى الفرعي بكامل العرض (سطر واحد) */
html[data-ui="copper"] body .topbar .topbar-title:has(.topbar-help) { position: relative; --h1h: calc(var(--fs-md) * 1.5 + 4px); }
html[data-ui="copper"] body .topbar .topbar-title:has(.topbar-help) h1 { padding-inline-end: 44px; }
html[data-ui="copper"] body .topbar .topbar-help {
  position: absolute; inset-inline-end: -2px; inset-block-start: calc((var(--h1h) - var(--touch)) / 2); display: grid; place-items: center;
  width: var(--touch); height: var(--touch); min-height: var(--touch); padding: 0; border: 0; border-radius: var(--r-md); background: none; color: var(--muted); font-size: 20px;
}
html[data-ui="copper"] body .topbar .topbar-help:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* WAVE2: المحادثة المفتوحة صفحة فرعية على الجوال (رجوع + اسمها + «⋯») فلا ترويسة القسم فوقها؛ من 768 تبقى ترويسة القشرة */
@media (max-width: 767.98px) {
  html[data-ui="copper"] body:has(.chat-shell.conversation-open) .topbar { display: none; }
}

/* WAVE2 (C6): الأزرار الرمادية الهادئة في الترويسة تقرأ «معطَّلة» في النهار؛ إطار بقوة --line يحدّد الحد */
html[data-ui="copper"][data-theme="light"] body .topbar .topbar-actions button { border: 1px solid var(--line); }

/* WAVE2: صفّ الأقسام في غلاف القطيع بحشوة علوية واحدة في كل تبويباته (كان صفر في الدفعات والتحصين و16 في غيرهما) */
html[data-ui="copper"] body:has(.herd-workspace) main#view { padding-top: 12px; }
@media (max-width: 899.98px) {
  /* حافة واحدة لمحتوى كل تبويبات القطيع على الجوال: الحشوة على الغلاف لا على main (كانت 12 في الصحة والتكاثر و16 في الدفعات والتحصين) */
  html[data-ui="copper"] body:has(.herd-workspace) main#view { padding-inline: 0 !important; max-width: none; }
  html[data-ui="copper"] body .herd-workspace { padding-inline: 16px; max-width: none; margin-inline: 0; }   /* F2: عمود واحد لكل التبويبات بحافتي الترويسة (كان للدفعات سقف 640 وللبقية 32) */
  html[data-ui="copper"] body .herd-workspace.vx-on { padding-top: 0; }
}

/* WAVE2: فراغ 8px بين صف أقسام القطيع وما تحته في كل التبويبات (كان 4px ملتصقاً بالزر الأول في الصحة) */
html[data-ui="copper"] body .herd-workspace > .ux:has(> .herd-section-tabs) { margin-bottom: 12px; }
/* F5: مسافة واحدة 12px بين صف التبويبات وأول محتوى في تبويبات القطيع الأربعة */
html[data-ui="copper"] body .herd-workspace .herd-section-content, html[data-ui="copper"] body .herd-workspace .hv-intro-actions, html[data-ui="copper"] body .herd-workspace .herd-section-content > :first-child { margin-top: 0; padding-top: 0; }
html[data-ui="copper"] body .herd-workspace .herd-section-tabs { margin-bottom: 0; }
@media (min-width: 1024px) { html[data-ui="copper"] body .topbar .topbar-title:has(.topbar-help) { --h1h: calc(var(--fs-xl) * 1.5 + 4px); } }

/* F6: حالة نشطة لزري المحادثات والحساب في الترويسة (aria-pressed): الحبر لا التعبئة، وإشارة ثانية بحلقة 2px */
html[data-ui="copper"] body .topbar #chat-button[aria-pressed="true"] { color: var(--accent-ink); box-shadow: inset 0 0 0 2px var(--accent-ink); }
html[data-ui="copper"] body .topbar #settings-gear[aria-pressed="true"] .profile-avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-ink); }
html[data-ui="copper"] body #tabs .sidebar-user .side-account[aria-pressed="true"] { color: var(--accent-ink); box-shadow: inset 0 0 0 2px var(--accent-ink); }
/* F10: «سوق مراح ذكي» عنوان مكرّر للترويسة: يبقى للقارئات فقط */
html[data-ui="copper"] .market-shell-head { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* F9: في محادثة مفتوحة على الجوال يبقى فراغ بين مربع الكتابة وبروز زر ＋ */
@media (max-width: 767.98px) { html:not(.kb-open) .chat-shell.conversation-open .chat-composer-wrap { margin-bottom: 38px; } }
