:root {
    --bg-color: #0d1117;
    --panel-bg: rgba(22, 27, 34, 0.8);
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent-color: #58a6ff;
    --sidebar-width-min: 70px;
    --sidebar-width-max: 260px;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --glass-effect: blur(12px) saturate(180%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: visible;
}

/* --- Expanding Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width-min);
    background: var(--panel-bg);
    backdrop-filter: var(--glass-effect);
    border-right: 1px solid var(--border-color);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow: hidden;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 0 20px 20px 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    overflow: hidden;
}

.brand-logo {
    min-width: 38px;
    width: 38px;
    height: 38px;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 5px rgba(88, 166, 255, 0.3));
}

.brand-name {
    font-size: 1.4rem;
    font-weight: 900;
    color: #fff;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.3s, transform 0.3s;
    letter-spacing: -0.5px;
}

.sidebar:hover .brand-name {
    opacity: 1;
    transform: translateX(0);
}

.sidebar:hover {
    width: var(--sidebar-width-max);
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 15px 22px;
    color: var(--text-secondary);
    transition: color 0.2s, background 0.2s;
    text-decoration: none;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-icon {
    min-width: 24px;
    margin-right: 25px;
    display: flex;
    justify-content: center;
}

.nav-text {
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .nav-text {
    opacity: 1;
}

/* --- Main Content Area --- */
.main-content {
    margin-left: var(--sidebar-width-min);
    flex-grow: 1;
    padding: 0 40px 40px 40px;
    min-height: 100vh;
    /* Removed fixed height and independent scroll */
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(13, 17, 23, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 20px 0;
    margin-bottom: 20px;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* --- Branding & Donation --- */
.credits-box {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.3;
    text-align: right;
    max-width: 120px;
    font-weight: 500;
    opacity: 0.8;
}

.credits-box a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 700;
}

.credits-box a:hover {
    text-decoration: underline;
}

.btn-bmc {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.btn-bmc i {
    font-size: 1rem;
    color: #FFDD00;
    /* Only icon has the coffee color */
}

.btn-bmc:hover {
    background: rgba(255, 221, 0, 0.1);
    border-color: rgba(255, 221, 0, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.btn-bmc:active {
    transform: translateY(0);
}


/* --- Dashboard Grid (CSS Masonry) --- */
.grid-container {
    margin-top: 30px;
    width: 100%;
    display: block; /* Changed from grid to block for columns */
    column-gap: 20px;
}

/* Size Classes (Columns) */
.grid-s {
    column-count: 5;
}

.grid-m {
    column-count: 3;
}

.grid-l {
    column-count: 2;
}

@media (max-width: 1200px) {
    .grid-s {
        column-count: 4;
    }

    .grid-m {
        column-count: 2;
    }
}

@media (max-width: 800px) {
    .grid-s {
        column-count: 2;
    }

    .grid-m {
        column-count: 1;
    }

    .grid-l {
        column-count: 1;
    }
}

/* --- Profile Grid (CSS Grid specific) --- */
.profile-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    column-count: unset !important;
    gap: 20px;
}

.profile-grid .card {
    width: 100%;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

@media (max-width: 1100px) {
    .profile-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 700px) {
    .profile-grid {
        grid-template-columns: 1fr !important;
    }
}

/* --- Search Bar --- */
.search-container {
    position: relative;
    width: 400px;
    margin-right: 20px;
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
    pointer-events: none;
    transition: color 0.3s;
}

#searchInput {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 100px;
    padding: 12px 20px 12px 48px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

#searchInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
    transition: opacity 0.3s;
}

#searchInput:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(88, 166, 255, 0.3);
    box-shadow: 0 0 20px rgba(88, 166, 255, 0.1), inset 0 0 10px rgba(255, 255, 255, 0.02);
    width: 450px;
    /* Slight expansion for "premium" feel */
}

#searchInput:focus+.search-icon {
    color: var(--accent-color);
}

#searchInput:focus::placeholder {
    opacity: 0.3;
}

/* --- Resize Slider --- */
.resize-container {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px 15px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.resize-label {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.slider-wrapper {
    position: relative;
    width: 80px;
    padding-top: 5px;
}

.size-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-color);
    transition: 0.2s;
}

/* --- Cards --- */
.card {
    display: block;
    width: 100%;
    margin-bottom: 20px; /* Added for masonry spacing */
    background: transparent;
    border: none;
    border-radius: 12px;
    perspective: 1000px;
    cursor: pointer;
    break-inside: avoid; /* Essential for masonry */
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: relative;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border: 1px solid var(--border-color);
    background: var(--panel-bg);
    box-shadow: var(--card-shadow);
    border-radius: 12px;
}

.card:not(.flipped) .card-back,
.card.flipped .card-front {
    pointer-events: none;
    /* Isolate clicks to the active face */
}

.card-back {
    position: absolute;
    top: 0;
    left: 0;
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: rgba(13, 17, 23, 0.95);
    backdrop-filter: var(--glass-effect);
    min-height: 200px;
}

.card-front:hover {
    border-color: var(--accent-color);
}

.card-image-container {
    width: 100%;
    background: #161b22;
    overflow: hidden;
    line-height: 0;
}

.card-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    transition: transform 0.5s;
}

.card-body {
    padding: 15px;
}

.card-author-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 10;
}

.header-actions {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.author-info {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.author-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
}

.author-name {
    font-size: 0.8rem;
    font-weight: 800;
}

.author-handle {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.heart-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

.heart-btn.liked {
    color: #ff4b2b;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent-color);
    border: 1px solid rgba(88, 166, 255, 0.2);
}

/* --- Card Back Header & Copy Controls --- */
.card-back-header {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    z-index: 10;
}

.copy-box {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.copy-label {
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1.5px;
    white-space: nowrap;
    line-height: 1;
    display: flex;
    align-items: center;
}

.copy-btns {
    display: flex;
    flex-direction: row;
    gap: 6px;
}

.mini-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 0.6rem;
    font-weight: 900;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    text-transform: uppercase;
    min-width: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay-copy {
    position: absolute;
    top: 70px;
    /* Moved higher per feedback */
    right: 10px;
    /* Moved closer to right edge */
    z-index: 20;
    background: rgba(13, 17, 23, 0.7) !important;
    backdrop-filter: blur(8px);
    width: 60px;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.overlay-copy:hover {
    background: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
}

.mini-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.mini-btn.btn-json {
    color: var(--accent-color);
}

.mini-btn.btn-text {
    color: #aff5b4;
}

.mini-btn.btn-json:hover {
    background: var(--accent-color);
    color: #fff;
}

.mini-btn.btn-text:hover {
    background: #00ba7c;
    color: #fff;
}

.prompt-detail {
    flex-grow: 1;
    overflow-y: auto;
    line-height: 1.6;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-family: monospace;
    white-space: pre-wrap;
    font-size: 0.85rem;
}

/* --- Admin Tools --- */
.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(218, 54, 51, 0.1);
    color: #ff7b72;
    border: 1px solid rgba(218, 54, 51, 0.2);
    padding: 8px 16px;
    border-radius: 12px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: 0.2s;
}

.btn-logout:hover {
    background: #da3633;
    color: #fff;
    border-color: #da3633;
}

.btn-magic-action {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    transition: 0.3s;
}

/* --- Admin Card Controls (On Front) --- */
.admin-card-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.admin-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.admin-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

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

.btn-delete:hover {
    color: #ff7b72;
    border-color: #da3633;
    background: rgba(218, 54, 51, 0.1);
}

/* --- Edit Lightbox --- */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.lightbox-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-content {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    width: 90%;
    max-width: 600px;
    padding: 30px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.lightbox-header {
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 15px;
}

.lightbox-title {
    font-size: 1.25rem;
    font-weight: 900;
    color: #fff;
}

.edit-textarea {
    width: 100%;
    height: 350px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    padding: 15px;
    font-family: monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
}

.edit-textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.lightbox-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 25px;
}

.btn-lightbox {
    padding: 10px 25px;
    border-radius: 10px;
    font-weight: 800;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.9rem;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-save {
    background: var(--accent-color);
    border: 1px solid var(--accent-color);
    color: #fff;
}

.btn-save:hover {
    filter: brightness(1.2);
    transform: translateY(-1px);
}

/* AI Magic Buttons */
.btn-magic-action {
    background: linear-gradient(135deg, #FF3D77 0%, #338AFF 100%);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(51, 138, 255, 0.3);
}

.btn-magic-action:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(51, 138, 255, 0.5);
}

.btn-magic-action:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

/* Interactive Tag Input */
.tags-input-container {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    min-height: 46px;
    /* Matches input height */
    cursor: text;
    margin-top: 10px;
    transition: border-color 0.2s;
}

.tags-input-container:focus-within {
    border-color: var(--accent-color);
}

.btn-magic-tag {
    background: transparent;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.btn-magic-tag:hover {
    opacity: 1;
    background: rgba(88, 166, 255, 0.1);
    transform: scale(1.1);
}

.tag-input-field {
    background: transparent;
    border: none;
    color: #e6edf3;
    flex-grow: 1;
    min-width: 100px;
    outline: none;
    font-size: 0.9rem;
}

/* Updated Top Filter Nav */
.top-filter-nav {
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px;
    border-radius: 8px;
    display: inline-flex;
    margin-left: 20px;
}

.top-filter-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.top-filter-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.top-filter-nav a.active {
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent-color);
    font-weight: 600;
}



/* User-added tags in the edit box */
.editable-tag {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 2px 8px;
    padding-right: 24px;
    /* Space for X */
    font-size: 0.85rem;
    color: #fff;
    position: relative;
    display: inline-flex;
    align-items: center;
}

.editable-tag .tag-close {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    opacity: 0.6;
    border-radius: 50%;
}

.editable-tag .tag-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
    color: #ff7b72;
}

/* Categories / Tag Pills */
.badges-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
    /* Spacing from type badge */
}

.tag-pill {
    font-size: 0.65rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 3px 10px;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s ease;
    font-weight: 600;
}

.tag-pill:hover {
    color: #fff;
    background: var(--accent-color);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.card.removing {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.5s ease;
    pointer-events: none;
}

.source-link {
    color: var(--text-secondary);
    font-size: 1.1rem;
    padding: 8px;
    margin-right: 5px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.source-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.btn-copy-link {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.btn-copy-link:hover {
    background: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
}