/* ─────────────────── ALRAWAF ENTERPRISE PORTAL SIDEBAR ─────────────────── */
:root {
  --ps-bg-1: #3b1e78;
  --ps-bg-2: #25115a;
  --ps-gold: #e8b547;
  --ps-w: 266px;
}

body.has-control-sidebar {
  padding-right: var(--ps-w) !important;
  box-sizing: border-box;
}

.control-sidebar {
  position: fixed;
  z-index: 4800;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--ps-w);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  padding: 0;
  border: none;
  border-inline-start: 1px solid rgba(232, 181, 71, .18);
  border-radius: 0;
  background: linear-gradient(180deg, #3b1e78 0%, #25115a 100%);
  box-shadow: -4px 0 28px rgba(20, 8, 48, .36);
  color: #fff;
}

.control-sidebar::before { display: none; }
.control-sidebar > * { position: relative; z-index: 1; }

/* ─── Brand ─── */
.control-sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 5px;
  padding: 24px 18px 20px;
  border-bottom: 1px solid rgba(232, 181, 71, .14);
  border-radius: 0;
  background: rgba(255, 255, 255, .04);
}

/* اللوجو داخل بطاقة بيضاء أنيقة → يبرز على الخلفية الداكنة */
.control-sidebar-logo {
  display: block;
  height: 58px;
  width: auto;
  max-width: 82%;
  object-fit: contain;
  background: #ffffff;
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22), inset 0 0 0 1px rgba(232,181,71,.18);
  margin-bottom: 12px;
}

.control-sidebar-brand span {
  color: var(--ps-gold);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  font-family: "Tajawal", "Cairo", Arial, sans-serif;
}

.control-sidebar-brand strong {
  color: #fff;
  font-size: 17px;
  line-height: 1.35;
  font-weight: 900;
  letter-spacing: .2px;
  font-family: "Tajawal", "Cairo", Arial, sans-serif;
}

/* خط ذهبي رفيع نادر يفصل العلامة */
.control-sidebar-brand strong::after {
  content: '';
  display: block;
  width: 40px;
  height: 2px;
  margin: 9px auto 4px;
  background: linear-gradient(90deg, transparent, var(--ps-gold), transparent);
  border-radius: 2px;
}

.control-sidebar-brand small {
  color: rgba(255, 255, 255, .65);
  font-size: 11px;
  font-weight: 700;
  font-family: "Tajawal", "Cairo", Arial, sans-serif;
}

/* ─── Nav ─── */
.control-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 16px 12px;
  overflow-y: auto;
  align-content: start;
}

/* ─── Nav links ─── */
.control-sidebar-link {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: none;
  border-inline-start: 3px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, .9);
  font-family: "Tajawal", "Cairo", Arial, sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease, box-shadow .2s ease;
}

.control-sidebar-link::before { display: none; }

/* ─── Department code badge ─── */
.control-sidebar-link .ps-code {
  flex: 0 0 auto;
  width: 36px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, .1);
  color: rgba(255, 255, 255, .72);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .5px;
  font-family: "Tajawal", monospace, sans-serif;
  transition: background .15s ease, color .15s ease;
}

/* ─── Label + sublabel ─── */
.control-sidebar-link .ps-texts {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.control-sidebar-link .ps-label {
  display: block;
  font-size: 13.5px;
  font-weight: 800;
  color: rgba(255, 255, 255, .95);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.control-sidebar-link .ps-sub {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, .56);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* ─── Hover ─── */
.control-sidebar-link:hover {
  background: rgba(255, 255, 255, .08);
  border-inline-start-color: rgba(232, 181, 71, .4);
  transform: translateX(-3px);
}

.control-sidebar-link:hover .ps-label { color: #fff; }
.control-sidebar-link:hover .ps-code {
  background: rgba(232, 181, 71, .14);
  color: var(--ps-gold);
}

/* ─── Active ─── */
.control-sidebar-link.active {
  background: rgba(232, 181, 71, .10);
  border-inline-start-color: var(--ps-gold);
}

.control-sidebar-link.active .ps-label { color: #fff; }
.control-sidebar-link.active .ps-sub  { color: rgba(255, 255, 255, .50); }
.control-sidebar-link.active .ps-code {
  background: var(--ps-gold);
  color: #141a2c;
}

/* ─── Logout ─── */
/* Specificity 0,2,0 beats button:not(.owner-modal-close) at 0,1,1 in internal-unified.css */
.control-sidebar .control-sidebar-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  border: none !important;
  border-top: 1px solid rgba(232, 181, 71, .18) !important;
  border-radius: 0 !important;
  background: linear-gradient(135deg, rgba(232,181,71,.22) 0%, rgba(232,181,71,.14) 100%) !important;
  color: var(--ps-gold) !important;
  font-family: "Tajawal", "Cairo", Arial, sans-serif;
  font-size: 13px;
  font-weight: 900 !important;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.control-sidebar .control-sidebar-logout:hover {
  background: linear-gradient(135deg, rgba(232,181,71,.42) 0%, rgba(232,181,71,.28) 100%) !important;
  color: #fff !important;
}

body.has-control-sidebar .portal-home-link,
body.has-control-sidebar .back-link {
  display: none !important;
}

/* ─── Theme toggle button (أيقونة فقط — تُحقن داخل هيدر كل صفحة) ─── */
.portal-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .30);
  background: rgba(255, 255, 255, .14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  transition: background .16s ease, transform .12s ease, box-shadow .16s ease;
}
.portal-theme-toggle:hover {
  background: rgba(255, 255, 255, .26);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.portal-theme-toggle:active { transform: translateY(0); }
.portal-theme-toggle svg { width: 18px; height: 18px; flex: 0 0 auto; }

/* عند تعذّر إيجاد هيدر — زر عائم أنيق بالركن العلوي */
.portal-theme-toggle.floating {
  position: fixed;
  top: 16px;
  left: 18px;
  z-index: 5000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
}
/* داخل الهيدر: هامش يفصله عن باقي الأزرار */
.portal-theme-toggle.in-header { margin-inline-end: 10px; }

/* عند وضعه داخل رأس قائمة فاتح الخلفية */
html[data-theme="grad"] .portal-theme-toggle.on-light {
  color: #6a55c9; background: #ece9fb; border-color: #d8cff3;
}
html[data-theme="green"] .portal-theme-toggle.on-light {
  color: #2d6a4f; background: #e6f0ea; border-color: #cfe3d6;
}
.portal-theme-toggle.on-light:hover { filter: brightness(.96); }

/* ═══════════════ ① البنفسجي المتدرّج — شريط كحلي إنديغو ═══════════════ */
html[data-theme="grad"] .control-sidebar {
  border-inline-start: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(180deg, #2a3157 0%, #1f2543 60%, #1a1f3a 100%);
  box-shadow: -4px 0 28px rgba(15, 12, 40, .42);
}
html[data-theme="grad"] .control-sidebar-brand {
  border-bottom-color: rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
}
html[data-theme="grad"] .control-sidebar-brand span { color: #b3a6f5; }
html[data-theme="grad"] .control-sidebar-brand small { color: rgba(255, 255, 255, .65); }
html[data-theme="grad"] .control-sidebar-link .ps-code {
  background: rgba(255, 255, 255, .10); color: rgba(255, 255, 255, .80);
}
html[data-theme="grad"] .control-sidebar-link:hover {
  background: rgba(255, 255, 255, .06);
  border-inline-start-color: rgba(108, 92, 231, .6);
}
html[data-theme="grad"] .control-sidebar-link:hover .ps-code {
  background: rgba(108, 92, 231, .35); color: #fff;
}
html[data-theme="grad"] .control-sidebar-link.active {
  background: linear-gradient(135deg, #4d5fe0, #6c5ce7);
  border-inline-start-color: #8b7bf0;
  box-shadow: 0 4px 14px rgba(77, 95, 224, .35);
}
html[data-theme="grad"] .control-sidebar-link.active .ps-label,
html[data-theme="grad"] .control-sidebar-link.active .ps-sub { color: #fff; }
html[data-theme="grad"] .control-sidebar-link.active .ps-code {
  background: rgba(255, 255, 255, .22); color: #fff;
}
html[data-theme="grad"] .control-sidebar .control-sidebar-logout {
  border-top-color: rgba(255, 255, 255, .12) !important;
  background: rgba(255, 255, 255, .08) !important;
  color: #c9bdf7 !important;
}
html[data-theme="grad"] .control-sidebar .control-sidebar-logout:hover {
  background: rgba(108, 92, 231, .26) !important; color: #fff !important;
}

/* ═══════════════ ② الأخضر الهادئ — شريط أخضر داكن ═══════════════ */
html[data-theme="green"] .control-sidebar {
  border-inline-start: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(180deg, #234232 0%, #1a3325 60%, #142a1e 100%);
  box-shadow: -4px 0 28px rgba(10, 30, 20, .40);
}
html[data-theme="green"] .control-sidebar-brand {
  border-bottom-color: rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
}
html[data-theme="green"] .control-sidebar-brand span { color: #b7e0c8; }
html[data-theme="green"] .control-sidebar-brand small { color: rgba(255, 255, 255, .65); }
html[data-theme="green"] .control-sidebar-link .ps-code {
  background: rgba(255, 255, 255, .10); color: rgba(255, 255, 255, .80);
}
html[data-theme="green"] .control-sidebar-link:hover {
  background: rgba(255, 255, 255, .06);
  border-inline-start-color: rgba(64, 145, 108, .6);
}
html[data-theme="green"] .control-sidebar-link:hover .ps-code {
  background: rgba(64, 145, 108, .35); color: #fff;
}
html[data-theme="green"] .control-sidebar-link.active {
  background: linear-gradient(135deg, #2f7a52, #40916c);
  border-inline-start-color: #74c69d;
  box-shadow: 0 4px 14px rgba(47, 122, 82, .35);
}
html[data-theme="green"] .control-sidebar-link.active .ps-label,
html[data-theme="green"] .control-sidebar-link.active .ps-sub { color: #fff; }
html[data-theme="green"] .control-sidebar-link.active .ps-code {
  background: rgba(255, 255, 255, .22); color: #fff;
}
html[data-theme="green"] .control-sidebar .control-sidebar-logout {
  border-top-color: rgba(255, 255, 255, .12) !important;
  background: rgba(255, 255, 255, .08) !important;
  color: #b7e0c8 !important;
}
html[data-theme="green"] .control-sidebar .control-sidebar-logout:hover {
  background: rgba(64, 145, 108, .26) !important; color: #fff !important;
}

/* ─── Responsive: tablet ─── */
@media (max-width: 980px) {
  :root { --ps-w: 72px; }

  .control-sidebar-brand strong,
  .control-sidebar-brand small,
  .control-sidebar-brand span,
  .control-sidebar-link .ps-texts,
  .control-sidebar-logout span {
    display: none;
  }
  .control-sidebar-logo { height: 30px; margin-bottom: 0; }

  .control-sidebar-brand {
    align-items: center;
    padding: 14px 8px;
    min-height: 56px;
  }

  .control-sidebar-link {
    min-height: 48px;
    justify-content: center;
    padding: 8px;
    border-inline-start: none;
    border-radius: 8px;
  }

  .control-sidebar-link.active {
    background: rgba(232, 181, 71, .14);
  }

  .control-sidebar-link .ps-code {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }

  .control-sidebar-nav {
    padding: 10px 8px;
    gap: 4px;
  }
}

/* ─── Responsive: mobile ─── */
@media (max-width: 620px) {
  :root { --ps-w: 0px; }

  body.has-control-sidebar {
    padding-right: 0 !important;
    padding-bottom: 68px !important;
  }

  .control-sidebar {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 60px;
    grid-template-rows: 1fr;
    border-inline-start: none;
    border-top: 1px solid rgba(232, 181, 71, .18);
    box-shadow: 0 -4px 20px rgba(10, 15, 35, .22);
  }

  .control-sidebar-brand,
  .control-sidebar-logout {
    display: none;
  }

  .control-sidebar-nav {
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 6px 8px;
    overflow-x: auto;
    gap: 4px;
    overflow-y: visible;
  }

  .control-sidebar-link {
    min-height: 48px;
    min-width: 48px;
    flex-direction: column;
    justify-content: center;
    padding: 4px 8px;
    gap: 2px;
    border-inline-start: none;
    border-bottom: 2px solid transparent;
    border-radius: 8px;
  }

  .control-sidebar-link.active {
    border-bottom-color: var(--ps-gold);
    background: rgba(232, 181, 71, .12);
  }

  .control-sidebar-link .ps-code {
    width: 28px;
    height: 22px;
    font-size: 10px;
  }

  .control-sidebar-link .ps-texts { display: none; }
}
