/* ---------------------------------------------------------------------------
   Base — resets, page frame, sidebar and typography defaults.
   --------------------------------------------------------------------------- */

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--slate);
  background: var(--cloud);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--command-navy);
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-xl); font-weight: 600; }
h3 { font-size: var(--text-md); font-weight: 600; }

p { margin: 0 0 var(--s-2); }
p:last-child { margin-bottom: 0; }

a { color: var(--command-navy); }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ---- App frame ---------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100%;
}

.content {
  padding: var(--s-6) var(--s-6) var(--s-10);
  overflow-x: hidden;
}

.content:focus { outline: none; }

.page {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ---- Sidebar ------------------------------------------------------------ */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: var(--s-5) var(--s-3) var(--s-3);
  /* align-self keeps the sidebar its own height so it can stick while the
     page scrolls; without it the grid stretches it and sticky does nothing. */
  position: sticky;
  align-self: start;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: block;
  padding: var(--s-1) var(--s-2) var(--s-6);
}

.sidebar__brand img {
  width: 142px;
  max-width: 100%;
  display: block;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius);
  color: var(--slate);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--cloud); }

.nav-item svg { width: 18px; height: 18px; flex: none; color: var(--command-navy); }

.nav-item.is-active {
  background: var(--aqua-tint);
  border-left-color: var(--control-aqua);
  color: var(--command-navy);
  font-weight: 600;
}

.nav-item__badge {
  margin-left: auto;
  background: var(--signal-yellow);
  color: var(--deep-navy);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-pill);
  padding: 1px var(--s-2);
}

.sidebar__foot {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  border-top: 1px solid var(--border);
  padding: var(--s-3) var(--s-3) var(--s-1);
}

/* An email address is usually wider than the sidebar — trim it rather
   than letting it push out over the page. */
.sidebar__foot-name {
  font-weight: 600;
  color: var(--command-navy);
  font-size: var(--text-base);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__foot-role { font-size: var(--text-sm); color: var(--muted); }
.sidebar__foot-text { min-width: 0; }   /* lets the name actually shrink */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-tint);
  color: var(--command-navy);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: var(--text-sm);
  flex: none;
}

/* ---- Narrow screens ----------------------------------------------------- */

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--s-4);
    overflow-x: auto;
    padding: var(--s-3) var(--s-4);
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar__brand { padding: 0; }
  .sidebar__brand img { width: 120px; }
  .sidebar__nav { flex-direction: row; flex: 1; }
  .nav-item { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .nav-item.is-active { border-left-color: transparent; border-bottom-color: var(--control-aqua); }
  .nav-item span { display: none; }
  .sidebar__foot { border-top: none; padding: 0; }
  .sidebar__foot-text { display: none; }
  .content { padding: var(--s-6) var(--s-4) var(--s-12); }
}

/* Sign out sits on its own line under the name, and says what it does */
.sidebar__foot { flex-wrap: wrap; }
.sidebar__sign-out { width: 100%; margin-top: var(--s-2); }

@media (max-width: 900px) {
  .sidebar__sign-out { width: auto; margin-top: 0; }
}
