/* ====================================================================
   LAYOUT.CSS — App Shell & Grid
   Adapted from designs/flows/kit.css patterns using token system.
   Breakpoints: mobile (<768px), tablet (768-1199px), desktop (≥1200px)
   ==================================================================== */

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html, body {
    height: 100%;
  }

  body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
} /* end @layer reset */

@layer base {
  /* ---- Headings ---- */
  h1, h2, h3, h4 {
    font-family: var(--font-display);
    margin: 0;
    line-height: 1.2;
    color: var(--text);
  }

  h1 { font-size: var(--text-xl); }
  h2 { font-size: var(--text-base); }
  h3 { font-size: var(--text-base); }

  /* ---- Links ---- */
  a {
    color: var(--accent);
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  /* ---- Paragraph ---- */
  p {
    margin: var(--space-s) 0;
  }

  /* ---- Code ---- */
  code, pre {
    font-family: var(--font-mono);
  }

  pre {
    background: var(--panel);
    border: var(--border-w) solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-xl);
    overflow-x: auto;
  }
} /* end @layer base */

@layer layout {

/* ---- Grid Shell ---- */
.shell {
  display: grid;
  min-height: 100vh;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  grid-template-areas:
    "top"
    "main"
    "foot";
}

/* ---- Topbar ---- */
.top {
  grid-area: top;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  background: var(--panel);
  border-bottom: var(--border-w) solid var(--line);
  padding: var(--space-m) var(--space-xl);
}

/* ---- Left Nav ---- */
.nav {
  grid-area: nav;
  background: var(--panel);
  border-right: var(--border-w) solid var(--line);
  padding: var(--space-xl) 0;
  overflow-y: auto;
  display: none;
}

/* ---- Main ---- */
.main {
  grid-area: main;
  padding: var(--space-2xl) var(--space-3xl) 5rem;
  overflow-y: auto;
}

/* ---- Right Rail ---- */
.right {
  grid-area: right;
  background: var(--panel);
  border-left: var(--border-w) solid var(--line);
  padding: var(--space-xl) var(--space-xl);
  overflow-y: auto;
  display: none;
}

/* ---- Footer ---- */
.foot {
  grid-area: foot;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-2xl);
  background: var(--panel);
  border-top: var(--border-w) solid var(--line);
  padding: var(--space-s) var(--space-xl);
  font-size: var(--text-xs);
  color: var(--text-3);
}

/* ---- Tablet (768px+) ---- */
@media (min-width: 768px) {
  .shell {
    grid-template-columns: 230px 1fr;
    grid-template-areas:
      "top   top"
      "nav   main"
      "foot  foot";
  }

  .nav {
    display: block;
  }
}

/* ---- Desktop (≥1200px) ---- */
/* The shell stays two columns (nav | main). The right rail is an empty
   placeholder for a future spec, so we don't reserve a third column for it —
   that lets .main (and the entity manuscript spread) own the full width. To
   re-enable: restore the 3-column grid + grid-template-areas and `.right`. */
@media (min-width: 1200px) {
  .right { display: none; }
}

/* ---- Page Wrapper ---- */
.page-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xl);
  max-width: 72rem;
  margin: 0 auto;
}

/* ---- Subnav ---- */
.subnav {
  display: flex;
  flex-direction: column;
  gap: var(--space-m);
  position: sticky;
  top: var(--space-xl);
}

.subnav__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-s); }
.subnav__title { font-family: var(--font-display); flex: 1 1 auto; }

.subnav__links { display: flex; flex-direction: column; gap: var(--space-2xs); }
.subnav__section {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: var(--text-3);
  margin-top: var(--space-m);
}
.subnav__link {
  padding: var(--space-xs) var(--space-m);
  border-radius: var(--radius);
  color: var(--text-2);
  text-decoration: none;
}
.subnav__link:hover { background: var(--panel-2); color: var(--text); }
.subnav__link.is-active { background: var(--accent); color: var(--bg); }

@media (max-width: 48rem) {
  .subnav { position: static; }
}

/* ---- Dropdown Menu ---- */
.dropdown-menu {
  list-style: none;
  margin: var(--space-xs) 0 0;
  padding: 0;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.dropdown-menu li { padding: 0; }
.dropdown-menu a {
  display: block;
  padding: var(--space-s) var(--space-m);
  color: var(--text);
  text-decoration: none;
}
.dropdown-menu a:hover { background: var(--panel-2); }

/* ---- Grid Utilities ---- */
.grid {
  display: grid;
  gap: var(--space-xl);
  align-items: start;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 60rem) {
  .grid-2 { grid-template-columns: 1fr; }
}

.grid-auto {
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
}

/* Reset list styling when grid is applied to ul/ol */
ul.grid, ol.grid {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ---- Staggered Entrance ---- */
@media (prefers-reduced-motion: no-preference) {
  @keyframes stagger-enter {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .stagger-in > * {
    animation: stagger-enter 0.35s ease both;
  }

  .stagger-in > *:nth-child(1) { animation-delay: 0s; }
  .stagger-in > *:nth-child(2) { animation-delay: 0.06s; }
  .stagger-in > *:nth-child(3) { animation-delay: 0.12s; }
  .stagger-in > *:nth-child(4) { animation-delay: 0.18s; }
  .stagger-in > *:nth-child(5) { animation-delay: 0.24s; }
  .stagger-in > *:nth-child(6) { animation-delay: 0.30s; }
  .stagger-in > *:nth-child(n+7) { animation-delay: 0.36s; }
}

/* ---- Flex Utilities ---- */
.flex-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-l);
}

.flex-baseline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-m);
}

} /* end @layer layout */
