/*
 * fIIS mobile app shell
 * ---------------------
 * Loaded last and intentionally scoped to authenticated phone-width screens.
 * Desktop/tablet geometry and print layouts remain controlled by the existing
 * stylesheets. Wide registers stay usable through contained touch scrolling.
 */

.fids-mobile-menu-toggle,
.fids-mobile-nav-backdrop {
  display: none;
}

@media screen and (max-width: 760px), screen and (max-height: 500px) and (pointer: coarse) {
  :root {
    --fids-mobile-topbar: calc(56px + env(safe-area-inset-top, 0px));
    --fids-mobile-gutter: 10px;
  }

  html {
    min-width: 0 !important;
    overflow-x: hidden !important;
    background: #f5f6f8 !important;
  }

  body.fids-shell-v3,
  body.fids-shell-v3.fids-mini,
  body[data-fids-authenticated="true"] {
    width: 100% !important;
    min-width: 0 !important;
    padding-top: var(--fids-mobile-topbar) !important;
    padding-right: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    padding-left: 0 !important;
    overflow-x: hidden !important;
    background: #f5f6f8 !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open {
    overflow: hidden !important;
  }

  /* Compact native-app top bar. */
  body.fids-shell-v3 .fids-visible-header {
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 6px !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--fids-mobile-topbar) !important;
    min-height: var(--fids-mobile-topbar) !important;
    max-height: var(--fids-mobile-topbar) !important;
    padding: env(safe-area-inset-top, 0px) max(7px, env(safe-area-inset-right, 0px)) 0 max(7px, env(safe-area-inset-left, 0px)) !important;
    background: #fff !important;
    border-bottom: 3px solid #e30613 !important;
    box-shadow: 0 2px 12px rgba(17, 24, 39, .12) !important;
  }

  .fids-mobile-menu-toggle {
    display: inline-grid !important;
    place-items: center;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    margin: 0 !important;
    padding: 10px !important;
    border: 0 !important;
    border-radius: 10px !important;
    background: transparent !important;
    color: #111827 !important;
  }

  .fids-mobile-menu-toggle:focus-visible {
    outline: 2px solid #e30613 !important;
    outline-offset: 1px;
  }

  .fids-mobile-menu-toggle svg {
    width: 24px !important;
    height: 24px !important;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2 !important;
    stroke-linecap: round !important;
  }

  body.fids-shell-v3 .fids-visible-brand {
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 7px !important;
    overflow: hidden !important;
  }

  body.fids-shell-v3 .fids-visible-brand img {
    width: 82px !important;
    height: 28px !important;
    min-width: 82px !important;
  }

  body.fids-shell-v3 .fids-visible-brand-copy strong {
    font-size: 10px !important;
    line-height: 1.1 !important;
  }

  body.fids-shell-v3 .fids-visible-brand-copy small {
    display: none !important;
  }

  body.fids-shell-v3 .fids-visible-actions {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 2px !important;
  }

  body.fids-shell-v3 .pwa-header-install,
  body.fids-shell-v3 .notification-toggle,
  body.fids-shell-v3 .fids-visible-user-btn {
    width: 42px !important;
    height: 44px !important;
    min-width: 42px !important;
    min-height: 44px !important;
    padding: 4px !important;
  }

  body.fids-shell-v3 .fids-visible-user,
  body.fids-shell-v3 .fids-visible-user.dropdown {
    width: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    margin: 0 !important;
  }

  body.fids-shell-v3 .fids-visible-user-name,
  body.fids-shell-v3 .fids-db-badge {
    display: none !important;
  }

  body.fids-shell-v3 .fids-visible-avatar {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
  }

  /* Full-height off-canvas navigation. No permanent 72px content loss. */
  body.fids-shell-v3 .fids-v3-sidebar,
  body.fids-shell-v3.fids-mini .fids-v3-sidebar,
  body[data-fids-authenticated="true"] .fids-v3-sidebar {
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    top: var(--fids-mobile-topbar) !important;
    bottom: 0 !important;
    left: 0 !important;
    width: min(86vw, 320px) !important;
    min-width: min(86vw, 320px) !important;
    max-width: min(86vw, 320px) !important;
    height: auto !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    overflow: hidden !important;
    z-index: 49000 !important;
    transform: translate3d(-104%, 0, 0) !important;
    transition: transform .22s ease !important;
    box-shadow: 10px 0 30px rgba(15, 23, 42, .22) !important;
    visibility: hidden !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open .fids-v3-sidebar {
    transform: translate3d(0, 0, 0) !important;
    visibility: visible !important;
  }

  .fids-mobile-nav-backdrop {
    position: fixed;
    inset: var(--fids-mobile-topbar) 0 0 0;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: rgba(15, 23, 42, .45) !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 48000;
    transition: opacity .2s ease, visibility .2s ease;
  }

  body.fids-mobile-nav-open .fids-mobile-nav-backdrop {
    display: block !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-search {
    display: block !important;
    padding: 10px !important;
  }

  body.fids-shell-v3 .fids-v3-search input {
    height: 46px !important;
    min-height: 46px !important;
    font-size: 16px !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-label {
    display: block !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-chevron {
    display: inline-block !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-left {
    display: flex !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-subnav {
    display: none !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open .fids-v3-section.open > .fids-v3-subnav,
  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-section.open > .fids-v3-subnav {
    display: block !important;
    max-height: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open .fids-v3-section:not(.open) > .fids-v3-subnav {
    display: none !important;
    max-height: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.fids-shell-v3 .fids-v3-scroll {
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 5px 7px 16px !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.fids-shell-v3 .fids-v3-menu,
  body.fids-shell-v3 .fids-v3-single,
  body.fids-shell-v3 .fids-v3-sub {
    width: 100% !important;
    min-height: 48px !important;
    margin: 2px 0 !important;
    padding: 7px 9px !important;
    justify-content: flex-start !important;
    border-radius: 9px !important;
  }

  /*
   * Opening the phone drawer must temporarily cancel every desktop mini-rail
   * row constraint. The body intentionally keeps fids-mini so the closed
   * state remains compact, but older desktop rules otherwise leave submenu
   * links only 44px wide and make their now-visible labels wrap one letter at
   * a time.
   */
  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-menu {
    width: 100% !important;
    margin: 2px 0 !important;
    padding: 7px 9px !important;
    justify-content: space-between !important;
    box-sizing: border-box !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-single,
  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-sub {
    width: 100% !important;
    min-height: 48px !important;
    margin: 2px 0 !important;
    padding: 7px 9px !important;
    justify-content: flex-start !important;
    box-sizing: border-box !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-left {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-sub .fids-v3-icon {
    position: static !important;
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    margin: 0 !important;
  }

  body.fids-shell-v3.fids-mobile-nav-open.fids-mini .fids-v3-sub .fids-v3-label {
    display: block !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    white-space: normal !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
  }

  body.fids-shell-v3 .fids-v3-subnav {
    margin: 2px 0 7px 12px !important;
    padding: 0 0 0 6px !important;
  }

  body.fids-shell-v3 .fids-v3-footer {
    display: none !important;
  }

  /*
   * Keep workspace tabs in normal document flow on phones. Desktop uses a
   * fixed strip, but sticky/fixed positioning can cover the first dashboard
   * card when Edge's visual viewport changes as its address bar expands.
   */
  body.fids-shell-v3 .fids-v3-tabs {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    display: flex !important;
    width: 100% !important;
    height: auto !important;
    min-height: 45px !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 5px 7px 4px !important;
    gap: 5px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    background: rgba(255, 255, 255, .98) !important;
    z-index: 10 !important;
    contain: none !important;
  }

  body.fids-shell-v3 .fids-v3-tab {
    flex: 0 0 126px !important;
    width: 126px !important;
    min-width: 126px !important;
    max-width: 126px !important;
    height: 36px !important;
    padding: 0 4px 0 10px !important;
    scroll-snap-align: start;
    border-radius: 8px 8px 0 0 !important;
  }

  body.fids-shell-v3 .fids-v3-tab-close {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
  }

  /* Full-width content canvas and mobile card rhythm. */
  body.fids-shell-v3 .app-container,
  body.fids-shell-v3.fids-mini .app-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: var(--fids-mobile-gutter) !important;
  }

  body.fids-shell-v3 main {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 0 max(12px, env(safe-area-inset-bottom, 0px)) !important;
  }

  body.fids-shell-v3 .page-header,
  body.fids-shell-v3 .page-header.compact {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    margin: 0 0 10px !important;
    padding: 12px !important;
    border-radius: 10px !important;
  }

  body.fids-shell-v3 .page-header::after {
    width: 72px !important;
    height: 72px !important;
    right: -28px !important;
    top: -34px !important;
  }

  body.fids-shell-v3 h1,
  body.fids-shell-v3 .page-header h1 {
    margin: 0 !important;
    font-size: 21px !important;
    line-height: 1.16 !important;
  }

  body.fids-shell-v3 h2 {
    font-size: 17px !important;
    line-height: 1.2 !important;
  }

  body.fids-shell-v3 .header-copy {
    margin: 4px 0 0 !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
  }

  body.fids-shell-v3 .header-actions,
  body.fids-shell-v3 .report-actions,
  body.fids-shell-v3 .form-actions,
  body.fids-shell-v3 .panel-actions,
  body.fids-shell-v3 .action-row,
  body.fids-shell-v3 .upload-actions,
  body.fids-shell-v3 .table-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: stretch !important;
    width: 100% !important;
    gap: 7px !important;
    white-space: normal !important;
  }

  body.fids-shell-v3 .header-actions > *,
  body.fids-shell-v3 .report-actions > *,
  body.fids-shell-v3 .form-actions > *,
  body.fids-shell-v3 .panel-actions > *,
  body.fids-shell-v3 .action-row > *,
  body.fids-shell-v3 .upload-actions > *,
  body.fids-shell-v3 .table-actions > * {
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 !important;
  }

  body.fids-shell-v3 .panel,
  body.fids-shell-v3 .card,
  body.fids-shell-v3 .section-card,
  body.fids-shell-v3 .dashboard-card {
    min-width: 0 !important;
    max-width: 100% !important;
    margin-bottom: 10px !important;
    padding: 10px !important;
    border-radius: 10px !important;
  }

  body.fids-shell-v3 .panel-heading {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 7px !important;
    min-width: 0 !important;
    margin-bottom: 8px !important;
  }

  body.fids-shell-v3 .panel-heading > *,
  body.fids-shell-v3 .content-grid > *,
  body.fids-shell-v3 .form-grid > *,
  body.fids-shell-v3 .filter-grid > *,
  body.fids-shell-v3 .template-grid > *,
  body.fids-shell-v3 .report-grid > *,
  body.fids-shell-v3 fieldset,
  body.fids-shell-v3 label {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  body.fids-shell-v3 .content-grid,
  body.fids-shell-v3 .form-grid,
  body.fids-shell-v3 .assignment-form .form-grid,
  body.fids-shell-v3 .filter-grid,
  body.fids-shell-v3 .template-grid,
  body.fids-shell-v3 .report-grid,
  body.fids-shell-v3 .column-grid,
  body.fids-shell-v3 .structure-grid,
  body.fids-shell-v3 .request-grid,
  body.fids-shell-v3 .metric-grid,
  body.fids-shell-v3 .status-summary,
  body.fids-shell-v3 .employee-context {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body.fids-shell-v3 .span-2,
  body.fids-shell-v3 .span-3,
  body.fids-shell-v3 .span-4,
  body.fids-shell-v3 .panel-wide {
    grid-column: auto !important;
  }

  /* Native mobile form sizing; 16px prevents iOS focus zoom. */
  body.fids-shell-v3 input:not([type="checkbox"]):not([type="radio"]),
  body.fids-shell-v3 select,
  body.fids-shell-v3 textarea,
  body.fids-shell-v3 .form-control,
  body.fids-shell-v3 .form-select {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 46px !important;
    padding: 10px 11px !important;
    border-radius: 9px !important;
    font-size: 16px !important;
    line-height: 1.25 !important;
  }

  body.fids-shell-v3 textarea {
    min-height: 96px !important;
  }

  body.fids-shell-v3 .btn,
  body.fids-shell-v3 button,
  body.fids-shell-v3 [role="button"] {
    min-height: 44px;
    max-width: 100%;
    white-space: normal !important;
    overflow-wrap: anywhere;
    touch-action: manipulation;
  }

  body.fids-shell-v3 input[type="checkbox"],
  body.fids-shell-v3 input[type="radio"] {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
  }

  /* Registers remain aligned: contained, labelled as scrollable, and touch-safe. */
  body.fids-shell-v3 .table-responsive {
    position: relative;
    width: calc(100% + 20px) !important;
    max-width: none !important;
    margin-right: -10px !important;
    margin-left: -10px !important;
    padding-bottom: 4px;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e1e5eb;
    border-radius: 8px;
    background: #fff;
  }

  body.fids-shell-v3 .data-table,
  body.fids-shell-v3 .asset-table,
  body.fids-shell-v3 .admin-table,
  body.fids-shell-v3 table.fids-ticket-register {
    width: max-content !important;
    min-width: max(680px, 100%) !important;
    max-width: none !important;
    margin: 0 !important;
  }

  body.fids-shell-v3 th,
  body.fids-shell-v3 td {
    padding: 8px 9px !important;
    font-size: 12px !important;
    line-height: 1.3 !important;
    vertical-align: top !important;
  }

  body.fids-shell-v3 th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f3f4f6 !important;
  }

  /* Header dropdowns and feedback use the phone viewport instead of desktop widths. */
  body.fids-shell-v3 .notification-menu,
  body.fids-shell-v3 .notification-menu.show,
  body.fids-shell-v3 .fids-visible-user .dropdown-menu.show {
    position: fixed !important;
    top: calc(var(--fids-mobile-topbar) + 4px) !important;
    right: max(8px, env(safe-area-inset-right, 0px)) !important;
    left: max(8px, env(safe-area-inset-left, 0px)) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: calc(100dvh - var(--fids-mobile-topbar) - 16px) !important;
    overflow-y: auto !important;
    transform: none !important;
  }

  body.fids-shell-v3 .pwa-install-banner {
    right: 8px !important;
    bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
    padding: 11px !important;
    border-radius: 11px !important;
  }

  body.fids-shell-v3 .fids-action-feedback {
    top: calc(var(--fids-mobile-topbar) + 8px) !important;
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
  }

  body.fids-shell-v3 .modal-dialog {
    width: calc(100vw - 16px) !important;
    max-width: none !important;
    margin: 8px auto !important;
  }

  body.fids-shell-v3 .modal-content {
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    border-radius: 12px !important;
  }
}

@media screen and (max-width: 390px) {
  body.fids-shell-v3 .fids-visible-brand-copy {
    display: none !important;
  }

  body.fids-shell-v3 .header-actions,
  body.fids-shell-v3 .report-actions,
  body.fids-shell-v3 .form-actions,
  body.fids-shell-v3 .panel-actions,
  body.fids-shell-v3 .action-row,
  body.fids-shell-v3 .upload-actions,
  body.fids-shell-v3 .table-actions {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body.fids-shell-v3 .fids-v3-tab {
    flex-basis: 116px !important;
    width: 116px !important;
    min-width: 116px !important;
    max-width: 116px !important;
  }
}

@media screen and (max-width: 340px) {
  body.fids-shell-v3 .pwa-header-install {
    display: none !important;
  }

  body.fids-shell-v3 .fids-visible-brand img {
    width: 74px !important;
    min-width: 74px !important;
    height: 26px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.fids-shell-v3 .fids-v3-sidebar,
  .fids-mobile-nav-backdrop {
    transition: none !important;
  }
}
