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

:root {
    --bg-color: #1e1e1e;
    --bg-secondary: #252525;
    --comfy-input-bg: #2a2a2a;
    --comfy-menu-bg: #222;
    --comfy-menu-secondary-bg: #2a2a2a;
    --fg-color: #ddd;
    --fg-secondary: #aaa;
    --fg-muted: #777;
    --border-color: #3a3a3a;
    --accent: #4a9eff;
    --accent-hover: #5aadff;
    --accent-dim: rgba(74, 158, 255, 0.15);
    --green: #4caf50;
    --orange: #ff9800;
    --pink: #e91e8f;
    --radius: 8px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--fg-color);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
    position: sticky; top: 0; z-index: 100;
    background: var(--comfy-menu-bg);
    border-bottom: 1px solid var(--border-color);
}
.header-inner {
    max-width: 1400px; margin: 0 auto;
    padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-icon { font-size: 26px; }
.logo-text { font-size: 21px; font-weight: 700; color: var(--fg-color); letter-spacing: -0.3px; }

.header-right {
    display: flex; align-items: center; gap: 14px;
}
.header-divider {
    width: 1px; height: 18px;
    background: var(--border-color);
}

/* Search hero section */
.search-hero {
    background: var(--comfy-menu-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 18px 24px 20px;
}
.search-hero-inner {
    max-width: 640px; margin: 0 auto; text-align: center;
}
.search-hero-subtitle {
    font-size: 13px; color: var(--fg-muted); margin: 0 0 12px;
    letter-spacing: 0.3px;
}

.search-box { position: relative; width: 100%; }
.search-box input {
    width: 100%; padding: 11px 16px 11px 42px;
    background: var(--comfy-input-bg); border: 1px solid var(--border-color);
    border-radius: 10px; color: var(--fg-color);
    font-size: 15px; outline: none; transition: var(--transition);
}
.search-box input::placeholder { color: var(--fg-muted); }
.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.search-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--fg-muted);
}
.search-kbd {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    padding: 2px 6px; font-size: 11px; color: var(--fg-muted);
    background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 4px; font-family: inherit;
}

.header-stats {
    font-size: 13px; color: var(--fg-secondary); flex-shrink: 0;
    display: flex; align-items: center;
}
.header-stats span { color: var(--accent); font-weight: 600; }
.github-link {
    color: var(--fg-muted); transition: var(--transition);
    display: flex; align-items: center;
}
.github-link:hover { color: var(--fg-color); }

/* ===== Layout Wrapper ===== */
.layout-wrapper {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    position: relative;
}
.main-content {
    flex: 1;
    min-width: 0;
    transition: margin-left 0.3s ease;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 53px;
    height: calc(100vh - 53px);
    overflow-y: auto;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease, opacity 0.3s ease;
    z-index: 98;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    opacity: 0;
    border-right: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--fg-color);
}
.sidebar-toggle {
    width: 28px; height: 28px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--fg-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.sidebar-toggle:hover {
    background: var(--comfy-input-bg);
    color: var(--fg-color);
}

.sidebar-expand {
    display: none;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 98;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 10px 8px;
    color: var(--fg-muted);
    cursor: pointer;
    transition: var(--transition);
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-family: inherit;
}
.sidebar-expand span {
    writing-mode: vertical-rl;
    text-orientation: mixed;
}
.sidebar-expand:hover {
    background: var(--comfy-input-bg);
    color: var(--fg-color);
}
.sidebar.collapsed ~ .sidebar-expand {
    display: flex;
}

/* Sidebar sections */
.sidebar-section {
    padding: 6px 12px;
}
.sidebar-section .filter-tag {
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 2px;
}
.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}
.sidebar-section-title:hover { color: var(--fg-secondary); }
.sidebar-section-title .collapse-arrow {
    transition: transform 0.2s ease;
}
.sidebar-section-title.collapsed .collapse-arrow {
    transform: rotate(-90deg);
}
.sidebar-section-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}
.sidebar-section-body.collapsed {
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
}

.sidebar .filter-clear {
    margin: 12px;
    width: calc(100% - 24px);
    text-align: center;
    justify-content: center;
}

/* ===== Mobile Filter ===== */
.mobile-filter-btn {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 150;
    padding: 10px 16px;
    border-radius: 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(74, 158, 255, 0.4);
    transition: var(--transition);
    align-items: center;
    gap: 6px;
}
.mobile-filter-btn:hover { background: var(--accent-hover); }

.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.drawer-overlay.active {
    opacity: 1;
}

/* Mobile: sidebar becomes bottom drawer */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        height: auto;
        max-height: 70vh;
        border-right: none;
        border-top: 1px solid var(--border-color);
        border-radius: 16px 16px 0 0;
        z-index: 200;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
    }
    .sidebar.mobile-open {
        transform: translateY(0);
    }
    .sidebar.collapsed {
        width: 100% !important;
        opacity: 1;
        transform: translateY(100%);
    }
    .sidebar-expand { display: none !important; }
    .sidebar-toggle svg {
        transform: rotate(-90deg);
    }
    .mobile-filter-btn { display: flex; }
    .drawer-overlay { display: block; }
    .layout-wrapper { flex-direction: column; }
}
.filter-tag {
    display: flex; align-items: center; gap: 5px;
    padding: 5px 12px; border-radius: var(--radius-sm);
    background: transparent; border: 1px solid transparent;
    color: var(--fg-secondary); font-size: 14px;
    cursor: pointer; transition: var(--transition);
    white-space: nowrap; font-family: inherit;
}
.filter-tag:hover {
    background: var(--comfy-input-bg);
    color: var(--fg-color);
}
.filter-tag.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}
.tag-dot {
    width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}

/* ===== Gallery Grid ===== */
.gallery {
    margin: 0 auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
@media (max-width: 1200px) { .gallery { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .gallery { grid-template-columns: repeat(2, 1fr); padding: 12px; gap: 10px; } }
@media (max-width: 480px) { .gallery { grid-template-columns: 1fr; } }

/* ===== Card ===== */
.card {
    background: var(--comfy-input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden; cursor: pointer;
    transition: var(--transition);
}
.card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-image-wrap {
    position: relative; width: 100%;
    padding-top: 75%;
    overflow: hidden;
    background: var(--bg-color);
}
.card-image {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    transition: transform 0.3s ease;
}
.card:hover .card-image { transform: scale(1.03); }

.card-body { padding: 10px 12px 6px; }
.card-prompt {
    font-size: 13px; color: var(--fg-secondary);
    line-height: 1.5; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    padding: 6px 12px 10px;
    display: flex; align-items: center; justify-content: space-between;
}
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.card-tag {
    font-size: 11px; padding: 2px 6px;
    border-radius: 3px; background: var(--bg-color);
    color: var(--fg-muted);
}
.card-meta {
    display: flex; align-items: center; gap: 6px;
    font-size: 11px; color: var(--fg-muted);
}
.card-author { color: var(--accent); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0, 0, 0, 0.7);
    display: flex; align-items: center; justify-content: center;
    padding: 20px; opacity: 0; visibility: hidden;
    transition: var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    width: 100%; max-width: 900px; max-height: 88vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden; position: relative;
    transform: translateY(10px);
    transition: var(--transition);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.modal-overlay.active .modal { transform: translateY(0); }

.modal-close {
    position: absolute; top: 12px; right: 12px; z-index: 10;
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    background: var(--comfy-input-bg); border: 1px solid var(--border-color);
    color: var(--fg-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--border-color); color: var(--fg-color); }

.modal-body {
    display: grid; grid-template-columns: 1fr 1fr;
    max-height: 88vh; overflow-y: auto;
}
@media (max-width: 768px) { .modal-body { grid-template-columns: 1fr; } }

.modal-image-wrap {
    background: var(--bg-color);
    display: flex; align-items: center; justify-content: center;
    min-height: 280px;
}
.modal-image-wrap img { width: 100%; height: 100%; object-fit: contain; }

.modal-content { padding: 24px; overflow-y: auto; }

.modal-meta {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 14px; flex-wrap: wrap;
}
.modal-author { font-size: 15px; font-weight: 600; color: var(--accent); }
.modal-tool {
    font-size: 12px; padding: 2px 8px;
    border-radius: 4px; background: var(--accent-dim);
    color: var(--accent);
}
.modal-date { font-size: 13px; color: var(--fg-muted); }

.modal-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.modal-tag-item {
    font-size: 12px; padding: 3px 8px;
    border-radius: 4px; background: var(--comfy-input-bg);
    color: var(--fg-secondary); border: 1px solid var(--border-color);
}

.modal-prompt-wrap {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden; margin-bottom: 14px;
}
.modal-prompt-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px; color: var(--fg-secondary);
}
.copy-btn {
    display: flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 4px;
    background: var(--comfy-input-bg); border: 1px solid var(--border-color);
    color: var(--fg-secondary); font-size: 12px;
    cursor: pointer; transition: var(--transition); font-family: inherit;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

.copy-link-btn {
    display: flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 4px;
    background: var(--comfy-input-bg); border: 1px solid var(--border-color);
    color: var(--fg-secondary); font-size: 12px;
    cursor: pointer; transition: var(--transition); font-family: inherit;
}
.copy-link-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-link-btn.copied { color: var(--green); border-color: var(--green); }

.modal-prompt {
    padding: 12px; margin: 0;
    font-size: 13px; line-height: 1.7;
    color: var(--fg-color);
    white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
    max-height: 260px; overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.modal-prompt::-webkit-scrollbar { width: 4px; }
.modal-prompt::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.modal-source {
    display: inline-flex; align-items: center;
    font-size: 12px; color: var(--accent);
    text-decoration: none; transition: var(--transition);
}
.modal-source:hover { color: var(--accent-hover); }

/* ===== Share Bar & Buttons ===== */
.modal-share-bar {
    display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap; padding-top: 4px;
}
.share-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 6px;
    background: var(--comfy-input-bg); border: 1px solid var(--border-color);
    color: var(--fg-secondary); font-size: 13px;
    cursor: pointer; transition: var(--transition);
    font-family: inherit; white-space: nowrap;
}
.share-btn:hover {
    border-color: var(--accent); color: var(--fg-color);
    background: var(--accent-dim);
}
.share-btn svg { flex-shrink: 0; }

.share-btn-copy:hover { border-color: var(--accent); color: var(--accent); }
.share-btn-copy.copied { border-color: var(--green); color: var(--green); }

.share-btn-twitter:hover {
    border-color: #1d9bf0; color: #1d9bf0;
    background: rgba(29, 155, 240, 0.1);
}

.share-btn-share:hover {
    border-color: var(--accent); color: var(--accent);
}

.modal-share-bar .modal-source {
    margin-left: auto;
}

@media (max-width: 768px) {
    .share-btn { padding: 6px 10px; font-size: 12px; }
    .share-btn span { display: none; }
    .modal-share-bar { gap: 6px; }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--fg-muted);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== Footer ===== */
.footer {
    text-align: center; padding: 30px 20px;
    border-top: 1px solid var(--border-color);
    color: var(--fg-muted); font-size: 12px;
}
.footer-sub { margin-top: 4px; font-size: 11px; opacity: 0.6; }
.footer-sub a { color: var(--accent); text-decoration: none; }
.footer-sub a:hover { text-decoration: underline; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ===== Animation ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.card { animation: fadeIn 0.3s ease both; }

/* ===== Back to Top ===== */
.back-to-top {
    position: fixed; bottom: 30px; right: 30px; z-index: 150;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--accent); border: none;
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(74, 158, 255, 0.3);
    opacity: 0; visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
}
.back-to-top.visible {
    opacity: 1; visibility: visible;
    transform: translateY(0);
}
.back-to-top:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(74, 158, 255, 0.4);
}

/* ===== Mobile Header ===== */
@media (max-width: 768px) {
    .header-inner { padding: 10px 14px; }
    .logo-text { font-size: 17px; }
    .logo-icon { font-size: 22px; }
    .search-hero { padding: 12px 14px 14px; }
    .search-hero-subtitle { font-size: 12px; margin-bottom: 8px; }
    .search-kbd { display: none; }
    .filter-bar { top: 90px; }
    .modal-image-wrap { min-height: 200px; max-height: 50vh; }
}

@media (max-width: 480px) {
    .header-inner { padding: 8px 12px; }
    .search-hero { padding: 10px 12px 12px; }
    .filter-inner { padding: 8px 12px; }
}

/* ===== Filter scroll hint ===== */
.filter-bar {
    position: relative;
}
.filter-bar::after {
    content: '';
    position: absolute; right: 0; top: 0; bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--bg-secondary));
    pointer-events: none;
    z-index: 1;
}

/* ===== Card tag colors ===== */
.card-tag[data-color] {
    border-left: 2px solid var(--tag-color, var(--fg-muted));
}

/* ===== NEW Badge ===== */
.card-badge-new {
    position: absolute; top: 8px; right: 8px; z-index: 2;
    padding: 2px 8px; border-radius: 4px;
    background: var(--green); color: #fff;
    font-size: 11px; font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(76, 175, 80, 0.4);
}

/* ===== Loading Spinner ===== */
.loading-spinner {
    display: flex; align-items: center; justify-content: center;
    padding: 80px 20px; flex-direction: column; gap: 16px;
}
.loading-spinner .spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loading-spinner .spinner-text {
    font-size: 14px; color: var(--fg-muted);
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Clear Filter Button ===== */
.filter-clear {
    display: none; align-items: center; gap: 4px;
    padding: 5px 12px; border-radius: var(--radius-sm);
    background: rgba(255, 82, 82, 0.1); border: 1px solid rgba(255, 82, 82, 0.3);
    color: #ff5252; font-size: 13px;
    cursor: pointer; transition: var(--transition);
    white-space: nowrap; font-family: inherit; flex-shrink: 0;
}
.filter-clear:hover {
    background: rgba(255, 82, 82, 0.2);
    border-color: #ff5252;
}
.filter-clear.visible { display: flex; }

/* ===== Modal Navigation Buttons ===== */
.modal-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    z-index: 10; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.15);
    color: #fff; border-radius: 50%; width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: var(--transition); opacity: 0.7;
}
.modal-nav:hover { opacity: 1; background: rgba(99,102,241,0.6); }
.modal-nav-prev { left: -56px; }
.modal-nav-next { right: -56px; }
@media (max-width: 768px) {
    .modal-nav-prev { left: 8px; }
    .modal-nav-next { right: 8px; }
    .modal-nav { width: 36px; height: 36px; opacity: 0.85; }
}
