/* v174: shared desktop rhythm. No business state, hidden rules or save changes. */
html body:is(.experience-ui,.operator-ui) {
  --ui-rhythm-caption: 4px;
  --ui-rhythm-field: 8px;
  --ui-rhythm-action: 12px;
  --ui-rhythm-group: 16px;
  --ui-rhythm-section: 24px;
  --ui-control-height: 44px;
  --context-help-mark: 16px;
}

/* Keep the glyph small; preserve the separate keyboard/pointer target. */
html body:is(.experience-ui,.operator-ui) .context-help-trigger > span {
  font-size: 11px;
  line-height: 1;
}
html body:is(.experience-ui,.operator-ui) :is(.context-help-label,.context-help-choice,.context-help-action,.context-help-control) {
  align-items: center;
}
html body.experience-ui .context-help-label { min-block-size: 24px; }
html body.experience-ui .context-help-caption { min-block-size: 24px; }
html body.experience-ui :is(.form-row,.workflow-grid,.af-grid,.si-grid) {
  column-gap: var(--ui-rhythm-group);
  row-gap: var(--ui-rhythm-group);
}
html body.experience-ui .workflow-grid { align-items: start; }
html body.experience-ui .workflow-grid > :is(label,.workflow-field,.context-help-field) {
  align-self: stretch;
}
html body.experience-ui .workflow-grid :is(.workflow-field,.context-help-field > label) {
  align-content: start;
  gap: var(--ui-rhythm-field);
}

/* Labeled and unlabeled filters share their input's bottom edge. A count is
   a separate full-width status row, rather than a variable-width flex spacer. */
html body.experience-ui .tab-toolbar {
  align-items: flex-end;
  gap: var(--ui-rhythm-action);
}
html body.experience-ui .tab-toolbar > :is(label,.context-help-field) {
  margin: 0;
  min-width: 0;
}
html body.experience-ui .tab-toolbar > label,
html body.experience-ui .tab-toolbar > .context-help-field > label {
  display: grid;
  align-content: end;
  gap: var(--ui-rhythm-caption);
}
html body.experience-ui .tab-toolbar > .context-help-control,
html body.experience-ui .tab-toolbar > .context-help-action {
  min-block-size: var(--ui-control-height);
  margin-block: 0;
}
html body.experience-ui #tab-apps .tab-toolbar > .btn,
html body.experience-ui #tab-apps .tab-toolbar > .context-help-action > .btn {
  min-block-size: var(--ui-control-height);
}
html body.experience-ui #adminAppsCounts { flex-basis: 100%; min-width: 0; }
html body.experience-ui :is(.ui-action-row,.workflow-actions,.af-actions,.si-footer-nav) {
  gap: var(--ui-rhythm-action);
  align-items: center;
}
html body.experience-ui td > :is(.btn,.context-help-action) + :is(.btn,.context-help-action) {
  margin-inline-start: var(--ui-rhythm-field);
}
html body.experience-ui :is(.btn,.rf-btn,.dash-btn,.vehicle-window-expand) > svg {
  flex: 0 0 auto;
  vertical-align: middle;
}

/* Reserve the route frame before its asynchronous content and late feature
   stylesheet arrive. Preserve the owner's expanded class and hidden overlay. */
html body.experience-ui #routeFormModal #rfModalCard {
  display: flex;
  flex-direction: column;
  overflow: clip;
  animation: none;
}
html body.experience-ui #routeFormModal #rfModalCard:not(.rf-expanded) {
  block-size: calc(100dvh - 48px);
  max-block-size: calc(100dvh - 48px);
}
html body.experience-ui #routeFormModal:has(#rfModalCard.rf-expanded) { padding: 0; }
html body.experience-ui #routeFormModal #rfModalCard > .vmodal-hdr { flex: 0 0 auto; }
html body.experience-ui #routeFormModal #rfBody {
  min-block-size: 0;
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
html body.experience-ui #routeFormModal .rf-form-panel {
  padding: var(--ui-rhythm-section);
}
html body.experience-ui #routeFormModal :is(.rf-grid-2,.rf-grid-3) {
  gap: var(--ui-rhythm-group);
}
html body.experience-ui #routeFormModal .rf-row-info {
  gap: var(--ui-rhythm-field);
  margin-block-end: var(--ui-rhythm-group);
}
html body.experience-ui #routeFormModal .rf-field :is(input:not([type=checkbox]):not([type=radio]):not([data-date-entry-calendar]),select) {
  block-size: 48px;
  min-block-size: 48px;
  line-height: 20px;
}
html body.experience-ui #routeFormModal .amis-date-calendar { block-size: 48px; }
html body.experience-ui #routeFormModal .rf-field textarea {
  min-block-size: 80px;
  line-height: 20px;
}
html body.experience-ui #routeFormModal .context-help-floating > .context-help-trigger {
  top: calc((48px - var(--context-help-target)) / 2);
}
html body.experience-ui #routeFormModal .rf-instr {
  margin-block: 0 var(--ui-rhythm-group);
  vertical-align: middle;
}
html body.experience-ui #routeFormModal .rf-form-panel > :is(label,.context-help-choice):has(#rfHideMap) {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--ui-control-height);
  /* The help decorator transfers the old inline label margin to its wrapper. */
  margin: 0 0 var(--ui-rhythm-group) var(--ui-rhythm-action) !important;
  vertical-align: middle;
}
html body.experience-ui #routeFormModal .context-help-choice:has(#rfHideMap) > label {
  margin: 0;
}
html body.experience-ui #routeFormModal #rfAccessSource {
  min-block-size: 312px;
  box-sizing: border-box;
}
html body.experience-ui #routeFormModal #rfAccessSource > .rf-btn {
  margin-inline-end: var(--ui-rhythm-field);
  margin-block-start: var(--ui-rhythm-field);
  vertical-align: middle;
}
html body.experience-ui #routeFormModal .rf-actions {
  gap: var(--ui-rhythm-action);
  align-items: center;
  padding-block-start: var(--ui-rhythm-group);
  margin-block-start: var(--ui-rhythm-section);
}

/* v273: clip frames cannot be scrolled by focus or scrollIntoView. Hidden
   would only remove the scrollbar and could still move the header away. */
html body:is(.experience-ui,.operator-ui) :is(#vehicleModal,#routeFormModal) {
  box-sizing: border-box;
  overflow: clip;
  overscroll-behavior: none;
}
html body.experience-ui #vehicleModal > .vmodal {
  min-block-size: 0;
  min-inline-size: 0;
  overflow: clip;
}
html body.experience-ui #vehicleModal > .vmodal > .vmodal-body {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scroll-padding-block: var(--ui-rhythm-group);
}
html body.experience-ui #vehicleModal .vmodal-tabs {
  flex-wrap: nowrap;
  max-block-size: none;
  overflow-x: auto;
  overflow-y: hidden;
}
html body.experience-ui #vehicleModal .vmodal-tabs > button {
  flex: 0 0 auto;
}
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  min-inline-size: 0;
  max-inline-size: min(1200px,100%) !important;
  overflow: clip;
}
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard:not(.rf-expanded) {
  block-size: calc(100dvh - 48px);
  max-block-size: calc(100dvh - 48px);
}
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .vmodal-hdr {
  flex: 0 0 auto;
}
html body:is(.experience-ui,.operator-ui) #routeFormModal:has(#rfModalCard.rf-expanded) { padding: 0; }
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard.rf-expanded {
  block-size: 100dvh !important;
  max-block-size: 100dvh !important;
  max-inline-size: 100% !important;
}
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfBody {
  flex: 1 1 auto;
  min-block-size: 0;
  min-inline-size: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-block: var(--ui-rhythm-group);
}
html body:is(.experience-ui,.operator-ui) #routeFormModal .rf-layout {
  min-block-size: 0;
  min-inline-size: 0;
}
html body:is(.experience-ui,.operator-ui) #routeFormModal .rf-form-panel {
  min-inline-size: 0;
  max-block-size: none;
  overflow: visible;
}
@media (min-width: 701px) {
  html body:is(.experience-ui,.operator-ui) #routeFormModal .rf-map-panel {
    position: sticky;
    top: 0;
    align-self: start;
    min-block-size: 0;
    min-inline-size: 0;
  }
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfMap {
    block-size: min(600px,65dvh) !important;
    min-block-size: 0 !important;
  }
}
@media (min-width: 701px) and (max-width: 900px) {
  html body:is(.experience-ui,.operator-ui) #routeFormModal .rf-layout {
    grid-template-columns: minmax(0,1fr) !important;
  }
  html body:is(.experience-ui,.operator-ui) #routeFormModal .rf-map-panel {
    position: static;
  }
}
html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions {
  position: static;
  flex: 0 0 auto;
  flex-wrap: wrap;
  margin: 0;
  padding: var(--ui-rhythm-group) var(--ui-rhythm-section);
  gap: var(--ui-rhythm-action);
  background: var(--surface);
}
@media (max-width: 700px) {
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: var(--ui-rhythm-field);
  }
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions > :is(#rfMainSave,.context-help-action:has(#rfMainSave)) {
    grid-column: 1 / -1;
  }
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions > *,
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions .rf-btn {
    min-inline-size: 0;
    inline-size: 100%;
    margin-inline: 0;
  }
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard > .rf-actions .rf-btn {
    min-block-size: var(--ui-control-height);
    white-space: normal;
    overflow-wrap: anywhere;
  }
}
@media (max-width: 640px) {
  html body:is(.experience-ui,.operator-ui) #routeFormModal { padding: var(--ui-rhythm-action); }
  html body:is(.experience-ui,.operator-ui) #routeFormModal #rfModalCard:not(.rf-expanded) {
    block-size: calc(100dvh - 24px);
    max-block-size: calc(100dvh - 24px);
  }
}

/* The shared reset removes the native dialog's auto margins. Restore them
   only for the saved-route preview, keeping one native scroll container. */
html body:is(.experience-ui,.operator-ui) #routeCatalogueDialog {
  inset: 0;
  margin: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-block: 88px;
}
html body:is(.experience-ui,.operator-ui) #routeCatalogueDialog > div:first-child:has(> [data-close]) {
  position: sticky;
  top: -20px;
  z-index: 3;
  margin: -20px -20px var(--ui-rhythm-group);
  padding: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
html body:is(.experience-ui,.operator-ui) #routeCatalogueDialog > .workflow-actions {
  position: sticky;
  bottom: -20px;
  margin: var(--ui-rhythm-group) -20px -20px;
  padding: var(--ui-rhythm-group) 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Help decorates Save with a wrapper. The wrapper owns its flex auto-margin;
   moving that margin off the button prevents the footer jumping to the left. */
html body.experience-ui #documentOrderDialog.workflow .order-save-actions > .context-help-action:has(#doSave) {
  margin-inline-start: auto;
  flex: 0 0 auto;
}
html body.experience-ui #documentOrderDialog.workflow .context-help-action > #doSave {
  margin-inline-start: 0;
}
html body.experience-ui #documentOrderDialog.workflow .order-guide {
  gap: var(--ui-rhythm-field);
  padding-inline: var(--ui-rhythm-section);
}
html body.experience-ui #documentOrderDialog.workflow .order-guide > .btn {
  min-block-size: var(--ui-control-height);
}
html body.experience-ui #documentOrderDialog.workflow .workflow-grid > label,
html body.experience-ui #documentOrderDialog.workflow .workflow-grid > .context-help-field > label {
  grid-template-rows: minmax(24px,auto) auto;
  align-content: start;
}
html body.experience-ui #documentOrderDialog.workflow #doAutoStatus { min-block-size: 40px; }
html body.experience-ui #documentOrderDialog.workflow #doAutoSource {
  min-block-size: 312px;
  box-sizing: border-box;
}
html body.experience-ui #documentOrderDialog.workflow #doAutoChoices:not([hidden]) {
  min-block-size: 160px;
  gap: var(--ui-rhythm-field);
}
html body.experience-ui #documentOrderDialog.workflow :is(.order-step-header,.order-step-body,.order-step-footer) {
  padding-inline: var(--ui-rhythm-section);
}
html body.experience-ui #documentOrderDialog.workflow .order-step-footer { min-block-size: 108px; }

@media (min-width: 1000px) {
  /* Contextual help adds the theme caption after load. Keep its exact slot
     reserved before insertion so the neighboring header actions do not move. */
  html body.experience-ui .topbar-links > .switcher { margin-inline-start: 144px; }
  html body.experience-ui .topbar-links > .context-help-group:has(+ .switcher) {
    flex: 0 0 136px;
    inline-size: 136px;
    margin: 0;
    white-space: nowrap;
  }
  html body.experience-ui .topbar-links > .context-help-group + .switcher { margin-inline-start: 0; }
}
@media (max-width: 640px) {
  html body:is(.experience-ui,.operator-ui) { --ui-rhythm-section: 16px; }
  html body.experience-ui #routeFormModal #rfModalCard:not(.rf-expanded) {
    block-size: calc(100dvh - 24px);
    max-block-size: calc(100dvh - 24px);
  }
  html body.experience-ui #routeFormModal #rfAccessSource { min-block-size: 0; }
  html body.experience-ui #documentOrderDialog.workflow #doAutoSource { min-block-size: 0; }
  html body.experience-ui #documentOrderDialog.workflow .order-save-actions > .context-help-action:has(#doSave) {
    margin-inline-start: 0;
  }
}

/* Shared modal frame: the title and close control remain outside the scroll area.
   :has protects old windows without a body wrapper; hidden overlays stay hidden. */
html body.experience-ui .modal-overlay:has(> .vmodal > .vmodal-body) {
  overflow: clip;
  overscroll-behavior: none;
}
html body.experience-ui .modal-overlay > .vmodal:has(> .vmodal-body) {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  max-block-size: calc(100dvh - 48px);
  overflow: clip;
  animation: none;
  transform: none;
}
html body.experience-ui .modal-overlay > .vmodal > .vmodal-hdr { flex: 0 0 auto; }
html body.experience-ui .modal-overlay > .vmodal > .vmodal-body {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-block: var(--ui-rhythm-group);
}
/* Floating-label fields retain their 48px layout and share the control typeface. */
html body.experience-ui #routeFormModal .rf-field :is(input:not([type=checkbox]):not([type=radio]):not([data-date-entry-calendar]),select,textarea) {
  font-size: .9375rem;
  border-radius: 8px;
}
@media (max-width: 600px) {
  html body.experience-ui .modal-overlay > .vmodal:has(> .vmodal-body) { max-block-size: calc(100dvh - 24px); }
  html body.experience-ui #routeFormModal .rf-field :is(input:not([type=checkbox]):not([type=radio]):not([data-date-entry-calendar]),select,textarea),
  html body.experience-ui #routeFormModal .rf-ms-input { font-size: 1rem; }
}

/* A help trigger must not change the baseline of its neighbouring fields. */
html body.experience-ui .stack > label,
html body.experience-ui .stack > .context-help-label {
  display: flex;
  align-items: center;
  min-block-size: var(--context-help-target, 24px);
  box-sizing: border-box;
  margin-block: 0;
  line-height: 1.4;
}
html body.experience-ui .form-row > .stack { align-self: start; }
html body.experience-ui .stack > :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select:not([multiple]):not([size])),
html body.experience-ui .stack > .context-help-control > :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select:not([multiple]):not([size])) {
  block-size: var(--ui-control-height);
  box-sizing: border-box;
}
/* Native select semantics and keyboard operation remain unchanged. */
html body.experience-ui {
  --ui-select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m2 4 4 4 4-4' fill='none' stroke='%234d6680' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
html[data-theme=dark] body.experience-ui {
  --ui-select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m2 4 4 4 4-4' fill='none' stroke='%23b8c9dc' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
html body.experience-ui select:not([multiple]):not([size]) {
  --ui-control-end-space: 40px;
  --ui-control-background: var(--surface) var(--ui-select-chevron) no-repeat right 14px center / 12px 12px;
  appearance: none;
}
html body.experience-ui #routeFormModal .rf-field select {
  background-image: var(--ui-select-chevron);
  background-position: right 14px center;
  background-size: 12px 12px;
}
@media (forced-colors: active) {
  html body.experience-ui select:not([multiple]):not([size]) {
    --ui-control-background: Canvas;
    appearance: auto;
  }
  html body.experience-ui #routeFormModal .rf-field select { background-image: none; appearance: auto; }
}

/* Shared tracks align even two-line calendar captions; feedback has its own
   third track, so adding an error does not move the neighbouring controls. */
@supports (grid-template-rows: subgrid) {
  html body.experience-ui .rp-grid:not(:has(> :not(label))) {
    row-gap: 0;
  }
  html body.experience-ui .rp-grid:not(:has(> :not(label))) > label {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    align-self: stretch;
    align-content: start;
    row-gap: 6px;
    padding-block-end: 12px;
  }
}
html body.experience-ui .rp-grid > label > :is(input:not([type=checkbox]):not([type=radio]):not([data-date-entry-calendar]),select:not([multiple]):not([size])) {
  block-size: 44px;
  box-sizing: border-box;
}
/* Passport and other workflow fields keep caption, control, source and error
   on separate shared tracks. Read-only information grids are not affected. */
@supports (grid-template-rows: subgrid) {
  html body.experience-ui .workflow-grid:not(:has(> :not(label.workflow-field))) { row-gap: 0; }
  html body.experience-ui .workflow-grid:not(:has(> :not(label.workflow-field))) > label.workflow-field:not([hidden]) {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 4;
    align-self: stretch;
    align-content: start;
    row-gap: 6px;
    padding-block-end: 12px;
  }
}
