.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 16px;
  min-height: 76px;
  padding: 14px max(24px, calc((100vw - var(--container)) / 2));
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid transparent;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: box-shadow 180ms ease, border-color 180ms ease;
}

.site-header.scrolled {
  border-color: var(--line);
  box-shadow: 0 8px 24px rgba(16, 47, 82, 0.08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: var(--navy);
  font-weight: 900;
}

.brand-logo {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand-name {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Stage 1 (widest-to-narrowest first step): the company name is hidden
   first, decided in JS from the header's actual available width - see
   the header-layout logic in public/js/app.js. The logo always stays. */
.site-header.hide-brand-name .brand-name {
  display: none;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.main-nav a {
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.main-nav a.active,
.main-nav a:hover {
  color: var(--navy);
  background: var(--soft);
}

.nav-toggle {
  display: none;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: var(--navy);
}

/* Stage 3 (only once the nav no longer fits even without the company
   name): the inline nav becomes a hamburger-triggered dropdown. Stage 2
   (nav compressing/adjusting while space allows) needs no extra CSS here -
   it is simply "the state before this class is applied", where the nav
   still renders inline at its natural size. */
.site-header.nav-collapsed .nav-toggle {
  display: inline-flex;
}

.site-header.nav-collapsed .main-nav {
  position: absolute;
  top: 76px;
  right: 24px;
  left: 24px;
  display: none;
  flex-direction: column;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.site-header.nav-collapsed .main-nav a {
  white-space: normal;
}

.site-header.nav-collapsed .main-nav.open {
  display: flex;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
  line-height: 1.2;
  transition: transform 170ms ease, box-shadow 170ms ease, background 170ms ease;
}

.button:hover {
  transform: translateY(-2px);
}

.button.primary {
  color: #071526;
  background: var(--amber);
  box-shadow: 0 10px 22px rgba(245, 165, 36, 0.25);
}

.button.primary:hover {
  background: var(--amber-2);
}

.button.ghost {
  color: var(--navy);
  border-color: var(--line);
  background: var(--paper);
}

.button.light {
  color: var(--paper);
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
}

.button.danger {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.25);
  background: #fff5f3;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
}

.flash-stack {
  position: fixed;
  top: 88px;
  right: 24px;
  z-index: 80;
  display: grid;
  gap: 8px;
}

.flash {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 700;
  transition: opacity 180ms ease, transform 180ms ease;
}

.flash button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: rgba(255, 255, 255, 0.65);
  font-weight: 900;
}

.flash-dismiss {
  opacity: 0;
  transform: translateY(-8px);
}

.flash.success {
  color: var(--success);
  background: #ecfdf3;
}

.flash.error {
  color: var(--danger);
  background: #fff1f0;
}

.site-footer {
  padding: 56px max(24px, calc((100vw - var(--container)) / 2)) 24px;
  background: #0d2238;
  color: #d8e7f4;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1.4fr 1fr;
  gap: 32px;
}

.site-footer h2 {
  font-size: 16px;
  color: var(--paper);
}

.site-footer a,
.site-footer p {
  display: block;
  color: #d8e7f4;
}

.footer-brand {
  color: var(--paper);
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.social-links a {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
}

.social-links svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.copyright {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  color: #afc5d9;
}

.dialog-card {
  width: min(640px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 28px 80px rgba(16, 47, 82, 0.28);
}

.wide-dialog {
  width: min(920px, calc(100vw - 32px));
}

.dialog-card::backdrop {
  background: rgba(8, 21, 35, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.close-dialog {
  position: absolute;
  top: 16px;
  right: 16px;
}

.stack-form,
.admin-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--navy);
  font-weight: 800;
}

label small {
  color: var(--muted);
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--ink);
  background: var(--paper);
}

input.is-invalid,
textarea.is-invalid,
select.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.field-error {
  display: block;
  flex: 1 0 100%;
  width: 100%;
  margin-top: 4px;
  color: var(--danger);
  font-weight: 700;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.toggle.inline {
  display: inline-flex;
  margin: 0;
  font-weight: 400;
}

.media-preview-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.media-preview-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--soft);
}

/*
 * Navbar responsive hierarchy is JS-driven, not based on fixed viewport
 * breakpoints - see the header-layout logic in public/js/app.js. It
 * measures the header's actual rendered content against its available
 * width and applies `.hide-brand-name` (stage 1) and then `.nav-collapsed`
 * (stage 3) only when the content genuinely no longer fits, so the exact
 * pixel width varies with the real company name/logo/font rendering
 * instead of an arbitrary guessed breakpoint that could still overlap.
 */

@media (max-width: 980px) {
  .footer-grid {
    grid-template-columns: 1fr;
  }
}
