/* ============================================================
   AccessiPress — Accessibility Toolbar Styles
   ============================================================ */

:root {
  --ap-primary:       #1a56db;
  --ap-primary-dark:  #1245b5;
  --ap-bg:            #ffffff;
  --ap-bg-panel:      #f9fafb;
  --ap-border:        #e5e7eb;
  --ap-text:          #111827;
  --ap-text-muted:    #6b7280;
  --ap-shadow:        0 8px 32px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.08);
  --ap-radius:        14px;
  --ap-radius-sm:     8px;
  --ap-transition:    150ms ease;
  --ap-panel-w:       280px;
  --ap-z:             999999;
  --ap-edge:          10px;
}

/* ---- Positioning wrapper ---- */
#accessipress-wrap {
  position: fixed;
  z-index: var(--ap-z);
  bottom: var(--ap-edge);
  right: var(--ap-edge);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

/* Ensure all plugin buttons don't inherit body font from browser UA stylesheet */
#accessipress-wrap button {
  font-family: inherit;
}

#accessipress-wrap.ap-pos-bottom-left  { right: auto; left: var(--ap-edge); align-items: flex-start; }
#accessipress-wrap.ap-pos-top-right    { bottom: auto; top: var(--ap-edge); flex-direction: column-reverse; }
#accessipress-wrap.ap-pos-top-left     { bottom: auto; top: var(--ap-edge); right: auto; left: var(--ap-edge); flex-direction: column-reverse; align-items: flex-start; }

/* ---- Toggle button — icon pill that expands on hover/focus ---- */
#accessipress-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  background: var(--ap-primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .01em;
  box-shadow: 0 2px 12px rgba(26,86,219,.35);
  /* width transitions from icon-only to icon+label */
  width: 46px;
  height: 46px;
  overflow: visible;
  transition:
    width     300ms cubic-bezier(0.34, 1.2, 0.64, 1),
    background var(--ap-transition),
    box-shadow var(--ap-transition);
  white-space: nowrap;
}

/* Active-feature indicator badge — sits outside the button at top-right */
.ap-active-dot {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 15px;
  height: 15px;
  background: #3b82f6;
  border: 2px solid var(--ap-primary-dark);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity var(--ap-transition), transform var(--ap-transition);
  pointer-events: none;
}

#accessipress-toggle.ap-has-active .ap-active-dot {
  opacity: 1;
  transform: scale(1);
}

/* The SVG sits in a fixed-size zone so it doesn't shift */
#accessipress-toggle svg {
  flex-shrink: 0;
  margin-left: 12px;
}

#accessipress-toggle .ap-toggle-label {
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  padding-left: 0;
  padding-right: 0;
  transition:
    max-width 300ms cubic-bezier(0.34, 1.2, 0.64, 1),
    opacity   200ms ease,
    padding   300ms ease;
}

#accessipress-toggle:hover,
#accessipress-toggle:focus-visible,
#accessipress-toggle[aria-expanded="true"] {
  width: auto;
  background: var(--ap-primary-dark);
  box-shadow: 0 4px 18px rgba(26,86,219,.40);
}

#accessipress-toggle:hover .ap-toggle-label,
#accessipress-toggle:focus-visible .ap-toggle-label,
#accessipress-toggle[aria-expanded="true"] .ap-toggle-label {
  max-width: 120px;
  opacity: 1;
  padding-left: 8px;
  padding-right: 16px;
}

#accessipress-toggle:focus-visible {
  outline: 3px solid var(--ap-primary);
  outline-offset: 3px;
}

/* ---- Panel ---- */
#accessipress-panel {
  width: var(--ap-panel-w);
  background: var(--ap-bg);
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow);
  overflow: hidden;
  transform-origin: bottom right;
}

#accessipress-wrap.ap-pos-bottom-left  #accessipress-panel { transform-origin: bottom left; }
#accessipress-wrap.ap-pos-top-right    #accessipress-panel { transform-origin: top right; }
#accessipress-wrap.ap-pos-top-left     #accessipress-panel { transform-origin: top left; }

#accessipress-panel[hidden] {
  display: none;
}

/* Panel open animation */
#accessipress-panel.ap-panel-enter {
  animation: ap-panel-in 180ms cubic-bezier(0.34, 1.3, 0.64, 1) forwards;
}

@keyframes ap-panel-in {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---- Panel header ---- */
.ap-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: var(--ap-bg-panel);
  border-bottom: 1px solid var(--ap-border);
}

.ap-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ap-text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.ap-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--ap-border);
  border-radius: 6px;
  color: var(--ap-text-muted);
  cursor: pointer;
  transition: background var(--ap-transition), color var(--ap-transition);
}

.ap-close:hover { background: var(--ap-border); color: var(--ap-text); }
.ap-close:focus-visible { outline: 2px solid var(--ap-primary); outline-offset: 2px; }

/* ---- Sections ---- */
.ap-section {
  padding: 14px 16px;
}

.ap-section-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ap-text-muted);
  margin-bottom: 10px;
}

.ap-divider {
  height: 1px;
  background: var(--ap-border);
  margin: 0;
}

/* ---- Font size controls ---- */
.ap-control-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border: 1px solid var(--ap-border);
  border-radius: var(--ap-radius-sm);
  background: var(--ap-bg);
  color: var(--ap-text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background var(--ap-transition), border-color var(--ap-transition);
  line-height: 1;
  flex: 1;
}

.ap-btn:hover { background: var(--ap-bg-panel); border-color: #d1d5db; }
.ap-btn:focus-visible { outline: 2px solid var(--ap-primary); outline-offset: 2px; }
.ap-btn--active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.ap-btn--reset {
  font-size: 12px;
  font-weight: 500;
  color: var(--ap-text-muted);
  flex: 0 0 auto;
}

.ap-btn-label { display: flex; align-items: baseline; gap: 1px; }
.ap-small { font-size: 10px; }
.ap-large { font-size: 16px; }

/* Font level indicator dots */
.ap-font-indicator {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  min-height: 16px;
}

#ap-font-level::before {
  content: '';
  display: block;
}

/* ---- Toggle buttons ---- */
.ap-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ap-toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--ap-radius-sm);
  cursor: pointer;
  color: var(--ap-text);
  text-align: left;
  font-size: 14px;
  transition: background var(--ap-transition), border-color var(--ap-transition);
}

.ap-toggle-btn:hover {
  background: var(--ap-bg-panel);
  border-color: var(--ap-border);
}

.ap-toggle-btn:focus-visible {
  outline: 2px solid var(--ap-primary);
  outline-offset: 2px;
}

.ap-toggle-btn[aria-checked="true"] {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.ap-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--ap-bg-panel);
  flex-shrink: 0;
  transition: background var(--ap-transition);
}

.ap-toggle-btn[aria-checked="true"] .ap-toggle-icon {
  background: #dbeafe;
  color: #1d4ed8;
}

.ap-toggle-text {
  flex: 1;
  font-weight: 500;
}

/* Toggle switch pill */
.ap-toggle-switch {
  position: relative;
  width: 34px;
  height: 20px;
  background: #d1d5db;
  border-radius: 10px;
  flex-shrink: 0;
  transition: background var(--ap-transition);
}

.ap-toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform var(--ap-transition);
}

.ap-toggle-btn[aria-checked="true"] .ap-toggle-switch {
  background: var(--ap-primary);
}

.ap-toggle-btn[aria-checked="true"] .ap-toggle-switch::after {
  transform: translateX(14px);
}

/* ---- Reset all button ---- */
.ap-reset-all {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-top: 1px solid var(--ap-border);
  color: #ef4444;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background var(--ap-transition);
}

.ap-reset-all:hover { background: #fef2f2; }
.ap-reset-all:focus-visible { outline: 2px solid #ef4444; outline-offset: -2px; }

/* ============================================================
   Accessibility Feature Styles — applied to <html>
   ============================================================ */

/* High contrast */
html.ap-high-contrast {
  filter: contrast(1.25);
}

/* Reduce motion */
html.ap-reduce-motion *,
html.ap-reduce-motion *::before,
html.ap-reduce-motion *::after {
  animation-duration:        0.001ms !important;
  animation-iteration-count: 1       !important;
  transition-duration:       0.001ms !important;
  scroll-behavior:           auto    !important;
}

/* Enhanced focus indicators */
html.ap-focus-enhanced *:focus,
html.ap-focus-enhanced *:focus-visible {
  outline:        3px solid #f59e0b !important;
  outline-offset: 3px               !important;
  border-radius:  2px;
}

/* Reading mode — improved line spacing & letter spacing */
html.ap-reading-mode body,
html.ap-reading-mode p,
html.ap-reading-mode li,
html.ap-reading-mode td,
html.ap-reading-mode th,
html.ap-reading-mode blockquote {
  line-height:    1.8   !important;
  letter-spacing: .03em !important;
  word-spacing:   .05em !important;
}

/* Force link underlines */
html.ap-link-underlines a,
html.ap-link-underlines a:visited {
  text-decoration:           underline !important;
  text-decoration-thickness: 2px       !important;
  text-underline-offset:     3px       !important;
}

/* ============================================================
   Dark mode
   ============================================================ */
@media (prefers-color-scheme: dark) {
  #accessipress-wrap {
    --ap-bg:        #1f2937;
    --ap-bg-panel:  #111827;
    --ap-border:    #374151;
    --ap-text:      #f9fafb;
    --ap-text-muted:#9ca3af;
    --ap-shadow:    0 8px 32px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.35);
  }

  /* Inactive toggle switch track */
  .ap-toggle-switch {
    background: #6b7280;
  }

  /* Active font size button */
  .ap-btn--active {
    background:   #1e3a5f;
    border-color: #3b82f6;
    color:        #93c5fd;
  }

  /* Active toggle row */
  .ap-toggle-btn[aria-checked="true"] {
    background:   #1e3a5f;
    border-color: #3b82f6;
    color:        #93c5fd;
  }

  .ap-toggle-btn[aria-checked="true"] .ap-toggle-icon {
    background: #1e3a5f;
    color:      #93c5fd;
  }

  /* Active toggle track — bright blue so the white dot is clearly visible */
  .ap-toggle-btn[aria-checked="true"] .ap-toggle-switch {
    background: #3b82f6;
  }

  /* Dot — stronger shadow so it reads against both light and dark tracks */
  .ap-toggle-switch::after {
    box-shadow: 0 1px 4px rgba(0,0,0,.6);
  }

  /* Reset all — brighter red + !important to override theme button colour rules */
  .ap-reset-all         { color: #f87171 !important; }
  .ap-reset-all:hover   { background: #450a0a; }
}

/* ============================================================
   Reduced motion — respect OS preference automatically
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  #accessipress-panel.ap-panel-enter {
    animation: none;
  }
  #accessipress-toggle,
  #accessipress-toggle .ap-toggle-label {
    transition: background var(--ap-transition), box-shadow var(--ap-transition);
  }
}
