/**
 * Additional Terms for WooCommerce - Frontend Styles
 * Version: 2.2.0
 */

/* ==========================================================================
   Terms Wrapper and Container
   ========================================================================== */

.atfw-terms-wrapper {
    margin: 20px 0;
    clear: both;
}

.atfw-terms-separator {
    margin: 15px 0;
    height: 1px;
    background: linear-gradient(to right, transparent, #e2e4e7 15%, #e2e4e7 85%, transparent);
}

.atfw-checkout-terms {
    animation: atfwFadeIn 0.3s ease-in;
}

@keyframes atfwFadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Terms Items and Checkboxes
   ========================================================================== */

.atfw-terms-item {
    margin-bottom: 15px;
    padding: 15px;
    background: #f9f9f9;
    border: 1px solid #e2e4e7;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.atfw-terms-item:hover {
    background: #fff;
    border-color: #ccd0d4;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.atfw-terms-item[data-required="true"] {
    border-left: 3px solid #007cba;
    padding-left: 13px;
}

.atfw-checkbox-row {
    margin: 0 !important;
}

.atfw-checkbox-row label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    line-height: 1.5;
}

.atfw-checkbox-row input[type="checkbox"] {
    margin: 3px 10px 0 0 !important;
    flex-shrink: 0;
}

.atfw-label-text {
    flex: 1;
    color: #50575e;
}

.atfw-required {
    color: #d63638;
    font-weight: 700;
    margin-left: 5px;
}

/* ==========================================================================
   Terms Links
   ========================================================================== */

.atfw-terms-link {
    color: #007cba;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.atfw-terms-link:hover {
    color: #005a87;
    text-decoration: none;
}

.atfw-terms-link:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
    text-decoration: none;
}

.atfw-external-link::after {
    content: " ↗";
    font-size: 0.85em;
    vertical-align: super;
}

/* ==========================================================================
   Embedded Content
   ========================================================================== */

.atfw-embedded-content {
    margin: 15px 0;
    padding: 20px;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease-in-out, padding 0.3s ease;
}

.atfw-embedded-content.active,
.atfw-terms-item[data-auto-show="true"] .atfw-embedded-content {
    max-height: 1000px;
    padding: 20px;
}

.atfw-content-inner {
    font-size: 14px;
    line-height: 1.6;
    color: #50575e;
}

.atfw-content-inner h1,
.atfw-content-inner h2,
.atfw-content-inner h3,
.atfw-content-inner h4,
.atfw-content-inner h5,
.atfw-content-inner h6 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #1d2327;
}

.atfw-content-inner p {
    margin-bottom: 15px;
}

.atfw-content-inner ul,
.atfw-content-inner ol {
    margin: 0 0 15px 20px;
    padding-left: 20px;
}

/* ==========================================================================
   Modal Dialog
   ========================================================================== */

.atfw-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: atfwModalFadeIn 0.3s ease-out;
}

@keyframes atfwModalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.atfw-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.atfw-modal-wrapper {
    position: relative;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    margin: 0 auto;
    animation: atfwModalSlideIn 0.3s ease-out;
}

@keyframes atfwModalSlideIn {
    from { transform: translateY(-20px) scale(0.95); }
    to { transform: translateY(0) scale(1); }
}

.atfw-modal-content {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.atfw-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: linear-gradient(135deg, #007cba15 0%, #007cba05 100%);
    border-bottom: 1px solid #e2e4e7;
}

.atfw-modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #1d2327;
}

.atfw-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: #787c82;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.atfw-modal-close:hover {
    background: #f0f0f1;
    color: #1d2327;
}

.atfw-modal-close:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.atfw-modal-body {
    padding: 25px;
    max-height: calc(90vh - 140px);
    overflow-y: auto;
    position: relative;
}

/* Custom scrollbar for modal */
.atfw-modal-body::-webkit-scrollbar {
    width: 8px;
}

.atfw-modal-body::-webkit-scrollbar-track {
    background: #f0f0f1;
}

.atfw-modal-body::-webkit-scrollbar-thumb {
    background: #a7aaad;
    border-radius: 4px;
}

.atfw-modal-body::-webkit-scrollbar-thumb:hover {
    background: #787c82;
}

/* ==========================================================================
   Loading States
   ========================================================================== */

.atfw-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    min-height: 200px;
}

.atfw-modal-loading.hidden {
    display: none;
}

.atfw-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f1;
    border-top: 4px solid #007cba;
    border-radius: 50%;
    animation: atfwSpin 1s linear infinite;
}

@keyframes atfwSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.atfw-modal-loading p {
    margin-top: 15px;
    color: #787c82;
    font-size: 14px;
}

/* ==========================================================================
   Validation and Errors
   ========================================================================== */

.atfw-terms-item.atfw-error {
    border-color: #d63638;
    background: #fef5f5;
    animation: atfwShake 0.5s ease-in-out;
}

@keyframes atfwShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
    20%, 40%, 60%, 80% { transform: translateX(3px); }
}

.atfw-terms-item.atfw-error .atfw-label-text {
    color: #d63638;
}

.atfw-error-message {
    display: none;
    margin-top: 10px;
    padding: 10px;
    background: #d63638;
    color: #fff;
    border-radius: 4px;
    font-size: 14px;
}

.atfw-terms-item.atfw-error .atfw-error-message {
    display: block;
    animation: atfwSlideDown 0.3s ease-out;
}

@keyframes atfwSlideDown {
    from { 
        opacity: 0; 
        transform: translateY(-10px);
        max-height: 0;
    }
    to { 
        opacity: 1; 
        transform: translateY(0);
        max-height: 100px;
    }
}

/* ==========================================================================
   Different Display Styles
   ========================================================================== */

/* Minimal Style */
.atfw-style-minimal .atfw-terms-item {
    background: transparent;
    border: none;
    border-bottom: 1px solid #e2e4e7;
    border-radius: 0;
    padding: 10px 0;
}

.atfw-style-minimal .atfw-terms-item:last-child {
    border-bottom: none;
}

/* Boxed Style */
.atfw-style-boxed .atfw-terms-item {
    background: #fff;
    border: 2px solid #007cba;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Highlighted Style */
.atfw-style-highlighted .atfw-terms-item {
    background: linear-gradient(135deg, #007cba08 0%, #007cba03 100%);
    border: 2px solid #007cba;
    position: relative;
}

.atfw-style-highlighted .atfw-terms-item::before {
    content: "⚠️";
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 20px;
}

/* ==========================================================================
   Grouped Terms Section
   ========================================================================== */

.atfw-terms-group {
    margin: 30px 0;
    padding: 20px;
    background: #f6f7f7;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
}

.atfw-terms-title {
    margin: 0 0 20px;
    font-size: 18px;
    font-weight: 600;
    color: #1d2327;
    padding-bottom: 10px;
    border-bottom: 2px solid #007cba;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media screen and (max-width: 768px) {
    .atfw-modal-wrapper {
        width: 95%;
        max-width: none;
    }
    
    .atfw-modal-body {
        padding: 20px 15px;
    }
    
    .atfw-terms-item {
        padding: 12px;
    }
    
    .atfw-checkbox-row label {
        font-size: 14px;
    }
    
    .atfw-modal-header {
        padding: 15px;
    }
    
    .atfw-modal-title {
        font-size: 18px;
    }
}

@media screen and (max-width: 480px) {
    .atfw-terms-wrapper {
        margin: 15px 0;
    }
    
    .atfw-terms-item {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .atfw-modal-wrapper {
        width: 100%;
        height: 100%;
        max-height: 100vh;
    }
    
    .atfw-modal-content {
        height: 100%;
        border-radius: 0;
    }
    
    .atfw-modal-body {
        max-height: calc(100vh - 120px);
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.atfw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for keyboard navigation */
.atfw-terms-item:focus-within {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .atfw-terms-item {
        border-width: 2px;
    }
    
    .atfw-modal-content {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .atfw-checkout-terms,
    .atfw-modal,
    .atfw-modal-wrapper,
    .atfw-embedded-content,
    .atfw-terms-item {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================================
   Dark Mode Support (if theme supports)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    body.theme-dark .atfw-terms-item {
        background: #2c3338;
        border-color: #50575e;
        color: #f0f0f1;
    }
    
    body.theme-dark .atfw-label-text {
        color: #f0f0f1;
    }
    
    body.theme-dark .atfw-modal-content {
        background: #1d2327;
        color: #f0f0f1;
    }
    
    body.theme-dark .atfw-modal-header {
        background: linear-gradient(135deg, #007cba20 0%, #007cba10 100%);
        border-bottom-color: #50575e;
    }
    
    body.theme-dark .atfw-modal-title {
        color: #f0f0f1;
    }
    
    body.theme-dark .atfw-modal-close {
        color: #a7aaad;
    }
    
    body.theme-dark .atfw-modal-close:hover {
        background: #2c3338;
        color: #f0f0f1;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .atfw-modal {
        display: none !important;
    }
    
    .atfw-terms-item {
        page-break-inside: avoid;
        border: 1px solid #000;
        padding: 10px;
    }
    
    .atfw-terms-link {
        color: #000;
        text-decoration: underline;
    }
    
    .atfw-terms-link::after {
        content: " (" attr(href) ")";
    }
}

/* ==========================================================================
   WooCommerce Blocks Compatibility
   ========================================================================== */

.wp-block-woocommerce-checkout .atfw-terms-wrapper {
    margin: 15px 0;
}

.wc-block-components-checkbox .atfw-checkbox-row {
    align-items: flex-start;
}

/* ==========================================================================
   Third-party Compatibility
   ========================================================================== */

/* CheckoutWC compatibility */
.cfw-module .atfw-terms-wrapper {
    margin: 15px 0;
}

/* Flux Checkout compatibility */
.flux-checkout .atfw-terms-wrapper {
    padding: 15px 0;
}

/* WooCommerce Germanized compatibility */
.woocommerce-gzd-checkout-legal-checkboxes .atfw-terms-wrapper {
    margin-top: 15px;
}