/**
 * Famylio Universal Scanner
 * Shared sensory scanner surface: upload, current device camera, paired-device QR.
 */

:root {
    --fus-ink: #f7faf8;
    --fus-muted: rgba(247, 250, 248, 0.64);
    --fus-soft: rgba(247, 250, 248, 0.78);
    --fus-panel: rgba(255, 255, 255, 0.045);
    --fus-panel-strong: rgba(255, 255, 255, 0.075);
    --fus-line: rgba(255, 255, 255, 0.1);
    --fus-line-strong: rgba(255, 255, 255, 0.16);
    --fus-phone-bg: #050607;
    --fus-phone-bg-soft: #0b0f12;
    --fus-accent: var(--terra, var(--init-button-orange, #d4654a));
    --fus-accent-soft: rgba(212, 101, 74, 0.18);
    --fus-green: #42d77d;
    --fus-green-soft: rgba(41, 196, 106, 0.14);
    --fus-danger: #fca5a5;
    --fus-shadow: 0 40px 120px rgba(0, 0, 0, 0.58);
    --fus-radius: 28px;
    --fus-radius-sm: 18px;
}

.fus-overlay {
    position: fixed;
    inset: 0;
    z-index: 10095;
    display: none;
    align-items: center;
    justify-content: center;
    padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    background: rgba(5, 6, 7, 0.74);
    backdrop-filter: blur(8px);
}

.fus-overlay.is-open {
    display: flex;
}

.fus-modal {
    width: min(980px, calc(100vw - 32px));
    height: min(820px, calc(100dvh - 32px));
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--fus-line);
    border-radius: var(--fus-radius);
    background:
        radial-gradient(circle at 18% 8%, rgba(41, 196, 106, 0.16), transparent 28%),
        radial-gradient(circle at 84% 12%, rgba(58, 153, 221, 0.12), transparent 30%),
        linear-gradient(145deg, var(--fus-phone-bg), var(--fus-phone-bg-soft) 54%, #11161b);
    box-shadow: var(--fus-shadow);
    color: var(--fus-ink);
    font-family: Inter, "SF Pro Display", "Poppins", system-ui, sans-serif;
    overscroll-behavior: contain;
}

.fus-modal * {
    box-sizing: border-box;
}

.fus-header,
.fus-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px;
}

.fus-header {
    position: sticky;
    top: 0;
    z-index: 4;
    min-height: 70px;
    background: linear-gradient(180deg, rgba(5, 6, 7, 0.96), rgba(5, 6, 7, 0.72) 74%, rgba(5, 6, 7, 0));
    backdrop-filter: blur(10px);
}

.fus-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.fus-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.045);
    color: #fff;
}

.fus-title {
    margin: 0;
    color: #fff;
    font-size: clamp(1.05rem, 2vw, 1.32rem);
    font-weight: 850;
    letter-spacing: 0;
    line-height: 1.16;
}

.fus-close,
.fus-cancel,
.fus-copy {
    border: 1px solid var(--fus-line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--fus-ink);
    font: inherit;
    font-weight: 820;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease, color 180ms ease;
}

.fus-close {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
}

.fus-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 16px;
    padding: 0 22px 18px;
    scrollbar-gutter: stable;
}

.fus-intro {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 13px 15px;
    border: 1px solid rgba(41, 196, 106, 0.18);
    border-radius: 18px;
    background: rgba(41, 196, 106, 0.08);
    color: rgba(247, 250, 248, 0.82);
    font-size: .96rem;
    font-weight: 740;
    line-height: 1.48;
}

.fus-intro i {
    margin-top: 2px;
    color: var(--fus-green);
}

.fus-source-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.fus-source {
    min-height: 138px;
    border: 1px solid var(--fus-line);
    border-radius: 22px;
    background: linear-gradient(180deg, var(--fus-panel-strong), rgba(255, 255, 255, 0.03));
    color: var(--fus-ink);
    text-align: left;
    cursor: pointer;
    padding: 15px;
    display: grid;
    align-content: start;
    gap: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 18px 46px rgba(0, 0, 0, 0.18);
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.fus-source.is-active {
    border-color: rgba(41, 196, 106, 0.36);
    background: linear-gradient(180deg, rgba(41, 196, 106, 0.13), rgba(255, 255, 255, 0.035));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 20px 54px rgba(0, 0, 0, 0.24);
}

.fus-source-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--fus-green);
}

.fus-source strong {
    display: block;
    color: #fff;
    font-size: 1rem;
    line-height: 1.24;
}

.fus-source > span:not(.fus-source-icon) {
    color: var(--fus-muted);
    font-size: .9rem;
    font-weight: 720;
    line-height: 1.36;
}

.fus-workspace {
    min-height: 0;
    display: grid;
    gap: 14px;
}

.fus-dropzone,
.fus-reader-shell,
.fus-device-panel {
    border: 1px solid var(--fus-line);
    border-radius: 24px;
    background: linear-gradient(180deg, var(--fus-panel), rgba(255, 255, 255, 0.025));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 22px 58px rgba(0, 0, 0, 0.22);
}

.fus-dropzone {
    min-height: 210px;
    display: grid;
    place-items: center;
    padding: 24px;
    text-align: center;
    color: var(--fus-ink);
    cursor: pointer;
    border-style: dashed;
    transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.fus-dropzone.is-dragover {
    border-color: rgba(41, 196, 106, 0.56);
    background: rgba(41, 196, 106, 0.11);
}

.fus-dropzone i {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto 12px;
    border-radius: 19px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--fus-green);
    font-size: 1.65rem;
}

.fus-dropzone strong {
    display: block;
    color: #fff;
    font-size: 1rem;
    line-height: 1.35;
}

.fus-dropzone span {
    display: block;
    margin-top: 6px;
    color: var(--fus-muted);
    font-size: .9rem;
    font-weight: 720;
}

.fus-reader-shell {
    overflow: hidden;
    padding: 10px;
    background: #050607;
}

.fus-reader {
    min-height: 360px;
    overflow: hidden;
    border-radius: 18px;
    background: #000;
}

.fus-reader video,
.fus-reader canvas {
    max-width: 100%;
    border-radius: 16px;
}

.fus-device-panel {
    padding: 24px;
    text-align: center;
}

.fus-device-qr {
    width: 198px;
    height: 198px;
    display: grid;
    place-items: center;
    margin: 0 auto 16px;
    border: 10px solid #fff;
    border-radius: 26px;
    background: #fff;
    box-shadow: 0 20px 52px rgba(0, 0, 0, 0.22);
}

.fus-device-title {
    margin: 0;
    color: #fff;
    font-size: 1.08rem;
    font-weight: 850;
    line-height: 1.28;
}

.fus-device-copy {
    max-width: 460px;
    margin: 8px auto 0;
    color: var(--fus-muted);
    font-size: .96rem;
    font-weight: 720;
    line-height: 1.5;
}

.fus-link-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin-top: 16px;
}

.fus-link-row input {
    min-width: 0;
    border: 1px solid var(--fus-line);
    border-radius: 16px;
    padding: 12px 14px;
    color: var(--fus-soft);
    background: rgba(0, 0, 0, 0.24);
    font: inherit;
    font-size: .9rem;
}

.fus-copy,
.fus-cancel {
    min-height: 44px;
    padding: 11px 16px;
}

.fus-copy {
    background: rgba(41, 196, 106, 0.12);
    border-color: rgba(41, 196, 106, 0.28);
    color: #dfffe9;
}

.fus-status {
    min-height: 24px;
    color: var(--fus-muted);
    font-size: .92rem;
    font-weight: 740;
    line-height: 1.48;
}

.fus-status.is-error {
    color: var(--fus-danger);
}

.fus-status.is-success {
    color: var(--fus-green);
}

.fus-footer {
    position: sticky;
    bottom: 0;
    justify-content: flex-end;
    border-top: 1px solid var(--fus-line);
    background: linear-gradient(180deg, rgba(5, 6, 7, 0), rgba(5, 6, 7, 0.92) 34%, rgba(5, 6, 7, 0.98));
    backdrop-filter: blur(10px);
}

.fus-hidden {
    display: none !important;
}

@media (hover: hover) and (pointer: fine) {
    .fus-source:hover,
    .fus-close:hover,
    .fus-cancel:hover,
    .fus-copy:hover,
    .fus-dropzone:hover {
        transform: translateY(-2px);
        border-color: rgba(255, 255, 255, 0.18);
        box-shadow: 0 22px 58px rgba(0, 0, 0, 0.28);
    }
}

.fus-source:focus-visible,
.fus-close:focus-visible,
.fus-cancel:focus-visible,
.fus-copy:focus-visible,
.fus-dropzone:focus-visible,
.fus-link-row input:focus {
    outline: none;
    border-color: rgba(41, 196, 106, 0.58);
    box-shadow: 0 12px 26px rgba(41, 196, 106, 0.12);
}

@media (min-width: 1440px) {
    .fus-modal {
        width: min(1040px, 72vw);
    }
}

@media (max-width: 1180px) {
    .fus-modal {
        width: min(900px, calc(100vw - 24px));
        height: min(820px, calc(100dvh - 24px));
    }
}

@media (max-width: 900px) {
    .fus-modal {
        border-radius: 24px;
    }

    .fus-body {
        grid-template-rows: auto auto auto;
    }

    .fus-source-grid {
        grid-template-columns: repeat(3, minmax(176px, 1fr));
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .fus-source-grid::-webkit-scrollbar {
        display: none;
    }

    .fus-source {
        min-height: 126px;
    }
}

@media (max-width: 720px) {
    .fus-overlay {
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
        background: rgba(5, 6, 7, 0.72);
    }

    .fus-modal {
        width: 100vw;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .fus-header {
        min-height: 60px;
        padding: max(10px, env(safe-area-inset-top)) 12px 8px;
    }

    .fus-body {
        gap: 12px;
        padding: 8px 12px 12px;
    }

    .fus-footer {
        padding: 12px 12px max(12px, env(safe-area-inset-bottom));
    }

    .fus-icon,
    .fus-close {
        width: 38px;
        height: 38px;
        border-radius: 13px;
    }

    .fus-title {
        font-size: .98rem;
    }

    .fus-intro {
        padding: 11px 12px;
        border-radius: 16px;
        font-size: .88rem;
    }

    .fus-source-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .fus-source {
        min-width: 0;
        min-height: 112px;
        padding: 11px;
        border-radius: 18px;
    }

    .fus-source-icon {
        width: 36px;
        height: 36px;
        border-radius: 13px;
    }

    .fus-source strong {
        font-size: .88rem;
        overflow-wrap: anywhere;
    }

    .fus-source > span:not(.fus-source-icon) {
        font-size: .78rem;
    }

    .fus-dropzone {
        min-height: 190px;
        padding: 18px;
        border-radius: 20px;
    }

    .fus-reader {
        min-height: min(58dvh, 430px);
    }

    .fus-device-panel {
        padding: 18px 12px;
        border-radius: 20px;
    }

    .fus-device-qr {
        width: min(190px, 66vw);
        height: min(190px, 66vw);
    }

    .fus-link-row {
        grid-template-columns: 1fr;
    }

    .fus-cancel {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 420px) {
    .fus-header {
        gap: 10px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .fus-body,
    .fus-footer {
        padding-left: 10px;
        padding-right: 10px;
    }

    .fus-title-wrap {
        gap: 9px;
    }

    .fus-source {
        min-height: 104px;
        padding: 10px;
        gap: 7px;
    }

    .fus-source > span:not(.fus-source-icon) {
        display: none;
    }

    .fus-dropzone {
        min-height: 170px;
    }
}

@media (max-width: 720px) and (max-height: 760px) {
    .fus-header {
        position: relative;
    }

    .fus-intro {
        display: none;
    }

    .fus-dropzone {
        min-height: 150px;
    }

    .fus-reader {
        min-height: 320px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fus-overlay *,
    .fus-overlay *::before,
    .fus-overlay *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
