/* ==========================================================================
   base.css  -  Reset, typography and the shared page shell (SHARED KIT)
   Contains the top navigation bar and the page layout used on every page.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }   /* the hidden attribute must win over display rules like .btn */

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--c-primary); }
img, svg { max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }

h1 { font-size: var(--fs-2xl); line-height: 1.2; font-weight: var(--fw-medium); }
h2 { font-size: var(--fs-xl);  line-height: 1.25; font-weight: var(--fw-bold); }
h3 { font-size: var(--fs-lg);  line-height: 1.3;  font-weight: var(--fw-bold); }

:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.container {
  width: min(100% - 2rem, var(--container));
  margin-inline: auto;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--c-forest);
  color: #fff;
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--space-3); }

/* Icons come from the SVG sprite at the top of each page */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.25em; height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Top navigation bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-height);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--c-forest);
  text-decoration: none;
  font-weight: var(--fw-bold);
  line-height: 1.1;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--c-primary);
  color: #fff;
  font-size: 1.35rem;
}
.brand__text { white-space: nowrap; }
.brand__text small {
  display: block;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--c-primary);
  letter-spacing: 0.02em;
}

.nav { margin-left: var(--space-5); }
.nav__list { display: flex; gap: var(--space-1); }
.nav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  color: var(--c-text);
  text-decoration: none;
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background-color 0.15s ease;
}
.nav__link:hover { background: var(--c-primary-soft); }
.nav__link[aria-current="page"] {
  background: var(--c-primary-soft);
  color: var(--c-primary-ink);
  font-weight: var(--fw-bold);
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px var(--space-4) 4px 4px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  background: var(--c-surface-soft);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.avatar {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--c-forest);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
}

.topbar__toggle { display: none; }

/* ---------- Page shell ---------- */
.page {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-width);
  gap: var(--space-5);
  align-items: start;
  padding-block: var(--space-5) var(--space-7);
}
.page--single { grid-template-columns: minmax(0, 1fr); }
.page__main { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); min-width: 0; }
.page__aside { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}
.page-head h1 strong { font-weight: var(--fw-bold); }
.page-head__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}

.footer {
  padding-block: var(--space-5);
  border-top: 1px solid var(--c-border);
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
}
.footer__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
}

/* ---------- Responsive ---------- */
/* Six links + the user chip: tighten the bar before switching to the mobile menu */
@media (max-width: 1360px) {
  .nav { margin-left: var(--space-2); }
  .nav__link { padding: 0 var(--space-3); }
  .user-chip__name { display: none; }
  .user-chip { padding: 4px; }
  .user-chip .role-pill { margin-right: var(--space-2); }
}

@media (max-width: 1024px) {
  .page { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1120px) {
  .topbar__toggle {
    display: inline-grid;
    place-items: center;
    width: 44px; height: 44px;
    margin-left: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-pill);
    background: var(--c-surface);
    font-size: 1.3rem;
  }
  .topbar__user { margin-left: 0; }
  .user-chip__name { display: none; }
  .user-chip { padding: 4px; }

  /* Without JavaScript the menu simply stays visible; with JS it collapses */
  .nav {
    order: 5;
    flex-basis: 100%;
    margin-left: 0;
    padding-bottom: var(--space-3);
  }
  .topbar__inner { flex-wrap: wrap; }
  .nav__list { flex-direction: column; }
  .nav__link { width: 100%; }
  html.js .nav { display: none; }
  html.js .nav.is-open { display: block; }
}

@media (max-width: 640px) {
  h1 { font-size: var(--fs-xl); }
  .user-chip { display: none; }
  .topbar__user .btn { padding: 0; width: 44px; min-height: 44px; }
  .topbar__user .btn__label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .brand__text { white-space: nowrap; }
.brand__text small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
