/* ============================================================
   Page chrome primitives
   Shared layout elements layered on top of Bootstrap 5:
     - .page-action-bar   Sticky, intent-coloured action bar
     - .collapsible-section  Collapsible/expandable content blocks
     - .info-tile  Infographic tiles for replacing label:value rows
     - .slam-pill  Compact chips for tags/trades/etc.
   ============================================================ */

:root {
  /* Height of the fixed top site nav — the action bar sits just below this. */
  --page-chrome-navbar-offset: 56px;
  --page-action-bar-gap: 0.5rem;
  --page-action-bar-pad-y: 0.6rem;
  --page-action-bar-pad-x: 0.9rem;
  --page-action-bar-bg: rgba(255, 255, 255, 0.96);
  --page-action-bar-border: rgba(15, 23, 42, 0.08);
  --page-action-bar-shadow: 0 6px 18px -8px rgba(15, 23, 42, 0.25);
  --page-action-bar-height: 0px;
}

[data-bs-theme="dark"] {
  --page-action-bar-bg: rgba(33, 37, 41, 0.96);
  --page-action-bar-border: rgba(255, 255, 255, 0.08);
  --page-action-bar-shadow: 0 6px 24px -10px rgba(0, 0, 0, 0.7);
}

/* ---------- Floating page action bar ----------
   Uses position:fixed so it works regardless of ancestor overflow/transform
   (position:sticky was unreliable because #main-content has overflow-x:hidden
   which makes sticky's scroll-container resolution inconsistent).
   The bar is constrained horizontally to the content area (right of the fixed
   left sidebar). A matching top padding on the page shell reserves space
   so the first card is not hidden behind the bar. The padding value is
   written to --page-action-bar-height by static/js/page-action-bar.js. */
.page-action-bar {
  position: fixed;
  top: var(--page-chrome-navbar-offset);
  /* --modal-safe-left is defined in base.html and follows the sidebar
     expanded/collapsed state via body.sidebar-expanded. Using it keeps the
     action bar aligned with the content area no matter the sidebar state. */
  left: var(--modal-safe-left, 80px);
  right: 0;
  /* Above page content but below the fixed top nav, whose menus must overlay
     page-level action controls. */
  z-index: 5500;
  display: flex;
  align-items: center;
  gap: var(--page-action-bar-gap);
  flex-wrap: wrap;
  padding: var(--page-action-bar-pad-y) var(--page-action-bar-pad-x);
  margin: 0 1rem;
  background: var(--page-action-bar-bg);
  border: 1px solid var(--page-action-bar-border);
  border-radius: 0.9rem;
  box-shadow: var(--page-action-bar-shadow);
  backdrop-filter: saturate(150%) blur(6px);
  -webkit-backdrop-filter: saturate(150%) blur(6px);
  transition: padding 0.2s ease, border-radius 0.2s ease, gap 0.2s ease,
              left 0.3s ease;
}

/* A class added by page-action-bar.js to the bar's nearest ancestor
   (.slam-page-shell or the bar's parent if no shell is found). Reserves
   vertical space equal to the bar's measured height so the first card is
   not hidden under the fixed bar. */
.has-page-action-bar {
  padding-top: calc(var(--page-action-bar-height, 0px) + 0.75rem);
}

@media (max-width: 576px) {
  .page-action-bar {
    margin: 0 0.5rem;
  }
}

/* Hide the floating action bar entirely while a modal is open so the bar's
   pills cannot visually float over the modal's header / close button.
   Three selectors so this works regardless of which mechanism puts the
   "modal is open" signal on the page:
     - body.modal-open  — Bootstrap's standard class
     - body.has-open-modal — fallback class set by static/js/page-action-bar.js
       (Bootstrap modal shown.bs.modal / hidden.bs.modal listeners)
     - body:has(.modal.show)  — modern :has() selector for browsers that
       support it, in case the Bootstrap class never lands. */
body.modal-open .page-action-bar,
body.has-open-modal .page-action-bar,
body:has(.modal.show) .page-action-bar {
  display: none !important;
}

.page-action-bar__title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-right: auto;
  min-width: 0;
}

.page-action-bar__title h1,
.page-action-bar__title h2,
.page-action-bar__title .h-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--bs-emphasis-color);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-action-bar__title small,
.page-action-bar__title .subtitle {
  color: var(--bs-secondary-color);
  font-size: 0.78rem;
  line-height: 1.2;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-action-bar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--page-action-bar-gap);
  align-items: center;
}

.page-action-bar__actions .btn-action,
.page-action-bar__actions .btn {
  transition: padding 0.18s ease, font-size 0.18s ease, border-radius 0.18s ease;
}

.page-action-bar .dropdown-menu {
  /* Must sit above the bar itself (z-index: 5500) so the menu isn't clipped
     behind the bar's own background and shadow. */
  z-index: 5600;
}

/* Condensed / scrolled state */
.page-action-bar.is-condensed {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  gap: 0.35rem;
}

.page-action-bar.is-condensed .page-action-bar__title h1,
.page-action-bar.is-condensed .page-action-bar__title h2,
.page-action-bar.is-condensed .page-action-bar__title .h-title {
  font-size: 0.95rem;
}

.page-action-bar.is-condensed .page-action-bar__title small,
.page-action-bar.is-condensed .page-action-bar__title .subtitle {
  display: none;
}

.page-action-bar.is-condensed .btn-action,
.page-action-bar.is-condensed .btn {
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  border-radius: 999px;
}

.page-action-bar.is-condensed .btn-action > i,
.page-action-bar.is-condensed .btn > i {
  font-size: 0.85em;
}

@media (max-width: 576px) {
  .page-action-bar {
    padding: 0.5rem 0.65rem;
    border-radius: 0.8rem;
  }

  .page-action-bar__title h1,
  .page-action-bar__title h2,
  .page-action-bar__title .h-title {
    font-size: 1rem;
  }
}

/* ---------- Collapsible sections ---------- */
.collapsible-section {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.9rem;
  box-shadow: var(--bs-box-shadow-sm);
  margin-bottom: 1rem;
  overflow: hidden;
}

.collapsible-section > .collapsible-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  cursor: pointer;
  user-select: none;
  width: 100%;
  text-align: left;
  color: var(--bs-emphasis-color);
  transition: background-color 0.15s ease;
}

.collapsible-section > .collapsible-header:hover {
  background: var(--bs-tertiary-bg);
}

.collapsible-section > .collapsible-header:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: -2px;
}

.collapsible-section > .collapsible-header .chevron {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
  transition: transform 0.2s ease;
  flex: 0 0 auto;
}

.collapsible-section.is-open > .collapsible-header .chevron {
  transform: rotate(90deg);
}

.collapsible-section > .collapsible-header .cs-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.15;
  color: inherit;
}

.collapsible-section > .collapsible-header .cs-subtitle {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
  margin-left: 0.5rem;
  font-weight: 400;
}

.collapsible-section > .collapsible-header .cs-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.collapsible-section > .collapsible-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid transparent;
}

.collapsible-section.is-open > .collapsible-body {
  border-top-color: var(--bs-border-color);
  padding-top: 1rem;
}

.collapsible-section:not(.is-open) > .collapsible-body {
  display: none;
}

/* ---------- Auto-wrapped Bootstrap cards (made collapsible on click) ---------- */
.auto-collapsible-card .auto-collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease;
}

.auto-collapsible-card .auto-collapsible-header:hover {
  background: var(--bs-tertiary-bg);
}

.auto-collapsible-card .auto-collapsible-header:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: -2px;
}

.auto-collapsible-card .auto-card-chevron {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
  transition: transform 0.2s ease;
  flex: 0 0 auto;
}

.auto-collapsible-card.is-closed .card-body {
  display: none;
}

/* Variant: insights (quiet card for deeper analytics at the bottom) */
.collapsible-section.is-insights {
  background: var(--bs-tertiary-bg);
}

.collapsible-section.is-insights > .collapsible-header .cs-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--bs-info);
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* ---------- Info tiles (infographic-style replacement for label:value rows) ---------- */
.info-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.info-tile {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.8rem;
  background: var(--bs-body-bg);
  min-height: 90px;
  position: relative;
  overflow: hidden;
}

.info-tile__icon {
  width: 36px;
  height: 36px;
  border-radius: 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 110, 253, 0.12);
  color: #0d6efd;
  font-size: 1rem;
}

.info-tile__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  font-weight: 600;
  line-height: 1.15;
}

.info-tile__value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--bs-emphasis-color);
  line-height: 1.2;
  word-break: break-word;
}

.info-tile__meta {
  font-size: 0.78rem;
  color: var(--bs-secondary-color);
  line-height: 1.2;
}

.info-tile.is-success .info-tile__icon {
  background: rgba(25, 135, 84, 0.14);
  color: #198754;
}

.info-tile.is-danger .info-tile__icon {
  background: rgba(220, 53, 69, 0.14);
  color: #dc3545;
}

.info-tile.is-warning .info-tile__icon {
  background: rgba(240, 160, 0, 0.18);
  color: #b67300;
}

.info-tile.is-info .info-tile__icon {
  background: rgba(13, 202, 240, 0.18);
  color: #087990;
}

.info-tile.is-muted .info-tile__icon {
  background: rgba(108, 117, 125, 0.18);
  color: #6c757d;
}

[data-bs-theme="dark"] .info-tile.is-success .info-tile__icon {
  color: #6dd4a1;
}
[data-bs-theme="dark"] .info-tile.is-danger .info-tile__icon {
  color: #f58a96;
}
[data-bs-theme="dark"] .info-tile.is-warning .info-tile__icon {
  color: #ffc864;
}
[data-bs-theme="dark"] .info-tile.is-info .info-tile__icon {
  color: #7cdbf2;
}
[data-bs-theme="dark"] .info-tile.is-muted .info-tile__icon {
  color: #adb5bd;
}

/* Big scope status callout (used on Work Pack Detail) */
.scope-callout {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 0.9rem;
  border: 1px solid transparent;
  background: var(--bs-body-bg);
}

.scope-callout__icon {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex: 0 0 auto;
}

.scope-callout__label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  line-height: 1.1;
}

.scope-callout__value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.15;
}

.scope-callout.is-in-scope {
  background: rgba(25, 135, 84, 0.1);
  border-color: rgba(25, 135, 84, 0.35);
}

.scope-callout.is-in-scope .scope-callout__icon {
  background: rgba(25, 135, 84, 0.18);
  color: #198754;
}

.scope-callout.is-in-scope .scope-callout__value {
  color: #198754;
}

.scope-callout.is-out-of-scope {
  background: rgba(220, 53, 69, 0.1);
  border-color: rgba(220, 53, 69, 0.4);
}

.scope-callout.is-out-of-scope .scope-callout__icon {
  background: rgba(220, 53, 69, 0.2);
  color: #dc3545;
}

.scope-callout.is-out-of-scope .scope-callout__value {
  color: #dc3545;
}

[data-bs-theme="dark"] .scope-callout.is-in-scope .scope-callout__value {
  color: #6dd4a1;
}

[data-bs-theme="dark"] .scope-callout.is-out-of-scope .scope-callout__value {
  color: #f58a96;
}

/* ---------- SLAM pills ---------- */
.slam-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bs-tertiary-bg);
  color: var(--bs-emphasis-color);
  border: 1px solid var(--bs-border-color);
  line-height: 1.3;
  white-space: nowrap;
}

.slam-pill.is-primary {
  background: rgba(13, 110, 253, 0.12);
  color: #0d6efd;
  border-color: rgba(13, 110, 253, 0.3);
}

.slam-pill.is-success {
  background: rgba(25, 135, 84, 0.14);
  color: #198754;
  border-color: rgba(25, 135, 84, 0.35);
}

.slam-pill.is-warning {
  background: rgba(240, 160, 0, 0.18);
  color: #996200;
  border-color: rgba(240, 160, 0, 0.4);
}

.slam-pill.is-danger {
  background: rgba(220, 53, 69, 0.14);
  color: #dc3545;
  border-color: rgba(220, 53, 69, 0.4);
}

.slam-pill.is-info {
  background: rgba(13, 202, 240, 0.16);
  color: #087990;
  border-color: rgba(13, 202, 240, 0.35);
}

[data-bs-theme="dark"] .slam-pill.is-primary { color: #6ea8fe; }
[data-bs-theme="dark"] .slam-pill.is-success { color: #6dd4a1; }
[data-bs-theme="dark"] .slam-pill.is-warning { color: #ffc864; }
[data-bs-theme="dark"] .slam-pill.is-danger { color: #f58a96; }
[data-bs-theme="dark"] .slam-pill.is-info { color: #7cdbf2; }

.slam-pill-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
