/* fqm-web's own rules, layered over the shared stylesheet. Linked by both
   shells (_layout.html and _public.html), after output.css.

   1. Phone and tablet: touch-sized controls, text controls that do not make
      the browser zoom, long values that wrap instead of widening the page. */

/* A long value (an e-mail address, an id) has no break opportunity: it widens
   its table until the columns after it are off-screen, and overflows a row
   that has reflowed into a card. */
.fqm-wrap-anywhere { overflow-wrap: anywhere; }

@media (max-width: 767.98px) {
  /* The shared table-to-cards reflow (`strata-rtable`): a value too long for
     its card wraps instead of running out of it. A cell marked as a long
     value puts its label on a line of its own, so the value gets the card's
     whole width and breaks only when it has to. */
  table.strata-rtable td { overflow-wrap: break-word; }
  table.strata-rtable td.fqm-wrap-anywhere { overflow-wrap: break-word; text-align: start; }
  table.strata-rtable td.fqm-wrap-anywhere::before { float: none; display: block; max-width: none; margin: 0 0 0.15rem; }
}

@media (max-width: 1023.98px) {
  /* iOS zooms the page when a focused text control is under 16px, and does
     not zoom back. The size classes (input-sm, select-xs) are smaller. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Touch targets: 44px in the content well, the drawer and the top bar. */
  :is(#content, main, .fqm-nav-foot) :is(button, .btn, select, summary, [role="tab"]),
  :is(#content, main, .fqm-nav-foot) input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]) {
    min-height: 2.75rem;
  }
  :is(#content, main, .fqm-nav-foot) :is(button, .btn) {
    min-width: 2.75rem;
  }
  /* A bare checkbox or radio: its label is the target. */
  :is(#content, main) label:has(> input[type="checkbox"], > input[type="radio"]) {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
  }
  /* The compact button sizes keep their type size but not their height. */
  :is(#content, main, .fqm-nav-foot) :is(.btn-xs, .btn-sm) {
    padding-inline: 0.875rem;
  }
  /* The top bar's menu button: the first control of the header beside the
     sidebar (the shell gives it no name of its own in every release). */
  .sidebar-nav + div > header > button:first-child {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    margin: -0.125rem;
  }
}

/* 2. Navigation: the sidebar (a drawer below 1024px) and the phone tab bar.
      Colours are the theme's tokens, so every theme and both directions
      (the rules use logical properties) get the same structure. */

/* The light theme's brand orange is about 2:1 on its canvas: eyebrow text
   takes the dark orange step there (5.8:1), the dark theme keeps the brand. */
[data-theme="atlasmerlin-light"] .am-eyebrow { color: #9A4A00; }
.fqm-mobile-mark { display: inline-flex; align-items: center; color: var(--color-base-content); }

/* Groups: a small mono heading over its rows. */
#nav-items > .fqm-nav-group + .fqm-nav-group { margin-top: 1.25rem; }
.fqm-nav-group > * + * { margin-top: 0.125rem; }
.fqm-nav-heading {
  padding: 0 0.75rem 0.375rem;
  color: color-mix(in oklab, var(--color-base-content) 48%, transparent);
}

/* A row. The current page is a filled row with the brand's rule on its
   leading edge; `aria-current` is the state, the classes follow it. */
.fqm-nav {
  min-height: 2.5rem;
  border-inline-start: 2px solid transparent;
  scroll-margin-block: 0.5rem;
}
.fqm-nav svg { opacity: 0.75; }
.fqm-nav[aria-current="page"] {
  border-inline-start-color: var(--color-primary);
  background: var(--color-base-300);
  color: var(--color-base-content);
}
.fqm-nav[aria-current="page"] svg { opacity: 1; color: var(--color-primary); }
.fqm-nav:focus-visible,
.fqm-nav-toggle:focus-visible,
.fqm-tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* A row that is a button (Equipment, Install, Sign out) reads as a row. */
button.fqm-nav {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: start;
  cursor: pointer;
  color: color-mix(in oklab, var(--color-base-content) 60%, transparent);
  transition: color 0.15s, background-color 0.15s;
}
button.fqm-nav:hover {
  color: var(--color-base-content);
  background: color-mix(in oklab, var(--color-base-300) 50%, transparent);
}

/* A row with nested rows: the row, then the control that folds them. */
.fqm-nav-parent { display: flex; align-items: stretch; gap: 0.125rem; }
.fqm-nav-parent > a { flex: 1 1 auto; min-width: 0; }
.fqm-nav-toggle {
  flex: none;
  display: inline-flex;
  width: 2.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  cursor: pointer;
  color: color-mix(in oklab, var(--color-base-content) 55%, transparent);
}
.fqm-nav-toggle:hover {
  color: var(--color-base-content);
  background: color-mix(in oklab, var(--color-base-300) 50%, transparent);
}
.fqm-nav-chevron { width: 1rem; height: 1rem; flex: none; transition: rotate 0.15s; }
.fqm-nav-fold .fqm-nav-chevron { margin-inline-start: auto; opacity: 0.6; }
[aria-expanded="false"] > .fqm-nav-chevron { rotate: -90deg; }
[dir="rtl"] [aria-expanded="false"] > .fqm-nav-chevron { rotate: 90deg; }

/* Nested rows: indented under a guide rule, lighter and smaller. */
.fqm-nav-children {
  display: grid;
  gap: 0.125rem;
  margin-inline-start: 1.3125rem;
  padding-inline-start: 0.5rem;
  border-inline-start: 1px solid color-mix(in oklab, var(--color-base-content) 12%, transparent);
}
.fqm-nav-children[hidden] { display: none; }
.fqm-nav-sub {
  display: flex;
  align-items: center;
  min-height: 2.125rem;
  padding: 0.3125rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  color: color-mix(in oklab, var(--color-base-content) 58%, transparent);
  transition: color 0.15s, background-color 0.15s;
}
.fqm-nav-sub:hover {
  color: var(--color-base-content);
  background: color-mix(in oklab, var(--color-base-300) 50%, transparent);
}

/* Under the list: Settings, the account, the language, Sign out. The
   shell pads this area 1rem and the list 0.75rem; the rows line up with the
   list's. */
.fqm-nav-foot { margin-inline: -0.25rem; }
.fqm-nav-foot > * + * { margin-top: 0.125rem; }
.fqm-nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border-inline-start: 2px solid transparent;
  font-size: 0.875rem;
  color: color-mix(in oklab, var(--color-base-content) 78%, transparent);
}
.fqm-nav-user svg { opacity: 0.75; }
.fqm-nav-user span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fqm-nav-prefs { padding: 0.125rem 0.75rem; }

/* Phone and tablet tab bar: the pages used most, then More (the drawer). */
.fqm-tabbar {
  display: flex;
  border-top: 1px solid color-mix(in oklab, var(--color-base-content) 10%, transparent);
  background: var(--color-base-200);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.fqm-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 3.375rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.2rem;
  padding: 0.5rem 0.25rem 0.45rem;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  color: color-mix(in oklab, var(--color-base-content) 62%, transparent);
  border-top: 2px solid transparent;
  margin-top: -1px;
  cursor: pointer;
}
/* A label too long for its tab (five tabs on a narrow phone, a longer
   language) takes a second line rather than losing its end. */
.fqm-tab span {
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.fqm-tab[aria-current="page"],
.fqm-tab[aria-expanded="true"] { color: var(--color-base-content); border-top-color: var(--color-primary); }
@media (min-width: 1024px) { .fqm-tabbar { display: none; } }

@media (max-width: 1023.98px) {
  /* Below 1024px the sidebar is always a drawer (the layout's sidebar_init):
     the shell's "Pin sidebar" control would put it back in flow, over most of
     a phone's width, so it is not offered there. */
  .sidebar-nav label:has(> input[x-model="sidebarPinned"]) { display: none; }
  /* In the drawer every row is a touch target. */
  .sidebar-nav .fqm-nav,
  .sidebar-nav .fqm-nav-sub { min-height: 2.75rem; }
  .sidebar-nav .fqm-nav-toggle { width: 2.75rem; }
}
