/* css/index.css */

/* --- Variables & Reset --- */
:root {
    /* Palette - Modern SaaS Blue/Indigo Theme */
    --primary: #6366f1;       /* Indigo 500 */
    --primary-dark: #4f46e5;  /* Indigo 600 */
    --primary-light: #e0e7ff; /* Indigo 100 */
    
    --bg-body: #f8fafc;       /* Slate 50 */
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    
    --text-main: #1e293b;     /* Slate 800 */
    --text-muted: #64748b;    /* Slate 500 */
    --text-light: #94a3b8;    /* Slate 400 */
    
    --border: #e2e8f0;        /* Slate 200 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'Fira Code', 'Consolas', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
}

/* --- Loader --- */
.loader-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary-light);
    border-bottom-color: var(--primary);
    border-radius: 50%;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Hero Stats --- */
.hero-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border);
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card i {    font-size: 1.5rem;
    color: var(--primary);
    background: var(--primary-light);
    padding: 10px;
    border-radius: var(--radius-sm);
}

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

.stat-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Filters Section --- */
.filters-section {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0 1.5rem 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    align-items: center;
}

.search-box {
    flex: 1;
    min-width: 280px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;    padding: 0.75rem 1rem 0.75rem 2.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 1rem;
    background: var(--bg-card);
    transition: all 0.2s;
    outline: none;
}

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

.filter-group {
    display: flex;
    gap: 0.75rem;
}

select {
    padding: 0.75rem 2rem 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background-color: var(--bg-card);
    color: var(--text-main);
    font-size: 0.95rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

/* --- Main Grid Layout --- */
.main-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    padding: 0 1.5rem 3rem;
    max-width: 1200px;
    margin: 0 auto;
    align-items: start;
}
/* --- Sidebar (Trending) --- */
.sidebar {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    position: sticky;
    top: 20px;
}

.sidebar-header h3 {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.sidebar-header i {
    color: #f59e0b; /* Amber for fire */
}

.trend-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.trend-item:last-child {
    border-bottom: none;
}

.trend-item:hover .trend-name {
    color: var(--primary);
}

.trend-rank {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text-light);
    width: 24px;
    text-align: center;
}
.trend-rank.r1 { color: #fbbf24; } /* Gold */
.trend-rank.r2 { color: #94a3b8; } /* Silver */
.trend-rank.r3 { color: #b45309; } /* Bronze */

.trend-body {
    flex: 1;
    min-width: 0; /* Text truncation fix */
}

.trend-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.trend-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Content Area & Cards --- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.snippet-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.snippet-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    line-height: 1.3;
}

.snippet-lang {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    text-transform: uppercase;
}

.card-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.card-meta span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.sc-author {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: auto; /* Push to bottom */
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 500;}

.sc-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
}

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

.verified-icon {
    color: #3b82f6;
    margin-left: 0.25rem;
    font-size: 0.8rem;
}

/* --- Empty State --- */
.empty-state {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* --- Expanded View (Overlay) --- */
.expanded-area {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;    height: 100%;
    background: var(--bg-body);
    z-index: 1000;
    overflow-y: auto;
    padding: 0;
    display: none; /* Toggled by JS */
}

/* When body has expanded-mode, hide main container visually if needed, 
   but usually z-index handles it. We can also scroll lock body in JS. */
body.expanded-mode {
    overflow: hidden;
}

.expanded-snippet {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
    animation: slideUp 0.3s ease-out;
}

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

.expanded-header {
    margin-bottom: 1.5rem;
}

.back-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.back-btn:hover {
    color: var(--primary);
}

.expanded-title-section h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;    color: var(--text-main);
}

.expanded-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.lang-badge {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8rem;
}

.snippet-desc {
    background: #fff;
    padding: 1rem;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
    margin-bottom: 1.5rem;
    color: var(--text-main);
    line-height: 1.6;
}

.expanded-stats {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;    font-weight: 500;
    color: var(--text-muted);
}

.stat-item i { color: var(--primary); }

/* Code Block Styling */
.expanded-code {
    background: #282c34; /* Atom One Dark BG */
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.code-header {
    background: #21252b;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #3e4451;
}

.code-filename {
    color: #abb2bf;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #abb2bf;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;}

.action-btn:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.action-btn.copy-btn:hover { background: #2ea44f; color: white; }
.action-btn.down-btn:hover { background: #0366d6; color: white; }
.action-btn.share-btn:hover { background: #6f42c1; color: white; }
.action-btn.like-btn:hover { background: #e0245e; color: white; }

.expanded-code pre {
    margin: 0;
    padding: 1.5rem;
    overflow-x: auto;
}

.expanded-code code {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Comments Section */
.expanded-comments {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.comments-header h3 {
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.add-comment-box {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.comment-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);    border-radius: var(--radius-full);
    outline: none;
    font-family: inherit;
}

.comment-input:focus {
    border-color: var(--primary);
}

.send-comment-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-comment-btn:hover {
    background: var(--primary-dark);
}

.single-comment {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.single-comment:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.comment-header strong {
    color: var(--text-main);
    display: flex;
    align-items: center;    gap: 0.4rem;
}

.comment-header span {
    color: var(--text-light);
    font-size: 0.8rem;
}

.single-comment p {
    color: var(--text-main);
    font-size: 0.95rem;
    line-height: 1.5;
}

.no-comments {
    text-align: center;
    color: var(--text-light);
    font-style: italic;
    padding: 1rem;
}

/* Preview Modal */
.preview-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.preview-modal > div {
    background: var(--bg-card);
    width: 100%;
    max-width: 800px;
    height: 80vh;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.preview-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;    justify-content: space-between;
    align-items: center;
    background: #f1f5f9;
}

.preview-header h3 {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

.preview-body {
    flex: 1;
    overflow: auto;
    position: relative;
}

.html-preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.json-preview {
    padding: 1.5rem;
    margin: 0;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    height: 100%;
}

/* Toast Notification */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    animation: fadeInUp 0.3s ease;
    pointer-events: auto;
}

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

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
        padding: 0 1rem 2rem;
    }

    .sidebar {
        order: -1; /* Move sidebar to top on mobile? Or keep bottom? Let's keep top for trending */
        position: static;
        margin-bottom: 1rem;
    }
    
    .sidebar-header h3 {
        font-size: 1rem;
    }

    .hero-stats {
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
    }

    .filters-section {
        padding: 0 1rem 1rem;        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    select {
        flex: 1;
    }

    .cards-grid {
        grid-template-columns: 1fr; /* Single column on mobile */
    }

    .expanded-snippet {
        padding: 1rem;
    }

    .code-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    
    .action-btn span {
        display: none; /* Hide text on small screens, show icons only */
    }
    
    .action-btn {
        padding: 0.5rem;
    }
}