/* =========================================
   1. CORE VARIABLES & THEME
   ========================================= */
:root {
    /* Neural Palette */
    --bg-body: #F8FAFC;
    --bg-sidebar: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-header: rgba(255, 255, 255, 0.85);

    --primary: #2563EB;
    /* Electric Blue */
    --primary-hover: #1D4ED8;
    --primary-light: #EFF6FF;

    --text-main: #0F172A;
    /* Slate 900 */
    --text-muted: #64748B;
    /* Slate 500 */
    --border: #E2E8F0;
    /* Slate 200 */

    /* Subsidiary Brand Identities */
    --brand-labs: #9333EA;
    /* Purple */
    --brand-labs-bg: #FAF5FF;

    --brand-kernel: #10B981;
    /* Emerald */
    --brand-kernel-bg: #ECFDF5;

    --brand-tech: #3B82F6;
    /* Blue */
    --brand-tech-bg: #EFF6FF;

    --brand-edge: #F59E0B;
    /* Amber */
    --brand-edge-bg: #FFFBEB;

    --brand-media: #DB2777;
    /* Pink */
    --brand-media-bg: #FDF2F8;

    /* Status Indicators */
    --stat-live-bg: #DCFCE7;
    --stat-live-text: #15803D;
    --stat-beta-bg: #FEF9C3;
    --stat-beta-text: #A16207;
    --stat-dev-bg: #F1F5F9;
    --stat-dev-text: #475569;
    --stat-research-bg: #F3E8FF;
    --stat-research-text: #7E22CE;

    /* Metrics */
    --sidebar-width: 280px;
    --header-height: 70px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #0F172A;
        --bg-sidebar: #1E293B;
        --bg-card: #1E293B;
        --bg-header: rgba(30, 41, 59, 0.85);
        --text-main: #F8FAFC;
        --text-muted: #94A3B8;
        --border: #334155;
        --primary-light: rgba(37, 99, 235, 0.15);
    }
}

/* Resets */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow: hidden;
    /* App-like structure */
    height: 100vh;
}

/* Background Effects */
.noise-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.03;
    background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');
}

.blob {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    z-index: -1;
    animation: float 20s infinite alternate;
}

.blob-1 {
    top: -200px;
    left: -200px;
    background: var(--brand-labs);
}

.blob-2 {
    bottom: -200px;
    right: -200px;
    background: var(--brand-tech);
    animation-delay: -10s;
}

@keyframes float {
    from {
        transform: translate(0, 0);
    }

    to {
        transform: translate(50px, 50px);
    }
}

/* =========================================
   2. LAYOUT ENGINE
   ========================================= */
.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* =========================================
   3. SIDEBAR NAVIGATION
   ========================================= */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    /* FIX: Ensure robust height for scrolling */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    z-index: 50;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.brand-text {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
}

.brand-text .highlight {
    color: var(--primary);
}

.nav-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    /* FIX: Nested scroll visibility quirks */
    min-height: 0;
    padding-bottom: 4rem;
    /* Extra space at bottom */
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.nav-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.75rem;
    margin-top: 1.5rem;
    padding-left: 12px;
}

.nav-category:first-child {
    margin-top: 0;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: none;
    border: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

/* Sidebar Card */
.nav-card {
    margin-top: 2rem;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    color: white;
}

.nav-card-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.nav-card h4 {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.nav-card p {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 1rem;
    line-height: 1.4;
}

.nav-card-btn {
    display: block;
    width: 100%;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 8px;
    font-size: 0.8rem;
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: 0.2s;
}

.nav-card-btn:hover {
    background: white;
    color: #0F172A;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    flex-shrink: 0;
    margin-top: auto;
    /* Push to bottom if content is short */
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--bg-body);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info .name {
    font-weight: 600;
    font-size: 0.85rem;
}

.user-info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =========================================
   4. MAIN VIEW & HEADER
   ========================================= */
.main-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.topbar {
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(var(--blur));
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: relative;
    z-index: 40;
}

.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 480px;
}

.search-wrapper i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-wrapper input {
    width: 100%;
    padding: 10px 16px 10px 44px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-body);
    font-size: 0.9rem;
    color: var(--text-main);
    transition: 0.2s;
}

.search-wrapper input:focus {
    background: var(--bg-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.shortcut-hint {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    background: var(--bg-card);
    pointer-events: none;
}

.github-btn {
    background: #24292e;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}

.github-btn:hover {
    background: black;
    transform: translateY(-1px);
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    scroll-behavior: smooth;
}

/* =========================================
   5. CAROUSEL & CONTROLS
   ========================================= */
.featured-carousel {
    margin-bottom: 2rem;
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    min-height: 280px;
    /* Prevent layout shift */
}

.featured-track {
    display: flex;
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    height: 100%;
}

.carousel-slide {
    min-width: 100%;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    padding: 3rem;
    color: white;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.slide-content {
    max-width: 60%;
    position: relative;
    z-index: 2;
}

.slide-badge {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    display: inline-block;
}

.slide-title {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
    line-height: 1.1;
}

.slide-desc {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 2rem;
    max-width: 500px;
}

.slide-bg-icon {
    position: absolute;
    right: -30px;
    bottom: -50px;
    font-size: 16rem;
    color: rgba(255, 255, 255, 0.05);
    transform: rotate(-15deg);
    z-index: 1;
    pointer-events: none;
}

.carousel-controls {
    position: absolute;
    bottom: 20px;
    right: 30px;
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 10;
}

.c-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.c-btn:hover {
    background: white;
    color: black;
}

.c-dots {
    display: flex;
    gap: 6px;
    margin: 0 10px;
}

.dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
}

.dot.active {
    background: white;
    transform: scale(1.2);
}

/* Grid Controls */
.grid-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.tabs {
    display: flex;
    gap: 4px;
    background: white;
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.tab-btn {
    padding: 6px 16px;
    border: none;
    background: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--bg-body);
    color: var(--primary);
}

.view-meta {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.view-meta .divider {
    margin: 0 8px;
    opacity: 0.3;
}

/* =========================================
   6. PRODUCTS GRID
   ========================================= */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.app-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.app-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
}

.card-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.icon-box {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: 0.3s;
}

/* Category Specific Icons */
.icon-ai {
    background: var(--brand-labs-bg);
    color: var(--brand-labs);
}

.icon-webapp {
    background: var(--brand-kernel-bg);
    color: var(--brand-kernel);
}

.icon-software {
    background: var(--brand-tech-bg);
    color: var(--brand-tech);
}

.icon-media {
    background: var(--brand-media-bg);
    color: var(--brand-media);
}

.icon-api {
    background: var(--brand-edge-bg);
    color: var(--brand-edge);
}

.icon-quantum {
    background: #F3E8FF;
    color: #7E22CE;
}

.icon-electronics {
    background: #FFF7ED;
    color: #EA580C;
}

/* Resource Cards Styling */
.resource-card {
    background: white;
    border-left: 4px solid var(--text-muted);
    border-radius: 8px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-left-width: 4px;
}

.resource-icon {
    background: #F1F5F9;
    color: #475569;
}

.status-pill {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    height: fit-content;
    text-transform: uppercase;
}

.stat-live {
    background: var(--stat-live-bg);
    color: var(--stat-live-text);
}

.stat-beta {
    background: var(--stat-beta-bg);
    color: var(--stat-beta-text);
}

.stat-in-development,
.stat-alpha {
    background: var(--stat-dev-bg);
    color: var(--stat-dev-text);
}

.meta h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.meta p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Developer Badges */
.dev-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.dev-jaiho-labs {
    background: var(--brand-labs-bg);
    color: var(--brand-labs);
}

.dev-jaiho-kernel {
    background: var(--brand-kernel-bg);
    color: var(--brand-kernel);
}

.dev-jaiho-techserve {
    background: var(--brand-tech-bg);
    color: var(--brand-tech);
}

.dev-jaiho-media {
    background: var(--brand-media-bg);
    color: var(--brand-media);
}

.dev-jaiho-edge {
    background: var(--brand-edge-bg);
    color: var(--brand-edge);
}

.launch-btn {
    margin-top: auto;
    padding: 10px;
    border-radius: 6px;
    background: var(--bg-body);
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    text-align: center;
    transition: 0.2s;
}

.app-card:hover .launch-btn {
    background: var(--primary);
    color: white;
}

.hub-footer {
    text-align: center;
    padding: 3rem 0 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    opacity: 0.7;
}

/* =========================================
   7. MODAL SYSTEM
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s ease;
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 850px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95) translateY(20px);
    transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-hero {
    background: linear-gradient(to right, #f8fafc, #ffffff);
    padding: 2.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.close-modal {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1.1rem;
}

.close-modal:hover {
    background: #EF4444;
    color: white;
}

.modal-icon-lg {
    width: 80px;
    height: 80px;
    border-radius: 16px;
    background: white;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
}

.modal-badges {
    display: flex;
    gap: 10px;
    margin-bottom: 0.5rem;
}

.modal-tagline {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.modal-body-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    min-height: 400px;
}

.modal-main {
    padding: 2.5rem;
    border-right: 1px solid var(--border);
}

.modal-main h3 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.modal-main p {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-main);
    margin-bottom: 2rem;
}

.feature-list {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.feature-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-main);
}

.feature-list li::before {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    color: var(--primary);
    font-size: 0.9rem;
    margin-top: 3px;
}

.modal-sidebar {
    padding: 2.5rem;
    background: #F8FAFC;
}

.info-block {
    margin-bottom: 1.5rem;
}

.info-block label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.info-value.mono {
    font-family: 'JetBrains Mono', monospace;
    background: #E2E8F0;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.tech-stack-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tech-tag {
    background: white;
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.action-btn {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    text-align: center;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 700;
    margin-top: 2rem;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
    transition: 0.2s;
}

.action-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* =========================================
   8. MOBILE RESPONSIVENESS
   ========================================= */
.menu-toggle,
.close-sidebar {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 280px;
        /* FIX: Mobile height again */
        height: 100vh;
        height: 100dvh;
        transition: 0.3s ease;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
        z-index: 50;
    }

    .sidebar.active {
        left: 0;
    }

    .menu-toggle {
        display: block;
        background: none;
        border: none;
        font-size: 1.25rem;
        color: var(--text-muted);
        cursor: pointer;
    }

    .close-sidebar {
        display: block;
        background: none;
        border: none;
        font-size: 1.25rem;
        cursor: pointer;
        color: var(--text-muted);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 45;
        /* Below sidebar (50) */
        opacity: 0;
        pointer-events: none;
        transition: 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    .modal-body-grid {
        grid-template-columns: 1fr;
    }

    .modal-main {
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 1.5rem;
    }

    .modal-sidebar {
        padding: 1.5rem;
    }
}

@media (max-width: 640px) {
    .feature-list {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: 0 1rem;
    }

    .content-body {
        padding: 1rem;
    }

    .featured-banner {
        flex-direction: column;
        text-align: center;
        padding: 2rem 1.5rem;
    }

    .banner-content {
        max-width: 100%;
    }

    .banner-bg-icon {
        font-size: 8rem;
        right: -10px;
        bottom: -10px;
    }

    .slide-title {
        font-size: 1.5rem;
    }

    .app-grid {
        grid-template-columns: 1fr;
    }
}