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

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-input: #1a1a26;
    --border: #2a2a3a;
    --text: #e8e8f0;
    --text-muted: #8888a0;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --warning: #f59e0b;
    --success: #22c55e;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,.4);
}

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

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

/* Navbar */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.nav-brand svg { color: var(--primary); }

.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: var(--text-muted); font-size: .9rem; font-weight: 500; text-decoration: none; }
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-links a.logout { color: var(--danger); }

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Grid */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .container { padding: 1rem; }
    .navbar { padding: 1rem; }
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.card h2 { font-size: 1.25rem; margin-bottom: .25rem; }
.subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.25rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .4rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

input[type="text"], input[type="password"], input[type="number"],
textarea, select {
    width: 100%;
    padding: .75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: .95rem;
    transition: border-color .2s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, opacity .2s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .4rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    position: relative;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, .05);
}

.dropzone-content { color: var(--text-muted); }
.dropzone-content svg { margin-bottom: .5rem; opacity: .5; }
.dropzone-content p { font-size: .875rem; }

.dropzone-preview {
    position: relative;
    width: 100%;
}

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

.btn-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
}

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: .9rem;
}

.alert-error { background: rgba(239,68,68,.15); border: 1px solid var(--danger); color: #fca5a5; }
.alert-warning { background: rgba(245,158,11,.15); border: 1px solid var(--warning); color: #fcd34d; }
.alert-success { background: rgba(34,197,94,.15); border: 1px solid var(--success); color: #86efac; }

/* Login */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow);
}

.login-header { text-align: center; margin-bottom: 2rem; }
.logo-icon {
    width: 56px;
    height: 56px;
    background: rgba(99,102,241,.15);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    color: var(--primary);
}

.login-header h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-header p { color: var(--text-muted); font-size: .9rem; }

/* History */
.history-list { display: flex; flex-direction: column; gap: .75rem; max-height: 600px; overflow-y: auto; }

.history-item {
    display: flex;
    gap: .75rem;
    align-items: center;
    padding: .75rem;
    background: var(--bg-input);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.history-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
}

.history-thumb img { width: 100%; height: 100%; object-fit: cover; }

.play-badge, .status-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.5);
    font-size: 1.2rem;
    color: #fff;
}

.status-badge.processing { font-size: .8rem; animation: pulse 1.5s infinite; }
.status-badge.failed { background: rgba(239,68,68,.6); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.history-info { flex: 1; min-width: 0; }
.history-prompt { font-size: .85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: .75rem; color: var(--text-muted); }
.history-error { font-size: .7rem; color: var(--danger); margin-top: .2rem; }

.history-actions { display: flex; gap: .4rem; flex-shrink: 0; }

.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }

/* Current job */
.current-job {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.current-job h3 { font-size: 1rem; margin-bottom: .75rem; }

.job-status {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--text-muted);
    font-size: .9rem;
}

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

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

.current-job video {
    width: 100%;
    border-radius: 8px;
    margin-top: 1rem;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.8);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 800px;
    z-index: 1;
}

.modal-content video { width: 100%; border-radius: var(--radius); }

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
}

/* Settings */
.settings-page h1 { font-size: 1.75rem; margin-bottom: .25rem; }
.settings-page > .subtitle { margin-bottom: 2rem; }

.key-status { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }
.key-status code { background: var(--bg-input); padding: .2rem .5rem; border-radius: 4px; }

.form-msg {
    margin-top: .75rem;
    font-size: .85rem;
    padding: .5rem .75rem;
    border-radius: 6px;
}

.form-msg.success { background: rgba(34,197,94,.15); color: var(--success); }
.form-msg.error { background: rgba(239,68,68,.15); color: #fca5a5; }
