/*
 * react-datepicker renders an aria-live="polite" announce element holding the
 * current month/year for screen readers. Its own stylesheet clips it out of
 * view, but @adminjs/design-system re-themes the datepicker with styled-
 * components and never loads react-datepicker/dist/react-datepicker.css, so
 * the element is never hidden and renders visibly — a duplicated "June 2026"
 * that is most apparent in Firefox when changing months.
 * See https://github.com/Hacker0x01/react-datepicker/issues/3924
 *
 * Restore the visually-hidden rule, scoped to that one class only (does not
 * touch the design-system datepicker theme). clip + clip-path + the sr-only
 * box belt-and-suspenders so Firefox honours it.
 */
.react-datepicker__aria-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip: rect(0 0 0 0);
  clip-path: circle(0);
}

[data-css='sidebar'],
[data-css='sidebar-logo'],
[data-css='sidebar-resources'],
[data-css='sidebar-footer'],
[data-css='sidebar'] > section:not([data-css]) {
  color: #f8fafc;
  background: #0f2d4a !important;
}

[data-css='sidebar'] {
  min-height: 100vh;
  min-height: 100dvh;
}

[data-css='sidebar'] :is(h1, label, a) {
  color: #f8fafc !important;
}

[data-css='sidebar'] a:hover {
  background: rgb(255 255 255 / 12%) !important;
}

[data-css='sidebar'] [data-css='sidebar-logo']:hover {
  background: #0f2d4a !important;
}

[data-css='sidebar-logo'] {
  display: flex;
  box-sizing: border-box;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  height: 80px !important;
  min-height: 80px !important;
  max-height: 80px;
  padding: 12px 56px 12px 24px !important;
  overflow: hidden;
}

[data-css='sidebar-logo'] img {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  object-fit: contain;
}

[data-css='sidebar-logo']::after {
  overflow: hidden;
  color: #f8fafc;
  font-weight: 700;
  font-size: 18px;
  line-height: 24px;
  white-space: nowrap;
  text-overflow: ellipsis;
  content: 'SQ Admin';
}

[data-css='sidebar-logo'] :is(h1, span) {
  display: none;
}

/*
 * JDM editor full-viewport layout.
 *
 * The editor is an iframe that needs the whole content area; AdminJS ships a
 * capped, padded action wrapper and a 300px sidebar, which leaves the graph a
 * narrow letterbox. Everything below is scoped to the
 * html[data-admin-editor-active="true"] marker that
 * apps/admin/src/components/form-graph-editor-action.tsx sets on mount and
 * removes on cleanup, so no other admin route is affected.
 *
 * Only the stable @adminjs/design-system data-css hooks are used (app,
 * app-content, topbar, sidebar, sidebar-logo, sidebar-resources,
 * sidebar-footer) plus suffix matches on the generated per-resource action
 * wrappers — no :has(), generated class hashes, nth-child, or resource ids.
 */
html[data-admin-editor-active='true'],
html[data-admin-editor-active='true'] body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

html[data-admin-editor-active='true'] [data-css='app'] {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

html[data-admin-editor-active='true'] [data-css='app-content'] {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

/*
 * Unbroken flex/min-height:0 chain from the route root down to the frame. The
 * action wrappers are named "<resource>-<action>-…", so match on the suffix.
 */
html[data-admin-editor-active='true'] [data-css$='-route-wrapper'],
html[data-admin-editor-active='true'] [data-css$='-action'],
html[data-admin-editor-active='true'] [data-css$='-action-content'],
html[data-admin-editor-active='true'] [data-css$='-action-wrapper'],
html[data-admin-editor-active='true'] [data-css$='-record-action'],
html[data-admin-editor-active='true'] [data-css$='-resource-action'],
html[data-admin-editor-active='true'] [data-css$='-edit-action'],
html[data-admin-editor-active='true'] [data-css$='-show-action'] {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

/* The action header duplicates the record title the editor already shows. */
html[data-admin-editor-active='true'] [data-css$='-action-header'] {
  display: none;
}

html[data-admin-editor-active='true'] [data-css='jdm-editor-frame'] {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: none;
}

/*
 * Desktop compact navigation. Keep AdminJS's native 300px layout intact,
 * exposing it on hover or when the editor toggle pins it open.
 */
@media (min-width: 1324px) {
  html[data-admin-editor-active='true'] [data-css='sidebar'] {
    position: relative;
    left: 0 !important;
    width: 64px;
    min-width: 64px;
    overflow: hidden;
    transition:
      width 160ms cubic-bezier(0.22, 1, 0.36, 1),
      min-width 160ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  html[data-admin-editor-active='true'] [data-css='sidebar-logo'],
  html[data-admin-editor-active='true'] [data-css='sidebar-resources'],
  html[data-admin-editor-active='true'] [data-css='sidebar-footer'] {
    width: 300px;
    min-width: 300px;
  }

  html[data-admin-editor-active='true'] [data-css='sidebar']:hover,
  html[data-admin-editor-active='true'][data-admin-sidebar-expanded='true'] [data-css='sidebar'] {
    width: 300px;
    min-width: 300px;
    overflow: visible;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    [data-css='sidebar-logo'] {
    visibility: visible;
    width: 64px;
    min-width: 64px;
    padding: 12px 32px 12px 8px !important;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    [data-css='sidebar-logo']::after {
    display: none;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    [data-css='sidebar-logo']
    img {
    flex-basis: 24px;
    width: 24px;
    height: 24px;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    > section {
    width: 64px;
    padding-inline: 0;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    label,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    li
    > a
    > div,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    .arrow-box,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    li
    > ul {
    display: none;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    > section
    > ul,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    > section
    > ul
    > li,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    > section
    > ul
    > li
    > a {
    width: 64px;
    margin: 0;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    :is([data-css='sidebar-resources'], [data-css='sidebar-footer'])
    > section
    > ul
    > li
    > a {
    justify-content: center;
    min-height: 48px;
    padding: 8px 16px;
  }

  /* AdminJS renders the custom Pages group as an unlabelled sidebar section. */
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    > section:not([data-css]) {
    width: 64px;
    padding-inline: 0;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    > section:not([data-css])
    label,
  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    > section:not([data-css])
    li
    > a
    > div {
    display: none;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    > section:not([data-css])
    :is(ul, li, li > a) {
    width: 64px;
    margin: 0;
  }

  html[data-admin-editor-active='true']:not([data-admin-sidebar-expanded='true'])
    [data-css='sidebar']:not(:hover)
    > section:not([data-css])
    li
    > a {
    justify-content: center;
    min-height: 48px;
    padding: 8px 16px;
  }
  html[data-admin-editor-active='true'] [data-css='sidebar-toggle'] {
    position: absolute;
    z-index: 80;
    top: 26px;
    right: 4px;
    display: grid;
    width: 24px;
    height: 28px;
    padding: 0;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    background: #c2410c;
    border: 1px solid #fff;
    border-radius: 4px 0 0 4px;
    place-items: center;
    cursor: pointer;
  }

  html[data-admin-editor-active='true'] [data-css='sidebar']:hover [data-css='sidebar-toggle'],
  html[data-admin-editor-active='true'][data-admin-sidebar-expanded='true']
    [data-css='sidebar-toggle'] {
    top: 24px;
    right: 8px;
    width: 32px;
    height: 32px;
    font-size: 24px;
  }

  html[data-admin-editor-active='true'] [data-css='sidebar-toggle']:hover,
  html[data-admin-editor-active='true'] [data-css='sidebar-toggle']:focus-visible {
    color: #fff;
    background: #9a3412;
  }
}

@media (min-width: 1324px) and (prefers-reduced-motion: reduce) {
  html[data-admin-editor-active='true'] [data-css='sidebar'] {
    transition: none;
  }
}

/* Narrow viewports: reclaim top bar height, keep the native menu control. */
@media (max-width: 576px) {
  html[data-admin-editor-active='true'] [data-css='topbar'] {
    height: 40px;
    min-height: 40px;
    padding: 4px 8px;
  }

  html[data-admin-editor-active='true'] [data-css='topbar'] button {
    min-width: 32px;
    min-height: 32px;
  }
}
