/*
 * Vinde.online canonical 0.5.17 — shared shell corrections.
 *
 * This layer intentionally contains no page-specific layout and no legacy
 * compatibility overlay. It supplies the responsive shell hooks required by
 * the approved contract while canonical.css remains the visual baseline.
 */

:root {
  --canonical-mobile-nav-height: 68px;
  --canonical-mobile-nav-measured-height: var(--canonical-mobile-nav-height);
  --canonical-mobile-nav-edge: 10px;
  --canonical-mobile-nav-clearance: calc(
    var(--canonical-mobile-nav-measured-height) +
    var(--canonical-mobile-nav-edge) +
    env(safe-area-inset-bottom, 0px) +
    14px
  );
  --canonical-visual-viewport-height: 100vh;
  --canonical-visual-viewport-width: 100vw;
  --canonical-visual-viewport-offset-top: 0px;
  --canonical-visual-viewport-offset-left: 0px;
  --canonical-keyboard-occlusion: 0px;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

@supports (overflow: clip) {
  html,
  body {
    overflow-x: clip;
  }
}

#app,
.vinde-canonical-app,
[data-vinde-canonical-root] {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@supports (min-height: 100dvh) {
  #app,
  .vinde-canonical-app,
  [data-vinde-canonical-root] {
    min-height: 100dvh;
  }
}

#app > main,
.vinde-canonical-app > main,
[data-vinde-canonical-root] > main {
  width: 100%;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}

#app > .site-footer,
.vinde-canonical-app > .site-footer,
[data-vinde-canonical-root] > .site-footer {
  flex: 0 0 auto;
  margin-top: auto;
}

.site-header,
.site-footer,
#page-content {
  max-width: 100%;
}

.shell-wide,
.shell-narrow,
.site-header__desktop,
.site-header__mobile,
.footer-main,
.footer-bottom {
  min-width: 0;
}

/* The navigation is injected once by the shared shell, never by a page. */
.mobile-bottom-nav,
[data-mobile-bottom-nav] {
  display: none;
}

.mobile-bottom-nav[hidden],
[data-mobile-bottom-nav][hidden] {
  display: none !important;
}

/* Explicit hooks for routes where a bottom navigation is intentionally absent. */
body.is-canonical-auth .mobile-bottom-nav,
body.is-canonical-auth [data-mobile-bottom-nav],
body.canonical-mobile-nav-suppressed .mobile-bottom-nav,
body.canonical-mobile-nav-suppressed [data-mobile-bottom-nav],
[data-canonical-view="auth"] .mobile-bottom-nav,
[data-canonical-view="auth"] [data-mobile-bottom-nav],
[data-canonical-route="auth"] .mobile-bottom-nav,
[data-canonical-route="auth"] [data-mobile-bottom-nav] {
  display: none !important;
}

/*
 * One visible keyboard-focus contract owns every page and every portal.
 * The disabled exclusions intentionally increase specificity so this final
 * shell layer also replaces component-level focus shadows from canonical.css.
 */
body :where(
  a[href],
  button,
  input,
  select,
  textarea,
  summary,
  [contenteditable="true"],
  [tabindex]:not([tabindex="-1"])
):focus-visible:not(:disabled):not([aria-disabled="true"]) {
  outline: 3px solid var(--focus, #101828);
  outline-offset: 2px;
  box-shadow: none;
}

/*
 * Search controls are visual composites: the wrapper owns the one focus
 * indicator while its borderless input remains ring-free.
 */
body :where(
  .header-search,
  .page-search,
  .admin-search,
  .help-search,
  .hero-search__query,
  .combo-search,
  .thread-list__tools label
):has(input:focus-visible):not([aria-disabled="true"]) {
  outline: 3px solid var(--focus, #101828);
  outline-offset: 2px;
  box-shadow: none;
}

/*
 * The Home search controls sit directly on the dark hero artwork. Preserve
 * the single Vinde-indigo focus channel with its light accessible tone so the
 * indicator keeps at least 3:1 contrast with that surface.
 */
body .hero-search__query:has(input:focus-visible):not([aria-disabled="true"]),
body .custom-combobox--hero > .combo-trigger:focus-visible:not(:disabled):not([aria-disabled="true"]) {
  outline-color: #f4f7fb;
}

body :where(
  .header-search,
  .page-search,
  .admin-search,
  .help-search,
  .hero-search__query,
  .combo-search,
  .thread-list__tools label
):has(input:focus-visible) input:focus-visible:not(:disabled):not([aria-disabled="true"]) {
  outline: none;
  outline-offset: 0;
  box-shadow: none;
}

@media (max-width: 760px) {
  /*
   * Long mobile routes must grow the document instead of shrinking the main
   * flex item and painting final controls underneath the footer. Short routes
   * still fill the viewport through flex-grow.
   */
  #app > main,
  .vinde-canonical-app > main,
  [data-vinde-canonical-root] > main {
    min-height: auto;
    flex: 1 0 auto;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
    textarea,
    select,
    [contenteditable="true"]
  ) {
    font-size: 16px !important;
    scroll-margin-block: 16px;
  }

  #app,
  .vinde-canonical-app,
  [data-vinde-canonical-root] {
    min-height: 100svh;
  }

  .mobile-bottom-nav,
  [data-mobile-bottom-nav] {
    position: fixed;
    z-index: 170;
    top: auto;
    right: max(var(--canonical-mobile-nav-edge), env(safe-area-inset-right, 0px));
    bottom: max(var(--canonical-mobile-nav-edge), env(safe-area-inset-bottom, 0px));
    left: max(var(--canonical-mobile-nav-edge), env(safe-area-inset-left, 0px));
    width: auto;
    max-width: none;
    height: auto;
    min-height: var(--canonical-mobile-nav-height);
    margin: 0;
    transform: none;
    isolation: isolate;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 0;
    padding: 5px 7px;
    border: 1px solid rgba(255, 255, 255, 0.74);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 16px 44px rgba(17, 24, 39, 0.16);
    -webkit-backdrop-filter: blur(24px) saturate(165%);
    backdrop-filter: blur(24px) saturate(165%);
  }

  .mobile-bottom-nav__indicator {
    position: absolute;
    z-index: 0;
    top: 5px;
    bottom: 5px;
    left: 7px;
    width: calc((100% - 14px) / 5);
    border: 1px solid rgba(99, 102, 241, 0.16);
    border-radius: 17px;
    background: rgba(238, 242, 255, 0.82);
    box-shadow: 0 6px 16px rgba(49, 46, 129, 0.08);
    transform: translateX(calc(var(--mobile-nav-index, 0) * 100%));
    transition: transform var(--motion-standard, 220ms) var(--motion-move, cubic-bezier(0.77, 0, 0.175, 1));
    pointer-events: none;
  }

  /* Detail owns the fixed mobile CTA, so the shared nav must not overlap it. */
  [data-canonical-route^="detail/"] .mobile-bottom-nav,
  [data-canonical-route^="detail/"] [data-mobile-bottom-nav] {
    display: none !important;
  }

  body.is-canonical-keyboard-open :where(.mobile-bottom-nav, [data-mobile-bottom-nav]),
  body.has-canonical-overlay :where(.mobile-bottom-nav, [data-mobile-bottom-nav]) {
    display: none !important;
  }

  body.is-canonical-keyboard-open :where(.install-banner, [data-install-prompt]),
  body.has-canonical-overlay :where(.install-banner, [data-install-prompt]),
  body.is-canonical-keyboard-open :where(.cookie-banner, [data-cookie-banner]),
  body.has-canonical-overlay :where(.cookie-banner, [data-cookie-banner]) {
    display: none !important;
  }

  [data-canonical-route^="detail/"] .breadcrumbs,
  [data-canonical-route^="detail/"] .breadcrumbs > *,
  [data-canonical-route^="detail/"] .detail-title-row > div,
  [data-canonical-route^="detail/"] .detail-title-row h1 {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  [data-canonical-route^="detail/"] .breadcrumbs {
    flex-wrap: wrap;
    white-space: normal;
  }

  .mobile-bottom-nav > :where(a, button, .nav-button, .mobile-bottom-nav__item),
  [data-mobile-bottom-nav] > :where(a, button, .nav-button, .mobile-bottom-nav__item) {
    position: relative;
    z-index: 1;
    min-width: 0;
    min-height: 48px;
    display: grid;
    grid-template-rows: 24px minmax(12px, auto);
    place-items: center;
    align-content: center;
    gap: 2px;
    padding: 4px 2px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--muted, #5f6b7a);
    font-size: 10.5px;
    font-weight: 750;
    line-height: 1.05;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .mobile-bottom-nav > :where(a, button, .nav-button, .mobile-bottom-nav__item) > :where(span, small),
  [data-mobile-bottom-nav] > :where(a, button, .nav-button, .mobile-bottom-nav__item) > :where(span, small) {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-bottom-nav > :where(a, button, .nav-button, .mobile-bottom-nav__item) > :where(span, small):last-child,
  [data-mobile-bottom-nav] > :where(a, button, .nav-button, .mobile-bottom-nav__item) > :where(span, small):last-child {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
  }

  .mobile-bottom-nav .icon,
  [data-mobile-bottom-nav] .icon,
  .mobile-bottom-nav [data-mobile-nav-icon],
  [data-mobile-bottom-nav] [data-mobile-nav-icon] {
    width: 21px;
    height: 21px;
  }

  .mobile-bottom-nav > :where([aria-current="page"], .is-active),
  [data-mobile-bottom-nav] > :where([aria-current="page"], .is-active) {
    background: transparent;
    color: var(--selected-ink, #312e81);
  }

  /* Optional publish-icon hook; the route remains one of the same five slots. */
  :where(.mobile-bottom-nav, [data-mobile-bottom-nav])
    :where([data-mobile-nav-item="publish"], .mobile-bottom-nav__item--publish)
    .mobile-bottom-nav__icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary, #111827);
    color: #fff;
  }

  /*
   * The footer is the sole owner of the fixed-nav reserve. Keyboard and
   * overlay visibility are temporary presentation states and never remove it.
   */
  body.has-canonical-mobile-nav .site-footer {
    padding-bottom: var(--canonical-mobile-nav-clearance);
  }

  /* App-install and cookie surfaces must never sit under the five-slot nav. */
  body.has-canonical-mobile-nav :where(.install-banner, [data-install-prompt]) {
    bottom: var(--canonical-mobile-nav-clearance);
  }

  body.has-canonical-mobile-nav :where(.cookie-banner, [data-cookie-banner]) {
    bottom: var(--canonical-mobile-nav-clearance);
    max-width: calc(100% - 20px);
  }

  /* Approved mobile controls use 44–48 px touch targets. */
  .site-header__mobile > .icon-button,
  .mobile-header-actions .icon-button,
  .mobile-menu .main-nav__link,
  .auth-tabs button,
  .combo-trigger,
  .combo-option,
  .filter-sheet :where(button, [role="button"]),
  .modal :where(button, [role="button"]),
  .install-banner > .icon-button,
  [data-install-prompt] > .icon-button {
    min-width: 44px;
    min-height: 44px;
  }

  .site-header__mobile > .icon-button,
  .mobile-header-actions .icon-button {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .mobile-menu .main-nav__link,
  .combo-trigger,
  .combo-option {
    min-height: 48px;
  }

  .section-heading,
  .account-section-heading,
  .admin-table-heading {
    flex-wrap: wrap;
  }

  .section-heading > *,
  .account-section-heading > *,
  .admin-table-heading > *,
  .page-intro :where(h1, h2),
  .detail-title-row h1,
  .admin-title h1,
  .owner-workspace__header h1 {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  /* Auth is deliberately compact and does not reserve a missing-nav gutter. */
  body.is-canonical-auth .auth-page,
  [data-canonical-view="auth"] .auth-page,
  [data-canonical-route="auth"] .auth-page {
    padding-bottom: 0;
  }

  body.is-canonical-auth .site-footer,
  body.canonical-mobile-nav-suppressed .site-footer {
    padding-bottom: 0;
  }
}

@media (max-width: 340px) {
  .mobile-bottom-nav,
  [data-mobile-bottom-nav] {
    right: max(6px, env(safe-area-inset-right, 0px));
    left: max(6px, env(safe-area-inset-left, 0px));
    padding-inline: 4px;
  }

  .mobile-bottom-nav > :where(a, button, .nav-button, .mobile-bottom-nav__item),
  [data-mobile-bottom-nav] > :where(a, button, .nav-button, .mobile-bottom-nav__item) {
    font-size: 10.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  :where(
    #app,
    .vinde-canonical-app,
    [data-vinde-canonical-root]
  ) *,
  :where(
    #app,
    .vinde-canonical-app,
    [data-vinde-canonical-root]
  ) *::before,
  :where(
    #app,
    .vinde-canonical-app,
    [data-vinde-canonical-root]
  ) *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
