/* ============================================
   ModelNexus - Main Stylesheet
   Aurora Dark Theme with Cyber Accents
   ============================================ */

/* --- Web Fonts (self-hosted via Google Fonts CDN) --- */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Variables --- */
:root {
    /* --- Typography --- */
    --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, monospace;

    /* Type scale (modular, ratio ~1.25) */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;
    --text-3xl: 2.25rem;
    --text-4xl: 3rem;
    --text-5xl: 4rem;

    /* --- Background --- */
    --bg-primary: #070710;
    --bg-secondary: #0e0e1a;
    --bg-tertiary: #15162a;
    --bg-card: #171828;
    --bg-card-hover: #20213a;
    --bg-input: #1a1b2e;
    --bg-overlay: rgba(5, 5, 12, 0.85);
    --bg-glass: rgba(23, 24, 40, 0.65);

    /* --- Text --- */
    --text-primary: #e8e9f1;
    --text-secondary: #a5a7bd;
    --text-muted: #6b6d85;
    --text-white: #ffffff;

    /* --- Accent (aurora palette) --- */
    --accent-primary: #7c5cff;      /* Vibrant indigo */
    --accent-primary-hover: #9478ff;
    --accent-primary-glow: rgba(124, 92, 255, 0.35);
    --accent-secondary: #5eb6ff;    /* Sky */
    --accent-secondary-glow: rgba(94, 182, 255, 0.35);
    --accent-tertiary: #ff6bd6;     /* Magenta */
    --accent-tertiary-glow: rgba(255, 107, 214, 0.35);

    --accent-success: #22d3a0;
    --accent-warning: #ffb547;
    --accent-danger: #ff5570;
    --accent-info: #4fd1c7;

    /* --- Aurora colors (for gradients/mesh backgrounds) --- */
    --aurora-1: #7c5cff;
    --aurora-2: #5eb6ff;
    --aurora-3: #ff6bd6;
    --aurora-4: #4fd1c7;

    /* --- Gradients --- */
    --grad-primary: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    --grad-aurora: linear-gradient(135deg, var(--aurora-1) 0%, var(--aurora-2) 50%, var(--aurora-3) 100%);
    --grad-mesh: radial-gradient(at 20% 20%, var(--aurora-1) 0, transparent 50%),
                 radial-gradient(at 80% 30%, var(--aurora-2) 0, transparent 50%),
                 radial-gradient(at 50% 80%, var(--aurora-3) 0, transparent 50%);
    --grad-card-hover: linear-gradient(135deg, rgba(124, 92, 255, 0.08), rgba(255, 107, 214, 0.04));

    /* --- Borders --- */
    --border-color: #272839;
    --border-light: #373950;
    --border-hover: #403f63;

    /* --- Shadows --- */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 6px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.55);
    --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 24px var(--accent-primary-glow);
    --shadow-glow-lg: 0 0 48px var(--accent-primary-glow);
    --shadow-glow-danger: 0 0 24px rgba(255, 85, 112, 0.4);
    --shadow-glow-success: 0 0 24px rgba(34, 211, 160, 0.4);

    /* --- Spacing scale (4/8/12/16/24/32/48/64/96) --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
    --space-9: 96px;

    --nav-height: 64px;
    --sidebar-width: 280px;
    --container-max: 1400px;

    /* --- Radius --- */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* --- Easings (all animations use these — consistent "signature") --- */
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-in-out-quart: cubic-bezier(0.76, 0, 0.24, 1);
    --ease-spring: cubic-bezier(0.2, 0.9, 0.3, 1.25);

    /* --- Transitions --- */
    --transition-fast: 150ms var(--ease-out-quart);
    --transition-base: 250ms var(--ease-out-quart);
    --transition-slow: 400ms var(--ease-out-quart);
    --transition-spring: 400ms var(--ease-out-back);

    /* --- Z-index layers --- */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 150;
    --z-modal-backdrop: 200;
    --z-modal: 300;
    --z-toast: 400;
    --z-tooltip: 500;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    background-color: var(--bg-primary);
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    letter-spacing: -0.011em;
    animation: bodyFadeIn 500ms var(--ease-out-expo) both;
}

@keyframes bodyFadeIn {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}

/* Text selection — branded */
::selection {
    background: rgba(124, 92, 255, 0.35);
    color: #ffffff;
    text-shadow: none;
}
::-moz-selection {
    background: rgba(124, 92, 255, 0.35);
    color: #ffffff;
    text-shadow: none;
}

/* Focus-visible refinement — aurora glow ring */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

a:focus-visible {
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.25);
    border-radius: 4px;
}

h1, h2, h3, h4, h5, h6,
.page-title, .section-title, .hero-title {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
    font-weight: 700;
}

code, pre, kbd, .mono {
    font-family: var(--font-mono);
}

/* Links: animated underline on hover (for inline content links) */
.legal-content a,
.main-content p a {
    position: relative;
    background-image: linear-gradient(var(--accent-primary), var(--accent-primary));
    background-size: 0% 1px;
    background-position: 0% 100%;
    background-repeat: no-repeat;
    text-decoration: none;
    transition: background-size 300ms var(--ease-out-quart),
                color 200ms var(--ease-out-quart);
}

.legal-content a:hover,
.main-content p a:hover {
    background-size: 100% 2px;
    color: var(--accent-primary-hover);
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(124, 92, 255, 0.4), rgba(94, 182, 255, 0.3));
    border-radius: 10px;
    border: 2px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(124, 92, 255, 0.6), rgba(255, 107, 214, 0.4));
}

/* --- Reduced motion: kill all heavy animations --- */
@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;
    }
}

/* --- Page transitions (SPA-like) --- */
main.main-content {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 180ms var(--ease-out-quart),
                transform 240ms var(--ease-out-quart);
}

main.main-content.page-leave {
    opacity: 0;
    transform: translateY(6px);
    transition-duration: 130ms;
}

main.main-content.page-enter {
    animation: pageEnter 420ms var(--ease-out-expo);
}

@keyframes pageEnter {
    0%   { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Top progress bar */
.page-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: var(--z-toast);
    pointer-events: none;
    background: linear-gradient(90deg,
        transparent,
        var(--accent-primary) 30%,
        var(--accent-tertiary) 50%,
        var(--accent-secondary) 70%,
        transparent);
    background-size: 200% 100%;
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
    transition: transform 180ms var(--ease-out-quart),
                opacity 200ms var(--ease-out-quart);
}

.page-progress.loading {
    opacity: 1;
    animation: progressSlide 1.6s var(--ease-in-out-quart) infinite;
}

.page-progress.done {
    transform: scaleX(1);
    opacity: 0;
    transition-duration: 300ms;
}

@keyframes progressSlide {
    0%   { transform: scaleX(0.05); background-position: 0% 0%; }
    50%  { transform: scaleX(0.6);  background-position: 100% 0%; }
    100% { transform: scaleX(0.95); background-position: 200% 0%; }
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-primary-hover);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

input, textarea, select, button {
    font-family: inherit;
    font-size: inherit;
}

ul, ol {
    list-style: none;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Layout --- */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
}

.main-content {
    padding-top: calc(var(--nav-height) + 24px);
    padding-bottom: 60px;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 32px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-white);
    margin-bottom: 8px;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* --- Grid System --- */
.grid {
    display: grid;
    gap: 20px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }

/* Models grid - responsive auto-fill */
.grid-models {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* Masonry-like for images */
.grid-masonry {
    columns: 5 240px;
    column-gap: 16px;
}

.grid-masonry > * {
    break-inside: avoid;
    margin-bottom: 16px;
}

/* --- Navbar (glassmorphism + scroll shadow) --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(7, 7, 16, 0.6);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    z-index: var(--z-modal-backdrop);
    overflow: visible;
    transition: box-shadow 300ms var(--ease-out-quart),
                background 300ms var(--ease-out-quart),
                border-color 300ms var(--ease-out-quart);
}

.navbar.scrolled {
    background: rgba(7, 7, 16, 0.85);
    border-bottom-color: rgba(124, 92, 255, 0.12);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4),
                0 1px 0 rgba(124, 92, 255, 0.1);
}

.navbar-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 20px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-white);
    text-decoration: none;
    flex-shrink: 0;
    position: relative;
    letter-spacing: -0.02em;
}

.navbar-brand span {
    background: linear-gradient(135deg, #fff 0%, #e8e9f1 60%, var(--accent-primary-hover) 100%);
    background-size: 200% 100%;
    background-position: 0% 50%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: background-position 600ms var(--ease-out-quart);
}

.navbar-brand:hover {
    color: var(--text-white);
}

.navbar-brand:hover span {
    background-position: 100% 50%;
}

.navbar-brand img {
    transition: transform 400ms var(--ease-out-back),
                filter 400ms var(--ease-out-quart);
    filter: drop-shadow(0 0 8px rgba(124, 92, 255, 0.4));
}

.navbar-brand:hover img {
    transform: rotate(-8deg) scale(1.08);
    filter: drop-shadow(0 0 14px rgba(124, 92, 255, 0.8));
}

.navbar-search {
    flex: 1;
    max-width: 520px;
    position: relative;
}

.navbar-search input {
    width: 100%;
    height: 40px;
    padding: 0 16px 0 40px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition-base);
}

.navbar-search input:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

.navbar-search input:focus {
    border-color: var(--accent-primary);
    background: rgba(124, 92, 255, 0.04);
    box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.12),
                0 0 24px rgba(124, 92, 255, 0.15);
}

.navbar-search input::placeholder {
    color: var(--text-muted);
}

.navbar-search .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
    transition: color var(--transition-base);
}

.navbar-search input:focus ~ .search-icon,
.navbar-search:focus-within .search-icon {
    color: var(--accent-primary);
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.navbar-nav .nav-link {
    position: relative;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.navbar-nav .nav-link::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--grad-primary);
    transform: translateX(-50%);
    transition: width 300ms var(--ease-out-quart);
    border-radius: 2px;
}

.navbar-nav .nav-link:hover {
    color: var(--text-white);
}

.navbar-nav .nav-link:hover::before {
    width: 40%;
}

.navbar-nav .nav-link.active {
    color: var(--text-white);
}

.navbar-nav .nav-link.active::before {
    width: 60%;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

/* Browsing level dropdown (eye icon) */
.browse-level .btn-icon {
    font-size: 1.1rem;
    padding: 8px 10px;
}

.browse-level-menu {
    padding: 12px;
}

.browse-level-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 4px;
}

.browse-level-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.browse-level-item:hover:not(.disabled) {
    background: var(--bg-tertiary);
}

.browse-level-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.browse-level-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.browse-level-item.disabled .browse-level-checkbox {
    cursor: not-allowed;
}

.browse-level-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 700;
    font-size: 0.7rem;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

.browse-level-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex: 1;
}

.browse-level-warning {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.browse-level-warning a {
    color: var(--accent-warning);
    text-decoration: underline;
}

.browse-level-status {
    min-height: 18px;
    margin-top: 8px;
    padding: 0 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
}

/* User avatar in navbar */
.nav-avatar {
    position: relative;
}

.nav-avatar-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: border-color var(--transition-fast);
    background: var(--bg-card);
}

.nav-avatar-btn:hover {
    border-color: var(--accent-primary);
}

.nav-avatar-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nav-avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
}

/* Dropdown menu */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: none;
    z-index: var(--z-modal);
}

.dropdown-menu.show {
    display: block;
    animation: fadeSlideDown 0.15s ease;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-card-hover);
    color: var(--text-white);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 0;
}

.dropdown-item.danger {
    color: var(--accent-danger);
}

.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* --- Footer --- */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 40px 0 24px;
    margin-top: 60px;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 40px;
    margin-bottom: 32px;
}

.footer-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-white);
    margin-bottom: 12px;
}

.footer-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.7;
}

.footer-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-white);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
}

.footer-links a {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 4px 0;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--text-primary);
}

.footer-bottom {
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- Animations --- */
@keyframes fadeSlideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

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

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent-success); }
.text-danger { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
