/* ============================================================
   DCMS Portal — 03 layout
   App shell: sidebar rail, main column, guest shell, toasts.
   ============================================================ */

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

  /* -- sidebar rail ------------------------------------------------------ */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: var(--z-nav);
    display: flex;
    flex-direction: column;
    width: 264px;
    flex-shrink: 0;
    height: 100dvh;
    padding: var(--space-5) var(--space-4);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--space-2);
    margin-bottom: var(--space-6);
    color: var(--text);
    text-decoration: none;
    border-radius: var(--radius-input);
  }

  .brand:hover {
    text-decoration: none;
  }

  .brand-name {
    display: flex;
    align-items: baseline;
    gap: 7px;
    font-size: 1.0625rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: var(--text);
  }

  /* PORTAL matches DCMS in size — set apart only by amber colour. */
  .brand-sub {
    font-size: 1em;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    color: var(--accent-ink);
  }

  /* -- nav ----------------------------------------------------------- */
  .nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 16px;
    border-radius: var(--radius-input);
    color: var(--text-muted);
    font-weight: 550;
    font-size: var(--fs-base);
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out),
      color var(--dur-fast) var(--ease-out);
  }

  .nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
  }

  .nav-link .icon {
    color: var(--text-faint);
    transition: color var(--dur-fast) var(--ease-out);
  }

  .nav-link:hover .icon {
    color: var(--text-muted);
  }

  /* Active link: soft amber pill fill — no edge bar. */
  .nav-link.active {
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 650;
  }

  .nav-link.active .icon {
    color: var(--accent-ink);
  }

  /* -- icons (shared) -------------------------------------------------- */
  .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .icon-sm {
    width: 16px;
    height: 16px;
  }

  /* -- sidebar foot ------------------------------------------------------ */
  .sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
  }

  /* Sign out fills the row; the theme toggle sits beside it. */
  .foot-actions {
    display: flex;
    align-items: stretch;
    gap: var(--space-2);
  }

  .foot-actions .btn-block {
    flex: 1;
  }

  .user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 6px 8px;
    border-radius: var(--radius-input);
  }

  .user-avatar {
    position: relative;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(160deg, var(--accent-from), var(--accent-to));
    color: var(--on-accent);
    font-size: var(--fs-sm);
    font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-sm);
  }

  .user-avatar-fallback {
    line-height: 1;
    user-select: none;
  }

  /* Gravatar overlays the letter fallback; JS adds .avatar-broken on a
     404/error so the letter shows through. */
  .user-avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
  }

  .user-avatar.avatar-broken .user-avatar-img {
    display: none;
  }

  .user-chip-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .user-chip-name {
    font-size: var(--fs-sm);
    font-weight: 650;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-chip-email {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* -- main column ------------------------------------------------------ */
  .main {
    flex: 1;
    min-width: 0;
    position: relative;
    padding: var(--space-8) max(clamp(20px, 4vw, 48px), calc((100% - 1040px) / 2)) 96px;
  }

  .main:focus {
    outline: none;
  }

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

  .guest-topbar {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-nav);
  }

  .main-guest {
    display: grid;
    place-items: center;
    padding: clamp(16px, 5vw, 48px);
  }

  /* -- toasts ------------------------------------------------------------ */
  .toasts {
    position: fixed;
    right: var(--space-5);
    bottom: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-2);
    pointer-events: none;
  }

  .toast {
    position: relative;
    pointer-events: auto;
    min-width: 240px;
    max-width: 380px;
    padding: 12px 16px 12px 38px;
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: 550;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lift);
    opacity: 0;
    transform: translateX(calc(100% + 32px));
    transition: transform var(--dur-base) var(--ease-spring),
      opacity var(--dur-base) var(--ease-out);
  }

  /* Status shown as a small leading dot, not a coloured edge bar. */
  .toast::before {
    content: "";
    position: absolute;
    left: 16px;
    top: 50%;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border-radius: 50%;
    background: var(--success-ink);
  }

  .toast-ok::before {
    background: var(--success-ink);
  }

  .toast-danger::before {
    background: var(--danger-ink);
  }

  .toast-in {
    opacity: 1;
    transform: none;
  }

  .toast-out {
    opacity: 0;
    transform: translateY(10px);
    transition: transform var(--dur-quick) var(--ease-out),
      opacity var(--dur-quick) var(--ease-out);
  }

  /* -- skeleton shimmer while a fragment loads --------------------------- */
  #app-main.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    background:
      linear-gradient(105deg, transparent 25%, var(--shimmer-sheen) 50%, transparent 75%),
      var(--shimmer-veil);
    background-size: 220% 100%, auto;
    background-repeat: no-repeat;
    animation: shimmer 1.1s var(--ease-in-out) infinite;
  }

  /* ============================================================
     <= 900px : sidebar becomes a top bar
     ============================================================ */
  @media (max-width: 900px) {
    .shell {
      flex-direction: column;
    }

    .sidebar {
      position: static;
      width: 100%;
      height: auto;
      flex-direction: row;
      align-items: center;
      gap: var(--space-3);
      padding: var(--space-2) var(--space-4);
      border-right: 0;
      border-bottom: 1px solid var(--border);
      overflow: visible;
    }

    .brand {
      margin-bottom: 0;
      padding: 6px;
      flex-shrink: 0;
    }

    .nav {
      flex-direction: row;
      justify-content: center;
      flex: 1;
      gap: 4px;
    }

    .nav-link {
      padding: 8px 12px;
    }

    .sidebar-foot {
      flex-direction: row;
      align-items: center;
      margin: 0 0 0 auto;
      padding-top: 0;
      border-top: 0;
      gap: var(--space-2);
    }

    .user-chip {
      padding: 0;
    }

    .user-chip-email {
      display: none;
    }

    .sidebar-foot .btn-block {
      display: inline-flex;
      width: auto;
    }

    .foot-actions .btn-block {
      flex: 0 0 auto;
    }

    .main {
      padding: var(--space-6) var(--space-4) var(--space-8);
    }

    .toasts {
      right: var(--space-3);
      left: var(--space-3);
      bottom: var(--space-3);
      align-items: stretch;
    }

    .toast {
      max-width: none;
    }
  }

  /* Very narrow: shed nav labels, keep icons. */
  @media (max-width: 560px) {
    .nav-link span {
      display: none;
    }

    .nav-link {
      padding: 10px;
    }

    .user-chip-name {
      display: none;
    }

    /* Sign-out label is a bare text node: collapse it, keep the icon. */
    .sidebar-foot .btn {
      font-size: 0;
      gap: 0;
      width: auto;
      padding: 8px;
    }

    .sidebar-foot .btn .icon {
      width: 18px;
      height: 18px;
    }
  }
}
