/**
 * Acne Ingredient Checker - Modern Enhanced UI
 * ADA/WCAG 2.1 AAA Compliant with Dark Mode Support
 *
 * @package AcneIngredientChecker
 * @since   2.4.0
 */

/* ==========================================================================
   CSS Custom Properties - Theme System
   ========================================================================== */

:root {
    /* Light Mode Colors */
    --aic-bg-primary: #ffffff;
    --aic-bg-secondary: #f9fafb;
    --aic-bg-tertiary: #f3f4f6;

    --aic-text-primary: #333333;
    --aic-text-secondary: #4b5563;
    --aic-text-muted: #9ca3af;

    --aic-border-primary: #e5e7eb;
    --aic-border-secondary: #d1d5db;

    --aic-accent-primary: #c9985e;
    --aic-accent-primary-hover: #b88850;
    --aic-accent-primary-active: #a67744;
    --aic-accent-focus: #d4a574;

    --aic-success-bg: #d1fae5;
    --aic-success-border: #10b981;
    --aic-success-text: #065f46;

    --aic-warning-bg: #fef3c7;
    --aic-warning-border: #f59e0b;
    --aic-warning-text: #92400e;

    --aic-error-bg: #fee2e2;
    --aic-error-border: #ef4444;
    --aic-error-text: #991b1b;

    --aic-problematic-bg: #fff5f5;
    --aic-safe-bg: #f0fdf4;
    --aic-unknown-bg: #fafafa;

    /* Glassmorphic Effects */
    --aic-glass-bg: rgba(255, 255, 255, 0.1);
    --aic-glass-border: rgba(255, 255, 255, 0.2);
    --aic-glass-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);

    /* Gradients */
    --aic-gradient-primary: linear-gradient(135deg, #c9985e 0%, #b88850 100%);
    --aic-gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --aic-gradient-error: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);

    /* Spacing Scale */
    --aic-space-xs: 4px;
    --aic-space-sm: 8px;
    --aic-space-md: 16px;
    --aic-space-lg: 24px;
    --aic-space-xl: 32px;
    --aic-space-2xl: 48px;

    /* Shadows */
    --aic-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --aic-shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --aic-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);

    /* Animation Timing */
    --aic-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --aic-transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --aic-transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index Scale */
    --aic-z-dropdown: 100;
}


/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --aic-border-primary: #000000;
        --aic-text-primary: #000000;
        --aic-accent-focus: #0000ff;
    }

}

/* Reset and Base Styles */
.aic-widget,
.aic-widget * {
    box-sizing: border-box;
}

/* Main Container - Enhanced with Glassmorphism */
.aic-widget {
    position: relative;
    max-width: 720px;
    margin: 40px auto;
    padding: 40px 50px;

    background: var(--aic-bg-primary);
    border-radius: 16px;
    box-shadow: var(--aic-glass-shadow);

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--aic-text-primary);

    /* Smooth theme transition */
    transition: background-color var(--aic-transition-slow),
                color var(--aic-transition-slow),
                border-color var(--aic-transition-slow);
}

/* Glassmorphic Enhancement */
.aic-widget::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-radius: inherit;
    pointer-events: none;
    opacity: 0.5;
}


/* Title Styling */
.aic-title {
    margin: 0 0 32px 0;
    font-size: 32px;
    font-weight: 400;
    color: var(--aic-text-primary);
    text-align: center;
    letter-spacing: -0.5px;

    /* Smooth text color transition */
    transition: color var(--aic-transition-slow);
}

/* Form Layout */
.aic-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Labels - Hidden for cleaner look, but accessible */
.aic-form label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Textarea - Enhanced with Glassmorphism */
.aic-form textarea {
    width: 100%;
    min-height: 120px;
    padding: 14px 18px;

    background: var(--aic-bg-primary);
    border: 2px solid var(--aic-border-primary);
    border-radius: 12px;

    font-size: 15px;
    line-height: 1.6;
    color: var(--aic-text-primary);
    resize: vertical;

    transition: all var(--aic-transition-normal);
    font-family: inherit;

    /* Subtle glassmorphic effect */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.aic-form textarea::placeholder {
    color: var(--aic-text-muted);
    font-size: 15px;
}

/* Focus State - Enhanced with Smooth Animation */
.aic-form textarea:focus,
.aic-form textarea:focus-visible {
    outline: none;
    border-color: var(--aic-accent-primary);
    box-shadow: 0 0 0 3px rgba(201, 152, 94, 0.15),
                0 2px 8px rgba(0, 0, 0, 0.08);
    background: var(--aic-bg-primary);
    transform: translateY(-1px);
}

.aic-form textarea:hover:not(:focus) {
    border-color: var(--aic-border-secondary);
    box-shadow: var(--aic-shadow-sm);
}

/* Button - Enhanced with Gradient and Animations */
.aic-submit {
    width: 100%;
    padding: 16px 28px;

    background: var(--aic-gradient-primary);
    border: none;
    border-radius: 12px;

    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    cursor: pointer;
    letter-spacing: 0.3px;

    transition: all var(--aic-transition-normal);
    position: relative;
    overflow: hidden;

    /* Subtle elevation */
    box-shadow: var(--aic-shadow-md);
}

.aic-submit::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left var(--aic-transition-slow);
}

.aic-submit:hover:not(:disabled) {
    background: linear-gradient(135deg, #b88850 0%, #a67744 100%);
    transform: translateY(-2px);
    box-shadow: var(--aic-shadow-lg);
}

.aic-submit:hover::before {
    left: 100%;
}

.aic-submit:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--aic-shadow-sm);
}

/* Focus State for Button - Enhanced */
.aic-submit:focus-visible {
    outline: 3px solid var(--aic-accent-focus);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.3),
                var(--aic-shadow-md);
}

/* Loading State with Pulse Animation */
.aic-submit[aria-busy="true"] {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.aic-submit[aria-busy="true"]::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.aic-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--aic-bg-tertiary);
    color: var(--aic-text-muted);
    transform: none;
    box-shadow: var(--aic-shadow-sm);
}

/* Pulse Animation for Primary Action */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

.aic-submit.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Global Focus Indicators for Accessibility */
.aic-widget *:focus-visible {
    outline: 3px solid var(--aic-accent-focus);
    outline-offset: 2px;
}

/* Status Messages - Enhanced */
.aic-status {
    min-height: 24px;
    font-size: 15px;
    color: var(--aic-text-secondary);
    margin-top: 8px;
    text-align: center;
    padding: var(--aic-space-sm);
    border-radius: 8px;
    transition: all var(--aic-transition-normal);
}

.aic-status[role="status"],
.aic-status[aria-live="polite"] {
    /* ARIA live region styling */
    min-height: auto;
}

/* Status Types */
.aic-status-error {
    background: var(--aic-error-bg);
    color: var(--aic-error-text);
    border-left: 3px solid var(--aic-error-border);
    padding: 12px 16px;
}

.aic-status-loading {
    background: var(--aic-warning-bg);
    color: var(--aic-warning-text);
    border-left: 3px solid var(--aic-warning-border);
    padding: 12px 16px;
}

/* Help Text - Enhanced */
.aic-help-text {
    display: block;
    font-size: 14px;
    color: var(--aic-text-muted);
    margin-top: 8px;
    text-align: center;
    opacity: 0.8;
}

/* Disclaimer Text - Enhanced */
.aic-disclaimer {
    margin-top: 20px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--aic-text-muted);
    text-align: center;
    opacity: 0.9;
}

/* Results Section - Enhanced with Progressive Animation */
.aic-results {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--aic-border-primary);
    animation: slideInDown var(--aic-transition-slow) ease-out;
}

/* Progressive Reveal Animation */
@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Summary Card - Enhanced with Glassmorphism */
.aic-summary {
    padding: 20px 24px;
    margin-bottom: 16px;

    background: var(--aic-bg-secondary);
    border: 1px solid var(--aic-border-primary);
    border-radius: 12px;

    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    /* Smooth transition for theme changes */
    transition: all var(--aic-transition-slow);
}

.aic-summary h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--aic-text-primary);
}

/* Risk Badge - Enhanced with Gradient */
.aic-overall-risk {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    margin: 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;

    /* Enhanced with shadow */
    box-shadow: var(--aic-shadow-sm);
    transition: all var(--aic-transition-normal);
}

.aic-overall-risk::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: inherit;
    opacity: 0.1;
    pointer-events: none;
}

/* Enhanced Color Coding for Risk Levels with Gradients */
.aic-risk-low {
    background: var(--aic-gradient-success);
    color: white;
    border: 1px solid var(--aic-success-border);
    animation: slideInLeft 0.4s ease-out;
}

.aic-risk-moderate {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border: 1px solid var(--aic-warning-border);
    animation: slideInLeft 0.4s ease-out 0.1s both;
}

.aic-risk-high {
    background: var(--aic-gradient-error);
    color: white;
    border: 1px solid var(--aic-error-border);
    animation: slideInLeft 0.4s ease-out 0.2s both;
}

/* Slide in animation for badges */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.aic-recommendation,
.aic-analysis-summary {
    font-size: 14px;
    line-height: 1.6;
    color: var(--aic-text-secondary);
    margin: 8px 0;
    padding: 12px;
    background: var(--aic-bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--aic-accent-primary);
}

/* Ingredient Grid - Compact */
.aic-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

/* Section Cards - Enhanced with Glassmorphism */
.aic-columns section {
    padding: 16px 20px;

    background: var(--aic-bg-secondary);
    border: 2px solid var(--aic-border-primary);
    border-radius: 12px;

    transition: all var(--aic-transition-normal);

    /* Glassmorphic effect */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    /* Hover elevation */
    transform: translateY(0);
}

.aic-columns section:hover {
    transform: translateY(-2px);
    box-shadow: var(--aic-shadow-lg);
}

/* Enhanced Color-Coded Section Borders */
.aic-problematic {
    border-left: 4px solid var(--aic-error-border);
    background: var(--aic-problematic-bg);
    animation: slideInUp 0.5s ease-out;
}

.aic-safe {
    border-left: 4px solid var(--aic-success-border);
    background: var(--aic-safe-bg);
    animation: slideInUp 0.5s ease-out 0.1s both;
}

.aic-unknown {
    border-left: 4px solid var(--aic-text-muted);
    background: var(--aic-unknown-bg);
    animation: slideInUp 0.5s ease-out 0.2s both;
}

/* Staggered animation for sections */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Section Headers - Enhanced */
.aic-columns h4 {
    margin: 0 0 12px 0;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--aic-border-primary);

    /* Smooth transitions */
    transition: color var(--aic-transition-normal);
}

.aic-problematic h4 {
    color: var(--aic-error-border);
}

.aic-safe h4 {
    color: var(--aic-success-border);
}

.aic-unknown h4 {
    color: var(--aic-text-secondary);
}

/* Ingredient Lists - Enhanced */
.aic-columns ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.aic-columns li {
    padding: 10px 12px;
    margin-bottom: 8px;

    background: var(--aic-bg-primary);
    border-radius: 8px;
    border-left: 3px solid transparent;

    font-size: 13px;
    line-height: 1.6;
    color: var(--aic-text-secondary);

    transition: all var(--aic-transition-normal);

    /* Smooth hover effect */
    transform: translateX(0);
}

.aic-columns li:hover {
    transform: translateX(5px);
    box-shadow: var(--aic-shadow-sm);
}

/* Enhanced Risk Indicators */
.aic-problematic li {
    border-left-color: var(--aic-error-border);
    background: var(--aic-error-bg);
    color: var(--aic-error-text);
}

.aic-problematic li:hover {
    transform: translateX(8px) translateY(-2px);
    box-shadow: var(--aic-shadow-md);
}

.aic-safe li {
    border-left-color: var(--aic-success-border);
    background: var(--aic-success-bg);
    color: var(--aic-success-text);
}

.aic-safe li:hover {
    transform: translateX(8px) translateY(-2px);
    box-shadow: var(--aic-shadow-md);
}

.aic-unknown li {
    border-left-color: var(--aic-text-muted);
    background: var(--aic-unknown-bg);
    color: var(--aic-text-secondary);
}

.aic-unknown li:hover {
    transform: translateX(8px) translateY(-2px);
    box-shadow: var(--aic-shadow-md);
}

/* Staggered animation for list items */
.aic-columns li {
    animation: fadeIn 0.3s ease-out both;
}

.aic-problematic li { animation-delay: 0.1s; }
.aic-safe li { animation-delay: 0.2s; }
.aic-unknown li { animation-delay: 0.3s; }

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

/* Empty State - Enhanced */
.aic-columns li.empty-placeholder {
    color: var(--aic-text-muted);
    font-style: italic;
    border-left-color: transparent;
    background: transparent;
    padding: 12px;
    text-align: center;
}

/* Reduced Motion - Enhanced */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Remove pulse animation for users who prefer reduced motion */
    .aic-submit.pulse {
        animation: none;
    }
}

/* Mobile Optimizations - Enhanced */
@media (max-width: 768px) {
    .aic-widget {
        padding: 30px 20px;
        margin: 16px 12px;
        border-radius: 12px;
    }

    .aic-title {
        font-size: 26px;
        margin-bottom: 24px;
    }

    .aic-form textarea {
        min-height: 100px;
        padding: 12px 16px;
        font-size: 15px;
        border-radius: 10px;
    }

    .aic-submit {
        padding: 14px 24px;
        font-size: 15px;
        border-radius: 10px;
    }

    .aic-submit:hover:not(:disabled) {
        transform: none;
    }

    .aic-disclaimer {
        font-size: 11px;
        margin-top: 16px;
    }

    .aic-columns {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .aic-summary {
        padding: 16px 18px;
        border-radius: 10px;
    }

    .aic-summary h3 {
        font-size: 16px;
        margin-bottom: 10px;
    }

    .aic-columns section {
        padding: 14px 16px;
        border-radius: 10px;
    }

    .aic-columns section:hover {
        transform: none;
    }

    .aic-columns h4 {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .aic-columns li {
        padding: 8px 10px;
        margin-bottom: 6px;
        font-size: 12px;
    }

    .aic-columns li:hover {
        transform: translateX(3px);
    }

    .aic-results {
        margin-top: 20px;
        padding-top: 20px;
    }
}

/* Print Styles - Enhanced */
@media print {
    .aic-widget {
        background: white;
        box-shadow: none;
        border: 1px solid #ccc;
        border-radius: 0;
    }

    .aic-submit {
        display: none;
    }

    /* Ensure dark mode colors don't interfere with printing */
    * {
        color: #000 !important;
        background: white !important;
    }
}

/* Skeleton Loading States */
@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.aic-skeleton {
    background: linear-gradient(90deg, var(--aic-bg-tertiary) 25%, var(--aic-bg-secondary) 50%, var(--aic-bg-tertiary) 75%);
    background-size: 200px 100%;
    animation: skeleton-loading 1.2s ease-in-out infinite;
    border-radius: 8px;
}

.aic-skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.aic-skeleton-text.short {
    width: 60%;
}

.aic-skeleton-text.medium {
    width: 80%;
}

.aic-skeleton-text.long {
    width: 100%;
}

/* Error Messages - Enhanced */
.aic-error-message {
    color: var(--aic-error-text);
    font-size: 14px;
    font-weight: 500;
    margin-top: 8px;
    text-align: left;
    padding: 16px;
    background: var(--aic-error-bg);
    border-left: 4px solid var(--aic-error-border);
    border-radius: 8px;

    /* Error shake animation */
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Screen Reader Only - Enhanced */
.sr-only {
    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 Trap */
.aic-focus-trap {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    z-index: 1000;
}

/* Success Animation */
@keyframes checkmark {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.aic-success-checkmark {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--aic-success-border);
    position: relative;
    animation: checkmark 0.5s ease-in-out;
}

.aic-success-checkmark::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: 2px solid white;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg);
}

/* Touch-Friendly Interactions */
@media (hover: none) and (pointer: coarse) {
    .aic-columns section:hover {
        transform: none;
    }

    .aic-columns li:hover {
        transform: none;
    }

    /* Add ripple effect for touch */
    .aic-submit {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* Pull-to-Refresh Indicator */
.aic-pull-refresh {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: var(--aic-accent-primary);
    color: white;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--aic-shadow-md);
    transition: all var(--aic-transition-normal);
    z-index: 10;
}

.aic-pull-refresh.active {
    top: -50px;
    opacity: 1;
}
