/*
 * Hello Samaj — UI / accessibility enhancements.
 * Loaded after theme.css (handle: hello-samaj-ui-enhancements).
 * Keep overrides here so theme.css stays untouched.
 */

/* ── Visually hidden helper ─────────────────────────────────────────────── */
.hs-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── Dialog scroll lock (HSDialog) ──────────────────────────────────────── */
html.hs-dialog-open,
html.hs-dialog-open body {
  overflow: hidden;
}

html.hs-dialog-open body {
  padding-right: var(--hs-scrollbar-comp, 0px);
}

[role="dialog"][tabindex="-1"]:focus {
  outline: none;
}

/* ── Video modal close button: 44px target ──────────────────────────────── */
.hs-video-modal .hs-video-modal__close {
  width: 44px;
  height: 44px;
  top: -54px;
}

.hs-video-modal .hs-video-modal__close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .hs-video-modal .hs-video-modal__close {
    top: 12px;
    right: 12px;
  }
}

/* ── Navigation sub-menu toggles ────────────────────────────────────────── */
.hs-nav__subtoggle {
  display: none;
}

@media (max-width: 991px) {
  .hs-nav .hs-nav__list li.has-dropdown {
    flex-wrap: wrap;
    align-items: center;
  }

  .hs-nav .hs-nav__list li.has-dropdown > a {
    flex: 1 1 0;
    min-width: 0;
  }

  /* The separate toggle carries the chevron on mobile. */
  .hs-nav .hs-nav__list li.has-dropdown > a .hs-nav__arrow {
    display: none;
  }

  .hs-nav__subtoggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--hs-primary, #0d3b66);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .hs-nav--primary .hs-nav__subtoggle,
  .hs-nav--boxed .hs-nav__subtoggle {
    color: #fff;
  }

  .hs-nav__subtoggle:hover {
    background: rgba(13, 59, 102, 0.08);
  }

  .hs-nav--primary .hs-nav__subtoggle:hover,
  .hs-nav--boxed .hs-nav__subtoggle:hover {
    background: rgba(255, 255, 255, 0.12);
  }

  .hs-nav__subtoggle:focus-visible {
    outline: 2px solid var(--hs-accent, #d62828);
    outline-offset: -2px;
  }

  .hs-nav__subtoggle svg {
    transition: transform 0.2s ease;
  }

  .hs-nav__subtoggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  /* Dropdown becomes an in-flow, indented list inside the scrollable menu. */
  .hs-nav .hs-nav__list .hs-nav__dropdown,
  .hs-nav .hs-nav__list li.has-dropdown:hover .hs-nav__dropdown,
  .hs-nav .hs-nav__list li.has-dropdown:focus-within .hs-nav__dropdown {
    position: static;
    display: none;
    flex: 1 1 100%;
    width: auto;
    min-width: 0;
    margin: 0.15rem 0 0.35rem 1rem;
    padding: 0.25rem 0;
    transform: none;
    opacity: 1;
    visibility: visible;
    box-shadow: none;
    border-radius: 10px;
    transition: none;
  }

  .hs-nav .hs-nav__list .hs-nav__dropdown.is-open {
    display: flex;
  }

  .hs-nav .hs-nav__list .hs-nav__dropdown a {
    text-align: left;
    white-space: normal;
    padding: 0.7rem 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hs-nav__subtoggle svg {
    transition: none;
  }
}

/* ── Reader tools: 44px tap targets ─────────────────────────────────────── */
.hs-article__tools .hs-article__tool-btn,
.hs-article__tool-btn[data-hs-font] {
  min-width: 44px;
  height: 44px;
  padding: 0 0.65rem;
}

.hs-article__tool-btn[data-hs-font]:focus-visible {
  outline: 2px solid var(--hs-accent, #d62828);
  outline-offset: 2px;
}

/* ── Reading progress bar (single articles) ─────────────────────────────── */
.hs-reading-progress {
  position: fixed;
  top: var(--wp-admin--admin-bar--height, 0px);
  left: 0;
  right: 0;
  height: 3px;
  z-index: 1000;
  pointer-events: none;
  background: transparent;
}

.hs-reading-progress__bar {
  width: 100%;
  height: 100%;
  background: var(--hs-accent, #d62828);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.1s linear;
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .hs-reading-progress__bar {
    transition: none;
  }
}

/* ── AI chat ────────────────────────────────────────────────────────────── */
.hs-ai-chat .hs-ai-chat__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  margin: -0.5rem -0.5rem 0 0;
  padding: 0;
  border-radius: 50%;
}

.hs-ai-chat .hs-ai-chat__close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
}

.hs-ai-chat .hs-ai-chat__close:focus-visible,
.hs-ai-chat .hs-ai-chat__fab:focus-visible {
  outline: 2px solid var(--hs-accent, #d62828);
  outline-offset: 2px;
}

.hs-ai-chat .hs-ai-chat__input[readonly] {
  opacity: 0.75;
}

/*
 * Phones: icon-only FAB, and a single right-hand stack of floating controls:
 *   [scroll-to-top 44px]
 *        12px
 *   [AI chat FAB 52px]
 *        12px
 *   [floating share bar, full width — only while visible]
 * html.hs-share-float-visible and --hs-share-float-h are set by theme-article.js.
 */
@media (max-width: 767px) {
  .hs-ai-chat .hs-ai-chat__fab {
    width: 52px;
    height: 52px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .hs-ai-chat .hs-ai-chat__fab-icon {
    width: 2rem;
    height: 2rem;
    font-size: 1.05rem;
  }

  /* Visually hidden but still part of the accessible name. */
  .hs-ai-chat .hs-ai-chat__fab-text {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  html .hs-ai-chat[data-hs-ai-chat] {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  html body .hs-scroll-top[data-hs-scroll-top] {
    right: 16px; /* centred over the 52px FAB */
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)); /* 12 + 52 + 12 */
  }

  /* Pages without the AI widget: scroll-to-top takes the FAB slot. */
  body:not(:has(.hs-ai-chat)) .hs-scroll-top[data-hs-scroll-top] {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* Share bar already includes the safe-area inset in its own padding. */
  html.hs-share-float-visible .hs-ai-chat[data-hs-ai-chat] {
    bottom: calc(var(--hs-share-float-h, 4rem) + 12px);
  }

  html.hs-share-float-visible body .hs-scroll-top[data-hs-scroll-top] {
    bottom: calc(var(--hs-share-float-h, 4rem) + 76px);
  }

  html.hs-share-float-visible body:not(:has(.hs-ai-chat)) .hs-scroll-top[data-hs-scroll-top] {
    bottom: calc(var(--hs-share-float-h, 4rem) + 12px);
  }

  .hs-ai-chat__panel {
    max-height: min(34rem, calc(100vh - 7rem));
    max-height: min(34rem, calc(100dvh - 7rem));
  }
}
