/* ==========================================
   VIDABOT VIDEO GENERATOR — DESIGN SYSTEM
   ========================================== */

/* === CSS VARIABLES === */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --bg-glass-hover: rgba(255, 255, 255, 0.09);

    --accent-1: #7c3aed;
    --accent-2: #06b6d4;
    --accent-1-dim: rgba(124, 58, 237, 0.15);
    --accent-2-dim: rgba(6, 182, 212, 0.15);
    --gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    --gradient-hover: linear-gradient(135deg, #8b5cf6, #22d3ee);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --border-accent: rgba(124, 58, 237, 0.4);

    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    --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 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(124, 58, 237, 0.15);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* === RESET & BASE === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* Subtle animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(124, 58, 237, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(6, 182, 212, 0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* === HEADER === */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-content {
    max-width: 760px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 1.6rem;
    filter: drop-shadow(0 0 8px rgba(124, 58, 237, 0.4));
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.brand-highlight {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.relay-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 100px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
    box-shadow: 0 0 8px var(--error);
    transition: background var(--transition-normal), box-shadow var(--transition-normal);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* === MAIN === */
.app-main {
    flex: 1;
    position: relative;
    z-index: 1;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 24px 40px;
}

/* === TAB BAR === */
.tab-bar {
    display: flex;
    position: relative;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 4px;
    margin-bottom: 24px;
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: color var(--transition-fast), background var(--transition-fast);
    position: relative;
    z-index: 2;
    user-select: none;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--text-primary);
}

.tab-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.tab-indicator {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: var(--bg-glass-hover);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-hover);
    transition: transform var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    box-shadow: var(--shadow-sm);
}

.tab-indicator.right {
    transform: translateX(calc(100% + 4px));
}

/* === FORM PANELS === */
.form-panel {
    animation: fadeSlideIn 250ms ease forwards;
}

.form-panel[hidden] {
    display: none;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === GLASS CARD === */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition-normal);
}

.glass-card:hover {
    border-color: var(--border-hover);
}

/* === FORM ELEMENTS === */
.form-group {
    margin-bottom: 22px;
}

.form-group:last-of-type {
    margin-bottom: 28px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.label-optional {
    font-weight: 400;
    text-transform: none;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.form-textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea:focus {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px var(--accent-1-dim);
}

.char-count {
    display: block;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* === RATIO SELECTOR === */
.ratio-selector {
    display: flex;
    gap: 10px;
}

.ratio-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.ratio-pill:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.ratio-pill.active {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.3);
}

.ratio-icon {
    width: 20px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 2px;
    flex-shrink: 0;
}

.ratio-icon.portrait {
    width: 14px;
    height: 20px;
}

/* === FRAME MODE SELECTOR === */
.frame-mode-selector {
    display: flex;
    gap: 10px;
}

.frame-mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    text-align: center;
}

.frame-mode-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.frame-mode-btn.active {
    background: var(--accent-1-dim);
    border-color: var(--accent-1);
    color: var(--text-primary);
}

/* === UPLOAD ZONES === */
.upload-zones {
    display: flex;
    gap: 16px;
    margin-bottom: 22px;
}

.upload-zone-wrapper {
    flex: 1;
    min-width: 0;
}

.upload-zone-wrapper[hidden] {
    display: none;
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    overflow: hidden;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--accent-1);
    background: var(--accent-1-dim);
}

.upload-zone.dragover {
    border-color: var(--accent-2);
    background: var(--accent-2-dim);
    border-style: solid;
    animation: zone-pulse 1s ease-in-out infinite;
}

@keyframes zone-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.2);
    }

    50% {
        box-shadow: 0 0 20px 4px rgba(6, 182, 212, 0.15);
    }
}

.upload-zone.has-image {
    border-style: solid;
    border-color: var(--border-hover);
    padding: 0;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-icon {
    width: 36px;
    height: 36px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.upload-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.upload-link {
    color: var(--accent-2);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.upload-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Upload Preview */
.upload-preview {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 160px;
}

.upload-preview[hidden] {
    display: none;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    min-height: 160px;
    max-height: 240px;
    object-fit: cover;
    border-radius: calc(var(--radius-lg) - 2px);
    display: block;
}

.preview-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), transform var(--transition-fast);
    backdrop-filter: blur(4px);
}

.preview-remove:hover {
    background: var(--error);
    transform: scale(1.1);
}

/* === GENERATE BUTTON === */
.btn-generate {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--gradient);
    color: #fff;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.01em;
}

.btn-generate::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-hover);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn-generate:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(124, 58, 237, 0.35);
}

.btn-generate:hover::before {
    opacity: 1;
}

.btn-generate:active {
    transform: translateY(0);
}

.btn-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-text,
.btn-loader {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-loader[hidden] {
    display: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* === QUEUE SECTION === */
.queue-section {
    margin-top: 32px;
}

.queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.queue-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-clear-queue {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-clear-queue:hover {
    border-color: var(--error);
    color: var(--error);
    background: rgba(239, 68, 68, 0.08);
}

.queue-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Queue Empty State */
.queue-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.queue-empty[hidden] {
    display: none;
}

.queue-empty-icon {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

/* Queue Item */
.queue-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 18px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--text-muted);
    transition: border-color var(--transition-fast), background var(--transition-fast);
    animation: slideInRight 300ms ease-out forwards;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.queue-item.status-pending {
    border-left-color: var(--text-muted);
}

.queue-item.status-processing {
    border-left-color: var(--warning);
    background: rgba(245, 158, 11, 0.04);
}

.queue-item.status-completed {
    border-left-color: var(--success);
}

.queue-item.status-failed {
    border-left-color: var(--error);
}

.queue-item-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.queue-item-body {
    flex: 1;
    min-width: 0;
}

.queue-item-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.queue-item-type {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--accent-1-dim);
    color: var(--accent-1);
}

.queue-item-type.i2v {
    background: var(--accent-2-dim);
    color: var(--accent-2);
}

.queue-item-prompt {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}

.queue-item-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.queue-item-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
}

.queue-item-status.pending {
    color: var(--text-muted);
}

.queue-item-status.processing {
    color: var(--warning);
}

.queue-item-status.completed {
    color: var(--success);
}

.queue-item-status.failed {
    color: var(--error);
}

.processing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse-glow 1.2s ease-in-out infinite;
}

/* Queue item video preview */
.queue-item-video {
    margin-top: 10px;
}

.queue-item-video video {
    width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    background: #000;
}

.queue-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-download {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-download:hover {
    border-color: var(--accent-2);
    color: var(--accent-2);
    text-decoration: none;
}

/* Queue Item Controls (Cancel / Retry) */
.queue-item-controls {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn-cancel,
.btn-retry {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.2);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-cancel {
    color: var(--text-muted);
}

.btn-cancel:hover {
    border-color: var(--error);
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

.btn-retry {
    color: var(--accent-2);
    border-color: var(--accent-2-dim);
}

.btn-retry:hover {
    border-color: var(--accent-2);
    background: var(--accent-2-dim);
    color: #fff;
}

.btn-cancel:disabled,
.btn-retry:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.retry-exhausted {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 4px;
    display: inline-block;
}

/* Progress Bar */
.progress-bar-container {
    position: relative;
    width: 100%;
    height: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    overflow: hidden;
    margin: 8px 0 4px;
    border: 1px solid var(--border);
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient);
    border-radius: 10px;
    transition: width 0.4s ease;
    min-width: 0;
}

.progress-bar-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* === TOAST === */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    max-width: 380px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 300ms ease forwards;
    backdrop-filter: blur(12px);
}

.toast.toast-out {
    animation: toastOut 250ms ease forwards;
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--error);
}

.toast.warning {
    border-left: 3px solid var(--warning);
}

.toast.info {
    border-left: 3px solid var(--info);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }
}

/* === FOOTER === */
.app-footer {
    text-align: center;
    padding: 20px 24px;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 1;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .header-content {
        padding: 14px 16px;
    }

    .brand-name {
        font-size: 1rem;
    }

    .container {
        padding: 16px 16px 32px;
    }

    .glass-card {
        padding: 22px 18px;
        border-radius: var(--radius-lg);
    }

    .upload-zones {
        flex-direction: column;
    }

    .frame-mode-selector {
        flex-direction: column;
    }

    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .brand-icon {
        font-size: 1.3rem;
    }

    .brand-name {
        font-size: 0.9rem;
    }

    .relay-status .status-text {
        display: none;
    }

    .tab-btn {
        font-size: 0.82rem;
        padding: 10px 14px;
        gap: 6px;
    }

    .tab-icon {
        width: 16px;
        height: 16px;
    }

    .glass-card {
        padding: 18px 14px;
    }

    .ratio-selector {
        flex-direction: column;
    }

    .ratio-pill {
        justify-content: center;
    }

    .btn-generate {
        padding: 14px 20px;
        font-size: 0.95rem;
    }

    .queue-item {
        padding: 14px;
    }
}