/* The application shell: sidebar, top bar, page area, the phone drawer and the sign-in page frame (design boards "Part: Sidebar", "Part: Top bar", "Phone screens").
   Logical properties only (inline-start, inset-inline), so the same rules serve Arabic (right to left) and English. */
.skip-link {
  position: absolute;
  inset-inline-start: 8px;
  top: -64px;
  z-index: 2000;
  padding: 10px 14px;
  background: var(--s1);
  color: var(--brt);
  border: 2px solid var(--ring);
  border-radius: var(--r2);
  font-weight: 600;
}
.skip-link:focus { top: 8px; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
html[data-sidebar="collapsed"] .shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.shell-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--s1);
  border-inline-end: 1px solid var(--bd);
  z-index: 1030;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--topbar-h);
  padding-inline: 16px;
  border-bottom: 1px solid var(--bd);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--tx); text-decoration: none; font-weight: 700; font-size: .9375rem; }
.brand:hover { color: var(--tx); }
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--r2);
  border: 1.5px dashed var(--bd2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--tx3);
  flex: none;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 12px 8px; }
.nav-group + .nav-group { margin-top: 2px; }
.nav-group-title { font-size: .72rem; font-weight: 600; color: var(--tx2); padding: 14px 12px 6px; letter-spacing: .04em; }
html[dir="rtl"] .nav-group-title { letter-spacing: 0; font-size: .78rem; }
.nav-i {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ctl-h);
  padding: 0 12px;
  border-radius: var(--r2);
  color: var(--tx2);
  font-weight: 500;
  text-decoration: none;
  border: 0;
  background: transparent;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  text-align: start;
  cursor: pointer;
  transition: background .15s;
}
.nav-i:hover { background: var(--s3); color: var(--tx); }
.nav-i.on { background: var(--brs); color: var(--brt); font-weight: 600; }
.nav-i .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot { flex: none; padding: 8px 12px 12px; border-top: 1px solid var(--bd); display: flex; flex-direction: column; gap: 4px; }
.sidebar-note { margin: 0; font-size: .75rem; color: var(--tx2); padding: 4px 12px; }
.nav-collapse .icon-expand { display: none; }
html[data-sidebar="collapsed"] .nav-collapse .icon-collapse { display: none; }
html[data-sidebar="collapsed"] .nav-collapse .icon-expand { display: inline; }
.drawer-close, .drawer-open { display: none; }

html[data-sidebar="collapsed"] .brand-name,
html[data-sidebar="collapsed"] .nav-label,
html[data-sidebar="collapsed"] .nav-group-title,
html[data-sidebar="collapsed"] .sidebar-note { display: none; }
html[data-sidebar="collapsed"] .sidebar-brand { padding-inline: 20px; }
html[data-sidebar="collapsed"] .nav-i { justify-content: center; padding: 0; }
html[data-sidebar="collapsed"] .nav-group + .nav-group { border-top: 1px solid var(--bd); margin-top: 8px; padding-top: 8px; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding-inline: 24px;
  background: var(--s1);
  border-bottom: 1px solid var(--bd);
}
.crumbs { min-width: 0; flex: 1; }
.crumbs ol { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0; list-style: none; color: var(--tx2); font-size: .875rem; min-width: 0; }
.crumbs li { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; }
.crumbs li + li::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M9 6l6 6-6 6'/%3e%3c/svg%3e") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M9 6l6 6-6 6'/%3e%3c/svg%3e") center / contain no-repeat;
  opacity: .7;
}
html[dir="rtl"] .crumbs li + li::before { transform: scaleX(-1); }
.crumbs a { color: var(--tx2); text-decoration: none; display: inline-flex; align-items: center; }
.crumbs a:hover { color: var(--tx); }
.crumbs .crumb-current, .crumbs .crumb-current a { color: var(--tx); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-tools { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.btn-icon { width: var(--ctl-h); padding: 0; }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }

.seg { display: inline-flex; border: 1px solid var(--bd2); border-radius: var(--r2); overflow: hidden; background: var(--s1); }
.seg-item {
  min-height: calc(var(--ctl-h) - 2px);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--tx2);
  font: inherit;
  font-weight: 600;
  font-size: .8125rem;
  cursor: pointer;
}
button.seg-item:hover { background: var(--s3); color: var(--tx); }
.seg-item.on { background: var(--brs); color: var(--brt); cursor: default; }

.user-btn { display: inline-flex; align-items: center; gap: 8px; min-height: var(--ctl-h); padding: 0 8px; border: 0; border-radius: var(--r2); background: transparent; color: var(--tx); font: inherit; font-weight: 600; cursor: pointer; }
.user-btn:hover { background: var(--s3); }
.avatar { width: 36px; height: 36px; border-radius: 999px; background: var(--brs); color: var(--brt); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8125rem; flex: none; }
.user-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Page area ---- */
.page { flex: 1; padding: 28px 32px; min-width: 0; width: 100%; max-width: 1480px; }
.page-footer { padding: 14px 32px; color: var(--tx2); font-size: .78rem; border-top: 1px solid var(--bd); }

/* The page header pattern: title and one line of help on one side, the page actions on the other. */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-header .lead { margin: 4px 0 0; color: var(--tx2); font-size: .875rem; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---- Phones and tablets: the sidebar becomes a drawer ---- */
.drawer-backdrop { display: none; }
@media (max-width: 991.98px) {
  .shell, html[data-sidebar="collapsed"] .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--sh2);
    visibility: hidden;
  }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  body.drawer-open .sidebar { transform: none; visibility: visible; }
  body.drawer-open { overflow: hidden; }
  .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(var(--bg-rgb), .6); z-index: 1025; opacity: 0; pointer-events: none; transition: opacity .2s; }
  [data-theme="dark"] .drawer-backdrop { background: rgba(0, 0, 0, .6); }
  body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  .drawer-open, .drawer-close { display: inline-flex; }
  .nav-collapse { display: none; }
  /* The collapsed (icons only) state is for wide screens: in the drawer everything is shown. */
  html[data-sidebar="collapsed"] .brand-name,
  html[data-sidebar="collapsed"] .nav-label,
  html[data-sidebar="collapsed"] .nav-group-title,
  html[data-sidebar="collapsed"] .sidebar-note { display: revert; }
  html[data-sidebar="collapsed"] .nav-i { justify-content: flex-start; padding: 0 12px; }
  html[data-sidebar="collapsed"] .sidebar-brand { padding-inline: 16px; }
  .topbar { padding-inline: 12px; gap: 8px; }
  .user-name { display: none; }
  .page { padding: 20px 16px; }
  .page-footer { padding: 14px 16px; }
}
@media (max-width: 575.98px) {
  .crumbs ol .crumb-group { display: none; }
  .seg-item { padding: 0 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-backdrop, .nav-i { transition: none; }
}

/* ---- Sign-in pages ---- */
.login-body { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; }
.login-main { flex: 1; width: 100%; max-width: 480px; margin-inline: auto; padding: 16px 16px 40px; display: flex; flex-direction: column; justify-content: flex-start; }
.login-card { padding: 0; }
.login-card .card-body { padding: 32px; }
.login-title { font-size: 1.5rem; margin: 0 0 16px; }
.login-note { text-align: center; color: var(--tx2); font-size: .78rem; margin-top: 16px; }
@media (max-width: 575.98px) {
  .login-top { padding: 12px 16px; }
  .login-card .card-body { padding: 24px 20px; }
}

/* On a phone the top bar keeps only the current page name; the rest of the trail is in the drawer. */
@media (max-width: 575.98px) {
  .crumbs ol li:not(:last-child) { display: none; }
  .crumbs ol li:last-child::before { content: none; }
  .crumbs .crumb-current, .crumbs .crumb-current a { max-width: 100%; }
}

/* Phone top bar: the page name has priority. Only the button that switches language stays (the current language is shown by the page itself). */
@media (max-width: 575.98px) {
  .lang-switch .seg-item.on { display: none; }
  .crumbs { flex: 1 1 0; min-width: 0; }
  .crumbs ol li:last-child { min-width: 0; }
  .crumbs ol li:last-child a, .crumbs ol li:last-child { overflow: hidden; text-overflow: ellipsis; }
  .topbar-tools { gap: 4px; }
}

/* On a short screen the menu rows get tighter so the last group (Administration) is visible without scrolling; the list still scrolls when it must. */
@media (min-width: 992px) and (max-height: 980px) {
  .sidebar-nav .nav-i { min-height: 33px; }
  .nav-group-title { padding-top: 10px; padding-bottom: 4px; }
  .sidebar-note { display: none; }
}
