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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --bg-glass-strong: rgba(255, 255, 255, 0.1);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #f0f0f5;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-muted: rgba(255, 255, 255, 0.35);
    --accent-1: #6366f1;
    --accent-2: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.5);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ===== Animated Background ===== */
.bg-blob {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
    animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #6366f1, transparent 70%);
    top: -150px;
    left: -100px;
    animation-delay: 0s;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #8b5cf6, transparent 70%);
    bottom: -100px;
    right: -50px;
    animation-delay: -7s;
}

.blob-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, #a78bfa, transparent 70%);
    top: 40%;
    left: 50%;
    animation-delay: -14s;
}

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -40px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(15px, 30px) scale(1.02); }
}

/* ===== App Container ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 60px;
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 24px;
}

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

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--bg-glass-strong);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: transform var(--transition-smooth);
}

.logo-icon:hover {
    transform: rotate(90deg);
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 6px 14px;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    margin-right: 4px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--bg-glass-strong);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-primary {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.45);
}

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

.btn-export,
.btn-import {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-export:hover,
.btn-import:hover {
    background: var(--bg-glass-strong);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-export svg,
.btn-import svg {
    flex-shrink: 0;
}

.btn-glass {
    padding: 8px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* ===== Input Section ===== */
.input-section {
    margin-bottom: 20px;
}

.input-row {
    display: flex;
    gap: 12px;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 18px;
    transition: all var(--transition-normal);
    backdrop-filter: blur(12px);
}

.input-title-wrapper {
    flex: 0 0 280px;
}

.input-url-wrapper {
    flex: 1;
}

.input-wrapper:focus-within {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15), 0 4px 24px rgba(0, 0, 0, 0.2);
}

.input-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex;
}

#urlInput,
#titleInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
    outline: none;
}

#urlInput::placeholder,
#titleInput::placeholder {
    color: var(--text-muted);
}

.input-hint {
    margin-top: 10px;
    padding-left: 18px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Search Section ===== */
.search-section {
    margin-bottom: 24px;
}

.search-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 4px 8px 4px 16px;
    transition: all var(--transition-normal);
    backdrop-filter: blur(12px);
}

.search-wrapper:focus-within {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

#searchInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.search-clear {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0;
    pointer-events: none;
}

.search-clear.visible {
    opacity: 1;
    pointer-events: auto;
}

.search-clear:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.empty-icon {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-xl);
    color: var(--text-muted);
    margin-bottom: 24px;
}

.empty-state h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* ===== Image Grid ===== */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    animation: fadeIn 0.4s ease;
}

.image-grid.grid-large {
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}

.image-card {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    cursor: grab;
    aspect-ratio: 4 / 3;
    transition: all var(--transition-smooth);
    animation: cardIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.image-card:active {
    cursor: grabbing;
}

.image-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
    box-shadow: none;
    z-index: 100;
}

.image-card.drag-over {
    border: 2px dashed var(--accent-1);
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

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

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-smooth);
}

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



/* Card Title */
.card-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
    z-index: 2;
}

.card-title h3 {
    font-size: 0.88rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.card-title .card-url {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.5);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 10;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.image-card:hover .card-actions,
.image-card:focus-within .card-actions,
.image-card:active .card-actions {
    opacity: 1;
}

@media (hover: none), (max-width: 768px) {
    .card-actions {
        opacity: 1;
        background: rgba(0, 0, 0, 0.4);
        padding: 4px;
        border-radius: var(--radius-md);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }
}

.card-actions .btn-glass {
    width: 34px;
    height: 34px;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: var(--shadow-sm);
}

.card-actions .btn-glass:hover {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    transform: translateY(-1px);
}

/* Loading skeleton */
.image-card.loading {
    background: var(--bg-card);
}

.image-card.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 25%,
        rgba(255, 255, 255, 0.04) 50%,
        transparent 75%
    );
    animation: shimmer 1.5s ease-in-out infinite;
}

.image-card .load-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent-1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.image-card.error {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.image-card.error svg {
    opacity: 0.4;
}

.image-card iframe {
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
    background: #fff;
    border-radius: inherit;
}

.lightbox-image-wrapper iframe {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.lightbox.active {
    display: flex;
    animation: fadeIn 0.25s ease;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(24px);
}

.lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    transform: rotate(90deg);
}

.lightbox-image-wrapper {
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.lightbox-image-wrapper img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-smooth);
    user-select: none;
    -webkit-user-drag: none;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

.lightbox-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 100px;
    backdrop-filter: blur(16px);
    z-index: 10;
}

.lightbox-counter {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    padding: 0 8px;
    min-width: 50px;
    text-align: center;
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.88rem;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
    animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 360px;
}

.toast.toast-error {
    border-color: rgba(239, 68, 68, 0.3);
}

.toast.toast-success {
    border-color: rgba(34, 197, 94, 0.3);
}

.toast-icon {
    flex-shrink: 0;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes shimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

/* ===== Login Screen ===== */
.login-wrapper {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    animation: fadeIn 0.4s ease;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

.login-card h2 {
    text-align: center;
    margin-bottom: 8px;
    font-weight: 600;
}

.login-card p.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.login-card .input-wrapper {
    margin-bottom: 16px;
    padding: 2px 6px 2px 16px;
    background: rgba(0, 0, 0, 0.2);
}

.login-card .input-wrapper.last-child {
    margin-bottom: 24px;
}

.login-card input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 14px 12px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
}

.login-card input::placeholder {
    color: var(--text-muted);
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 1rem;
}

.login-notice {
    text-align: center;
    margin-top: 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    .header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 10px;
    }

    .image-grid.grid-large {
        grid-template-columns: 1fr;
    }

    .lightbox-nav {
        width: 40px;
        height: 40px;
    }

    .lightbox-prev { left: 8px; }
    .lightbox-next { right: 8px; }

    .input-row {
        flex-direction: column;
        gap: 8px;
    }

    .input-title-wrapper {
        flex: none;
    }

    .input-wrapper {
        flex-wrap: wrap;
        padding: 8px;
    }

    .input-icon {
        display: none;
    }

    #urlInput,
    #titleInput {
        width: 100%;
        padding: 10px 12px;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }
}

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

    .image-card {
        border-radius: var(--radius-sm);
    }
    
    .login-wrapper {
        padding: 16px;
    }
    
    .login-card {
        padding: 32px 20px;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== Footer ===== */
.app-footer {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    margin-top: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 24px 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    z-index: 10;
    position: relative;
}

.app-footer a {
    color: var(--accent-1);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.app-footer a:hover {
    color: var(--accent-2);
    text-decoration: underline;
}
