/* Caparazón de la app (estilo Fluent): barra superior, navegación inferior (móvil)
   y riel lateral (desde 900px). Capa: components. */

@layer components {

  /* ---------- Barra superior ---------- */
  .shell-top {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-height: 48px;
    padding: 0 var(--s-3) 0 var(--s-4);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }
  .shell-espacio { flex: 1 1 auto; }

  .shell-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: var(--hit);
    color: var(--ink-strong);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    border-radius: var(--r-sm);
    min-width: 0;
  }
  .shell-brand > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 18ch;
  }
  .shell-monograma {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    background: var(--brand);
    color: var(--on-brand);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-bold);
    letter-spacing: 0.02em;
    flex: 0 0 auto;
  }

  .shell-avatar {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: var(--on-brand);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    cursor: pointer;
  }
  .shell-avatar:hover { background: color-mix(in srgb, var(--brand) 88%, var(--ink-strong)); }

  /* ---------- Navegación: barra inferior (móvil) ---------- */
  .shell-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .shell-items {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0 var(--s-1);
    gap: 0;
  }
  .shell-items > li { flex: 1 1 0; min-width: 0; }
  .shell-link {
    position: relative;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-height: 56px;
    padding: var(--s-1) 2px;
    border-radius: var(--r-sm);
    color: var(--muted);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-regular);
    text-decoration: none;
    line-height: 1.2;
    text-align: center;
  }
  .shell-link svg { width: 20px; height: 20px; }
  .shell-link > span { max-width: 100%; }
  .shell-nav > .shell-brand { display: none; }
  .shell-link:hover { color: var(--ink-strong); background: var(--surface-2); }
  .shell-link[aria-current="page"] {
    color: var(--brand-ink);
    font-weight: var(--fw-semibold);
  }
  .shell-link[aria-current="page"] svg { color: var(--brand); }
  /* Indicador Fluent: barra de 3px arriba del ítem activo */
  .shell-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--brand);
  }
  /* Solo en el riel lateral se usa el bloque de usuario */
  .shell-usuario { display: none; }

  /* ---------- Contenedor principal ---------- */
  .app {
    display: grid;
    align-content: start;
    gap: var(--s-4);
    width: 100%;
    max-width: var(--content);
    margin: 0 auto;
    padding: var(--s-4) var(--s-4) calc(88px + env(safe-area-inset-bottom));
    min-width: 0;
  }
  .app > * { min-width: 0; }
  .app-footer {
    padding: var(--s-4);
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
    text-align: center;
    color: var(--muted);
    font-size: var(--fs-xs);
  }
  .app-footer p { margin: 0; }

  /* ---------- Subnavegación (Análisis / Gestión): pestañas subrayadas ---------- */
  .shell-sub {
    position: relative;
    margin: 0 calc(var(--s-4) * -1) var(--s-4);
    border-bottom: 1px solid var(--line);
  }
  .shell-sub ul {
    display: flex;
    gap: var(--s-4);
    margin: 0;
    padding: 0 var(--s-4);
    list-style: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-padding-inline: var(--s-4);
    scrollbar-width: none;
  }
  .shell-sub ul::-webkit-scrollbar { display: none; }
  .shell-sub li { flex: 0 0 auto; }
  .shell-sub a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--s-1);
    color: var(--muted);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    text-decoration: none;
    white-space: nowrap;
  }
  .shell-sub a:hover { color: var(--ink-strong); }
  .shell-sub a[aria-current="page"] {
    color: var(--ink-strong);
    font-weight: var(--fw-semibold);
  }
  .shell-sub a[aria-current="page"]::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    border-radius: 1px;
    background: var(--brand);
  }

  /* ---------- Escritorio: riel lateral desde 900px ---------- */
  @media (min-width: 900px) {
    .shell-top {
      position: sticky;
      left: var(--rail);
      margin-left: var(--rail);
      padding: 0 var(--s-6);
      min-height: 48px;
    }
    .shell-nav {
      top: 0;
      right: auto;
      bottom: 0;
      width: var(--rail);
      display: flex;
      flex-direction: column;
      gap: var(--s-4);
      padding: var(--s-4) var(--s-2) var(--s-3);
      border-top: 0;
      border-right: 1px solid var(--line);
      overflow-y: auto;
    }
    .shell-nav > .shell-brand { display: inline-flex; padding: 0 var(--s-2); }
    .shell-top .shell-brand { display: none; }
    .shell-items {
      flex-direction: column;
      padding: 0;
      gap: 2px;
    }
    .shell-items > li { flex: none; }
    .shell-link {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: var(--s-3);
      min-height: 36px;
      padding: 0 var(--s-3);
      border-radius: var(--r-sm);
      font-size: var(--fs-sm);
      text-align: left;
    }
    .shell-link svg { width: 20px; height: 20px; }
    .shell-link[aria-current="page"] { background: var(--brand-soft); }
    .shell-link[aria-current="page"]::before {
      top: 8px;
      bottom: 8px;
      left: 0;
      right: auto;
      width: 3px;
      height: auto;
      border-radius: 0 3px 3px 0;
    }
    .shell-usuario {
      display: flex;
      align-items: center;
      gap: var(--s-3);
      margin-top: auto;
      min-height: 52px;
      padding: var(--s-2);
      border: 0;
      border-radius: var(--r-sm);
      background: transparent;
      text-align: left;
      color: var(--ink);
      cursor: pointer;
    }
    .shell-usuario:hover { background: var(--surface-2); }
    .shell-usuario-icono {
      display: inline-grid;
      place-items: center;
      width: 32px; height: 32px;
      border-radius: 50%;
      background: var(--brand);
      color: var(--on-brand);
      font-size: var(--fs-xs);
      font-weight: var(--fw-semibold);
      flex: 0 0 auto;
    }
    .shell-usuario-texto { display: grid; min-width: 0; line-height: 1.3; }
    .shell-usuario-texto strong { font-size: var(--fs-sm); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .shell-usuario-texto small { color: var(--muted); font-size: var(--fs-xs); }

    .app {
      width: auto;
      margin-left: var(--rail);
      margin-right: auto;
      padding: var(--s-6) var(--s-6) var(--s-10);
    }
    .app-footer { margin-left: var(--rail); padding-bottom: var(--s-6); }
    .toasts { left: calc(var(--rail) + var(--s-6)); right: var(--s-6); bottom: var(--s-6); }
    .shell-sub { margin: 0 0 var(--s-4); }
    .shell-sub ul { padding-left: 0; padding-right: 0; scroll-padding-inline: 0; }
  }
}
