/*
 * Accessibility ("Maxsus imkoniyatlar") panel — VM 176-son nizom, 10-band.
 * Markup: resources/views/inc/partials/a11y-toggle.blade.php
 * Behaviour: public/assets/frontend/js/gov-a11y.js
 *
 * Settings live as attributes on <html> (set before first paint by a11y-head):
 *   data-a11y-font="1|2"          text size 115% / 130%
 *   data-a11y-contrast="high|gray"
 *   data-a11y-motion="off"        no animations / transitions
 *   data-a11y-images="off"        images hidden
 */

/* ---------- Toggle button ---------- */
.a11y-widget {
    position: relative;
}

.a11y-toggle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    color: var(--gov-primary, #2d4a6f);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.a11y-toggle:hover,
.a11y-toggle[aria-expanded="true"] {
    background: var(--gov-primary, #2d4a6f);
    border-color: var(--gov-primary, #2d4a6f);
    color: #fff;
}

.a11y-toggle:focus-visible,
.a11y-panel button:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 2px;
}

/* ---------- Panel ---------- */
.a11y-panel {
    box-sizing: border-box;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1100;
    width: 300px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 16px;
    background: #fff;
    color: var(--gov-text-dark, #1a1a1a);
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
}

.a11y-panel[hidden] {
    display: none;
}

.a11y-panel:focus {
    outline: none;
}

.a11y-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.a11y-panel__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--gov-primary-dark, #1e3654);
    display: flex;
    align-items: center;
    gap: 8px;
}

.a11y-panel__close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #64748b;
    font-size: 18px;
    cursor: pointer;
}

.a11y-panel__close:hover {
    background: #f1f5f9;
    color: #1a1a1a;
}

.a11y-group {
    padding: 12px 0;
    border-top: 1px solid #eef0f3;
}

.a11y-group[hidden] {
    display: none;
}

.a11y-group__label {
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #64748b;
}

.a11y-group__value {
    margin-top: 6px;
    font-size: 12px;
    color: #64748b;
    text-align: center;
}

.a11y-seg {
    display: flex;
    gap: 6px;
}

.a11y-seg--col {
    flex-direction: column;
}

.a11y-btn,
.a11y-switch,
.a11y-reset {
    box-sizing: border-box;
    font: inherit;
    cursor: pointer;
    border: 1px solid #d8dee6;
    border-radius: 6px;
    background: #f8fafc;
    color: #1f2937;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.a11y-btn {
    flex: 1 1 0;
    min-height: 38px;
    padding: 6px 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.a11y-seg--col .a11y-btn {
    justify-content: flex-start;
}

.a11y-btn--lg {
    font-size: 17px;
}

.a11y-btn--icon {
    flex: 0 0 42px;
    font-size: 18px;
}

.a11y-btn:hover,
.a11y-switch:hover,
.a11y-reset:hover {
    border-color: var(--gov-primary, #2d4a6f);
}

.a11y-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.a11y-btn[aria-pressed="true"] {
    background: var(--gov-primary, #2d4a6f);
    border-color: var(--gov-primary, #2d4a6f);
    color: #fff;
}

.a11y-row {
    display: flex;
    gap: 6px;
}

.a11y-row .a11y-switch {
    margin: 0;
}

/* On/off switch rendered as a button with aria-pressed */
.a11y-switch {
    position: relative;
    width: 100%;
    min-height: 40px;
    margin-bottom: 6px;
    padding: 8px 56px 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.a11y-switch:last-child {
    margin-bottom: 0;
}

.a11y-switch::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    width: 34px;
    height: 18px;
    margin-top: -9px;
    border-radius: 9px;
    background: #cbd5e1;
    box-shadow: inset 0 0 0 2px #cbd5e1;
    transition: background 0.2s;
}

.a11y-switch::before {
    content: "";
    position: absolute;
    right: 28px;
    top: 50%;
    z-index: 1;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border-radius: 50%;
    background: #fff;
    transition: right 0.2s;
}

.a11y-switch[aria-pressed="true"] {
    border-color: var(--gov-primary, #2d4a6f);
    background: #eef3f9;
}

.a11y-switch[aria-pressed="true"]::after {
    background: var(--gov-primary, #2d4a6f);
    box-shadow: inset 0 0 0 2px var(--gov-primary, #2d4a6f);
}

.a11y-switch[aria-pressed="true"]::before {
    right: 12px;
}

.a11y-hint {
    margin: 8px 0 0;
    font-size: 12px;
    color: #64748b;
}

.a11y-reset {
    width: 100%;
    margin-top: 4px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    color: #475569;
}

/* Element being read aloud */
.a11y-speaking {
    outline: 2px dashed #f59e0b !important;
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .a11y-panel {
        position: fixed;
        top: auto;
        right: 16px;
        bottom: 16px;
        left: 16px;
        width: auto;
        max-height: calc(100vh - 32px);
    }
}

/* ---------- Text size ---------- */
/* Most site CSS uses px, so the page is zoomed (scales px and rem alike and
   reflows to the viewport); the root font-size is the fallback without zoom. */
@supports (zoom: 1) {
    html[data-a11y-font="1"] body { zoom: 1.15; }
    html[data-a11y-font="2"] body { zoom: 1.3; }
}

@supports not (zoom: 1) {
    html[data-a11y-font="1"] { font-size: 115%; }
    html[data-a11y-font="2"] { font-size: 130%; }
}

html[data-a11y-font] body {
    overflow-x: hidden;
}

/* The panel sits inside the zoomed body: keep it within the real viewport. */
@supports (zoom: 1) {
    html[data-a11y-font="1"] .a11y-panel { max-height: calc((100vh - 32px) / 1.15); }
    html[data-a11y-font="2"] .a11y-panel { max-height: calc((100vh - 32px) / 1.3); }
}

/* ---------- Grayscale ---------- */
html[data-a11y-contrast="gray"] {
    filter: grayscale(100%);
}

/* ---------- High contrast: black background, white/yellow text ---------- */
html[data-a11y-contrast="high"] {
    --gov-primary: #ffff00;
    --gov-primary-dark: #ffff00;
    --gov-text-dark: #ffffff;
    --gov-text-body: #ffffff;
    background: #000 !important;
    color-scheme: dark;
}

/* :where() keeps specificity low so the link / heading rules below win. */
html[data-a11y-contrast="high"] :where(body, body *:not(img, video, svg, svg *)) {
    background-color: #000 !important;
    background-image: none !important;
    color: #fff !important;
    border-color: #fff !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

html[data-a11y-contrast="high"] :where(body *)::before,
html[data-a11y-contrast="high"] :where(body *)::after {
    color: #fff !important;
    border-color: #fff !important;
}

html[data-a11y-contrast="high"] a,
html[data-a11y-contrast="high"] a * {
    color: #ffff00 !important;
}

html[data-a11y-contrast="high"] a {
    text-decoration: underline !important;
}

html[data-a11y-contrast="high"] h1,
html[data-a11y-contrast="high"] h2,
html[data-a11y-contrast="high"] h3,
html[data-a11y-contrast="high"] h4,
html[data-a11y-contrast="high"] h5,
html[data-a11y-contrast="high"] h6 {
    color: #ffff00 !important;
}

html[data-a11y-contrast="high"] button,
html[data-a11y-contrast="high"] input,
html[data-a11y-contrast="high"] select,
html[data-a11y-contrast="high"] textarea {
    border: 1px solid #fff !important;
}

html[data-a11y-contrast="high"] svg {
    fill: currentColor;
}

html[data-a11y-contrast="high"] :focus-visible {
    outline: 3px solid #ffff00 !important;
    outline-offset: 2px;
}

html[data-a11y-contrast="high"] .a11y-panel {
    border: 2px solid #ffff00 !important;
}

html[data-a11y-contrast="high"] .a11y-btn[aria-pressed="true"],
html[data-a11y-contrast="high"] .a11y-btn[aria-pressed="true"] *,
html[data-a11y-contrast="high"] .a11y-switch[aria-pressed="true"],
html[data-a11y-contrast="high"] .a11y-switch[aria-pressed="true"] * {
    background-color: #ffff00 !important;
    color: #000 !important;
}

html[data-a11y-contrast="high"] .a11y-switch::after {
    background-color: #000 !important;
    box-shadow: inset 0 0 0 2px #fff !important;
}

html[data-a11y-contrast="high"] .a11y-switch[aria-pressed="true"]::after {
    background-color: #000 !important;
    box-shadow: inset 0 0 0 2px #000 !important;
}

html[data-a11y-contrast="high"] .a11y-switch::before {
    background-color: #fff !important;
}

/* ---------- No animations ---------- */
html[data-a11y-motion="off"],
html[data-a11y-motion="off"] *,
html[data-a11y-motion="off"] *::before,
html[data-a11y-motion="off"] *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
}

/* ---------- Hidden images ---------- */
html[data-a11y-images="off"] img,
html[data-a11y-images="off"] picture,
html[data-a11y-images="off"] video,
html[data-a11y-images="off"] iframe {
    visibility: hidden !important;
}

html[data-a11y-images="off"] body *:not(.a11y-panel *) {
    background-image: none !important;
}
