/**
 * WePresta VAT Preview - Front-office Styles
 * 
 * @author    WePresta <mail@wepresta.shop>
 * @copyright Since 2024 WePresta
 * @license   AFL-3.0
 */

/* =========================================================================
   CSS VARIABLES - Customizable theme colors
   ========================================================================= */

:root {
    --wepresta-primary: #25b9d7;
    --wepresta-primary-rgb: 37, 185, 215;
    --wepresta-text: #333;
    --wepresta-text-muted: #666;
    --wepresta-border: #ddd;
    --wepresta-bg-light: #f8f9fa;
    --wepresta-bg-hover: #e9ecef;
    --wepresta-radius: 4px;
    --wepresta-font-size: 13px;
    --wepresta-success: #28a745;
    --wepresta-warning: #ffc107;
    --wepresta-info-bg: linear-gradient(135deg, #e8f4f8 0%, #d4edfa 100%);
}

/* =========================================================================
   COUNTRY SELECTOR
   ========================================================================= */

.wepresta-vat-selector {
    display: inline-flex;
    align-items: center;
    font-size: var(--wepresta-font-size, 13px);
    font-family: inherit;
}

.vat-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vat-selector-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--wepresta-text-muted);
    margin: 0;
    font-weight: 500;
}

.vat-selector-label .wepresta-icon {
    width: 16px;
    height: 16px;
}

.vat-selector-label .label-text {
    display: none;
}

@media (min-width: 768px) {
    .vat-selector-label .label-text {
        display: inline;
    }
}

.vat-selector-dropdown {
    display: flex;
    align-items: center;
    gap: 4px;
}

.vat-country-select {
    padding: 6px 10px;
    border: 1px solid var(--wepresta-border);
    border-radius: var(--wepresta-radius, 4px);
    background: var(--wepresta-bg-light, #fff);
    color: var(--wepresta-text, #333);
    font-size: var(--wepresta-font-size, 13px);
    cursor: pointer;
    min-width: 150px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.vat-country-select:hover {
    border-color: var(--wepresta-primary);
}

.vat-country-select:focus {
    outline: none;
    border-color: var(--wepresta-primary);
    box-shadow: 0 0 0 3px rgba(var(--wepresta-primary-rgb), 0.15);
}

.vat-delivery-text {
    padding: 6px 10px;
    font-size: var(--wepresta-font-size, 13px);
    color: var(--wepresta-text);
}

/* (removed) legacy reset/source UI */

/* =========================================================================
   CUSTOM INLINE / MODAL WIDGET (template system)
   ========================================================================= */

.wepresta-vat-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--wepresta-border);
    border-radius: var(--wepresta-radius, 4px);
    background: var(--wepresta-bg-light, #fff);
    color: var(--wepresta-text, #333);
    font-size: var(--wepresta-font-size, 13px);
    cursor: pointer;
    line-height: 1.2;
}

.wepresta-vat-trigger:hover {
    border-color: var(--wepresta-primary);
}

.wepresta-vat-trigger:focus {
    outline: none;
    border-color: var(--wepresta-primary);
    box-shadow: 0 0 0 3px rgba(var(--wepresta-primary-rgb), 0.15);
}

.wepresta-vat-caret {
    color: var(--wepresta-text-muted);
    font-size: 11px;
}

.wepresta-vat-dropdown {
    position: fixed;
    z-index: 999999;
    min-width: 240px;
    max-width: 360px;
    max-height: 320px;
    overflow: auto;
    background: #fff;
    border: 1px solid var(--wepresta-border);
    border-radius: calc(var(--wepresta-radius, 4px) + 2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.wepresta-vat-list {
    list-style: none;
    margin: 0;
    padding: 6px;
}

.wepresta-vat-option {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border: 0;
    border-radius: calc(var(--wepresta-radius, 4px) + 2px);
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-size: var(--wepresta-list-font-size, var(--wepresta-font-size, 13px));
    color: var(--wepresta-text, #333);
}

.wepresta-vat-option:hover,
.wepresta-vat-option:focus {
    background: var(--wepresta-bg-hover);
    outline: none;
}

.wepresta-vat-option-right {
    color: var(--wepresta-primary);
    font-weight: 700;
    white-space: nowrap;
}

.wepresta-vat-inline-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.wepresta-vat-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.wepresta-vat-modal {
    width: min(720px, 100%);
    max-height: min(80vh, 720px);
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--wepresta-border);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.wepresta-vat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--wepresta-border);
}

.wepresta-vat-modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--wepresta-text, #333);
}

.wepresta-vat-modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--wepresta-border);
    border-radius: 10px;
    background: var(--wepresta-bg-light, #fff);
    cursor: pointer;
    color: var(--wepresta-text-muted, #666);
}

.wepresta-vat-modal-close:hover {
    border-color: var(--wepresta-primary);
    color: var(--wepresta-primary);
}

.wepresta-vat-modal-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--wepresta-border);
}

.wepresta-vat-modal-body {
    padding: 12px 12px 14px 12px;
    overflow: auto;
}

.wepresta-vat-modal-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

@media (max-width: 576px) {
    .wepresta-vat-modal-grid {
        grid-template-columns: 1fr;
    }
}

.vat-source-badge--manual {
    background: rgba(var(--wepresta-primary-rgb), 0.1);
    color: var(--wepresta-primary);
}

.vat-source-badge--auto {
    background: #e9ecef;
    color: #6c757d;
}

.vat-source-badge--default {
    background: #f8f9fa;
    color: #999;
}

.vat-source-badge .wepresta-icon {
    width: 12px;
    height: 12px;
}

.wepresta-vat-selector.loading {
    opacity: 0.6;
    pointer-events: none;
}

.wepresta-vat-selector.loading .vat-country-select {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2325b9d7"><path d="M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8Z"><animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="1s" repeatCount="indefinite"/></path></svg>');
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    padding-right: 32px;
}

/* =========================================================================
   DISCLAIMER
   ========================================================================= */

.wepresta-vat-disclaimer {
    position: relative;
    margin: 15px 0;
    padding: 12px 40px 12px 15px;
    background: var(--wepresta-info-bg);
    border-left: 4px solid var(--wepresta-primary);
    border-radius: 4px;
    font-size: 13px;
    color: var(--wepresta-text);
    animation: weprestaSlideIn 0.3s ease-out;
}

.disclaimer-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.disclaimer-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--wepresta-primary);
}

.disclaimer-text {
    line-height: 1.5;
    flex: 1;
}

.disclaimer-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #999;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.disclaimer-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #666;
}

.disclaimer-close .wepresta-icon {
    width: 14px;
    height: 14px;
}

/* Dark theme variant */
.wepresta-vat-disclaimer.wepresta-vat-disclaimer--dark {
    background: linear-gradient(135deg, #2d3e50 0%, #1e2f40 100%);
    border-left-color: #3498db;
    color: #ecf0f1;
}

.wepresta-vat-disclaimer--dark .disclaimer-icon {
    color: #3498db;
}

/* Compact variant for product pages */
.wepresta-vat-disclaimer.wepresta-vat-disclaimer--compact {
    padding: 8px 32px 8px 12px;
    margin: 10px 0;
    font-size: 12px;
}

.wepresta-vat-disclaimer--compact .disclaimer-icon {
    width: 16px;
    height: 16px;
}

@keyframes weprestaSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes weprestaSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.wepresta-vat-disclaimer.hiding {
    animation: weprestaSlideOut 0.2s ease-out forwards;
}

/* =========================================================================
   TOAST NOTIFICATIONS
   ========================================================================= */

.wepresta-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.wepresta-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    color: var(--wepresta-text);
    pointer-events: auto;
    animation: weprestaToastIn 0.3s ease-out;
    max-width: 320px;
}

.wepresta-toast.hiding {
    animation: weprestaToastOut 0.2s ease-out forwards;
}

.wepresta-toast--success {
    border-left: 4px solid var(--wepresta-success);
}

.wepresta-toast--success .wepresta-toast-icon {
    color: var(--wepresta-success);
}

.wepresta-toast--error {
    border-left: 4px solid #dc3545;
}

.wepresta-toast--error .wepresta-toast-icon {
    color: #dc3545;
}

.wepresta-toast--info {
    border-left: 4px solid var(--wepresta-primary);
}

.wepresta-toast--info .wepresta-toast-icon {
    color: var(--wepresta-primary);
}

.wepresta-toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.wepresta-toast-message {
    flex: 1;
    line-height: 1.4;
}

@keyframes weprestaToastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes weprestaToastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* =========================================================================
   CHECKOUT WARNING
   ========================================================================= */

.wepresta-checkout-warning {
    animation: shakeX 0.5s ease-out;
}

@keyframes shakeX {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* =========================================================================
   ADDRESS COUNTRY MESSAGE (CHECKOUT / ADDRESS FORMS)
   ========================================================================= */

.wepresta-vat-address-country-message {
    margin-top: 6px;
    color: #6c757d;
    line-height: 1.3;
}

.wepresta-vat-address-country-message--info {
    color: #0c5460;
}

.wepresta-vat-address-country-message--warning {
    color: #856404;
}

select.wepresta-vat-country-locked {
    opacity: 0.8;
    cursor: not-allowed !important;
}

/* =========================================================================
   CHECKOUT NOTICE
   ========================================================================= */

.vatpreview-checkout-notice {
    margin: 15px 0;
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

@media (max-width: 576px) {
    .wepresta-vat-selector {
        width: 100%;
    }
    
    .vat-selector-wrapper {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .vat-country-select {
        min-width: unset;
        flex: 1;
    }
    
    .wepresta-vat-disclaimer {
        font-size: 12px;
        padding: 10px;
    }
    
    .wepresta-checkout-warning {
        font-size: 13px;
    }
}

/* =========================================================================
   ACCESSIBILITY - Screen reader only
   ========================================================================= */

.sr-only,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* =========================================================================
   FOCUS VISIBLE - Keyboard navigation
   ========================================================================= */

.vat-country-select:focus-visible,
.disclaimer-close:focus-visible {
    outline: 2px solid var(--wepresta-primary);
    outline-offset: 2px;
}

/* =========================================================================
   PRINT STYLES
   ========================================================================= */

@media print {
    .wepresta-vat-selector,
    .wepresta-vat-disclaimer,
    .wepresta-checkout-warning,
    .wepresta-toast-container {
        display: none !important;
    }
}

/* =========================================================================
   HIGH CONTRAST MODE
   ========================================================================= */

@media (prefers-contrast: high) {
    .wepresta-vat-disclaimer {
        border-left-width: 6px;
    }
    
    .vat-country-select {
        border-width: 2px;
    }
}


/* =========================================================================
   COUNTRY + LANGUAGE PANEL (template "country_language")
   Desktop: full-width sheet under the header + dark overlay (Thomann style)
   Mobile:  full-width sheet from the top + "Back" link
   ========================================================================= */

.wepresta-cl {
    position: relative;
}

.wepresta-cl-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px;
    border: 0;
    background: transparent;
    color: var(--wepresta-text, #000);
    font-size: var(--wepresta-font-size, 13px);
    font-weight: 600;
    line-height: 1.2;
    text-transform: uppercase;
    cursor: pointer;
    white-space: nowrap;
}

.wepresta-cl-trigger:hover .wepresta-cl-trigger-text,
.wepresta-cl-trigger:focus-visible .wepresta-cl-trigger-text {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.wepresta-cl-trigger:focus-visible {
    outline: 2px solid var(--wepresta-primary);
    outline-offset: 2px;
}

/* Round country flag with dark border (same look as the djmania language selector) */
.wepresta-cl-flag-round {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border: 2px solid currentColor;
    border-radius: 50%;
    overflow: hidden;
    box-sizing: border-box;
    background: #fff;
}

.wepresta-cl-flag-round img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wepresta-cl-flag-iso {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

.wepresta-cl-caret {
    width: 7px;
    height: 7px;
    margin-left: 2px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.15s ease;
}

.wepresta-cl-trigger[aria-expanded="true"] .wepresta-cl-caret {
    transform: rotate(-135deg) translateY(-2px);
}

.wepresta-cl.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ---- sheet ---- */

.wepresta-cl-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 999998;
    background: rgba(0, 0, 0, 0.6);
}

.wepresta-cl-panel {
    position: fixed;
    z-index: 999999;
    left: 0;
    right: 0;
    top: 0;
    box-sizing: border-box;
    max-height: 100vh;
    overflow-y: auto;
    padding: 28px 16px 32px;
    background: #fff;
    color: var(--wepresta-text, #000);
    border-bottom: 4px solid var(--wepresta-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    font-size: var(--wepresta-font-size, 14px);
    text-align: left;
}

.wepresta-cl-panel[hidden],
.wepresta-cl-overlay[hidden] {
    display: none !important;
}

.wepresta-cl-inner {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
}

/* Desktop "modal" mode (Display > Desktop mode = Modal) */
.wepresta-cl-panel.is-modal {
    top: 50%;
    left: 50%;
    right: auto;
    width: 440px;
    max-width: calc(100vw - 32px);
    transform: translate(-50%, -50%);
    border-radius: calc(var(--wepresta-radius, 4px) + 4px);
}

.wepresta-cl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 22px;
}

.wepresta-cl-title {
    font-size: 16px;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
    text-decoration-color: var(--wepresta-primary);
}

.wepresta-cl-close {
    display: none;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--wepresta-text-muted, #666);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.wepresta-cl-panel.is-modal .wepresta-cl-close {
    display: block;
}

.wepresta-cl-back {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0 0 18px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--wepresta-text, #000);
    font-size: 14px;
    cursor: pointer;
}

.wepresta-cl-back::before {
    content: "";
    width: 7px;
    height: 7px;
    border-left: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
}

.wepresta-cl-panel.is-mobile .wepresta-cl-back {
    display: inline-flex;
}

.wepresta-cl-panel.is-mobile {
    padding-top: 20px;
}

html.wepresta-cl-open body {
    overflow: hidden;
}

/* ---- fields ---- */

.wepresta-cl-field {
    position: relative;
    margin-bottom: 18px;
}

.wepresta-cl-field label {
    position: absolute;
    top: -8px;
    left: 10px;
    z-index: 1;
    margin: 0;
    padding: 0 4px;
    background: #fff;
    color: var(--wepresta-text, #000);
    font-size: 11px;
    font-weight: 400;
    line-height: 16px;
}

.wepresta-cl-select-wrap {
    position: relative;
}

.wepresta-cl-select-wrap::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--wepresta-text, #000);
    border-bottom: 2px solid var(--wepresta-text, #000);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

/* Flag inside the country select (like Thomann) */
.wepresta-cl-select-flag {
    position: absolute;
    top: 50%;
    left: 12px;
    z-index: 1;
    width: 24px;
    height: 18px;
    object-fit: cover;
    transform: translateY(-50%);
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

.wepresta-cl-select-flag[hidden] {
    display: none !important;
}

.wepresta-cl-select-flag:not([hidden]) + .wepresta-cl-select {
    padding-left: 46px;
}

.wepresta-cl-select {
    display: block;
    width: 100%;
    height: 46px;
    margin: 0;
    padding: 8px 36px 8px 12px;
    border: 1px solid #8a8a8a;
    border-radius: var(--wepresta-radius, 4px);
    background: #fff;
    color: var(--wepresta-text, #000);
    font-size: 15px;
    font-family: inherit;
    box-shadow: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
}

.wepresta-cl-select:hover {
    border-color: var(--wepresta-text, #000);
}

.wepresta-cl-select:focus {
    outline: none;
    border-color: var(--wepresta-primary);
    box-shadow: 0 0 0 1px var(--wepresta-primary);
}

.wepresta-cl-save {
    display: block;
    width: 100%;
    margin: 6px 0 0;
    padding: 12px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--wepresta-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.wepresta-cl-save:hover {
    filter: brightness(0.92);
}

.wepresta-cl-save:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ---- menu-row variant (hook displayWeprestaOssMobile) ---- */

.wepresta-cl--row {
    display: block;
    width: 100%;
}

.wepresta-cl--row .wepresta-cl-trigger {
    display: flex;
    width: 100%;
    padding: 12px 0;
    justify-content: flex-start;
}

.wepresta-cl--row .wepresta-cl-flag-round {
    width: 26px;
    height: 26px;
}

.wepresta-cl--row .wepresta-cl-trigger-text {
    text-transform: none;
}

.wepresta-cl--row .wepresta-cl-chevron {
    width: 8px;
    height: 8px;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
}

/* Mobile: when the menu-row placement exists, use only that one (hide the header trigger) */
@media (max-width: 767px) {
    /* JS-added class (all browsers) */
    html.wepresta-cl-has-row .wepresta-cl--header {
        display: none !important;
    }
}

@media (max-width: 767px) {
    /* Same rule without waiting for JS (no flash); separate block so older browsers
       that do not know :has() still apply the rule above. */
    body:has(.wepresta-cl--row) .wepresta-cl--header {
        display: none !important;
    }
}
