/* The shell: one <header> and one <nav> at every width.
   Phone (under 768px): a navy band on top, the pattern line along its bottom (docs/BRAND.md), and a
     tab bar pinned to the bottom with Today, Calendar, Money, Jobs and More.
   Tablet (768-1023px): a navy rail of icons down the left.
   Desktop (1024px up): a navy sidebar with the badge, the pattern line under it, Find, the screens,
     and who is signed in at the foot. The screens get the whole width beside it. */

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.skip {
  position: absolute; left: 8px; top: -80px; z-index: 60;
  padding: 10px 14px; border-radius: 6px; background: var(--paper); color: var(--navy);
}
.skip:focus { top: 8px; }

/* ---- The band (phone) ---- */

.site-header {
  position: relative;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  padding: 12px var(--gutter) 0;
  background: var(--navy);
  color: var(--paper);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; color: var(--paper); text-decoration: none; }
.brand:hover { color: var(--paper); }
.badge { width: 40px; height: 40px; flex: none; color: var(--paper); }
.wordmark {
  display: flex; flex-direction: column;
  font: 700 1.25rem/1.05 var(--font-display);
  color: var(--paper);
  white-space: nowrap;
}
.wordmark span {
  margin-top: 3px;
  font: 700 0.62rem/1 var(--font-body); letter-spacing: 0.26em; text-transform: uppercase;
  color: var(--sand);
}
/* The pattern line runs edge to edge along the bottom of the band, with a strip of navy under it. */
.pattern-line {
  order: 99;
  flex: 0 0 calc(100% + 2 * var(--gutter));
  margin: 4px calc(-1 * var(--gutter)) 0;
  height: 30px;
  border-bottom: 12px solid var(--navy);
  background: url('../img/pattern.svg') repeat-x left top / auto 18px;
}

.side-foot { display: flex; align-items: center; gap: 8px; }
.mode-badge, .offline-badge, .outbox-badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 4px; white-space: nowrap;
}
.mode-badge { color: var(--navy); background: var(--sand); }
.offline-badge { color: var(--navy); background: var(--paper); }
.outbox-badge { color: var(--paper); background: var(--alert); }
.mode-badge[hidden], .offline-badge[hidden], .outbox-badge[hidden], .who[hidden], .find-link[hidden], .site-nav[hidden] { display: none; }
.who { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--sand); }
.who-name { display: none; }
.who-out {
  min-height: 36px; padding: 0 12px;
  border: 1px solid rgba(217, 195, 154, 0.5); border-radius: 6px;
  background: transparent; color: var(--paper);
  font: 700 0.85rem var(--font-body); cursor: pointer;
}
.who-out:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--sand); }

.find-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 44px; min-height: 44px; padding: 0 8px;
  border-radius: 6px; color: var(--paper); text-decoration: none;
}
.find-link:hover { background: rgba(255, 255, 255, 0.08); color: var(--paper); }
.find-link span, .find-link kbd { display: none; }
.find-link[aria-current="page"] { background: rgba(255, 255, 255, 0.12); }
kbd { padding: 1px 6px; border: 1px solid rgba(217, 195, 154, 0.5); border-radius: 4px; color: var(--sand); font-size: 0.75rem; }

.site-header :focus-visible { outline: 2px solid var(--sand); outline-offset: -2px; }

/* ---- The tab bar (phone) ---- */

.site-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 0 4px env(safe-area-inset-bottom);
  background: var(--navy);
  border-top: 1px solid rgba(217, 195, 154, 0.25);
}
.nav-today { order: -1; }
.site-nav > a, .nav-more {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 62px; padding: 6px 2px 4px;
  border: 0; background: none; color: rgba(255, 255, 255, 0.78);
  font: 700 0.72rem var(--font-body); letter-spacing: 0.02em;
  text-decoration: none; white-space: nowrap; cursor: pointer;
}
.site-nav > a:hover, .nav-more:hover { color: var(--paper); }
.site-nav > a[aria-current="page"], .nav-more.is-current, .nav-more[aria-expanded="true"] {
  color: var(--paper);
  box-shadow: inset 0 3px 0 var(--gold);
}
.site-nav > a[aria-current="page"] .ico, .nav-more.is-current .ico { color: var(--sand); }
.nav-extra {
  position: absolute; right: 8px; bottom: calc(100% + 8px);
  display: none; flex-direction: column;
  min-width: 230px; padding: 6px;
  background: var(--paper);
  border: 1px solid var(--hair); border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(26, 40, 56, 0.3);
}
.site-nav.is-open .nav-extra { display: flex; }
.nav-extra a {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 0 12px; border-radius: 6px;
  color: var(--ink); font-weight: 700; text-decoration: none;
}
.nav-extra a:hover { background: var(--linen); color: var(--navy); }
.nav-extra a[aria-current="page"] { background: var(--linen); box-shadow: inset 3px 0 0 var(--gold); color: var(--navy); }
.nav-extra .ico { color: var(--gold); }
.site-nav > :focus-visible { outline: 2px solid var(--sand); outline-offset: -3px; }
.nav-extra :focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
body.has-nav { padding-bottom: calc(63px + env(safe-area-inset-bottom)); }

/* Shown only when a screen takes a moment, so a quick one does not flicker. */
.loading-bar {
  position: fixed; top: 0; left: var(--side); right: 0; z-index: 50; height: 3px;
  overflow: hidden; opacity: 0; pointer-events: none;
}
.loading-bar::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 35%;
  background: var(--gold);
  animation: loading 1.1s ease-in-out infinite;
}
body.is-loading .loading-bar { opacity: 1; transition: opacity 0.15s 0.25s; }
@keyframes loading { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

main {
  display: block;
  width: 100%;
  padding: 20px var(--gutter) 40px;
}

/* ---- Tablet: a rail of icons ---- */

@media (min-width: 768px) {
  body.has-nav { --side: 92px; padding-bottom: 0; padding-left: var(--side); }
  body.has-nav .site-header {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    width: var(--side);
    flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0;
    padding: 16px 0 12px;
    overflow-y: auto; scrollbar-width: none;
  }
  body.has-nav .brand { flex-direction: column; margin: 0 auto; }
  body.has-nav .badge { width: 52px; height: 52px; }
  body.has-nav .wordmark { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  body.has-nav .pattern-line { order: 0; flex: none; margin: 14px 0 10px; height: 14px; border: 0; background-size: auto 14px; }
  body.has-nav .find-link { margin: 0 12px 8px; min-height: 48px; border: 1px solid rgba(217, 195, 154, 0.35); }
  body.has-nav .site-nav {
    position: static; display: flex; flex-direction: column; gap: 2px;
    padding: 4px 8px; border: 0; background: none;
  }
  body.has-nav .nav-today { order: 0; }
  body.has-nav .nav-more { display: none; }
  body.has-nav .nav-extra {
    position: static; display: flex; flex-direction: column; gap: 2px;
    min-width: 0; padding: 0; border: 0; background: none; box-shadow: none;
  }
  body.has-nav .site-nav a, body.has-nav .nav-extra a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 60px; padding: 6px 2px; border-radius: 8px;
    color: rgba(255, 255, 255, 0.78); background: none; box-shadow: none;
    font: 700 0.7rem var(--font-body); text-align: center; white-space: normal;
  }
  body.has-nav .nav-extra .ico { color: inherit; }
  body.has-nav .site-nav a:hover, body.has-nav .nav-extra a:hover { background: rgba(255, 255, 255, 0.07); color: var(--paper); }
  body.has-nav .site-nav a[aria-current="page"], body.has-nav .nav-extra a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.1); color: var(--paper); box-shadow: inset 3px 0 0 var(--gold);
  }
  body.has-nav .site-nav a[aria-current="page"] .ico { color: var(--sand); }
  body.has-nav .side-foot { flex-direction: column; margin-top: auto; padding: 12px 8px 0; gap: 8px; }
  body.has-nav .who { flex-direction: column; }
  body.has-nav .who-out { padding: 0 8px; font-size: 0.75rem; }
  body.has-nav .loading-bar { position: fixed; }
}

/* ---- Desktop: the sidebar ---- */

@media (min-width: 1024px) {
  body.has-nav { --side: 248px; }
  body.has-nav .site-header { padding: 22px 0 16px; }
  body.has-nav .brand { flex-direction: row; gap: 12px; margin: 0 20px; }
  body.has-nav .badge { width: 56px; height: 56px; }
  body.has-nav .wordmark { position: static; width: auto; height: auto; overflow: visible; clip: auto; font-size: 1.45rem; }
  body.has-nav .pattern-line { margin: 18px 0 16px; height: 18px; background-size: auto 18px; }
  body.has-nav .find-link {
    justify-content: flex-start; gap: 10px;
    margin: 0 16px 14px; min-height: 42px; padding: 0 10px 0 12px;
    background: rgba(255, 255, 255, 0.06); color: rgba(255, 255, 255, 0.8);
  }
  body.has-nav .find-link span { display: inline; flex: 1; text-align: left; font-weight: 400; }
  body.has-nav .find-link kbd { display: inline; }
  body.has-nav .find-link .ico { width: 18px; height: 18px; }
  body.has-nav .site-nav { padding: 0 12px; gap: 2px; }
  body.has-nav .site-nav a, body.has-nav .nav-extra a {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    min-height: 44px; padding: 0 14px; border-radius: 6px;
    font: 700 1rem var(--font-body); text-align: left;
  }
  body.has-nav .nav-extra { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(217, 195, 154, 0.2); }
  body.has-nav .side-foot { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 20px 0; border-top: 1px solid rgba(217, 195, 154, 0.2); margin: 16px 0 0; margin-top: auto; }
  body.has-nav .who { flex-direction: row; flex-wrap: wrap; width: 100%; justify-content: space-between; }
  body.has-nav .who-name { display: block; color: var(--sand); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
  body.has-nav .who-out { font-size: 0.82rem; }
  main { max-width: 1640px; }
}

/* The crew's screens have no nav: the band on top at every width, the work centred below. */
body.is-crew main { max-width: 920px; margin: 0 auto; }
