/*
 * Left rail (D-05 Director, A-01 Admin): 236px sage panel, radius 28px, logo card, product row with
 * role pill, pill-shaped nav items (44px, 14px/600, 18px icon), count badges, and a bottom block
 * (Director: user block linking to Profile; Admin: .rail__foot with "View as" above the user
 * block, which links to the Admin's profile).
 * Sticky so it stays in view on long pages. Collapses to icons 768–1023; hidden < 768.
 */
@layer layout {
  .rail {
    position: sticky;
    top: 16px;
    flex: none;
    width: var(--rail-width);
    height: calc(100vh - 32px);
    height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    gap: 30px;
    padding: 24px 14px 16px;
    overflow-y: auto;
    scrollbar-width: none;
    border-radius: var(--radius-card);
    background: var(--color-rail);
    color: var(--color-rail-text);
  }
  .rail::-webkit-scrollbar { display: none; }

  .app--banner .rail {
    top: calc(var(--banner-height) + 16px);
    height: calc(100dvh - var(--banner-height) - 32px);
  }

  .rail__brand {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .rail__logo {
    display: block;
    padding: 10px 12px 8px;
    border-radius: 18px;
    background: var(--color-bg);
  }
  .rail__logo img { width: 100%; height: auto; }

  .rail__product {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-rail-contrast);
  }

  .rail__role {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--color-rail-contrast) 14%, transparent);
    font-size: 11px;
    font-weight: 600;
    color: var(--color-rail-text);
  }

  .rail__nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: var(--radius-pill);
    color: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
  }
  .nav-item:hover {
    background: var(--color-on-rail-hover);
    color: inherit;
  }
  .nav-item.is-active,
  .nav-item[aria-current="page"] {
    background: var(--color-rail-active);
    color: var(--color-rail-active-text);
    font-weight: 700;
    /* Keeps the pill visible on a very light rail. */
    box-shadow: var(--shadow-sm);
  }
  .nav-item:focus-visible { outline-color: var(--color-rail-contrast); }

  .nav-item__icon {
    display: flex;
    flex: none;
    font-size: 18px;
  }

  .nav-item__label { flex: 1; }

  .nav-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-pill);
    background: var(--color-accent-700);
    color: var(--color-bg);
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1;
  }
  .nav-badge--err { background: var(--color-err); }
  /* Credentials that are only expiring (E-13): amber. */
  .nav-badge--warn { background: var(--color-warn); }

  /* Bottom: Director user block */
  .rail__user {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-pill);
    background: var(--color-on-rail-hover);
    color: inherit;
    text-decoration: none;
  }
  .rail__user:hover {
    background: color-mix(in srgb, var(--color-rail-contrast) 14%, transparent);
    color: inherit;
  }
  .rail__user:focus-visible { outline-color: var(--color-rail-contrast); }

  .rail__user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.5;
  }
  .rail__user-name {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--color-rail-contrast);
  }
  .rail__user-sub {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Bottom: Admin "View as Director" */
  .rail__cta {
    margin-top: auto;
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--color-rail-contrast) 12%, transparent);
    color: var(--color-rail-contrast);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
  }
  .rail__cta .icon { font-size: 18px; }
  .rail__cta:hover {
    background: color-mix(in srgb, var(--color-rail-contrast) 18%, transparent);
    color: var(--color-rail-contrast);
  }
  .rail__cta:focus-visible { outline-color: var(--color-rail-contrast); }

  /* Bottom: Admin "View as" with the user block under it. */
  .rail__foot {
    margin-top: auto;
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 10px;
  }
  .rail__foot > .rail__cta,
  .rail__foot > .rail__user { margin-top: 0; }

  /* A short screen (1440 × 900): the Admin rail — twelve items since change request 7, then View as
     and the user block — tightens its gaps so all of it shows without scrolling. */
  @media (min-width: 1024px) and (max-height: 960px) {
    .rail:has(.rail__foot) { gap: 18px; }
    .rail:has(.rail__foot) .nav-item { min-height: 42px; }
  }

  /* Tablet: icon rail */
  @media (min-width: 768px) and (max-width: 1023px) {
    .rail {
      width: var(--rail-width-collapsed);
      gap: 20px;
      padding: 16px 10px;
      align-items: center;
    }

    .rail__brand { display: none; }

    .rail__nav { width: 100%; }

    .nav-item {
      justify-content: center;
      width: 100%;
      min-height: 48px;
      padding: 0;
    }
    .nav-item__label {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
    .nav-item .nav-badge {
      position: absolute;
      top: 4px;
      right: 6px;
      min-width: 18px;
      height: 18px;
      padding: 0 5px;
      font-size: 10.5px;
    }

    .rail__user {
      padding: 6px;
      justify-content: center;
    }
    .rail__user-text { display: none; }

    .rail__cta {
      width: 52px;
      height: 52px;
      padding: 0;
    }

    .rail__foot { align-items: center; }
    .rail__cta-label {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
  }

  @media (max-width: 767px) {
    .rail { display: none; }
  }
}
