/* Physical shell defaults — English LTR puts sidebar on the LEFT.
   Arabic RTL overrides move sidebar to the RIGHT (see below). */

.app-shell {
  min-height: 100vh;
  position: relative;
}

.app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--brand-900) 0%, var(--brand-950) 55%, #041a17 100%);
  color: var(--color-text-inverse);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  transition: width var(--transition), transform var(--transition), left var(--transition), right var(--transition);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3) 0 var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  height: var(--topbar-height);
  flex-shrink: 0;
}

.app-sidebar__mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--brand-500), var(--brand-700));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.02em;
  color: #fff;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.app-sidebar__brand-text {
  min-width: 0;
  flex: 1;
}

.app-sidebar__brand-text strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar__brand-text span {
  display: block;
  font-size: 11px;
  color: var(--color-text-sidebar);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar__collapse {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-sidebar);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
}

.app-sidebar__collapse:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.app-sidebar__nav {
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-2);
  flex: 1;
  scrollbar-gutter: stable;
}

.nav-section {
  margin-bottom: 2px;
}

.nav-section__btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: 0;
  color: var(--color-text-sidebar);
  padding: 9px 10px;
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
  text-align: inherit;
  min-height: 40px;
}

.nav-section__btn:hover,
.nav-section.is-open > .nav-section__btn {
  background: var(--color-bg-sidebar-hover);
  color: #fff;
}

.nav-item__icon,
.nav-section__icon {
  width: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0.9;
}

.nav-item__label,
.nav-section__btn-label {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: start;
}

.nav-item__meta,
.nav-section__meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-inline-start: auto;
}

.nav-section__chevron,
.nav-item__chevron {
  font-size: 10px;
  opacity: 0.7;
  transition: transform var(--transition);
  width: 14px;
  text-align: center;
}

.nav-section.is-open .nav-section__chevron {
  transform: rotate(180deg);
}

.nav-section__links {
  display: none;
  padding: 2px 0 6px 0;
}

.nav-section.is-open .nav-section__links {
  display: block;
}

.nav-section__links a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-sidebar);
  padding: 8px 10px 8px 34px;
  border-radius: 8px;
  margin-bottom: 1px;
  font-size: 12.5px;
  position: relative;
  border: 0;
}

.nav-section__links a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-section__links a.is-active {
  background: var(--color-bg-sidebar-active);
  color: #fff;
  font-weight: 600;
}

/* Active indicator on the content-facing edge of the sidebar */
.nav-section__links a.is-active::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: 0;
  left: auto;
  width: 3px;
  border-radius: 3px 0 0 3px;
  background: var(--accent-orange);
}

/* Arabic RTL: sidebar on the right → indicator on the LEFT edge */
html[dir="rtl"] .nav-section__links a.is-active::after,
body[dir="rtl"] .nav-section__links a.is-active::after {
  left: 0;
  right: auto;
  border-radius: 0 3px 3px 0;
}

.app-sidebar__footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--color-text-sidebar);
  flex-shrink: 0;
}

/* ========== Shell offsets: LTR left / RTL right ========== */

/* English LTR — sidebar LEFT */
.app-sidebar {
  left: 0;
  right: auto;
}

.app-main {
  margin-left: var(--sidebar-width);
  margin-right: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition), margin-right var(--transition);
  padding-top: var(--topbar-height);
}

.app-header {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  z-index: var(--z-header);
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(180px, 1.4fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--page-padding);
  background: var(--color-bg-header);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  transition: left var(--transition), right var(--transition);
}

/* Arabic RTL — sidebar RIGHT */
html[dir="rtl"] .app-sidebar,
body[dir="rtl"] .app-sidebar {
  right: 0;
  left: auto;
}

html[dir="rtl"] .app-main,
body[dir="rtl"] .app-main {
  margin-right: var(--sidebar-width);
  margin-left: 0;
}

html[dir="rtl"] .app-header,
body[dir="rtl"] .app-header {
  right: var(--sidebar-width);
  left: 0;
}

.app-header__start,
.app-header__center,
.app-header__end {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.app-header__start { justify-content: flex-start; }
.app-header__center { justify-content: center; }
.app-header__end { justify-content: flex-end; }

.breadcrumb {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
  color: var(--color-text-secondary);
  font-size: 12.5px;
  overflow: hidden;
  white-space: nowrap;
}

.breadcrumb a { color: var(--color-text-secondary); }
.breadcrumb .sep { opacity: 0.45; }
.breadcrumb .current {
  color: var(--color-text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(420px, 100%);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.topbar-search input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 13px;
}

.topbar-select {
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-elevated);
  padding: 0 10px;
  font-size: 12.5px;
  max-width: 160px;
}

.app-content {
  padding: var(--page-padding);
  animation: fade-up 220ms ease;
  flex: 1;
  max-width: var(--page-max-width);
  width: 100%;
  margin-inline: auto;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 47, 43, 0.42);
  z-index: var(--z-overlay);
}

body.sidebar-open .sidebar-overlay {
  display: block;
}

/* Collapsed desktop sidebar */
body.sidebar-collapsed .app-sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .app-main {
  margin-left: var(--sidebar-collapsed-width);
  margin-right: 0;
}

body.sidebar-collapsed .app-header {
  left: var(--sidebar-collapsed-width);
  right: 0;
}

html[dir="rtl"] body.sidebar-collapsed .app-main,
body[dir="rtl"].sidebar-collapsed .app-main {
  margin-right: var(--sidebar-collapsed-width);
  margin-left: 0;
}

html[dir="rtl"] body.sidebar-collapsed .app-header,
body[dir="rtl"].sidebar-collapsed .app-header {
  right: var(--sidebar-collapsed-width);
  left: 0;
}

body.sidebar-collapsed .app-sidebar__brand-text,
body.sidebar-collapsed .app-sidebar__footer,
body.sidebar-collapsed .nav-section__btn-label,
body.sidebar-collapsed .nav-section__meta,
body.sidebar-collapsed .nav-section__links,
body.sidebar-collapsed .app-sidebar__collapse-label {
  display: none;
}

body.sidebar-collapsed .nav-section__btn {
  justify-content: center;
  padding: 10px;
}

body.sidebar-collapsed .nav-section__icon {
  margin: 0;
}

body.sidebar-collapsed .app-sidebar__brand {
  justify-content: center;
  padding: 0;
}

.user-menu {
  position: relative;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 4px 8px 4px 4px;
  height: 38px;
}

.user-chip__avatar {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
}

.user-chip__meta strong {
  display: block;
  font-size: 12.5px;
  line-height: 1.2;
}

.user-menu__dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: var(--z-dropdown);
  padding: 6px;
}

.user-menu.is-open .user-menu__dropdown {
  display: block;
}

.user-menu__dropdown a,
.user-menu__dropdown button {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--color-text);
}

.user-menu__dropdown a:hover,
.user-menu__dropdown button:hover {
  background: var(--surface-muted);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background:
    linear-gradient(135deg, rgba(6, 47, 43, 0.94), rgba(15, 103, 90, 0.78)),
    var(--brand-950);
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-7);
  animation: fade-up 280ms ease;
  border: 1px solid var(--border);
}

.login-card__brand {
  text-align: center;
  margin-bottom: var(--space-6);
}

.login-card__brand .mark {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-3);
  border-radius: 12px;
  background: linear-gradient(145deg, var(--brand-600), var(--brand-800));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 700;
}

/* Collapsed tooltip */
.nav-section__btn[data-tooltip] {
  position: relative;
}

body.sidebar-collapsed .nav-section__btn:hover::before {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  background: var(--brand-900);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 80;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

html[dir="rtl"] body.sidebar-collapsed .nav-section__btn:hover::before,
body[dir="rtl"].sidebar-collapsed .nav-section__btn:hover::before {
  right: calc(100% + 10px);
  left: auto;
}
