/* ═══════════════════════════════════════════
   UI Controls — graphical checkboxes & switches
   Brand: طراح سفید (#7fc945)
   ═══════════════════════════════════════════ */

:root {
    --ui-brand: #7fc945;
    --ui-brand-2: #62a832;
    --ui-brand-soft: #eef8ea;
    --ui-ink: #1a2b20;
    --ui-mute: #64748b;
    --ui-line: #d8e0d9;
    --ui-track: #c9d2cb;
    --ui-danger: #ef4444;
}

/* ─── Base checkbox (site-wide) ─── */
input[type="checkbox"] {
    --ui-sz: 1.25rem;
    appearance: none !important;
    -webkit-appearance: none !important;
    width: var(--ui-sz) !important;
    height: var(--ui-sz) !important;
    min-width: var(--ui-sz) !important;
    min-height: var(--ui-sz) !important;
    margin: 0 !important;
    flex: 0 0 auto;
    display: inline-grid !important;
    place-content: center;
    vertical-align: middle;
    cursor: pointer;
    border: 2px solid var(--ui-line) !important;
    border-radius: .45rem !important;
    background:
        linear-gradient(180deg, #fff 0%, #f6faf4 100%) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .9),
        0 1px 2px rgba(20, 32, 26, .06) !important;
    transition:
        background .18s ease,
        border-color .18s ease,
        box-shadow .18s ease,
        transform .15s ease;
    color: #fff;
    accent-color: var(--ui-brand);
}

input[type="checkbox"]::before {
    content: "";
    width: .62rem;
    height: .62rem;
    transform: scale(0) rotate(-12deg);
    transition: transform .16s cubic-bezier(.2, .9, .3, 1.2);
    background: currentColor;
    clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 18%, 82% 0, 38% 62%);
}

input[type="checkbox"]:hover {
    border-color: color-mix(in srgb, var(--ui-brand) 55%, var(--ui-line)) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .9),
        0 0 0 4px rgba(127, 201, 69, .12) !important;
}

input[type="checkbox"]:focus-visible {
    outline: none !important;
    border-color: var(--ui-brand) !important;
    box-shadow: 0 0 0 4px rgba(127, 201, 69, .28) !important;
}

input[type="checkbox"]:checked {
    border-color: transparent !important;
    background:
        linear-gradient(145deg, var(--ui-brand) 0%, var(--ui-brand-2) 100%) !important;
    box-shadow:
        0 4px 12px rgba(98, 168, 50, .35),
        inset 0 1px 0 rgba(255, 255, 255, .25) !important;
}

input[type="checkbox"]:checked::before {
    transform: scale(1) rotate(0deg);
}

input[type="checkbox"]:active {
    transform: scale(.92);
}

input[type="checkbox"]:disabled {
    opacity: .45;
    cursor: not-allowed;
    box-shadow: none !important;
}

input[type="checkbox"]:indeterminate {
    border-color: transparent !important;
    background: linear-gradient(145deg, #94a3b8, #64748b) !important;
}

input[type="checkbox"]:indeterminate::before {
    transform: scale(1);
    clip-path: inset(38% 12% 38% 12% round 2px);
}

/* ─── Radio ─── */
input[type="radio"] {
    --ui-sz: 1.2rem;
    appearance: none !important;
    -webkit-appearance: none !important;
    width: var(--ui-sz) !important;
    height: var(--ui-sz) !important;
    min-width: var(--ui-sz) !important;
    min-height: var(--ui-sz) !important;
    margin: 0 !important;
    flex: 0 0 auto;
    display: inline-grid !important;
    place-content: center;
    vertical-align: middle;
    cursor: pointer;
    border: 2px solid var(--ui-line) !important;
    border-radius: 999px !important;
    background: linear-gradient(180deg, #fff, #f6faf4) !important;
    box-shadow: 0 1px 2px rgba(20, 32, 26, .06) !important;
    transition: .18s ease;
}

input[type="radio"]::before {
    content: "";
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    transform: scale(0);
    background: linear-gradient(145deg, var(--ui-brand), var(--ui-brand-2));
    box-shadow: 0 1px 4px rgba(98, 168, 50, .35);
    transition: transform .16s cubic-bezier(.2, .9, .3, 1.2);
}

input[type="radio"]:hover {
    border-color: color-mix(in srgb, var(--ui-brand) 55%, var(--ui-line)) !important;
    box-shadow: 0 0 0 4px rgba(127, 201, 69, .12) !important;
}

input[type="radio"]:focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 4px rgba(127, 201, 69, .28) !important;
}

input[type="radio"]:checked {
    border-color: var(--ui-brand) !important;
    background: #fff !important;
}

input[type="radio"]:checked::before {
    transform: scale(1);
}

input[type="radio"]:disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* ─── Label companions ─── */
.ui-check {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    cursor: pointer;
    user-select: none;
    line-height: 1.35;
}

/* ─── Pill switch (anchor / role=switch) ─── */
.sc-switch,
.ui-switch-track,
a.sc-switch,
[role="switch"].sc-switch {
    --sw-w: 2.85rem;
    --sw-h: 1.55rem;
    --sw-knob: 1.15rem;
    position: relative;
    width: var(--sw-w) !important;
    height: var(--sw-h) !important;
    border-radius: 999px !important;
    background:
        linear-gradient(180deg, #b8c2bb 0%, var(--ui-track) 100%) !important;
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: middle;
    box-shadow:
        inset 0 1px 3px rgba(15, 23, 42, .18),
        0 1px 0 rgba(255, 255, 255, .35) !important;
    transition: background .22s ease, box-shadow .22s ease;
    text-decoration: none !important;
    overflow: hidden;
}

.sc-switch::before,
.ui-switch-track::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(10px 10px at 72% 50%, rgba(255, 255, 255, .22), transparent 70%);
    pointer-events: none;
    opacity: .7;
}

.sc-switch::after,
.ui-switch-track::after {
    content: "" !important;
    position: absolute !important;
    top: 50% !important;
    right: .2rem !important;
    width: var(--sw-knob) !important;
    height: var(--sw-knob) !important;
    border-radius: 50% !important;
    background:
        linear-gradient(180deg, #fff 0%, #f1f5f3 100%) !important;
    box-shadow:
        0 2px 6px rgba(15, 23, 42, .22),
        0 0 0 1px rgba(15, 23, 42, .04) !important;
    transform: translateY(-50%) !important;
    transition: right .22s cubic-bezier(.2, .9, .3, 1.05), background .2s ease, box-shadow .2s ease !important;
}

.sc-switch.on,
.sc-switch[aria-checked="true"],
.ui-switch-track.is-on {
    background: linear-gradient(135deg, var(--ui-brand) 0%, var(--ui-brand-2) 100%) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .28),
        0 4px 14px rgba(98, 168, 50, .32) !important;
}

.sc-switch.on::after,
.sc-switch[aria-checked="true"]::after,
.ui-switch-track.is-on::after {
    right: calc(var(--sw-w) - var(--sw-knob) - .2rem) !important;
    box-shadow:
        0 2px 8px rgba(15, 23, 42, .2),
        0 0 0 1px rgba(255, 255, 255, .35) !important;
}

.sc-switch:hover,
.ui-switch-track:hover {
    filter: brightness(1.03);
}

.sc-switch:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px rgba(127, 201, 69, .3) !important;
}

/* ─── Checkbox-as-switch (settings / toggles) ─── */
.as-switch > input[type="checkbox"],
.as-switch input[type="checkbox"],
.ab-toggles input[type="checkbox"],
.ui-switch input[type="checkbox"],
label.ui-switch > input[type="checkbox"],
.ab-check input[type="checkbox"][name="is_active"],
.ahs-check input[type="checkbox"][name="is_reseller"],
.ahs-check input[type="checkbox"][name="is_active"],
input[type="checkbox"].ui-toggle {
    --sw-w: 2.85rem;
    --sw-h: 1.55rem;
    --sw-knob: 1.15rem;
    width: var(--sw-w) !important;
    height: var(--sw-h) !important;
    min-width: var(--sw-w) !important;
    min-height: var(--sw-h) !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: linear-gradient(180deg, #b8c2bb 0%, var(--ui-track) 100%) !important;
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, .18) !important;
    display: inline-block !important;
    place-content: unset;
    position: relative;
    overflow: hidden;
    color: transparent;
}

.as-switch > input[type="checkbox"]::before,
.as-switch input[type="checkbox"]::before,
.ab-toggles input[type="checkbox"]::before,
.ui-switch input[type="checkbox"]::before,
label.ui-switch > input[type="checkbox"]::before,
.ab-check input[type="checkbox"][name="is_active"]::before,
.ahs-check input[type="checkbox"][name="is_reseller"]::before,
.ahs-check input[type="checkbox"][name="is_active"]::before,
input[type="checkbox"].ui-toggle::before {
    content: "";
    position: absolute;
    top: 50%;
    right: .2rem;
    width: var(--sw-knob);
    height: var(--sw-knob);
    border-radius: 50%;
    background: linear-gradient(180deg, #fff, #f1f5f3);
    box-shadow: 0 2px 6px rgba(15, 23, 42, .22);
    transform: translateY(-50%);
    transition: right .22s cubic-bezier(.2, .9, .3, 1.05);
    clip-path: none;
}

.as-switch > input[type="checkbox"]:checked,
.as-switch input[type="checkbox"]:checked,
.ab-toggles input[type="checkbox"]:checked,
.ui-switch input[type="checkbox"]:checked,
label.ui-switch > input[type="checkbox"]:checked,
.ab-check input[type="checkbox"][name="is_active"]:checked,
.ahs-check input[type="checkbox"][name="is_reseller"]:checked,
.ahs-check input[type="checkbox"][name="is_active"]:checked,
input[type="checkbox"].ui-toggle:checked {
    background: linear-gradient(135deg, var(--ui-brand), var(--ui-brand-2)) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .28),
        0 4px 14px rgba(98, 168, 50, .32) !important;
}

.as-switch > input[type="checkbox"]:checked::before,
.as-switch input[type="checkbox"]:checked::before,
.ab-toggles input[type="checkbox"]:checked::before,
.ui-switch input[type="checkbox"]:checked::before,
label.ui-switch > input[type="checkbox"]:checked::before,
.ab-check input[type="checkbox"][name="is_active"]:checked::before,
.ahs-check input[type="checkbox"][name="is_reseller"]:checked::before,
.ahs-check input[type="checkbox"][name="is_active"]:checked::before,
input[type="checkbox"].ui-toggle:checked::before {
    right: calc(var(--sw-w) - var(--sw-knob) - .2rem);
}

.as-switch > input[type="checkbox"]:hover,
.ab-toggles input[type="checkbox"]:hover,
.ui-switch input[type="checkbox"]:hover,
input[type="checkbox"].ui-toggle:hover {
    filter: brightness(1.03);
    transform: none;
}

/* ─── Custom track switch (footer toggles etc.) ─── */
.as-ft-toggle .track {
    width: 2.7rem !important;
    height: 1.45rem !important;
    border-radius: 999px !important;
    background: linear-gradient(180deg, #b8c2bb, var(--ui-track)) !important;
    box-shadow: inset 0 1px 3px rgba(15, 23, 42, .18) !important;
    transition: background .22s ease, box-shadow .22s ease !important;
}

.as-ft-toggle .track::after {
    top: 50% !important;
    right: .18rem !important;
    width: 1.05rem !important;
    height: 1.05rem !important;
    transform: translateY(-50%) !important;
    background: linear-gradient(180deg, #fff, #f1f5f3) !important;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .22) !important;
    transition: right .22s cubic-bezier(.2, .9, .3, 1.05) !important;
}

.as-ft-toggle input:checked + .track {
    background: linear-gradient(135deg, var(--ui-brand), var(--ui-brand-2)) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .28),
        0 4px 12px rgba(98, 168, 50, .3) !important;
}

.as-ft-toggle input:checked + .track::after {
    right: calc(2.7rem - 1.05rem - .18rem) !important;
    transform: translateY(-50%) !important;
}

/* Hidden native inputs used only as controllers */
.as-ft-toggle input[type="checkbox"],
input[type="checkbox"][data-ui-native],
input[type="checkbox"].sr-only,
.sr-only > input[type="checkbox"] {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.as-ft-toggle input[type="checkbox"]::before,
input[type="checkbox"][data-ui-native]::before,
input[type="checkbox"].sr-only::before {
    content: none !important;
    display: none !important;
}

/* ─── Compact size helpers ─── */
input[type="checkbox"].ui-sm,
.ui-sm input[type="checkbox"]:not(.ui-toggle) {
    --ui-sz: 1.05rem;
    border-radius: .38rem !important;
}

input[type="checkbox"].ui-sm::before {
    width: .52rem;
    height: .52rem;
}

/* Card-style option rows (WP import etc.) */
.ui-opt-grid label,
.awi-opts label,
.wp-opts label,
.wpi-checks label,
.wpi-checkline {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .7rem .85rem;
    border: 1px solid #e7ece8;
    border-radius: 12px;
    background: linear-gradient(180deg, #fff, #f8fbf6);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    font-weight: 700;
    color: var(--ui-ink);
    cursor: pointer;
}

.ui-opt-grid label:focus-within,
.awi-opts label:focus-within,
.wp-opts label:focus-within,
.wpi-checks label:focus-within,
.wpi-checkline:focus-within {
    border-color: color-mix(in srgb, var(--ui-brand) 45%, #e7ece8);
    background: var(--ui-brand-soft);
    box-shadow: 0 0 0 3px rgba(127, 201, 69, .12);
}

.ui-switch {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    cursor: pointer;
    user-select: none;
}

.ui-switch > span {
    font-weight: 800;
}

/* Toggle row polish in blog editor */
.ab-toggles {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .65rem;
}

.ab-toggles .ui-switch {
    padding: .75rem .9rem;
    border: 1px solid #e7ece8;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff, #f7faf5);
    font-size: .88rem;
    color: var(--ui-ink);
}

@media (max-width: 640px) {
    .ab-toggles {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    input[type="checkbox"],
    input[type="checkbox"]::before,
    input[type="radio"],
    input[type="radio"]::before,
    .sc-switch,
    .sc-switch::after,
    .as-ft-toggle .track,
    .as-ft-toggle .track::after {
        transition: none !important;
    }
}
