@import url('base/_variables.css');
@import url('base/_base.css');
@import url('components/_unified_card.css');
@import url('components/_form.css');
@import url('components/_unified_button.css');
@import url('components/_admin_form.css');
@import url('components/_overlay_shared.css');
@import url('components/_mode-toggle.css');
@import url('components/_processing_spinner.css');
@import url('components/_markdown.css');
@import url('components/_sidebar.css');
@import url('pages/generator.css');
@import url('pages/_build_studio.css');
@import url('pages/_dashboard.css');
@import url('pages/_tutor_dashboard_v2.css');
@import url('pages/_wizard.css');
@import url('pages/compliance.css');
@import url('utils/_utilities.css');


/* CONTAINER UTILITY */
.main-container {
    width: 100%;
    max-width: var(--container-width-narrow);
    position: relative;
    z-index: 1;
    margin-top: 5rem;
    margin-bottom: 5rem;     /* Mirror top: breathing room above footer on all pages */
}

/* Vertical centering for auth pages (login, signup, change password) */
/* These pages have a single .c-card--form as direct child */
.main-container:has(> .c-card--form) {
    flex-grow: 1;                /* Take remaining vertical space */
    display: flex;
    flex-direction: column;
    justify-content: center;     /* Center content vertically within main */
    margin-top: 0;               /* Override base 5rem margin */
    margin-bottom: 0;            /* Override base 5rem margin — padding handles spacing */
    padding-top: 5rem;           /* Maintain spacing from nav */
    padding-bottom: 5rem;        /* Mirror top: equal breathing room above footer */
}

/* Vertical centering for processing/spinner pages */
/* These pages show only a loading indicator during AI generation */
.main-container:has(.processing-page) {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-top: 0;
    margin-bottom: 0;            /* Override base — centered content needs no outer margin */
    padding-top: 5rem;
}
.main-container--medium { max-width: var(--container-width-medium); }
.main-container--wide { max-width: var(--container-width-wide); }
.main-container--xl-wide { max-width: var(--container-width-xl-wide); }

/* Expand main-container for wizard pages to prevent crushing child containers */
.main-container:has(.wizard-container) {
    max-width: var(--container-width-xl-wide);
}

/* Expand main-container for compliance wizard to allow 800px cards */
.main-container:has(.compliance-page) {
    max-width: 900px;  /* Allow compliance cards to reach their 800px max-width */
}

/* Expand main-container for privacy settings to allow wider consent option cards */
.main-container:has(.c-card--form .consent-option) {
    max-width: 1100px;  /* Allow privacy settings card to reach 1100px for horizontal consent layout */
}

/* Expand main-container for profile generation name capture (pre-step) */
.main-container:has(#profile-wizard-container[data-page="generate-profile"]) {
    max-width: var(--container-width-wide);  /* 1200px - matches other wizard pages */
}

/* ANIMATION DELAYS */
.delay-0 { animation-delay: 0s; }
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }
.delay-5 { animation-delay: 0.5s; }
.delay-6 { animation-delay: 0.6s; }
.delay-7 { animation-delay: 0.7s; }
.delay-8 { animation-delay: 0.8s; }
.delay-9 { animation-delay: 0.9s; }

/* HTMX LOADING STATES */
.htmx-request {
    opacity: 0.6;
    transition: opacity var(--transition-base);
}

/* ATMOSPHERIC BACKGROUND EFFECTS */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background:
      radial-gradient(circle at 20% 30%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
      radial-gradient(circle at 80% 70%, rgba(6, 182, 212, 0.1) 0%, transparent 50%),
      radial-gradient(circle at 50% 50%, rgba(14, 165, 233, 0.08) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
    animation: atmosphericGlow 8s ease-in-out infinite alternate;
    contain: strict;
    will-change: contents;
}
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-size: 60px 60px;
    background-image:
      radial-gradient(circle at 1px 1px, rgba(59, 130, 246, 0.1) 1px, transparent 0);
    animation: float 20s linear infinite;
    pointer-events: none;
    z-index: 0;
}
@keyframes atmosphericGlow {
    0% { opacity: 0.8; }
    100% { opacity: 1; }
}
@keyframes float {
    0% { transform: translateY(0) translateX(0); }
    33% { transform: translateY(-10px) translateX(5px); }
    66% { transform: translateY(5px) translateX(-5px); }
    100% { transform: translateY(0) translateX(0); }
}

/* ANIMATIONS & UTILITIES */
.fade-in {
    animation: fadeInUp 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* SKIP-TO-CONTENT — WCAG 2.4.1 */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 9999;
    padding: var(--space-3) var(--space-4);
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 var(--radius-md) 0;
}

.skip-to-content:focus {
    position: fixed;
    left: 0;
    top: 0;
    width: auto;
    height: auto;
    overflow: visible;
}

/* MEDIA QUERIES & ACCESSIBILITY */
@media (max-width: 640px) {
    body {
        padding: var(--space-3);
    }
    .header h1 {
        font-size: var(--font-size-xl);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.form-input:focus-visible {
    outline: 2px solid var(--color-primary-hover);
    outline-offset: 2px;
}

@media (prefers-contrast: high) {
    :root {
        --glass-bg: rgba(15, 23, 42, 0.95);
        --glass-border: rgba(59, 130, 246, 0.5);
    }
}

/* ERROR ALERT STYLING */
.error-alert {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(239, 68, 68, 0.3);
    margin-bottom: var(--space-6);
    font-weight: 500;
    text-align: center;
}

/* Toast System v2.0 - Enhanced with backward compatibility */
:root {
    --toast-z-index: 1000;
    --toast-transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --toast-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Container - prevents click blocking */
.alert-container {
    position: fixed;
    top: 0;
    right: 0;
    z-index: var(--toast-z-index);
    pointer-events: none;
    padding: 1rem;
}

/* Toast base styles */
.toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 250px;
    max-width: 400px;
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--toast-shadow);
    transition: var(--toast-transition); /* TODO(TOAST-GASP): 0.3s causes "gasping" - see Option 2 fix */
    pointer-events: auto;
}

/* TODO(TOAST-GASP): OPTION 2 - Add this class to disable transition on pre-redirect toast
 * ========================================================================================
 * PURPOSE: Prevent CSS transition on first toast (before redirect) to avoid "gasping"
 * USAGE: JS adds this class when skipTransition=true parameter is passed to showToast()
 * TIMING: Only used for pre-redirect toasts, replay toasts use normal transition
 * ========================================================================================
 * .toast.no-transition {
 *     transition: none !important;
 * }
 * ========================================================================================
 */

/* Toast positioning variants */
.toast-position-fixed {
    position: fixed;
    top: 1rem;
    right: 1rem;
}

/* Toast type variants */
.toast.success-alert {
    background-color: rgba(40, 167, 69, 0.95);
    border: 1px solid #28a745;
    color: white;
}

.toast.error-alert {
    background-color: rgba(220, 53, 69, 0.95);
    border: 1px solid #dc3545;
    color: white;
}

.toast.warning-alert {
    background-color: rgba(255, 193, 7, 0.95);
    border: 1px solid #ffc107;
    color: #212529;
}

.toast.info-alert {
    background-color: rgba(23, 162, 184, 0.95);
    border: 1px solid #17a2b8;
    color: white;
}

/* Toast content */
.toast-content {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 0.75rem;
}

.toast-message {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
    flex: 1;
}

/* Toast close button */
.toast-close-btn {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: 0.75rem;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    min-width: 1.5rem;
    min-height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close-btn:hover,
.toast-close-btn:focus {
    opacity: 1;
    outline: none;
}

.toast-close-btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Progress bar */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 0 0 0.5rem 0.5rem;
    transition: width 0.1s linear;
}

/* Display states */
.toast.d-none {
    display: none !important;
}

.toast:not(.d-none) {
    display: flex;
    animation: toastSlideIn 0.3s ease-out;
}

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

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

/* Responsive design */
@media (max-width: 768px) {
    .alert-container {
        left: 1rem;
        right: 1rem;
        padding: 0.5rem;
    }
    
    .toast {
        min-width: auto;
        width: 100%;
        max-width: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .toast {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .toast {
        transition: opacity 0.2s ease;
    }
    
    .toast:not(.d-none) {
        animation: none;
    }
}

/* Legacy support */
#alert-container .toast.show {
    display: flex;
}

#alert-container .toast.hide {
    display: none;
}

/* PASSWORD STRENGTH METER - !!!IMPLEMENTATION PENDING!!! */
.password-strength-meter {
    margin-top: -1rem;
    margin-bottom: 1.75rem;
}

.password-strength-progress {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid var(--slate-700);
    background-color: var(--slate-800);
}

.password-strength-progress::-webkit-progress-bar {
    background-color: var(--slate-800);
}

.password-strength-progress::-webkit-progress-value {
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* Score-based colors */
.password-strength-progress[value="0"]::-webkit-progress-value { background-color: var(--slate-600); }
.password-strength-progress[value="1"]::-webkit-progress-value { background-color: #ef4444; }
.password-strength-progress[value="2"]::-webkit-progress-value { background-color: #f97316; }
.password-strength-progress[value="3"]::-webkit-progress-value { background-color: #84cc16; }
.password-strength-progress[value="4"]::-webkit-progress-value { background-color: #22c55e; }

/* Firefox support */
.password-strength-progress::-moz-progress-bar {
    border-radius: 3px;
    transition: background-color 0.3s ease;
}
.password-strength-progress[value="0"]::-moz-progress-bar { background-color: var(--slate-600); }
.password-strength-progress[value="1"]::-moz-progress-bar { background-color: #ef4444; }
.password-strength-progress[value="2"]::-moz-progress-bar { background-color: #f97316; }
.password-strength-progress[value="3"]::-moz-progress-bar { background-color: #84cc16; }
.password-strength-progress[value="4"]::-moz-progress-bar { background-color: #22c55e; }

.password-strength-text {
    font-size: var(--font-size-sm);
    color: var(--slate-400);
    margin-top: var(--space-2);
    text-align: right;
    height: 1.2em; /* Reserve space to prevent layout shift */
    min-height: 1.2em; /* Ensure consistent height */
}

/* BUTTON SPINNER */
.submit-btn .htmx-indicator { display: none; }
.submit-btn.htmx-request .htmx-indicator { display: inline-block; }
.submit-btn.htmx-request .button-text { display: none; }
.spinner {
    animation: rotate 2s linear infinite;
    width: 20px;
    height: 20px;
    margin: -2px 0;
}
.spinner .path {
    stroke: #fff;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}
@keyframes rotate { 100% { transform: rotate(360deg); } }
@keyframes dash {
    0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

/* PROFILE SECTION STYLES - WCAG AA Compliant for Dark Backgrounds */
.profile-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.3);  /* Semi-transparent border for dark bg */
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.3);  /* Subtle dark background for section separation */
}

.profile-section h3 {
    color: var(--slate-100);  /* Light heading on dark bg */
    margin-bottom: 1rem;
}

.profile-field {
    margin-bottom: 0.75rem;
}

.profile-field strong {
    color: var(--slate-300);  /* WCAG AA: Light color on dark bg (#cbd5e1 on dark) */
    margin-right: 0.5rem;
    font-weight: 600;
}

.profile-value {
    color: var(--slate-100);  /* WCAG AAA: Very light color on dark bg (#f1f5f9) */
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.metric-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    background-color: rgba(248, 250, 252, 0.95);  /* Light background for metric cards */
    border-radius: 6px;
    border: 1px solid rgba(226, 232, 240, 0.3);
}

.metric-label {
    font-size: 0.875rem;
    color: var(--slate-700);  /* WCAG AA: Dark on light bg (#334155 on light) */
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--navy-deep);  /* WCAG AAA: Very dark on light bg (#0f172a on light) */
}

.profile-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    justify-content: flex-start;
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .profile-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .profile-actions .c-button {
        width: 100%;
        justify-content: center;
    }
}

/* TRUST BADGES — Social proof signals on auth pages */
.trust-badges {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding: 0 var(--space-4);
}

.trust-badge {
    display: inline-block;
    color: var(--slate-400);
    font-size: var(--font-size-xs);
    padding: 0.375rem 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: var(--radius-md);
    background: rgba(15, 23, 42, 0.3);
}

/* SITE FOOTER - Marco Civil Compliance (Report Discoverability) */
.site-footer {
    /* Bleed past body padding (var(--space-4)) to match fixed nav full-width */
    align-self: stretch;
    margin-left: calc(-1 * var(--space-4));
    margin-right: calc(-1 * var(--space-4));
    margin-bottom: calc(-1 * var(--space-4));
    width: calc(100% + 2 * var(--space-4));
    padding: var(--space-2) var(--space-6);
    background: rgba(15, 23, 42, 0.6);
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    text-align: center;
    margin-top: auto;        /* Push to bottom of flex column */
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: var(--space-4);
}

.footer-link {
    display: inline-block;
    color: var(--slate-400);
    text-decoration: none;
    font-size: var(--font-size-xs);   /* was --font-size-sm: ~30% size reduction */
    padding: 0.25rem 0.625rem;        /* was 0.5rem 1rem: ~30% size reduction */
    border: 1px solid var(--slate-600);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.footer-link:hover {
    color: var(--slate-100);
    border-color: var(--slate-400);
    background: rgba(148, 163, 184, 0.1);
    text-decoration: none;
}

.footer-link:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .footer-links {
        flex-wrap: wrap;
    }
    .footer-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }
}