/* Global Reset & Base Styles */
:root {
    --bg-color: #050505;
    --card-bg: rgba(20, 20, 20, 0.8);
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --secondary: #111111;
    --secondary-hover: #222222;
    --text-main: #FFFFFF;
    --text-muted: #A1A1AA;
    --border: rgba(255, 255, 255, 0.08);
    --success: #10B981;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    --glow: 0 0 20px rgba(59, 130, 246, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: row;
    /* Changed to row for Sidebar */
    overflow-x: hidden;
    caret-color: transparent;
    /* Prevent caret from flashing on non-inputs */
}

/* Restore caret for inputs */
input,
textarea,
[contenteditable] {
    caret-color: var(--primary);
}

/* Background Mesh Gradient */
.background-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background:
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.08), transparent 25%);
    z-index: -1;
    pointer-events: none;
}

/* App Layout (Sidebar + Main) */
.app-layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: rgba(5, 5, 5, 0.85);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 2.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

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

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow);
}

/* Main Content */
.app-container {
    flex: 1;
    max-width: 1400px;
    /* Wider for dashboard view */
    width: 100%;
    margin: 0;
    padding: 2rem 3rem;
    overflow-y: auto;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.6s ease-out;
}

.logo-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    color: var(--primary);
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.4));
}

h1 {
    font-size: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 300;
}

/* Action Bar */
.action-bar {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 3rem;
    animation: fadeInUp 0.6s ease-out 0.1s backwards;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: var(--shadow), var(--glow);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(59, 130, 246, 0.25);
}

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

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-main);
    border-color: var(--border);
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Gallery Grid */
.gallery-container {
    animation: fadeInUp 0.6s ease-out 0.2s backwards;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    width: 100%;
}

/* Responsive Grid */
@media (max-width: 1024px) {
    .image-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .image-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-bar {
        flex-direction: column;
        width: 100%;
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }

    .btn {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .image-grid {
        grid-template-columns: 1fr;
    }
}

/* Image Card */
.image-card {
    position: relative;
    aspect-ratio: 1;
    /* Square aspect ratio */
    border-radius: var(--radius);
    overflow: hidden;
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    transition: transform 0.3s ease, border-color 0.3s ease;
    cursor: pointer;
}

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

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

.image-card:hover img {
    transform: scale(1.05);
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    /* Span full width */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6rem 2rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
}

.empty-icon {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.hint {
    font-size: 0.9rem;
    opacity: 0.7;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
    pointer-events: none;
}

.toast svg {
    color: var(--success);
}

/* Animations Keyframes */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Login Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: fadeInDown 0.6s ease-out;
}

.login-card h2 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.input-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}


/* Card Actions (Admin & Public) */
.card-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 0.5rem;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-card:hover .card-actions {
    opacity: 1;
}

.action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    color: white;
    transition: transform 0.2s;
}

.delete-btn {
    background: rgba(239, 68, 68, 0.9);
}

.delete-btn:hover {
    background: #DC2626;
    transform: scale(1.1);
}

.edit-btn {
    background: rgba(59, 130, 246, 0.9);
}

.edit-btn:hover {
    background: #2563EB;
    transform: scale(1.1);
}

/* Public Overlay */
.image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
    z-index: 5;
}

.image-card:hover .image-overlay {
    opacity: 1;
}

.copy-btn-overlay {
    background: white;
    color: #0F172A;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.image-card:hover .copy-btn-overlay {
    transform: translateY(0);
}

.copy-btn-overlay:hover {
    background: var(--primary);
    color: white;
}

/* Download Button Overlay */
.download-btn-overlay {
    background: white;
    color: #0F172A;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    display: inline-block;
}

.image-card:hover .download-btn-overlay {
    transform: translateY(0);
}

.download-btn-overlay:hover {
    background: var(--primary);
    color: white;
}

/* Code Indicator in Admin */
.code-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
}

.no-code-badge {
    position: absolute;
    bottom: 10px;
    background: rgba(239, 68, 68, 0.8);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
}