/*
 * ============================================================
 * Общинска банка — Виджет за достъпност
 * Версия: 1.4  |  WCAG 2.1 AA / 2.2  |  EU Accessibility Act
 * Промени в 1.4: пълен TTS плейър (pause/resume, prev/next,
 * контрол на скоростта, highlighting на активното изречение,
 * нормализация на банков текст: числа, суми, IBAN, дати, %)
 * ============================================================
 */

/* ── Google Fonts & OpenDyslexic — ТРЯБВА да са преди всички други правила ── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500;600&family=Source+Sans+3:wght@300;400;500;600&display=swap');
@import url('https://fonts.cdnfonts.com/css/opendyslexic');

/* ── Защита на виджета от html font-size scale (задава се и от JS при init) ── */
#mb-a11y-fab,
#mb-a11y-panel,
#mb-a11y-panel *,
#mb-a11y-tooltip,
#mb-tts-reading,
#mb-tts-reading * {
  font-size: initial !important;
}

/* ── Design Tokens ── */
:root {
  --mb-navy:        #00B1EB;
  --mb-navy2:       #009DD4;
  --mb-gold:        #00B1EB;
  --mb-gold-light:  #33C4F0;
  --mb-cream:       #f0f9fd;
  --mb-white:       #ffffff;
  --mb-text:        #1a1a2e;
  --mb-muted:       #6b7280;
  --mb-border:      #d8e8f0;
  --mb-shadow:      0 24px 64px rgba(0,177,235,.18), 0 4px 16px rgba(0,177,235,.10);
}

/* ══════════════════════════════════════════
   WRAPPER (Фиксиран контейнер)
══════════════════════════════════════════ */
#mb-a11y-wrapper {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 2147483000; /* почти max int — над всякакви banner/modal overlays */
  overflow: visible;
  /* isolation — осигурява собствен stacking context и предпазва от
     ефекти на родителски filter/mix-blend-mode, ако потребителят все пак
     прикачи wrapper-а под body (fallback защита). */
  isolation: isolate;
}
#mb-a11y-wrapper > * {
  pointer-events: auto;
}

/* ══════════════════════════════════════════
   FAB BUTTON (плаващ бутон — фиксиран долу вдясно)
══════════════════════════════════════════ */
#mb-a11y-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--mb-navy);
  box-shadow: 0 8px 28px rgba(0,177,235,.38), 0 2px 8px rgba(0,177,235,.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s;
}
#mb-a11y-fab::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.7);
  opacity: .7;
  transition: opacity .22s;
}
#mb-a11y-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 36px rgba(0,177,235,.45);
}
#mb-a11y-fab:hover::after { opacity: 1; }
#mb-a11y-fab svg {
  width: 26px;
  height: 26px;
  fill: #ffffff;
}

/* Tooltip над бутона */
#mb-a11y-tooltip {
  position: fixed;
  bottom: 96px;
  right: 20px;
  background: var(--mb-navy);
  color: #ffffff;
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .06em;
  padding: 5px 11px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
#mb-a11y-fab:hover + #mb-a11y-tooltip { opacity: 1; transform: translateY(0); }

/* ══════════════════════════════════════════
   PANEL (изскачащ панел — фиксиран)
══════════════════════════════════════════ */
#mb-a11y-panel {
  position: fixed;
  bottom: 98px;
  right: 28px;
  width: 320px;
  max-height: min(600px, calc(100vh - 110px));
  background: var(--mb-white);
  border-radius: 16px;
  box-shadow: var(--mb-shadow);
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transform: translateY(18px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .28s cubic-bezier(.34,1.3,.64,1), opacity .22s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#mb-a11y-panel.mb-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}
/* Panel body */
.mb-pb {
  padding: 18px 20px 20px;
  flex: 1;
  overflow-y: auto;
}

/* Panel header — винаги видим, не скролира */
.mb-ph {
  background: var(--mb-navy);
  padding: 20px 20px 16px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  border-radius: 16px 16px 0 0;
}
.mb-ph::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 100px; height: 100px;
  border-radius: 50%;
  border: 20px solid rgba(255,255,255,.1);
}
.mb-ph::after {
  content: '';
  position: absolute;
  bottom: -20px; left: 60px;
  width: 70px; height: 70px;
  border-radius: 50%;
  border: 14px solid rgba(255,255,255,.06);
}
.mb-ph-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
}
.mb-ph-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
}
.mb-ph-icon svg { width: 20px; height: 20px; fill: #ffffff; }
.mb-ph-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.1);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mb-ph-close:hover { background: rgba(255,255,255,.1); }
.mb-ph-close svg { width: 12px; height: 12px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }
.mb-ph-title {
  font-family: 'Playfair Display', serif;
  font-size: 20px; font-weight: 600;
  color: #fff;
  margin-top: 14px;
  letter-spacing: .01em;
}
.mb-ph-sub { font-size: 13.5px; color: rgba(255,255,255,.9); margin-top: 4px; font-weight: 400; letter-spacing: .02em; }


/* ══════════════════════════════════════════
MOBILE STYLES
══════════════════════════════════════════ */
@media (max-width: 480px) {
  #mb-a11y-panel {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 80px;
    max-height: min(560px, calc(100vh - 100px));
  }
  #mb-a11y-fab {
    width: 50px;
    height: 50px;
    bottom: 16px;
    right: 16px;
  }
  #mb-a11y-fab svg {
    width: 22px;
    height: 22px;
  }
  #mb-a11y-tooltip {
    display: none;
  }
  #mb-tts-reading {
    right: 12px;
    bottom: 140px;
    width: calc(100vw - 24px);
  }
  .mb-pb {
    max-height: calc(100vh - 180px);
  }
}

/* Section label */
.mb-sec {
  font-size: 9.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: #004884;
  margin: 16px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.mb-sec::after { content: ''; flex: 1; height: 1px; background: var(--mb-border); }
.mb-sec:first-child { margin-top: 0; }

/* Toggle row */
.mb-trow {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid #f3f0ea;
}
.mb-trow:last-of-type { border-bottom: none; }
.mb-trow-left { display: flex; align-items: center; gap: 10px; }
.mb-trow-icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--mb-cream);
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.mb-trow-icon svg { width: 14px; height: 14px; fill: var(--mb-muted); transition: fill .2s; }
.mb-trow.mb-active .mb-trow-icon { background: rgba(0,177,235,.08); }
.mb-trow.mb-active .mb-trow-icon svg { fill: var(--mb-navy); }
.mb-trow-name { font-size: 13px; color: var(--mb-text); }

/* Toggle switch */
.mb-tog {
  width: 40px; height: 22px;
  border-radius: 11px; border: none;
  background: #e5e0d5;
  cursor: pointer; position: relative;
  transition: background .25s;
  flex-shrink: 0;
}
.mb-tog.mb-on { background: var(--mb-navy); }
.mb-tok {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
  transition: left .25s cubic-bezier(.34,1.56,.64,1);
}
.mb-tog.mb-on .mb-tok { left: 21px; }

/* Sliders */
.mb-srow { margin: 8px 0; }
.mb-srow-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.mb-srow-name { font-size: 13px; color: var(--mb-text); }
.mb-srow-val {
  font-size: 11px; font-weight: 600; color: #004884;
  background: rgba(0, 72, 132, .08);
  padding: 2px 8px; border-radius: 10px;
}
.mb-srow input[type="range"] {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: linear-gradient(to right, var(--mb-navy) var(--pct, 0%), #e5e0d5 var(--pct, 0%));
  border-radius: 2px; outline: none; cursor: pointer;
}
.mb-srow input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--mb-navy);
  box-shadow: 0 2px 6px rgba(0,177,235,.2);
  transition: transform .15s;
}
.mb-srow input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
.mb-srow input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--mb-navy);
  box-shadow: 0 2px 6px rgba(0,177,235,.2);
}

/* Reset button */
.mb-reset {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--mb-border);
  background: transparent;
  cursor: pointer;
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--mb-muted);
  letter-spacing: .04em;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.mb-reset:hover { background: var(--mb-cream); color: var(--mb-navy); border-color: var(--mb-navy); }
.mb-reset svg { width: 13px; height: 13px; fill: currentColor; }

/* ══════════════════════════════════════════
DYSLEXIA FONT (дислексия шрифт)
══════════════════════════════════════════ */
body.mb-dyslexia-font {
  font-family: 'OpenDyslexic', 'Comic Sans MS', Georgia, serif !important;
  line-height: 2 !important;
  word-spacing: 0.18em !important;
  letter-spacing: 0.05em !important;
}
body.mb-dyslexia-font * {
  font-family: 'OpenDyslexic', 'Comic Sans MS', Georgia, serif !important;
  line-height: 2 !important;
  word-spacing: 0.18em !important;
  letter-spacing: 0.05em !important;
}
/* Изключваме виджета от дислексия шрифта */
body.mb-dyslexia-font #mb-a11y-panel,
body.mb-dyslexia-font #mb-a11y-panel *,
body.mb-dyslexia-font #mb-a11y-fab,
body.mb-dyslexia-font #mb-a11y-tooltip,
body.mb-dyslexia-font #mb-tts-reading,
body.mb-dyslexia-font #mb-tts-reading * {
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
  line-height: normal !important;
  word-spacing: normal !important;
  letter-spacing: initial !important;
}

/* ══════════════════════════════════════════
BIG TEXT BUTTONS (голям текст за бутони)
══════════════════════════════════════════ */
body.mb-big-buttons button,
body.mb-big-buttons input[type="button"],
body.mb-big-buttons input[type="submit"],
body.mb-big-buttons input[type="reset"],
body.mb-big-buttons .btn,
body.mb-big-buttons a.button,
body.mb-big-buttons .credit_button,
body.mb-big-buttons .block,
body.mb-big-buttons .fixed_buttons .tabs li,
body.mb-big-buttons .fixed_buttons .tabs a {
  font-size: 120% !important;
  padding: 14px 24px !important;
  min-height: 52px !important;
}

/* ══════════════════════════════════════════
TEXT TO SPEECH PLAYER
══════════════════════════════════════════ */
#mb-tts-reading {
  position: fixed;
  bottom: 166px;
  right: 28px;
  background: var(--mb-navy);
  color: var(--mb-white);
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  padding: 12px 16px;
  border-radius: 10px;
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  box-shadow: var(--mb-shadow);
  min-width: 260px;
  max-width: 300px;
  z-index: 999999;
}
#mb-tts-reading.mb-active { display: flex; }

/* Ред 1: вълни + статус етикет */
#mb-tts-reading .mb-tts-label {
  font-weight: 500;
  font-size: 13px;
  flex: 1;
}
#mb-tts-reading > .mb-tts-wave {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  position: absolute;
  top: 14px;
  right: 14px;
}
#mb-tts-reading .mb-tts-wave span {
  width: 3px;
  height: 12px;
  background: #ffffff;
  border-radius: 2px;
  animation: mb-tts-wave .6s ease-in-out infinite;
}
#mb-tts-reading .mb-tts-wave span:nth-child(2) { animation-delay: .1s; }
#mb-tts-reading .mb-tts-wave span:nth-child(3) { animation-delay: .2s; }
#mb-tts-reading .mb-tts-wave span:nth-child(4) { animation-delay: .3s; }
@keyframes mb-tts-wave {
  0%, 100% { height: 4px; }
  50% { height: 14px; }
}

/* Ред 2: контроли за навигация — prev, pause/resume, next */
#mb-tts-reading .mb-tts-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
#mb-tts-reading .mb-tts-ctrl {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  width: 44px;          /* WCAG 2.5.5 — минимум 44×44 */
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s ease, transform .1s ease;
}
#mb-tts-reading .mb-tts-ctrl:hover {
  background: rgba(255,255,255,.22);
}
#mb-tts-reading .mb-tts-ctrl:active {
  transform: scale(.95);
}
#mb-tts-reading .mb-tts-ctrl:focus-visible {
  outline: 2px solid var(--mb-gold);
  outline-offset: 2px;
}
#mb-tts-reading .mb-tts-ctrl svg {
  width: 18px;
  height: 18px;
  display: block;
}
#mb-tts-reading .mb-tts-ctrl-main {
  background: #ffffff;
  border-color: #ffffff;
  color: var(--mb-navy);
}
#mb-tts-reading .mb-tts-ctrl-main:hover {
  background: rgba(255,255,255,.85);
}

/* Превключване между pause (докато тече) и play (докато е на пауза) икони */
#mb-tts-reading .mb-tts-icon-play  { display: none; }
#mb-tts-reading .mb-tts-icon-pause { display: inline-flex; }
#mb-tts-reading #mb-tts-pause.mb-paused .mb-tts-icon-pause { display: none; }
#mb-tts-reading #mb-tts-pause.mb-paused .mb-tts-icon-play  { display: inline-flex; }

/* Ред 3: контрол на скоростта */
#mb-tts-reading .mb-tts-rate {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
#mb-tts-reading .mb-tts-rate-lbl {
  color: rgba(255,255,255,.85);
  min-width: 48px;
}
#mb-tts-reading .mb-tts-rate-val {
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  font-weight: 500;
}
#mb-tts-reading #mb-tts-rate-input {
  flex: 1;
  height: 28px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  margin: 0;
}
#mb-tts-reading #mb-tts-rate-input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,.25);
}
#mb-tts-reading #mb-tts-rate-input::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,.25);
}
#mb-tts-reading #mb-tts-rate-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #fff;
  margin-top: -6px;
  cursor: pointer;
}
#mb-tts-reading #mb-tts-rate-input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #fff;
  cursor: pointer;
}
#mb-tts-reading #mb-tts-rate-input:focus-visible {
  outline: 2px solid var(--mb-gold);
  outline-offset: 4px;
  border-radius: 4px;
}

/* Ред 4: Stop бутон — широк, ясен */
#mb-tts-stop {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  min-height: 32px;
  font-family: inherit;
}
#mb-tts-stop:hover { background: rgba(255,255,255,.25); }
#mb-tts-stop:focus-visible {
  outline: 2px solid var(--mb-gold);
  outline-offset: 2px;
}

/* ══════════════════════════════════════════
TTS HIGHLIGHT (активно четено изречение)
══════════════════════════════════════════ */
/* Модерни браузъри с CSS Custom Highlights API */
::highlight(mb-tts-active) {
  background-color: #d9f2fc;
  color: #1a1a2e;
  text-decoration: underline;
  text-decoration-color: var(--mb-navy);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* Fallback за браузъри без ::highlight поддръжка */
.mb-tts-highlight {
  background-color: #d9f2fc;
  color: #1a1a2e;
  text-decoration: underline;
  text-decoration-color: var(--mb-navy);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  border-radius: 2px;
  padding: 1px 2px;
  /* Избягваме layout shift когато добавим padding */
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* В B&W режим highlight-ът остава видим (не само с цвят — WCAG 1.4.1).
   Подчертаването и bold осигуряват различимост без цвят. */
.mb-tts-highlight {
  font-weight: 500;
}

/* ══════════════════════════════════════════
FOCUS HIGHLIGHT (силен фокус)
══════════════════════════════════════════ */
body.mb-focus-highlight *:focus,
body.mb-focus-highlight *:focus-visible {
  outline: 3px solid var(--mb-gold) !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 6px rgba(0,177,235,.35), 0 0 0 9px rgba(0,177,235,.15) !important;
  border-radius: 2px;
  position: relative;
  z-index: 1;
}
/* Изключение: елементите на самия виджет запазват своя нормален фокус */
body.mb-focus-highlight #mb-a11y-wrapper *:focus,
body.mb-focus-highlight #mb-a11y-wrapper *:focus-visible,
body.mb-focus-highlight #mb-a11y-fab:focus,
body.mb-focus-highlight #mb-a11y-panel *:focus,
body.mb-focus-highlight #mb-tts-reading *:focus {
  outline: 2px solid var(--mb-gold) !important;
  outline-offset: 2px !important;
  box-shadow: none !important;
}

/* ══════════════════════════════════════════
READING MASK (маска за четене)
══════════════════════════════════════════ */
#mb-reading-mask {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 9998;
}
#mb-reading-mask.mb-active { display: block; }
#mb-reading-mask .mb-mask-top,
#mb-reading-mask .mb-mask-bottom {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  background: rgba(0,0,0,.75);
  pointer-events: none;
}
#mb-reading-mask .mb-mask-top {
  top: 0;
  height: 0;
}
#mb-reading-mask .mb-mask-bottom {
  bottom: 0;
  height: 0;
}
#mb-reading-mask .mb-mask-line {
  position: fixed;
  left: 5%;
  right: 5%;
  height: 90px;
  top: 0;
  border: 3px solid var(--mb-gold);
  border-radius: 8px;
  pointer-events: none;
  background: transparent;
  box-shadow: 0 0 20px rgba(184,148,63,.4);
}