/**
 * Professional Cookie Consent Styling for Atenzia
 * GDPR Compliant - Custom Implementation
 * Includes: Dark Mode, Responsive Design, Accessibility, Animations
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Colors */
    --cc-primary: #3b82f6;
    --cc-primary-hover: #2563eb;
    --cc-primary-light: rgba(59, 130, 246, 0.1);
    --cc-secondary: #64748b;
    --cc-secondary-hover: #475569;
    --cc-bg: #ffffff;
    --cc-text: #1f2937;
    --cc-text-secondary: #4b5563;
    --cc-text-light: #6b7280;
    --cc-border: #e5e7eb;
    --cc-overlay: rgba(0, 0, 0, 0.5);

    /* Spacing */
    --cc-spacing-xs: 0.5rem;
    --cc-spacing-sm: 0.75rem;
    --cc-spacing-md: 1rem;
    --cc-spacing-lg: 1.5rem;
    --cc-spacing-xl: 2rem;

    /* Border Radius */
    --cc-radius-sm: 0.5rem;
    --cc-radius-md: 0.75rem;
    --cc-radius-lg: 1rem;
    --cc-radius-full: 50%;

    /* Shadows */
    --cc-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --cc-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --cc-shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.2);
    --cc-shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.3);

    /* Transitions */
    --cc-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --cc-transition-fast: all 0.15s ease;
}

/* Dark mode - DISABLED for cookie modal (always light theme for better contrast)
@media (prefers-color-scheme: dark) {
    :root {
        --cc-bg: #1f2937;
        --cc-text: #f9fafb;
        --cc-text-secondary: #d1d5db;
        --cc-text-light: #9ca3af;
        --cc-border: #374151;
        --cc-overlay: rgba(0, 0, 0, 0.7);
    }
}
*/

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --cc-primary: #1e40af;
        --cc-text: #000000;
        --cc-bg: #ffffff;
    }
}

/* ============================================
   OVERLAY
   ============================================ */
#cookie-consent-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--cc-overlay);
    z-index: 9998;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
}

/* ============================================
   MODAL
   ============================================ */
#cookie-consent-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff !important;
    color: #1f2937 !important;
    box-shadow: var(--cc-shadow-xl);
    padding: 0;
    z-index: 9999;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    border-radius: var(--cc-radius-lg);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Force all text inside modal to be dark on white background */
#cookie-consent-modal * {
    color: inherit;
}

/* Modal content (scrollable) */
#cookie-consent-modal > div:first-child {
    background: transparent !important;
    padding: var(--cc-spacing-xl);
    overflow-y: auto;
    flex: 1;
}

/* Scrollbar styling for modal content */
#cookie-consent-modal > div:first-child::-webkit-scrollbar {
    width: 8px;
}

#cookie-consent-modal > div:first-child::-webkit-scrollbar-track {
    background: var(--cc-border);
    border-radius: var(--cc-radius-sm);
}

#cookie-consent-modal > div:first-child::-webkit-scrollbar-thumb {
    background: var(--cc-secondary);
    border-radius: var(--cc-radius-sm);
}

#cookie-consent-modal > div:first-child::-webkit-scrollbar-thumb:hover {
    background: var(--cc-secondary-hover);
}

/* Modal title */
#cookie-consent-modal h3 {
    margin: 0 0 var(--cc-spacing-md) 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: #1f2937 !important;
    background: linear-gradient(135deg, var(--cc-primary) 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
    line-height: 1.2;
}

/* Modal description */
#cookie-consent-modal p {
    margin: 0 0 var(--cc-spacing-lg) 0;
    font-size: 1rem;
    color: #4b5563 !important;
    line-height: 1.6;
}

/* Links in modal */
#cookie-consent-modal a {
    color: var(--cc-primary) !important;
    text-decoration: underline;
}

/* ============================================
   COOKIE CATEGORIES
   ============================================ */
#cookie-consent-modal > div > div {
    margin-bottom: var(--cc-spacing-lg);
}

/* Category Block */
.cc-category-block {
    background: linear-gradient(135deg, rgba(249, 250, 251, 0.8) 0%, rgba(243, 244, 246, 0.6) 100%);
    padding: var(--cc-spacing-md);
    border-radius: var(--cc-radius-md);
    margin-bottom: var(--cc-spacing-sm);
    border: 1px solid var(--cc-border);
    transition: var(--cc-transition);
}

.cc-category-block:hover {
    background: linear-gradient(135deg, rgba(249, 250, 251, 1) 0%, rgba(243, 244, 246, 0.8) 100%);
    border-color: var(--cc-primary-light);
    box-shadow: var(--cc-shadow-sm);
}

/* Category Header */
.cc-category-header {
    display: flex;
    flex-direction: column;
    gap: var(--cc-spacing-sm);
}

#cookie-consent-modal label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

#cookie-consent-modal label > div:first-child {
    flex: 1;
}

#cookie-consent-modal label > div > div:first-child {
    font-weight: 600;
    color: #1f2937 !important;
    margin-bottom: var(--cc-spacing-xs);
    font-size: 1rem;
}

#cookie-consent-modal label > div > div:last-child {
    font-size: 0.875rem;
    color: #6b7280 !important;
}

/* Toggle Details Button */
.cc-toggle-details {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--cc-border);
    border-radius: var(--cc-radius-sm);
    color: var(--cc-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--cc-transition-fast);
    width: fit-content;
}

.cc-toggle-details:hover {
    background: var(--cc-primary-light);
    border-color: var(--cc-primary);
}

.cc-toggle-details svg {
    transition: transform 0.3s ease;
}

/* Cookie Details Table */
.cc-cookie-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, margin-top 0.4s ease, opacity 0.4s ease;
    opacity: 0;
}

.cc-cookie-details.cc-expanded {
    max-height: 1000px;
    margin-top: var(--cc-spacing-md);
    opacity: 1;
}

.cc-cookie-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background: white;
    border-radius: var(--cc-radius-sm);
    overflow: hidden;
    box-shadow: var(--cc-shadow-sm);
}

.cc-cookie-table thead {
    background: linear-gradient(135deg, var(--cc-primary) 0%, #2563eb 100%);
    color: white;
}

.cc-cookie-table thead th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cc-cookie-table tbody tr {
    border-bottom: 1px solid var(--cc-border);
    transition: background-color 0.2s ease;
}

.cc-cookie-table tbody tr:last-child {
    border-bottom: none;
}

.cc-cookie-table tbody tr:hover {
    background-color: rgba(59, 130, 246, 0.05);
}

.cc-cookie-table tbody td {
    padding: 0.75rem;
    vertical-align: top;
}

.cc-cookie-table tbody td:first-child {
    font-weight: 500;
}

.cc-cookie-table code {
    background: rgba(59, 130, 246, 0.1);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.8125rem;
    color: var(--cc-primary);
    font-weight: 600;
}

/* Checkbox styling */
#cookie-consent-modal input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: var(--cc-primary);
    border-radius: var(--cc-radius-sm);
    transition: var(--cc-transition);
}

#cookie-consent-modal input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

#cookie-consent-modal input[type="checkbox"]:focus {
    outline: 3px solid var(--cc-primary-light);
    outline-offset: 2px;
}

#cookie-consent-modal input[type="checkbox"]:hover:not(:disabled) {
    transform: scale(1.1);
}

/* ============================================
   BUTTONS
   ============================================ */
#cookie-consent-modal button {
    padding: 0.875rem 1.75rem;
    border: none;
    border-radius: var(--cc-radius-md);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--cc-transition);
    position: relative;
    overflow: hidden;
}

#cookie-consent-modal button:focus {
    outline: 3px solid var(--cc-primary-light);
    outline-offset: 2px;
}

/* Accept All button - Green */
#cc-accept-all {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

#cc-accept-all:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
    transform: translateY(-2px);
}

#cc-accept-all:active {
    transform: translateY(0);
}

/* Save Preferences button - Blue */
#cc-save-preferences {
    background: linear-gradient(135deg, var(--cc-primary) 0%, #2563eb 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

#cc-save-preferences:hover {
    background: linear-gradient(135deg, var(--cc-primary-hover) 0%, #1e40af 100%) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: translateY(-2px);
}

#cc-save-preferences:active {
    transform: translateY(0);
}

/* Configure button - Blue (neutral) */
#cc-configure {
    background: linear-gradient(135deg, var(--cc-primary) 0%, #2563eb 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

#cc-configure:hover {
    background: linear-gradient(135deg, var(--cc-primary-hover) 0%, #1e40af 100%) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: translateY(-2px);
}

#cc-configure:active {
    transform: translateY(0);
}

/* Secondary button (Only Necessary) - Now with equal prominence per AEPD guidelines */
#cc-accept-necessary {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(75, 85, 99, 0.4);
}

#cc-accept-necessary:hover {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%) !important;
    box-shadow: 0 6px 20px rgba(75, 85, 99, 0.5);
    transform: translateY(-2px);
}

#cc-accept-necessary:active {
    transform: translateY(0);
}

/* Button container adjustments */
.cc-button-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: var(--cc-spacing-lg);
}

/* When there are 3 buttons (initial modal) */
.cc-button-group button {
    flex: 1 1 auto;
    min-width: fit-content;
}

/* Sticky buttons (always visible at bottom) */
.cc-sticky-buttons {
    position: sticky;
    bottom: 0;
    background: #ffffff !important;
    padding: var(--cc-spacing-md) var(--cc-spacing-xl);
    margin: 0;
    border-top: 1px solid var(--cc-border);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

/* Config modal button styles */
#cc-config-accept-all {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

#cc-config-accept-all:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
    transform: translateY(-2px);
}

#cc-config-save-preferences {
    background: linear-gradient(135deg, var(--cc-primary) 0%, #2563eb 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

#cc-config-save-preferences:hover {
    background: linear-gradient(135deg, var(--cc-primary-hover) 0%, #1e40af 100%) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: translateY(-2px);
}

#cc-config-accept-necessary {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(75, 85, 99, 0.4);
}

#cc-config-accept-necessary:hover {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%) !important;
    box-shadow: 0 6px 20px rgba(75, 85, 99, 0.5);
    transform: translateY(-2px);
}

/* Button ripple effect */
#cookie-consent-modal button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

#cookie-consent-modal button:active::before {
    width: 300px;
    height: 300px;
}

/* ============================================
   FLOATING BUTTON
   ============================================ */
#cookie-consent-float {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--cc-primary) 0%, #2563eb 100%);
    color: #ffffff;
    border: none;
    border-radius: var(--cc-radius-full);
    cursor: pointer;
    font-size: 28px;
    box-shadow: var(--cc-shadow-lg);
    z-index: 9997;
    transition: var(--cc-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: floatIn 0.5s ease-out, pulse 2s ease-in-out infinite;
}

#cookie-consent-float:hover {
    background: linear-gradient(135deg, var(--cc-primary-hover) 0%, #1e40af 100%);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    transform: scale(1.15) rotate(10deg);
}

#cookie-consent-float:active {
    transform: scale(1.05);
}

#cookie-consent-float:focus {
    outline: 3px solid var(--cc-primary-light);
    outline-offset: 4px;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes floatIn {
    from {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    }
    50% {
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3), 0 0 0 10px rgba(59, 130, 246, 0.1), 0 0 0 20px rgba(59, 130, 246, 0.05);
    }
}

/* Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    #cookie-consent-float {
        animation: none;
    }
}

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

/* Tablets and below */
@media (max-width: 768px) {
    #cookie-consent-modal {
        max-width: 95%;
        padding: var(--cc-spacing-lg);
    }

    #cookie-consent-modal h3 {
        font-size: 1.5rem;
    }

    #cookie-consent-modal button {
        padding: 0.75rem 1.5rem;
        font-size: 0.9375rem;
    }

    /* Stack buttons vertically on tablets */
    .cc-button-group {
        flex-direction: column;
    }

    .cc-button-group button {
        width: 100%;
    }

    #cookie-consent-float {
        width: 56px;
        height: 56px;
        font-size: 24px;
        bottom: 16px;
        left: 16px;
    }
}

/* Mobile devices */
@media (max-width: 480px) {
    #cookie-consent-modal {
        width: 95%;
        max-height: 85vh;
        padding: var(--cc-spacing-md);
    }

    #cookie-consent-modal h3 {
        font-size: 1.25rem;
        margin-bottom: var(--cc-spacing-sm);
    }

    #cookie-consent-modal p {
        font-size: 0.9375rem;
        margin-bottom: var(--cc-spacing-md);
    }

    #cookie-consent-modal > div > div {
        margin-bottom: var(--cc-spacing-md);
    }

    .cc-category-block {
        padding: var(--cc-spacing-sm);
    }

    #cookie-consent-modal label > div > div:first-child {
        font-size: 0.9375rem;
    }

    #cookie-consent-modal label > div > div:last-child {
        font-size: 0.8125rem;
    }

    #cookie-consent-modal button {
        width: 100%;
        padding: 0.875rem;
        font-size: 0.9375rem;
    }

    .cc-button-group {
        flex-direction: column;
        gap: var(--cc-spacing-sm);
    }

    #cookie-consent-float {
        width: 50px;
        height: 50px;
        font-size: 22px;
        bottom: 12px;
        left: 12px;
    }

    /* Mobile responsive table */
    .cc-cookie-table {
        font-size: 0.75rem;
    }

    .cc-cookie-table thead {
        display: none;
    }

    .cc-cookie-table tbody td {
        display: block;
        padding: 0.5rem;
        text-align: left;
        border-bottom: none;
    }

    .cc-cookie-table tbody td:first-child {
        background: var(--cc-primary-light);
        font-weight: 700;
        font-size: 0.875rem;
        padding-top: 0.75rem;
    }

    .cc-cookie-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        display: inline-block;
        margin-right: 0.5rem;
        color: var(--cc-text);
    }

    .cc-cookie-table tbody td:first-child::before {
        content: '';
    }

    .cc-cookie-table tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--cc-border);
        border-radius: var(--cc-radius-sm);
        overflow: hidden;
    }

    .cc-toggle-details {
        width: 100%;
        justify-content: center;
        font-size: 0.8125rem;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    #cookie-consent-overlay,
    #cookie-consent-modal,
    #cookie-consent-float {
        display: none !important;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus visible (keyboard navigation) */
#cookie-consent-modal button:focus-visible,
#cookie-consent-modal input[type="checkbox"]:focus-visible,
#cookie-consent-float:focus-visible {
    outline: 3px solid var(--cc-primary);
    outline-offset: 3px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   DARK MODE SPECIFIC ADJUSTMENTS - DISABLED (always light theme)
   ============================================ */
/*
@media (prefers-color-scheme: dark) {
    .cc-category-block {
        background: linear-gradient(135deg, rgba(55, 65, 81, 0.8) 0%, rgba(31, 41, 55, 0.6) 100%);
        border-color: var(--cc-border);
    }

    .cc-category-block:hover {
        background: linear-gradient(135deg, rgba(55, 65, 81, 1) 0%, rgba(31, 41, 55, 0.8) 100%);
        border-color: rgba(59, 130, 246, 0.3);
    }

    #cc-accept-necessary {
        background: #374151;
        color: var(--cc-text);
    }

    #cc-accept-necessary:hover {
        background: #4b5563;
    }

    .cc-cookie-table {
        background: #1f2937;
    }

    .cc-cookie-table tbody tr:hover {
        background-color: rgba(59, 130, 246, 0.15);
    }

    .cc-cookie-table tbody tr {
        border-bottom-color: #374151;
    }

    .cc-toggle-details {
        border-color: #374151;
    }

    .cc-toggle-details:hover {
        background: rgba(59, 130, 246, 0.2);
    }
}
*/

/* ============================================
   LOADING STATE
   ============================================ */
.cc-loading {
    pointer-events: none;
    opacity: 0.6;
}

.cc-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
