/* Shell: sidebar + top bar + main, off-canvas under 960 px, overlays and toasts. */
.app {
  min-height: 100vh;
}
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
}
.sidebar__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--gold-gradient);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: var(--fs-lg);
}
.sidebar__title {
  font-family: var(--font-brand);
  font-size: var(--fs-lg);
  font-weight: 700;
}
.sidebar__subtitle {
  font-size: var(--fs-xs);
  color: var(--text-2);
}
.nav {
  flex: 1;
  padding: var(--sp-2) var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav__item,
.nav__group {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 0 var(--sp-3);
  min-height: 38px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  text-align: start;
  text-decoration: none;
}
.nav__item:hover,
.nav__group:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav__item.is-current {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 700;
}
.nav__item.is-locked {
  color: var(--text-2);
}
.nav__item--child {
  padding-inline-start: 42px;
  min-height: 34px;
  font-size: var(--fs-sm);
}
.nav__group {
  color: var(--text);
  font-weight: 600;
}
.nav__group .nav__chevron {
  margin-inline-start: auto;
  transition: transform 0.15s;
}
.nav__group[aria-expanded='true'] .nav__chevron {
  transform: rotate(90deg);
}
[dir='rtl'] .nav__group .nav__chevron {
  transform: rotate(180deg);
}
[dir='rtl'] .nav__group[aria-expanded='true'] .nav__chevron {
  transform: rotate(90deg);
}
.nav__badge {
  margin-inline-start: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--amber-soft);
  color: var(--amber-text);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-align: center;
}
.nav__lock {
  margin-inline-start: auto;
  color: var(--text-3);
}
.sidebar__footer {
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__search {
  flex: 1;
  max-width: 460px;
  position: relative;
}
.topbar__search .icon {
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.topbar__search .input {
  padding-inline-start: 38px;
  height: var(--control-h-sm);
}
.topbar__spacer {
  flex: 1;
}
.topbar__actions {
  display: flex;
  gap: var(--sp-2);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text-2);
}
/* Tone pills follow the status-chip rule: dot in the tone colour, label in --text (AA). */
.pill--amber,
.pill--green {
  color: var(--text);
}
.pill--amber::before,
.pill--green::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tone);
}
.pill--amber {
  --tone: var(--amber);
  background: var(--amber-soft);
}
.pill--green {
  --tone: var(--green);
  background: var(--green-soft);
}
.menu {
  position: relative;
}
.menu__panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  min-width: 260px;
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  z-index: 30;
}
.menu__header {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-2);
}
.menu__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 38px;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  text-align: start;
}
.menu__item:hover {
  background: var(--surface-2);
}
.menu__section {
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-text);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--fs-sm);
}
.page {
  padding: var(--sp-5);
  max-width: 1440px;
  width: 100%;
}
.page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.page__header > .row:last-child {
  margin-inline-start: auto;
  flex-wrap: wrap;
}
.page__header .row {
  flex-wrap: wrap;
}
.page__subtitle {
  color: var(--text-2);
  margin-top: var(--sp-1);
}
.scrim-nav {
  display: none;
}
.sidebar-toggle {
  display: none;
}
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(var(--sidebar-w), 86vw);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  [dir='rtl'] .sidebar {
    transform: translateX(100%);
  }
  .layout.nav-open .sidebar {
    transform: none;
  }
  .layout.nav-open .scrim-nav {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 35;
  }
  .sidebar-toggle {
    display: inline-flex;
  }
  .topbar {
    padding: 0 var(--sp-3);
  }
  .topbar__search {
    max-width: none;
    min-width: 0;
  }
  .topbar {
    gap: var(--sp-2);
  }
  .topbar__actions .button span,
  .topbar .pill {
    display: none;
  }
  .topbar__actions .button {
    padding: 0 10px;
  }
  .page {
    padding: var(--sp-4);
  }
}
/* Overlays */
.overlay-root {
  display: none;
}
.overlay-root.is-open {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 50;
}
.scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}
.dialog,
.drawer {
  position: absolute;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2 * var(--sp-5));
}
.dialog {
  inset-inline-start: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 2 * var(--sp-4)));
  border-radius: var(--r-xl);
}
[dir='rtl'] .dialog {
  transform: translate(50%, -50%);
}
.dialog--sm {
  width: min(460px, calc(100vw - 2 * var(--sp-4)));
}
.dialog--lg {
  width: min(720px, calc(100vw - 2 * var(--sp-4)));
}
.drawer {
  inset-block: 0;
  inset-inline-end: 0;
  width: min(640px, 100vw);
  max-height: none;
}
.dialog__header,
.drawer__header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.dialog__title,
.drawer__title {
  font-size: var(--fs-xl);
  font-weight: 700;
}
.dialog--danger .dialog__title {
  color: var(--red);
}
.dialog__body,
.drawer__body {
  padding: var(--sp-5);
  overflow: auto;
}
.dialog__text {
  color: var(--text-2);
}
.dialog__footer,
.drawer__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
/* Toasts */
.toast-root {
  position: fixed;
  bottom: var(--sp-5);
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
  z-index: 60;
}
/* Keep toasts clear of the editor's fixed save bar so its buttons stay clickable. */
body:has(.save-bar) .toast-root {
  bottom: calc(var(--sp-5) + 72px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: min(520px, calc(100vw - 2 * var(--sp-4)));
  /* A long word (a code, a URL) must wrap, not push the page sideways on a phone. */
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 10px 12px 10px 14px;
  border-radius: var(--r-md);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-3);
  animation: toastIn 0.18s ease-out;
}
.toast__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
}
.toast--success .toast__dot {
  background: var(--green);
}
.toast--warning .toast__dot {
  background: var(--amber);
}
.toast--error .toast__dot {
  background: var(--red);
}
.toast__action {
  border: 0;
  background: transparent;
  color: #e1b85f;
  font-weight: 700;
}
.toast__close {
  border: 0;
  background: transparent;
  color: var(--toast-text);
  font-size: var(--fs-lg);
  line-height: 1;
  opacity: 0.7;
}

/* Global search results (top bar). */
.topbar__search {
  position: relative;
}
.search-results {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 50;
  margin: 0;
  padding: var(--sp-1);
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md, 0 8px 24px rgba(0, 0, 0, 0.12));
  max-height: 60vh;
  overflow: auto;
}
.search-results__item {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
}
.search-results__item[aria-selected='true'],
.search-results__item:hover {
  background: var(--surface-2);
}
.search-results__empty {
  padding: var(--sp-2) var(--sp-3);
}
