/* Portal shell: light sidebar on the page ground, quiet top bar, scrolling content, footer line.
   Phones: the sidebar becomes a menu and a bottom bar carries the main actions. */

.t-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  background: var(--color-bg);
}

/* ---------- Sidebar ---------- */
.t-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  border-right: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  min-width: 0;
}

.t-sidebar__brand {
  padding: 0 var(--space-2) var(--space-3);
}

.t-sidebar__brand .t-brand__eyebrow {
  color: var(--color-sidebar-muted);
  opacity: 1;
}

.t-sidebar__brand .t-brand__name {
  color: var(--color-sidebar-text);
}

.t-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0;
}

.t-sidebar__bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.t-credits {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-sidebar-raised);
}

.t-credits__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.t-credits__head .t-icon {
  width: 18px;
  height: 18px;
}

.t-credits__value {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--color-sidebar-text);
}

.t-credits .t-progress {
  background: var(--color-surface-muted);
}

.t-credits__link {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--brand-accent);
  text-decoration: none;
}

.t-credits__link:hover {
  text-decoration: underline;
}

.t-sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2) 0;
}

.t-sidebar__user .t-avatar {
  background: var(--color-deep);
  color: var(--color-deep-text);
}

.t-sidebar__user-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.t-sidebar__user-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t-sidebar__user-mail {
  font-size: var(--font-size-xs);
  color: var(--color-sidebar-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t-sidebar__user .t-badge {
  align-self: flex-start;
  margin-top: 2px;
}

.t-sidebar__user form {
  display: contents;
}

.t-sidebar__signout {
  color: var(--color-sidebar-muted);
}

.t-sidebar__signout:hover {
  background: var(--color-surface-muted);
  color: var(--color-sidebar-text);
}

/* ---------- Body, top bar, footer ---------- */
.t-shell__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.t-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--topbar-height);
  padding: var(--space-3) var(--space-8);
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
}

.t-topbar__start {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.t-topbar__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.t-topbar__title {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t-topbar__title {
  display: none;
}

.t-topbar__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.t-nav-toggle {
  display: none;
}

.t-main {
  flex: 1;
  padding: var(--space-2) var(--space-8) var(--space-8);
  width: 100%;
}

.t-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-8);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.t-footer .t-icon {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

/* ---------- Bottom bar (phones only) ---------- */
.t-bottomnav {
  display: none;
}

/* ---------- Small screens: sidebar becomes a menu, bottom bar carries the main actions ---------- */
@media (max-width: 900px) {
  .t-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .t-sidebar {
    position: fixed;
    inset: var(--topbar-height) 0 0 0;
    z-index: 20;
    height: auto;
    display: none;
    border-right: 0;
    padding-bottom: calc(var(--bottomnav-height) + var(--space-5));
  }

  .t-shell--nav-open .t-sidebar {
    display: flex;
  }

  .t-topbar {
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-border);
  }

  .t-main {
    padding: var(--space-4) var(--space-4) calc(var(--bottomnav-height) + var(--space-6));
  }

  .t-footer {
    padding: var(--space-4) var(--space-4) calc(var(--bottomnav-height) + var(--space-4));
  }

  .t-nav-toggle {
    display: inline-flex;
  }

  .t-topbar__title {
    display: block;
  }

  .t-topbar__heading .t-breadcrumbs {
    display: none;
  }

  .t-shell--has-bottomnav .t-footer {
    display: none;
  }

  .t-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
    min-height: var(--bottomnav-height);
    padding: var(--space-2) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
  }

  .t-bottomnav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 48px;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--color-text-muted);
    text-decoration: none;
  }

  .t-bottomnav__item .t-icon {
    width: 22px;
    height: 22px;
  }

  .t-bottomnav__item[aria-current="page"] {
    color: var(--brand-accent);
    font-weight: 600;
  }

  .t-bottomnav__action {
    justify-self: center;
    width: 60px;
    height: 60px;
    margin-top: -28px;
    border-radius: 20px;
    background: var(--brand-accent);
    color: var(--color-on-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-accent);
  }

  .t-bottomnav__action:hover {
    color: var(--color-on-accent);
    background: color-mix(in srgb, var(--brand-accent) 86%, black);
  }

  .t-bottomnav__action[aria-current="page"] {
    box-shadow: 0 0 0 4px var(--color-surface), 0 0 0 6px var(--brand-accent);
  }

  .t-bottomnav__action .t-icon {
    width: 26px;
    height: 26px;
  }
}
