/* ============================================
   Layout – Sidebar + Header + Main
   ============================================ */

/* ---- SIDEBAR ---- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--navy-600);
  display: flex;
  flex-direction: column;
  z-index: 110;
  transition: transform 0.3s ease, width 0.3s ease;
}

[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
}

.sidebar-logo {
  height: 88px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.logo-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--navy-600), var(--navy-500));
  border: 2px solid var(--gold-400);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.logo-text { display: flex; flex-direction: column; }
.logo-line1 { color: #fff; font-family: var(--font-heading); font-size: 15px; line-height: 1.3; }
.logo-line2 { color: var(--gold-400); font-family: var(--font-heading); font-size: 15px; line-height: 1.3; }

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 24px 0;
  overflow-y: auto;
}

.nav-label {
  padding: 0 24px;
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 48px;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  transition: all 0.2s ease;
  border-right: 3px solid transparent;
}

[dir="rtl"] .nav-item {
  border-right: none;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(169,129,48,0.1); }

.nav-item.active {
  background: rgba(169,129,48,0.15);
  border-right-color: var(--gold-400);
  color: #fff;
}

[dir="rtl"] .nav-item.active {
  border-right-color: transparent;
  border-left-color: var(--gold-400);
}

.nav-item.active .nav-icon { color: var(--gold-400); }

.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.1);
  margin: 16px 24px;
}

/* Sidebar User */
.sidebar-user { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }
.user-card {
  background: rgba(255,255,255,0.05);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gold-400);
  color: var(--navy-700);
  font-weight: 700;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info { flex: 1; }
.user-name { font-size: 14px; font-weight: 500; color: #fff; }
.user-role { font-size: 12px; color: rgba(255,255,255,0.5); }
.logout-btn {
  color: rgba(255,255,255,0.5);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
}
.logout-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.logout-btn:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

/* ---- HEADER ---- */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease, margin-right 0.3s ease;
}

[dir="rtl"] .main-wrapper {
  margin-left: 0;
  margin-right: var(--sidebar-w);
}

/* Desktop: collapsed rail */
body.sidebar-desktop-collapsed {
  --sidebar-w: var(--sidebar-w-collapsed);
}

body.sidebar-desktop-collapsed .logo-text,
body.sidebar-desktop-collapsed .nav-label {
  opacity: 0;
  visibility: hidden;
  width: 0;
  height: 0;
  overflow: hidden;
  position: absolute;
}

body.sidebar-desktop-collapsed .sidebar-logo {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

body.sidebar-desktop-collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
}

[dir="rtl"] body.sidebar-desktop-collapsed .nav-item {
  border-left-color: transparent;
}

body.sidebar-desktop-collapsed .nav-item > span:not(.nav-icon) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.sidebar-desktop-collapsed .nav-divider {
  margin-left: 12px;
  margin-right: 12px;
}

body.sidebar-desktop-collapsed .user-info {
  display: none;
}

body.sidebar-desktop-collapsed .user-card {
  justify-content: center;
  padding-left: 8px;
  padding-right: 8px;
}

body.sidebar-desktop-collapsed .logout-btn {
  display: none;
}

body.sidebar-desktop-collapsed .sidebar-edge-icon {
  transform: rotate(180deg);
}

[dir="rtl"] body.sidebar-desktop-collapsed .sidebar-edge-icon {
  transform: rotate(0deg);
}

/* Sidebar controls */
.sidebar-mobile-close {
  display: none;
  position: absolute;
  top: 12px;
  /* Logical end: LTR = physical right (toward main content); RTL = physical left — avoids overlapping the logo icon on RTL drawers */
  inset-inline-end: 12px;
  inset-inline-start: auto;
  z-index: 5;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: 28px;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  cursor: pointer;
}

.sidebar-mobile-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-edge-toggle {
  display: none;
  position: absolute;
  top: 50%;
  right: -14px;
  transform: translateY(-50%);
  width: 28px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--navy-600);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-left: none;
  color: var(--gold-400);
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  z-index: 6;
}

[dir="rtl"] .sidebar-edge-toggle {
  right: auto;
  left: -14px;
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  border-right: none;
}

.sidebar-edge-toggle:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 25, 41, 0.45);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

body.sidebar-mobile-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* Header burger */
.header-burger {
  display: none;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  border-radius: var(--r-md);
  color: var(--navy-600);
  background: transparent;
  border: none;
  cursor: pointer;
}

.header-burger:hover {
  background: var(--gray-100);
}

.header-burger:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

.header-burger-box {
  width: 22px;
  height: 16px;
  position: relative;
  display: block;
}

.header-burger-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.25s ease, opacity 0.2s ease, top 0.25s ease;
}

.header-burger-bar:nth-child(1) {
  top: 0;
}

.header-burger-bar:nth-child(2) {
  top: 7px;
}

.header-burger-bar:nth-child(3) {
  top: 14px;
}

body.sidebar-mobile-open .header-burger-bar:nth-child(1) {
  top: 7px;
  transform: rotate(45deg);
}

body.sidebar-mobile-open .header-burger-bar:nth-child(2) {
  opacity: 0;
}

body.sidebar-mobile-open .header-burger-bar:nth-child(3) {
  top: 7px;
  transform: rotate(-45deg);
}

@media (min-width: 1024px) {
  .sidebar-edge-toggle {
    display: flex;
  }

  .sidebar {
    transform: none !important;
  }
}

@media (max-width: 1023px) {
  .sidebar {
    width: min(280px, 88vw);
    transform: translateX(-100%);
  }

  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }

  body.sidebar-mobile-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
  }

  [dir="rtl"] body.sidebar-mobile-open .sidebar {
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.2);
  }

  .main-wrapper {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .sidebar-edge-toggle {
    display: none !important;
  }

  .sidebar-mobile-close {
    display: flex;
  }

  /* Room for the close control on the inner edge (inline-end) without crowding logo / title */
  .sidebar-logo {
    padding-block: 0;
    padding-inline-start: 24px;
    padding-inline-end: 56px;
  }

  .header-burger {
    display: flex;
  }

  .sidebar-overlay {
    display: block;
  }

  .top-header {
    z-index: 120;
  }
}

.top-header {
  position: sticky;
  top: 0;
  min-height: var(--header-h);
  height: auto;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  z-index: 30;
  flex-shrink: 0;
}

/* Navbar: grid keeps title + actions aligned on wide screens; stacks cleanly on small */
.header-inner {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-height: var(--header-h);
  padding: 10px 32px;
  display: grid;
  align-items: center;
  column-gap: 20px;
  row-gap: 12px;
  /* Desktop: title column must not collapse to 0 (minmax(0,1fr) caused vertical letter stacking) */
  grid-template-columns: minmax(14rem, 1fr) auto;
}

.header-burger {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

.header-left {
  min-width: 0;
  grid-column: 1;
  grid-row: 1;
}

.header-right {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
  flex-shrink: 1;
  min-width: 0;
  max-width: 100%;
}

/* When burger is visible it occupies column 1; shift title and actions */
@media (max-width: 1023px) {
  .header-inner {
    grid-template-columns: auto minmax(12rem, 1fr) auto;
    padding: 10px 16px;
  }

  .header-burger {
    grid-column: 1;
    grid-row: 1;
  }

  .header-left {
    grid-column: 2;
    grid-row: 1;
  }

  .header-right {
    grid-column: 3;
    grid-row: 1;
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 8px;
    max-width: 100%;
  }

  .header-right .search-input {
    width: clamp(120px, 28vw, 220px);
    max-width: 100%;
  }
}

/* Small screens: search full width under title row */
@media (max-width: 767px) {
  .header-inner {
    grid-template-columns: auto minmax(10rem, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
  }

  .header-burger {
    grid-column: 1;
    grid-row: 1;
  }

  .header-left {
    grid-column: 2;
    grid-row: 1;
  }

  .header-right {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: stretch;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
  }

  .header-right .search-wrapper {
    order: -1;
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }

  .header-right .search-input {
    width: 100%;
    max-width: 100%;
  }

  /* Navbar profile: show avatar only (hide name + badge) */
  .header-profile {
    padding-left: 8px;
    gap: 0;
  }

  .header-profile > div:last-child {
    display: none;
  }

  [dir="rtl"] .header-profile {
    padding-left: 0;
    padding-right: 8px;
  }
}

/* RTL: mirror navbar columns (text direction unchanged) */
[dir="rtl"] .header-left {
  grid-column: 2;
}

[dir="rtl"] .header-right {
  grid-column: 1;
  justify-self: start;
}

@media (max-width: 1023px) {
  [dir="rtl"] .header-burger {
    grid-column: 3;
  }

  [dir="rtl"] .header-left {
    grid-column: 2;
  }

  [dir="rtl"] .header-right {
    grid-column: 1;
    justify-self: start;
  }
}

@media (max-width: 767px) {
  [dir="rtl"] .header-burger {
    grid-column: 1;
  }

  [dir="rtl"] .header-left {
    grid-column: 2;
  }

  [dir="rtl"] .header-right {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: stretch;
  }
}

.header-title {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 600;
  color: var(--navy-600);
  line-height: 1.25;
  word-wrap: break-word;
}

.header-subtitle { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* Search (allow shrinking so title column is not starved in the navbar grid) */
.search-wrapper {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
[dir="rtl"] .search-icon { left: auto; right: 12px; }
.search-input {
  width: clamp(140px, 22vw, 260px);
  max-width: 100%;
  height: 44px;
  padding-left: 42px;
  padding-right: 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  font-size: 14px;
  color: var(--gray-700);
  transition: all 0.2s;
  outline: none;
}
[dir="rtl"] .search-input { padding-left: 16px; padding-right: 42px; }
.search-input::placeholder { color: var(--gray-400); }
.search-input:focus { border-color: var(--gold-400); box-shadow: 0 0 0 3px rgba(169,129,48,0.1); }

/* Language: globe + dropdown */
.lang-dropdown {
  position: relative;
  flex-shrink: 0;
}

.lang-dropdown-toggle {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--gray-500);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.lang-dropdown-toggle:hover {
  background: var(--gray-100);
  color: var(--navy-600);
}

.lang-dropdown--open .lang-dropdown-toggle {
  color: var(--navy-600);
  border-color: var(--gold-400);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(169, 129, 48, 0.12);
}

.lang-dropdown-toggle:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

.lang-dropdown-globe {
  display: block;
  pointer-events: none;
}

.lang-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  min-width: 11rem;
  max-width: min(11rem, calc(100vw - 16px));
  box-sizing: border-box;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card-hover);
  z-index: 200;
}

.lang-dropdown-option {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 12px;
  min-height: 44px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

[dir="rtl"] .lang-dropdown-option {
  text-align: right;
  justify-content: flex-end;
}

.lang-dropdown-option:hover {
  background: var(--gray-50);
}

.lang-dropdown-option.is-active {
  background: rgba(169, 129, 48, 0.1);
  color: var(--navy-600);
}

.lang-dropdown-option:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 0;
}

/* Notification */
.notif-btn {
  position: relative;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--gray-500);
  transition: background 0.2s;
}
.notif-btn:hover { background: var(--gray-50); }
.notif-btn:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}
.notif-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 8px; height: 8px;
  background: var(--error);
  border-radius: 50%;
  border: 2px solid #fff;
}

/* Profile */
.header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 16px;
  border-left: 1px solid var(--gray-200);
  flex-shrink: 0;
  min-width: 0;
}

.header-profile > div:last-child {
  min-width: 0;
}
[dir="rtl"] .header-profile { padding-left: 0; padding-right: 16px; border-left: none; border-right: 1px solid var(--gray-200); }
.profile-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #D4AF37, #C9A227);
  color: var(--navy-700);
  font-size: 18px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.profile-name { font-size: 14px; font-weight: 500; color: var(--gray-800); }
.profile-badge { font-size: 12px; color: var(--gold-400); display: flex; align-items: center; gap: 4px; }

/* ---- PAGE CONTENT ---- */
.page-content {
  flex: 1;
  padding: 32px;
}

.page { display: none; }
.page.active { display: block; }
