/* ==========================================================================
   TrainerPlatform - Application Shell
   --------------------------------------------------------------------------
   Mobile-first responsive chrome, implemented entirely in CSS.

     < 64rem (mobile/tablet) : sticky top bar + fixed bottom navigation
     >= 64rem (desktop)      : persistent left sidebar + content top bar

   There is no JavaScript and no collapse state to manage: the breakpoint
   alone decides which navigation affordance is present, so the layout is
   correct on first paint during static server rendering.
   ========================================================================== */

.tp-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-areas:
    "topbar"
    "main";
  grid-template-rows: auto 1fr;
  background: var(--tp-bg-canvas);
}

/* ======================================================================
   TOP BAR
   ====================================================================== */
.tp-topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: var(--tp-z-sticky);
  display: flex;
  align-items: center;
  gap: var(--tp-space-3);
  min-height: var(--tp-topbar-height);
  padding-inline: var(--tp-space-4);
  background: color-mix(in srgb, var(--tp-bg-surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--tp-border-thin) solid var(--tp-border-subtle);
}

.tp-topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--tp-space-2);
  font-weight: var(--tp-weight-bold);
  font-size: var(--tp-text-lg);
  letter-spacing: var(--tp-tracking-snug);
  color: var(--tp-text-primary);
  text-decoration: none;
}

.tp-topbar__title {
  font-size: var(--tp-text-base);
  font-weight: var(--tp-weight-semibold);
  color: var(--tp-text-primary);
  min-width: 0;
}

.tp-topbar__spacer { flex: 1 1 auto; }

.tp-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--tp-space-2);
}

/* The brand belongs in the sidebar once the sidebar exists. */
@media (min-width: 64rem) {
  .tp-topbar__brand { display: none; }
}

/* ======================================================================
   BRAND MARK
   ====================================================================== */
.tp-brandmark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  border-radius: var(--tp-radius-md);
  background: linear-gradient(135deg, var(--tp-primary-500), var(--tp-primary-700));
  color: #fff;
  font-weight: var(--tp-weight-bold);
  font-size: var(--tp-text-sm);
  letter-spacing: 0;
  box-shadow: var(--tp-shadow-sm);
}

/* ======================================================================
   SIDEBAR - desktop only
   ====================================================================== */
.tp-sidebar { display: none; }

@media (min-width: 64rem) {
  .tp-shell {
    grid-template-areas:
      "sidebar topbar"
      "sidebar main";
    grid-template-columns: var(--tp-sidebar-width) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }

  .tp-sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    z-index: var(--tp-z-sidebar);
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: var(--tp-space-4) var(--tp-space-3);
    background: var(--tp-bg-surface);
    border-right: var(--tp-border-thin) solid var(--tp-border-subtle);
  }
}

.tp-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--tp-space-3);
  padding: var(--tp-space-2);
  margin-bottom: var(--tp-space-5);
  border-radius: var(--tp-radius-md);
  color: var(--tp-text-primary);
  text-decoration: none;
}

.tp-sidebar__brand:hover { background: var(--tp-bg-hover); color: var(--tp-text-primary); }

.tp-sidebar__wordmark {
  display: flex;
  flex-direction: column;
  line-height: var(--tp-leading-none);
  min-width: 0;
}

.tp-sidebar__wordmark-name {
  font-weight: var(--tp-weight-bold);
  font-size: var(--tp-text-base);
  letter-spacing: var(--tp-tracking-snug);
}

.tp-sidebar__wordmark-sub {
  margin-top: 0.2rem;
  font-size: var(--tp-text-2xs);
  letter-spacing: var(--tp-tracking-caps);
  text-transform: uppercase;
  color: var(--tp-text-muted);
}

.tp-sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--tp-space-1);
  /* Bleed the scroll container to the panel edge without clipping focus rings. */
  margin-inline: calc(var(--tp-space-1) * -1);
  padding-inline: var(--tp-space-1);
}

.tp-sidebar__footer {
  flex: 0 0 auto;
  padding-top: var(--tp-space-3);
  margin-top: var(--tp-space-3);
  border-top: var(--tp-border-thin) solid var(--tp-border-subtle);
}

/* Section grouping inside the sidebar */
.tp-nav-section { display: contents; }

.tp-nav-section__label {
  padding: var(--tp-space-4) var(--tp-space-3) var(--tp-space-1);
  font-size: var(--tp-text-2xs);
  font-weight: var(--tp-weight-semibold);
  letter-spacing: var(--tp-tracking-caps);
  text-transform: uppercase;
  color: var(--tp-text-muted);
}

.tp-nav-section__label:first-child { padding-top: 0; }

/* ======================================================================
   SIDEBAR NAV LINK
   ====================================================================== */
.tp-nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--tp-space-3);
  padding: var(--tp-space-3);
  border-radius: var(--tp-radius-md);
  color: var(--tp-text-secondary);
  font-size: var(--tp-text-sm);
  font-weight: var(--tp-weight-medium);
  text-decoration: none;
  transition:
    background-color var(--tp-duration-fast) var(--tp-ease-standard),
    color var(--tp-duration-fast) var(--tp-ease-standard);
}

.tp-nav-link:hover {
  background: var(--tp-bg-hover);
  color: var(--tp-text-primary);
}

.tp-nav-link__icon {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  color: currentColor;
}

.tp-nav-link__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tp-nav-link__trailing { margin-left: auto; flex: 0 0 auto; }

/* Blazor applies `active` to a matching NavLink. */
.tp-nav-link.active {
  background: var(--tp-brand-subtle);
  color: var(--tp-brand-on-subtle);
  font-weight: var(--tp-weight-semibold);
}

/* Active rail marker */
.tp-nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  translate: -0.55rem -50%;
  width: 3px;
  height: 1.25rem;
  border-radius: var(--tp-radius-pill);
  background: var(--tp-brand);
}

/* ======================================================================
   MAIN CONTENT
   ====================================================================== */
.tp-shell__main {
  grid-area: main;
  min-width: 0;
  padding: var(--tp-space-5) var(--tp-space-4);
  /* Clear the fixed bottom navigation, including the iOS home indicator. */
  padding-bottom: calc(
    var(--tp-bottomnav-height) + var(--tp-space-6) + env(safe-area-inset-bottom, 0px)
  );
}

@media (min-width: 64rem) {
  .tp-shell__main {
    padding: var(--tp-space-6);
    padding-bottom: var(--tp-space-8);
  }
}

.tp-container {
  width: 100%;
  max-width: var(--tp-content-max);
  margin-inline: auto;
}

/* ======================================================================
   BOTTOM NAVIGATION - mobile only
   ====================================================================== */
.tp-bottom-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--tp-z-bottomnav);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: var(--tp-space-1);
  padding: var(--tp-space-1) var(--tp-space-2);
  padding-bottom: calc(var(--tp-space-1) + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--tp-bg-surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: var(--tp-border-thin) solid var(--tp-border-subtle);
}

@media (min-width: 64rem) {
  .tp-bottom-nav { display: none; }
}

.tp-bottom-nav__link {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  /* 44px minimum touch target. */
  min-height: 2.75rem;
  padding: var(--tp-space-1) var(--tp-space-1);
  border-radius: var(--tp-radius-md);
  color: var(--tp-text-muted);
  font-size: var(--tp-text-2xs);
  font-weight: var(--tp-weight-medium);
  text-decoration: none;
  text-align: center;
  transition: color var(--tp-duration-fast) var(--tp-ease-standard);
  -webkit-tap-highlight-color: transparent;
}

.tp-bottom-nav__link:hover { color: var(--tp-text-secondary); }

.tp-bottom-nav__icon {
  width: 1.5rem;
  height: 1.5rem;
  flex: 0 0 auto;
}

.tp-bottom-nav__text {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: var(--tp-tracking-normal);
}

.tp-bottom-nav__link.active {
  color: var(--tp-brand);
  font-weight: var(--tp-weight-semibold);
}

/* Active pill behind the icon */
.tp-bottom-nav__link.active .tp-bottom-nav__icon-wrap {
  background: var(--tp-brand-subtle);
}

.tp-bottom-nav__icon-wrap {
  display: grid;
  place-items: center;
  padding: 0.2rem 0.75rem;
  border-radius: var(--tp-radius-pill);
  transition: background-color var(--tp-duration-base) var(--tp-ease-standard);
}

/* ======================================================================
   PAGE HEADER
   ====================================================================== */
.tp-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--tp-space-4);
  margin-bottom: var(--tp-space-5);
}

.tp-page-header__text { flex: 1 1 20rem; min-width: 0; }

.tp-page-header__description {
  margin-top: var(--tp-space-2);
  color: var(--tp-text-secondary);
  font-size: var(--tp-text-sm);
  max-width: var(--tp-measure);
  text-wrap: pretty;
}

.tp-page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tp-space-2);
  margin-left: auto;
}
