/* Reset, typography and the app shell (header + sidebar + main). */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.45;
}
h1, h2, h3, h4, p, dl, dd { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
h1 { font-size: var(--fs-3xl); font-weight: 600; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-xl); font-weight: 600; }

a { color: var(--brand-strong); }
a:hover { color: var(--brand-stronger); }

button, select, textarea, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 16px; top: 8px; z-index: 10; padding: 8px 12px; background: var(--surface); }

/* ---------- Shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 5;
  height: var(--header-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: var(--brand); color: var(--on-brand);
}
.app-header__brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.app-header__brand:hover { color: inherit; }
/* The stamp logo is a circle on white (redesign/img/logo.png, a small copy of legacy logo.jpeg);
   cropping it round makes it a white badge on the red header. */
.app-header__logo { display: block; width: 40px; height: 40px; border-radius: 50%; background: #fff; flex-shrink: 0; }
.app-header__title { font-size: var(--fs-lg); }
.app-header__spacer { flex-grow: 1; }
.app-header__search {
  width: 280px; height: 36px; padding: 0 12px;
  border: 0; border-radius: var(--radius);
  background: var(--brand-strong); color: var(--on-brand); font-size: var(--fs-md);
}
.app-header__search::placeholder { color: #F3C5C7; }
.app-header__docs {
  height: 36px; display: flex; align-items: center; gap: 6px; padding: 0 12px;
  border: 1px solid var(--brand-line); border-radius: var(--radius);
  color: var(--on-brand); text-decoration: none;
}
.app-header__docs:hover { color: var(--on-brand); background: var(--brand-strong); }
.app-header__avatar {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill); background: var(--surface); color: var(--brand);
  font-size: var(--fs-sm); font-weight: 700;
}
.app-header__logout { color: var(--on-brand); font-size: var(--fs-md); }
.app-header__logout:hover { color: var(--on-brand); }
.app-header__menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin-left: -10px; margin-right: -6px;
  background: transparent; border: 0; border-radius: var(--radius); color: var(--on-brand);
}
.app-header__menu-toggle:hover { background: var(--brand-strong); }

.app-body { flex-grow: 1; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 18px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group__label {
  padding: 0 12px 6px;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; color: var(--text-subtle);
}
.nav-item {
  min-height: 38px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-radius: var(--radius);
  color: var(--text-2); text-decoration: none;
}
.nav-item:hover { background: var(--surface-sunken); color: var(--text); }
.nav-item__label { flex-grow: 1; }
.nav-item--sub { padding-left: 28px; font-size: var(--fs-md); }
.nav-item[aria-current="page"] { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }

.main {
  flex-grow: 1; min-width: 0;
  padding: 24px 32px 64px;
}
.page { display: flex; flex-direction: column; gap: 20px; max-width: 1280px; margin: 0 auto; }
.page--narrow { max-width: 1100px; }

/* ---------- Wide screens: the menu button collapses the sidebar (open by default) ---------- */
@media (min-width: 901px) {
  .nav-collapsed .sidebar { display: none; }
}

/* ---------- Small screens: sidebar becomes a toggleable drawer ---------- */
@media (max-width: 900px) {
  .app-header { padding: 0 16px; gap: 10px; }
  .app-header__search, .app-header__title, .app-header__docs { display: none; }
  .sidebar {
    position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 4;
    overflow-y: auto; transform: translateX(-100%); transition: transform .2s ease;
  }
  .app--nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .25); }
  .main { padding: 20px 16px 48px; }
}
