/*
  Base typography, resets, and the app page shell (header + collapsible navigation).
  Depends on tokens.css. See docs/design-system/design-principles.md.
*/

body {
  margin: 0;
  font-family: var(--font-base);
  font-size: var(--font-size-body);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

h1, .page-title {
  font-size: var(--font-size-title);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  margin: 0 0 var(--space-md);
}

h2, .section-heading {
  font-size: var(--font-size-heading);
  font-weight: var(--font-weight-semibold);
  color: var(--color-primary);
  margin: 0 0 var(--space-sm);
}

/* UI pass 2: sub-headings inside a .tile-subsection (see components.css) - a smaller step than
   h2, but still on-brand navy rather than the browser's unstyled bold-black default.
   Typeface pass: given its own type-scale step (--font-size-subheading/--font-weight-medium)
   rather than reusing body size/bold, so hierarchy between h2 and h3 is carried by type. */
h3 {
  font-size: var(--font-size-subheading);
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
  margin: 0 0 var(--space-sm);
}

/* Typeface pass: machine/reference identifiers (quote/job/PO numbers) - applied specifically to
   these, not to money/date/count values generally. See docs/design-system/design-principles.md. */
.reference-number {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-medium);
}

a {
  color: var(--color-accent);
}

a:hover {
  color: var(--color-accent-dark);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius);
}

/* ---- Page shell: header + collapsible navigation ---- */

.app-shell-header {
  position: sticky;
  top: 0;
  z-index: var(--z-shell-header);
  background-color: var(--color-primary);
  box-shadow: var(--shadow-card);
}

.app-shell-header__bar {
  max-width: var(--content-width-list);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  flex-wrap: wrap;
}

.app-shell-brand {
  font-size: var(--font-size-heading);
  font-weight: var(--font-weight-bold);
  color: #FFFFFF;
  text-decoration: none;
  padding: var(--space-xs) 0;
}

.app-shell-brand:hover,
.app-shell-brand:focus-visible {
  color: #FFFFFF;
  text-decoration: underline;
}

.app-shell-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
}

.app-shell-toggle__icon,
.app-shell-toggle__icon::before,
.app-shell-toggle__icon::after {
  display: block;
  width: 20px;
  height: 2px;
  background-color: #FFFFFF;
  border-radius: 1px;
}

.app-shell-toggle__icon {
  position: relative;
}

.app-shell-toggle__icon::before,
.app-shell-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.app-shell-toggle__icon::before {
  top: -6px;
}

.app-shell-toggle__icon::after {
  top: 6px;
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  margin-left: var(--space-lg);
}

.app-nav__list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: var(--space-xs);
}

.app-nav__item {
  position: relative;
}

.app-nav__link {
  display: block;
  padding: var(--space-sm) var(--space-sm);
  color: #FFFFFF;
  text-decoration: none;
  border-radius: var(--radius);
  transition: background-color var(--transition-fast);
}

.app-nav__link:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
}

.app-nav__link:focus-visible {
  box-shadow: var(--focus-ring);
}

.app-nav__link.active {
  background-color: rgba(255, 255, 255, 0.18);
  font-weight: var(--font-weight-bold);
}

.app-nav__submenu {
  list-style: none;
  margin: 0;
  padding: var(--space-xs);
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  background-color: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
  display: none;
  z-index: var(--z-shell-header);
}

.app-nav__item:hover > .app-nav__submenu,
.app-nav__item:focus-within > .app-nav__submenu,
.app-nav__item.expanded > .app-nav__submenu {
  display: block;
}

/* A mega-menu group's trigger is a real <button> (not a link with no destination of its own) -
   see Views/Shared/_MainNav.cshtml and the record action bar's flyout trigger, which shares this
   exact same interaction pattern. Reset native button chrome so it looks identical to a plain
   .app-nav__link, then add a small chevron so it's visually obvious it opens a panel. */
.app-nav__group-trigger {
  background: transparent;
  border: none;
  font: inherit;
  cursor: pointer;
}

.app-nav__group-trigger::after {
  content: "\25BE";
  margin-left: var(--space-xs);
  font-size: 0.7em;
  vertical-align: middle;
}

.app-nav__submenu .app-nav__link {
  color: var(--color-text);
  padding: var(--space-sm);
}

.app-nav__submenu .app-nav__link:hover {
  background-color: var(--color-bg-subtle);
}

.app-nav__account {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: #FFFFFF;
}

.app-nav__account-name {
  font-weight: var(--font-weight-bold);
}

.app-nav__account-btn.btn-outline {
  background-color: transparent;
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.6);
}

.app-nav__account-btn.btn-outline:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
}

.app-main {
  max-width: var(--content-width-list);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md) var(--space-xl);
}

/* UI foundation pass: list/search pages keep the wider (1200px) default above - unconstrained,
   no page changes needed. Detail/record pages opt into the narrower legacy width by setting
   ViewData["PageWidth"] = "detail" (see _Layout.cshtml), which adds this modifier - the single
   central place both widths live, per the phase brief's "central design tokens, not page by
   page" requirement. .record-header (UI pass 3) is capped at the same width so it lines up with
   the narrower content it sits above. */
.app-main--detail {
  max-width: var(--content-width-detail);
}

.auth-layout {
  display: flex;
  justify-content: center;
  padding-top: var(--space-lg);
}

.app-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
  padding: var(--space-md);
  text-align: center;
}

.app-footer a {
  color: var(--color-text-muted);
}

@media (max-width: 768px) {
  .app-shell-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    margin-left: 0;
    margin-top: var(--space-sm);
  }

  .app-nav.show {
    display: flex;
  }

  .app-nav__list {
    flex-direction: column;
    width: 100%;
  }

  .app-nav__submenu {
    position: static;
    box-shadow: none;
    background-color: transparent;
    padding-left: var(--space-md);
  }

  .app-nav__item:hover > .app-nav__submenu,
  .app-nav__item:focus-within > .app-nav__submenu {
    display: none;
  }

  .app-nav__item.expanded > .app-nav__submenu {
    display: block;
  }

  .app-nav__account {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid rgba(255, 255, 255, 0.25);
    width: 100%;
    justify-content: space-between;
  }
}

/* ---- Responsive tile/card grid (dashboard-style layouts) ---- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

@media (max-width: 768px) {
  .tile-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .tile-grid {
    grid-template-columns: 1fr;
  }
}
