/* sidebar.css — Single Source of Truth */

:root {
    --sb-w: 280px;
    --sb-bg: #ffffff;
    --sb-border: #E5EAE4;

    /* Text slightly darker for better readability */
    --sb-text: #1f2b2d;
    --sb-muted: #5e6c70;

    --sb-active1: #00843D;
    --sb-active2: #FFC400;
}

/* ===== App container ===== */
.app {
    display: flex !important;
    min-height: 100vh;
    flex-direction: row !important;
}

/* MAIN should flex */
.main {
    flex: 1;
    min-width: 0;
}

/* ===== Sidebar base (compact icon+label rail) ===== */
.sidebar {
    width: 230px;
    background: var(--sb-bg);
    padding: 18px 14px;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    order: 0 !important;
}

/* ===== Brand clickable wrapper ===== */
.sidebar .brand-link {
    display: block;
    color: inherit;
    text-decoration: none;
    border-radius: 14px;
}

/* Brand focus (keyboard) */
.sidebar .brand-link:focus {
    outline: none;
}

.sidebar .brand-link:focus-visible {
    outline: 2px solid rgba(255, 196, 0, .55);
    outline-offset: 3px;
}

/* Sidebar internals */
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 16px;
}

.sidebar .brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: #F2F4F1;
    border: 1px solid var(--sb-border);
    flex: none;
}

.sidebar .brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: filter 0.3s ease;
    /* تنعيم التحول */
}

.sidebar .brand-title {
    font-weight: 700;
    color: var(--sb-text);
    line-height: 1.1;
}

.sidebar .brand-sub {
    font-size: 12px;
    color: var(--sb-muted);
    margin-top: 2px;
}

/* ===== Menu (icon+label rail items, no group labels) ===== */
.sidebar .menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    padding: 8px 0 18px;
}

.sidebar .menu-label {
    display: none;
}

.sidebar .menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--sb-muted);
    padding: 11px 14px;
    border-radius: 13px;
    border: 1px solid transparent;
    transition: background .15s ease, color .15s ease;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.2;
}

.sidebar .menu a:hover {
    background: var(--sb-hover, rgba(0, 132, 61, .08));
    color: var(--sb-text);
}

/* ✅ Focus for keyboard navigation */
.sidebar .menu a:focus {
    outline: none;
}

.sidebar .menu a:focus-visible {
    outline: 2px solid var(--sb-active1);
    outline-offset: 3px;
}

.sidebar .menu a .menu-icon {
    width: 18px;
    display: inline-flex;
    justify-content: center;
    font-size: 15px;
}

/* Active */
.sidebar .menu a.active {
    color: #fff;
    background: var(--sb-active1);
    font-weight: 800;
}

.sidebar .menu a.active .menu-icon {
    color: #fff;
}

/* Active hover stays consistent */
.sidebar .menu a.active:hover {
    background: var(--sb-active1);
}

.sidebar .menu a.active:focus-visible {
    outline: 2px solid rgba(255, 255, 255, .55);
    outline-offset: 3px;
}

/* ===== Bottom dark-mode toggle button ===== */
.sidebar .rail-toggle-theme {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 13px;
    background: var(--sb-hover, #F6F8F6);
    color: var(--sb-text);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 700;
    border: none;
    width: 100%;
    text-align: start;
    font-family: inherit;
}

.sidebar .rail-toggle-theme:hover {
    background: var(--sb-border);
}

/* ===== Borders Handling Based on Direction ===== */

/* ARABIC (RTL): Border on Left */
html[dir="rtl"] .sidebar {
    border-left: 1px solid var(--sb-border) !important;
    border-right: none !important;
}

/* ENGLISH (LTR): Border on Right */
html[dir="ltr"] .sidebar {
    border-right: 1px solid var(--sb-border) !important;
    border-left: none !important;
}

/* Optional: Scrollbar styling */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #d7dde8;
    border-radius: 999px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}


/* =========================
   DARK MODE (Sidebar only)
   Activate by: <html class="dark">
   - Logo turns white using filter
========================= */

html.dark {
    --sb-bg: #161A15;
    --sb-border: rgba(255, 255, 255, .10);
    --sb-text: rgba(243, 244, 246, .96);
    --sb-muted: rgba(156, 163, 175, .95);
    --sb-active1: #2FBE72;
    --sb-active2: #FFD23F;
    --sb-hover: rgba(47, 190, 114, .12);
}

/* Sidebar base surface */
html.dark .sidebar {
    background: var(--sb-bg);
}

/* Brand area */
html.dark .sidebar .brand {
    border-bottom-color: var(--sb-border);
}

html.dark .sidebar .brand-logo {
    background: rgba(255, 255, 255, .04);
    border-color: var(--sb-border);
}

/* ✅ NEW: Turn Logo White in Dark Mode */
html.dark .sidebar .brand-logo img {
    filter: brightness(0) invert(1);
}

html.dark .sidebar .brand-title {
    color: var(--sb-text);
}

html.dark .sidebar .brand-sub {
    color: var(--sb-muted);
}

/* Hover: tuned for dark readability */
html.dark .sidebar .menu a:hover {
    background: var(--sb-hover);
    color: var(--sb-text);
}

/* Focus visible: same behavior, tuned slightly */
html.dark .sidebar .menu a:focus-visible {
    outline-color: var(--sb-active1);
}

/* Active: keep shadow consistent */
html.dark .sidebar .menu a.active {
    box-shadow: 0 14px 34px rgba(0, 0, 0, .35);
}

html.dark .sidebar .rail-toggle-theme {
    background: rgba(255, 255, 255, .05);
    color: var(--sb-text);
}

html.dark .sidebar .rail-toggle-theme:hover {
    background: rgba(255, 255, 255, .09);
}

/* Borders by direction in dark */
html.dark[dir="rtl"] .sidebar {
    border-left-color: var(--sb-border) !important;
}

html.dark[dir="ltr"] .sidebar {
    border-right-color: var(--sb-border) !important;
}

/* Scrollbar in dark */
html.dark .sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .18);
}

html.dark .sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, .26);
}

html.dark .sidebar::-webkit-scrollbar-track {
    background: transparent;
}

/* ===========================================================
   Grouped navigation — built to the approved design canvas.
   Text-only items on a dark green rail, gold leading bar on the
   active item, count badges (red when urgent).
   =========================================================== */
.sidebar {
  background: #013B22;
  color: #EAF3ED;
  padding: 18px 12px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* --- Brand --- */
.sidebar .brand-link {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 20px; text-decoration: none; color: inherit;
}
.sidebar .brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  background: #FFC400; color: #013B22;
  display: grid; place-items: center; overflow: hidden;
  font-family: 'Cairo', system-ui, sans-serif; font-weight: 900; font-size: 17px;
}
.sidebar .brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.sidebar .brand-text { display: grid; gap: 1px; min-width: 0; }
.sidebar .brand-name {
  font-family: 'Cairo', system-ui, sans-serif;
  font-weight: 700; font-size: 16px; line-height: 1.1; color: #EAF3ED;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar .brand-sub { font-size: 11px; color: #8FB6A1; letter-spacing: .04em; }

/* --- Groups --- */
.sidebar .menu { display: block; }
.menu-group { margin-bottom: 20px; }
.menu-group-label {
  font-size: 11px; font-weight: 600; letter-spacing: .09em;
  color: #7EA791; padding: 0 12px 8px;
}

/* --- Items --- */
.sidebar .menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 10px; margin-bottom: 2px;
  font-size: 14px; font-weight: 500; line-height: 1.4;
  color: #CBDFD3; text-decoration: none; cursor: pointer;
  border-inline-start: 3px solid transparent;
  transition: background .15s ease, color .15s ease;
}
.sidebar .menu-item:hover { background: rgba(255, 255, 255, .10); color: #EAF3ED; }
.sidebar .menu-item.active {
  background: rgba(255, 196, 0, .16);
  color: #FFD966;
  border-inline-start-color: #FFC400;
  font-weight: 600;
}
.sidebar .menu-item:focus-visible { outline: 2px solid #FFC400; outline-offset: -2px; }
.menu-item-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Badges --- */
.menu-badge {
  min-width: 22px; text-align: center; padding: 1px 7px;
  border-radius: 20px; font-size: 11px; font-weight: 700;
  background: rgba(255, 255, 255, .14); color: #D6E7DC;
  flex: 0 0 auto; font-variant-numeric: tabular-nums;
}
.menu-badge.urgent { background: #CD2A3E; color: #fff; }

/* --- Foot --- */
.sidebar-foot {
  margin-top: auto; padding: 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  font-size: 12px; color: #A9C9B7; line-height: 1.6;
}

.rail-toggle-theme {
  margin-top: 10px; background: transparent; border: 0;
  color: #8FB6A1; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer; width: 100%;
  text-align: start; border-radius: 10px; font: inherit; font-size: 13px;
}
.rail-toggle-theme:hover { background: rgba(255, 255, 255, .08); color: #EAF3ED; }
