/**
 * Cookie Consent Popup - EstiloMMA
 * Optimizado para rendimiento (non-blocking load)
 * Control por categorías (estándar industria)
 * v2.1.0
 */

/* ==========================================================================
   Variables CSS (valores por defecto, se sobrescriben inline)
   ========================================================================== */
:root {
    --cookie-consent-btn-primary: #000;
    --cookie-consent-btn-primary-text: #fff;
    --cookie-consent-btn-reject: #ddd;
    --cookie-consent-btn-reject-text: #000;
    --cookie-consent-btn-config: #171717;
    --cookie-consent-btn-config-hover: #00a4d6;
}

/* ==========================================================================
   Base & Container
   ========================================================================== */
#cookie-consent {
    position: fixed;
    inset: 0;
    z-index: 9999;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#cookie-consent.is-active {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   Overlay (fondo oscuro)
   ========================================================================== */
.cookie-consent__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.cookie-consent__overlay.is-shaking {
    animation: cc-shake 0.4s ease-in-out;
}

@keyframes cc-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ==========================================================================
   Popup Principal
   ========================================================================== */
.cookie-consent__popup {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    z-index: 2;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 24px;
    width: calc(100% - 40px);
    max-width: 500px;
    text-align: center;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#cookie-consent.is-active.show-popup .cookie-consent__popup {
    transform: translateX(-50%) translateY(0);
}

/* Cookie Icon */
.cookie-consent__icon {
    width: 64px;
    height: 64px;
    margin: -56px auto 16px;
}

.cookie-consent__icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Title & Description */
.cookie-consent__title {
    font-size: 18px;
    font-weight: 700;
    color: #171717;
    margin: 0 0 8px;
}

.cookie-consent__description {
    font-size: 13px;
    color: #444;
    margin: 0 0 20px;
    text-align: justify;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.cookie-consent__accept {
    padding: 21px 16px;
    border: none;
    border-radius: 8px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
	background: var(--cookie-consent-btn-primary);
    color: var(--cookie-consent-btn-primary-text);
	width: 100%;
}

.cookie-consent__reject {
	cursor: pointer;
	background: transparent;
	border: none;
    color: var(--cookie-consent-btn-reject-text);
    text-align: right;
    font-size: 14px;
}
.cookie-consent__reject:hover {
    opacity: 0.8;
}

/* Config Link */
.cookie-consent__config {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    font-size: 13px;
}
.cookie-consent__config>div{
	cursor:pointer;
	margin-right: auto;
	color: var(--cookie-consent-btn-config);
	transition: color 0.15s ease;
}

.cookie-consent__config>div:hover {
    color: var(--cookie-consent-btn-config-hover);
}

.cookie-consent__config-icon {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

/* ==========================================================================
   Settings Window (Panel lateral)
   ========================================================================== */
.cookie-consent__window {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    width: 100%;
    max-width: 480px;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.1);
	visibility:hidden;
}

#cookie-consent.is-active.show-window .cookie-consent__window {
    transform: translateX(0);
	visibility:visible;
}

/* Window Header */
.cookie-consent__window-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
}

.cookie-consent__window-icon {
    width: 24px;
    height: 24px;
}

.cookie-consent__window-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #333;
}

.cookie-consent__window-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    color: #666;
    transition: background 0.15s ease;
}

.cookie-consent__window-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Window Content */
.cookie-consent__window-content {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.cookie-consent__window-description {
    padding: 16px 20px;
    font-size: 13px;
    color: #555;
    text-align: justify;
    border-bottom: 1px solid #e0e0e0;
}

/* ==========================================================================
   Categories (Acordeones)
   ========================================================================== */
.cookie-consent__category {
    border-bottom: 1px solid #e0e0e0;
}

.cookie-consent__category-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    user-select: none;
}

.cookie-consent__category-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.cookie-consent__category-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.cookie-consent__category.is-active > .cookie-consent__category-header .cookie-consent__category-toggle {
    background: #4caf50;
}

.cookie-consent__category.is-active > .cookie-consent__category-header .cookie-consent__category-toggle::after {
    transform: translateX(20px);
}

.cookie-consent__category.is-readonly .cookie-consent__category-toggle {
    opacity: 0.6;
    cursor: not-allowed;
}

.cookie-consent__category-name {
    flex: 1;
    margin-left: 12px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
}

.cookie-consent__category-arrow {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
}

.cookie-consent__category-arrow svg {
    width: 100%;
    height: 100%;
    fill: #999;
}

.cookie-consent__category.is-expanded .cookie-consent__category-arrow {
    transform: rotate(180deg);
}

/* Category Content */
.cookie-consent__category-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.cookie-consent__category.is-expanded .cookie-consent__category-content {
    max-height: 1000px;
}

.cookie-consent__category-description {
    padding: 12px 20px;
    background: #f9f9f9;
    font-size: 13px;
    color: #666;
}

/* ==========================================================================
   Tools (lista informativa dentro de cada categoría, sin toggles)
   ========================================================================== */
.cookie-consent__tools {
    padding: 8px 20px 12px 20px;
    background: #f9f9f9;
}

.cookie-consent__tool {
    display: flex;
    align-items: flex-start;
    padding: 10px 0;
    gap: 20px;
}

.cookie-consent__tool:not(:last-child) {
    border-bottom: 1px solid #eee;
}

.cookie-consent__tool-icon {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

.cookie-consent__tool-info {
    flex: 1;
    min-width: 0;
}

.cookie-consent__tool-name {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.cookie-consent__tool-description {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    line-height: 1.4;
}

.cookie-consent__tool-privacy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: #e0e0e0;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    color: #666;
    text-decoration: none;
    flex-shrink: 0;
}

.cookie-consent__tool-privacy:hover {
    background: var(--cookie-consent-btn-config-hover);
    color: #fff;
}

/* ==========================================================================
   Window Footer (Save Button)
   ========================================================================== */
.cookie-consent__window-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    background: #fff;
}

.cookie-consent__btn--save {
    width: 100%;
    padding: 14px;
    background: var(--cookie-consent-btn-primary);
    color: var(--cookie-consent-btn-primary-text);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cookie-consent__btn--save:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   Hidden inputs (para formulario)
   ========================================================================== */
.cookie-consent__input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 600px) {
    .cookie-consent__popup {
        bottom: 10px;
        padding: 20px;
        max-width: calc(100% - 20px);
    }

    .cookie-consent__window {
        max-width: 100%;
    }
    
    .cookie-consent__icon {
        width: 56px;
        height: 56px;
        margin-top: -48px;
    }
}

/* ==========================================================================
   Accesibilidad
   ========================================================================== */
.cookie-consent__config:focus-visible,
.cookie-consent__window-close:focus-visible,
.cookie-consent__category-header:focus-visible {
    outline: 2px solid var(--cookie-consent-btn-config-hover);
    outline-offset: 2px;
}

/* Reducir movimiento si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
    #cookie-consent,
    .cookie-consent__popup,
    .cookie-consent__window,
    .cookie-consent__category-content,
    .cookie-consent__category-toggle::after {
        transition: none;
    }
    
    .cookie-consent__overlay.is-shaking {
        animation: none;
    }
}
