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

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-hover: #1a1a2e;
    --bg-input: #16161f;
    --border: #2a2a3e;
    --border-focus: #6366f1;
    --text: #e8e8f0;
    --text-muted: #8888a0;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.3);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ===== AUTH PAGES ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
}

.auth-container { width: 100%; max-width: 420px; padding: 20px; }

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: var(--shadow);
}

.auth-logo { text-align: center; margin-bottom: 32px; }

.logo-icon {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #e8e8f0, #a5a5c0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.auth-card h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
}

.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-group input::placeholder { color: #555568; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #818cf8, #8b5cf6);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.5);
}

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

.btn-outline:hover { background: var(--bg-hover); border-color: var(--text-muted); }

.btn-full { width: 100%; margin-top: 8px; }
.btn-sm { padding: 8px 16px; font-size: 13px; }

.auth-switch {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-muted);
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #fca5a5; }
.alert-success { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.3); color: #86efac; }

/* ===== HEADER ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 16px; }

.logo-link { display: flex; align-items: center; gap: 10px; text-decoration: none; }

.logo-small {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.header-link {
    font-size: 14px;
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}
.header-link:hover { color: var(--text); background: var(--bg-hover); }

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 10px;
    transition: background 0.2s;
    position: relative;
}
.user-menu:hover { background: var(--bg-hover); }

.user-avatar { font-size: 22px; }
.user-name { font-size: 14px; font-weight: 500; }

.dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 220px;
    box-shadow: var(--shadow);
    padding: 8px;
    z-index: 200;
}

.dropdown.show { display: block; }

.dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
}

.dropdown-avatar { font-size: 28px; }
.dropdown-header strong { display: block; font-size: 14px; }
.dropdown-header small { color: var(--text-muted); font-size: 12px; }

.dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.dropdown a {
    display: block;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text);
    border-radius: 8px;
    transition: background 0.2s;
}
.dropdown a:hover { background: var(--bg-hover); }

.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted); }

/* ===== SEARCH / MAIN ===== */
.search-main { padding: 0 32px 60px; }

.search-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(70vh - 80px);
    transition: min-height 0.5s ease;
}

.search-hero.compact { min-height: auto; padding: 40px 0; }

.hero-logo {
    margin-bottom: 16px;
    display: flex;
    align-items: baseline;
}

.hero-v {
    font-size: 72px;
    font-weight: 800;
    background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}

.hero-text {
    font-size: 72px;
    font-weight: 300;
    color: var(--text);
    line-height: 1;
}

.hero-subtitle {
    color: var(--text-muted);
    font-size: 18px;
    margin-bottom: 40px;
}

.search-form { width: 100%; max-width: 680px; }

.search-box {
    display: flex;
    align-items: flex-start;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 8px 8px 8px 20px;
    transition: border-color 0.2s, box-shadow 0.3s;
    gap: 8px;
}

.search-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px var(--primary-glow), 0 8px 32px rgba(99, 102, 241, 0.15);
}

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

.search-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    padding: 10px 0;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 150px;
}

.search-box textarea::placeholder { color: #555568; }

.search-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.search-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 16px rgba(99, 102, 241, 0.5);
}

.search-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== MODE TOGGLE ===== */
.mode-toggle {
    display: flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 24px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover { color: var(--text); }

.mode-btn.active {
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4);
}

.mode-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

.mode-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.image-badge { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.video-badge { background: rgba(236, 72, 153, 0.15); color: #f472b6; }

.mode-desc { font-size: 13px; color: var(--text-muted); }

.search-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
}

.hint {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.hint:hover {
    border-color: var(--primary);
    color: var(--text);
    background: var(--bg-hover);
}

/* ===== STATUS / LOADING ===== */
.status-area { padding: 20px 0; display: flex; justify-content: center; }

.status-card {
    text-align: center;
    padding: 48px;
    max-width: 480px;
    width: 100%;
}

.status-card h3 { font-size: 20px; margin: 20px 0 8px; }

.spinner {
    width: 48px; height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

.spinner-small {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 24px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    border-radius: 2px;
    width: 0%;
    transition: width 1s ease;
}

/* ===== RESULT ===== */
.result-area { padding: 20px 0; display: flex; justify-content: center; }

.result-card { max-width: 960px; width: 100%; }

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.result-header h3 { font-size: 22px; }

.image-grid-result {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.result-image-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.2s;
}

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

.result-image-card img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: transform 0.3s;
}

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

.result-image-actions {
    padding: 10px;
    display: flex;
    justify-content: center;
}

.result-video {
    width: 100%;
    max-width: 720px;
    border-radius: var(--radius-lg);
    background: #000;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    margin: 0 auto;
    display: block;
}

.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

/* ===== IMAGE GRID (HOME) ===== */
.recent-section {
    max-width: 960px;
    margin: 60px auto 0;
}

.recent-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-muted);
}

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

.image-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

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

.image-thumb {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
    background: var(--bg-hover);
}

.image-thumb-placeholder {
    width: 100%;
    aspect-ratio: 1/1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    color: var(--text-muted);
    font-size: 14px;
}

.image-info { padding: 12px; }
.image-prompt { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

/* ===== LIGHTBOX ===== */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
}

.lightbox.active { display: flex; }

.lightbox img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: var(--radius);
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    z-index: 1001;
}

.lightbox-download { margin-top: 8px; }

/* ===== HISTORY PAGE ===== */
.history-main { padding: 32px; max-width: 1100px; margin: 0 auto; }
.history-main h2 { font-size: 24px; margin-bottom: 24px; }

.empty-state {
    text-align: center;
    padding: 80px 20px;
}

.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state h3 { font-size: 22px; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 24px; }

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.history-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.history-images {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
}

.history-images img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s;
}

.history-images img:hover { opacity: 0.85; }

.image-placeholder {
    width: 100%;
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    color: var(--text-muted);
}

.image-placeholder.failed { color: var(--danger); }

.history-video {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    display: block;
}

.gallery-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 4px;
    width: fit-content;
}

.gallery-tab {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
}

.gallery-tab:hover { color: var(--text); }

.gallery-tab.active {
    background: var(--primary);
    color: #fff;
}

.history-meta { padding: 16px; }
.history-prompt { font-size: 14px; line-height: 1.5; margin-bottom: 12px; }
.history-footer { display: flex; justify-content: space-between; align-items: center; }

.status-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.status-completed { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-generating { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status-failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .header { padding: 12px 16px; }
    .search-main { padding: 0 16px 40px; }
    .hero-v, .hero-text { font-size: 48px; }
    .hero-subtitle { font-size: 15px; }
    .search-box { padding: 6px 6px 6px 16px; }
    .search-hints { gap: 6px; }
    .hint { font-size: 12px; padding: 6px 12px; }
    .user-name { display: none; }
    .auth-card { padding: 28px 24px; }
    .result-actions { flex-direction: column; }
    .video-grid-full { grid-template-columns: 1fr; }
    .history-main { padding: 20px 16px; }
}

@media (max-width: 480px) {
    .hero-v, .hero-text { font-size: 36px; }
    .header-link { display: none; }
}
