/**
 * MB Accessibility – Widget UI
 * The floating button and slide-out panel.
 */

/* ==========================================================================
   CSS Custom Properties (defaults – overridden inline by PHP)
   ========================================================================== */

:root {
	--mba-color:       #1a6baa;
	--mba-color-dark:  #1a6baa;
	--mba-color-alpha: rgba(26,107,170,0.12);
	--mba-white:       #fff;
	--mba-text:        #222;
	--mba-border:      #dde0e5;
	--mba-bg:          #fff;
	--mba-section-bg:  #f7f8fa;
	--mba-radius:      10px;
	--mba-shadow:      0 8px 32px rgba(0,0,0,0.18);
	--mba-panel-w:     300px;
	--mba-z:           9999;
}

/* ==========================================================================
   WRAPPER
   ========================================================================== */

#mba-widget-wrapper {
	position: fixed;
	bottom: 24px;
	z-index: var(--mba-z);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	/* Font-size fisso in px: immune da qualsiasi variazione della pagina */
	font-size: 14px !important;
	line-height: 1.4;
	color: var(--mba-text);
}

/* Tutti i figli del widget usano dimensioni relative al wrapper (14px), non alla pagina */
#mba-widget-wrapper * {
	font-size: inherit;
	box-sizing: border-box;
}

#mba-widget-wrapper.mba-pos-right {
	right: 20px;
}

#mba-widget-wrapper.mba-pos-left {
	left: 20px;
}

@media (max-width: 768px) {
	#mba-widget-wrapper.mba-hide-mobile {
		display: none !important;
	}
}

/* ==========================================================================
   TOGGLE BUTTON (floating)
   ========================================================================== */

#mba-toggle {
	width: 54px;
	height: 54px;
	border-radius: 50%;
	border: none;
	background: var(--mba-color);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 16px rgba(0,0,0,0.25);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	position: relative;
	z-index: calc(var(--mba-z) + 1);
}

#mba-toggle:hover,
#mba-toggle:focus {
	transform: scale(1.08);
	box-shadow: 0 6px 20px rgba(0,0,0,0.30);
	outline: 3px solid rgba(255,255,255,0.7);
	outline-offset: 2px;
}

#mba-toggle svg {
	width: 26px;
	height: 26px;
	fill: #fff;
	pointer-events: none;
}

/* ==========================================================================
   PANEL
   ========================================================================== */

#mba-panel {
	position: absolute;
	bottom: calc(100% + 10px);
	width: var(--mba-panel-w);
	max-height: 78vh;
	background: var(--mba-bg);
	border-radius: var(--mba-radius);
	box-shadow: var(--mba-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;

	/* Hidden by default */
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px) scale(0.97);
	transform-origin: bottom center;
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s 0.22s;
	pointer-events: none;
}

/* Right-aligned panel */
#mba-widget-wrapper.mba-pos-right #mba-panel {
	right: 0;
}

/* Left-aligned panel */
#mba-widget-wrapper.mba-pos-left #mba-panel {
	left: 0;
}

/* Open state */
#mba-panel.is-open {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s 0s;
	pointer-events: auto;
}

/* Small screens: full-width panel from bottom */
@media (max-width: 480px) {
	#mba-widget-wrapper {
		bottom: 16px;
	}
	#mba-widget-wrapper.mba-pos-right,
	#mba-widget-wrapper.mba-pos-left {
		right: 16px;
		left: 16px;
	}
	#mba-panel {
		position: fixed;
		bottom: 80px;
		left: 10px !important;
		right: 10px !important;
		width: auto !important;
		max-height: 75vh;
	}
}

/* ==========================================================================
   PANEL HEADER
   ========================================================================== */

.mba-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	background: var(--mba-color);
	color: #fff;
	flex-shrink: 0;
}

.mba-panel-title {
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: #fff;
}

.mba-close {
	background: none;
	border: none;
	cursor: pointer;
	padding: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 6px;
	color: #fff;
	opacity: 0.85;
	transition: opacity 0.15s;
}

.mba-close:hover,
.mba-close:focus {
	opacity: 1;
	outline: 2px solid rgba(255,255,255,0.7);
}

.mba-close svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

/* ==========================================================================
   PANEL BODY
   ========================================================================== */

.mba-panel-body {
	overflow-y: auto;
	flex: 1;
	padding: 12px;
	-webkit-overflow-scrolling: touch;
}

.mba-panel-body::-webkit-scrollbar { width: 4px; }
.mba-panel-body::-webkit-scrollbar-track { background: transparent; }
.mba-panel-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ==========================================================================
   RESET BUTTON  (prominente, sempre visibile)
   ========================================================================== */

.mba-reset-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	width: 100%;
	padding: 9px 14px;
	background: #fff5f5;
	border: 1.5px solid #f5a5a5;
	border-radius: 8px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 700;
	color: #c0392b;
	margin-bottom: 12px;
	transition: background 0.15s, border-color 0.15s, color 0.15s;
	font-family: inherit;
	letter-spacing: 0.01em;
}

.mba-reset-btn svg {
	width: 15px;
	height: 15px;
	fill: currentColor;
	flex-shrink: 0;
}

.mba-reset-btn:hover,
.mba-reset-btn:focus {
	background: #ffe0e0;
	border-color: #c0392b;
	color: #a02020;
	outline: none;
}

/* ==========================================================================
   SECTIONS
   ========================================================================== */

.mba-section {
	margin-bottom: 10px;
}

.mba-section-title {
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: #888;
	margin-bottom: 7px;
	padding: 0 2px;
}

/* ==========================================================================
   FEATURE GRID
   ========================================================================== */

.mba-features-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 7px;
}

/* ==========================================================================
   FEATURE BUTTON
   States: default → hover → active (aria-pressed="true" / .is-active)
   ========================================================================== */

.mba-feature-btn {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 5px;
	padding: 10px 6px;
	/* Default: neutral white/light background */
	background: #ffffff;
	border: 1.5px solid #d0d5dd;
	border-radius: 8px;
	cursor: pointer;
	font-size: 11px;
	font-weight: 600;
	color: #444;
	line-height: 1.3;
	text-align: center;
	transition: background 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s;
	font-family: inherit;
	min-height: 62px;
	box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Hover: colored border + tinted bg — hint che è cliccabile */
.mba-feature-btn:hover:not(.is-active):not([aria-pressed="true"]) {
	background: var(--mba-color-alpha);
	border-color: var(--mba-color);
	color: var(--mba-color);
	box-shadow: 0 2px 6px rgba(0,0,0,0.10);
}

/* Focus keyboard */
.mba-feature-btn:focus-visible {
	outline: 2px solid var(--mba-color);
	outline-offset: 2px;
}

/* ACTIVE (on): solid fill — visivamente pieno, stato ON chiaro */
.mba-feature-btn.is-active,
.mba-feature-btn[aria-pressed="true"] {
	background: var(--mba-color);
	border-color: var(--mba-color);
	color: #fff;
	box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

/* Hover su tasto già attivo: leggermente più scuro */
.mba-feature-btn.is-active:hover,
.mba-feature-btn[aria-pressed="true"]:hover {
	filter: brightness(0.88);
	box-shadow: 0 3px 10px rgba(0,0,0,0.22);
}

/* Icona SVG e testo label: bianco esplicito sullo stato attivo.
   Serve perché alcuni browser/temi non propagano correttamente
   color: #fff sull'attributo SVG fill via currentColor. */
.mba-feature-btn.is-active .mba-feature-icon,
.mba-feature-btn[aria-pressed="true"] .mba-feature-icon {
	color: #fff !important;
}

.mba-feature-btn.is-active .mba-feature-icon svg,
.mba-feature-btn[aria-pressed="true"] .mba-feature-icon svg {
	fill: #fff !important;
}

.mba-feature-btn.is-active .mba-feature-label,
.mba-feature-btn[aria-pressed="true"] .mba-feature-label {
	color: #fff !important;
}

.mba-feature-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
}

.mba-feature-icon svg {
	width: 20px;
	height: 20px;
	fill: currentColor;
}

.mba-feature-label {
	font-size: 10.5px;
	line-height: 1.25;
}

/* Screen reader button spans full width */
.mba-sr-toggle-btn {
	flex-direction: row;
	justify-content: flex-start;
	gap: 10px;
	width: 100%;
	padding: 10px 14px;
	min-height: 44px;
	font-size: 12px;
}

.mba-sr-toggle-btn.is-active .mba-feature-icon svg,
.mba-sr-toggle-btn[aria-pressed="true"] .mba-feature-icon svg {
	fill: #fff !important;
}

.mba-sr-toggle-btn.is-active .mba-feature-label,
.mba-sr-toggle-btn[aria-pressed="true"] .mba-feature-label {
	color: #fff !important;
}

/* ==========================================================================
   FONT SIZE CONTROL
   ========================================================================== */

.mba-fontsize-row {
	grid-column: 1 / -1;  /* full width */
	background: var(--mba-section-bg);
	border: 1.5px solid var(--mba-border);
	border-radius: 8px;
	padding: 8px 10px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.mba-fontsize-label {
	font-size: 10.5px;
	font-weight: 600;
	color: var(--mba-text);
}

.mba-fontsize-controls {
	display: flex;
	align-items: center;
	gap: 6px;
}

.mba-font-btn {
	display: flex;
	align-items: center;
	gap: 2px;
	background: #fff;
	border: 1.5px solid var(--mba-border);
	border-radius: 6px;
	cursor: pointer;
	padding: 4px 8px;
	font-weight: 700;
	color: var(--mba-text);
	transition: color 0.15s, border-color 0.15s;
	font-family: inherit;
	font-size: 13px;
	line-height: 1;
}

.mba-font-btn svg {
	width: 12px;
	height: 12px;
	fill: currentColor;
}

.mba-font-btn:hover,
.mba-font-btn:focus {
	color: var(--mba-color);
	border-color: var(--mba-color);
	outline: none;
}

.mba-font-btn:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

.mba-font-current {
	flex: 1;
	text-align: center;
	font-size: 13px;
	font-weight: 700;
	color: var(--mba-text);
	min-width: 42px;
}

/* ==========================================================================
   SCREEN READER CONTROLS
   ========================================================================== */

.mba-sr-status {
	font-size: 11px;
	color: #666;
	margin: 6px 0 4px;
	min-height: 16px;
	padding: 0 2px;
}

.mba-sr-stop-btn {
	display: flex;
	align-items: center;
	gap: 6px;
	background: #ffe5e5;
	border: 1.5px solid #f88;
	border-radius: 7px;
	padding: 7px 12px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 600;
	color: #c00;
	width: 100%;
	margin-top: 4px;
	font-family: inherit;
	transition: background 0.15s;
}

.mba-sr-stop-btn:hover,
.mba-sr-stop-btn:focus {
	background: #fdd;
	outline: none;
}

.mba-sr-stop-btn svg {
	width: 14px;
	height: 14px;
	fill: currentColor;
	flex-shrink: 0;
}

.mba-sr-speed {
	display: flex;
	align-items: center;
	gap: 7px;
	margin-top: 8px;
	padding: 6px 8px;
	background: var(--mba-section-bg);
	border-radius: 7px;
}

.mba-sr-speed label {
	display: flex;
	align-items: center;
	color: #777;
	cursor: pointer;
}

.mba-sr-speed label svg {
	fill: currentColor;
}

#mba-sr-speed {
	flex: 1;
	appearance: none;
	-webkit-appearance: none;
	height: 4px;
	background: var(--mba-border);
	border-radius: 2px;
	outline: none;
	cursor: pointer;
}

#mba-sr-speed::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--mba-color);
	cursor: pointer;
}

#mba-sr-speed::-moz-range-thumb {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--mba-color);
	cursor: pointer;
	border: none;
}

#mba-sr-speed-val {
	font-size: 11px;
	font-weight: 700;
	color: var(--mba-text);
	min-width: 24px;
	text-align: right;
}

/* ==========================================================================
   PANEL FOOTER – Accessibility Statement
   ========================================================================== */

.mba-panel-footer {
	flex-shrink: 0;
	padding: 8px 14px;
	border-top: 1px solid var(--mba-border);
	text-align: center;
	background: #fafbfc;
}

.mba-statement-link {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 10.5px;
	color: var(--mba-color);
	text-decoration: none;
	opacity: 0.8;
	transition: opacity 0.15s;
}

.mba-statement-link:hover,
.mba-statement-link:focus {
	opacity: 1;
	text-decoration: underline;
	outline: none;
}

.mba-statement-link svg {
	fill: currentColor;
	flex-shrink: 0;
}

/* ==========================================================================
   RTL SUPPORT
   ========================================================================== */

body[dir="rtl"] #mba-widget-wrapper.mba-pos-right {
	right: auto;
	left: 20px;
}

body[dir="rtl"] #mba-widget-wrapper.mba-pos-left {
	left: auto;
	right: 20px;
}

body[dir="rtl"] #mba-widget-wrapper.mba-pos-right #mba-panel {
	right: auto;
	left: 0;
}

body[dir="rtl"] #mba-widget-wrapper.mba-pos-left #mba-panel {
	left: auto;
	right: 0;
}
