/* Design 003 app frame (UI contract layer 2: shell). AppHeader, PillNav, NavPill, IconButton, WorkspaceSwitcher,
 * account menu, mobile bottom bar and its More sheet, and the page frame they sit on.
 * Reads only --fm-* tokens (assets/design-003-app.css). No colour, size, radius, shadow or font literals here.
 * Scope: body.fd-design (os.html). Markup is static in os.html and filled by assets/os-boot.js (paintSidebar).
 * Tabs under the header are .fm-tabs / .fm-tab, drawn by os-boot.js; their look lives in assets/d3/components.css. */

/* ---- page frame -------------------------------------------------------------------------------------------- */
body.fd-design #shell {
  display: block;
  max-width: var(--fm-page-max);
  min-height: calc(100dvh - var(--fm-header-h));
  margin: 0 auto;
  padding: 0;
}
body.fd-design #main {
  display: flex;
  flex-direction: column;
  width: auto;
  min-width: 0;
  max-width: none;
  margin: 0;
  padding: var(--fm-space-6) max(var(--fm-gutter), env(safe-area-inset-right)) var(--fm-space-8) max(var(--fm-gutter), env(safe-area-inset-left));
  background: transparent;
}
body.auth-pending .fm-header,
body.auth-pending .fm-mobilenav { visibility: hidden; }

/* ---- AppHeader --------------------------------------------------------------------------------------------- */
.fm-header {
  position: sticky;
  top: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: var(--fm-space-4);
  box-sizing: border-box;
  height: var(--fm-header-h);
  padding-block: 0;
  padding-inline: max(var(--fm-gutter), calc((100% - var(--fm-page-max)) / 2 + var(--fm-gutter)));
  background: var(--fm-bg);
  border-bottom: var(--fm-border-width) solid var(--fm-line);
  color: var(--fm-ink);
  font-family: var(--fm-font-sans);
}
.fm-header [hidden],
.fm-mobilenav [hidden] { display: none !important; }
.fm-brand {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: var(--fm-space-2);
  min-height: var(--fm-tap-min);
  color: var(--fm-ink);
  font-size: var(--fm-text-lg);
  font-weight: var(--fm-weight-bold);
  text-decoration: none;
}
.fm-brand img {
  display: block;
  width: calc(var(--fm-tap-min) * .75);
  height: calc(var(--fm-tap-min) * .75);
  object-fit: contain;
}
.fm-header__tools {
  display: flex;
  align-items: center;
  flex: none;
  gap: var(--fm-space-2);
  margin-inline-start: auto;
}

/* ---- PillNav / NavPill: one pill per space, always all visible ---------------------------------------------- */
.fm-pillnav {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: var(--fm-space-1);
  min-width: 0;
  padding: var(--fm-space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.fm-pillnav::-webkit-scrollbar { display: none; }
.fm-pill {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: var(--fm-space-2);
  box-sizing: border-box;
  min-width: var(--fm-tap-min);
  min-height: var(--fm-tap-min);
  padding-inline: var(--fm-space-4);
  border-radius: var(--fm-radius-pill);
  color: var(--fm-ink-2);
  font-size: var(--fm-text-md);
  font-weight: var(--fm-weight-medium);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--fm-motion-fast) var(--fm-ease), color var(--fm-motion-fast) var(--fm-ease);
}
.fm-pill svg,
.fm-mobilenav__item svg,
.fm-sheet__item svg,
.fm-menu__item svg {
  flex: none;
  width: var(--fm-text-lg);
  height: var(--fm-text-lg);
}
.fm-pill:hover { background: var(--fm-surface-alt); color: var(--fm-ink); }
/* R1: navy marks only where you are. */
.fm-pill[aria-current="page"] {
  background: var(--fm-nav-active-bg);
  color: var(--fm-nav-active-ink);
  font-weight: var(--fm-weight-semibold);
}

/* ---- IconButton --------------------------------------------------------------------------------------------- */
.fm-iconbtn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  box-sizing: border-box;
  width: var(--fm-tap-min);
  height: var(--fm-tap-min);
  margin: 0;
  padding: 0;
  border: var(--fm-border-width) solid var(--fm-line);
  border-radius: var(--fm-radius-pill);
  background: var(--fm-surface);
  color: var(--fm-ink);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--fm-motion-fast) var(--fm-ease);
}
.fm-iconbtn svg { width: var(--fm-text-lg); height: var(--fm-text-lg); }
.fm-iconbtn:hover { background: var(--fm-surface-alt); }
.fm-iconbtn[aria-current="page"] { border-color: var(--fm-nav-active-bg); }
.fm-iconbtn__badge {
  position: absolute;
  top: calc(var(--fm-space-1) * -1);
  inset-inline-end: calc(var(--fm-space-1) * -1);
  box-sizing: border-box;
  min-width: var(--fm-space-5);
  height: var(--fm-space-5);
  padding-inline: var(--fm-space-1);
  border-radius: var(--fm-radius-pill);
  background: var(--fm-urgent);
  color: var(--fm-on-dark);
  font-size: var(--fm-text-sm);
  font-weight: var(--fm-weight-bold);
  line-height: var(--fm-space-5);
  text-align: center;
}

/* ---- WorkspaceSwitcher (one firm today: opens My Firm) ------------------------------------------------------- */
.fm-workspace {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  max-width: calc(var(--fm-tap-min) * 4);
  min-height: var(--fm-tap-min);
  padding-inline: var(--fm-space-3);
  overflow: hidden;
  border-radius: var(--fm-radius-pill);
  color: var(--fm-ink-2);
  font-size: var(--fm-text-sm);
  font-weight: var(--fm-weight-semibold);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fm-workspace:hover { background: var(--fm-surface-alt); color: var(--fm-ink); }

/* ---- Account: avatar + menu --------------------------------------------------------------------------------- */
.fm-account { position: relative; }
body.fd-design .fm-account > .fm-avatar {
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  width: var(--fm-tap-min);
  height: var(--fm-tap-min);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--fm-radius-pill);
  background: var(--fm-nav-active-bg);
  color: var(--fm-nav-active-ink);
  font-family: var(--fm-font-sans);
  font-size: var(--fm-text-sm);
  font-weight: var(--fm-weight-bold);
  cursor: pointer;
}
.fm-menu {
  position: absolute;
  top: calc(100% + var(--fm-space-2));
  inset-inline-end: 0;
  z-index: 90;
  box-sizing: border-box;
  width: calc(var(--fm-tap-min) * 6);
  max-width: calc(100vw - var(--fm-gutter) * 2);
  max-height: calc(100dvh - var(--fm-header-h) - var(--fm-space-4));
  overflow-y: auto;
  padding: var(--fm-space-2);
  border: var(--fm-border-width) solid var(--fm-line);
  border-radius: var(--fm-radius-lg);
  background: var(--fm-surface);
  box-shadow: var(--fm-shadow-2);
}
.fm-menu__who {
  display: flex;
  flex-direction: column;
  gap: var(--fm-space-2);
  padding: var(--fm-space-3);
  border-bottom: var(--fm-border-width) solid var(--fm-line);
}
.fm-menu__email {
  color: var(--fm-ink);
  font-size: var(--fm-text-sm);
  font-weight: var(--fm-weight-semibold);
  overflow-wrap: anywhere;
}
.fm-menu__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--fm-space-2);
}
.fm-menu__credits { color: var(--fm-ink-2); font-size: var(--fm-text-sm); }
.fm-menu__list { margin: 0; padding: var(--fm-space-2) 0; list-style: none; }
.fm-menu__item {
  display: flex;
  align-items: center;
  gap: var(--fm-space-3);
  box-sizing: border-box;
  width: 100%;
  min-height: var(--fm-tap-min);
  margin: 0;
  padding: 0 var(--fm-space-3);
  border: 0;
  border-radius: var(--fm-radius-md);
  background: transparent;
  color: var(--fm-ink);
  font-family: var(--fm-font-sans);
  font-size: var(--fm-text-md);
  font-weight: var(--fm-weight-medium);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
.fm-menu__item:hover { background: var(--fm-surface-alt); }
/* R1: a selected row is the cream tint with a bold title, never navy. */
.fm-menu__item[aria-current="page"] {
  background: var(--fm-row-selected-bg);
  color: var(--fm-row-selected-ink);
  font-weight: var(--fm-weight-bold);
}
.fm-menu__item .lock {
  margin-inline-start: auto;
  padding: 0 var(--fm-space-2);
  border: var(--fm-border-width) solid var(--fm-line-strong);
  border-radius: var(--fm-radius-pill);
  color: var(--fm-ink-2);
  font-size: var(--fm-text-sm);
}
#sb-signout.fm-menu__item { border-top: var(--fm-border-width) solid var(--fm-line); border-radius: 0 0 var(--fm-radius-md) var(--fm-radius-md); }

/* ---- focus: every control in the frame shows the one ring --------------------------------------------------- */
.fm-brand:focus-visible,
.fm-pill:focus-visible,
.fm-iconbtn:focus-visible,
.fm-workspace:focus-visible,
body.fd-design .fm-account > .fm-avatar:focus-visible,
.fm-menu__item:focus-visible,
.fm-mobilenav__item:focus-visible,
.fm-sheet__item:focus-visible,
.fm-header .fm-btn:focus-visible {
  outline: calc(var(--fm-border-width) * 2) solid var(--fm-focus-ring);
  outline-offset: calc(var(--fm-border-width) * 2);
}
.fm-menu__item:focus-visible,
.fm-sheet__item:focus-visible { outline-offset: calc(var(--fm-border-width) * -2); }

/* ---- Tabs under the header (.fm-tabs look: components.css; placement here) ---------------------------------- */
body.fd-design #subnav[hidden] { display: none; }
body.fd-design #subnav.fm-tabs {
  flex-wrap: nowrap;
  margin: 0 0 var(--fm-space-4);
  overflow-x: auto;
  scrollbar-width: none;
}
body.fd-design #subnav.fm-tabs::-webkit-scrollbar { display: none; }
body.fd-design #subnav.fm-tabs > a { flex: none; white-space: nowrap; }

/* ---- the note that opens from "Send feedback" in the menu ---------------------------------------------------- */
@media (min-width: 761px) {
  body.fd-design.fm-feedback-in-menu #fedm8-feedback-fab {
    top: calc(var(--fm-header-h) + var(--fm-space-2));
    bottom: auto;
    left: auto;
    right: max(var(--fm-gutter), env(safe-area-inset-right));
    z-index: 95;
  }
  body.fd-design.fm-feedback-in-menu #fedm8-feedback-fab .ff-btn { display: none; }
  body.fd-design.fm-feedback-in-menu #fedm8-feedback-fab .ff-panel {
    top: 0;
    bottom: auto;
    right: 0;
    max-height: calc(100dvh - var(--fm-header-h) - var(--fm-space-6));
    overflow-y: auto;
  }
}

/* ---- wide screens that are not wide enough for nine labels: icons, with the open space named --------------- */
@media (max-width: 1180px) {
  .fm-pill:not([aria-current="page"]) { padding-inline: var(--fm-space-3); }
  .fm-pill:not([aria-current="page"]) > span {
    position: absolute;
    width: var(--fm-border-width);
    height: var(--fm-border-width);
    margin: calc(var(--fm-border-width) * -1);
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .fm-workspace { max-width: calc(var(--fm-tap-min) * 2.5); }
}
@media (max-width: 1023px) {
  .fm-workspace { display: none; }
}
@media (max-width: 900px) {
  .fm-pill[aria-current="page"] { padding-inline: var(--fm-space-3); }
  .fm-pill[aria-current="page"] > span {
    position: absolute;
    width: var(--fm-border-width);
    height: var(--fm-border-width);
    margin: calc(var(--fm-border-width) * -1);
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Very small phones (320px): the signed-out tools row shrinks and the help label wraps instead of pushing the page sideways. */
@media (max-width: 400px) {
  .fm-header__tools { flex: 0 1 auto; min-width: 0; }
  .fm-header__tools #fm-help { min-width: 0; white-space: normal; text-align: center; }
  .fm-header__tools #fm-signin { flex: none; white-space: nowrap; }
}

/* ---- phone: compact header, bottom bar, More sheet ----------------------------------------------------------- */
.fm-mobilenav { display: none; }
.fm-sheet { display: none; }
@media (max-width: 768px) {
  .fm-header {
    gap: var(--fm-space-2);
    padding-inline: max(var(--fm-gutter-mobile), env(safe-area-inset-left)) max(var(--fm-gutter-mobile), env(safe-area-inset-right));
  }
  .fm-pillnav,
  .fm-workspace { display: none; }
  body.fd-design #main {
    padding: var(--fm-space-4) max(var(--fm-gutter-mobile), env(safe-area-inset-right)) calc(var(--fm-tap-min) * 2 + var(--fm-space-4) + env(safe-area-inset-bottom)) max(var(--fm-gutter-mobile), env(safe-area-inset-left));
  }
  .fm-mobilenav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 90;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--fm-space-1);
    box-sizing: border-box;
    padding: var(--fm-space-2) max(var(--fm-space-2), env(safe-area-inset-right)) calc(var(--fm-space-2) + env(safe-area-inset-bottom)) max(var(--fm-space-2), env(safe-area-inset-left));
    border-top: var(--fm-border-width) solid var(--fm-line);
    background: var(--fm-surface);
  }
  .fm-mobilenav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--fm-space-1);
    box-sizing: border-box;
    min-width: 0;
    min-height: calc(var(--fm-tap-min) + var(--fm-space-3));
    margin: 0;
    padding: var(--fm-space-1);
    border: 0;
    border-radius: var(--fm-radius-lg);
    background: transparent;
    color: var(--fm-ink-2);
    font-family: var(--fm-font-sans);
    font-size: var(--fm-text-sm);
    font-weight: var(--fm-weight-medium);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
  }
  .fm-mobilenav__item > span { max-width: 100%; overflow-wrap: anywhere; }
  .fm-mobilenav__item[aria-current="page"] {
    background: var(--fm-nav-active-bg);
    color: var(--fm-nav-active-ink);
    font-weight: var(--fm-weight-semibold);
  }
  .fm-mobilenav__item[data-within="true"] { color: var(--fm-ink); font-weight: var(--fm-weight-bold); }
  .fm-sheet:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: flex;
    align-items: flex-end;
  }
  .fm-sheet::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--fm-ink);
    opacity: .5;
  }
  .fm-sheet__panel {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    max-height: 80dvh;
    overflow-y: auto;
    padding: var(--fm-space-4) max(var(--fm-gutter-mobile), env(safe-area-inset-right)) calc(var(--fm-space-4) + env(safe-area-inset-bottom)) max(var(--fm-gutter-mobile), env(safe-area-inset-left));
    border-radius: var(--fm-radius-xl) var(--fm-radius-xl) 0 0;
    background: var(--fm-surface);
    color: var(--fm-ink);
  }
  .fm-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--fm-space-3); }
  .fm-sheet__title { margin: 0; font-size: var(--fm-text-lg); font-weight: var(--fm-weight-bold); }
  .fm-sheet__list { margin: var(--fm-space-2) 0 0; padding: 0; list-style: none; }
  .fm-sheet__item {
    display: flex;
    align-items: center;
    gap: var(--fm-space-3);
    box-sizing: border-box;
    min-height: var(--fm-tap-min);
    padding: 0 var(--fm-space-3);
    border-radius: var(--fm-radius-md);
    color: var(--fm-ink);
    font-size: var(--fm-text-md);
    font-weight: var(--fm-weight-medium);
    text-decoration: none;
  }
  .fm-sheet__item:hover { background: var(--fm-surface-alt); }
  .fm-sheet__item[aria-current="page"] {
    background: var(--fm-row-selected-bg);
    color: var(--fm-row-selected-ink);
    font-weight: var(--fm-weight-bold);
  }
  .fm-menu { position: fixed; top: calc(var(--fm-header-h) + var(--fm-space-1)); inset-inline: var(--fm-gutter-mobile); width: auto; max-width: none; }
  body.fm-sheet-open { overflow: hidden; }
}
/* 320 px phones (Q-31): five columns leave too little room, so "Veterans" broke mid-word. Give the labels the side padding and gaps instead. */
@media (max-width: 359px) {
  .fm-mobilenav { gap: 0; padding-inline: max(var(--fm-space-1), env(safe-area-inset-left)) max(var(--fm-space-1), env(safe-area-inset-right)); }
  .fm-mobilenav__item { padding-inline: 0; }
}
@media (max-width: 768px) and (max-height: 480px) {
  .fm-mobilenav__item { min-height: var(--fm-tap-min); flex-direction: row; justify-content: center; }
}

/* Rebuilt routes (os-boot.js D3_PAGES) start with their own fm-page header: the earlier page title, help button, photo and public tab strip step aside. */
body.fd-design[data-d3-page="true"] #main :is(#page-head, #fd-public-tabs, figure.fd-topic-photo) { display: none; }
/* A rebuilt page without a header of its own (D3_PAGES value "title") keeps the shell page title as its H1; everything else above it steps aside. */
body.fd-design[data-d3-page="title"] #main :is(#fd-public-tabs, figure.fd-topic-photo, #page-help, .fd-page-help, #page-head .sub) { display: none; }
body.fd-design[data-d3-page="title"] #main #page-head { margin-block: var(--fm-space-3) var(--fm-space-5); padding: 0; }
