/* Floating help button, Sojo chat panel, accessibility panel, tooltips. Moved out of the inline <style> in
   Utils/PageBuilder.build_widgets so browsers cache it; linked from the same place (in <body>, after the
   theme stylesheet) so the cascade order is unchanged. */
/* Sojo Chat Panel */
#sojo-chat-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 370px;
  min-width: 320px;
  min-height: 350px;
  max-width: calc(100vw - 40px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#sojo-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  cursor: nw-resize;
  z-index: 10001;
  border-top-left-radius: 12px;
}
#sojo-resize-handle::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(255,255,255,0.5);
  border-left: 2px solid rgba(255,255,255,0.5);
}
.sojo-header {
  background: var(--color-primary, #1e3a5f);
  color: var(--color-text-inverse);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.sojo-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sojo-avatar { flex-shrink: 0; }
.sojo-header-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.sojo-title { font-weight: 600; font-size: 0.9375em; }
/* currentColor + an outline (rather than a filled background) means the
   badge keeps 4.5:1 contrast automatically if a county themes the header
   background, instead of a hard-coded color pairing that could fail on a
   different header color (WP-B accessibility requirement). */
.sojo-badge {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.6875em;
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: currentColor;
  white-space: nowrap;
}
.sojo-minimize {
  background: none;
  border: none;
  color: var(--color-text-inverse);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}
.sojo-minimize:hover { opacity: 0.8; }
.sojo-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sojo-welcome p {
  background: var(--color-widget-bg);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.875em;
  color: var(--color-widget-text);
  line-height: 1.5;
}
/* First-message disclosure (WP-B element C): styled as a system note, not
   a chat bubble, so it reads as distinct from an answer -- a dashed border
   instead of the solid bot-bubble background. */
.sojo-disclosure p {
  background: var(--color-widget-bg);
  border: 1px dashed var(--color-border);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.8125em;
  color: var(--color-widget-text);
  line-height: 1.5;
}
.sojo-disclosure a { color: var(--color-accent, #2563eb); }
.sojo-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875em;
  line-height: 1.5;
  word-wrap: break-word;
}
.sojo-msg.user {
  align-self: flex-end;
  background: var(--color-primary, #1e3a5f);
  color: var(--color-text-inverse);
  border-bottom-right-radius: 4px;
}
.sojo-msg.user::selection,
.sojo-msg.user *::selection {
  background: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}
.sojo-msg.user::-moz-selection,
.sojo-msg.user *::-moz-selection {
  background: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}
.sojo-msg.bot {
  align-self: flex-start;
  background: var(--color-widget-bg);
  color: var(--color-widget-text);
  border-bottom-left-radius: 4px;
}
/* Answers use <ul>/<ol> (the prompt asks for simple HTML lists). The page-wide reset (portal-chrome.css
   `* { margin: 0; padding: 0 }`) takes away the indent the bullets sit in, so they hung outside the bubble. */
.sojo-msg ul,
.sojo-msg ol {
  margin: 4px 0;
  padding-left: 1.4em;
}
.sojo-msg li {
  margin: 2px 0;
}
.sojo-msg.bot .sojo-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--color-divider);
  font-size: 0.75em;
}
.sojo-msg.bot .sojo-sources a {
  color: var(--color-accent, #2563eb);
  text-decoration: none;
  display: block;
  margin-top: 2px;
}
.sojo-msg.bot .sojo-sources a:hover { text-decoration: underline; }
.sojo-feedback-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.sojo-feedback-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: var(--color-text-secondary);
  font-size: 0.8125em;
  transition: all 0.15s;
}
.sojo-feedback-btn:hover { border-color: var(--color-primary, #1e3a5f); color: var(--color-primary-fg, #1e3a5f); }
.sojo-feedback-btn.selected { border-color: var(--color-primary, #1e3a5f); color: var(--color-primary-fg, #1e3a5f); background: var(--color-widget-bg); }
.sojo-feedback-btn .material-icons { font-size: 1em; }
.sojo-feedback-sent {
  font-size: 0.75em;
  color: var(--color-success-fg);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}
.sojo-feedback-sent .material-icons { font-size: 0.875em; }
.sojo-feedback-comment {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
/* WP-B element E: a non-dismissible public-records note, shown for as long
   as the comment box itself is open (removed together with it). */
.sojo-feedback-note {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  line-height: 1.4;
}
/* WP-C section A: PII warning helper text, always visible, not
   dismissible, associated to its field with aria-describedby. */
.form-text.pii-note {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  line-height: 1.4;
  margin: 2px 0 6px 0;
}
/* WP-C section B: one-line note shown under a Sojo answer whose incoming
   message had personal details removed before it was sent to the model. */
.sojo-pii-masked-note {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  line-height: 1.4;
  margin-top: 6px;
  font-style: italic;
}
.sojo-feedback-comment-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.sojo-feedback-comment input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8125em;
  outline: none;
  font-family: inherit;
}
.sojo-feedback-comment input:focus { border-color: var(--color-accent, #2563eb); }
.sojo-feedback-comment button {
  background: var(--color-primary, #1e3a5f);
  color: var(--color-text-inverse);
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8125em;
  cursor: pointer;
}
.sojo-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--color-widget-bg);
  border-radius: 12px;
}
.sojo-typing span {
  width: 8px;
  height: 8px;
  background: var(--color-muted);
  border-radius: 50%;
  animation: sojoBounce 1.4s infinite ease-in-out both;
}
.sojo-typing span:nth-child(1) { animation-delay: -0.32s; }
.sojo-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes sojoBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
.sojo-suggest-label {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}
.sojo-suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.sojo-suggest-chip {
  display: inline-block;
  padding: 6px 12px;
  font-size: 0.8125em;
  border-radius: 16px;
  background: var(--color-widget-bg);
  color: var(--color-primary-fg, #1e3a5f);
  border: 1px solid var(--color-border);
  cursor: pointer;
  text-align: left;
  line-height: 1.3;
  transition: background 0.15s, border-color 0.15s;
}
.sojo-suggest-chip:hover {
  border-color: var(--color-primary, #1e3a5f);
  background: var(--color-accent-bg, #eef4ff);
}
.sojo-stream-text {
  white-space: pre-wrap;
}
.sojo-footer {
  border-top: 1px solid var(--color-divider);
  padding: 12px 16px;
  flex-shrink: 0;
}
.sojo-footer-links {
  margin-bottom: 8px;
  font-size: 0.75em;
}
.sojo-footer-links a {
  color: var(--color-text-secondary);
  text-decoration: underline;
}
.sojo-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
#sojo-input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 1em;
  outline: none;
  font-family: inherit;
}
#sojo-input:focus { border-color: var(--color-accent); box-shadow: 0 0 0 2px var(--color-primary-light); }
#sojo-send {
  background: var(--color-primary, #1e3a5f);
  border: none;
  border-radius: 8px;
  color: var(--color-text-inverse);
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
#sojo-send:hover { opacity: 0.85; }
#sojo-send .material-icons { font-size: 1.25em; }

/* Help Panel */
#help-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--color-surface);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 10001;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}
#help-panel.open { right: 0; }
.help-header {
  background: var(--color-primary, #1e3a5f);
  color: var(--color-text-inverse);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.help-title { font-weight: 600; font-size: 1em; }
.help-close {
  background: none;
  border: none;
  color: var(--color-text-inverse);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}
.help-close:hover { opacity: 0.8; }
.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: 0.875em;
  line-height: 1.6;
  color: var(--color-widget-text);
}
.help-body h1, .help-body h2, .help-body h3 { color: var(--color-primary-fg, #1e3a5f); margin: 16px 0 8px; }
.help-body h1 { font-size: 1.25em; }
.help-body h2 { font-size: 1.0625em; }
.help-body h3 { font-size: 0.9375em; }
.help-body p { margin-bottom: 12px; }
.help-body ul, .help-body ol { margin-bottom: 12px; padding-left: 20px; }

/* FAB */
#fab-container {
  position: fixed;
  /* --fab-lift is how much of the footer is on screen (set by FAB.init), so
     the button rides 16px above the footer instead of covering it. */
  bottom: max(60px, calc(var(--fab-lift, 0px) + 16px));
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: opacity 0.3s, transform 0.3s;
}
/* openModal() traps focus in the dialog, so the button can't be used while one is open; on a phone it
   sat on top of the dialog's footer buttons. */
body.modal-open #fab-container { visibility: hidden; }
#fab-container.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}
#fab-main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary, #1e3a5f);
  color: var(--color-text-inverse);
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
#fab-main:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,0.25); }
#fab-main .material-icons { font-size: 1.75em; }
#fab-sub-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.fab-sub {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab-sub:hover { transform: scale(1.1); box-shadow: 0 4px 12px rgba(0,0,0,0.18); }
.fab-sub .material-icons { font-size: 1.375em; color: var(--color-primary-fg, #1e3a5f); }

body.sojo-open { overflow: hidden; }

/* Responsive */
@media (max-width: 500px) {
  #sojo-chat-panel {
    width: calc(100vw - 20px);
    right: 10px;
    bottom: max(48px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    top: max(96px, calc(env(safe-area-inset-top, 0px) + 48px));
    height: auto;
  }
  #help-panel { width: 100vw; max-width: 100vw; }
}

/* Accessibility Panel */
.a11y-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 10060;
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
}
.a11y-panel-backdrop.open { opacity: 1; visibility: visible; }

.a11y-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    max-width: 90vw;
    height: 100vh;
    background: var(--color-surface, #fff);
    z-index: 10061;
    box-shadow: -4px 0 20px rgba(0,0,0,0.18);
    transition: right .3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.a11y-panel.open { right: 0; }

.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--color-primary, #1e3a5f);
    color: var(--color-text-inverse, #fff);
}
.a11y-panel-close {
    background: none;
    border: none;
    color: var(--color-text-inverse, #fff);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}
.a11y-panel-close:hover { opacity: 0.8; }

.a11y-panel-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 1rem;
}

.a11y-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.6rem;
}

.a11y-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 0.25rem;
    border: 2px solid var(--color-border, #dee2e6);
    border-radius: var(--radius-md, 8px);
    background: var(--color-surface, #fff);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text, #40474F);
    text-align: center;
    transition: border-color .15s, background .15s, color .15s;
    line-height: 1.2;
    font-family: inherit;
    min-width: 0;
    word-break: break-word;
}
.a11y-btn:hover {
    border-color: var(--color-primary, #1e3a5f);
    color: var(--color-primary-fg, #1e3a5f);
}
.a11y-btn:focus-visible {
    outline: 3px solid var(--color-primary, #1e3a5f);
    outline-offset: 2px;
}
.a11y-btn[aria-pressed="true"] {
    background: var(--color-primary, #1e3a5f);
    border-color: var(--color-primary, #1e3a5f);
    color: var(--color-text-inverse, #fff);
}
.a11y-btn .a11y-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.a11y-panel-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-divider, #dee2e6);
    text-align: center;
}
.a11y-reset-btn {
    background: none;
    border: 1px solid var(--color-danger, #dc3545);
    color: var(--color-danger-fg, #dc3545);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.4rem 1.5rem;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    transition: background .15s, color .15s;
    font-family: inherit;
}
.a11y-reset-btn:hover {
    background: var(--color-danger-fill, #dc3545);
    color: #fff;
}

/* Accessibility Feature Styles */
html.a11y-bigger-text-1 body { font-size: 110% !important; }
html.a11y-bigger-text-2 body { font-size: 125% !important; }

html.a11y-text-spacing body {
    letter-spacing: 0.08em !important;
    word-spacing: 0.16em !important;
}

html.a11y-line-height body { line-height: 2 !important; }
html.a11y-line-height p,
html.a11y-line-height li,
html.a11y-line-height td,
html.a11y-line-height th,
html.a11y-line-height span,
html.a11y-line-height label,
html.a11y-line-height input,
html.a11y-line-height textarea { line-height: 2 !important; }

html.a11y-highlight-links a:not(.sidebar a):not(.nav-link):not(.nav-parent):not([class*="btn"]):not(.fab-sub):not(#fab-main) {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
    background-color: rgba(255, 255, 0, 0.2) !important;
    padding: 0 2px !important;
    border-radius: 2px !important;
}
html.a11y-highlight-links .sidebar a,
html.a11y-highlight-links a[class*="btn"] {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
}

html.a11y-pause-anim *,
html.a11y-pause-anim *::before,
html.a11y-pause-anim *::after {
    animation-play-state: paused !important;
    transition-duration: 0s !important;
    scroll-behavior: auto !important;
}

html.a11y-hide-images img:not(.a11y-keep),
html.a11y-hide-images svg:not(.a11y-keep),
html.a11y-hide-images [role="img"]:not(.a11y-keep),
html.a11y-hide-images picture { visibility: hidden !important; }

@font-face {
    font-family: "OpenDyslexic";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/opendyslexic-400.woff2") format("woff2");
}
@font-face {
    font-family: "OpenDyslexic";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/opendyslexic-700.woff2") format("woff2");
}
@font-face {
    font-family: "OpenDyslexic";
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/opendyslexic-400italic.woff2") format("woff2");
}
@font-face {
    font-family: "OpenDyslexic";
    font-style: italic;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/opendyslexic-700italic.woff2") format("woff2");
}
html.a11y-dyslexia,
html.a11y-dyslexia *:not(.material-icons):not(.material-icons-outlined):not(.material-symbols-outlined):not([class*="fa-"]):not(i) {
    font-family: "OpenDyslexic", "Lexie Readable", "Comic Sans MS", sans-serif !important;
}

html.a11y-large-cursor,
html.a11y-large-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M5 2 L5 26 L11 20 L17 28 L21 26 L15 18 L23 18 Z' fill='black' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 5 2, auto !important;
}
html.a11y-large-cursor a,
html.a11y-large-cursor button,
html.a11y-large-cursor [role="button"],
html.a11y-large-cursor input[type="submit"],
html.a11y-large-cursor input[type="button"],
html.a11y-large-cursor select,
html.a11y-large-cursor label {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M14 2 C14 2 14 14 14 14 L10 14 C10 14 10 18 14 18 L14 18 C14 18 14 20 14 20 L9 20 C9 20 9 24 13 24 L14 24 L14 26 L8 26 C8 26 8 30 12 30 L22 30 C26 30 28 28 28 24 L28 16 C28 14 26 12 24 12 L20 12 L20 2 C20 0 14 0 14 2Z' fill='black' stroke='white' stroke-width='1.2'/%3E%3C/svg%3E") 16 2, pointer !important;
}

/* Dotted-underline affordance stays on the element. The tooltip itself is a
   single body-level element (#a11y-js-tooltip) positioned with JS, so it can
   never be clipped by an ancestor's overflow and its text is not truncated.
   [data-a11y-title] is the temporary stash while the native title is
   suppressed during hover/focus, so the underline doesn't flicker. */
html.a11y-tooltips [title]:not([title=""]),
html.a11y-tooltips [data-a11y-title] {
    text-decoration: underline dotted !important;
}
#a11y-js-tooltip {
    position: fixed;
    display: none;
    top: 0;
    left: 0;
    background: #191919;
    color: #fff;
    padding: 0.35rem 0.65rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    font-weight: normal;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
    max-width: min(320px, 90vw);
    z-index: 2147483600;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
