/* Rev5 "app feel" layer, shared by Parent, Projects, Tuition, and Events.
   Loaded next to rev5-sidebar.js. Rules use :where() so each app's own styles still win. */

:root {
  --rev5-brand: #172e2a;
  --rev5-accent: #4f8a6b;
  --rev5-skeleton: #e4e9e6;
  --rev5-skeleton-shine: #f3f6f4;
}

/* ---------------------------------------------------------------- touch basics */

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior-y: none;
}

:where(dialog, [role="dialog"], .modal, .modal-body, .menu) {
  overscroll-behavior: contain;
}

/* App chrome is tapped, not read: no accidental text selection or callouts on long-press. */
:where(nav, .tabs, .bottom-tabs, .view-tabs, .toolbar-actions, .page-header .header-actions, button, .button) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

@media (pointer: coarse) {
  /* 16px stops iOS zooming the page when a field is focused. */
  :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"]), select, textarea) {
    font-size: max(16px, 1em);
  }

  :where(button, .button, [role="button"], a.tab, .tab) {
    min-height: 44px;
  }

  :where(button, .button) {
    touch-action: manipulation;
  }
}

/* ---------------------------------------------------------------- button feedback */

:where(button, .button, [role="button"]) {
  transition-property: transform, opacity, background-color, border-color, color, box-shadow;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

:where(button, .button, [role="button"]):active:not(:disabled, [aria-disabled="true"], [aria-busy="true"]) {
  transform: scale(0.97);
  opacity: 0.88;
}

/* A save or submit that is waiting on the server: an inline spinner, and no second press. */
[data-rev5-busy] {
  position: relative;
  pointer-events: none;
  cursor: progress;
}

[data-rev5-busy]::after {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.5em;
  vertical-align: -0.12em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: rev5-spin 700ms linear infinite;
}

/* ---------------------------------------------------------------- loading: skeletons and spinner */

.rev5-loading {
  display: grid;
  gap: 12px;
  padding: 4px 0;
  /* Hidden for the first 150ms so a fast load never flashes a skeleton. */
  animation: rev5-appear 160ms ease-out 150ms both;
}

.rev5-loading-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.rev5-skeleton {
  display: block;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--rev5-skeleton) 0%, var(--rev5-skeleton-shine) 45%, var(--rev5-skeleton) 90%);
  background-size: 300% 100%;
  animation: rev5-shimmer 1.3s ease-in-out infinite;
}

.rev5-skeleton-title { width: min(260px, 60%); height: 22px; }
.rev5-skeleton-line { width: 100%; height: 12px; border-radius: 6px; }
.rev5-skeleton-line.short { width: 55%; }
.rev5-skeleton-row { height: 54px; }
.rev5-skeleton-card { height: 124px; }

.rev5-skeleton-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.rev5-skeleton-rows {
  display: grid;
  gap: 8px;
}

.rev5-spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--rev5-skeleton);
  border-top-color: var(--rev5-accent);
  border-radius: 50%;
  animation: rev5-spin 700ms linear infinite;
}

/* ---------------------------------------------------------------- first paint */

/* Until rev5-sidebar.js defines the sidebar, draw its dark column (top bar on phones) in place, so a page
   never starts as a blank screen and the layout doesn't jump when the sidebar arrives. */
:root {
  --rev5-sidebar-offset: 244px;
}

/* Projects lets people hide the sidebar on wide screens (a class on <html>, set before first paint). */
@media (min-width: 881px) {
  html.rev5-sidebar-collapsed {
    /* Room for the Show sidebar button at the top left. */
    --rev5-sidebar-offset: 28px;
  }

  html.rev5-sidebar-collapsed rev5-shell-sidebar:not(:defined),
  html.rev5-sidebar-collapsed .rev5-boot::before {
    display: none;
  }
}

rev5-shell-sidebar:not(:defined),
.rev5-boot::before {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  display: block;
  width: 244px;
  background: #172e2a;
  content: "";
}

/* Single-page apps (Projects, Events, Tuition) ship this inside #app; their first render replaces it. */
.rev5-boot {
  display: grid;
  gap: 14px;
  max-width: 1100px;
  padding: 34px 32px 32px calc(var(--rev5-sidebar-offset, 244px) + 32px);
}

@media (max-width: 880px) {
  rev5-shell-sidebar:not(:defined),
  .rev5-boot::before {
    inset: 0 0 auto 0;
    width: auto;
    height: calc(52px + env(safe-area-inset-top));
  }

  .rev5-boot {
    padding: calc(52px + env(safe-area-inset-top) + 22px) 16px 16px;
  }
}

/* ---------------------------------------------------------------- top progress bar */

#rev5-progress {
  position: fixed;
  z-index: 2147483000;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  width: 100%;
  height: 3px;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left center;
  opacity: 0;
  background: linear-gradient(90deg, var(--rev5-accent), #8cc3a1);
  box-shadow: 0 0 8px rgba(79, 138, 107, 0.45);
  transition: transform 260ms ease-out, opacity 220ms ease 120ms;
}

#rev5-progress.is-active {
  opacity: 1;
  transition: transform 2.4s cubic-bezier(0.1, 0.6, 0.3, 1), opacity 120ms ease;
}

#rev5-progress.is-done {
  opacity: 0;
  transform: scaleX(1);
}

/* ---------------------------------------------------------------- page transitions */

/* Same-origin page loads cross-fade where the browser supports it (Safari 18.2+, Chrome 126+). */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: 120ms ease-in both rev5-fade-out;
}

::view-transition-new(root) {
  animation: 180ms ease-out both rev5-fade-in;
}

/* Elsewhere, the page body fades in quickly instead of popping. */
@supports not (view-transition-name: none) {
  body {
    animation: rev5-fade-in 160ms ease-out both;
  }
}

/* ---------------------------------------------------------------- sheets and modals on phones */

@media (max-width: 700px) {
  dialog[open] {
    animation: rev5-sheet-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  dialog::backdrop {
    animation: rev5-fade-in 200ms ease-out both;
  }
}

/* ---------------------------------------------------------------- keyframes */

@keyframes rev5-spin {
  to { transform: rotate(360deg); }
}

@keyframes rev5-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@keyframes rev5-appear {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rev5-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rev5-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes rev5-sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------------------------------------------------------------- reduced motion: one switch for the whole suite */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }

  .rev5-skeleton {
    background: var(--rev5-skeleton);
  }
}

/* iPad home-screen app: iPadOS draws a Liquid Glass edge blur over the top ~40px of the page. WebKit skips that blur
   and paints the status bar in a solid colour when a fixed, opaque element at least ~10px tall spans the top edge;
   it hit-tests a point a few pixels below the top's midpoint, so the element must be a real DOM node and take pointer
   events. (Pseudo-elements are not returned by hit-testing, which is why the earlier body::before band had no
   effect.) Each shared-shell entry point puts .rev5-top-edge first in body. Safari in the browser has no blur, so
   only the installed app gets it; any-pointer: coarse catches an iPad even with a trackpad keyboard, and the minimum
   height leaves phones out, landscape included. Page-level sticky headers stick below it at --rev5-top-bar. */
@media (display-mode: standalone) and (any-pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  :root {
    --rev5-top-bar: 12px;
  }

  .rev5-top-edge {
    position: fixed;
    z-index: 2147482998;
    top: 0;
    right: 0;
    left: 0;
    height: var(--rev5-top-bar);
    background-color: #172e2a;
    pointer-events: auto;
  }
}

/* A child app's first paint, before its own shell exists. */
.rev5-boot {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 16px 24px;
}

/* ---------------------------------------------------------------- phone navigation (built by rev5-sidebar.js) */

/* Below 881px the shared top bar is 52px tall. Pages with a sticky header use --rev5-phone-top so it also clears the
   tab row when there is one. */
:root {
  --rev5-phone-top: calc(52px + env(safe-area-inset-top));
}

.rev5-app-bar,
.rev5-tabs {
  display: none;
}

@media (max-width: 880px) {
  body.has-rev5-tabs {
    --rev5-phone-top: calc(96px + env(safe-area-inset-top));
    padding-top: 44px;
  }

  /* The current app's tabs, in a row under the top bar. */
  .rev5-tabs:not([hidden]) {
    position: fixed;
    top: calc(52px + env(safe-area-inset-top));
    right: 0;
    left: 0;
    z-index: 19;
    display: flex;
    height: 44px;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    border-bottom: 1px solid #dfe5e1;
    background: #fffefa;
    scrollbar-width: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .rev5-tabs::-webkit-scrollbar {
    display: none;
  }

  .rev5-tab {
    position: relative;
    display: inline-flex;
    min-height: 32px;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 0 13px;
    border-radius: 999px;
    color: #3d4b47;
    background: #edf2ef;
    font-size: 13px;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
    -webkit-touch-callout: none;
  }

  .rev5-tab.is-active {
    color: #fff;
    background: var(--rev5-brand);
  }

  /* A tab that opens a sheet instead of a page (Projects: Jump to). */
  /* It stays at the right end of the row, even when the other tabs scroll underneath it. */
  .rev5-tab.is-action {
    position: sticky;
    right: 0;
    z-index: 1;
    gap: 4px;
    margin-left: auto;
    border: 1px solid #c9d6cf;
    color: var(--rev5-brand);
    background: #fffefa;
    box-shadow: -14px 0 12px -4px #fffefa;
  }

  .rev5-tab:focus-visible {
    outline: 2px solid var(--rev5-accent);
    outline-offset: 2px;
  }

  .rev5-tab-badge {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    color: white;
    background: #b5523f;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
  }

  /* Four pins and the Apps button. */
  .rev5-app-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(var(--rev5-app-bar-columns, 5), minmax(0, 112px));
    justify-content: center;
    padding: 4px max(6px, env(safe-area-inset-right)) max(4px, calc(env(safe-area-inset-bottom) - 10px)) max(6px, env(safe-area-inset-left));
    border-top: 1px solid #dfe5e1;
    background: #fffefa;
    box-shadow: 0 -6px 20px rgba(23, 46, 42, 0.06);
    -webkit-user-select: none;
    user-select: none;
  }

  .rev5-app-bar-item {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 50px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 2px;
    border: 0;
    border-radius: 10px;
    color: #66746f;
    background: none;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    -webkit-touch-callout: none;
  }

  .rev5-app-bar-item:focus-visible {
    outline: 2px solid var(--rev5-accent);
    outline-offset: -2px;
  }

  .rev5-app-bar-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rev5-app-bar-icon {
    position: relative;
    display: grid;
    width: 44px;
    height: 28px;
    place-items: center;
    border-radius: 999px;
    transition: background-color 160ms ease;
  }

  /* A pinned tab's app colour. */
  .rev5-app-bar-from {
    position: absolute;
    top: 1px;
    right: 7px;
    width: 8px;
    height: 8px;
    border: 1.5px solid #fffefa;
    border-radius: 50%;
  }

  .rev5-app-bar-item.is-active {
    color: var(--rev5-brand);
  }

  .rev5-app-bar-item.is-active .rev5-app-bar-icon {
    background: #dfeee4;
  }

  .rev5-app-bar-item:active .rev5-app-bar-icon {
    transform: scale(0.94);
  }

  .rev5-app-bar-badge {
    position: absolute;
    top: 3px;
    left: calc(50% + 8px);
    min-width: 18px;
    padding: 1px 5px;
    border-radius: 999px;
    color: white;
    background: #b5523f;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
  }

  body.has-rev5-app-bar {
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
  }

  /* The tab row replaces each app's own tabs at the top of the page. */
  body.has-rev5-tabs :is(.inventory-tabs, .staff-area-tabs, .finance-tabs) {
    display: none;
  }

  body.has-rev5-app-bar .toast,
  body.has-rev5-app-bar [data-rev5-masquerade-banner] {
    margin-bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

/* Classic navigation (chosen per device): the menu drawer for apps, and on phones a bar with the current app's tabs
   in place of its own tabs at the top of the page. */
.rev5-app-bar[hidden] {
  display: none;
}

@media (min-width: 701px) and (max-width: 880px) {
  html.rev5-nav-classic .rev5-app-bar {
    display: none;
  }

  html.rev5-nav-classic body.has-rev5-app-bar {
    padding-bottom: 0;
  }
}

@media (max-width: 700px) {
  html.rev5-nav-classic body.has-rev5-app-bar :is(.inventory-tabs, .staff-area-tabs, .finance-tabs) {
    display: none;
  }
}
