:root {
    --bg-primary: #0f0f11;
    --bg-secondary: #1a1a1f;
    --bg-tertiary: #242429;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --primary: #4285f4;
    --primary-hover: #5a9bff;
    --success: #34a853;
    --warning: #fbbc04;
    --danger: #ea4335;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

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

body {
    width: auto;
    height: 900px;
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--card-border);
}

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

.logo-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
}

.logo-text span {
    color: var(--primary);
}

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

.btn-reset {
    padding: 6px 10px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--card-bg);
    border-radius: 20px;
    font-size: 0.75rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px rgba(52, 168, 83, 0.5);
}

.status-dot.disconnected {
    background: var(--danger);
}

.credits {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

.credits .material-symbols-rounded {
    font-size: 1rem;
    color: var(--primary);
}

/* Main Tabs */
.main-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--card-border);
    padding: 0 8px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--card-bg);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn .material-symbols-rounded {
    font-size: 1.2rem;
}

.tab-btn .badge {
    padding: 2px 6px;
    background: var(--primary);
    color: white;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

.tab-btn .badge.hidden {
    display: none;
}

/* Content */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

textarea,
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    transition: border-color 0.2s;
}

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

select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.settings-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.setting label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* Upload Zone */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover {
    border-color: var(--primary);
    background: rgba(66, 133, 244, 0.05);
}

.upload-zone .material-symbols-rounded {
    font-size: 2rem;
    color: var(--text-muted);
}

.upload-zone span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.ref-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.ref-slot {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--bg-tertiary);
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.ref-slot:hover {
    border-color: var(--primary);
    background: rgba(66, 133, 244, 0.05);
}

.ref-slot.add-slot {
    background: rgba(255, 255, 255, 0.02);
}

.ref-slot .ref-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-slot .ref-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
    padding: 8px;
}

.ref-slot .ref-placeholder .material-symbols-rounded {
    font-size: 1.4rem;
}

.ref-slot .remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    background: rgba(234, 67, 53, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.15s, background 0.15s;
}

.ref-slot .remove-btn:hover {
    transform: scale(1.1);
    background: rgba(234, 67, 53, 1);
}

.ref-slot .account-badge {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 0.65rem;
    border-radius: 999px;
    line-height: 1;
    max-width: calc(100% - 12px);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    z-index: 6;
    pointer-events: none;
}

.ref-slot .upload-overlay {
    border-radius: var(--radius-md);
}

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

.preview-list {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(234, 67, 53, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.15s, background 0.15s;
}

.preview-item .remove-btn:hover {
    transform: scale(1.1);
    background: rgba(234, 67, 53, 1);
}

/* Upload Status Overlay */
.preview-item .status-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    z-index: 5;
}

.preview-item.uploading .status-overlay {
    background: rgba(0, 0, 0, 0.6);
}

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

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

/* Success Badge */
.preview-item.success .status-overlay {
    background: rgba(52, 168, 83, 0.3);
}

.preview-item .status-icon {
    font-size: 20px;
}

.preview-item.success .status-icon {
    color: var(--success);
}

/* Error Badge */
.preview-item.error .status-overlay {
    background: rgba(234, 67, 53, 0.3);
}

.preview-item.error .status-icon {
    color: var(--error);
}

/* Upload Overlay (for video frame uploads) */
.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    z-index: 5;
    transition: opacity 0.3s;
}

.upload-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.upload-overlay.success {
    background: rgba(52, 168, 83, 0.4);
}

.upload-overlay.error {
    background: rgba(234, 67, 53, 0.4);
}

.upload-overlay .success-icon {
    font-size: 32px;
    color: var(--success);
}

.upload-overlay .error-icon {
    font-size: 32px;
    color: var(--error);
}

.hidden-delayed {
    animation: fadeOutDelayed 1.5s forwards;
}

@keyframes fadeOutDelayed {

    0%,
    70% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        pointer-events: none;
    }
}

/* Dual Upload */
.dual-upload {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.dual-upload .upload-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dual-upload .upload-item label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.upload-box.small {
    aspect-ratio: 1/1;
}

.upload-box.small .placeholder {
    font-size: 0.7rem;
}

.upload-box.small .placeholder .material-symbols-rounded {
    font-size: 24px;
}

.upload-box {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--bg-tertiary);
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
}

.upload-box:hover {
    border-color: var(--primary);
}

.upload-box .placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
}

.upload-box .placeholder .material-symbols-rounded {
    font-size: 1.5rem;
}

.upload-box .placeholder span {
    font-size: 0.75rem;
}

.upload-box .preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upload-box .preview.hidden {
    display: none;
}

/* Remove Upload Button */
.upload-box .remove-upload-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: rgba(234, 67, 53, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.upload-box .remove-upload-btn:hover {
    background: var(--error);
    transform: scale(1.1);
}

.upload-box .remove-upload-btn.hidden {
    display: none;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, #357ae8 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(66, 133, 244, 0.3);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--card-bg);
    border-color: var(--primary);
}

.btn-danger {
    padding: 8px 14px;
    background: rgba(234, 67, 53, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.75rem;
}

.btn-sm .material-symbols-rounded {
    font-size: 1rem;
}

/* Video Status */
.video-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    background: rgba(66, 133, 244, 0.1);
    border-radius: var(--radius-md);
    margin-top: 12px;
}

.video-status.hidden {
    display: none;
}

/* Quick Results */
.quick-results {
    margin-top: 16px;
}

.result-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 12px;
}

.result-card img,
.result-card video {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    background: #000;
}

.result-card .actions {
    display: flex;
    gap: 8px;
    padding: 10px;
}

/* Results Grid */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.results-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.results-grid .item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
}

.results-grid .item img,
.results-grid .item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.results-grid .item .overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.results-grid .item:hover .overlay {
    opacity: 1;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state .material-symbols-rounded {
    font-size: 3rem;
    opacity: 0.5;
    margin-bottom: 10px;
}

/* Settings */
.settings-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
}

.settings-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--card-border);
}

.setting-row:last-of-type {
    border-bottom: none;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 4px 0 0 0;
    font-style: italic;
}

.status-badge {
    padding: 4px 8px;
    background: var(--card-bg);
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.connected {
    background: rgba(52, 168, 83, 0.2);
    color: var(--success);
}

.mono {
    font-family: 'Menlo', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.instructions {
    font-size: 0.85rem;
    padding-left: 20px;
    color: var(--text-secondary);
}

.instructions li {
    margin-bottom: 8px;
}

.instructions a {
    color: var(--primary);
}

.version {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 16px;
}

.proxy-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.proxy-host-setting,
.proxy-bypass-setting {
    grid-column: 1 / -1;
}

.proxy-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.proxy-grid textarea,
.proxy-grid input,
.proxy-grid select {
    width: 100%;
}

/* Loading Overlay - Premium Design */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, rgba(8, 12, 24, 0.98), rgba(20, 30, 48, 0.99));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(15px);
    transition: all 0.3s ease;
}

.loading-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    padding: 40px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.loading-visual {
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid transparent;
    border-top-color: var(--primary);
    border-right-color: var(--accent);
    border-radius: 50%;
    animation: loading-spin 2s cubic-bezier(0.6, -0.28, 0.735, 0.045) infinite;
    filter: drop-shadow(0 0 10px var(--primary));
}

.loading-ring.delay {
    width: 80%;
    height: 80%;
    border-top-color: var(--accent);
    border-right-color: var(--primary);
    animation-delay: 0.3s;
    animation-direction: reverse;
    animation-duration: 1.5s;
}

.loading-ring.inner {
    width: 60%;
    height: 60%;
    border-top-color: #fff;
    border-right-color: transparent;
    animation-delay: 0.6s;
    animation-duration: 1s;
}

.loading-particles {
    position: absolute;
    width: 160%;
    height: 160%;
    pointer-events: none;
}

.particle {
    position: absolute;
    background: white;
    border-radius: 50%;
    filter: blur(1px);
    opacity: 0;
    animation: particle-float 3s infinite ease-in-out;
}

.loading-icon {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 40px rgba(66, 133, 244, 0.6), 0 0 80px rgba(138, 180, 248, 0.4);
    z-index: 2;
    animation: loading-pulse 2s ease-in-out infinite;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.loading-icon .material-symbols-rounded {
    font-size: 32px;
    color: white;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

.loading-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    letter-spacing: 1px;
    background: linear-gradient(90deg, #fff, var(--primary), #fff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: loading-shimmer 2s linear infinite;
}

.loading-dots {
    display: flex;
    gap: 10px;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    border-radius: 50%;
    animation: loading-bounce 1.4s ease-in-out infinite;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Inline Video/Image Status - Premium Version */
.video-status,
.image-status {
    margin-top: 20px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.8));
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    animation: fadeIn 0.4s ease-out;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
}

.video-status .mini-loading,
.image-status .mini-loading {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-status .mini-ring,
.image-status .mini-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid transparent;
    border-top-color: var(--primary);
    border-right-color: var(--accent);
    border-radius: 50%;
    animation: loading-spin 1.2s linear infinite;
}

#videoStatusText,
#imageStatusText {
    font-weight: 600;
    font-size: 0.95rem;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    background: linear-gradient(90deg, #fff, var(--primary), #fff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: loading-shimmer 2s linear infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes particle-float {
    0% {
        transform: translate(var(--x, 0), var(--y, 0)) scale(0);
        opacity: 0;
    }

    50% {
        opacity: 0.8;
    }

    100% {
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(1);
        opacity: 0;
    }
}

@keyframes loading-spin {
    0% {
        transform: rotate(0deg) scale(0.9);
    }

    50% {
        transform: rotate(180deg) scale(1.1);
    }

    100% {
        transform: rotate(360deg) scale(0.9);
    }
}

@keyframes loading-pulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 40px rgba(66, 133, 244, 0.6);
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 0 70px rgba(66, 133, 244, 0.9);
    }
}

@keyframes loading-icon-sparkle {

    0%,
    100% {
        opacity: 1;
        transform: rotate(0deg);
    }

    50% {
        opacity: 0.7;
        transform: rotate(15deg);
    }
}

@keyframes loading-shimmer {
    0% {
        background-position: 200% center;
    }

    100% {
        background-position: -200% center;
    }
}

@keyframes loading-bounce {

    0%,
    80%,
    100% {
        transform: translateY(0) scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: translateY(-10px) scale(1.1);
        opacity: 1;
    }
}

/* Spinner (keep for other uses) */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--card-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.large {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

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

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
}

.toast {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    margin-top: 8px;
    animation: slideUp 0.3s ease;
}

.toast.success {
    border-color: var(--success);
    background: rgba(52, 168, 83, 0.1);
}

.toast.error {
    border-color: var(--danger);
    background: rgba(234, 67, 53, 0.1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Sub-tabs */
.sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    padding: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.sub-tab {
    flex: 1;
    padding: 8px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.sub-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.sub-tab.active {
    background: var(--primary);
    color: white;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked+.slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

.toggle-switch input:checked+.slider:before {
    transform: translateX(20px);
    background-color: white;
}

/* Grid 4 columns for settings row */
.settings-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

/* Hidden helpers */
.hidden {
    display: none !important;
}

.video-image-section {
    margin-bottom: 16px;
}

.i2i-only {
    margin-bottom: 16px;
}

/* Prompt Header with Batch Toggle */
.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.batch-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
}

.batch-toggle input {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
}

.batch-help {
    font-size: 0.75rem;
    color: var(--warning);
    margin-top: 6px;
    padding: 8px 10px;
    background: rgba(251, 188, 4, 0.1);
    border-radius: var(--radius-sm);
}

/* Queue Header */
.queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

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

.queue-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* Queue Stats */
.queue-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.queue-stats .stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.queue-stats .stat .material-symbols-rounded {
    font-size: 1rem;
}

.queue-stats .stat.pending .material-symbols-rounded {
    color: var(--warning);
}

.queue-stats .stat.running .material-symbols-rounded {
    color: var(--primary);
    animation: spin 1s linear infinite;
}

.queue-stats .stat.done .material-symbols-rounded {
    color: var(--success);
}

.queue-stats .stat.error .material-symbols-rounded {
    color: var(--danger);
}

/* Queue List */
.queue-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 750px;
    overflow-y: auto;
}

/* Queue Item */
.queue-item {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    border-left: 3px solid var(--card-border);
}

.queue-item.pending {
    border-left-color: var(--warning);
}

.queue-item.running {
    border-left-color: var(--primary);
}

.queue-item.done {
    border-left-color: var(--success);
}

.queue-item.error {
    border-left-color: var(--danger);
}

.queue-item-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.queue-item-index {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    min-width: 28px;
}

.queue-item-prompt {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item-top {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}

.queue-item-info {
    min-width: 0;
}

.queue-item-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    min-width: 120px;
}

.queue-item-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
}

.queue-item-status.pending {
    background: rgba(251, 188, 4, 0.2);
    color: var(--warning);
}

.queue-item-status.running {
    background: rgba(66, 133, 244, 0.2);
    color: var(--primary);
}

.queue-item-status.done {
    background: rgba(52, 168, 83, 0.2);
    color: var(--success);
}

.queue-item-status.error {
    background: rgba(234, 67, 53, 0.2);
    color: var(--danger);
}

.queue-item-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.queue-tag {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
}

.queue-tag .material-symbols-rounded {
    font-size: 0.85rem;
    margin-right: 4px;
}

.queue-tag.mode-tag {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* Queue Item Error Details */
.queue-item-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 6px;
    padding: 8px;
    background: rgba(234, 67, 53, 0.1);
    border: 1px solid rgba(234, 67, 53, 0.3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.queue-item-error:hover {
    background: rgba(234, 67, 53, 0.2);
}

.queue-item-error .material-symbols-rounded {
    color: var(--danger);
    font-size: 16px;
    flex-shrink: 0;
}

.queue-item-error .error-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    word-break: break-word;
}

.queue-item-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--warning);
}

.queue-item-hint .material-symbols-rounded {
    font-size: 16px;
}

.queue-progress {
    position: relative;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    margin-top: 6px;
}

.queue-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
    transition: width 0.3s ease;
}

.queue-progress-text {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.68rem;
    color: var(--text-muted);
}

.queue-item-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.queue-item-actions.compact {
    margin-top: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.queue-item-actions button {
    padding: 4px 8px;
    font-size: 0.7rem;
}

/* Queue Item Result Preview */
.queue-item-result {
    margin-top: 8px;
}

.queue-item-result img,
.queue-item-result video {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
}

/* Results Actions */
.results-actions {
    display: flex;
    gap: 8px;
}

/* Media Viewer Modal */
.media-viewer {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-viewer.hidden {
    display: none;
}

.media-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
}

.media-viewer-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.media-viewer-content img,
.media-viewer-content video {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: var(--radius-md);
    object-fit: contain;
}

.media-viewer-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.media-viewer-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.media-viewer-close .material-symbols-rounded {
    font-size: 28px;
}

.media-viewer-actions {
    margin-top: 16px;
}

/* View Button in Results Grid */
.results-grid .item .overlay {
    display: flex;
    gap: 8px;
}

.results-grid .item .view-btn,
.results-grid .item .download-btn {
    padding: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.results-grid .item .view-btn:hover,
.results-grid .item .download-btn:hover {
    background: white;
}

.results-grid .item .view-btn .material-symbols-rounded,
.results-grid .item .download-btn .material-symbols-rounded {
    font-size: 18px;
    color: #000;
}

/* Queue item view button */
.queue-item-result {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-thumb-btn {
    opacity: 0.7;
    cursor: pointer;
    transition: opacity 0.2s;
}

.view-thumb-btn:hover {
    opacity: 1;
}

/* Range Slider Styling */
.concurrency-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.concurrency-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.concurrency-value {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
}

#concurrencySetting {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

#concurrencySetting::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

#concurrencySetting:hover::-webkit-slider-thumb {
    transform: scale(1.1);
}

/* ==========================================
   Connection Prompt Overlay
   ========================================== */
.connection-prompt {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.connection-prompt.hidden {
    display: none;
}

.connection-prompt-content {
    text-align: center;
    padding: 32px;
    max-width: 320px;
}

.connection-prompt-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, rgba(234, 67, 53, 0.2), rgba(251, 188, 5, 0.2));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s ease infinite;
}

.connection-prompt-icon .material-symbols-rounded {
    font-size: 40px;
    color: var(--error);
}

.connection-prompt h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.connection-prompt p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.connection-prompt-btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(66, 133, 244, 0.4);
}

.connection-prompt-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(66, 133, 244, 0.6);
}

.connection-prompt-btn .material-symbols-rounded {
    font-size: 24px;
}

.connection-prompt-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 16px;
}

.connection-prompt-hint strong {
    color: var(--accent);
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

/* UI Polish: Results Filters */
.result-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.filter-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.filter-btn .material-symbols-rounded {
    font-size: 16px;
}

/* UI Polish: Settings Grid */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.settings-section {
    height: 100%;
    margin-bottom: 0 !important;
    display: flex;
    flex-direction: column;
}

.settings-section:last-child {
    grid-column: span 2;
}

/* UI Polish: Result Card Type Badge */
.result-type-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 2;
    pointer-events: none;
}

.result-type-badge span {
    font-size: 12px;
}

/* Account Badge Style */
.preview-item .account-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(52, 168, 83, 0.9);
    color: white;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 500;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.preview-item.error .account-badge {
    display: none;
}
