/*
 * Interface alignment fixes.
 * Loaded after style.css and premium.css so these rules can repair narrow,
 * demonstrated layout defects without changing the incumbent visual system.
 */

/* Keep the page itself vertically constrained while allowing pinch zoom and
   horizontal touch gestures inside intentional scroll wrappers. */
html {
  touch-action: manipulation;
}

/* Controls and their icons should share one optical centre. Heading icons keep
   their existing spacing because this only targets icons inside controls. */
button,
.btn {
  max-width: 100%;
  gap: 6px;
}

:is(button, .btn) > .btn-ic {
  position: static;
  top: auto;
  align-items: center;
  justify-content: center;
  margin: 0;
}

:is(button, .btn) > :is(.ic, .btn-ic) {
  flex: 0 0 auto;
}

.btn-full {
  display: flex;
}

/* Text owns the available row space; action forms keep their intrinsic width. */
.list-item > div:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.list-item > form {
  flex: 0 0 auto;
  max-width: 100%;
}

@media (min-width: 761px) {
  .list-item > div:first-child {
    flex: 1 1 0%;
  }
}

:where(button, .btn, a, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Search fields must surrender space to their action instead of squeezing the
   action label at 320/390px. */
.search-box {
  align-items: stretch;
  min-width: 0;
}

.search-box input {
  width: auto;
  min-width: 0;
  flex: 1 1 12rem;
}

.search-box button {
  min-width: 84px;
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Rich-text controls previously inherited 11px 19px global button padding
   inside a fixed 32px box, clipping H/list labels and the image SVG. */
.rte-toolbar button {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  flex: 0 0 36px;
  gap: 0;
  padding: 0;
  line-height: 1;
}

.rte-toolbar button > .ic {
  width: 16px;
  height: 16px;
}

/* User-authored documentation can contain URLs or other unbroken strings. */
.doc-content,
.doc-content :where(p, li, a, span, strong, em, code) {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Ordinary dialogs need a viewport boundary and an independently scrollable
   body; image dialogs retain their specialised zoom behaviour. */
.modal-box:not(.modal-box-image) {
  display: flex;
  max-height: calc(100dvh - 40px);
  flex-direction: column;
  overflow: hidden;
}

.modal-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-header > :first-child:not(.btn-ic),
.modal-header > .btn-ic + span {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}

.modal-close {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  flex: 0 0 36px;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  padding: 0;
}

/* Keep assignment controls fluid for current and future dated producer rows. */
.assignment-duration {
  width: min(100%, 320px);
  max-width: 100%;
  min-width: 0;
}

/* Shift-history rows use explicit structure so desktop stays compact while
   the same content can reflow safely on a phone. */
.employee-shift-heading {
  align-items: flex-start;
}

.employee-shift-selection {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: inherit;
  font-size: inherit;
  font-weight: 700;
}

.employee-shift-selection > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-shift-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .container :is(a.btn-small, a.btn-secondary) {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  /* Interactive controls in the main task surface retain a 44px touch target.
     The fixed bottom navigation and Back bar are intentionally out of scope. */
  .container :is(button, .btn),
  .container a.btn-small,
  .modal-body :is(button, .btn),
  .modal-close,
  details > summary {
    min-height: 44px;
  }

  .container :is(button, .btn),
  .modal-body :is(button, .btn),
  .salary-week-arrow {
    min-width: 44px;
  }

  details > summary.token-correction-button,
  details > summary.employee-name-toggle {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
  }

  .container :is(input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), select) {
    min-height: 44px;
  }

  label:has(> input[type="checkbox"]),
  label:has(> input[type="radio"]) {
    min-height: 44px;
    align-items: center;
    padding-block: 8px;
  }

  label > input[type="checkbox"],
  label > input[type="radio"] {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .rte-toolbar button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    flex-basis: 44px;
  }

  .search-box {
    flex-wrap: wrap;
  }

  .search-box input {
    flex-basis: min(100%, 12rem);
  }

  /* At phone widths the old nowrap action row placed Delete at x=302..379 in
     a 320px viewport. Wrap the semantic title/action groups instead. */
  .employee-shift-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .employee-shift-selection {
    width: 100%;
    min-height: 44px;
    flex: 1 1 100%;
  }

  .employee-shift-selection > span {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .employee-shift-actions {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 8px;
    white-space: normal;
  }

  .employee-shift-actions > strong {
    flex: 1 1 100%;
  }

  .employee-shift-actions > :is(button, a, form) {
    min-width: 0;
    flex: 1 1 7.5rem;
  }

  .employee-shift-actions > form > button {
    width: 100%;
  }

  /* Secondary task/goal action groups follow the same wrapping rule. */
  .task-item > div:last-child,
  .goal-item > div > div:last-child {
    max-width: 100%;
    flex-wrap: wrap;
  }

  .modal-box:not(.modal-box-image) {
    max-height: calc(100dvh - var(--mobile-content-top, 10px) - 20px);
  }

  .salary-advance-header {
    padding-top: calc(15px + var(--mobile-content-top, 10px));
  }

  .modal-close {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  /* Two-column inline settings grids become illegible in the 258px card
     content area. This narrow selector only overrides that authored inline
     declaration. */
  .settings-page [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

