/* The shell: sidebar, working panel and topbar. See base.css for the order. */

/* ---- Shell: sidebar + working panel (DESIGN_SYSTEM §2) ----------------- */

.shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  display: none;
}

.workspace {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  background: var(--background);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3.5rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--background);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* minmax(0, 1fr): a wide table scrolls inside its card instead of
   stretching the page past the screen. */
.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 1.5rem;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 0.5rem;
}

.brand-tile {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: calc(var(--radius) - 2px);
  background: var(--brand-orange);
  color: var(--brand-orange-foreground);
  font-size: 0.75rem;
  font-weight: 600;
}

.brand-name {
  font-weight: 600;
}

.nav {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-heading {
  padding: 0 0.625rem 0.375rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  height: 2.25rem;
  padding: 0 0.625rem;
  border-radius: calc(var(--radius) - 2px);
  transition: background-color 0.15s;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  background: var(--sidebar-accent);
}

.nav-link[aria-current="page"] {
  font-weight: 500;
  box-shadow: var(--shadow-xs);
}

/* ---- Phone: brand tile in the topbar, tab bar along the bottom ---------- */

.topbar-brand {
  flex-shrink: 0;
}

/* The unread count, over the bell's corner. */
.bell {
  position: relative;
}

.count-badge {
  position: absolute;
  top: 0.125rem;
  right: 0.125rem;
  display: grid;
  place-items: center;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--danger);
  color: var(--destructive-foreground);
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1;
}

.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 20;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  padding: 0.25rem max(0.25rem, env(safe-area-inset-right))
    max(0.25rem, env(safe-area-inset-bottom))
    max(0.25rem, env(safe-area-inset-left));
  border-top: 1px solid var(--hairline);
  background: var(--background);
}

.tabbar-item {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.125rem;
  min-width: 0;
  min-height: 3rem;
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--muted-foreground);
  font: inherit;
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
}

.tabbar-item > span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The current tab: a pill behind its icon as well as the colour, so it is
   not marked by colour alone. */
.tabbar-item > .icon {
  width: 2.75rem;
  height: 1.75rem;
  padding: 0.25rem 0.875rem;
  border-radius: 999px;
  transition: background-color 0.15s;
}

.tabbar-item:is([aria-current="page"], [data-current]) {
  color: var(--foreground);
}

.tabbar-item:is([aria-current="page"], [data-current]) > .icon {
  background: var(--accent);
  color: var(--primary);
}

/* "More" opens upwards, lined up with the bar's right edge. */
@supports (position-area: block-end) {
  .tabbar .dropdown {
    position-area: block-start span-inline-start;
  }
}

/* Room under the last thing on a page, so the bar never covers it, and
   focus never stops behind it. */
.page {
  padding-bottom: calc(5rem + env(safe-area-inset-bottom));
}

html {
  scroll-padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
}

/* Error messages appear above the bar, not under it. */
.status {
  bottom: calc(4.5rem + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  .tabbar,
  .topbar-brand {
    display: none;
  }

  html {
    scroll-padding-bottom: 0;
  }

  .status {
    bottom: 1rem;
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 16rem;
    height: 100dvh;
    flex-shrink: 0;
    padding: 1rem 0.75rem;
  }

  .workspace {
    margin: 0.5rem 0.5rem 0.5rem 0;
    border: 1px solid var(--hairline);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow-xs);
  }

  .topbar {
    padding: 0 1.5rem;
    border-radius: calc(var(--radius) + 4px) calc(var(--radius) + 4px) 0 0;
  }

  .page {
    padding: 1.5rem;
  }
}
