/*
 * The web app's header (issue #112), shared by the web app (web/index.html)
 * and the Manager's Office opened there (web/edit-app.html) — see
 * app-header.js and README.md → "The header". It uses the page's own colors
 * (--bg-bar, --hairline, --text, --text-secondary, --brand, --brand-solid,
 * --bg-card, --hover-wash, --focus), which both pages define for light and
 * dark. The title's look comes from App Content as the --title-* variables,
 * which app-header.js sets on <html>; the values here are the defaults.
 *
 * Phones (< 700px): ☰ · logo + title · buttons — the tabs are the web app's
 * tab bar along the bottom. Wider: the tabs sit in the middle of the bar.
 */
:root {
  --app-header-height: 52px;
  --app-header-z: 20;
  --app-header-pill: rgba(64, 55, 40, 0.10);
  --title-font: "Caprasimo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --title-weight: 400;
  --title-size: 22px;
  --title-color: #0060e6ff;
  --title-color-dark: #4d97ff;
}
@media (prefers-color-scheme: dark) {
  :root { --app-header-pill: rgba(211, 189, 147, 0.16); }
}
@media (min-width: 700px) {
  :root { --app-header-height: 60px; }
}

.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: var(--app-header-z);
  box-sizing: border-box;
  height: calc(var(--app-header-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hairline);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: normal;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
.app-header *, .app-header *::before, .app-header *::after { box-sizing: border-box; }
:where(.app-header) button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
:where(.app-header) a { -webkit-tap-highlight-color: transparent; }

/* ☰, then the logo and title — one link to the homepage */
.header-start { display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0; }
.menu-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; color: var(--text);
}
.menu-btn svg { width: 22px; height: 22px; }
.menu-btn[aria-expanded="true"] { background: var(--hover-wash); }
.menu-btn:active { opacity: 0.6; }
.brand-link {
  display: flex; align-items: center; gap: 9px; min-width: 0;
  padding: 4px 6px; border-radius: 10px; text-decoration: none; color: inherit;
}
.brand-link .logo { display: block; height: 30px; width: auto; flex: none; }
.brand-link:active { opacity: 0.7; }
.brand-title {
  display: block; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-family: var(--title-font); font-weight: var(--title-weight);
  font-size: min(var(--title-size), 22px); line-height: 1.25;
  color: var(--title-color);
}
@media (prefers-color-scheme: dark) {
  .brand-title { color: var(--title-color-dark); }
}

/* The tabs (wider screens) */
.top-nav { display: none; }

/* Buttons on the right: refresh, sign out, sign up / log in */
.header-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.header-btn {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  color: var(--brand); font-size: 15px; font-weight: 600; white-space: nowrap;
  padding: 8px 10px; border-radius: 10px; text-decoration: none;
}
.header-btn svg { width: 17px; height: 17px; }
.header-btn:active { opacity: 0.5; }
.header-btn.header-cta {
  margin-left: 4px; padding: 7px 14px; border-radius: 999px;
  background: var(--brand-solid); color: #fff; font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  .header-btn.header-cta { background: var(--brand); color: #1c1c1e; }
}

/* Phones: the title shrinks with the screen (to fit beside Events' refresh
   and Sign Up / Log In), and so do the buttons; the smallest phones keep a
   smaller logo, then none. */
@media (max-width: 699px) {
  .header-start { gap: 0; }
  .brand-link { gap: 7px; padding: 4px 5px; }
  .brand-title { font-size: min(var(--title-size), max(16px, 5.1vw)); }
  .header-btn { padding: 8px 7px; }
  .header-btn.header-cta { margin-left: 2px; padding: 6px 11px; font-size: 13px; }
}
@media (max-width: 380px) {
  .brand-link .logo { height: 26px; }
  .brand-title { font-size: min(var(--title-size), max(16px, 4.9vw)); }
  .header-btn { padding: 8px 5px; }
  .header-btn.header-cta { padding: 5px 9px; font-size: 12.5px; }
}
@media (max-width: 340px) {
  .brand-link .logo { display: none; }
  .brand-title { font-size: min(var(--title-size), max(15px, 4.7vw)); }
}

@media (min-width: 700px) {
  .app-header {
    display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px;
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right));
  }
  .brand-link .logo { height: 32px; }
  .brand-title { font-size: var(--title-size); }
  .top-nav { display: flex; align-items: center; gap: 4px; }
  .top-nav button, .top-nav a {
    padding: 7px 18px; border-radius: 999px; text-decoration: none;
    font-size: 15px; font-weight: 600; color: var(--text-secondary); white-space: nowrap;
  }
  .top-nav .active { color: var(--brand); background: var(--app-header-pill); }
  .header-actions { justify-self: end; }
}
@media (min-width: 700px) and (max-width: 860px) {
  .top-nav button, .top-nav a { padding-left: 13px; padding-right: 13px; }
}

/* ── The ☰ menu ───────────────────────────────────────────────────── */
.site-menu {
  position: absolute; z-index: 1;
  top: calc(100% + 6px); left: max(8px, env(safe-area-inset-left));
  width: min(330px, calc(100vw - 16px));
  max-height: calc(100vh - var(--app-header-height) - env(safe-area-inset-top) - 24px);
  max-height: calc(100dvh - var(--app-header-height) - env(safe-area-inset-top) - 24px);
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 6px;
  background: var(--bg-card); color: var(--text);
  border-radius: 14px;
  box-shadow: 0 0 0 0.5px var(--hairline), 0 16px 44px rgba(0, 0, 0, 0.2);
  animation: app-menu-in 0.16s ease-out;
}
.site-menu[hidden] { display: none; }
.site-menu ul { list-style: none; margin: 0; padding: 0; }
.site-menu .menu-heading, .site-menu .menu-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: 16px; line-height: 1.3;
}
.site-menu .menu-heading { font-weight: 700; }
.site-menu .menu-sublist .menu-link { padding-left: 26px; font-size: 15px; }
.site-menu .menu-list > li + li { margin-top: 2px; }
.site-menu .menu-list > li.menu-group + li, .site-menu .menu-list > li + li.menu-group {
  margin-top: 6px; padding-top: 6px; border-top: 0.5px solid var(--hairline);
}
.site-menu .menu-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.site-menu .menu-ext { flex: none; width: 14px; height: 14px; color: var(--text-secondary); opacity: 0.7; }
.site-menu .menu-hint {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.site-menu a:active { background: var(--hover-wash); }
.site-menu a:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* Catches clicks outside the menu — over the Home tab's frame too. */
.site-menu-backdrop { position: fixed; inset: 0; z-index: calc(var(--app-header-z) - 1); background: transparent; }
.site-menu-backdrop[hidden] { display: none; }
@media (max-width: 699px) {
  .site-menu-backdrop { background: rgba(0, 0, 0, 0.22); }
}

@keyframes app-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

@media (hover: hover) and (pointer: fine) {
  .menu-btn:hover { background: var(--hover-wash); }
  .brand-link:hover { opacity: 0.85; }
  .header-btn:hover { background: var(--hover-wash); }
  .header-btn.header-cta:hover { background: var(--brand-solid); opacity: 0.88; }
  .top-nav button:hover, .top-nav a:hover { color: var(--text); }
  .top-nav .active:hover { color: var(--brand); }
  .site-menu a:hover { background: var(--hover-wash); }
  .site-menu a:hover .menu-ext { opacity: 1; }
}
@media (hover: hover) and (pointer: fine) and (prefers-color-scheme: dark) {
  .header-btn.header-cta:hover { background: var(--brand); }
}
@media (prefers-reduced-motion: reduce) {
  .site-menu { animation: none; }
}
@media print {
  .app-header, .site-menu-backdrop { display: none !important; }
}
