/* Task 9: remaining mobile-web refinements at ~360–430px.
   Activity workflow/fields stay the same. Only contain page-level overflow at ~390px:
   native <select> option text was expanding form.form / .activityModeBox past the viewport.
   Does not change Android, Attendance, Task 4/8, or Command persistence. */

@media (max-width: 430px) {
  #ibs-dra-command,
  #ibs-next-shell,
  #ibs-c360-modal,
  #ibs-smart-panel,
  #ibs-smart-modal,
  .ibs-staff-page {
    overflow-x: clip;
    max-width: 100vw;
  }

  #ibs-smart-panel {
    max-height: min(48dvh, 360px);
  }

  #ibs-smart-panel.collapsed {
    max-height: 56px;
  }

  .ibs-staff-page .nl-toolbar,
  .ibs-staff-page .nl-form-grid,
  #ibs-branch-master .nl-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .ibs-staff-page .nl-toolbar > *,
  .ibs-staff-page .nl-input,
  .ibs-staff-page .nl-select,
  .ibs-staff-page .nl-btn {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .ibs-staff-table,
  .ibs-staff-table tbody,
  .ibs-staff-table tr,
  .ibs-staff-table td {
    min-width: 0 !important;
    max-width: 100%;
  }

  .ibs-staff-dialog {
    width: calc(100vw - 12px);
    max-width: 100vw;
    max-height: min(96dvh, 100%);
    overflow: auto;
  }

  .ibs-staff-dialog-head,
  .ibs-staff-dialog-body,
  .ibs-staff-dialog-foot {
    min-width: 0;
  }

  .ibs-staff-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ibs-c360-modal {
    padding: 8px;
    align-items: stretch;
  }

  .ibs-c360-dialog {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 100%);
    box-sizing: border-box;
    overflow: auto;
  }

  .ibs-c360-actions {
    flex-direction: column;
  }

  .ibs-c360-btn {
    width: 100%;
    min-height: 44px;
  }

  .ibs-c360-meta,
  .ibs-c360-note,
  .ibs-c360-dialog p {
    overflow-wrap: anywhere;
  }

  .ibs-dra-filters,
  .ibs-dra-kpis,
  .ibs-dra-grid {
    grid-template-columns: 1fr;
  }

  .ibs-dra-kpis.ibs-dra-kpis-pair {
    grid-template-columns: 1fr 1fr;
  }

  .ibs-dra-filters input,
  .ibs-dra-filters select,
  .ibs-dra-card,
  .ibs-dra-row,
  .ibs-dra-kpi {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .ibs-dra-kpi strong {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .ibs-dra-stage {
    flex-direction: column;
    align-items: flex-start;
  }

  .ibs-dra-crumbs {
    max-width: 100%;
  }

  .ibs-smart-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ibs-smart-row > * {
    width: 100%;
  }

  .ibs-smart-dialog,
  #ibs-smart-modal .ibs-smart-dialog {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 100%);
    margin: 0;
    box-sizing: border-box;
  }

  .ibs-smart-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .ibs-smart-sticky-actions button,
  .ibs-smart-actions .ibs-smart-btn,
  .ibs-contact-actions a,
  .ibs-contact-actions button {
    min-height: 44px;
  }

  .ibs-workflow-field {
    min-width: 0;
    width: 100%;
  }

  .ibs-workflow-details {
    flex-direction: column;
  }

  .ibs-workflow-scroll,
  .tableWrap,
  .nl-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ibs-workflow-scroll {
    overflow-x: visible;
  }
  .ibs-workflow-table {
    min-width: 0 !important;
    width: 100%;
  }
  .ibs-workflow-table thead {
    display: none;
  }
  .ibs-workflow-table,
  .ibs-workflow-table tbody,
  .ibs-workflow-table tr,
  .ibs-workflow-table td {
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .ibs-workflow-table tr {
    border: 1px solid #dde4ed;
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 10px;
    background: #fff;
  }
  .ibs-workflow-table th,
  .ibs-workflow-table td {
    white-space: normal;
    border: 0;
    padding: 6px 4px;
  }
  .ibs-workflow-table td:before {
    content: attr(data-label);
    display: block;
    color: #667085;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 2px;
  }
  .ibs-workflow-table td[colspan]:before {
    content: none;
    display: none;
  }

  /* Item 6 #8: keep TEST/LIVE ribbon visible without covering stacked report cards. */
  .ibs-environment-ribbon {
    top: calc(8px + env(safe-area-inset-top));
    right: 8px;
    bottom: auto;
    left: auto;
  }

  /* Banking phone: Command/Smart Work stay visible; Import stays off the report canvas. */
  .tabs {
    flex-wrap: nowrap;
  }
  .hero {
    padding: 12px;
    gap: 8px;
    position: relative;
    z-index: 2147483001;
  }
  h2:has(+ .dashboardDateBadge),
  .dashboardWelcome h2 {
    position: relative;
    z-index: 2147483001;
    background: #f4f7fb;
    padding-bottom: 6px;
  }
  #ibs-import-launcher {
    display: none !important;
  }
  #ibs-next-launcher,
  #ibs-smart-launcher {
    top: auto !important;
    max-width: calc(50vw - 18px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 8px 10px !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
  }
  #ibs-next-launcher {
    left: 8px !important;
    right: auto !important;
  }
  #ibs-smart-launcher {
    right: 8px !important;
    left: auto !important;
  }
  .app {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
  body:has(.ibs-dra-tracker) #ibs-next-launcher,
  body:has(.ibs-dra-tracker) #ibs-smart-launcher {
    display: none !important;
  }

  .nl-form-grid:not(#nl-activity-form) {
    grid-template-columns: 1fr;
  }

  .nl-grow {
    min-width: 0;
    width: 100%;
  }

  html:has(.activityModeBox),
  body:has(.activityModeBox),
  .app:has(.activityModeBox),
  .app:has(.activityEntryFilter),
  .gridTwo:has(.activityModeBox),
  .gridTwo:has(.activityEntryFilter) {
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  .gridTwo:has(.activityModeBox),
  .gridTwo:has(.activityEntryFilter) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .app:has(.activityModeBox),
  .app:has(.activityEntryFilter) {
    max-width: 100vw;
  }

  .card:has(.activityModeBox),
  .card:has(.activityEntryFilter) {
    overflow-x: clip;
  }

  .card:has(.activityModeBox),
  .card:has(.activityEntryFilter),
  .activityModeBox,
  .activityEntryFilter,
  .activityUploadBox,
  .formTitleRow,
  form.form,
  form.form .field,
  form.form .two {
    min-width: 0;
    max-width: 100%;
  }

  form.form,
  form.form .two,
  .modeToggle {
    grid-template-columns: 1fr;
  }

  form.form select,
  form.form input,
  form.form textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .ibs-att-card .ibs-att-actions {
    flex-direction: column;
  }
  .ibs-att-card .ibs-att-actions .btn,
  .ibs-att-card .ibs-workflow-field input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .ibs-att-card {
    overflow-x: clip;
    max-width: 100%;
  }
  .ibs-att-flags {
    max-width: 100%;
  }
  .ibs-att-flag {
    box-sizing: border-box;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  .ibs-att-cal,
  .ibs-att-cal-panel,
  .ibs-att-cal-grid,
  .ibs-att-cal-weekdays {
    max-width: 100%;
    overflow-x: clip;
  }
  .ibs-att-cal-controls {
    display: grid;
    grid-template-columns: 1fr;
  }
  .ibs-att-cal-controls .ibs-workflow-field,
  .ibs-att-cal-panel .ibs-workflow-field,
  .ibs-att-cal-panel input,
  .ibs-att-cal-panel select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .ibs-att-cal-cell {
    min-height: 54px;
    padding: 4px;
  }
  .ibs-att-cal-cell small {
    font-size: 9px;
  }
  .ibs-att-dash,
  .ibs-att-dash-filters,
  .ibs-att-dash-list,
  .ibs-att-dash-row,
  #ibs-att-detail {
    max-width: 100%;
    overflow-x: clip;
  }
  .ibs-att-dash {
    padding-bottom: 96px;
  }
  .ibs-att-dash-filters {
    display: grid;
    grid-template-columns: 1fr;
  }
  .ibs-att-dash-filters .ibs-workflow-field,
  .ibs-att-dash-filters select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .ibs-att-dash-cards {
    grid-template-columns: 1fr 1fr;
  }
  .ibs-att-dash-row {
    grid-template-columns: 1fr;
  }
  .ibs-att-corr-form,
  .ibs-att-corr-mine,
  .ibs-att-corr-queue,
  .ibs-att-corr-card,
  .ibs-att-corr-filters {
    max-width: 100%;
    overflow-x: clip;
  }
  .ibs-att-corr-queue {
    padding-bottom: 96px;
  }
  .ibs-att-corr-filters {
    display: grid;
    grid-template-columns: 1fr;
  }
  .ibs-att-corr-filters .ibs-workflow-field,
  .ibs-att-corr-form input,
  .ibs-att-corr-form select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .ibs-att-report,
  .ibs-att-report-filters,
  .ibs-att-report-list,
  .ibs-att-report-row,
  #ibs-att-report-days {
    max-width: 100%;
    overflow-x: clip;
  }
  .ibs-att-report {
    padding-bottom: 96px;
  }
  .ibs-att-report-filters {
    display: grid;
    grid-template-columns: 1fr;
  }
  .ibs-att-report-filters .ibs-workflow-field,
  .ibs-att-report-filters select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .ibs-att-report-cards {
    grid-template-columns: 1fr 1fr;
  }
  .ibs-att-report-row {
    min-width: 0;
  }
  #ibs-att-report-days .ibs-workflow-scroll {
    overflow-x: auto;
    max-width: 100%;
  }
  .ibs-att-config,
  .ibs-att-config-filters,
  .ibs-att-shift,
  .ibs-att-shift-filters,
  .ibs-att-shift-list,
  .ibs-att-shift-row {
    max-width: 100%;
    overflow-x: clip;
  }
  .ibs-att-config,
  .ibs-att-shift {
    padding-bottom: 96px;
  }
  .ibs-att-config-filters,
  .ibs-att-shift-filters {
    display: grid;
    grid-template-columns: 1fr;
  }
  .ibs-att-config-filters .ibs-workflow-field,
  .ibs-att-config-filters select,
  .ibs-att-config-filters input,
  .ibs-att-shift-filters .ibs-workflow-field,
  .ibs-att-shift-filters select,
  .ibs-att-shift-filters input {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* DRA mobile: hide extra DRA floater always. Hide Command / Smart Work / Import only for a floating (non-embedded) Command overlay. Embedded DRA landing keeps launchers. Banking / lead / C360 still hide them. */
  #ibs-dra-command-launcher,
  body:has(#ibs-dra-command.open:not(.embedded)) #ibs-import-launcher,
  body:has(#ibs-dra-command.open:not(.embedded)) #ibs-next-launcher,
  body:has(#ibs-dra-command.open:not(.embedded)) #ibs-smart-launcher,
  body:has(.leadDetailCard) #ibs-import-launcher,
  body:has(.leadDetailCard) #ibs-next-launcher,
  body:has(.leadDetailCard) #ibs-smart-launcher,
  body:has(#ibs-c360-modal.open) #ibs-import-launcher,
  body:has(#ibs-c360-modal.open) #ibs-next-launcher,
  body:has(#ibs-c360-modal.open) #ibs-smart-launcher {
    display: none !important;
  }
}

/* M2: compact the shared legacy header only while DRA is open.
   Desktop and Dashboard, Attendance, Field Visits, Smart Work, and IBS Command keep the existing header. */
@media (max-width: 640px) {
  body:has(.ibs-dra-tracker) .app > header.hero {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 14px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .brand {
    flex: 1 1 180px;
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .mainLogo,
  body:has(.ibs-dra-tracker) .app > header.hero .heroBrand img {
    width: auto !important;
    height: 36px !important;
    max-width: 100% !important;
    max-height: 36px !important;
    flex: 0 1 auto;
    object-fit: contain !important;
    object-position: left center !important;
    padding: 2px 6px !important;
    border-radius: 10px !important;
    box-shadow: none !important;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroCopy {
    min-width: 0;
    flex: 1 1 140px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .kicker {
    font-size: 10px;
    letter-spacing: 0.04em;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroCopy h1 {
    font-size: 16px;
    line-height: 1.15;
    margin: 0;
    letter-spacing: 0;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .mutedText {
    font-size: 11px;
    line-height: 1.25;
    margin: 2px 0 0;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroPills {
    margin-top: 4px;
    gap: 4px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroPills span {
    padding: 3px 8px;
    font-size: 12px;
    line-height: 1.3;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions {
    flex: 1 1 100%;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions .field {
    flex: 1 1 148px;
    min-width: 148px;
    max-width: 100%;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions .field input {
    width: 100%;
    font-size: 14px;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions .field span {
    font-size: 10px;
    letter-spacing: 0.04em;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions button,
  body:has(.ibs-dra-tracker) .app > header.hero .heroActions input {
    min-height: 44px;
    box-sizing: border-box;
  }

  body:has(.ibs-dra-tracker) .app > header.hero .heroActions input[type="date"] {
    min-width: 0;
    flex: 1 1 9rem;
    max-width: 100%;
  }
}

/* LIVE chrome 20261029: compact Review Date row only. Do not change .mainLogo. */
@media (max-width: 640px) {
  .app > header.hero .heroActions {
    flex: 1 1 100%;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
  }
  .app > header.hero .heroActions .field {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }
  .app > header.hero .heroActions button,
  .app > header.hero .heroActions input {
    min-height: 44px;
    box-sizing: border-box;
  }
}
