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

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-input: #1a1a26;
    --bg-hover: #1e1e2e;
    --border: #2a2a3a;
    --text: #e4e4ef;
    --text-dim: #8888a0;
    --accent: #7c5cfc;
    --accent-hover: #9070ff;
    --accent-glow: rgba(124, 92, 252, 0.15);
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    --sidebar-w: 260px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px;
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}

.nav-tabs {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-tab:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.nav-tab.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-group label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-group input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    outline: none;
}

.settings-group input:focus {
    border-color: var(--accent);
}

/* Content */
.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 28px 36px;
    min-height: 100vh;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.panel-header {
    margin-bottom: 24px;
    position: relative;
}

.panel-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.panel-header p {
    color: var(--text-dim);
    font-size: 14px;
}

.panel-body {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 28px;
    align-items: start;
}

/* Form */
.form-area {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    resize: vertical;
}

.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}

.form-group select option {
    background: var(--bg-input);
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
}

.upload-zone:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.upload-zone.has-image {
    display: none;
}

.preview-img {
    max-width: 100%;
    max-height: 160px;
    border-radius: 8px;
    object-fit: contain;
    cursor: pointer;
}

.btn-generate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-generate:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

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

.btn-generate.loading {
    position: relative;
}

.btn-generate.loading::after {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
}

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

/* Result Area */
.result-area {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.placeholder {
    color: var(--text-dim);
    font-size: 14px;
    text-align: center;
    padding: 40px;
}

.result-area img {
    max-width: 100%;
    max-height: 600px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: contain;
}

.result-area video {
    max-width: 100%;
    max-height: 600px;
    border-radius: 8px;
}

.result-status {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 16px;
    white-space: pre-wrap;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

/* History */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

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

.history-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.history-card-media {
    position: relative;
    aspect-ratio: 16/10;
    overflow: hidden;
    background: var(--bg-input);
}

.history-card-media img,
.history-card-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-card-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.badge-image { color: var(--success); }
.badge-video { color: var(--warning); }

.history-card-info {
    padding: 12px;
}

.history-card-info .prompt {
    font-size: 13px;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.history-card-info .meta {
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.meta-actions {
    display: flex;
    gap: 4px;
}

.history-card-info .btn-delete,
.history-card-info .btn-dl {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.history-card-info .btn-delete:hover {
    color: var(--error);
}

.history-card-info .btn-dl:hover {
    color: var(--accent);
}

.btn-download {
    margin-top: 10px;
    padding: 8px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
}

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

.btn-clear {
    position: absolute;
    top: 0;
    right: 0;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-clear:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.lightbox-content img,
.lightbox-content video {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 8px;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast-success { background: #065f46; color: #a7f3d0; }
.toast-error { background: #7f1d1d; color: #fecaca; }
.toast-info { background: #1e1b4b; color: #c7d2fe; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1024px) {
    .panel-body {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .app {
        flex-direction: column;
    }
    .content {
        margin-left: 0;
        padding: 16px;
    }
    .nav-tabs {
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
    }
    .nav-tab {
        white-space: nowrap;
        font-size: 12px;
        padding: 8px 12px;
    }
    .sidebar-footer {
        display: none;
    }
}
