:host {
  --admin-sidebar-width: 280px;
  --admin-sidebar-width-collapsed: 72px;
  --admin-topbar-height: 72px;
  display: block;
  height: 100vh;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.admin-layout__skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-md);
  z-index: 1000;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);

  &:focus {
    top: var(--space-sm);
  }
}

.admin-layout {
  display: grid;
  grid-template-columns: var(--admin-sidebar-width) 1fr;
  grid-template-rows: var(--admin-topbar-height) 1fr;
  grid-template-areas:
    'sidebar topbar'
    'sidebar content';
  height: 100vh;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.admin-layout__backdrop {
  position: fixed;
  inset: 0;
  /* Neutral modal/drawer scrim - intentionally not a themed token (Elevation
     section covers floating surfaces, not the dimming layer behind them);
     stays black-alpha regardless of tenant theme like the rest of the app's
     overlay scrims. */
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
  display: none;
}

/* ---------- Sidebar ---------- */

.admin-layout__sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  z-index: 40;
}

.admin-layout__brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  text-decoration: none;
  color: var(--text-primary);
  font-weight: var(--font-weight-bold, 700);
  border-bottom: 1px solid var(--border-color);
}

.admin-layout__brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--gradient-primary);
  color: #fff;
  flex-shrink: 0;
}

.admin-layout__nav-list {
  list-style: none;
  margin: 0;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-layout__nav-list--bottom {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding-top: var(--space-sm);
}

.admin-layout__nav-group {
  padding: var(--space-md) var(--space-sm) var(--space-xs);
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-semibold, 600);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-light);
}

.admin-layout__nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--font-size-lg, 1rem);
  text-align: left;
  text-decoration: none;
  cursor: pointer;

  .pi {
    font-size: var(--font-size-lg, 1rem);
    width: 1.2rem;
    flex-shrink: 0;
  }

  &:hover {
    background: color-mix(in srgb, var(--primary-color) 8%, transparent);
    color: var(--primary-color);
  }

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }

  &--active {
    background: color-mix(in srgb, var(--primary-color) 8%, transparent);
    color: var(--primary-color);
    font-weight: var(--font-weight-semibold, 600);
  }

  &--disabled {
    color: var(--text-light);
    cursor: not-allowed;

    &:hover {
      background: none;
      color: var(--text-light);
    }
  }
}

.admin-layout__soon-badge {
  margin-left: auto;
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-semibold, 600);
  padding: 2px 8px;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--primary-color) 8%, transparent);
  color: var(--primary-color);
  border: 1px solid color-mix(in srgb, var(--primary-color) 20%, transparent);
}

/* ---------- Topbar ---------- */

.admin-layout__topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}

.admin-layout__menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

.admin-layout__heading {
  min-width: 0;
  flex: 1;
  padding: var(--space-sm) 0;
}

.admin-layout__breadcrumb {
  ol {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    margin: 0 0 2px;
    padding: 0;
    font-size: var(--font-size-xs, 0.75rem);
    color: var(--text-light);
  }

  li {
    display: flex;
    align-items: center;
  }

  a {
    color: var(--text-light);
    text-decoration: none;

    &:hover {
      color: var(--primary-color);
      text-decoration: underline;
    }

    &:focus-visible {
      outline: 2px solid var(--primary-color);
      outline-offset: 2px;
    }
  }

  [aria-current='page'] {
    color: var(--text-secondary);
  }
}

.admin-layout__breadcrumb-sep {
  margin: 0 var(--space-xs);
}

.admin-layout__title {
  margin: 0;
  font-size: var(--font-size-xl, 1.125rem);
  font-weight: var(--font-weight-semibold, 600);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-layout__description {
  margin: 2px 0 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-layout__topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.admin-layout__search {
  position: relative;
  display: none;

  input {
    width: 220px;
    padding: 10px 12px 10px 32px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-field, var(--radius-sm));
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: var(--font-size-lg, 1rem);

    &:focus-visible {
      outline: 2px solid var(--primary-color);
      outline-offset: 1px;
    }
  }
}

.admin-layout__search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: var(--font-size-lg, 1rem);
}

.admin-layout__icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;

  &:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
  }

  &:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
}

.admin-layout__notifications {
  position: relative;
}

.admin-layout__notifications-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger, #ef4444);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

.admin-layout__notifications-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 240px;
  max-height: 60vh;
  overflow-y: auto;
  padding: var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-lg, 1rem);
  color: var(--text-secondary);
  z-index: 25;

  p {
    margin: 0;
  }
}

.admin-layout__notification-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm, 4px);
}

.admin-layout__notification-item:hover {
  background: var(--bg-secondary, #f4f6f5);
}

.admin-layout__notification-order { font-weight: var(--font-weight-medium, 500); }
.admin-layout__notification-customer { color: var(--text-secondary, #6b7280); font-size: var(--font-size-sm, 0.8125rem); }
.admin-layout__notification-amount { font-size: var(--font-size-sm, 0.8125rem); }

.admin-layout__account {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding-left: var(--space-sm);
  border-left: 1px solid var(--border-color);
}

.admin-layout__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-bold, 700);
  flex-shrink: 0;
}

.admin-layout__account-name {
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-semibold, 600);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: none;
}

/* ---------- Content / inspector ---------- */

.admin-layout__content {
  grid-area: content;
  overflow-y: auto;
  padding: var(--space-lg);

  &:focus-visible {
    outline: none;
  }
}

.admin-layout__inspector {
  display: none;
  width: 0;
}

/* ---------- Responsive ---------- */

@media (min-width: 640px) {
  .admin-layout__search {
    display: block;
  }

  .admin-layout__account-name {
    display: block;
  }
}

/* Tablet: icon-only rail */
@media (max-width: 1023px) and (min-width: 768px) {
  /* Doubled selector: deliberate specificity bump so this reliably wins over
     the base .admin-layout grid-template-columns declaration regardless of
     the two rules' relative order after the build's CSS bundling pass. */
  .admin-layout.admin-layout {
    grid-template-columns: var(--admin-sidebar-width-collapsed) 1fr;
  }

  .admin-layout__brand-name,
  .admin-layout__nav-label,
  .admin-layout__soon-badge {
    display: none;
  }

  .admin-layout__brand {
    justify-content: center;
  }

  .admin-layout__nav-link {
    justify-content: center;
  }
}

/* Mobile: drawer */
@media (max-width: 767px) {
  .admin-layout.admin-layout {
    grid-template-columns: 0 1fr;
  }

  .admin-layout__menu-toggle {
    display: inline-flex;
  }

  .admin-layout__sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--admin-sidebar-width), 84vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }

  .admin-layout--drawer-open {
    .admin-layout__sidebar {
      transform: translateX(0);
    }

    .admin-layout__backdrop {
      display: block;
    }
  }

  .admin-layout__title,
  .admin-layout__description {
    max-width: 55vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .admin-layout__sidebar {
    transition: none;
  }
}

@media (prefers-color-scheme: dark) {
  .admin-layout__backdrop {
    /* Same neutral-scrim exception as the light-mode rule above, just darker. */
    background: rgba(0, 0, 0, 0.6);
  }
}

/* Print: only the page content matters - hide navigation chrome so
   browser print / save-as-PDF produces a clean document (orders,
   transactions, analytics). */
@media print {
  .admin-layout__sidebar,
  .admin-layout__topbar,
  .admin-layout__inspector {
    display: none !important;
  }
  .admin-layout {
    display: block !important;
  }
}
