/* =============================================================
   DWR Accessibility Widget — UI Styles
   Floating button + slide-in panel
   ============================================================= */

/* ── Root / Variables ── */
#dwr-a11y-root {
  --a11y-accent:      #2271b1;
  --a11y-accent-dark: #135e96;
  --a11y-bg:          #ffffff;
  --a11y-text:        #1d2327;
  --a11y-muted:       #50575e;
  --a11y-border:      #dcdcde;
  --a11y-radius:      12px;
  --a11y-shadow:      0 8px 32px rgba(0,0,0,.18);
  --a11y-panel-w:     340px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Trigger Button ── */
.dwr-a11y-trigger {
  position: fixed;
  top: var(--a11y-top, 50%);   /* configurable จาก admin setting */
  transform: translateY(-50%);
  z-index: 999990;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--a11y-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, box-shadow .15s;
  outline: none;
}

.dwr-a11y-trigger:hover {
  background: var(--a11y-accent-dark);
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}

.dwr-a11y-trigger:hover .dwr-a11y-tooltip {
  opacity: 1;
  pointer-events: none;
}

.dwr-a11y-trigger:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.dwr-a11y-trigger svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.dwr-a11y-trigger[data-pos="right"] { right: 0; border-radius: 8px 0 0 8px; }
.dwr-a11y-trigger[data-pos="left"]  { left: 0;  border-radius: 0 8px 8px 0; }

/* ── Compact quick cluster (design: พิลล์ +/ก/- + ปุ่มวงกลม, มุมล่าง เหนือปุ่มแชท) ── */
.dwr-a11y-quick {
  position: fixed;
  z-index: 999985;               /* ใต้ปุ่มแชท (99999) เล็กน้อย ไม่ทับกัน */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* พิลล์ตัวอักษร +/ก/- (พื้นขาว โชว์ตลอด) — ขนาดปรับได้ผ่าน --a11y-fq-scale */
.dwr-a11y-fontquick {
  --a11y-fq-scale: 1;            /* JS ตั้งค่าจากแอดมิน (fallback = 1) */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(15,42,70,.20);
  padding: calc(6px * var(--a11y-fq-scale)) calc(5px * var(--a11y-fq-scale));
}
.dwr-a11y-fontquick button[data-font] {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  width: calc(34px * var(--a11y-fq-scale));
  height: calc(30px * var(--a11y-fq-scale));
  font-size: calc(20px * var(--a11y-fq-scale));
  font-weight: 700;
  line-height: 1;
  color: #14487e;
  border-radius: 50%;
  padding: 0;
  transition: background .15s;
}
.dwr-a11y-fontquick button[data-font]:hover  { background: #eaf2fb; }
.dwr-a11y-fontquick button[data-font]:active { background: #dcebf9; }
.dwr-a11y-fontquick button[data-font]:focus-visible { outline: 2px solid #14487e; outline-offset: 1px; }
.dwr-a11y-fontquick-ico {
  font-size: calc(17px * var(--a11y-fq-scale));
  font-weight: 700;
  color: #14487e;
  line-height: 1;
  padding: calc(2px * var(--a11y-fq-scale)) 0;
}

/* ปุ่ม trigger (วงกลมหยดน้ำ) อยู่ในพิลล์ขาวเดียวกัน — ขนาดตั้งผ่าน inline width/height จาก JS */
.dwr-a11y-quick .dwr-a11y-trigger {
  position: static !important;
  top: auto !important;
  right: auto !important;
  left: auto !important;
  transform: none !important;
  border-radius: 50% !important;
  box-shadow: none;              /* พิลล์ขาวเป็นตัวให้เงาแล้ว */
  flex: none;                    /* กันโดนบีบในพิลล์ */
}
.dwr-a11y-quick .dwr-a11y-trigger svg {
  width: 52%;
  height: 52%;
  fill: #fff;
}

/* ── Tooltip ── */
.dwr-a11y-tooltip {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}

.dwr-a11y-trigger[data-pos="right"] .dwr-a11y-tooltip {
  right: calc(100% + 8px);
}

.dwr-a11y-trigger[data-pos="left"] .dwr-a11y-tooltip {
  left: calc(100% + 8px);
}

/* ── Panel Backdrop ── */
.dwr-a11y-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 999991;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.dwr-a11y-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Panel ── */
.dwr-a11y-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--a11y-panel-w);
  max-width: 95vw;
  background: var(--a11y-bg);
  z-index: 999992;
  display: flex;
  flex-direction: column;
  box-shadow: var(--a11y-shadow);
  transform: translateX(110%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.dwr-a11y-panel[data-pos="right"] {
  right: 0;
  border-radius: var(--a11y-radius) 0 0 var(--a11y-radius);
  transform: translateX(110%);
}

.dwr-a11y-panel[data-pos="left"] {
  left: 0;
  border-radius: 0 var(--a11y-radius) var(--a11y-radius) 0;
  transform: translateX(-110%);
}

.dwr-a11y-panel.is-open {
  transform: translateX(0) !important;
}

/* ── Panel Header ── */
.dwr-a11y-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--a11y-accent);
  color: #fff;
  flex-shrink: 0;
}

.dwr-a11y-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .01em;
}

.dwr-a11y-header-btns {
  display: flex;
  gap: 6px;
}

.dwr-a11y-header-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}

.dwr-a11y-header-btn:hover {
  background: rgba(255,255,255,.28);
}

/* ── Panel Body (scrollable) ── */
.dwr-a11y-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--a11y-border) transparent;
}

/* ── Section Group ── */
.dwr-a11y-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--a11y-muted);
  margin: 12px 0 8px;
}

.dwr-a11y-group-title:first-child {
  margin-top: 0;
}

/* ── Feature Buttons Grid ── */
.dwr-a11y-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

/* Font size control (spans full width) */
.dwr-a11y-fontsize-ctrl {
  grid-column: span 3;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f6f7f7;
  border: 1px solid var(--a11y-border);
  border-radius: 10px;
  padding: 8px 12px;
}

.dwr-a11y-fontsize-ctrl .a11y-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--a11y-text);
  flex: 1;
}

.dwr-a11y-fontsize-ctrl button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--a11y-border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  color: var(--a11y-text);
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dwr-a11y-fontsize-ctrl button:hover {
  background: var(--a11y-accent);
  color: #fff;
  border-color: var(--a11y-accent);
}

.dwr-a11y-fontsize-ctrl .a11y-level {
  font-size: 12px;
  font-weight: 600;
  color: var(--a11y-accent);
  min-width: 30px;
  text-align: center;
}

/* ── Feature Button ── */
.dwr-a11y-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  border: 1.5px solid var(--a11y-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all .15s;
  font-size: 11px;
  font-weight: 500;
  color: var(--a11y-text);
  text-align: center;
  line-height: 1.3;
  min-height: 72px;
  position: relative;
}

.dwr-a11y-btn:hover {
  border-color: var(--a11y-accent);
  background: #f0f6fc;
  color: var(--a11y-accent);
}

.dwr-a11y-btn.is-active {
  border-color: var(--a11y-accent);
  background: var(--a11y-accent);
  color: #fff;
}

.dwr-a11y-btn .a11y-icon {
  font-size: 22px;
  line-height: 1;
  display: block;
}

/* TTS button special state */
.dwr-a11y-btn[data-feature="tts"].is-active {
  background: #d63638;
  border-color: #d63638;
}

/* ── TTS Hint ── */
.dwr-a11y-tts-hint {
  display: none;
  font-size: 11px;
  color: var(--a11y-muted);
  background: #fffbea;
  border: 1px solid #f5e07a;
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 4px;
  line-height: 1.5;
}

.dwr-a11y-tts-hint.is-visible {
  display: block;
}

/* ── Panel Footer ── */
.dwr-a11y-footer {
  flex-shrink: 0;
  padding: 10px 16px;
  background: var(--a11y-accent);
  color: rgba(255,255,255,.85);
  text-align: center;
  font-size: 11px;
  font-weight: 500;
}

/* ── Reading Guide overlay ── */
.dwr-a11y-reading-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 40px;
  background: rgba(34, 113, 177, .12);
  border-top: 2px solid rgba(34, 113, 177, .5);
  border-bottom: 2px solid rgba(34, 113, 177, .5);
  pointer-events: none;
  z-index: 999989;
  display: none;
  transform: translateY(-50%);
}

.dwr-a11y-reading-guide.is-visible {
  display: block;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #dwr-a11y-root {
    --a11y-panel-w: 100vw;
  }

  .dwr-a11y-panel[data-pos="right"],
  .dwr-a11y-panel[data-pos="left"] {
    border-radius: 0;
  }

  .dwr-a11y-trigger[data-pos="right"] { right: 0; }
  .dwr-a11y-trigger[data-pos="left"]  { left: 0; }
  .dwr-a11y-trigger[data-pos="left"]  { left: 12px; bottom: 16px; }
}

/* ═══════════════════════════════════════════════════════════════════
   WCAG 2.1 Level AAA — typography-only overrides.
   (The universal :focus-visible rule and the trigger-button white ring
    live in dwr-shared/assets/css/dwr-frontend-theme.css, scoped to
    #dwr-a11y-root + .dwr-a11y-trigger.)
   ─────────────────────────────────────────────────────────────────── */
.dwr-a11y-group-title {
  font-weight: 700 !important;
  font-size: 14px !important;
}
