/* ==========================================================================
   Shell: sidebar, top bar, viewport, page header, tabs
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns var(--dur-3) var(--ease);
}

.shell.nav-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
}

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

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line-1);
  overflow: hidden;
  z-index: 20;
}

.sb-top {
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 4px 0 6px;
}

.sb-mark {
  width: 22px;
  height: 22px;
  color: var(--fg-1);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.sb-mark svg {
  width: 22px;
  height: 22px;
}

.sb-word {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.sb-word-tag {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--fg-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xs);
  padding: 1px 4px;
  margin-left: 2px;
  text-transform: uppercase;
}

.sb-brand .icon-btn {
  margin-left: auto;
}

.sb-account {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-1);
  box-shadow: var(--highlight);
  min-width: 0;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.sb-account.switchable {
  cursor: pointer;
}

.sb-account.switchable:hover {
  border-color: var(--line-3);
  background: var(--surface-2);
}

.sb-account-avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  background: var(--inv-bg);
  color: var(--inv-fg);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.sb-account-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.sb-account-meta b {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-account-meta span {
  font-size: 11px;
  color: var(--fg-3);
  white-space: nowrap;
}

.sb-account-caret {
  margin-left: auto;
  color: var(--fg-3);
}

.account-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  padding: 4px;
  z-index: 40;
}

.account-menu[hidden] {
  display: none;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--fg-2);
  text-align: left;
}

.account-item:hover {
  background: var(--surface-4);
  color: var(--fg-1);
}

.account-item.active {
  color: var(--fg-1);
}

.account-item.active::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-1);
  margin-left: auto;
}

.sb-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-group {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-4);
  padding: 16px 10px 6px;
  white-space: nowrap;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-md);
  color: var(--fg-2);
  font-size: 13.5px;
  font-weight: 450;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.nav-item .nav-ic {
  width: 16px;
  height: 16px;
  color: var(--fg-3);
  transition: color var(--dur-1) var(--ease);
}

.nav-item:hover {
  background: var(--surface-3);
  color: var(--fg-1);
}

.nav-item:hover .nav-ic {
  color: var(--fg-2);
}

.nav-item.active {
  background: var(--surface-4);
  color: var(--fg-1);
  font-weight: 500;
}

.nav-item.active .nav-ic {
  color: var(--fg-1);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--fg-1);
}

.nav-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.nav-count.hot {
  color: var(--inv-fg);
  background: var(--inv-bg);
  border-radius: var(--r-xs);
  padding: 1px 5px;
  font-weight: 500;
}

.nav-count:empty,
.nav-count[data-zero="true"] {
  display: none;
}

.sb-foot {
  border-top: 1px solid var(--line-1);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
}

.sb-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-user {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: var(--r-md);
  min-width: 0;
  text-align: left;
  width: 100%;
  transition: background var(--dur-1) var(--ease);
}

.sb-user:hover {
  background: var(--surface-3);
}

.sb-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.sb-user-meta b {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-user-meta span {
  font-size: 11px;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% - 4px);
  background: var(--surface-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  padding: 4px;
  z-index: 40;
}

.user-menu[hidden] {
  display: none;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  color: var(--fg-2);
  font-size: 13px;
  text-align: left;
}

.menu-item:hover {
  background: var(--surface-4);
  color: var(--fg-1);
}

.menu-item .kbd {
  margin-left: auto;
}

.menu-sep {
  height: 1px;
  background: var(--line-1);
  margin: 4px 2px;
}

/* Collapsed rail */
.shell.nav-collapsed .sb-word,
.shell.nav-collapsed .sb-word-tag,
.shell.nav-collapsed .sb-account-meta,
.shell.nav-collapsed .sb-account-caret,
.shell.nav-collapsed .nav-text,
.shell.nav-collapsed .nav-group,
.shell.nav-collapsed .sb-status-text,
.shell.nav-collapsed .sb-user-meta {
  display: none;
}

.shell.nav-collapsed .sb-brand {
  flex-direction: column;
  height: auto;
  gap: 10px;
  padding: 0;
}

.shell.nav-collapsed .sb-brand .icon-btn {
  margin-left: 0;
}

.shell.nav-collapsed .sb-account {
  justify-content: center;
  padding: 7px 0;
}

.shell.nav-collapsed .nav-item {
  justify-content: center;
  padding: 0;
}

.shell.nav-collapsed .nav-count {
  position: absolute;
  top: 5px;
  right: 7px;
  width: 6px;
  height: 6px;
  padding: 0;
  font-size: 0;
  border-radius: 50%;
  background: var(--fg-3);
}

.shell.nav-collapsed .nav-count.hot {
  background: var(--fg-1);
}

.shell.nav-collapsed .sb-status,
.shell.nav-collapsed .sb-user {
  justify-content: center;
}

.shell.nav-collapsed .nav-group + .nav-item {
  margin-top: 12px;
}

/* --- Main column --------------------------------------------------------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  position: relative;
  z-index: 15;
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line-1);
  background: color-mix(in srgb, var(--canvas) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  color: var(--fg-3);
  white-space: nowrap;
}

.crumbs i {
  font-style: normal;
  color: var(--fg-4);
}

.crumbs b {
  color: var(--fg-1);
  font-weight: 500;
}

.crumbs button {
  color: var(--fg-3);
}

.crumbs button:hover {
  color: var(--fg-1);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-1);
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--fg-3);
  white-space: nowrap;
}

.live-pill b {
  color: var(--fg-1);
  font-weight: 500;
}

.search-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  min-width: 220px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--fg-3);
  font-size: 13px;
  transition: border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.search-btn:hover {
  border-color: var(--line-3);
  color: var(--fg-2);
}

.search-btn .kbd {
  margin-left: auto;
}

.viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: auto;
}

#app {
  min-height: 100%;
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 28px var(--gutter) 64px;
  animation: page-in var(--dur-3) var(--ease) both;
}

.page.no-anim {
  animation: none;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- Page header --------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-end;
  gap: var(--s-6);
  margin-bottom: var(--s-6);
}

.page-head-main {
  flex: 1 1 auto;
  min-width: 0;
}

.page-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.page-eyebrow .sq {
  width: 6px;
  height: 6px;
  background: var(--fg-1);
}

.page-title {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.page-lede {
  margin-top: 8px;
  color: var(--fg-2);
  font-size: var(--fs-md);
  max-width: 760px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.page-tabs {
  display: flex;
  align-items: stretch;
  gap: 22px;
  border-bottom: 1px solid var(--line-1);
  margin: -8px 0 var(--s-6);
  overflow-x: auto;
  overflow-y: hidden;
}

.page-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  font-size: 13.5px;
  color: var(--fg-3);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease);
}

.page-tab:hover {
  color: var(--fg-1);
}

.page-tab.active {
  color: var(--fg-1);
  font-weight: 500;
}

.page-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.5px;
  background: var(--fg-1);
}

.page-tab .tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
}

/* --- Boot loader ---------------------------------------------------------- */

.boot {
  min-height: calc(100vh - var(--topbar-h));
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  color: var(--fg-3);
}

.boot-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.boot-mark {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line-3);
  transform: rotate(22.5deg);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  background: var(--surface-3);
  animation: boot-spin 2.4s var(--ease-in-out) infinite;
}

@keyframes boot-spin {
  50% {
    transform: rotate(202.5deg);
    background: var(--surface-5);
  }
  100% {
    transform: rotate(382.5deg);
  }
}

body.loading-data .topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--fg-1), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: route-progress 1.1s var(--ease-in-out) infinite;
}

@keyframes route-progress {
  from {
    background-position: -40% 0;
  }
  to {
    background-position: 140% 0;
  }
}

@media (max-width: 900px) {
  :root {
    --gutter: 16px;
  }

  .shell,
  .shell.nav-collapsed {
    grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
  }

  .shell .sb-word,
  .shell .sb-word-tag,
  .shell .sb-account-meta,
  .shell .sb-account-caret,
  .shell .nav-text,
  .shell .nav-group,
  .shell .sb-status-text,
  .shell .sb-user-meta,
  .live-pill,
  .search-btn .search-label {
    display: none;
  }

  .shell .nav-item {
    justify-content: center;
    padding: 0;
  }

  .shell .sb-brand {
    justify-content: center;
    padding: 0;
  }

  .shell .sb-brand .icon-btn {
    display: none;
  }

  .shell .sb-account {
    justify-content: center;
    padding: 7px 0;
  }

  .shell .sb-status,
  .shell .sb-user {
    justify-content: center;
  }

  .shell .nav-count {
    position: absolute;
    top: 5px;
    right: 7px;
    width: 6px;
    height: 6px;
    padding: 0;
    font-size: 0;
    border-radius: 50%;
    background: var(--fg-3);
  }

  .search-btn {
    min-width: 0;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* --- Pages turned off for the account (operators still see them) --------- */

.nav-hidden-mark {
  display: none;
  margin-left: auto;
  color: var(--fg-4);
}

.nav-item.is-hidden .nav-text,
.nav-item.is-hidden .nav-ic {
  opacity: 0.45;
}

.nav-item.is-hidden .nav-hidden-mark {
  display: inline-flex;
}

.nav-item.is-hidden .nav-count {
  display: none;
}

.shell.nav-collapsed .nav-hidden-mark {
  display: none;
}

.page-tab.is-hidden {
  color: var(--fg-4);
}

.page-tab.is-hidden svg {
  margin-right: 5px;
  vertical-align: -1px;
}

/* Phones: the breadcrumb gives way to the actions instead of running under them. */
@media (max-width: 600px) {
  .crumbs {
    overflow: hidden;
    flex: 1 1 auto;
  }

  .crumbs > *:not(:last-child) {
    display: none;
  }

  .crumbs b {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
