/**
 * WooCommerce NIP Validator - Styles
 * Style dla formularza rejestracji i elementów walidacji
 * Kompatybilne z User Registration i WooCommerce
 * Wersja z rozwiązaniem problemu autofill
 */

/* ========================================
   ROZWIĄZANIE PROBLEMU AUTOFILL
   ======================================== */

/* Style dla pól z autofill PRZEGLĄDARKI (nie wtyczki) */
input:-webkit-autofill:not(.wnv-autofilled),
input:-webkit-autofill:hover:not(.wnv-autofilled),
input:-webkit-autofill:focus:not(.wnv-autofilled),
input:-webkit-autofill:active:not(.wnv-autofilled),
.ur-frontend-form input:-webkit-autofill:not(.wnv-autofilled),
.user-registration-form input:-webkit-autofill:not(.wnv-autofilled) {
    /* Domyślnie białe litery dla ciemnego tła (macOS Dark Mode) */
    -webkit-text-fill-color: #FFFFFF !important;
    color: #FFFFFF !important;
    font-weight: 600 !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8) !important;
}

/* Wykrywanie jasnego trybu - czarne litery */
@media (prefers-color-scheme: light) {
    input:-webkit-autofill:not(.wnv-autofilled),
    input:-webkit-autofill:hover:not(.wnv-autofilled),
    input:-webkit-autofill:focus:not(.wnv-autofilled),
    input:-webkit-autofill:active:not(.wnv-autofilled) {
        -webkit-text-fill-color: #000000 !important;
        color: #000000 !important;
        font-weight: 700 !important;
        text-shadow: none !important;
    }
}

/* Windows/Chrome - specyficzne style */
@supports (-webkit-appearance:none) and (not (-moz-appearance:none)) {
    input:-webkit-autofill:not(.wnv-autofilled) {
        -webkit-text-fill-color: #000000 !important;
        color: #000000 !important;
        font-weight: 600 !important;
    }
}

/* Pola wypełnione przez WTYCZKĘ NIP - zawsze czytelne */
input.wnv-autofilled,
input.wnv-processed,
.ur-frontend-form input.wnv-autofilled,
.user-registration-form input.wnv-autofilled {
    /* Wymuszenie jasnego tła */
    -webkit-box-shadow: 0 0 0 1000px #f0f8ff inset !important;
    box-shadow: 0 0 0 1000px #f0f8ff inset !important;
    background-color: #f0f8ff !important;
    
    /* Ciemny tekst */
    -webkit-text-fill-color: #1f1f1f !important;
    color: #1f1f1f !important;
    font-weight: normal !important;
    text-shadow: none !important;
    
    /* Transition dla efektu */
    transition: all 0.3s ease;
}

/* ========================================
   ORYGINALNE STYLE WTYCZKI
   ======================================== */

/* Kontener pola NIP - WooCommerce */
.wnv-nip-field {
    position: relative;
}

.wnv-nip-field input {
    padding-right: 40px;
}

/* User Registration - Kontener pola NIP */
.ur-frontend-field.wnv-nip-field {
    position: relative;
    margin-bottom: 1em;
}

.ur-frontend-field.wnv-nip-field .ur-frontend-input {
    position: relative;
}

.ur-frontend-field.wnv-nip-field input {
    width: 100%;
    padding-right: 40px;
}

/* Spinner ładowania */
.wnv-spinner {
    position: absolute;
    right: 12px;
    top: 36px;
    width: 20px;
    height: 20px;
    display: none;
    z-index: 10;
}

/* User Registration - Spinner pozycjonowanie */
.ur-frontend-field .wnv-spinner {
    top: 12px;
    right: 12px;
}

.wnv-spinner:after {
    content: " ";
    display: block;
    width: 16px;
    height: 16px;
    margin: 2px;
    border-radius: 50%;
    border: 2px solid #ddd;
    border-color: #333 transparent #333 transparent;
    animation: wnv-spinner-animation 1.2s linear infinite;
}

@keyframes wnv-spinner-animation {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Komunikaty */
.wnv-message {
    display: none;
    margin-top: 5px;
    padding: 8px 12px;
    border-radius: 3px;
    font-size: 13px;
    line-height: 1.5;
    clear: both;
    width: 100%;
    box-sizing: border-box;
}

/* User Registration - Komunikaty */
.ur-frontend-field .wnv-message {
    margin-top: 5px;
    margin-bottom: 0;
}

.wnv-message.wnv-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.wnv-message.wnv-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.wnv-message .dashicons {
    font-size: 16px;
    line-height: 1;
    vertical-align: middle;
    margin-right: 5px;
}

/* Podświetlenie automatycznie uzupełnionych pól przez wtyczkę */
.wnv-highlight {
    animation: wnv-highlight-pulse 0.5s ease-in-out;
    border-color: #28a745 !important;
    box-shadow: 0 0 5px rgba(40, 167, 69, 0.3);
}

@keyframes wnv-highlight-pulse {
    0% {
        box-shadow: 0 0 0 rgba(40, 167, 69, 0);
    }
    50% {
        box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
    }
    100% {
        box-shadow: 0 0 5px rgba(40, 167, 69, 0.3);
    }
}

/* Style dla pól formularza - kompatybilność z różnymi motywami */
.woocommerce-form-register .form-row {
    margin-bottom: 1em;
}

.woocommerce-form-register .form-row label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.woocommerce-form-register .form-row .required {
    color: #e2401c;
    font-weight: 700;
}

/* User Registration - Style pól */
.ur-frontend-field label .required {
    color: #e2401c;
    font-weight: 700;
}

.ur-frontend-field input.wnv-autofill-target:focus {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

/* Responsywność */
@media (max-width: 768px) {
    .wnv-spinner {
        top: 32px;
        right: 10px;
    }
    
    .ur-frontend-field .wnv-spinner {
        top: 10px;
        right: 10px;
    }
    
    .form-row-first,
    .form-row-last {
        width: 100%;
        float: none;
        margin-right: 0;
    }
    
    /* User Registration responsive */
    .ur-frontend-field .ur-frontend-input {
        width: 100%;
    }
}

/* Dodatkowe style dla lepszej integracji z popularnymi motywami */

/* Storefront */
.storefront .wnv-message {
    font-family: inherit;
}

.storefront .ur-frontend-field .wnv-message {
    font-family: inherit;
    font-size: 14px;
}

/* Flatsome */
.flatsome .wnv-nip-field input,
.flatsome .ur-frontend-field input {
    height: auto;
}

/* Astra */
.astra .wnv-message {
    margin-bottom: 10px;
}

/* OceanWP */
.oceanwp-theme .wnv-nip-field,
.oceanwp-theme .ur-frontend-field.wnv-nip-field {
    margin-bottom: 20px;
}

/* Divi */
.et_divi_theme .wnv-message {
    font-size: 14px;
    line-height: 1.4;
}

/* Avada */
.avada-version .ur-frontend-field {
    margin-bottom: 15px;
}

/* Style dla ciemnych motywów - ZAKTUALIZOWANE */
@media (prefers-color-scheme: dark) {
    /* Zachowaj białe litery dla autofill przeglądarki */
    input:-webkit-autofill:not(.wnv-autofilled) {
        -webkit-text-fill-color: #FFFFFF !important;
    }
    
    /* Ale pola wypełnione przez wtyczkę mają jasne tło i ciemny tekst */
    input.wnv-autofilled,
    input.wnv-processed {
        -webkit-box-shadow: 0 0 0 1000px #f0f8ff inset !important;
        -webkit-text-fill-color: #1f1f1f !important;
    }
    
    .wnv-spinner:after {
        border-color: #fff transparent #fff transparent;
    }
    
    .wnv-message.wnv-error {
        background-color: #5a2a2a;
        color: #ffcccc;
        border-color: #8a4444;
    }
    
    .wnv-message.wnv-success {
        background-color: #2a4a2a;
        color: #ccffcc;
        border-color: #448844;
    }
}

/* Animacja pojawiania się komunikatów */
.wnv-message {
    animation: wnv-fade-in 0.3s ease-in;
}

@keyframes wnv-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tooltip dla pola NIP */
.wnv-nip-field input:focus + .wnv-spinner + .wnv-message:empty:before,
.ur-frontend-field input[name="billing_nip"]:focus + .wnv-spinner + .wnv-message:empty:before {
    content: "Wprowadź 10-cyfrowy numer NIP";
    display: block;
    position: absolute;
    top: -30px;
    left: 0;
    background: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    animation: wnv-tooltip-show 0.3s ease-in 0.5s forwards;
    z-index: 1000;
}

@keyframes wnv-tooltip-show {
    to {
        opacity: 0.9;
    }
}

/* Kompatybilność z WooCommerce Blocks */
.wp-block-woocommerce-checkout .wnv-nip-field {
    margin: 1em 0;
}

/* User Registration - specyficzne style dla różnych typów pól */
.ur-frontend-field.ur-frontend-text .ur-frontend-input,
.ur-frontend-field.ur-frontend-email .ur-frontend-input {
    position: relative;
}

/* Style dla trybu wysokiego kontrastu */
@media (prefers-contrast: high) {
    /* Zawsze czarne litery na białym tle dla autofill przeglądarki w trybie wysokiego kontrastu */
    input:-webkit-autofill:not(.wnv-autofilled) {
        -webkit-box-shadow: 0 0 0 1000px white inset !important;
        -webkit-text-fill-color: #000000 !important;
        color: #000000 !important;
        font-weight: 900 !important;
    }
    
    .wnv-message.wnv-error {
        background-color: #fff;
        color: #d00;
        border: 2px solid #d00;
    }
    
    .wnv-message.wnv-success {
        background-color: #fff;
        color: #008000;
        border: 2px solid #008000;
    }
    
    .wnv-highlight {
        border: 3px solid #28a745 !important;
        box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
    }
}

/* Style dla formularzy User Registration - dodatkowe klasyfikacje */
.user-registration-form .ur-frontend-field {
    margin-bottom: 1.2em;
}

.user-registration-form .ur-frontend-field.wnv-nip-field .ur-frontend-label {
    margin-bottom: 8px;
}

/* Loading state dla całego formularza */
.wnv-form-loading {
    opacity: 0.7;
    pointer-events: none;
}

.wnv-form-loading .wnv-spinner {
    display: block !important;
}

/* Animacje sukcesu dla uzupełnionych pól */
.wnv-success-fill {
    animation: wnv-success-fill 0.6s ease-in-out;
}

@keyframes wnv-success-fill {
    0% {
        background-color: transparent;
        transform: scale(1);
    }
    50% {
        background-color: #e8f5e8;
        transform: scale(1.02);
    }
    100% {
        background-color: #f0f8ff;
        transform: scale(1);
    }
}

/* Error states dla pól */
.wnv-field-error {
    border-color: #dc3232 !important;
    box-shadow: 0 0 5px rgba(220, 50, 50, 0.3);
}

.wnv-field-error:focus {
    border-color: #dc3232 !important;
    box-shadow: 0 0 8px rgba(220, 50, 50, 0.4);
}

/* Print styles */
@media print {
    .wnv-spinner,
    .wnv-message {
        display: none !important;
    }
}

/* ========================================
   DODATKOWE STYLE DLA EDGE CASES
   ======================================== */

/* Safari na macOS - specjalne traktowanie */
@supports (-webkit-backdrop-filter: none) and (not (-webkit-touch-callout: default)) {
    input:-webkit-autofill:not(.wnv-autofilled) {
        -webkit-text-fill-color: #FFFFFF !important;
        font-weight: 700 !important;
    }
}

/* Firefox - fallback (nie obsługuje -webkit-autofill ale dla kompletności) */
@-moz-document url-prefix() {
    input:autofill:not(.wnv-autofilled) {
        background-color: transparent !important;
        color: inherit !important;
    }
}