/* Site-wide mobile overrides. Link last in each page's "styles" list in site.json. */

/* Controls injected by the script in include/header.html; mobile-only. */
.nea-filters-toggle,
.nea-doc-tab,
.nea-contents-back {
  display: none;
}

.nea-scroll-hint {
  display: none;
  position: fixed;
  width: 1.1rem;
  z-index: 20;
  pointer-events: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 18, 76, 0.55);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
}

.nea-scroll-hint-left {
  border-radius: 0 0.5rem 0.5rem 0;
}

.nea-scroll-hint-right {
  border-radius: 0.5rem 0 0 0.5rem;
}

.nea-scroll-hint-left::before {
  content: "\2039";
}

.nea-scroll-hint-right::before {
  content: "\203A";
}

.nea-scroll-hint.nea-show {
  display: flex;
}

@media only screen and (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    font-size: 11pt;
    overflow-x: hidden;
  }

  img,
  video,
  iframe,
  svg {
    max-width: 100%;
    height: auto;
  }

  iframe {
    height: auto;
    min-height: 50vh;
  }

  .content {
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: anywhere;
  }

  /* 16px prevents iOS Safari from zooming on focus. */
  input,
  select,
  textarea {
    font-size: 16px !important;
    max-width: 100%;
  }

  button,
  .sidebar-toggle,
  nav a,
  select {
    min-height: 44px;
  }

  .sidebar-toggle {
    min-width: 44px;
    width: 44px;
    height: 44px;
  }

  nav a {
    display: block;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .g4-search {
    width: 100%;
    margin: 12px 0;
    gap: 8px;
  }

  .g4-search input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .g4-search button {
    flex: 0 0 auto;
    padding: 0 16px;
  }

  /* Wide tables scroll within themselves instead of the page. */
  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  pre,
  code {
    white-space: pre-wrap;
    overflow-x: auto;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.35rem;
  }

  /* Search page: a plain column. The desktop grid keeps empty named rows (summary,
     picker, fields) that each add a gap when the filters are collapsed. */
  .content:has(> .search-results) {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
  }

  /* search.css hides these at <=600px expecting an ".open" class nothing adds. */
  .search-summary .query,
  .search-collection-picker .collections {
    display: block;
  }

  .search-summary .field {
    grid-template-columns: 5rem minmax(0, 1fr) 1.25rem;
    column-gap: 0.5rem;
  }

  /* Search page: let the selected-collection blurb wrap instead of overflowing. */
  .search-entry form {
    width: 100%;
  }

  .selected-collection-blurb {
    flex-wrap: wrap;
    white-space: normal;
    row-gap: 0;
  }

  .selected-collection-blurb button,
  .selected-collection-blurb .search-field-picker {
    min-height: 0;
  }

  /* Contents page: the page itself never scrolls; the browser fills what the header leaves. */
  .layout:has(.contents-browser) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .layout:has(.contents-browser) > .header {
    flex: 0 0 auto;
  }

  .content:has(.contents-browser) {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    padding-bottom: 0;
    overflow: hidden;
  }

  .content:has(.contents-browser) > * {
    flex: 0 0 auto;
  }

  /* Contents page: tree and document list are full-width columns that scroll sideways. */
  .content > .contents-browser {
    flex: 1 1 0;
    min-height: 0;
  }

  .contents-browser {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0;
    width: 100%;
    height: auto;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .contents-browser > .contents-tree,
  .contents-browser > .contents-list {
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    margin: 0;
    padding: 0.5rem 0.5rem 0;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-align: start;
  }

  /* The document viewer root is a zero-size wrapper around a fixed overlay. */
  .contents-browser > :not(.contents-tree):not(.contents-list) {
    flex: 0 0 0;
    width: 0;
  }

  body.nea-contents-list .nea-contents-back {
    display: flex;
    align-items: center;
    position: fixed;
    left: 0.75rem;
    bottom: 0.75rem;
    z-index: 5000;
    padding: 0 1rem;
    border: 1px solid #001246;
    border-radius: 1.4rem;
    background: linear-gradient(180deg, #001a71 0%, #011d52 100%);
    color: #fff;
    font-size: 1rem;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0, 18, 70, 0.35);
    cursor: pointer;
  }

  /* Search page: summary, collection picker and fields collapse behind a toggle. */
  .nea-filters-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 0.85rem;
    border: 1px solid var(--nea-line);
    border-radius: 0.5rem;
    background: var(--nea-paper-alt);
    color: var(--nea-navy);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 10px -3px rgba(0, 18, 76, 0.35);
  }

  .nea-filters-toggle::after {
    content: "\25BE";
    font-size: 1.8rem;
    line-height: 1;
  }

  .nea-filters-toggle[aria-expanded="true"]::after {
    content: "\25B4";
  }

  .nea-filters:not(.nea-open) {
    display: none;
  }

  /* Open: the toggle and the filters share one tinted, bordered frame. */
  .nea-filters-toggle[aria-expanded="true"] {
    border-bottom-color: transparent;
    border-radius: 0.5rem 0.5rem 0 0;
    clip-path: inset(-12px -12px 0 -12px);
  }

  .nea-filters.nea-open {
    margin-top: -0.75rem;
    padding: 0.5rem;
    border: 1px solid var(--nea-line);
    border-top: 0;
    border-radius: 0 0 0.5rem 0.5rem;
    background: var(--nea-paper-alt);
    box-shadow: 0 2px 10px -3px rgba(0, 18, 76, 0.35);
    clip-path: inset(0 -12px -12px -12px);
  }

  /* Document page: metadata bar spans the full width; the controls drawer sits below it. */
  .docview-metadata {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Long titles wrap onto extra lines instead of being clipped. */
  .docview-metadata-header {
    height: auto;
    min-height: 2.75rem;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    padding-right: 3.25rem;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
  }

  /* Metadata rows are grids so they always fit the page width regardless of content. */
  .docview-metadata table,
  .docview-metadata tbody {
    display: block;
    width: 100%;
    overflow: visible;
  }

  .docview-metadata tr {
    display: grid;
    grid-template-columns: minmax(4.5rem, 7rem) minmax(0, 1fr) auto;
  }

  .docview-metadata td {
    display: block;
    width: auto;
    min-width: 0;
    max-width: none;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Document page: Close stays put; the other in-doc controls slide in behind a tab. */
  .in-doc-controls {
    position: fixed;
    top: var(--nea-doc-top, 3.25rem);
    right: 0;
    width: 2.75rem !important;
    max-height: calc(100vh - var(--nea-doc-top, 3.25rem));
    overflow: hidden auto;
    pointer-events: none;
  }

  .in-doc-controls > * {
    pointer-events: auto;
  }

  .in-doc-controls > :not(.control-close) {
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  body.nea-doc-open .in-doc-controls > :not(.control-close) {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.2s ease;
  }

  /* Fixed to the viewport corner; the metadata header leaves room for it. */
  .in-doc-controls > .control-close {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 5004;
  }

  body.nea-has-doc-controls .nea-doc-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: var(--nea-doc-top, 3.25rem);
    right: 0;
    width: 1.5rem;
    min-height: 0;
    height: 2.75rem;
    padding: 0;
    z-index: 5004;
    border: 1px solid #001246;
    border-right: 0;
    border-radius: 0.5rem 0 0 0.5rem;
    background: linear-gradient(180deg, #001a71 0%, #011d52 100%);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    transition: right 0.2s ease;
  }

  body.nea-has-doc-controls .nea-doc-tab::before {
    content: "\25C0";
  }

  body.nea-doc-open .nea-doc-tab {
    right: 2.75rem;
  }

  body.nea-doc-open .nea-doc-tab::before {
    content: "\25B6";
  }

  /* Document page: the document starts below the metadata header, not under it. */
  .document-viewer iframe {
    margin-top: var(--nea-doc-top, 3.25rem);
    height: calc(100vh - var(--nea-doc-top, 3.25rem));
    height: calc(100dvh - var(--nea-doc-top, 3.25rem));
    min-height: 0;
  }

  /* Login page: a near-full-width card with stacked labels and fields. */
  .login-area {
    width: calc(100% - 1.5rem);
    margin: 1.5rem auto;
    padding: 1rem;
  }

  .login-area .label {
    display: block;
    width: auto;
    margin: 0.5rem 0 0.25rem;
    text-align: left;
  }

  .login-area input.credential {
    display: block;
    width: 100%;
    height: 44px;
    margin-bottom: 0.5rem;
  }

  .login-area #remember {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
  }

  .login-area .remember label {
    font-size: 1rem;
  }

  .login-area .buttons button {
    width: 100%;
    min-height: 48px;
  }

  .login-area .links {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .login-area .links a {
    margin: 0;
    padding: 0.4rem 0;
  }

  .login-logo-frame {
    text-align: center;
    padding: 0.5rem 0;
  }

  /* Hamburger first, logo beside it. The toggle may sit in a wrapper div, so order the wrapper too. */
  .header > .sidebar-toggle,
  .header > :has(> .sidebar-toggle) {
    order: -1;
    flex: 0 0 auto;
    height: auto;
    margin: 0;
    padding: 0;
  }

  .header .logo {
    margin: 0;
  }

  /* Users page: filters stack, and each table row becomes a labelled card. */
  .users-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem 0;
  }

  .users-filter input,
  .users-filter select,
  .users-filter button {
    width: 100%;
    min-height: 44px;
  }

  .users {
    height: auto;
    overflow-x: hidden;
  }

  .users table,
  .users tbody,
  .users tr,
  .users td {
    display: block;
    width: 100%;
    max-width: none;
    white-space: normal;
    overflow: visible;
  }

  .users table thead {
    display: none;
  }

  .users table tbody tr {
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--nea-line);
    border-radius: 0.5rem;
  }

  .users table td,
  .users table td:first-child {
    padding: 0.15rem 0;
    border: 0;
    overflow-wrap: anywhere;
  }

  .users table td:empty {
    display: none;
  }

  .users table td::before {
    display: inline-block;
    width: 5.5rem;
    font-weight: bold;
    color: var(--nea-navy);
  }

  .user .username::before { content: "Username"; }
  .user .fullname::before { content: "Name"; }
  .user .email::before { content: "Email"; }
  .user .status::before { content: "Status"; }
  .user .last-login::before { content: "Last login"; }
  .user .profiles::before { content: "Profiles"; }

  /* Users page: the edit dialog spans nearly the full width. */
  .user-dialog {
    position: fixed;
    top: 0.75rem;
    left: 0.5rem;
    right: 0.5rem;
    margin: 0;
    transform: none;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    padding: 0.75rem;
  }

  .user-dialog .form-field {
    flex-direction: column;
    margin-bottom: 0.4rem;
  }

  .user-dialog .form-label {
    width: auto;
    padding: 0.25rem 0;
  }

  .user-dialog .form-value {
    width: 100%;
    padding: 0;
  }

  .user-dialog .form-value input,
  .user-dialog .form-value select {
    width: 100%;
  }

  .user-dialog .form-profiles input {
    width: auto;
  }

  .user-dialog .ud-controls {
    flex-direction: column-reverse;
    padding: 0.5rem 0 0;
  }

  .user-dialog .ud-controls-1,
  .user-dialog .ud-controls-2 {
    width: 100%;
    gap: 0.5rem;
  }

  .user-dialog button {
    flex: 1 1 0;
    height: auto;
    min-height: 44px;
    padding: 0.4rem 0.75rem;
    white-space: nowrap;
    line-height: 1.2;
  }

  /* Profiles page: the edit dialog spans nearly the full width. */
  .profiles {
    min-width: 0;
  }

  .profile-dialog {
    position: fixed;
    top: 0.75rem;
    left: 0.5rem;
    right: 0.5rem;
    margin: 0;
    transform: none;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    padding: 0.75rem;
  }

  .profile-dialog .pd-name {
    display: block;
    width: 100%;
    margin: 0.35rem 0 0;
  }

  .profile-dialog fieldset {
    min-width: 0;
  }

  .profile-dialog .pd-controls {
    flex-direction: column-reverse;
    padding: 0.5rem 0 0;
  }

  .profile-dialog .pd-controls-1,
  .profile-dialog .pd-controls-2 {
    width: 100%;
    gap: 0.5rem;
  }

  .profile-dialog button {
    flex: 1 1 0;
    height: auto;
    min-height: 44px;
    padding: 0.4rem 0.75rem;
    white-space: nowrap;
    line-height: 1.2;
  }

  /* Collection boxes on subpages: one full-width box per row. */
  #content-area ul.boxList {
    grid-template-columns: 1fr;
  }

  #content-area ul.boxList > li {
    width: 100%;
  }

  .g4admin-link {
    top: auto !important;
    bottom: 0.5rem;
    left: auto !important;
    right: 0.5rem;
    width: auto;
  }
}

@media only screen and (max-width: 480px) {
  .content {
    padding: 0.75rem;
  }

  .header {
    padding: 0.5rem 0.65rem;
  }

  .logo {
    width: 130px;
  }

  h1 {
    font-size: 1.4rem;
  }

  h2 {
    font-size: 1.2rem;
  }
}
