/* ==========================================================================
   هوية المجتهد البصرية — Heritage Calm
   - رملي هادئ + طيني دافئ + زمردي رصين
   - الخطوط: Amiri للعناوين + Noto Naskh للنصوص + Lotus Linotype كاحتياطي نظامي
   - أيقونات فلات (Lucide) بحجم موحّد وبدون تعبئة
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&family=Noto+Naskh+Arabic:wght@400;500;600;700&display=swap');

:root {
  /* ثلاثية الهوية: رملي · طيني · زمردي */
  --bg-canvas: #F1E9DC;
  /* 1. رملي هادئ */
  --text-main: #2A221A;
  /* 2. حبر ترابي */
  --accent-clay: #B56A4C;
  /* 3. طيني رئيسي */
  --accent-emerald: #2F6F5E;
  /* زمردي مكمّل */

  /* تدرجات مشتقة */
  --bg-surface: #FBF7F0;
  --bg-surface-hover: #EDE4D4;
  --bg-muted: #E7DCCB;
  --border-subtle: #D6CBB8;
  --border-hover: #BFAE96;
  --text-muted: #6A5C4D;
  --text-light: #978675;
  --accent-light: #F2E3DA;
  --accent-hover: #9A5740;
  --accent-subtle: rgba(181, 106, 76, 0.14);
  --emerald-light: #E3EFEA;
  --emerald-subtle: rgba(47, 111, 94, 0.12);
  --emerald-hover: #245A4C;
  --ink-deep: #1C1611;
  --mark-gold: #A8842E;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --glass: rgba(251, 247, 240, 0.92);
  --wash-a: rgba(181, 106, 76, 0.10);
  --wash-b: rgba(47, 111, 94, 0.09);
  --veil: rgba(255, 255, 255, 0.28);
  --btn-text: #FFFFFF;

  /* أميري للعناوين · نسخ للنصوص · لوتس كاحتياطي إن وُجد على النظام */
  --font-amiri: 'Amiri', 'Lotus Linotype', 'Traditional Arabic', serif;
  --font-naskh: 'Noto Naskh Arabic', 'Amiri', 'Lotus Linotype', serif;
  --font-ui: 'Amiri', 'Noto Naskh Arabic', 'Lotus Linotype', serif;

  /* انحناء بسيط — ليس دائرياً/حبوبياً */
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;

  --transition-fast: 0.18s ease;
  --transition-normal: 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  --icon-size: 18px;
}

[data-theme="dark"] {
  --bg-canvas: #1A1612;
  --text-main: #F0E8DC;
  --bg-surface: #241F1A;
  --bg-surface-hover: #2E2720;
  --bg-muted: #2A241E;
  --border-subtle: #3D342B;
  --border-hover: #564A3E;
  --text-muted: #B0A090;
  --text-light: #7E7163;
  --accent-light: #3A2A22;
  --accent-hover: #D08A6C;
  --accent-subtle: rgba(208, 138, 108, 0.18);
  --accent-emerald: #4A9B84;
  --emerald-light: #1E332C;
  --emerald-subtle: rgba(74, 155, 132, 0.16);
  --emerald-hover: #5FB39A;
  --ink-deep: #F0E8DC;
  --mark-gold: #C9A84A;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --glass: rgba(36, 31, 26, 0.92);
  --wash-a: rgba(208, 138, 108, 0.12);
  --wash-b: rgba(74, 155, 132, 0.10);
}

/* الثيم 2 — حبر هندسي: ورق بارد، نيلي ونحاسي، زوايا قائمة */
[data-theme="ink"] {
  --bg-canvas: #F3F5F7;
  --text-main: #1A2430;
  --accent-clay: #1E4D78;
  --accent-emerald: #8C5A2B;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #EEF2F6;
  --bg-muted: #E5EBF1;
  --border-subtle: #CDD5DE;
  --border-hover: #93A4B6;
  --text-muted: #5A6A7A;
  --text-light: #8796A6;
  --accent-light: #E3EDF6;
  --accent-hover: #16385A;
  --accent-subtle: rgba(30, 77, 120, 0.12);
  --emerald-light: #F4EBE2;
  --emerald-subtle: rgba(140, 90, 43, 0.14);
  --emerald-hover: #70461F;
  --ink-deep: #101820;
  --mark-gold: #8C5A2B;
  --glass: rgba(255, 255, 255, 0.94);
  --wash-a: rgba(30, 77, 120, 0.07);
  --wash-b: rgba(140, 90, 43, 0.05);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-text: #FFFFFF;
}

/* الثيم 3 — واحة: أخضر زيتوني وذهبي، انحناء أوضح */
[data-theme="oasis"] {
  --bg-canvas: #E6F0E3;
  --text-main: #1C2A22;
  --accent-clay: #1E6A49;
  --accent-emerald: #A47A2A;
  --bg-surface: #F6FBF4;
  --bg-surface-hover: #E2EEDC;
  --bg-muted: #D5E6D0;
  --border-subtle: #C0D6B8;
  --border-hover: #8AAD82;
  --text-muted: #4C6355;
  --text-light: #789184;
  --accent-light: #D7EFE2;
  --accent-hover: #155338;
  --accent-subtle: rgba(30, 106, 73, 0.14);
  --emerald-light: #F7EED9;
  --emerald-subtle: rgba(164, 122, 42, 0.16);
  --emerald-hover: #86631E;
  --ink-deep: #132018;
  --mark-gold: #A47A2A;
  --glass: rgba(246, 251, 244, 0.92);
  --wash-a: rgba(30, 106, 73, 0.10);
  --wash-b: rgba(164, 122, 42, 0.08);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
}

/* الثيم 4 — حرير: ذهبي مع أخضر مزرق */
[data-theme="silk"] {
  --bg-canvas: #F6F1E6;
  --text-main: #17302E;
  --accent-clay: #C4A15A;
  --accent-emerald: #0E7F7A;
  --bg-surface: #FFFCF6;
  --bg-surface-hover: #F3EDE1;
  --bg-muted: #EBE3D2;
  --border-subtle: #E2D4B4;
  --border-hover: #C4A15A;
  --text-muted: #5C6B68;
  --text-light: #8A9794;
  --accent-light: #F8F1DE;
  --accent-hover: #A8863E;
  --accent-subtle: rgba(196, 161, 90, 0.16);
  --emerald-light: #E3F3F1;
  --emerald-subtle: rgba(14, 127, 122, 0.14);
  --emerald-hover: #0B655F;
  --ink-deep: #102422;
  --mark-gold: #C4A15A;
  --glass: rgba(255, 252, 246, 0.9);
  --wash-a: rgba(196, 161, 90, 0.18);
  --wash-b: rgba(14, 127, 122, 0.12);
  --veil: rgba(255, 255, 255, 0.35);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: linear-gradient(115deg, #F3E2B0 0%, #C4A15A 46%, #E8D29A 100%);
  --btn-bg: linear-gradient(115deg, #F3E2B0 0%, #C4A15A 46%, #E8D29A 100%);
  --btn-text: #1C2416;
  --btn-hover: linear-gradient(115deg, #F8EBC4, #D4B56A);
}

/* الثيم 5 — فحمي: أسود فحمي مع ذهبي */
[data-theme="charcoal"] {
  --bg-canvas: #121212;
  --text-main: #F6F0E4;
  --accent-clay: #D6B56A;
  --accent-emerald: #E7D3A1;
  --bg-surface: #1B1B1B;
  --bg-surface-hover: #262626;
  --bg-muted: #202020;
  --border-subtle: #34302A;
  --border-hover: #B89245;
  --text-muted: #C2B8A8;
  --text-light: #8A8174;
  --accent-light: #2C271C;
  --accent-hover: #E8CC8C;
  --accent-subtle: rgba(214, 181, 106, 0.16);
  --emerald-light: #2A261C;
  --emerald-subtle: rgba(231, 211, 161, 0.14);
  --emerald-hover: #F2E2B8;
  --ink-deep: #F8F3E8;
  --mark-gold: #E8CC8C;
  --glass: rgba(18, 18, 18, 0.9);
  --wash-a: rgba(214, 181, 106, 0.12);
  --wash-b: rgba(255, 255, 255, 0.03);
  --veil: rgba(255, 255, 255, 0.02);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: linear-gradient(135deg, #F4E0A8 0%, #D6B56A 52%, #9A7434 100%);
  --btn-bg: linear-gradient(135deg, #F4E0A8 0%, #D6B56A 52%, #9A7434 100%);
  --btn-text: #16130E;
  --btn-hover: linear-gradient(135deg, #F8E8BE, #E2C47A);
}

/* الثيم 6 — بحري: أزرق بحري مع طيني */
[data-theme="marine"] {
  --bg-canvas: #0C2740;
  --text-main: #F6EFE8;
  --accent-clay: #C56B45;
  --accent-emerald: #E4C2AE;
  --bg-surface: #13314E;
  --bg-surface-hover: #1A3C5C;
  --bg-muted: #10283F;
  --border-subtle: #2C4C68;
  --border-hover: #C56B45;
  --text-muted: #C5D2DE;
  --text-light: #8AA3B8;
  --accent-light: #3A2C28;
  --accent-hover: #D88864;
  --accent-subtle: rgba(197, 107, 69, 0.2);
  --emerald-light: #1A3348;
  --emerald-subtle: rgba(228, 194, 174, 0.16);
  --emerald-hover: #F0D4C4;
  --ink-deep: #F8F3EE;
  --mark-gold: #E4C2AE;
  --glass: rgba(12, 39, 64, 0.88);
  --wash-a: rgba(197, 107, 69, 0.16);
  --wash-b: rgba(80, 150, 190, 0.14);
  --veil: rgba(255, 255, 255, 0.03);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: linear-gradient(140deg, #E59A78 0%, #C56B45 58%, #8E4630 100%);
  --btn-bg: linear-gradient(140deg, #E59A78 0%, #C56B45 58%, #8E4630 100%);
  --btn-text: #FFF8F4;
  --btn-hover: linear-gradient(140deg, #F0B090, #D48462);
}

/* الثيم 7 — رمال الشمال: كريمي دافئ، أصفر زبدي، وفحم ناعم */
[data-theme="north-sand"] {
  --bg-canvas: #F4F0E4;
  --text-main: #2A2A28;
  --accent-clay: #F0C93A;
  --accent-emerald: #2C2C2C;
  --bg-surface: #FBF8F1;
  --bg-surface-hover: #F3EEDF;
  --bg-muted: #EFE8D6;
  --border-subtle: #E6DCC4;
  --border-hover: #D7C48A;
  --text-muted: #8C8678;
  --text-light: #B3AB9A;
  --accent-light: #FBF3C8;
  --accent-hover: #E2B520;
  --accent-subtle: rgba(240, 201, 58, 0.28);
  --emerald-light: #F4F1EA;
  --emerald-subtle: rgba(44, 44, 44, 0.08);
  --emerald-hover: #111111;
  --ink-deep: #1C1C1C;
  --mark-gold: #F0C93A;
  --glass: rgba(251, 248, 241, 0.82);
  --wash-a: rgba(245, 214, 92, 0.55);
  --wash-b: rgba(255, 252, 240, 0.2);
  --veil: rgba(255, 250, 230, 0.72);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: #1E1E1E;
  --btn-text: #FBF8F1;
  --btn-hover: #111111;
}

/* الثيم 8 — ليلك: رمادي بارد، بنفسجي، وأزرار فحمية */
[data-theme="lilac"] {
  --bg-canvas: #F3F4F8;
  --text-main: #17171C;
  --accent-clay: #7B5CFA;
  --accent-emerald: #1C1C22;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F6F6FB;
  --bg-muted: #EEF0F5;
  --border-subtle: #E4E6EE;
  --border-hover: #C8B8F5;
  --text-muted: #6E7380;
  --text-light: #9AA0AD;
  --accent-light: #EDE7FF;
  --accent-hover: #6846F0;
  --accent-subtle: rgba(123, 92, 250, 0.14);
  --emerald-light: #F3F4F8;
  --emerald-subtle: rgba(28, 28, 34, 0.08);
  --emerald-hover: #111114;
  --ink-deep: #121216;
  --mark-gold: #7B5CFA;
  --glass: rgba(255, 255, 255, 0.86);
  --wash-a: rgba(123, 92, 250, 0.12);
  --wash-b: rgba(183, 164, 255, 0.16);
  --veil: rgba(255, 255, 255, 0.55);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: #1C1C22;
  --btn-text: #FFFFFF;
  --btn-hover: #111114;
}

/* الثيم 9 — مارشملو: باستيل وردي وخوخي، وبنفسجي عميق */
[data-theme="marshmallow"] {
  --bg-canvas: #F7F1FB;
  --text-main: #241833;
  --accent-clay: #6B4DFF;
  --accent-emerald: #3B2A78;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F8F4FC;
  --bg-muted: #F3EDF8;
  --border-subtle: #E7E0F2;
  --border-hover: #CDBFF0;
  --text-muted: #6E6582;
  --text-light: #9A91AD;
  --accent-light: #EFE8FF;
  --accent-hover: #5838F0;
  --accent-subtle: rgba(107, 77, 255, 0.14);
  --emerald-light: #F4EFFA;
  --emerald-subtle: rgba(59, 42, 120, 0.10);
  --emerald-hover: #2A1C5C;
  --ink-deep: #1A1228;
  --mark-gold: #E4549B;
  --glass: rgba(255, 255, 255, 0.72);
  --wash-a: rgba(243, 182, 214, 0.72);
  --wash-b: rgba(248, 210, 160, 0.7);
  --veil: rgba(255, 255, 255, 0.28);
  --radius-sm: 6px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --radius-pill: 6px;
  --btn-bg: #3B2A78;
  --btn-bg: #3B2A78;
  --btn-text: #FFFFFF;
  --btn-hover: #2C1E60;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-canvas);
  background-image:
    radial-gradient(ellipse 85% 50% at 100% -8%, var(--wash-a), transparent 55%),
    radial-gradient(ellipse 65% 42% at -8% 108%, var(--wash-b), transparent 50%),
    linear-gradient(180deg, var(--veil) 0%, transparent 240px);
  color: var(--text-main);
  font-family: var(--font-ui);
  line-height: 1.7;
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[data-theme="dark"] body,
body[data-theme="dark"] {
  background-image:
    radial-gradient(ellipse 85% 50% at 100% -8%, rgba(208, 138, 108, 0.12), transparent 55%),
    radial-gradient(ellipse 65% 42% at -8% 108%, rgba(74, 155, 132, 0.10), transparent 50%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, transparent 240px);
}

/* أيقونات Lucide الفلات */
.icon,
[data-lucide] {
  width: var(--icon-size);
  height: var(--icon-size);
  stroke-width: 1.75;
  flex-shrink: 0;
  vertical-align: middle;
}

.nav-tab-btn .icon,
.btn-icon .icon,
.btn-flat-primary .icon,
.btn-new-chat .icon {
  width: 17px;
  height: 17px;
}

/* ==========================================================================
   ترويسة التطبيق (Header الهوية)
   ========================================================================== */
.app-header {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: none;
  animation: headerReveal 0.55s var(--transition-normal) both;
}

@keyframes headerReveal {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.brand-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-amiri);
  font-size: 28px;
  font-weight: 700;
  color: var(--ink-deep);
  letter-spacing: -0.2px;
  line-height: 1.15;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title .brand-icon {
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, var(--accent-clay), var(--accent-emerald));
  border-radius: 50%;
  display: inline-block;
}

.brand-subtitle-1 {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-clay);
  letter-spacing: 0.15px;
}

.brand-subtitle-2 {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ==========================================================================
   أزرار التبويبات العلوية (Navigation Tabs)
   ========================================================================== */
.main-nav {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: none;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-amiri);
  font-size: 15.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.nav-tab-btn .icon,
.nav-tab-btn svg {
  opacity: 0.72;
  flex-shrink: 0;
}

.nav-tab-btn:hover {
  color: var(--text-main);
  background: rgba(251, 247, 240, 0.65);
}

.nav-tab-btn.active {
  background: var(--bg-surface);
  color: var(--accent-emerald);
  box-shadow: none;
  font-weight: 700;
}

.nav-tab-btn.active .icon,
.nav-tab-btn.active svg {
  opacity: 1;
  color: var(--accent-emerald);
  stroke: var(--accent-emerald);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: none;
}

.btn-icon:hover {
  background: var(--emerald-light);
  color: var(--accent-emerald);
  border-color: transparent;
}

/* ==========================================================================
   محتوى التبويبات (Tab Panes)
   ========================================================================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.tab-pane {
  display: none;
  flex: 1;
  width: 100%;
  animation: fadeIn 0.2s ease-in-out;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   1. تبويب البحث الدلالي (Semantic Search Tab)
   ========================================================================== */
.search-container {
  max-width: 1080px;
  width: 100%;
  margin: 40px auto 48px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: fadeIn 0.45s var(--transition-normal) both;
}

.search-hero {
  text-align: center;
  margin-bottom: 4px;
  position: relative;
}

.search-hero::before {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  margin: 0 auto 16px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent-clay), var(--accent-emerald));
  animation: fadeIn 0.6s ease 0.1s both;
}

.search-hero h2 {
  font-family: var(--font-amiri);
  font-size: clamp(26px, 3.5vw, 38px);
  font-weight: 700;
  color: var(--ink-deep);
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.search-hero p {
  color: var(--text-muted);
  font-size: 14.5px;
  margin-top: 8px;
  max-width: 560px;
  margin-inline: auto;
  line-height: 1.7;
}

.search-box-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px 12px 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-normal);
  box-shadow: none;
}

.search-box-wrapper:focus-within {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  font-family: var(--font-naskh);
  font-size: 19px;
  color: var(--text-main);
  outline: none;
  min-width: 0;
}

.search-input::placeholder {
  color: var(--text-light);
  font-size: 17px;
  font-family: var(--font-amiri);
}

.btn-flat-primary {
  background: var(--btn-bg, var(--accent-clay));
  color: var(--btn-text, #FFFFFF);
  border: none;
  font-family: var(--font-amiri);
  font-size: 17px;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: none;
  flex-shrink: 0;
}

.btn-flat-primary:hover {
  background: var(--btn-hover, var(--accent-hover));
}

.btn-flat-primary:active {
  transform: translateY(0);
}

.btn-flat-secondary {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-amiri);
  font-size: 15px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: none;
}

.btn-flat-secondary:hover {
  background: var(--emerald-light);
  border-color: transparent;
  color: var(--accent-emerald);
}

/* شريط الفلاتر الدقيقة */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: none;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-item label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.filter-select,
.filter-input {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 13.5px;
  font-family: var(--font-naskh);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filter-select:focus,
.filter-input:focus {
  border-color: var(--accent-clay);
  box-shadow: none;
}

/* زر تفعيل وتعطيل البحث الهجين (Dense + BM25) */
.btn-hybrid-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-surface-elevated, rgba(140, 140, 140, 0.06));
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 5px 12px;
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-naskh);
  cursor: pointer;
  outline: none;
  transition: all 0.22s ease-in-out;
  user-select: none;
}

.btn-hybrid-toggle:hover {
  transform: translateY(-1px);
}

.btn-hybrid-toggle .hybrid-indicator-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a1a1aa;
  transition: all 0.2s ease;
}

.btn-hybrid-toggle.is-active {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.35);
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.1);
}

.btn-hybrid-toggle.is-active:hover {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(37, 99, 235, 0.5);
}

.btn-hybrid-toggle.is-active .hybrid-indicator-dot {
  background: #2563eb;
  box-shadow: 0 0 6px rgba(37, 99, 235, 0.65);
}

.btn-hybrid-toggle.is-disabled {
  background: var(--bg-surface-elevated, rgba(140, 140, 140, 0.06));
  color: var(--text-muted);
  border: 1px dashed var(--border-subtle);
  opacity: 0.85;
}

.btn-hybrid-toggle.is-disabled:hover {
  background: var(--bg-surface-elevated, rgba(140, 140, 140, 0.12));
  color: var(--text-main);
  opacity: 1;
}

.btn-hybrid-toggle.is-disabled .hybrid-indicator-dot {
  background: #9ca3af;
  box-shadow: none;
}

/* بطاقات النتائج الفقهية */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 22px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-normal), transform var(--transition-fast);
  box-shadow: none;
  border-inline-start: 3px solid transparent;
}

.result-card:hover {
  border-color: var(--border-hover);
  border-inline-start-color: var(--accent-clay);
  background: var(--bg-surface-hover);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.result-book-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.book-title-tag {
  font-family: var(--font-amiri);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-deep);
}

.author-tag {
  font-size: 13px;
  color: var(--text-muted);
}

.score-badge {
  background: var(--emerald-subtle);
  color: var(--accent-emerald);
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-family: var(--font-naskh);
}

.result-chapter {
  font-size: 13.5px;
  color: var(--accent-emerald);
  margin-bottom: 10px;
  font-weight: 700;
  font-family: var(--font-amiri);
}

.result-text {
  font-family: var(--font-naskh);
  font-size: 19px;
  line-height: 1.95;
  color: var(--text-main);
  white-space: pre-wrap;
}

.result-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-light);
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

/* ==========================================================================
   2. تبويب الشات (Chat Tab — Scholarly Layout)
   ========================================================================== */
.chat-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - 72px);
  overflow: hidden;
}

/* القائمة الجانبية للمحادثات */
.chat-sidebar {
  width: 268px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
}

.btn-new-chat {
  background: var(--btn-bg, var(--accent-emerald));
  border: none;
  color: var(--btn-text, #FFFFFF);
  font-family: var(--font-amiri);
  font-size: 16px;
  font-weight: 700;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition-fast);
  box-shadow: none;
}

.btn-new-chat:hover {
  background: var(--btn-hover, var(--emerald-hover));
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover,
.history-item.active {
  background: var(--bg-surface);
  color: var(--text-main);
}

/* منطقة المحادثة المركزية */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  position: relative;
}

.chat-top-control {
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-canvas);
  font-size: 13px;
}

.chat-model-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.thinking-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.thinking-btn-group {
  display: flex;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.btn-think {
  background: transparent;
  border: none;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-think.active {
  background: var(--bg-surface);
  color: var(--accent-clay);
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.message-bubble {
  display: flex;
  gap: 14px;
  line-height: 1.7;
}

.message-bubble.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-main);
  flex-shrink: 0;
}

.message-bubble.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent-clay), var(--accent-emerald));
  color: #FFFFFF;
  box-shadow: none;
  font-family: var(--font-amiri);
  font-weight: 700;
}

.message-content {
  background: var(--bg-muted);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  max-width: 80%;
  font-size: 15px;
  border: 1px solid var(--border-subtle);
}

.message-bubble.user .message-content {
  background: var(--accent-light);
  border-color: transparent;
  color: var(--text-main);
}

.message-bubble.assistant .message-content {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 100%;
  font-family: var(--font-naskh);
  font-size: 18.5px;
  line-height: 1.9;
}

/* صندوق الإدخال (Prompt Box) */
.chat-input-area {
  padding: 16px 24px 22px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.chat-input-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-normal);
  box-shadow: none;
}

.chat-input-box:focus-within {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.chat-textarea {
  width: 100%;
  min-height: 48px;
  max-height: 180px;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-amiri);
  font-size: 18px;
  color: var(--text-main);
  resize: none;
}

.chat-textarea::placeholder {
  color: var(--text-light);
  font-size: 16px;
}

/* شريط قوالب الإخراج التخصصية الجاهزة فوق زر الإرسال */
.chat-templates-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 6px;
  border-top: 1px dashed var(--border-subtle);
}

.chat-templates-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  user-select: none;
  margin-left: 2px;
}

.chat-template-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.chat-template-chip:hover {
  background: var(--accent-subtle);
  border-color: var(--accent-clay);
  color: var(--accent-clay);
  box-shadow: none;
}

.chat-template-chip:active {
  transform: translateY(0);
}

.chat-template-chip.highlight-chip {
  background: var(--accent-subtle);
  border-color: rgba(184, 115, 51, 0.45);
  color: var(--accent-clay);
  font-weight: 700;
}

.chat-template-chip.highlight-chip:hover {
  background: rgba(184, 115, 51, 0.16);
  border-color: var(--accent-clay);
  box-shadow: 0 2px 6px rgba(184, 115, 51, 0.15);
}

.chat-input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-input-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-attachment {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.btn-attachment:hover {
  color: var(--text-main);
}

.btn-send-chat {
  background: var(--accent-clay);
  color: #FFFFFF;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.btn-send-chat:hover {
  background: var(--accent-hover);
}

/* فاصل شريط الإدخال */
.chat-input-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 0 4px;
}

/* حاوية منتقي مجموعة الوكلاء في الشات */
.chat-agent-group-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.chat-agent-group-picker.active {
  border-color: var(--accent-clay);
  background: var(--accent-subtle);
  box-shadow: none;
}

.chat-agent-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.chat-agent-group-picker.active .chat-agent-checkbox-label {
  color: var(--accent-clay);
}

.chat-agent-checkbox-label input[type="checkbox"] {
  accent-color: var(--accent-clay);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.chat-checkbox-title {
  white-space: nowrap;
}

.chat-agent-select-wrap {
  display: inline-flex;
  align-items: center;
}

.chat-agent-dropdown {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  max-width: 260px;
  transition: all var(--transition-fast);
}

.chat-agent-dropdown:hover {
  border-color: var(--accent-clay);
}

.chat-agent-group-picker.active .chat-agent-dropdown {
  border-color: var(--accent-clay);
  background: #FFFFFF;
  color: var(--accent-clay);
  font-weight: 600;
}

/* ==========================================================================
   قائمة تشيك ليست اختيار الوكلاء المساعدين المتعددين في الشات
   ========================================================================== */
.chat-subagent-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.chat-subagent-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-surface) !important;
  color: var(--accent-clay) !important;
  border: 1px solid var(--accent-clay) !important;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  max-width: 300px;
  min-width: 160px;
  transition: all var(--transition-fast);
}

/* زر تبديل نمط التوزيع في الشات (متوازي vs مباشر - حفظ خط الرجعة) */
.chat-dispatch-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(197, 160, 89, 0.12);
  color: var(--accent-clay);
  border: 1px solid rgba(197, 160, 89, 0.4);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.chat-dispatch-mode-toggle:hover {
  background: var(--accent-clay);
  color: #FFFFFF;
  border-color: var(--accent-clay);
}

.chat-dispatch-mode-toggle.mode-direct {
  background: rgba(100, 116, 139, 0.1);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

.chat-dispatch-mode-toggle.mode-direct:hover {
  background: var(--text-secondary);
  color: #FFFFFF;
  border-color: var(--text-secondary);
}

.chat-subagent-trigger:hover {
  background: var(--accent-subtle) !important;
}

.chat-subagent-btn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  flex: 1;
}

.chat-subagent-chevron {
  transition: transform 0.2s ease;
  flex-shrink: 0;
  color: var(--accent-clay);
}

.chat-subagent-trigger.is-open .chat-subagent-chevron {
  transform: rotate(180deg);
}

.chat-subagent-checklist-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-width: 92vw;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
  z-index: 100050 !important;
  display: flex;
  flex-direction: column;
  animation: checklistIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes checklistIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-checklist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
}

.chat-checklist-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
}

.chat-checklist-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
}

.btn-checklist-action {
  background: none;
  border: none;
  color: var(--accent-clay);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  transition: background 0.15s;
}

.btn-checklist-action:hover {
  background: var(--accent-subtle);
  text-decoration: underline;
}

.checklist-sep {
  color: var(--text-light);
  font-size: 10px;
}

.chat-checklist-items {
  max-height: 240px;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.chat-checklist-item:hover {
  background: var(--accent-subtle);
  border-color: rgba(184, 115, 51, 0.2);
}

.chat-checklist-item.is-selected {
  background: rgba(184, 115, 51, 0.08);
  border-color: rgba(184, 115, 51, 0.25);
}

.chat-agent-item-checkbox {
  margin-top: 3px;
  accent-color: var(--accent-clay);
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-agent-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.chat-agent-item-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.chat-agent-scope-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--accent-clay);
  white-space: nowrap;
}

.chat-agent-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chat-checklist-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-muted);
  border-top: 1px solid var(--border-subtle);
  font-size: 11.5px;
}

.chat-checklist-count-badge {
  font-weight: 700;
  color: var(--text-secondary);
}

.btn-checklist-done {
  background: var(--accent-clay);
  color: #FFFFFF;
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-checklist-done:hover {
  opacity: 0.9;
}

.chat-input-hint {
  font-size: 11.5px;
  color: var(--text-light);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .chat-input-hint {
    display: none;
  }
}

/* شارة إسناد الرسالة لمجموعة الوكلاء داخل فقاعة الشات */
.message-agent-group-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-subtle);
  border: 1px solid rgba(184, 115, 51, 0.3);
  color: var(--accent-clay);
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  margin-top: 6px;
  margin-right: 6px;
}

/* ==========================================================================
   3. تبويب الوكلاء المساعدين (Sub-Agents Tab)
   ========================================================================== */
.agents-container {
  max-width: 1100px;
  width: 100%;
  margin: 28px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.agents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agents-header h2 {
  font-family: var(--font-amiri);
  font-size: 28px;
  color: var(--text-main);
}

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.agent-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: all var(--transition-fast);
}

.agent-card:hover {
  border-color: var(--border-hover);
}

.agent-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agent-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-name {
  font-family: var(--font-amiri);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
}

/* زر التبديل التفاعلي Flat Toggle */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  transition: .2s;
  border-radius: 34px;
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 2px;
  background-color: var(--text-light);
  transition: .2s;
  border-radius: 50%;
}

input:checked+.slider-toggle {
  background-color: var(--accent-clay);
  border-color: var(--accent-clay);
}

input:checked+.slider-toggle:before {
  transform: translateX(17px);
  background-color: #FFFFFF;
}

.agent-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.agent-params-badge-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
}

.param-badge {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.agent-card-footer {
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* ==========================================================================
   نافذة الإعدادات الكبرى (Settings Modal - 5 Tabs)
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(28, 22, 17, 0.48);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open,
.modal-overlay.active {
  display: flex !important;
}

#systemMaintenanceModal,
#projectToChatModalOverlay {
  z-index: 10005 !important;
}

.modal-window {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 900px;
  max-width: 95vw;
  height: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: none;
  animation: modalIn 0.28s var(--transition-normal) both;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-canvas) 100%);
}

.modal-title {
  font-family: var(--font-amiri);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink-deep);
}

.modal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.modal-tabs-sidebar {
  width: 220px;
  background: var(--bg-canvas);
  border-left: 1px solid var(--border-subtle);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-amiri);
  font-size: 15.5px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: right;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.settings-tab-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.settings-tab-btn.active {
  background: var(--bg-surface);
  color: var(--accent-clay);
  box-shadow: none;
}

.modal-tab-content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  width: 100%;
}

.settings-section-title {
  font-family: var(--font-amiri);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
  margin-bottom: 6px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.form-group .form-help {
  font-size: 12px;
  color: var(--text-muted);
}

.form-input,
.form-select,
.form-textarea {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.api-keys-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.api-key-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.api-key-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.api-key-head label {
  font-family: var(--font-amiri);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-deep);
}

.api-key-head span {
  font-size: 12px;
  color: var(--text-muted);
}

.api-key-card .form-help {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent-clay);
}

.form-textarea {
  min-height: 90px;
  resize: vertical;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-container input[type="range"] {
  flex: 1;
  accent-color: var(--accent-clay);
}

.slider-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-clay);
  width: 50px;
}

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-canvas);
}

/* =============================================================================
   نافذة تصفح وقراءة الكتاب الأصلي (Book Reader Overlay)
   ============================================================================= */
.reader-modal-window {
  max-width: 960px;
  width: 94%;
  height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-lg);
  box-shadow: none;
  border: 1px solid var(--border-subtle);
}

.reader-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-canvas);
  flex-shrink: 0;
}

.reader-header-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reader-book-title {
  font-family: var(--font-amiri);
  font-size: 21px;
  font-weight: 700;
  color: var(--text-dark);
  margin: 0;
}

.reader-category-badge {
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.reader-author-meta {
  font-size: 13.5px;
  color: var(--text-muted);
  font-family: var(--font-amiri);
}

.reader-toolbar {
  padding: 10px 24px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.reader-tool-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.reader-select {
  padding: 4px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
}

.reader-page-input {
  width: 75px;
  padding: 4px 8px;
  text-align: center;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
}

.reader-tool-btn {
  padding: 5px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.reader-tool-btn.active {
  background: var(--accent-light);
  color: var(--accent-clay);
  border-color: var(--accent-clay);
}

.reader-mini-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.reader-chat-btn {
  background: var(--accent-clay);
  color: #FFFFFF !important;
  margin-right: auto;
  border: none;
  font-weight: 600;
}

.reader-chat-btn:hover {
  opacity: 0.92;
}

.reader-context-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  background: rgba(199, 92, 58, 0.08);
  border-bottom: 1px solid rgba(199, 92, 58, 0.25);
  font-size: 13.5px;
  color: var(--accent-clay);
  gap: 12px;
}

.reader-context-banner .reader-mini-btn {
  font-size: 11.5px;
  padding: 3px 8px;
}

.surrounding-page-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 18px;
  padding: 16px 20px;
  background: var(--bg-canvas);
  transition: all 0.2s ease;
}

.surrounding-page-card.target-page {
  border: 2px solid var(--accent-clay);
  background: rgba(199, 92, 58, 0.03);
  box-shadow: 0 4px 14px rgba(199, 92, 58, 0.08);
}

.surrounding-page-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-muted);
  margin-bottom: 10px;
}

.surrounding-page-card.target-page .surrounding-page-badge {
  background: var(--accent-clay);
  color: #fff;
}

.reader-betaka-panel {
  padding: 16px 24px;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  max-height: 220px;
  overflow-y: auto;
  flex-shrink: 0;
  animation: fadeIn 0.2s ease;
}

.reader-betaka-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-clay);
  margin-bottom: 8px;
}

.reader-betaka-text {
  font-family: var(--font-amiri);
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-muted);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  margin: 0;
}

.reader-content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 30px 48px;
  background: var(--bg-canvas);
}

.reader-page-body {
  font-family: var(--font-amiri);
  font-size: 21px;
  line-height: 2.25;
  color: var(--text-dark);
  word-spacing: 1px;
  user-select: text;
}

.reader-paragraph {
  margin-bottom: 18px;
  text-align: justify;
}

.reader-highlight {
  background-color: var(--accent-light);
  color: var(--accent-clay);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
}

.reader-footnotes-container {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px dashed var(--border-subtle);
}

.reader-footnotes-divider {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-clay);
  margin-bottom: 12px;
}

.reader-footnotes-text {
  font-family: var(--font-amiri);
  font-size: 16px;
  line-height: 2;
  color: var(--text-muted);
}

.reader-footer {
  padding: 12px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-canvas);
  flex-shrink: 0;
}

.reader-nav-btn {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.reader-page-counter {
  font-size: 13.5px;
  color: var(--text-muted);
  font-weight: 500;
  font-family: var(--font-amiri);
}

.reader-floating-tooltip {
  position: fixed;
  transform: translate(-50%, -100%);
  background: var(--text-dark);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  box-shadow: none;
  z-index: 10000;
  cursor: pointer;
  animation: fadeIn 0.15s ease;
}

.reader-floating-tooltip button {
  background: transparent;
  border: none;
  color: #FFFFFF;
  font-family: var(--font-amiri);
  font-size: 14.5px;
  cursor: pointer;
}

/* =============================================================================
   تنسيقات نطاق البحث وترقيم النتائج وإعادة الترتيب (Search Scope & Ranking)
   ============================================================================= */

/* زر نطاق البحث في شريط الفلاتر */
.btn-scope-selector {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-scope-selector:hover {
  border-color: var(--accent-clay);
  background: var(--bg-surface);
}

.badge-scope-count {
  background: var(--accent-clay);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
}

.btn-scope-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  font-size: 12px;
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.btn-scope-clear:hover {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.1);
}

/* نافذة نطاق البحث */
.scope-modal-window {
  width: 92%;
  max-width: 950px;
  height: 86vh;
  max-height: 860px;
  display: flex;
  flex-direction: column;
}

.scope-toolbar {
  padding: 14px 22px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scope-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.scope-control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.scope-control-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.scope-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-scope-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-scope-action:hover {
  border-color: var(--accent-clay);
  color: var(--accent-clay);
}

.scope-status-counts {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* شبكة عرض الكتب */
.scope-books-container {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  background: var(--bg-canvas);
}

.scope-book-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.scope-book-card:hover {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.scope-book-card.selected {
  border-color: var(--accent-clay);
  background: rgba(204, 120, 92, 0.07);
}

.scope-book-card input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent-clay);
  cursor: pointer;
}

.scope-book-title {
  font-family: var(--font-amiri);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 2px;
}

.scope-book-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.scope-cat-tag {
  background: rgba(42, 40, 37, 0.05);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* شارات ترقيم النتائج الفقهية */
.result-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.result-rank-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-pill-current {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-amiri);
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-clay);
  background: rgba(204, 120, 92, 0.1);
  border: 1px solid rgba(204, 120, 92, 0.3);
  padding: 1px 9px;
  border-radius: var(--radius-sm);
}

.rank-badge-prev {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
  color: var(--text-muted);
}

.rank-badge-prev.rank-up {
  color: #27ae60;
  background: rgba(39, 174, 96, 0.08);
  border-color: rgba(39, 174, 96, 0.25);
}

.rank-badge-prev.rank-down {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
  border-color: rgba(192, 57, 43, 0.25);
}

.rank-badge-prev.rank-same {
  color: var(--text-muted);
}

/* =============================================================================
   تبويب مزودي الخدمة والذكاء الاصطناعي (Providers & Models Tab - Matched to Search Aesthetic)
   ============================================================================= */
.providers-container {
  max-width: 1080px;
  width: 100%;
  margin: 32px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* بطاقة التحكم الرئيسية */
.provider-main-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* شريط عناصر التحكم - شريط أفقي موحد على نسق واحد ومطابق لـ filters-bar */
.provider-controls-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  padding: 14px 16px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 13px;
  min-width: 0;
}

.provider-ctrl-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
  white-space: normal;
}

.provider-ctrl-item label {
  white-space: normal;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.provider-key-wrapper {
  grid-column: 1 / -1;
}

#providerSelect,
#providerModelSelect,
#modelSearchFilterInput {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.provider-key-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#providerApiKey {
  flex: 1;
  width: auto;
  min-width: 0;
}

#modelSearchFilterWrapper {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

@media (max-width: 720px) {
  .provider-controls-bar {
    grid-template-columns: 1fr;
  }
}

.btn-icon-pad {
  padding: 5px 8px !important;
  font-size: 12px !important;
  border-radius: var(--radius-sm) !important;
}

.btn-save-pad {
  padding: 5px 12px !important;
  font-size: 12px !important;
  border-radius: var(--radius-sm) !important;
}

/* لوحة مواصفات النموذج المختار */
.provider-specs-panel {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-top: 4px;
}

.specs-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 14px;
}

.specs-panel-title {
  font-family: var(--font-amiri);
  font-size: 21px;
  font-weight: 700;
  color: var(--text-main);
  display: inline-block;
  margin-left: 10px;
}

.specs-panel-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  direction: ltr;
  display: inline-block;
}

.specs-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.spec-stat-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.spec-stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
}

.spec-stat-val {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-main);
}

.spec-stat-val strong {
  color: var(--accent-clay);
  font-size: 15.5px;
}

/* خط فاصل ناعم */
.provider-divider {
  border: none;
  height: 1px;
  background: var(--border-subtle);
  margin: 28px 0 20px;
}

/* أفضل النماذج */
.benchmarks-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rankings-two-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}

.ranking-subcard {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ranking-subcard-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.ranking-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ranking-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ranking-item-row:hover {
  border-color: var(--accent-clay);
  background: var(--bg-surface-hover);
}

.ranking-num-tag {
  font-family: var(--font-amiri);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-clay);
  background: var(--accent-subtle);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.ranking-item-body {
  flex: 1;
  min-width: 0;
}

.ranking-item-title {
  font-family: var(--font-amiri);
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.ranking-item-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.ranking-item-pills {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.rank-price-tag {
  font-size: 11.5px;
  font-family: monospace;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
}

/* =============================================================================
   التبويبات الفرعية لمزود الخدمة (Models / Consumption / Under Construction)
   ============================================================================= */
.provider-subtabs-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 14px;
  margin-bottom: 8px;
}

.provider-subtab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.provider-subtab-btn:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.provider-subtab-btn.active {
  background: var(--accent-light);
  color: var(--accent-clay);
  border-color: var(--accent-clay);
}

.badge-subtab-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-canvas);
  color: var(--text-main);
  font-weight: 700;
  border: 1px solid var(--border-subtle);
}

.provider-subtab-btn.active .badge-subtab-pill {
  background: #FFF;
  color: var(--accent-clay);
  border-color: rgba(204, 120, 92, 0.3);
}

.provider-subtab-pane {
  display: none;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.provider-subtab-pane.active {
  display: flex !important;
}

/* =============================================================================
   تبويب الاستهلاك والرصيد بالدولار والريال السعودي
   ============================================================================= */
.consumption-hero-card {
  padding: 24px 28px;
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-canvas) 100%);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.consumption-hero-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.saudi-currency-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(0, 108, 53, 0.08);
  border: 1px solid rgba(0, 108, 53, 0.22);
  color: #006C35;
}

[data-theme="dark"] .saudi-currency-badge {
  background: rgba(56, 180, 114, 0.12);
  border-color: rgba(56, 180, 114, 0.3);
  color: #38b472;
}

.saudi-emblem-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #006C35;
}

[data-theme="dark"] .saudi-emblem-icon {
  color: #38b472;
}

.saudi-badge-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.badge-title {
  font-size: 12px;
  font-weight: 700;
}

.badge-rate {
  font-size: 11px;
  opacity: 0.85;
}

.consumption-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-refresh-credits {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-charge-credits {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.balance-display-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 20px;
  padding: 20px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}

.balance-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.balance-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.sar-header-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sar-symbol-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #006C35;
  color: #FFF;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

[data-theme="dark"] .sar-symbol-pill {
  background: #258550;
}

.balance-amount-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.balance-amount {
  font-size: 38px;
  font-weight: 800;
  font-family: var(--font-amiri), serif;
  color: var(--text-main);
  line-height: 1;
}

.balance-amount.text-sar {
  color: #006C35;
}

[data-theme="dark"] .balance-amount.text-sar {
  color: #38b472;
}

.currency-tag {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.tag-usd {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.tag-sar {
  background: rgba(0, 108, 53, 0.1);
  color: #006C35;
  border: 1px solid rgba(0, 108, 53, 0.2);
}

[data-theme="dark"] .tag-sar {
  background: rgba(56, 180, 114, 0.15);
  color: #38b472;
  border-color: rgba(56, 180, 114, 0.3);
}

.balance-exchange-divider {
  display: flex;
  align-items: center;
  justify-content: center;
}

.divider-equal {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-light);
}

.consumption-sync-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}

.sync-dot.live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: none;
  display: inline-block;
}

.key-label-tag {
  margin-right: auto;
  font-family: monospace;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

/* شبكة المؤشرات التفصيلية */
.consumption-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.consumption-metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-val-usd {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-amiri), serif;
  color: var(--text-main);
}

.metric-val-sar {
  font-size: 12px;
  color: #006C35;
  font-weight: 600;
}

[data-theme="dark"] .metric-val-sar {
  color: #38b472;
}

.metric-val-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.text-success {
  color: #10B981;
}

/* لوحة تفاصيل الإنفاق والتوزيع حسب النماذج */
.spending-breakdown-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 24px;
}

.model-spend-progress-bar {
  height: 12px;
  border-radius: var(--radius-pill);
  display: flex;
  overflow: hidden;
  background: var(--bg-muted);
  margin: 6px 0 12px 0;
}

.spend-seg {
  height: 100%;
  transition: width 0.3s ease;
}

.spend-seg.seg-claude {
  background: #CC785C;
}

.spend-seg.seg-deepseek {
  background: #3B82F6;
}

.spend-seg.seg-openai {
  background: #10A37F;
}

.spend-seg.seg-google {
  background: #F59E0B;
}

.model-spend-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.model-spend-mini-card {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot-legend {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-claude {
  background: #CC785C;
}

.dot-deepseek {
  background: #3B82F6;
}

.dot-openai {
  background: #10A37F;
}

.dot-google {
  background: #F59E0B;
}

.mini-model-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  flex: 1;
}

.mini-share-pct {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.mini-spend-nums {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.mini-usd {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-amiri), serif;
  color: var(--text-main);
}

.mini-sar {
  font-size: 12px;
  color: #006C35;
  font-weight: 600;
}

[data-theme="dark"] .mini-sar {
  color: #38b472;
}

.mini-tokens-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* جدول سجل النشاط والاستعلامات */
.consumption-activity-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 16px;
}

.activity-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.activity-section-title {
  font-size: 14.5px;
  font-weight: 700;
  font-family: var(--font-amiri);
  color: var(--text-main);
}

.activity-badge-count {
  font-size: 11px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
}

.activity-table-wrapper {
  overflow-x: auto;
}

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: right;
}

.activity-table th {
  padding: 10px 12px;
  background: var(--bg-canvas);
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
}

.activity-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.activity-table tr:hover td {
  background: var(--bg-surface-hover);
}

.badge-status-ok {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: rgba(16, 185, 129, 0.1);
  color: #10B981;
  font-size: 11px;
  font-weight: 600;
}

/* بطاقة تحت الإنشاء */
.under-construction-card {
  text-align: center;
  padding: 48px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.construction-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-clay);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.construction-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-subtle);
  color: var(--accent-clay);
  font-size: 12.5px;
  font-weight: 600;
}

.construction-title {
  font-family: var(--font-amiri);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  max-width: 650px;
}

.construction-desc {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 680px;
  line-height: 1.8;
}

.construction-tags-list {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.construction-tag {
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

/* =============================================================================
   محدد النموذج المتزامن في ترويسة الشات الذكي (Chat Model & Provider Synchronizer)
   ============================================================================= */
.chat-provider-model-selector {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-active-provider-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(197, 160, 89, 0.12);
  border: 1px solid rgba(197, 160, 89, 0.35);
  color: var(--accent-gold);
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.chat-active-provider-pill:hover {
  background: rgba(197, 160, 89, 0.22);
  border-color: var(--accent-gold);
}

.provider-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: none;
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.85);
  }
}

.chat-model-dropdown {
  min-width: 180px;
  max-width: 260px;
  font-size: 13px;
  font-weight: 600;
  border-color: var(--border-subtle);
  background: var(--bg-canvas);
  color: var(--text-main);
  text-overflow: ellipsis;
}

/* =============================================================================
   القائمة المنسدلة المخصصة للنماذج مع فلترة وبحث سريع في الأعلى
   ============================================================================= */
.custom-model-dropdown-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.custom-model-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 190px;
  max-width: 280px;
  height: 32px;
  padding: 0 10px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: right;
  outline: none;
}

.custom-model-dropdown-trigger:hover,
.custom-model-dropdown-wrapper.open .custom-model-dropdown-trigger {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.custom-model-trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  direction: ltr;
}

.custom-model-trigger-arrow {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.custom-model-dropdown-wrapper.open .custom-model-trigger-arrow {
  transform: rotate(180deg);
  color: var(--accent-clay);
}

.custom-model-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  width: 340px;
  max-width: 92vw;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: none;
  z-index: 1200;
  overflow: hidden;
  animation: modelDropFadeIn 0.15s ease-out;
}

@keyframes modelDropFadeIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.custom-model-dropdown-wrapper.open .custom-model-dropdown-menu {
  display: flex;
  flex-direction: column;
}

.model-dropdown-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 2;
}

.model-dropdown-search-box svg {
  flex-shrink: 0;
  color: var(--accent-clay);
}

.model-dropdown-search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 500;
  outline: none;
  font-family: inherit;
  direction: ltr;
  text-align: right;
}

.model-dropdown-search-input::placeholder {
  color: var(--text-light);
  font-size: 11.5px;
}

.model-dropdown-search-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--transition-fast);
}

.model-dropdown-search-clear:hover {
  color: var(--accent-clay);
}

.custom-model-options-list {
  max-height: 290px;
  overflow-y: auto;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.model-group-title {
  padding: 6px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  border-bottom: 1px dashed rgba(197, 160, 89, 0.25);
  margin-top: 4px;
  user-select: none;
}

.custom-model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.12s ease;
}

.custom-model-item:hover,
.custom-model-item.highlighted {
  background: var(--bg-muted);
  color: var(--accent-clay);
}

.custom-model-item.active {
  background: rgba(197, 160, 89, 0.15);
  color: var(--accent-gold);
  font-weight: 700;
}

.custom-model-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: right;
}

.custom-model-item-tag {
  font-size: 10px;
  font-family: monospace;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.custom-model-empty-msg {
  padding: 16px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* عمق التفكير كقائمة منسدلة */
.thinking-dropdown {
  font-size: 12px;
  font-weight: 600;
  height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.thinking-dropdown:hover,
.thinking-dropdown:focus {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.chat-model-dropdown optgroup {
  font-weight: 700;
  color: var(--accent-gold);
  background: var(--bg-surface);
}

.chat-model-dropdown option {
  font-weight: 500;
  color: var(--text-main);
  background: var(--bg-canvas);
}

.chat-synced-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.message-model-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

/* =============================================================================
   شارة الرصيد التفاعلية في ترويسة الشات (Chat Header Live Balance)
   ============================================================================= */
.chat-balance-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(197, 160, 89, 0.08) 100%);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.chat-balance-badge:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16) 0%, rgba(197, 160, 89, 0.16) 100%);
  border-color: #10b981;
  box-shadow: none;
}

.chat-balance-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.chat-balance-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.chat-balance-usd {
  font-size: 13.5px;
  font-weight: 700;
  color: #10b981;
  font-family: monospace;
}

.chat-balance-divider {
  color: var(--border-subtle);
  font-size: 12px;
  margin: 0 1px;
}

.chat-balance-sar {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-gold);
  font-family: system-ui, -apple-system, sans-serif;
}

/* =============================================================================
   مجموعات الوكلاء المساعدين (Agent Groups & Actions)
   ============================================================================= */
.groups-table-wrap {
  margin-top: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.groups-table {
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  border-collapse: collapse;
  background: transparent;
  table-layout: fixed;
}

.groups-table .col-group-name {
  width: 24%;
}

.groups-table .col-group-desc {
  width: 32%;
}

.groups-table .col-group-agents {
  width: 26%;
}

.groups-table .col-group-actions {
  width: 18%;
}

.groups-table th {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  text-align: center !important;
}

.groups-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  text-align: center !important;
}

.groups-table td:first-child {
  text-align: right !important;
}

.groups-table .group-name-cell {
  justify-content: flex-start;
  text-align: right;
}

.groups-table tr:hover td {
  background: var(--bg-surface-hover);
}

.group-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.group-name-cell:hover {
  color: var(--accent-clay);
}

.group-icon-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(197, 160, 89, 0.12);
  color: var(--accent-gold);
  border: 1px solid rgba(197, 160, 89, 0.25);
  flex-shrink: 0;
}

.group-desc-cell {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.group-badge-count {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-canvas);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.group-actions-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.action-icon-btn:hover {
  box-shadow: none;
}

.action-icon-btn.btn-edit-group:hover {
  color: var(--accent-clay);
  border-color: var(--accent-clay);
  background: rgba(197, 160, 89, 0.12);
}

.action-icon-btn.btn-duplicate-group:hover {
  color: #3b82f6;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.12);
}

.action-icon-btn.btn-delete-group:hover {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.group-detail-nav-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.btn-back-to-groups {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.group-breadcrumb-tag {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(197, 160, 89, 0.12);
  border: 1px solid rgba(197, 160, 89, 0.3);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

.groups-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

#searchScopeModal {
  z-index: 3000 !important;
}

/* =============================================================================
   تنسيق وضبط اتجاه كافة الجداول في المنظومة من اليمين لليسار (RTL Tables)
   ============================================================================= */
table,
.markdown-body table,
.message-content table,
.chat-table-wrapper table,
.execution-round-card table,
.project-run-panel table {
  direction: rtl !important;
  text-align: right !important;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 18px 0;
  font-size: 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: none;
}

table thead,
.markdown-body thead,
.message-content thead {
  direction: rtl !important;
  text-align: right !important;
  background: var(--bg-muted);
}

table th,
.markdown-body th,
.message-content th {
  direction: rtl !important;
  text-align: right !important;
  background: var(--bg-muted);
  color: var(--text-main);
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border-medium);
  border-left: 1px solid var(--border-subtle);
  border-right: none !important;
  font-family: var(--font-amiri), serif;
  font-size: 16.5px;
  letter-spacing: 0.2px;
}

table th:last-child,
.markdown-body th:last-child,
.message-content th:last-child {
  border-left: none;
}

table td,
.markdown-body td,
.message-content td {
  direction: rtl !important;
  text-align: right !important;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  border-right: none !important;
  color: var(--text-main);
  line-height: 1.7;
  vertical-align: top;
}

table td:last-child,
.markdown-body td:last-child,
.message-content td:last-child {
  border-left: none;
}

table tr:last-child td,
.markdown-body tr:last-child td,
.message-content tr:last-child td {
  border-bottom: none;
}

table tr:nth-child(even) td,
.markdown-body tr:nth-child(even) td,
.message-content tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.018);
}

[data-theme="dark"] table tr:nth-child(even) td,
[data-theme="dark"] .markdown-body tr:nth-child(even) td,
[data-theme="dark"] .message-content tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.025);
}

table tr:hover td,
.markdown-body tr:hover td,
.message-content tr:hover td {
  background: rgba(181, 106, 76, 0.06);
}

[data-theme="dark"] .message-content tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.message-content tr:hover td {
  background: var(--accent-subtle);
}

/* تنسيق الاقتباسات (محصورة حصراً بالآيات القرآنية والأحاديث النبوية) */
.message-content blockquote {
  border-right: 4px solid var(--accent-clay);
  border-left: none;
  background: var(--accent-subtle);
  margin: 16px 0;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-amiri);
  font-size: 19.5px;
  line-height: 1.85;
  font-style: normal;
}

.message-content blockquote p {
  margin: 0;
}

.chat-subagent-select-wrap {
  display: flex;
  align-items: center;
}

/* =============================================================================
   تغليف الجداول الماركداون مع شريط أدوات التحميل بصيغة CSV
   ============================================================================= */
.chat-table-wrapper {
  margin: 20px 0;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
  box-shadow: none;
  direction: rtl !important;
  text-align: right !important;
}

.chat-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-medium);
  gap: 12px;
  direction: rtl !important;
}

.chat-table-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  direction: rtl !important;
}

.chat-table-title svg {
  color: var(--accent-clay);
}

.chat-table-csv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: none;
  direction: rtl !important;
}

.chat-table-csv-btn:hover {
  background: var(--accent-clay);
  color: #ffffff !important;
  border-color: var(--accent-clay);
  box-shadow: none;
}

.chat-table-csv-btn:hover svg {
  stroke: #ffffff;
}

.chat-table-csv-btn svg {
  stroke-width: 2.2;
  transition: stroke 0.2s ease;
}

.chat-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  direction: rtl !important;
  text-align: right !important;
}

.chat-table-scroll table {
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none;
}

/* =============================================================================
   مظهر منظومة المشاريع البحثية التراثية (Heritage Research Projects Hub)
   ============================================================================= */

.projects-container {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 28px 40px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.projects-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
}

.projects-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: none;
}

.projects-search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 480px;
}

.projects-search-box input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.projects-stats-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-clay);
  background: rgba(181, 106, 76, 0.12);
  padding: 5px 12px;
  border-radius: var(--radius-pill);
}

/* شبكة بطاقات المشاريع */
#projectsListViewWrapper {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
  margin-top: 4px;
}

.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.project-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-clay);
  box-shadow: none;
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.project-card-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.project-card-date {
  font-size: 12px;
  color: var(--text-muted);
}

.project-card-title {
  font-family: var(--font-amiri);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  margin: 0;
}

.project-card-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.meta-chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.btn-card-action {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-card-action.primary {
  background: var(--accent-clay);
  color: #FFFFFF;
  border-color: var(--accent-clay);
}

.btn-card-action.primary:hover {
  background: var(--accent-clay-hover);
}

.btn-card-action.danger:hover {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
  border-color: #dc2626;
}

.projects-empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-surface);
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.projects-empty-state .empty-icon {
  font-size: 48px;
}

/* مساحة عمل المشروع التفصيلية */
#projectDetailWorkspaceWrapper {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.project-workspace-header,
.project-cards-toggle-bar,
.project-components-grid,
.project-run-panel {
  width: 100%;
  max-width: 100%;
  margin-inline: 0;
  box-sizing: border-box;
}

.project-workspace-header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin-bottom: 0;
  box-shadow: none;
}

.project-workspace-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-back-to-projects {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-clay);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-back-to-projects:hover {
  background: rgba(181, 106, 76, 0.12);
}

.project-title-meta {
  width: 100%;
}

.project-title-meta h3,
.project-title-meta h2 {
  font-family: var(--font-amiri);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 6px 0;
  line-height: 1.4;
  word-break: break-word;
}

.project-title-meta p {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.6;
  word-break: break-word;
}

.project-workspace-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

/* شريط التحكم ببطاقات المشروع */
.project-cards-toggle-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0;
  padding: 12px 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: none;
}

/* شبكة مكونات المشروع الستة */
.project-components-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 16px;
  width: 100%;
  min-width: 0;
  transition: all 0.25s ease;
}

.project-component-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.project-component-card.collapsed {
  border-color: var(--border-subtle);
  box-shadow: none;
}

.project-component-card.component-disabled {
  opacity: 0.55;
  filter: grayscale(0.5);
}

.p-card-header {
  padding: 14px 18px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.p-card-header:hover {
  background: rgba(184, 115, 51, 0.05);
}

.project-component-card.collapsed .p-card-header {
  border-bottom: none;
}

.project-component-card.collapsed .p-card-body {
  display: none !important;
}

.p-card-collapse-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: 6px;
  transition: transform 0.25s ease, background 0.15s ease;
  flex-shrink: 0;
  margin-right: 6px;
}

.p-card-header:hover .p-card-collapse-icon {
  background: var(--bg-surface);
  color: var(--text-main);
}

.project-component-card.collapsed .p-card-collapse-icon svg {
  transform: rotate(90deg);
}

.project-component-card:not(.collapsed) .p-card-collapse-icon svg {
  transform: rotate(0deg);
}

.p-card-quick-summary {
  display: none;
  font-size: 11.5px;
  color: var(--accent-clay);
  font-weight: 600;
  background: rgba(184, 115, 51, 0.08);
  border: 1px solid rgba(184, 115, 51, 0.2);
  padding: 2px 10px;
  border-radius: var(--radius-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 200px;
  max-width: 34%;
  min-width: 0;
}

.project-component-card.collapsed .p-card-quick-summary {
  display: block;
}

.p-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(181, 106, 76, 0.14);
  color: var(--accent-clay);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.p-card-titles {
  flex: 1 1 auto;
  min-width: 0;
}

.p-card-titles h4,
.p-card-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p-card-titles h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 2px 0;
}

.p-card-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  display: block;
}

.p-status-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.p-status-pill.active {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.p-card-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.p-subagents-preview-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.subagent-preview-item {
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.subagent-p-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  color: var(--text-main);
}

.subagent-p-pool {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-clay);
  background: rgba(181, 106, 76, 0.14);
  padding: 1px 6px;
  border-radius: 4px;
}

.subagent-p-scope {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.p-outputs-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.p-output-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  cursor: pointer;
}

.p-output-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-clay);
  cursor: pointer;
}

/* لوحة تشغيل المشروع */
.project-run-panel {
  margin-top: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: none;
  overflow: hidden;
}

.project-run-header {
  padding: 16px 22px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 14px;
}

.project-run-status-text {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-main);
}

.project-run-action-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.project-run-action-btns .btn-primary-gradient {
  background: var(--btn-bg, var(--accent-clay));
  color: var(--btn-text, #fff) !important;
  border-color: transparent;
  box-shadow: none !important;
}

.project-run-action-btns .btn-primary-gradient:hover {
  background: var(--btn-hover, var(--accent-hover));
  color: var(--btn-text, #fff) !important;
}

.project-run-action-btns .btn-primary-gradient svg {
  stroke: currentColor;
}

.project-run-action-btns .btn-secondary-action {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  box-shadow: none !important;
}

.project-run-content {
  padding: 24px;
  max-height: 650px;
  overflow-y: auto;
}

/* استوديو تخطيط وهندسة المشروع التفاعلي الشامل */
.project-planning-studio-window,
.planning-studio-modal-window {
  width: 96vw;
  max-width: 1420px;
  height: 92vh;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: none;
  overflow: hidden;
  animation: modalPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.planner-model-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-muted);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.planner-model-picker label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.form-select-sm {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--text-main);
  outline: none;
  max-width: 380px;
}

.planning-studio-body {
  display: flex !important;
  flex-direction: row !important;
  width: 100% !important;
  flex: 1 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: var(--bg-canvas);
}

/* لوحة المحاورة التفاعلية (يمين في RTL) */
.studio-chat-panel {
  flex: 1.25 !important;
  width: 55% !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  height: 100% !important;
  overflow: hidden !important;
}

.studio-chat-history {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
}

.studio-msg {
  display: flex;
  gap: 12px;
  max-width: 95%;
  min-width: 0;
  box-sizing: border-box;
  animation: fadeIn 0.2s ease-in;
}

.studio-msg.architect {
  align-self: flex-start;
}

.studio-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.studio-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  background: rgba(181, 106, 76, 0.15);
  color: var(--accent-clay);
  border: 1px solid rgba(181, 106, 76, 0.22);
}

.studio-msg.user .studio-avatar {
  background: var(--bg-muted);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.studio-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text-main);
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

.studio-bubble * {
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

.studio-bubble pre,
.studio-bubble code {
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-x: auto;
  max-width: 100%;
  font-family: var(--font-mono, monospace);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.studio-bubble p {
  margin: 0 0 10px 0;
}

.studio-bubble p:last-child {
  margin-bottom: 0;
}

.studio-bubble ul,
.studio-bubble ol {
  padding-right: 22px;
  margin: 6px 0 10px 0;
}

.studio-bubble table {
  width: 100%;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.studio-msg.architect .studio-bubble {
  background: rgba(181, 106, 76, 0.06);
  border-color: rgba(181, 106, 76, 0.20);
}

.studio-msg.user .studio-bubble {
  background: var(--accent-clay);
  color: #FFFFFF !important;
  border-color: var(--accent-clay);
}

.studio-msg.user .studio-bubble * {
  color: #FFFFFF !important;
}

.studio-quick-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  overflow-x: auto;
  white-space: nowrap;
}

.studio-chip {
  font-size: 11.5px;
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.studio-chip:hover {
  background: rgba(181, 106, 76, 0.14);
  border-color: var(--accent-clay);
  color: var(--accent-clay);
}

.studio-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-muted);
  border-top: 1px solid var(--border-subtle);
}

.studio-textarea {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text-main);
  resize: none;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
}

.studio-textarea:focus {
  border-color: var(--accent-clay);
}

.studio-send-btn {
  padding: 10px 18px;
  font-size: 13.5px;
  white-space: nowrap;
  height: 42px;
}

/* درج استكشاف الكتب الببليوغرافية في استوديو التخطيط */
.studio-books-drawer {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 18px;
  animation: fadeIn 0.25s ease-in;
}

.studio-books-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.studio-books-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-clay);
  display: flex;
  align-items: center;
  gap: 6px;
}

.studio-books-search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.studio-books-search-input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  color: var(--text-main);
  outline: none;
  transition: border-color var(--transition-fast);
}

.studio-books-search-input:focus {
  border-color: var(--accent-clay);
  box-shadow: none;
}

.studio-books-clear-btn {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
}

.studio-books-clear-btn:hover {
  color: var(--text-main);
}

.studio-books-cat-select {
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  max-width: 180px;
}

.studio-books-cat-select:focus {
  border-color: var(--accent-clay);
}

.studio-books-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 95px;
  overflow-y: auto;
  padding: 2px;
}

.studio-book-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11.5px;
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.studio-book-chip:hover {
  border-color: var(--accent-clay);
  background: rgba(181, 106, 76, 0.12);
  color: var(--accent-clay);
}

.studio-book-chip .book-id-badge {
  background: var(--accent-clay);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: monospace;
  letter-spacing: 0.5px;
}

.studio-book-chip .book-author {
  color: var(--text-muted);
  font-size: 10.5px;
}

/* لوحة المعاينة الحية لكروت المشروع (يسار) */
.studio-blueprint-panel {
  flex: 1 !important;
  width: 45% !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  background: var(--bg-canvas);
  height: 100% !important;
  overflow: hidden !important;
}

.blueprint-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.b-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
}

.studio-cards-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.studio-empty-blueprint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  min-height: 280px;
  padding: 30px;
  color: var(--text-muted);
}

.studio-empty-blueprint .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.studio-empty-blueprint h4 {
  font-family: var(--font-amiri);
  font-size: 18px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.studio-empty-blueprint p {
  font-size: 13px;
  line-height: 1.6;
  max-width: 380px;
}

.studio-card-preview {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: none;
}

.studio-card-preview .scp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.studio-card-preview .scp-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--accent-clay);
  display: flex;
  align-items: center;
  gap: 6px;
}

.studio-card-preview .scp-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-muted);
  font-weight: 600;
}

.studio-card-preview .scp-body {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-main);
}

.studio-blueprint-footer {
  padding: 14px 18px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

.planning-compass-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(181, 106, 76, 0.15);
  color: var(--accent-clay);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}


/* نافذة تأسيس مشروع يدوي ونوافذ المشاريع */
.project-manual-modal-window {
  width: 92%;
  max-width: 660px;
  height: auto;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: none;
  overflow: hidden;
  animation: modalPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopIn {
  0% {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-title-with-icon {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-title-with-icon h3 {
  font-family: var(--font-amiri);
  font-size: 21px;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
  line-height: 1.25;
}

.modal-title-with-icon .modal-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 3px 0 0 0;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close-modal:hover {
  background: var(--bg-muted);
  color: var(--accent-clay);
}

.project-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 26px;
  overflow-y: auto;
}

.project-modal-body .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-modal-body .form-group label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
}

.project-modal-body .form-input,
.project-modal-body .form-select,
.project-modal-body .form-textarea {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-main);
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.project-modal-body .form-input:focus,
.project-modal-body .form-select:focus,
.project-modal-body .form-textarea:focus {
  border-color: var(--accent-clay);
  box-shadow: none;
  outline: none;
}

.project-modal-body .form-textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.6;
}

.project-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 26px;
  background: var(--bg-muted);
  border-top: 1px solid var(--border-subtle);
}

.manual-project-toggles-card {
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.m-toggles-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-clay);
}

.m-toggles-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.m-toggle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.m-toggle-item input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent-clay);
  cursor: pointer;
}

/* أزرار المشاريع الموحدة والفاخرة */
.btn-primary-gradient {
  background: linear-gradient(135deg, var(--accent-clay) 0%, #8c320d 100%);
  color: #FFFFFF !important;
  border: 1px solid var(--accent-clay);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 20px;
  font-size: 14px;
  transition: all var(--transition-fast);
  box-shadow: none;
  font-family: inherit;
  text-decoration: none;
}

.btn-primary-gradient:hover {
  background: linear-gradient(135deg, #b45309 0%, #6e2406 100%);
  box-shadow: none;
  color: #FFFFFF !important;
}

.btn-primary-gradient:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-primary-gradient svg {
  stroke: #FFFFFF;
}

.btn-secondary-action {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 13.5px;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.btn-secondary-action:hover {
  background: var(--bg-muted);
  border-color: var(--accent-clay);
  color: var(--accent-clay);
}

/* ==========================================================================
   تبويب مستودع الأدوات والإضافات الذكية (Tools & Extensions Hub)
   ========================================================================== */
.tools-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 20px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: none;
}

.tools-header-info h2 {
  font-family: var(--font-amiri);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.tools-header-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 800px;
}

.tools-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* شريط التصفية والفلترة */
.tools-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
}

.tools-filter-pill {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: var(--font-amiri);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: none;
}

.tools-filter-pill:hover {
  border-color: var(--accent-clay);
  color: var(--text-main);
}

.tools-filter-pill.active {
  background: var(--btn-bg, var(--accent-clay));
  color: var(--btn-text, #FFFFFF);
  border-color: var(--accent-clay);
}

/* شبكة كروت الأدوات */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

.tool-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  box-shadow: none;
  transition: all var(--transition-normal);
  position: relative;
}

.tool-card:hover {
  border-color: var(--accent-clay);
  background: var(--bg-surface-hover);
}

.tool-card.disabled {
  opacity: 0.6;
  filter: grayscale(0.6);
}

.tool-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tool-card-title-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-card-title {
  font-family: var(--font-amiri);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-card-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 700;
  width: fit-content;
}

.tool-badge-web {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.tool-badge-python {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
  border: 1px solid rgba(22, 163, 74, 0.2);
}

.tool-card-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  flex: 1;
}

.tool-card-meta {
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: monospace;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
}

.tool-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.tool-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* محرر الكود وبيئة الاختبار */
.tool-code-box {
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: "JetBrains Mono", Consolas, Monaco, monospace;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  padding: 12px;
  line-height: 1.5;
  direction: ltr;
  text-align: left;
  border: 1px solid #333;
  width: 100%;
  box-sizing: border-box;
}

.tool-test-result-box {
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 13px;
  margin-top: 10px;
  direction: ltr;
  text-align: left;
  font-family: monospace;
  white-space: pre-wrap;
  max-height: 250px;
  overflow-y: auto;
}

.tool-test-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #166534;
}

[data-theme="dark"] .tool-test-success {
  color: #4ade80;
}

.tool-test-failure {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #991b1b;
}

[data-theme="dark"] .tool-test-failure {
  color: #f87171;
}

/* نافذة المودال الكبيرة للأدوات */
.tool-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 75vh;
  overflow-y: auto;
  padding: 20px;
}

.tool-type-toggle-group {
  display: flex;
  gap: 12px;
}

.tool-type-radio-card {
  flex: 1;
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all var(--transition-fast);
  background: var(--bg-surface);
}

.tool-type-radio-card:hover {
  border-color: var(--accent-clay);
}

.tool-type-radio-card.active {
  border-color: var(--accent-clay);
  background: rgba(181, 106, 76, 0.07);
}

.tool-type-radio-card input {
  cursor: pointer;
}

.tool-ai-chat-box {
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-render-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 14px;
  box-shadow: none;
}

.chart-render-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.chart-render-title {
  font-family: var(--font-amiri);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* بطاقة شجرة الأسانيد وشبكات الرواة */
.isnad-render-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 16px;
  margin-bottom: 16px;
  box-shadow: none;
}

.isnad-render-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.isnad-render-title {
  font-family: var(--font-amiri);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.isnad-canvas-container {
  height: 280px;
  width: 100%;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}

/* أزرار تصدير نتائج الرسائل في الشات */
.btn-msg-export {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.btn-msg-export:hover {
  border-color: var(--accent-clay);
  color: var(--accent-clay);
  background: var(--bg-muted);
}

/* أزرار تبديل نوع الشارت التفاعلي */
.chart-type-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-chart-type {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-chart-type:hover {
  border-color: var(--accent-clay);
  color: var(--accent-clay);
}

.btn-chart-type.active {
  background: var(--accent-clay);
  color: #FFFFFF !important;
  border-color: var(--accent-clay);
}

/* تنسيقات الطباعة والتصدير الأكاديمي */
@media print {
  body {
    background: #FFFFFF !important;
    color: #111827 !important;
  }

  .main-nav,
  .header-actions,
  .tools-header-actions,
  .project-modal-footer,
  #projectRunActionBtns,
  .tools-filter-bar,
  button {
    display: none !important;
  }

  .execution-round-card,
  .chart-render-wrapper,
  .isnad-render-wrapper,
  table {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  table {
    border-collapse: collapse !important;
    width: 100% !important;
  }

  th,
  td {
    border: 1px solid #d1d5db !important;
    padding: 6px 10px !important;
  }

  th {
    background-color: #f3f4f6 !important;
    color: #111827 !important;
  }
}

  /* ==========================================================================
   نافذة إعداد وتوجيه مدارسة المشروع في الشات الذكي (Project to Chat Setup Modal)
   ========================================================================== */
  .project-to-chat-window {
    width: 90%;
    max-width: 880px;
    max-height: 92vh;
    border-radius: var(--radius-lg);
    box-shadow: none;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalScaleUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .p2c-agent-badge-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
  }

  .p2c-agent-badge-card:hover {
    border-color: var(--accent-clay);
    background: rgba(181, 106, 76, 0.05);
  }

  .p2c-agent-badge-card.active {
    border-color: var(--accent-clay);
    background: rgba(181, 106, 76, 0.12);
  }

  .p2c-agent-badge-card input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--accent-clay);
  }

  .p2c-agent-badge-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
  }

  .p2c-agent-badge-name {
    font-weight: 700;
    font-size: 12.5px;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .p2c-agent-badge-role {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ==========================================================================
   طبقة تلميع نهائية — Scholarly Ink polish
   ========================================================================== */
  ::selection {
    background: var(--accent-subtle);
    color: var(--ink-deep);
  }

  :focus-visible {
    outline: 2px solid var(--accent-clay);
    outline-offset: 2px;
  }

  .history-item:hover,
  .history-item.active {
    background: var(--accent-light);
    color: var(--accent-clay);
    font-weight: 500;
  }

  .chat-top-control {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .search-welcome-card {
    background:
      radial-gradient(ellipse 80% 80% at 50% 0%, var(--accent-subtle), transparent 70%),
      var(--bg-surface) !important;
  }

  .tab-pane.active {
    animation: fadeIn 0.35s var(--transition-normal) both;
  }

  @media (max-width: 1100px) {
    .app-header {
      flex-wrap: wrap;
      row-gap: 12px;
      padding: 12px 16px;
    }

    .main-nav {
      order: 3;
      width: 100%;
      justify-content: flex-start;
    }

    .brand-title {
      font-size: 24px;
    }

    .nav-tab-btn span {
      display: none;
    }

    .nav-tab-btn {
      padding: 9px 12px;
    }

    .nav-tab-btn.active span {
      display: inline;
    }
  }

  @media (max-width: 640px) {
    .search-box-wrapper {
      flex-wrap: wrap;
      padding: 12px;
    }

    .search-input {
      width: 100%;
      font-size: 17px;
    }

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

    .chat-layout {
      height: calc(100vh - 120px);
    }

    .chat-sidebar {
      display: none;
    }

    .search-hero h2 {
      font-size: 24px;
    }
  }

  /* ==========================================================================
   تسطيح عام: بدون ظلال + انحناء بسيط للحوايا
   ========================================================================== */
  .app-header,
  .main-nav,
  .nav-tab-btn,
  .btn-icon,
  .btn-flat-primary,
  .btn-flat-secondary,
  .btn-new-chat,
  .search-box-wrapper,
  .filters-bar,
  .result-card,
  .chat-input-box,
  .chat-sidebar,
  .modal-window,
  .tools-header,
  .tools-filter-pill,
  .tool-card,
  .studio-chip,
  .meta-chip,
  .score-badge,
  .chat-template-chip,
  .btn-scope-selector {
    box-shadow: none !important;
  }

  .tools-filter-pill,
  .studio-chip,
  .meta-chip,
  .score-badge,
  .chat-template-chip {
    border-radius: var(--radius-sm) !important;
  }

  /* شكل الحبر: تبويبات سفلية وحاويات بزوايا قائمة */
  [data-theme="ink"] .main-nav {
    background: transparent;
    border: none;
    padding: 0;
    gap: 0;
    border-radius: 0;
  }

  [data-theme="ink"] .nav-tab-btn {
    border-radius: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
  }

  [data-theme="ink"] .nav-tab-btn.active {
    background: transparent;
    color: var(--accent-clay);
    border-bottom-color: var(--accent-clay);
  }

  [data-theme="ink"] .search-hero::before {
    width: 64px;
    height: 2px;
    border-radius: 0;
    background: var(--accent-clay);
  }

  [data-theme="ink"] .result-card,
  [data-theme="ink"] .tool-card {
    border-inline-start-width: 1px;
    border-top: 2px solid var(--border-subtle);
  }

  [data-theme="ink"] .result-card:hover,
  [data-theme="ink"] .tool-card:hover {
    border-top-color: var(--accent-clay);
  }

  /* شكل الواحة: انحناء أوضح وشريط جانبي أسمك */
  [data-theme="oasis"] .main-nav {
    border-radius: 16px;
    padding: 5px;
  }

  [data-theme="oasis"] .nav-tab-btn,
  [data-theme="oasis"] .nav-tab-btn.active {
    border-radius: 12px;
  }

  [data-theme="oasis"] .search-box-wrapper,
  [data-theme="oasis"] .chat-input-box {
    border-radius: 20px;
  }

  [data-theme="oasis"] .result-card,
  [data-theme="oasis"] .tool-card {
    border-radius: 16px;
    border-inline-start-width: 4px;
    border-inline-start-color: var(--accent-clay);
  }

  [data-theme="oasis"] .search-hero::before {
    width: 56px;
    height: 4px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent-clay), var(--accent-emerald));
  }

  /* حرير: كبسولات ناعمة وخط ذهبي رفيع */
  [data-theme="silk"] .app-header {
    border-bottom: 1px solid transparent;
    background-image: linear-gradient(var(--glass), var(--glass)), linear-gradient(90deg, var(--accent-emerald), var(--accent-clay));
    background-origin: border-box;
    background-clip: padding-box, border-box;
  }

  [data-theme="silk"] .main-nav,
  [data-theme="silk"] .nav-tab-btn,
  [data-theme="silk"] .nav-tab-btn.active {
    border-radius: 999px;
  }

  [data-theme="silk"] .nav-tab-btn.active {
    background: var(--emerald-light);
    color: var(--accent-emerald);
  }

  [data-theme="silk"] .search-box-wrapper,
  [data-theme="silk"] .chat-input-box,
  [data-theme="silk"] .btn-flat-primary,
  [data-theme="silk"] .btn-new-chat {
    border-radius: 999px;
  }

  /* فحمي: إطار ذهبي رفيع وزوايا شبه قائمة */
  [data-theme="charcoal"] .app-header,
  [data-theme="charcoal"] .search-box-wrapper,
  [data-theme="charcoal"] .result-card,
  [data-theme="charcoal"] .tool-card,
  [data-theme="charcoal"] .chat-input-box,
  [data-theme="charcoal"] .modal-window {
    border-color: #6E5830;
  }

  [data-theme="charcoal"] .nav-tab-btn.active {
    background: #2C271C;
    color: var(--accent-clay);
  }

  [data-theme="charcoal"] .search-hero::before {
    width: 72px;
    height: 1px;
    border-radius: 0;
    background: var(--accent-clay);
  }

  /* بحري: كبسولات واسعة وشريط طيني */
  [data-theme="marine"] .main-nav,
  [data-theme="marine"] .nav-tab-btn,
  [data-theme="marine"] .nav-tab-btn.active {
    border-radius: 999px;
  }

  [data-theme="marine"] .nav-tab-btn.active {
    background: var(--accent-light);
    color: var(--accent-clay);
  }

  [data-theme="marine"] .search-box-wrapper,
  [data-theme="marine"] .chat-input-box,
  [data-theme="marine"] .result-card,
  [data-theme="marine"] .tool-card {
    border-radius: 24px;
  }

  [data-theme="marine"] .result-card,
  [data-theme="marine"] .tool-card {
    border-inline-start: 4px solid var(--accent-clay);
  }

  [data-theme="marine"] .search-hero::before {
    width: 48px;
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-clay), #7EB4D4);
  }

  /* رمال الشمال: أصفر فاتح من أسفل اليمين إلى رصاصي فاتح أعلى اليسار */
  html[data-theme="north-sand"],
  html[data-theme="north-sand"] body {
    background-color: #E4E2DC;
    background-image: linear-gradient(to top left, #F8E7A0 0%, #F4EBD0 46%, #E3E1DC 100%);
    background-attachment: fixed;
    background-repeat: no-repeat;
  }

  [data-theme="north-sand"] .app-header {
    background: rgba(251, 248, 241, 0.72);
    border-bottom-color: transparent;
  }

  [data-theme="north-sand"] .main-nav {
    background: #F7F3E8;
    border-radius: 999px;
    padding: 5px;
    border-color: transparent;
  }

  [data-theme="north-sand"] .nav-tab-btn,
  [data-theme="north-sand"] .nav-tab-btn.active {
    border-radius: 999px;
  }

  [data-theme="north-sand"] .nav-tab-btn.active {
    background: #1E1E1E;
    color: #FBF8F1;
  }

  [data-theme="north-sand"] .nav-tab-btn.active .icon,
  [data-theme="north-sand"] .nav-tab-btn.active svg {
    color: #F0C93A;
    stroke: #F0C93A;
  }

  [data-theme="north-sand"] .search-box-wrapper,
  [data-theme="north-sand"] .chat-input-box,
  [data-theme="north-sand"] .result-card,
  [data-theme="north-sand"] .tool-card,
  [data-theme="north-sand"] .filters-bar,
  [data-theme="north-sand"] .modal-window,
  [data-theme="north-sand"] .project-component-card,
  [data-theme="north-sand"] .project-run-panel,
  [data-theme="north-sand"] .project-workspace-header {
    border-radius: 28px;
    border-color: transparent;
    background: #FBF8F1;
  }

  [data-theme="north-sand"] .btn-flat-primary,
  [data-theme="north-sand"] .btn-new-chat {
    border-radius: 999px;
    background: #1E1E1E;
    color: #FBF8F1;
  }

  [data-theme="north-sand"] .btn-flat-primary:hover,
  [data-theme="north-sand"] .btn-new-chat:hover {
    background: #111111;
  }

  [data-theme="north-sand"] .score-badge,
  [data-theme="north-sand"] .tools-filter-pill.active {
    background: #F0C93A;
    color: #1E1E1E;
    border-color: transparent;
  }

  /* ليلك: بطاقات بيضاء ناعمة، تبويب فحمي، ولمسة بنفسجية */
  html[data-theme="lilac"],
  html[data-theme="lilac"] body {
    background-color: #F3F4F8;
    background-image:
      radial-gradient(ellipse 72% 46% at 100% -8%, rgba(123, 92, 250, 0.13), transparent 56%),
      radial-gradient(ellipse 48% 38% at -6% 108%, rgba(183, 164, 255, 0.16), transparent 52%);
    background-attachment: fixed;
    background-repeat: no-repeat;
  }

  [data-theme="lilac"] .app-header {
    background: rgba(243, 244, 248, 0.82);
    border-bottom-color: transparent;
  }

  [data-theme="lilac"] .main-nav {
    background: #EEF0F5;
    border-radius: 999px;
    padding: 5px;
    border-color: transparent;
  }

  [data-theme="lilac"] .nav-tab-btn,
  [data-theme="lilac"] .nav-tab-btn.active {
    border-radius: 999px;
  }

  [data-theme="lilac"] .nav-tab-btn.active {
    background: #1C1C22;
    color: #FFFFFF;
  }

  [data-theme="lilac"] .nav-tab-btn.active .icon,
  [data-theme="lilac"] .nav-tab-btn.active svg {
    color: #C4B5FD;
    stroke: #C4B5FD;
  }

  [data-theme="lilac"] .search-box-wrapper,
  [data-theme="lilac"] .chat-input-box,
  [data-theme="lilac"] .result-card,
  [data-theme="lilac"] .tool-card,
  [data-theme="lilac"] .filters-bar,
  [data-theme="lilac"] .modal-window,
  [data-theme="lilac"] .project-component-card,
  [data-theme="lilac"] .project-run-panel,
  [data-theme="lilac"] .project-workspace-header {
    border-radius: 24px;
    border-color: #ECEEF4;
    background: #FFFFFF;
    box-shadow: 0 10px 28px rgba(23, 23, 28, 0.05) !important;
  }

  [data-theme="lilac"] .btn-flat-primary,
  [data-theme="lilac"] .btn-new-chat {
    border-radius: 999px;
    background: #1C1C22;
    color: #FFFFFF;
  }

  [data-theme="lilac"] .btn-flat-primary:hover,
  [data-theme="lilac"] .btn-new-chat:hover {
    background: #111114;
  }

  [data-theme="lilac"] .score-badge,
  [data-theme="lilac"] .tools-filter-pill.active {
    background: #7B5CFA;
    color: #FFFFFF;
    border-color: transparent;
  }

  /* مارشملو: خلفية باستيل، تبويب بنفسجي عميق، وبطاقات بيضاء طافية */
  html[data-theme="marshmallow"],
  html[data-theme="marshmallow"] body {
    background-color: #F6E8F6;
    background-image:
      radial-gradient(ellipse 48% 62% at 0% 0%, #F6B7D6 0%, transparent 58%),
      radial-gradient(ellipse 46% 58% at 100% 0%, #F8D7A4 0%, transparent 54%),
      radial-gradient(ellipse 42% 50% at 100% 100%, #F6C98E 0%, transparent 52%),
      radial-gradient(ellipse 40% 52% at 0% 100%, #D9C4F6 0%, transparent 56%),
      linear-gradient(155deg, #F8E3F2 0%, #F4F0FB 46%, #FDEED6 100%);
    background-attachment: fixed;
    background-repeat: no-repeat;
  }

  [data-theme="marshmallow"] .app-header {
    background: rgba(255, 255, 255, 0.62);
    border-bottom-color: transparent;
  }

  [data-theme="marshmallow"] .main-nav {
    background: rgba(255, 255, 255, 0.78);
    border-radius: 6px;
    padding: 5px;
    border-color: transparent;
    box-shadow: 0 8px 24px rgba(59, 42, 120, 0.06) !important;
  }

  [data-theme="marshmallow"] .nav-tab-btn {
    color: #5C5474;
  }

  [data-theme="marshmallow"] .nav-tab-btn,
  [data-theme="marshmallow"] .nav-tab-btn.active {
    border-radius: 4px;
  }

  [data-theme="marshmallow"] .nav-tab-btn.active {
    background: #3B2A78;
    color: #FFFFFF;
  }

  [data-theme="marshmallow"] .nav-tab-btn.active .icon,
  [data-theme="marshmallow"] .nav-tab-btn.active svg {
    color: #F3C6E0;
    stroke: #F3C6E0;
  }

  [data-theme="marshmallow"] .search-hero::before {
    width: 56px;
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, #E4549B, #6B4DFF);
  }

  [data-theme="marshmallow"] .search-box-wrapper,
  [data-theme="marshmallow"] .chat-input-box,
  [data-theme="marshmallow"] .result-card,
  [data-theme="marshmallow"] .tool-card,
  [data-theme="marshmallow"] .filters-bar,
  [data-theme="marshmallow"] .modal-window,
  [data-theme="marshmallow"] .project-component-card,
  [data-theme="marshmallow"] .project-run-panel,
  [data-theme="marshmallow"] .project-workspace-header,
  [data-theme="marshmallow"] .search-welcome-card {
    border-radius: 6px;
    border-color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 16px 40px rgba(80, 48, 140, 0.08) !important;
  }

  [data-theme="marshmallow"] .btn-flat-primary,
  [data-theme="marshmallow"] .btn-new-chat {
    border-radius: 4px;
    background: #3B2A78;
    color: #FFFFFF;
  }

  [data-theme="marshmallow"] .btn-icon,
  [data-theme="marshmallow"] .theme-select-trigger,
  [data-theme="marshmallow"] .tools-filter-pill,
  [data-theme="marshmallow"] .score-badge {
    border-radius: 4px;
  }

  [data-theme="marshmallow"] .btn-flat-primary:hover,
  [data-theme="marshmallow"] .btn-new-chat:hover {
    background: #2C1E60;
  }

  [data-theme="marshmallow"] .score-badge {
    background: #E4549B;
    color: #FFFFFF;
    border-color: transparent;
  }

  [data-theme="marshmallow"] .tools-filter-pill.active {
    background: #6B4DFF;
    color: #FFFFFF;
    border-color: transparent;
  }

  /* القوائم المنسدلة: زر وقائمة بخلفية الثيم وخطه، لا قائمة النظام */
  .theme-select {
    position: relative;
    display: inline-flex;
    max-width: 100%;
    min-width: 0;
    vertical-align: middle;
  }

  .theme-select.is-fluid {
    display: flex;
    width: 100%;
  }

  .theme-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    border: 0 !important;
    appearance: none !important;
  }

  .theme-select-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: auto;
    max-width: 320px;
    min-height: 32px;
    padding: 6px 12px;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    font-family: var(--font-ui) !important;
    font-size: 13px !important;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    text-align: right;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
  }

  .theme-select.is-fluid .theme-select-trigger {
    width: 100%;
    max-width: none;
    min-height: 40px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
  }

  .theme-select-trigger:hover,
  .theme-select.is-open .theme-select-trigger {
    border-color: var(--accent-clay);
    background: var(--bg-surface);
  }

  .theme-select-trigger:disabled {
    opacity: 0.55;
    cursor: default;
  }

  .theme-select-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .theme-select-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-muted);
  }

  .theme-select.is-open .theme-select-chevron {
    color: var(--accent-clay);
  }

  .theme-select-trigger:focus,
  .theme-select-trigger:focus-visible,
  .theme-select-native:focus,
  .theme-select-native:focus-visible {
    outline: none;
  }

  .theme-select-menu {
    position: fixed;
    z-index: 100020 !important;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 6px;
    max-height: 280px;
    overflow: auto;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 16px 40px rgba(23, 23, 28, 0.12);
    font-family: var(--font-ui) !important;
    font-size: 13px !important;
  }

  .theme-select-menu[hidden] {
    display: none !important;
  }

  .theme-select-group {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
  }

  .theme-select-option {
    display: block;
    width: 100%;
    padding: 8px 12px;
    white-space: nowrap;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-main);
    font-family: var(--font-ui) !important;
    font-size: 13px !important;
    font-weight: 600;
    line-height: 1.45;
    text-align: right;
    cursor: pointer;
  }

  .theme-select-option:hover,
  .theme-select-option.is-active {
    background: var(--accent-light);
    color: var(--ink-deep);
  }

  .theme-select-option.is-selected {
    background: var(--accent-clay);
    color: var(--btn-text, #fff);
  }

  .theme-select-option:disabled {
    opacity: 0.45;
    cursor: default;
  }

  select,
  select option,
  select optgroup,
  .filter-select,
  .form-select,
  .form-select-sm,
  .chat-agent-dropdown,
  .reader-select,
  .studio-books-cat-select {
    font-family: var(--font-ui) !important;
    font-size: 13px !important;
    background-color: var(--bg-surface);
    color: var(--text-main);
  }

  select option,
  select optgroup {
    background-color: var(--bg-surface);
    color: var(--text-main);
  }

  select option:checked {
    background-color: var(--accent-light);
    color: var(--ink-deep);
  }

  [data-theme="charcoal"] select,
  [data-theme="marine"] select,
  [data-theme="dark"] select {
    color-scheme: dark;
  }

  [data-theme="sand"] select,
  [data-theme="ink"] select,
  [data-theme="oasis"] select,
  [data-theme="silk"] select,
  [data-theme="north-sand"] select,
  [data-theme="lilac"] select,
  [data-theme="marshmallow"] select {
    color-scheme: light;
  }

/* انحناء موحّد: الحاويات والأزرار 6px في كل الثيمات */
button,
.btn-icon,
.btn-flat-primary,
.btn-flat-secondary,
.btn-new-chat,
.btn-secondary-action,
.btn-primary-gradient,
.btn-back-to-projects,
.btn-scope-selector,
.nav-tab-btn,
.main-nav,
.theme-select-trigger,
.theme-select-menu,
.theme-select-option,
.search-box-wrapper,
.chat-input-box,
.filters-bar,
.projects-filter-bar,
.result-card,
.tool-card,
.project-card,
.agent-card,
.modal-window,
.project-workspace-header,
.project-cards-toggle-bar,
.project-component-card,
.project-run-panel,
.search-welcome-card,
.chat-sidebar,
.form-input,
.form-textarea,
.form-select,
.filter-select,
.filter-input,
.tools-filter-pill,
.score-badge,
.studio-chip,
.meta-chip,
.chat-template-chip,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
textarea,
select {
  border-radius: 6px !important;
}

/* ==========================================================================
   نظام نوافذ الحوار والتأكيد الموحدة (Custom Dialog System - Confirm / Alert / Prompt)
   ========================================================================== */
.app-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 17, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.app-dialog-overlay.active {
  opacity: 1;
  visibility: visible;
}

.app-dialog-window {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.32);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  transform: translateY(16px) scale(0.96);
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: right;
  direction: rtl;
}

.app-dialog-overlay.active .app-dialog-window {
  transform: translateY(0) scale(1);
}

.app-dialog-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.app-dialog-icon-badge {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.app-dialog-icon-badge .icon {
  width: 22px;
  height: 22px;
}

.app-dialog-icon-badge.danger {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.28);
}

.app-dialog-icon-badge.warning {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.28);
}

.app-dialog-icon-badge.info {
  background: rgba(47, 111, 94, 0.12);
  color: var(--accent-emerald);
  border: 1px solid rgba(47, 111, 94, 0.28);
}

.app-dialog-icon-badge.primary {
  background: var(--accent-subtle);
  color: var(--accent-clay);
  border: 1px solid rgba(181, 106, 76, 0.28);
}

.app-dialog-title {
  font-family: var(--font-amiri);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink-deep);
  line-height: 1.35;
  margin-bottom: 5px;
}

.app-dialog-message {
  font-family: var(--font-naskh);
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-line;
}

.app-dialog-input-wrapper {
  margin-top: 4px;
}

.app-dialog-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-naskh);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.app-dialog-input:focus {
  border-color: var(--accent-clay);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.app-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.app-dialog-btn {
  padding: 9px 22px;
  border-radius: var(--radius-sm);
  font-family: var(--font-naskh);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
}

.app-dialog-btn.cancel {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.app-dialog-btn.cancel:hover {
  background: var(--bg-muted);
  color: var(--text-main);
}

.app-dialog-btn.confirm-danger {
  background: #dc2626;
  color: #ffffff;
}

.app-dialog-btn.confirm-danger:hover {
  background: #b91c1c;
}

.app-dialog-btn.confirm-primary {
  background: var(--accent-clay);
  color: #ffffff;
}

.app-dialog-btn.confirm-primary:hover {
  background: var(--accent-hover);
}