/**
 * Frontend Security Styles
 * Proteções visuais e anti-tampering
 */

/* 🚫 PROTEÇÃO ANTI-SELEÇÃO EM PRODUÇÃO */
body:not(.localhost) {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ✅ PERMITIR SELEÇÃO EM INPUTS */
body:not(.localhost) input,
body:not(.localhost) textarea,
body:not(.localhost) select,
body:not(.localhost) [contenteditable] {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* 🔒 PROTEÇÃO ANTI-DRAG */
body:not(.localhost) img,
body:not(.localhost) video,
body:not(.localhost) audio {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* ✅ PERMITIR INTERAÇÃO EM ELEMENTOS NECESSÁRIOS */
body:not(.localhost) a,
body:not(.localhost) button,
body:not(.localhost) input,
body:not(.localhost) textarea,
body:not(.localhost) select,
body:not(.localhost) [role="button"],
body:not(.localhost) .interactive {
    pointer-events: auto !important;
}

/* 🛡️ PROTEÇÃO CONTRA OVERLAY MALICIOSO */
html::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: -1;
    pointer-events: none;
}

/* 🚫 ESCONDER ELEMENTOS SUSPEITOS */
script[src*="eval"],
script[src*="inject"],
iframe[src*="javascript:"],
object[data*="javascript:"],
embed[src*="javascript:"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
}

/* 🔍 HIGHLIGHT DE ELEMENTOS INJETADOS (DEV) */
.localhost script:not([data-eretz-safe]),
.localhost iframe:not([data-eretz-safe]) {
    outline: 2px solid red !important;
    outline-offset: 2px;
}

.localhost script:not([data-eretz-safe])::before,
.localhost iframe:not([data-eretz-safe])::before {
    content: "⚠️ UNSAFE ELEMENT";
    position: absolute;
    background: red;
    color: white;
    padding: 2px 5px;
    font-size: 10px;
    z-index: 9999;
}

/* 🔒 PROTEÇÃO VISUAL FORMS */
form {
    position: relative;
}

form::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: -1;
}

/* 🚫 PROTEÇÃO ANTI-PRINT (OPCIONAL) */
@media print {
    body:not(.localhost) {
        display: none !important;
    }
    
    body:not(.localhost)::before {
        content: "Impressão não autorizada - eretz.bio";
        display: block !important;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 24px;
        font-weight: bold;
        color: red;
    }
}

/* 🛡️ PROTEÇÃO VISUAL CONTRA CLICKJACKING */
body {
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.security-loaded {
    opacity: 1;
}

/* Se não carregar JS em 3s, mostrar mesmo assim */
body {
    animation: fallback-show 3s forwards;
}

@keyframes fallback-show {
    0% { opacity: 0; }
    99% { opacity: 0; }
    100% { opacity: 1; }
}

/* 🔍 PROTEÇÃO DEVTOOLS VISUAL */
.devtools-warning {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff0000;
    color: white;
    text-align: center;
    padding: 10px;
    z-index: 999999;
    font-weight: bold;
    display: none;
}

body.devtools-open .devtools-warning {
    display: block;
}

/* 🚫 PROTEÇÃO CONTRA EXTENSÕES MALICIOSAS */
[data-extension-id],
[data-extension],
.extension-injected {
    display: none !important;
}

/* 🔒 PROTEÇÃO VISUAL INPUTS IMPORTANTES */
input[type="password"],
input[name*="email"],
input[name*="user"],
input[name*="login"] {
    background-image: linear-gradient(45deg, transparent 40%, rgba(0,255,0,0.1) 50%, transparent 60%);
    background-size: 10px 10px;
    animation: security-sweep 2s infinite linear;
}

@keyframes security-sweep {
    0% { background-position: 0 0; }
    100% { background-position: 20px 20px; }
}

/* 🛡️ WATERMARK DE SEGURANÇA (SUTIL) */
body::after {
    content: "";
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 20px;
    height: 20px;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="green" stroke-width="1"><path d="M9 12l2 2 4-4"/><circle cx="12" cy="12" r="9"/></svg>') no-repeat center;
    background-size: contain;
    opacity: 0.3;
    z-index: 1;
    pointer-events: none;
}

/* 📱 RESPONSIVE SECURITY */
@media (max-width: 768px) {
    body:not(.localhost) {
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
}

/* 🎨 TEMA ESCURO - PROTEÇÃO */
@media (prefers-color-scheme: dark) {
    .devtools-warning {
        background: #cc0000;
    }
}
