/* Admin shell responsive layout — viewport-bands reconcile (Y1).
   Layout bands use html[data-viewport] set by admin-shell.js (viewport-constants.mjs).
   Capability queries (orientation, hover) remain @media where noted in brief.
*/

/* ── Touch scroll: middle panel (#contentArea) on iPad Safari ───────────── */
#contentArea,
.main-content > .content-area {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
}

/* ── Cap roadmap brief-drawer rail so 560px default cannot blow the grid ── */
html[data-viewport^="tablet-"],
html[data-viewport="desktop-s"] {
  .admin-shell:has([data-right-rail][data-right-rail-tenant="drawer"]) {
    --shell-right-rail-w: min(var(--oar-drawer-rail-width-px, 360px), 42vw);
  }
}

/* desktop-s: collapsed context rail = 36px ribbon */
html[data-viewport="desktop-s"] {
  .admin-shell[data-bilateral-chrome][data-context-rail="visible"][data-context-rail-state="collapsed"] {
    grid-template-columns: var(--shell-sidebar-w) minmax(0, 1fr) 36px;
  }

  .admin-shell[data-bilateral-chrome][data-context-rail="visible"][data-context-rail-state="collapsed"][data-sidebar="closed"] {
    grid-template-columns: 48px minmax(0, 1fr) 36px;
  }

  .admin-shell[data-bilateral-chrome][data-context-rail="visible"][data-context-rail-state="collapsed"][data-sidebar="rail"],
  .admin-shell[data-bilateral-chrome][data-context-rail="visible"][data-context-rail-state="collapsed"][data-sidebar="ribbon"] {
    grid-template-columns: 44px minmax(0, 1fr) 36px;
  }

  body[data-surface-classification="internal-ops"]
    .admin-shell[data-bilateral-chrome][data-context-rail="visible"][data-context-rail-state="collapsed"] {
    grid-template-columns: var(--shell-sidebar-w) minmax(0, 1fr) 36px;
  }
}

/* Prevent minmax(320px,1fr) from forcing grid overflow below desktop-m (not mobile — phone block below) */
html[data-viewport^="tablet-"],
html[data-viewport="desktop-s"] {
  .admin-shell {
    grid-template-columns: minmax(0, var(--shell-sidebar-w)) minmax(0, 1fr);
  }

  .admin-shell[data-bilateral-chrome] {
    grid-template-columns: minmax(0, var(--shell-sidebar-w)) minmax(0, 1fr) minmax(0, var(--shell-right-rail-w));
  }

  .admin-shell[data-bilateral-chrome][data-sidebar="closed"] {
    grid-template-columns: 48px minmax(0, 1fr) minmax(0, var(--shell-right-rail-w));
  }

  .admin-shell[data-bilateral-chrome][data-sidebar="rail"],
  .admin-shell[data-bilateral-chrome][data-sidebar="ribbon"] {
    grid-template-columns: 44px minmax(0, 1fr) minmax(0, var(--shell-right-rail-w));
  }

  .admin-shell[data-bilateral-chrome][data-context-rail="hidden"] {
    grid-template-columns: minmax(0, var(--shell-sidebar-w)) minmax(0, 1fr);
  }

  .admin-shell > .admin-shell__nav-column,
  .admin-shell > .main-content,
  .admin-shell > .bilateral-right-rail {
    min-width: 0;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   TABLET — in-flow 2-column; right rail hidden (toggle via header)
   Overrides compact overlay drawer rules in admin-shell.css for this band.
   ══════════════════════════════════════════════════════════════════════════ */
html[data-viewport^="tablet-"] {
  .admin-shell,
  .admin-shell[data-bilateral-chrome],
  .admin-shell[data-bilateral-chrome][data-sidebar="open"],
  .admin-shell[data-bilateral-chrome][data-sidebar="rail"],
  .admin-shell[data-bilateral-chrome][data-sidebar="browse"],
  .admin-shell[data-bilateral-chrome][data-sidebar="hidden"],
  .admin-shell[data-bilateral-chrome][data-sidebar="ribbon"],
  .admin-shell[data-bilateral-chrome][data-sidebar="edge-overlay"] {
    grid-template-columns: minmax(0, var(--shell-sidebar-w)) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: none;
  }

  .admin-shell[data-bilateral-chrome][data-sidebar="rail"],
  .admin-shell[data-bilateral-chrome][data-sidebar="ribbon"],
  .admin-shell[data-bilateral-chrome][data-sidebar="closed"] {
    grid-template-columns: minmax(44px, 60px) minmax(0, 1fr);
  }

  .shell-top-cluster {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .admin-shell > .admin-shell__nav-column {
    grid-column: 1;
    grid-row: 2;
    grid-area: auto;
    position: relative;
    width: auto;
    min-width: 0;
  }

  .admin-shell > .main-content {
    grid-column: 2;
    grid-row: 2;
    grid-area: auto;
    width: auto;
    min-width: 0;
    padding-bottom: 0;
  }

  .admin-shell > .shell-footer {
    grid-column: 1 / -1;
    grid-row: 3;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
  }

  .admin-shell > .admin-shell__nav-column > .sidebar {
    position: relative;
    inset: auto;
    transform: none;
    width: auto;
    min-width: 0;
    max-width: none;
    height: auto;
    min-height: 0;
    max-height: none;
    box-shadow: none;
    z-index: 30;
    display: flex;
    flex-direction: column;
  }

  /* Right rail: off-canvas until data-shell-rail-drawer=open */
  .admin-shell[data-bilateral-chrome] > .bilateral-right-rail {
    display: flex;
    position: fixed;
    top: var(--shell-header-height, 0px);
    right: 0;
    bottom: var(--shell-footer-height, 0px);
    width: min(320px, 92vw);
    max-width: min(320px, 92vw);
    grid-column: auto;
    grid-row: auto;
    z-index: 900;
    transform: translateX(100%);
    transition: transform var(--s-duration-normal) cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    /* Tablet landscape with right notch / home indicator — eat the corresponding
       safe-areas so rail content does not slide under the rounded corners. */
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .admin-shell[data-bilateral-chrome][data-shell-rail-drawer="open"] > .bilateral-right-rail {
    transform: translateX(0);
  }

  .admin-shell[data-bilateral-chrome]:has([data-right-rail-tenant="drawer"]) {
    --shell-right-rail-w: 0px;
  }

  .admin-shell__rail-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 899;
    background: var(--s-color-backdrop-scrim);
    border: none;
    padding: 0;
    margin: 0;
    cursor: default;
  }

  .admin-shell__rail-drawer-backdrop[hidden] {
    display: none;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   PHONE (mobile-*) — single-column; left nav is overlay drawer
   ══════════════════════════════════════════════════════════════════════════ */
html[data-viewport^="mobile-"] {
  .admin-shell,
  .admin-shell[data-bilateral-chrome],
  .admin-shell[data-bilateral-chrome][data-sidebar="open"],
  .admin-shell[data-bilateral-chrome][data-sidebar="rail"],
  .admin-shell[data-bilateral-chrome][data-sidebar="browse"],
  .admin-shell[data-bilateral-chrome][data-sidebar="hidden"],
  .admin-shell[data-bilateral-chrome][data-sidebar="ribbon"],
  .admin-shell[data-bilateral-chrome][data-sidebar="closed"],
  .admin-shell[data-bilateral-chrome][data-sidebar="edge-overlay"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "shellhdr"
      "shellmain";
  }

  .admin-shell[data-bilateral-chrome] > .bilateral-right-rail {
    display: none;
  }

  .admin-shell[data-bilateral-chrome]:has([data-right-rail-tenant="drawer"]) {
    --shell-right-rail-w: 0px;
  }

  /* Mobile nav drawer: closed by default */
  .admin-shell[data-shell-mobile-drawer="closed"] > .admin-shell__nav-column > .sidebar,
  .admin-shell:not([data-shell-mobile-drawer="open"]) > .admin-shell__nav-column > .sidebar {
    transform: translateX(-100%);
  }

  .admin-shell[data-shell-mobile-drawer="open"] > .admin-shell__nav-column > .sidebar {
    transform: translateX(0);
    box-shadow: var(--s-shadow-lg);
  }

  .admin-shell__mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 998;
    background: var(--s-color-backdrop-scrim);
    border: none;
    padding: 0;
    margin: 0;
    cursor: default;
  }

  .admin-shell__mobile-drawer-backdrop[hidden] {
    display: none;
  }
}

/* ── Top chrome responsive ─────────────────────────────────────────────── */
html[data-viewport^="mobile-"],
html[data-viewport^="tablet-"],
html[data-viewport="desktop-s"] {
  .shell-prototype-chrome {
    display: none;
  }

  .shell-header--three-segment {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: var(--s-space-2);
  }

  .shell-header__center-segment {
    justify-content: flex-end;
  }

  .shell-breadcrumb-pill {
    max-width: min(28vw, 10rem);
  }

  .shell-breadcrumb-pill__segments {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

html[data-viewport^="mobile-"] {
  .shell-header--three-segment {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .shell-breadcrumb-pill,
  .shell-breadcrumb-status:not([hidden]):not(:empty) {
    display: none;
  }

  .shell-global-search {
    max-width: calc(var(--s-font-size-active) * 2);
  }

  .shell-global-search:not(:focus-within) .shell-global-search__input,
  .shell-global-search:not(:focus-within) .shell-global-search__hint {
    display: none;
  }

  .shell-global-search:not(:focus-within) .shell-global-search__field {
    width: calc(var(--s-font-size-active) * 2);
    min-width: calc(var(--s-font-size-active) * 2);
    padding: 0;
    justify-content: center;
  }
}

html[data-viewport^="tablet-"] {
  .shell-global-search {
    max-width: 76px;
  }

  .shell-global-search:not(:focus-within) .shell-global-search__input {
    width: 0;
    min-width: 0;
    padding: 0;
    flex: 0 0 0;
  }

  .shell-global-search:not(:focus-within) .shell-global-search__input::placeholder {
    opacity: 0;
  }
}

/* Narrow-screen fallback when kanban cannot fit */
html[data-viewport^="mobile-"] {
  .admin-shell[data-surface-layout="phone-narrow"] .main-content .oar-kanban-viewport-grid-host:empty,
  .admin-shell[data-surface-layout="phone-narrow"] .main-content .oar-kanban-grid:empty {
    display: none;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   TOUCH-INPUT REGULATORY FLOORS (Y2 admin-shell-iphone-orientation v2)
   ──────────────────────────────────────────────────────────────────────────
   Discriminator: @media (hover: none) queries the input mechanism directly.
   True on touch devices (iPhone + iPad in any orientation); false on
   desktop-with-mouse (even touchscreen-with-mouse desktops). Correct gate
   for touch-only enforcement — density-condensed desktop with mouse keeps
   its tight sizing because hover-capable input mechanism keeps these rules
   inactive there.

   Tokens come from @scilence/tokens/_interactive.css and are NOT
   density-scaled (regulatory floors, not design preferences):
     - --s-size-touch-target-min: 44px (Apple HIG)
     - --s-size-input-font-min-touch: 16px (iOS Safari zoom prevention)
   ══════════════════════════════════════════════════════════════════════════ */

@media (hover: none) {
  /* 44×44 touch target floor for ALL interactive elements within the admin
     shell. min-* (not width/height) so existing larger affordances stay larger
     and only the under-floor cases get bumped. */
  .admin-shell button,
  .admin-shell [role="button"],
  .admin-shell a[href],
  .admin-shell input,
  .admin-shell textarea,
  .admin-shell select,
  .admin-shell [tabindex="0"],
  .admin-shell [contenteditable]:not([contenteditable="false"]) {
    min-width: var(--s-size-touch-target-min);
    min-height: var(--s-size-touch-target-min);
  }

  /* 16px input font floor — iOS Safari auto-zooms when a focused input has
     font-size < 16px, jarring the user out of context. max() preserves any
     LARGER existing font-size from density/typography tokens — never demotes
     a 20px label down to 16px. */
  .admin-shell input,
  .admin-shell textarea,
  .admin-shell select {
    font-size: max(var(--s-size-input-font-min-touch), var(--s-font-size-base));
  }

  /* Footer icon row — regulatory floor on avatar only; compact icon buttons
     stay icon-sized so the status strip does not balloon on touch devices. */
  .shell-footer button,
  .shell-footer [role="button"] {
    min-width: unset;
    min-height: unset;
  }

  .shell-footer__affordance--avatar {
    min-width: var(--s-size-touch-target-min);
    min-height: var(--s-size-touch-target-min);
  }

  .shell-footer .footer-action-btn,
  .shell-footer .header-icon-btn,
  .shell-footer__affordance:not(.shell-footer__affordance--avatar) {
    min-width: calc(var(--s-font-size-active) * 1.85);
    min-height: calc(var(--s-font-size-active) * 1.85);
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   SHELL FOOTER — compact when nav is overlay or viewport is narrow
   (Pre-2026-06-09 a fixed --shell-sidebar-w on the account column wrapper stole
   budget on single-column layouts; that wrapper is gone — the avatar button now
   sizes to content, so only inter-cluster gap + bottom-right inset need
   tightening here.)
   ══════════════════════════════════════════════════════════════════════════ */

html[data-viewport^="mobile-"],
html[data-shell-nav-overlay],
html[data-viewport^="tablet-"],
html[data-viewport="desktop-s"] {
  .shell-footer__inner {
    gap: var(--s-space-1);
  }

  .shell-footer__status-band {
    padding: 0 var(--s-space-1);
    font-size: var(--s-font-size-0);
  }

  .shell-footer__bottom-right {
    gap: var(--s-space-tight-3);
    padding-right: var(--s-space-1);
  }
}

html[data-viewport^="mobile-"],
html[data-shell-nav-overlay] {
  .shell-footer__avatar-name,
  .shell-footer__name-role-sep,
  .shell-footer__avatar-chevron {
    display: none;
  }

  .shell-footer__affordance--avatar {
    padding: 0 var(--s-space-1);
    gap: 0;
  }

  .shell-footer__status__tier {
    display: none;
  }
}

html[data-viewport^="tablet-"] {
  .shell-footer__name-role-sep,
  .shell-footer__avatar-name[data-user-role] {
    display: none;
  }
}

html[data-viewport^="mobile-"] {
  .shell-footer__status-band {
    padding: 0 var(--s-space-tight-3);
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   FULL-WIDTH CHROME — non-wide layout bands
   Flat selectors (no nesting) so header/footer always span every grid track.
   Caitlin direct 2026-05-28: chrome must occupy the full viewport width, not
   the sidebar column only.
   ══════════════════════════════════════════════════════════════════════════ */

html[data-viewport^="mobile-"] .admin-shell > .shell-top-cluster,
html[data-viewport^="tablet-"] .admin-shell > .shell-top-cluster,
html[data-viewport="desktop-s"] .admin-shell > .shell-top-cluster,
html[data-shell-nav-overlay] .admin-shell > .shell-top-cluster,
.admin-shell[data-shell-layout-band="phone"] > .shell-top-cluster,
.admin-shell[data-shell-layout-band="tablet"] > .shell-top-cluster {
  grid-column: 1 / -1;
  grid-row: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  justify-self: stretch;
}

html[data-viewport^="mobile-"] .admin-shell > .shell-footer,
html[data-viewport^="tablet-"] .admin-shell > .shell-footer,
html[data-viewport="desktop-s"] .admin-shell > .shell-footer,
html[data-shell-nav-overlay] .admin-shell > .shell-footer,
.admin-shell[data-shell-layout-band="phone"] > .shell-footer,
.admin-shell[data-shell-layout-band="tablet"] > .shell-footer {
  grid-column: 1 / -1;
  grid-row: 3;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  justify-self: stretch;
}

html[data-viewport^="mobile-"] .admin-shell > .shell-top-cluster .shell-header,
html[data-viewport^="tablet-"] .admin-shell > .shell-top-cluster .shell-header,
html[data-viewport="desktop-s"] .admin-shell > .shell-top-cluster .shell-header,
html[data-shell-nav-overlay] .admin-shell > .shell-top-cluster .shell-header {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

html[data-viewport^="mobile-"] .admin-shell,
html[data-viewport^="tablet-"] .admin-shell,
html[data-viewport="desktop-s"] .admin-shell,
html[data-shell-nav-overlay] .admin-shell,
.admin-shell[data-shell-layout-band="phone"],
.admin-shell[data-shell-layout-band="tablet"] {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

html[data-viewport^="mobile-"] .admin-shell > .main-content,
html[data-shell-nav-overlay] .admin-shell > .main-content,
.admin-shell[data-shell-layout-band="phone"] > .main-content {
  padding-bottom: var(--shell-footer-height, 0px);
}
