/* FRRS shared component primitives (shadcn-derived): button, card, badge,
   input/form-field, table, alert, avatar, tabs, pagination, modal, checkbox,
   segmented, filters, dl-grid, actions, empty-state, sr-only, and the shared
   responsive mobile-cards list swap. Loaded on every page right after
   base.css (cascade: tokens → components → page scopes). */

/* Card — a column flex container whose gap is the single ruler of internal
   spacing. Direct children drop their own block margins (see the layout-reset
   section at the end of this file) so the gap is consistent across every card
   instead of doubling up with per-component margin rules. */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--card-gap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* List card — the standard layout for every paginated list page. The card
   stretches to fill the remaining viewport height (`.app-main` is a flex
   column inside the `.app-shell` grid, whose row tracks the sticky 100vh
   sidebar), the heading/filters stay pinned at the top, the table region
   scrolls internally, and the pagination control sits at the bottom. Applied
   opt-in via `card card--list` so dashboard multi-card pages and the bounded
   reference-data tables keep their natural height. */
.card--list {
  flex: 1 1 auto;
  min-height: 0;
}

/* The table region grows to absorb leftover height and scrolls internally so
   the heading and pagination stay visible even with few/many rows. */
.card--list > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* The shared pagination control (see `_pagination.html`). A flat row anchored
   at the foot of a list card: Previous / "Page N" / Next. */
.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pagination__page {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Card section heading (used inside dashboard cards and reference-data
   tables alike). */
.card__heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.card__heading h2 {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card__heading p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Inline segmented group: a lightweight, borderless wrapper for a small set of
   toggle links (e.g. the Repairs list's Open / Done / All status filter). It is
   intentionally NOT the heavyweight `.filters` disclosure card — just enough
   flex layout to hold a label + a row of buttons that wraps on narrow screens. */
.segmented {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 var(--card-gap);
}

/* Button + variants — shadcn shape (rounded, medium weight) translated to the
   FRRS token layer. Default is the neutral secondary; modifiers layer on the
   variant surface/colour. A subtle press-down (translateY) mirrors the demo's
   active feedback without a per-variant rule. */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  white-space: nowrap;
  vertical-align: middle;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: var(--secondary);
  color: var(--text);
  transition: background-color 0.12s, border-color 0.12s, filter 0.12s;
}

.button:hover {
  filter: brightness(0.96);
}

.button:active {
  transform: translateY(1px);
}

.button--primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.button--success {
  background: var(--success);
  color: var(--primary-foreground);
}

.button--secondary {
  background: var(--secondary);
  color: var(--text);
}

/* Ghost: no chrome until hover, matching the demo's quiet tertiary action. */
.button--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}

.button--ghost:hover {
  filter: none;
  background: color-mix(in srgb, var(--text) 7%, transparent);
}

/* Outline: a bordered surface button — the demo's default "quiet but present"
   action (e.g. Edit / secondary CTAs). */
.button--outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.button--outline:hover {
  filter: none;
  background: color-mix(in srgb, var(--text) 6%, var(--surface));
}

/* Destructive: soft red tint (not solid) so the primary red CTA stays the loud
   one. The legacy .button--danger alias resolves here. */
.button--destructive,
.button--danger {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-color: transparent;
  color: var(--primary);
}

.button--destructive:hover,
.button--danger:hover {
  filter: none;
  background: color-mix(in srgb, var(--primary) 20%, transparent);
}

.button--sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.button--icon {
  flex: none;
  padding: 0.55rem;
}

.danger-zone {
  display: grid;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.danger-zone > h2,
.danger-zone > p {
  margin: 0;
}

.danger-zone form {
  display: grid;
  gap: 0.75rem;
}

.danger-zone > .button,
.danger-zone form > .button {
  width: fit-content;
}

.danger-zone > .button {
  margin-top: 0.5rem;
}

/* ---------- Modal (shadcn Dialog equivalent) ----------
   The shared native <dialog> modal used by every confirm/prompt popup
   (container delete, deny reason, forklift/board move confirm, move alert).
   The base owns chrome + backdrop; variants only tweak size/padding, and
   sub-elements (title/question/actions) carry the shared typography. */
.modal {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.45);
}

/* Backdrop element for hand-built overlay modals that don't use the native
   <dialog> element (e.g. the bulk-duplicate confirmation). The photo-viewer
   keeps its own darker backdrop for image viewing. */
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
}

/* Larger confirm prompt (forklift / board move, stage-move alert): more room
   and a stronger backdrop for field use. */
.modal--confirm {
  width: min(32rem, calc(100vw - 2rem));
  padding: 1.75rem;
  border-radius: calc(var(--radius) + 2px);
}

.modal--confirm::backdrop {
  background: rgb(0 0 0 / 0.55);
}

/* Wide prompt (container delete): roomier than the default but not a
   full confirm layout. */
.modal--wide {
  width: min(32rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border-radius: 0.75rem;
}

/* Detail modal (forklift move row detail): room for full note and fields. */
.modal--detail {
  width: min(36rem, calc(100vw - 2rem));
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
  padding: 1.5rem;
  border-radius: var(--radius);
}

.modal--detail[open] {
  display: flex;
  flex-direction: column;
}

.modal--detail .modal__header {
  display: flex;
  flex: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.modal--detail .modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.modal--detail .modal__actions {
  flex: none;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
}

.modal--detail .modal__actions .button {
  flex: 0 1 auto;
  min-height: 2.5rem;
  max-width: none;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.table tbody tr[data-forklift-row],
.table tbody tr[data-forklift-row] *,
tr.forklift-row,
tr.forklift-row *,
.mobile-cards__item[data-forklift-row],
.mobile-cards__item[data-forklift-row] * {
  cursor: pointer !important;
}

.forklift-table__notes {
  max-width: 18rem;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}

.forklift-detail-note {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-top: 0.35rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.forklift-detail__field {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.forklift-detail__field:last-child {
  border-bottom: none;
}

/* The title is focused programmatically on open so focus does not land on a
   button; it is non-interactive, so suppress the focus ring/highlight. */
.modal--detail:focus,
.modal--detail .modal__title:focus,
.modal--detail .modal__title:focus-visible {
  outline: none;
}

.forklift-detail__label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.forklift-detail__value {
  font-size: 0.95rem;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  min-width: 0;
}

/* Bottom-sheet drawer (completed calendar day detail): docks to the bottom
   edge instead of centering, fills the width up to a reading max, and hands
   scrolling to an inner panel. */
.modal--drawer {
  width: 100%;
  height: 80vh;
  height: 80dvh;
  max-width: 48rem;
  max-height: 80vh;
  max-height: 80dvh;
  margin: auto auto 0;
  padding: 0;
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.35;
}

.modal__question {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-start;
  margin-top: 1.5rem;
}

.modal__actions--center {
  justify-content: center;
}

.modal__actions .button {
  flex: 1 1 8rem;
  max-width: 12rem;
  min-height: 3.25rem;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 650;
}

.modal__cancel {
  color: var(--text-muted);
}

@media (max-width: 30rem) {
  .modal--confirm {
    padding: 1.25rem;
  }

  .modal__title {
    font-size: 1.2rem;
  }

  .modal__question {
    font-size: 0.95rem;
  }

  .modal__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .modal__actions .button {
    max-width: none;
  }
}

/* ---------- Forms ---------- */
/* Invalid-control ring. Deliberately ordered BEFORE the shared control rule
   below so the focus ring (which follows it) wins while the user is typing in
   an errored control, matching the pre-dedup cascade. */
.form-field
  input[aria-invalid="true"],
.form-field
  select[aria-invalid="true"],
.form-field
  textarea[aria-invalid="true"] {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent);
}

/* Shared text control (shadcn Input equivalent) — the single source of truth
   for the `.input` class and the bare controls inside `.form-field`.
   File inputs, select chevrons and textarea sizing layer on top below. */
.input,
.form-field input:not([type="checkbox"]):not([type="radio"]),
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text);
  font: inherit;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 5%, transparent);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.input:focus,
.form-field input:not([type="checkbox"]):not([type="radio"]):focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);
}

/* Forms */
.form-field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

/* Label and control on one compact row (site pickers, the board move bar).
   The control keeps the remaining width instead of stacking under the label. */
.form-field--inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.form-field--inline > label {
  margin: 0;
  white-space: nowrap;
}

.form-field--inline > :is(input, select) {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

/* Field-level validation feedback. Errored fields get a red ring via
   `aria-invalid` (set by the _forms.html macros) plus an inline message, so the
   user never needs to scroll to find what broke. Uses the primary/danger token
   so the look matches the existing `.alert--danger` banner. */
.form-field--error label,
.form-field__error {
  color: var(--primary);
}

.form-field__error {
  font-size: 0.85rem;
  margin: 0;
}

.form-field__required {
  color: var(--primary);
}

.form-field__hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

/* Helper text that ends a form (e.g. the calculated rebuild total) otherwise
   touches the submit button directly below it. */
.form-field__hint + .button {
  margin-top: 1rem;
}

/* Top-of-form validation summary banner emitted by the `error_summary` macro.
   Sits inside the `.alert--danger` chip; the inner `<ul>` lists whole-form
   messages, so reset browser list styling so it reads as a tight stack of
   lines rather than an indented bullet list. */
.form-errors {
  margin-bottom: 1rem;
}

.form-errors__list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}

.form-errors__list li {
  font-size: 0.9rem;
}

/* Small helper-text line under a form (e.g. "A new container starts at…"). */
.form-help {
  margin: 0.5rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form-field label {
  font-weight: 700;
}

/* Control chrome lives in the shared `.input` rule above. */

/* File inputs: don't stretch to full width (filename row reads better sized
   to content) and restyle the native choose-file button to match .button. */
.form-field input[type="file"] {
  width: auto;
  max-width: min(100%, 28rem);
}

.form-field input[type="file"]::file-selector-button {
  padding: 0.45rem 0.9rem;
  margin-right: 0.6rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--secondary);
  color: var(--text);
  transition: filter 0.12s;
}

.form-field input[type="file"]::file-selector-button:hover {
  filter: brightness(0.96);
}

/* Style the native select consistently across browsers; a custom chevron keeps
   the control on-palette without losing native keyboard behaviour. */
.form-field select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(
      45deg, transparent 50%, var(--text-muted) 50% 62%, transparent 62% 78%, var(--text-muted) 78%
    );
  background-repeat: no-repeat;
  background-size: 0.5rem 0.5rem;
  background-position: right 0.7rem center;
  padding-right: 2rem;
}

.form-field textarea {
  resize: vertical;
  min-height: 5rem;
}

/* Password field with a trailing show/hide toggle button (password-toggle.js).
   The input keeps its normal `.form-field input` styling; the wrapper only
   adds the relative positioning the absolutely-placed button needs, plus
   right padding so typed text never sits under the icon. */
.form-field__password-wrap {
  position: relative;
  display: flex;
}

.form-field__password-wrap input {
  padding-right: 2.5rem;
}

.form-field__password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}

.form-field__password-toggle:hover {
  color: var(--text);
}

.form-field__password-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--radius-sm);
}

.app-icon--eye,
.app-icon--eye-off {
  width: 1.1rem;
  height: 1.1rem;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  align-items: end;
  gap: 0.75rem;
  margin-top: 1.25rem;
  margin-bottom: 2rem;
}

/* Filter card: the container tracking list's collapsible filter panel. A
   native <details>/<summary> styled as a shadcn-style card so the user gets a
   clear clickable bar (icon + label + caret + an "Active" hint when filters
   are applied) and a responsive field grid with room to breathe. No JS: the
   disclosure state is the `open` attribute, auto-set by the template when any
   filter is active. */
.filters {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  margin: 0 0 var(--card-gap);
}

.filters__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 0.75rem 1rem;
  font-weight: 700;
}

.filters__summary::-webkit-details-marker {
  display: none;
}

.filters__summary-text {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.filters__summary-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.filters__summary:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.filters__summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* The field grid owns the inner spacing so the open panel has generous top &
   bottom breathing room; reset .form-field's own bottom margin here so the
   grid gap is the single source of vertical rhythm. */
.filters__form {
  padding: 1.25rem 1rem;
}

.filters__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem 1.25rem;
}

.filters__grid .form-field {
  margin-bottom: 0;
}

.filters__actions {
  margin-top: 1.25rem;
}

/* Always-visible rail can search row at the top of list pages. */
.list-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.list-search__input {
  flex: 1 1 16rem;
  max-width: 28rem;
}

@media (max-width: 720px) {
  .list-search {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .list-search__input {
    flex: 1 1 6rem;
    min-width: 0;
    max-width: none;
  }

  .list-search .button {
    flex: none;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
  }
}

/* Bottom-aligning fields (`align-items: end` above) only works while every
   field is the same height. An inline error `<p>` is a 3rd grid row of
   `.form-field`, so one errored field is taller than its siblings and the
   clean fields' inputs sink to the errored field's error line. Take the
   error out of flow here so each field keeps a label+input height and the
   shared input baseline holds; the reserved `margin-bottom` on the row
   gives the overlay room so it doesn't clip into the next content.

   Shared field-error overlay: used by the bottom-aligned `.inline-form`
   grids here, and by the `.inspection-item__fields` grids in inspections
   (which reserve extra margin on the errored field via
   `.form-field--error`). */
.inline-form .form-field,
.inspection-item__fields .form-field {
  position: relative;
  margin-bottom: 0;
  min-width: 0;
}

.inline-form .form-field__error,
.inspection-item__fields .form-field__error {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0.35rem 0 0;
  z-index: 1;
}

.inline-form .button {
  justify-self: start;
  align-self: end;
}

/* Compact multi-checkbox fieldsets (e.g. Users Site/Station access). The
   templates use <label class="checkbox"> for each row; each renders an input
   + label in a flex row. */
.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 1rem;
  min-width: 0;
}

fieldset.form-field {
  margin-bottom: 1rem;
}

/* Multi-checkbox group (e.g. a catalog item's can-type checklist assignment). */
.form-field--check-group legend {
  font-weight: 700;
  padding: 0;
}

.form-field--check-group .form-help {
  margin: 0.25rem 0 0;
}

/* Slightly denser styling for the fieldset row variant. */
.checkbox {
  padding: 0.2rem 0;
  font-weight: 500;
}

input[type="checkbox"],
input[type="radio"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Toggle switch: the checkbox-shaped control for on/off preferences (e.g.
   the settings page's notification toggles). The markup pairs a (possibly
   visually hidden) native checkbox with a .switch track; the sibling
   selector lets the input's :checked state drive the track, so the switch
   works with zero JavaScript and stays keyboard-accessible through the
   input itself. */
.switch {
  position: relative;
  display: inline-block;
  flex: none;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 150ms ease;
}

.switch__thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 150ms ease;
}

input:checked + .switch {
  background: var(--primary);
}

input:checked + .switch .switch__thumb {
  transform: translateX(1.1rem);
}

input:focus-visible + .switch {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input:disabled + .switch {
  opacity: 0.5;
}

/* Submit row for stacked forms (e.g. repair-catalog new/edit): breathing room so
   the action isn't flush against the last checkbox above it. */
.form-actions {
  margin-top: 1.25rem;
}

/* ---------- Feedback ---------- */
.alert {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}

.alert--danger {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, var(--background));
}

.alert--success {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  background: color-mix(in srgb, var(--success) 12%, var(--background));
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert--info {
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
  background: color-mix(in srgb, var(--info) 12%, var(--background));
  color: var(--info);
}

.alert--warning {
  border-color: color-mix(in srgb, var(--warning-strong) 45%, transparent);
  background: color-mix(in srgb, var(--warning) 14%, var(--background));
  color: var(--warning-strong);
  font-weight: 700;
}

/* ---------- Tables ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap .table {
  min-width: max-content;
}

/* Key/value tables that must fit narrow viewports: let the table shrink and
   long values wrap instead of forcing a horizontal scrollbar. */
.table-wrap .table--fit {
  min-width: 0;
}

.table--fit td {
  overflow-wrap: anywhere;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
  text-align: left;
  vertical-align: middle;
}

.table th {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Flat rows (no zebra striping) with a subtle hover, matching the demo. */
.table tbody tr:hover {
  background: color-mix(in srgb, var(--text) 4%, var(--surface));
}

/* ---------- Badge ---------- */
/* Badge — pill chips. The default (no modifier) is a muted neutral chip
   matching the demo's `bg-muted text-muted-foreground`; semantic variants tint
   a soft fill from the status tokens. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-muted);
}

/* Neutral: an explicit alias for the unmodified `.badge` styling, for callers
   that pass a "neutral" status variant name (e.g. a revenue target of $0). */
.badge--neutral {
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge--success {
  background: color-mix(in srgb, var(--success) 16%, var(--surface));
  color: var(--success);
}

.badge--warning {
  background: color-mix(in srgb, var(--warning) 18%, var(--surface));
  color: var(--warning-strong);
  font-weight: 600;
}

.badge--danger {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.badge--info {
  background: color-mix(in srgb, var(--info) 14%, var(--surface));
  color: var(--info);
}

/* ---------- Avatar + identity ---------- */
/* Avatar — a round initials chip on the muted surface. Used by the Users table
   and the sidebar identity block. --lg is the larger footer/identity size. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  line-height: 1;
  overflow: hidden;
}

.avatar--lg {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.95rem;
}

/* Rounded-square avatar used in the sidebar footer identity row (matches the
   demo's rounded-lg avatar rather than the default circle). */
.avatar--square {
  border-radius: var(--radius);
}

/* An avatar + label row, e.g. a Users table name cell. */
.identity {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

/* Two-line identity label: the display name over a muted login-username
   subline. Each line stays on a single line (no wrapping); the ellipsis
   properties guard against overflow if the column is ever width-constrained.
   Today the table sizes to `max-content` and scrolls, so long names widen the
   column rather than truncate. */
.identity__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.identity__name {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity__sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Action rows ---------- */
.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Submit/Save-draft row at the foot of the inspection form: separate it from
   the last item section, which otherwise butts right up against the buttons.
   Shared with any form footer that uses the row. */
.actions--form-footer {
  margin-top: var(--card-gap);
}

/* Keep a long form's primary actions reachable at the bottom of the viewport.
   The row stays in normal flow, so it never covers the content that follows the
   form; the extra bottom padding clears the home-indicator safe area. */
.actions--sticky {
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding-block: 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px color-mix(in srgb, var(--text) 6%, transparent);
}

/* Reserve room below the viewport so focus/scroll-into-view lands above the
   sticky actions instead of underneath them (notably with the mobile keyboard
   open). */
html:has(.actions--sticky) {
  scroll-padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
}

/* Right-aligned actions (e.g. the Approve/Reopen buttons on the repair review
   page, which sit in the bottom-right corner per the customer's request). */
.actions--end {
  justify-content: flex-end;
}

/* ---------- Empty state ---------- */
.empty-state {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Accessibility ---------- */
/* Visually-hidden but available to assistive tech. Used by the move-bar's
   implicit "Move selected to" label (the visible affordance is the live
   count + adjacent select), and any other label that must exist for AT only. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Tabs ---------- */
/* Period tabs (Day / Week / Month / Year) and prev/next navigation. Kept
   lightweight: the tabs are simple pill-shaped links, not a heavy client-side
   tab component. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tabs__tab {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  line-height: 1;
}

.tabs__tab:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.tabs__tab.is-active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

/* ---------- Definition list grid ---------- */
/* Used for the payroll-detail card and other key/value summaries. */
.dl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem 1.25rem;
}

.dl-grid dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0;
}

.dl-grid dd {
  margin: 0.2rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
}

/* ---------- Responsive list swap (mobile-cards) ----------
   Hidden on desktop, revealed at the phone breakpoint. Paired with
   .table-wrap--desktop which is visible by default and hidden at the
   breakpoint, so each list page renders both markups and CSS toggles them. */
.mobile-cards {
  display: none;
}

@media (max-width: 720px) {
  .inline-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .inline-form .button {
    justify-self: stretch;
    align-self: stretch;
  }
}

@media (max-width: 559px) {
  /* Reveal the stacked card list and hide the desktop table. */
  .mobile-cards {
    display: block;
  }
  .table-wrap--desktop {
    display: none;
  }

  /* The card list fills the remaining card height and scrolls internally,
     mirroring the .card--list > .table-wrap flex/scroll contract. */
  .card--list > .mobile-cards {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Each row becomes a mini-card separated by a border. */
  .mobile-cards__item {
    padding: 0.85rem 0.25rem;
    border-bottom: 1px solid var(--border);
  }
  .mobile-cards__item:last-child {
    border-bottom: none;
  }

  /* Whole-card tap target: the title link's pseudo-element stretches over the
     card so a tap anywhere opens the record (no JavaScript needed). Only the
     controls inside the action row sit above that overlay; the row's empty
     space stays click-through. The card carries the focus ring for the
     stretched link. */
  .mobile-cards__item--stretched-link {
    position: relative;
    transition: background-color 0.12s ease;
  }
  @media (hover: hover) {
    .mobile-cards__item--stretched-link:hover {
      background-color: var(--surface-2);
    }
  }
  .mobile-cards__item--stretched-link:has(.mobile-cards__title a:active) {
    background-color: color-mix(in srgb, var(--primary) 8%, var(--surface-2));
  }
  .mobile-cards__item--stretched-link .mobile-cards__title a::after {
    content: "";
    position: absolute;
    inset: 0;
  }
  .mobile-cards__item--stretched-link
    .mobile-cards__actions
    :is(a, button, input, label, select, textarea) {
    position: relative;
    z-index: 1;
  }
  @supports selector(:has(*)) {
    .mobile-cards__item--stretched-link .mobile-cards__title a:focus-visible {
      outline: none;
    }
    .mobile-cards__item--stretched-link:has(.mobile-cards__title a:focus-visible) {
      outline: 2px solid var(--primary);
      outline-offset: -2px;
    }
  }

  /* The primary line: rail-can number (often a link) sits prominently. */
  .mobile-cards__title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.4rem;
  }

  /* Compact two-line summary: title + status badges on the first line, then
     the customer and priority/description on the second. */
  .mobile-cards__head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .mobile-cards__head .mobile-cards__title {
    margin-bottom: 0;
  }
  .mobile-cards__head .badge {
    flex: none;
  }
  .mobile-cards__meta {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.3rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 0;
  }
  .mobile-cards__meta-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-cards__meta-text + .mobile-cards__meta-text::before {
    content: "· ";
  }
  .mobile-cards__note {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    margin: 0.3rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
  }
  .mobile-cards__meta .badge {
    flex: none;
  }

  /* Label:value pairs stack vertically, full width, no horizontal scroll. */
  .mobile-cards__field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.18rem 0;
  }
  .mobile-cards__label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .mobile-cards__value {
    text-align: right;
    font-size: 0.9rem;
    word-break: break-word;
    min-width: 0;
  }

  /* Per-row action row (e.g. the "Mark moved" button, or the users list's
     Edit + Test push pair). A wrapping flex row with the same gap as the
     desktop .actions row, so a card holding several controls keeps them
     side by side instead of stacking flush with no space between them. */
  .mobile-cards__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }

  /* Reduce card padding so content gets more of the narrow viewport. */
  .card {
    padding: 1rem;
  }

  /* Compact table cells for tables that remain (reference data, etc.). */
  .table th,
  .table td {
    padding: 0.5rem 0.35rem;
    font-size: 0.82rem;
  }

  /* ---------- Stacked tables (table--stack) ----------
     Scroll-only tables opt into a stacked layout on phones: each row becomes
     a bordered block and each cell a label/value line, so wide tables wrap in
     place instead of scrolling sideways. `data-label` supplies the cell label;
     the header row stays in the accessibility tree but is visually hidden. */
  .table-wrap:has(> .table--stack) {
    overflow: visible;
  }

  .table-wrap .table--stack {
    display: block;
    min-width: 0;
  }

  .table--stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .table--stack tbody,
  .table--stack tfoot {
    display: block;
  }

  .table--stack tbody tr {
    display: block;
    padding: 0.7rem 0.15rem;
    border-bottom: 1px solid var(--border);
  }

  .table--stack tbody tr:last-child {
    border-bottom: none;
  }

  /* `display: block` would otherwise beat the UA `[hidden]` rule and reveal
     rows such as the inspection deny form. */
  .table--stack tr[hidden] {
    display: none;
  }

  .table--stack td,
  .table--stack tfoot th {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.18rem 0;
    border-bottom: 0;
    text-align: right;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
  }

  .table--stack td[data-label]::before,
  .table--stack tfoot th[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
  }

  /* Cells without a label (actions, expanded detail rows, empty states) use
     the full row width. */
  .table--stack td:not([data-label]) {
    display: block;
    text-align: left;
  }

  /* Padding-only spacer cells (e.g. the tfoot row's trailing column) would
     otherwise render as a blank line in the stacked layout. */
  .table--stack td:empty {
    display: none;
  }

  /* In-body row labels (key/value tables and total rows) sit above the value. */
  .table--stack tbody th {
    display: block;
    padding: 0.3rem 0 0;
    border: 0;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .table--stack tfoot tr {
    display: block;
    padding: 0.7rem 0.15rem 0;
    border-top: 1px solid var(--border);
  }

  .table--stack tfoot th:first-child {
    display: block;
    padding: 0 0 0.25rem;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
  }

  .table--stack tfoot th:first-child::before {
    content: none;
  }

  /* Filter card: tighter summary, form padding, and action row on phones. */
  .filters__form {
    padding: 0.75rem 0.5rem;
  }
  .filters__summary {
    min-height: 2.25rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
  }
  .filters__actions {
    margin-top: 0.75rem;
  }
  .filters__actions .button {
    width: 100%;
  }
}

/* ---------- Photo-compression busy state ---------- */
/* While the client-side photo compressor (photo-compress.js, loaded on every
   page) is resizing/re-encoding a selection, the owning form carries
   `.is-compressing` (and aria-busy). Submit controls are disabled by the
   script; an appended ellipsis + progress cursor signals that work is in
   flight so a slow encode on a phone doesn't read as a frozen page. Lives
   here rather than photos.css because the script can enhance any form with
   an image input (e.g. the new-container intake form).
   `input[type="submit"]` can't host a pseudo-element (void element), so
   it only gets the cursor; the visible ellipsis renders on <button>. */
.is-compressing button[type="submit"],
.is-compressing input[type="submit"],
.is-compressing button:not([type]) {
  cursor: progress;
}

.is-compressing button[type="submit"]::after,
.is-compressing button:not([type])::after {
  content: " …";
}

/* ---------- Card layout resets ----------
   Scoped under .card (higher specificity than the component base rules) so
   non-card layouts that reuse these classes — e.g. the dashboard places
   .page-heading and .dash-stats directly in <main>, not in a card — keep their
   own spacing. Forms keep 0 outer margins here; their inner .form-field
   margins are untouched for internal field rhythm. The list intentionally
   includes classes owned by page-scope files (inspection-list,
   reference-images) because every card layout must neutralize their block
   margins; those scope files load after this one and only style internals. */
.card > .page-heading,
.card > .card__heading,
.card > .inline-form,
.card > .filters,
.card > .alert,
.card > .empty-state,
.card > .inspection-list,
.card > .reference-images,
.card > .pagination,
.card > .segmented,
.card > h2,
.card > form,
.card > p {
  margin-top: 0;
  margin-bottom: 0;
}

/* A lone direct-child button (e.g. the dashboard's "Open review queue" link)
   should keep its natural width and left alignment rather than stretching across
   the full card width as a column flex item. */
.card > .button {
  align-self: flex-start;
}
