/* Top institutional header, platform brand/logo and counselor scope pill.
   Layer: layout. */
@layer layout {
  /* Top Institutional Utility Header */
  .top-header {
    background-color: var(--color-navy);
    color: var(--ds-color-text-inverse);
    border-bottom: 2px solid var(--ds-navy-900);
  }

  .header-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--ds-space-65) var(--ds-space-150);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .header-brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-85);
  }

  .header-logo {
    height: 38px;
    background: var(--ds-color-surface);
    padding: var(--ds-space-2px) var(--ds-space-6px);
    border-radius: var(--radius-xs);
  }

  .header-title-block h1 {
    font-size: var(--ds-font-size-115);
    font-weight: var(--ds-font-weight-bold);
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--ds-color-text-inverse);
  }

  .header-title-block p {
    font-size: var(--ds-font-size-80);
    color: var(--ds-slate-300-alt);
    font-weight: var(--ds-font-weight-regular);
  }

  .nav-tabs {
    display: flex;
    align-items: center;
    gap: var(--ds-space-25);
    margin-left: var(--ds-space-200);
  }

  .nav-tab {
    color: var(--ds-slate-300-alt6);
    padding: var(--ds-space-50) var(--ds-space-90);
    font-size: var(--ds-font-size-88);
    font-weight: var(--ds-font-weight-medium);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-40);
  }

  .nav-tab:hover {
    background-color: var(--ds-white-a10);
    color: var(--ds-color-text-inverse);
    text-decoration: none;
  }

  .nav-tab.active {
    background-color: var(--ds-navy-950);
    color: var(--ds-color-text-inverse);
    font-weight: var(--ds-font-weight-semibold);
    border-bottom: 2px solid var(--ds-academy-400);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }

  .header-user-section {
    display: flex;
    align-items: center;
    gap: var(--ds-space-125);
  }

  .user-status {
    text-align: right;
    line-height: 1.2;
  }

  .user-status-name {
    font-size: var(--ds-font-size-88);
    font-weight: var(--ds-font-weight-semibold);
    color: var(--ds-color-text-inverse);
  }

  /* the name opens the Account page; looks like plain text until hovered */
  .user-status-name__link {
    color: inherit;
    text-decoration: none;
  }

  .user-status-name__link:hover,
  .user-status-name__link:focus-visible {
    text-decoration: underline;
  }

  .user-status-role {
    font-size: var(--ds-font-size-75);
    color: var(--ds-slate-300-alt);
  }

  .btn-signout {
    color: var(--ds-slate-300-alt6);
    font-size: var(--ds-font-size-82);
    padding: var(--ds-space-35) var(--ds-space-75);
    border: 1px solid var(--ds-white-a25);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    line-height: inherit;  /* a <button> since sign-out is a POST: same height as the links beside it */
  }

  .app-header__signout {
    display: inline-flex;
    margin: 0;
  }

  .btn-signout:hover {
    background: var(--ds-white-a12);
    color: var(--ds-color-text-inverse);
    text-decoration: none;
  }

  /* Help button (opens the in-app guide at the current page's article) */
  .btn-help {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-40);
    color: var(--ds-slate-300-alt6);
    font-size: var(--ds-font-size-82);
    padding: var(--ds-space-35) var(--ds-space-60);
    border-radius: var(--radius-sm);
  }

  .btn-help:hover {
    background: var(--ds-white-a12);
    color: var(--ds-color-text-inverse);
    text-decoration: none;
  }

  /* Account (own sign-in methods), styled like Help */
  .btn-account {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-40);
    color: var(--ds-slate-300-alt6);
    font-size: var(--ds-font-size-82);
    padding: var(--ds-space-35) var(--ds-space-60);
    border-radius: var(--radius-sm);
  }

  .btn-account:hover,
  .btn-account--active {
    background: var(--ds-white-a12);
    color: var(--ds-color-text-inverse);
    text-decoration: none;
  }

  .btn-account__icon {
    width: 16px;
    height: 16px;
  }

  .btn-help__icon {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    font-size: var(--ds-font-size-75);
    font-weight: var(--ds-font-weight-bold);
    border: 1.5px solid currentColor;
    border-radius: 50%;
  }

  /* Header Counselor Scope Pill */
  .counselor-scope-pill {
    font-size: var(--ds-font-size-76);
    color: var(--text-dim);
    font-weight: var(--ds-font-weight-medium);
  }

  .counselor-scope-pill.unassigned {
    color: var(--ds-red-700-alt);
    font-weight: var(--ds-font-weight-semibold);
  }

  .header-platform-brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-85);
  }

  .platform-logo-img {
    width: 38px;
    height: 38px;
    border-radius: var(--ds-radius-10px);
    object-fit: contain;
    box-shadow: 0 2px 8px var(--ds-teal-600-a35);
    flex-shrink: 0;
  }

  /* Dyyno Platform Brand & Logo */
  .header-platform-brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-85);
  }

  .platform-logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: var(--ds-radius-9px);
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--ds-black-a20);
    transition: var(--ds-transition-transform-200-ease);
  }

  .platform-logo-img:hover {
    transform: scale(1.05);
  }

  /* Laptops: keep every label on one line. Long names are cut with an ellipsis (full text in the
     tooltip or on the Account page) and the least important text goes first as the window narrows. */
  .header-brand,
  .header-title-block,
  .user-status {
    min-width: 0;
  }

  @media (min-width: 961px) {
    .header-title-block h1,
    .header-title-block p,
    .user-status-name,
    .user-status-role {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .header-title-block h1 {
      max-width: 18rem;
    }

    .user-status-name {
      max-width: 14rem;
    }
  }

  .nav-tab,
  .btn-signout,
  .btn-help,
  .btn-account {
    white-space: nowrap;
    flex-shrink: 0;
  }

  @media (max-width: 1360px) and (min-width: 961px) {
    .header-container {
      padding-left: var(--ds-space-100);
      padding-right: var(--ds-space-100);
      gap: var(--ds-space-75);
    }

    .header-title-block p {
      display: none; /* the tagline is the first thing to go */
    }

    .nav-tabs {
      margin-left: var(--ds-space-100);
    }

    .nav-tab {
      padding: var(--ds-space-50) var(--ds-space-65);
    }

    .header-user-section {
      gap: var(--ds-space-50);
    }

    .header-title-block h1 {
      max-width: 13rem;
    }

    .user-status-name {
      max-width: 11rem;
    }
  }

  @media (max-width: 1200px) and (min-width: 961px) {
    .btn-account__label,
    .btn-help__label {
      display: none; /* icon only; both links keep their aria-label */
    }

    .header-title-block h1 {
      max-width: 10rem;
    }

    .user-status-name {
      max-width: 9rem;
    }
  }

  @media (max-width: 960px) {
    .header-container {
      padding: var(--ds-space-75) var(--ds-space-100);
      flex-wrap: wrap;
      gap: var(--ds-space-75);
    }

    .header-brand {
      width: 100%;
      justify-content: space-between;
      flex-wrap: wrap;
    }

    .nav-tabs {
      margin-left: 0;
      width: 100%;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      padding-bottom: var(--ds-space-4px);
      gap: var(--ds-space-35);
    }

    .header-user-section {
      width: 100%;
      justify-content: space-between;
      padding-top: var(--ds-space-50);
      border-top: 1px solid var(--ds-white-a10);
    }
  }

  @media (max-width: 768px) {
    /* Phones: wrap the tabs onto a second row so every section (Teachers, Settings ...)
       stays visible instead of hiding off-screen in a sideways-scrolling strip. */
    .nav-tabs {
      flex-wrap: wrap;
      overflow-x: visible;
    }

    /* Nav Tab Touch Target Optimization */
    .nav-tab {
      min-height: 44px;
      padding: var(--ds-space-50) var(--ds-space-100);
      font-size: var(--ds-font-size-92);
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
    }

    .btn-signout {
      min-height: 38px;
      padding: 0 var(--ds-space-85);
      display: inline-flex;
      align-items: center;
    }

    .btn-help {
      min-height: 38px;
    }

    .btn-account {
      min-height: 38px;
      margin-left: auto;
    }
  }

  @media (max-width: 480px) {
    .btn-account__label {
      display: none; /* icon only; the link keeps its aria-label */
    }

    .header-brand h1 {
      font-size: var(--ds-font-size-100);
    }

    .header-brand p {
      display: none; /* Conserve vertical space */
    }

    .user-status-role {
      font-size: var(--ds-font-size-70);
    }
  }
}
