/* Site shell: compact header, section row, tool row, welcome strip.
   Behaviour lives in static/js/site-nav.js. The header sits on the dark page
   background in both themes, so it uses light-on-dark colours throughout. */

/* --- Header ---
   Desktop (992px+): three columns, the brand centred as it always was, the
   links and theme on the right, the supporter hub bar (if any) on the left.
   Tablet: brand left, actions right. Phone: brand and actions centred. */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.site-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.6rem;
  font-size: 0.8rem;
}
.site-header-actions > * {
  white-space: nowrap;
}

@media (min-width: 992px) {
  .site-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    column-gap: 1.5rem;
    margin-bottom: 1rem;
  }
  .site-title-link {
    grid-column: 2;
    grid-row: 1;
    text-align: center;
  }
  .site-header-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  .site-title {
    font-size: 2.8rem;
    padding-top: 2.3rem;
  }
  .site-title .correction .handwritten {
    font-size: 2rem;
  }
  /* The welcome strip sits on the same centre axis as everything else (the id
     outranks the base rule further down). */
  #siteWelcome {
    justify-content: center;
    column-gap: 1.5rem;
  }
  /* Sections are the parent level: as large as the tool tabs below (the extra
     class outranks the base rule further down). */
  .site-nav-sections .site-nav-section {
    padding: 0.45rem 1.1rem;
    font-size: 1rem;
  }
  /* Sections sit centred under the brand; the tools are centred on the panel. */
  .site-nav-sections,
  #mainTabs {
    justify-content: center;
  }
}

/* Larger text from Options (115-150%, options.js sets html.ts-*) does not fit
   three columns or one line of actions: the header goes back to the wrapping
   row and the actions may wrap. */
@media (min-width: 992px) {
  html:is(.ts-115, .ts-130, .ts-150) .site-header {
    display: flex;
    justify-content: center;
  }
}
html:is(.ts-115, .ts-130, .ts-150) .site-header-actions {
  flex-wrap: wrap;
  justify-content: center;
}

.site-save-status {
  color: rgba(255, 255, 255, 0.6);
  cursor: help;
}
/* Narrow headers say just "Saved", so the links and the theme switch stay on
   one line (a title tooltip never shows on touch). */
.site-save-short {
  display: none;
}
@media (max-width: 1299.98px) {
  .site-save-long {
    display: none;
  }
  .site-save-short {
    display: inline;
  }
}
.site-save-status::before {
  content: '';
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: var(--accent-success-bright);
  vertical-align: 0.05rem;
}

.site-feedback-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: underline;
}
.site-feedback-link:hover {
  color: #fff;
}

/* --- Section row --- */
.site-nav-sections {
  display: flex;
  align-items: center; /* pills keep their height beside a two-line legend */
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.site-nav-section {
  padding: 0.4rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}
.site-nav-section:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}
.site-nav-section:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}
/* The tool tabs get the same gold ring (Bootstrap's blue halo is 1.3:1 here). */
#mainTabs .nav-link:focus-visible {
  box-shadow: none;
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}
.site-nav-section.active {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: var(--surface-900);
}
/* Dark-theme gold is darker: light text keeps AA contrast (4.6:1). */
[data-theme='dark'] .site-nav-section.active {
  color: #fff;
}

/* --- Tool row: the active section's Bootstrap tabs --- */
#mainTabs {
  gap: 0.25rem;
}

/* --- First-visit welcome --- */
.site-welcome {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  padding: 0.6rem 2.6rem 0.6rem 0.9rem;
  border: 1px solid var(--accent-gold-glow);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
}
.site-welcome-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem 0.9rem;
  flex-wrap: wrap;
}
.site-welcome-actions a {
  color: var(--accent-gold-light);
  font-weight: 600;
}
/* Always at the right edge, also when the strip wraps. */
.site-welcome .btn-close {
  position: absolute;
  top: 50%;
  right: 0.8rem;
  transform: translateY(-50%);
  margin: 0;
  filter: invert(1);
  opacity: 0.7;
}
.site-welcome-short {
  display: none;
}
/* "Set up" points at Lock All on the Super Managers tab with an outline that
   fades (box-shadow belongs to the button's focus style; the id outranks
   Bootstrap's focus outline). With reduced motion it stays until blur. */
#smToggleBtn.site-welcome-flash {
  outline: 3px solid var(--accent-gold);
  outline-offset: 2px;
  animation: site-welcome-flash 2s ease-out forwards;
}
@keyframes site-welcome-flash {
  0%,
  60% {
    outline-color: var(--accent-gold);
  }
  100% {
    outline-color: transparent;
  }
}
@media (prefers-reduced-motion: reduce) {
  #smToggleBtn.site-welcome-flash {
    animation: none;
  }
}

/* The narrowest grid widths: tighter links so they keep one line. */
@media (min-width: 992px) and (max-width: 1099.98px) {
  .site-header-actions {
    gap: 0.5rem;
    font-size: 0.75rem;
  }
}

/* Laptops to 1299px: the strip keeps one line by dropping the extra links. */
@media (min-width: 992px) and (max-width: 1299.98px) {
  .site-welcome-extra {
    display: none;
  }
}

/* Tablets: the long tool labels shorten (as on phones), so the active
   section's tools fit one row of folder tabs. */
@media (min-width: 768px) and (max-width: 991.98px) {
  #mainTabs .site-nav-long {
    display: none;
  }
  /* The phone welcome (one line, the step and Set up) fits tablets too. */
  .site-welcome-detail,
  .site-welcome-extra {
    display: none;
  }
  .site-welcome-short {
    display: inline;
  }
  .sm-chrono-standalone #mainTabs .nav-link {
    padding: 0.5rem 0.75rem;
  }
}

/* A shared snapshot shows one read-only roster: no navigation, no welcome. */
body.sm-share-readonly .site-nav,
body.sm-share-readonly .site-welcome,
body.sm-share-readonly .site-save-status {
  display: none !important;
}

/* Below the sidebar (1200px) the active section's 2-6 tools are folder tabs
   in one row that scrolls sideways when it does not fit, on a phone or with
   the Options text size up (site-nav.js keeps the open tool in view). The
   scroll box clips a border, so the baseline is an inset shadow the active
   tab paints over. */
@media (max-width: 1199.98px) {
  .sm-chrono-standalone #mainTabs {
    flex-wrap: nowrap;
    justify-content: flex-start;
    justify-content: safe center;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    border-bottom: 0;
    box-shadow: inset 0 -1px 0 var(--bs-nav-tabs-border-color);
  }
  /* More tools past an edge: that edge fades (site-nav.js sets the classes).
     The -webkit- line is for browsers before the unprefixed mask (2023). */
  .sm-chrono-standalone #mainTabs.site-tools-more-end {
    --site-tools-fade: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
  }
  .sm-chrono-standalone #mainTabs.site-tools-more-start {
    --site-tools-fade: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
  }
  .sm-chrono-standalone #mainTabs.site-tools-more-start.site-tools-more-end {
    --site-tools-fade: linear-gradient(
      to right,
      transparent,
      #000 2.5rem,
      #000 calc(100% - 2.5rem),
      transparent
    );
  }
  .sm-chrono-standalone #mainTabs:is(.site-tools-more-start, .site-tools-more-end) {
    -webkit-mask-image: var(--site-tools-fade);
    mask-image: var(--site-tools-fade);
  }
  /* The scroll box clips anything outside it: the ring goes inside the tab. */
  #mainTabs .nav-link:focus-visible {
    outline-offset: -2px;
  }
  .sm-chrono-standalone #mainTabs::-webkit-scrollbar {
    display: none;
  }
  #mainTabs > li {
    flex: none;
  }
  .sm-chrono-standalone #mainTabs .nav-link {
    margin: 0;
  }
}
/* Tablets: the brand and the sections start at the left, so do the tools. */
@media (min-width: 768px) and (max-width: 991.98px) {
  .sm-chrono-standalone #mainTabs {
    justify-content: flex-start;
  }
}

@media (max-width: 767.98px) {
  .site-header {
    margin-bottom: 0.5rem;
    justify-content: center;
    text-align: center;
  }
  .site-header-actions {
    width: 100%;
    justify-content: center;
    gap: 0.6rem;
  }
  /* Sections stay on one line down to 360px. */
  .site-nav-sections {
    justify-content: center;
    gap: 0.3rem;
  }
  .site-nav-section {
    padding: 0.3rem 0.35rem;
    font-size: 0.78rem;
    min-height: 32px;
  }
  /* On a phone (from 360px) the welcome is one line: the step, the link, close.
     "Set up" opens Super Managers and flashes Lock All. */
  .site-nav-long,
  .site-welcome-detail,
  .site-welcome-extra {
    display: none;
  }
  .site-welcome {
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.4rem 2.6rem 0.4rem 0.6rem;
    font-size: 0.82rem;
  }
  .site-welcome-actions {
    flex-wrap: nowrap;
  }
  .site-welcome-short {
    display: inline;
  }
  /* A 32px hit area for the close button, clear of the Set up link. */
  .site-welcome .btn-close {
    right: 0.25rem;
    width: 32px;
    height: 32px;
    padding: 0;
    background-size: 0.75rem;
  }
  /* Smaller tabs, so most sections fit the row without scrolling. */
  .sm-chrono-standalone #mainTabs {
    gap: 0.2rem;
  }
  .sm-chrono-standalone #mainTabs .nav-link {
    padding: 0.3rem 0.55rem;
    min-height: 32px;
    font-size: 0.78rem;
  }
  .sm-chrono-standalone .tab-content {
    border-radius: var(--radius-md);
  }
}

/* --- Desktop (1200px+): every tool in a left sidebar, one click away ---
   The section row goes; the tools run down the left side grouped under small
   section labels (the first tool of each group carries its label) and the
   content sits to the right. Narrower screens keep sections + tool tabs. */
@media (min-width: 1200px) {
  .sm-chrono-standalone > .container-fluid {
    display: grid;
    grid-template-columns: 13.5rem minmax(0, 1fr);
    grid-template-areas:
      'head head'
      'welcome welcome'
      'nav main';
    column-gap: 1.25rem;
  }
  .site-header {
    grid-area: head;
  }
  #siteWelcome {
    grid-area: welcome;
  }
  #siteNav {
    grid-area: nav;
    align-self: start;
    position: sticky;
    top: 1rem;
    /* Short laptop screens: the list scrolls on its own, nothing out of reach. */
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 0.25rem; /* room for the focus ring inside the scroll box */
  }
  #mainTabsContent {
    grid-area: main;
  }
  .site-nav-sections .site-nav-section {
    display: none;
  }
  .site-nav-sections {
    margin: 0;
  }
  .sm-chrono-standalone #mainTabs {
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0.15rem;
    border-bottom: 0;
  }
  /* site-nav.js hides the other sections' tools; the sidebar lists them all
     (!important beats Bootstrap's [hidden] rule). */
  #mainTabs > li[hidden] {
    display: block !important;
  }
  #mainTabs > li[data-nav-group='managers']:first-child::before,
  #mainTabs > li:not([data-nav-group='events']) + li[data-nav-group='events']::before,
  #mainTabs > li:not([data-nav-group='calculators']) + li[data-nav-group='calculators']::before,
  #mainTabs > li:not([data-nav-group='help']) + li[data-nav-group='help']::before {
    display: block;
    margin: 0.9rem 0 0.3rem 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  #mainTabs > li[data-nav-group='managers']:first-child::before {
    content: 'My Managers';
    margin-top: 0;
  }
  #mainTabs > li:not([data-nav-group='events']) + li[data-nav-group='events']::before {
    content: 'Events';
  }
  #mainTabs > li:not([data-nav-group='calculators']) + li[data-nav-group='calculators']::before {
    content: 'Calculators';
  }
  #mainTabs > li:not([data-nav-group='help']) + li[data-nav-group='help']::before {
    content: 'Help';
  }
  .sm-chrono-standalone #mainTabs .nav-link {
    width: 100%;
    margin: 0;
    padding: 0.45rem 0.75rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 0.95rem;
    text-align: left;
  }
  .sm-chrono-standalone #mainTabs .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
  }
  .sm-chrono-standalone #mainTabs .nav-link.active {
    border-color: var(--accent-gold);
    background: rgba(255, 255, 255, 0.06);
    color: var(--accent-gold-light);
  }
  .sm-chrono-standalone .tab-content {
    border-radius: var(--radius-md);
  }
  /* A shared snapshot has no navigation (see above): no sidebar column. */
  body.sm-share-readonly > .container-fluid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'head'
      'welcome'
      'main';
  }
}
