/* Neural Defend Face Swap — light, clean UI */

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --text: #1a1d26;
    --text-muted: #5c6370;
    --border: #e2e6ee;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* ========== Login ========== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #eef2ff 0%, var(--bg) 45%, #f0fdf4 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.brand-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.brand-tagline {
    margin: 0 0 1.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.login-form .field-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.field-input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.field-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin: 0 0 0.75rem;
    min-height: 1.25rem;
}

/* ========== Buttons ========== */
.btn {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-outline {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== App shell ========== */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.menu-toggle {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
}

.menu-toggle:hover {
    background: var(--bg);
}

.menu-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}

.page-heading {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

/* ========== Slide nav ========== */
.nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 90;
    opacity: 1;
    transition: opacity 0.2s;
}

.nav-overlay.hidden {
    display: none;
}

.nav-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: min(280px, 88vw);
    height: 100%;
    background: var(--surface);
    z-index: 100;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.nav-panel.open {
    transform: translateX(0);
}

.nav-panel-inner {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.nav-close {
    align-self: flex-end;
    border: none;
    background: none;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

.nav-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
}

.nav-list li {
    margin-bottom: 4px;
}

.nav-link {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
}

.nav-link:hover {
    background: var(--bg);
}

.nav-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.user-email {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 0.75rem;
}

/* ========== Shared source bar ========== */
.shared-source-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.shared-source-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 32px;
}

.source-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.camera-group {
    margin-left: auto;
    flex-shrink: 0;
}

.panel-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.upload-inline {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    vertical-align: middle;
}

.upload-thumb {
    width: 72px;
    height: 72px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    text-align: center;
    padding: 4px;
}

.upload-thumb:hover {
    border-color: var(--primary);
}

#upload-area.drag-over .upload-thumb {
    border-color: var(--primary);
    background: #eef2ff;
}

.source-preview {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
}

.source-actions {
    display: inline-flex;
    gap: 8px;
    margin-left: 12px;
    vertical-align: middle;
}

.source-status {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    width: 100%;
}

.source-status.success {
    color: var(--success);
}

.source-status.error {
    color: var(--danger);
}

.shared-camera-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.field-label-inline {
    font-size: 0.85rem;
    font-weight: 600;
}

.field-select {
    min-width: 180px;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

/* ========== Pages ========== */
.app-main {
    flex: 1;
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.page {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.page-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 12px;
}

/* Face Swap output */
.fs-video-shell {
    position: relative;
}

.video-frame {
    position: relative;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    max-height: 70vh;
}

.video-frame--large {
    width: 100%;
}

.video-el {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    vertical-align: top;
}

.sr-only-video {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.95rem;
    padding: 16px;
    text-align: center;
}

.video-overlay.hidden {
    display: none;
}

.btn-fs {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 5;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.btn-fs:hover {
    background: #fff;
}

.status-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 0.85rem;
}

.conn-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.connected {
    background: var(--success);
}

.dot.connecting {
    background: #f59e0b;
}

.dot.disconnected {
    background: #94a3b8;
}

.latency-text {
    color: var(--text-muted);
}

/* Dual grid */
.dual-video-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 768px) {
    .dual-video-grid {
        grid-template-columns: 1fr;
    }
}

.video-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.video-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.dual-status {
    justify-content: space-between;
}

.fps-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.65);
    color: #4ade80;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 4;
}

/* Placeholder */
.placeholder-card {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.placeholder-card h2 {
    margin: 0 0 0.5rem;
    font-weight: 600;
}

.placeholder-card p {
    margin: 0;
    color: var(--text-muted);
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.app-footer p {
    margin: 0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.modal-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 16px;
}

.modal-body img {
    max-width: 100%;
    max-height: 70vh;
    display: block;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

/* ========== Detect page ========== */

.detect-controls {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: center;
}

.btn-detect {
    background: #0891b2;
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-detect:hover {
    background: #0e7490;
}

.btn-detect:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-clear {
    background: #6b7280;
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-clear:hover {
    background: #4b5563;
}

.detect-result {
    margin: 6px 0 0;
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-muted);
    min-height: 1.2em;
}

.detect-result.genuine {
    color: #10b981;
    font-weight: 700;
}

.detect-result.fake {
    color: #ef4444;
    font-weight: 700;
}

.detect-json {
    margin: 8px 0 0;
    padding: 10px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.72rem;
    font-family: 'Courier New', monospace;
    max-height: 180px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: #334155;
}

/* ========== Scanning overlay ========== */

.scan-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    overflow: hidden;
    pointer-events: none;
    border-radius: var(--radius);
}

.scan-overlay .scan-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
}

.scan-overlay .scan-header {
    position: absolute;
    top: 12px;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 3;
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #22d3ee;
    text-shadow: 0 0 10px rgba(34, 211, 238, 0.8);
}

/* Corner brackets */
.scan-corners {
    position: absolute;
    inset: 12px;
}

.scan-corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: #22d3ee;
    animation: scan-pulse 1.5s ease-in-out infinite;
}

.scan-corner--tl { top: 0; left: 0; border-left: 2px solid; border-top: 2px solid; }
.scan-corner--tr { top: 0; right: 0; border-right: 2px solid; border-top: 2px solid; animation-delay: 0.1s; }
.scan-corner--bl { bottom: 0; left: 0; border-left: 2px solid; border-bottom: 2px solid; animation-delay: 0.2s; }
.scan-corner--br { bottom: 0; right: 0; border-right: 2px solid; border-bottom: 2px solid; animation-delay: 0.3s; }

/* Grid lines */
.scan-grid {
    position: absolute;
    inset: 24px;
}

.scan-grid .grid-h {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(34, 211, 238, 0.3), transparent);
}

.scan-grid .grid-v {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(to bottom, transparent, rgba(34, 211, 238, 0.3), transparent);
}

/* Grid nodes */
.scan-grid .grid-node {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22d3ee;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px 2px rgba(34, 211, 238, 0.6);
    animation: scan-pulse 1.5s ease-in-out infinite;
}

/* Scan line */
.scan-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(to right, transparent, #22d3ee, transparent);
    box-shadow: 0 0 20px 5px rgba(34, 211, 238, 0.8), 0 0 40px 10px rgba(34, 211, 238, 0.4);
    z-index: 2;
    transition: none;
}

.scan-trail {
    position: absolute;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to bottom, rgba(34, 211, 238, 0.2), transparent);
    z-index: 1;
    transition: none;
}

/* Status badge */
.scan-status {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 999px;
    border: 1px solid rgba(34, 211, 238, 0.4);
}

.scan-status .scan-dot {
    position: relative;
    width: 10px;
    height: 10px;
}

.scan-status .scan-dot::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #22d3ee;
    animation: scan-ping 1.2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.scan-status .scan-dot::after {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: 50%;
    background: #06b6d4;
}

.scan-status .scan-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #22d3ee;
    letter-spacing: 0.05em;
}

/* Progress bar inside status badge */
.scan-status .scan-progress {
    width: 60px;
    height: 4px;
    background: rgba(34, 211, 238, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.scan-status .scan-progress-fill {
    height: 100%;
    background: #22d3ee;
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* ========== Detection result indicators ========== */

.video-frame.result-genuine {
    border: 2px solid rgba(16, 185, 129, 0.8);
    animation: success-pulse 1s ease-in-out infinite;
}

.video-frame.result-fake {
    border: 2px solid rgba(239, 68, 68, 0.8);
    animation: danger-pulse 1s ease-in-out infinite;
}

/* Result banners */
.detect-banner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    padding: 6px 12px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    border-radius: var(--radius) var(--radius) 0 0;
}

.detect-banner--genuine {
    background: rgba(16, 185, 129, 0.92);
    color: #fff;
    animation: blink-success 0.8s ease-in-out infinite;
}

.detect-banner--fake {
    background: rgba(239, 68, 68, 0.92);
    color: #fff;
    animation: blink-warning 0.8s ease-in-out infinite;
}

/* ========== Keyframe animations ========== */

@keyframes scan-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes scan-ping {
    0% { transform: scale(1); opacity: 1; }
    75%, 100% { transform: scale(2.2); opacity: 0; }
}

@keyframes danger-pulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.5), 0 0 20px rgba(239, 68, 68, 0.3);
        border-color: rgba(239, 68, 68, 0.8);
    }
    50% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.8), 0 0 40px rgba(239, 68, 68, 0.5), 0 0 60px rgba(239, 68, 68, 0.3);
        border-color: rgba(239, 68, 68, 1);
    }
}

@keyframes success-pulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.5), 0 0 20px rgba(16, 185, 129, 0.3);
        border-color: rgba(16, 185, 129, 0.8);
    }
    50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.8), 0 0 40px rgba(16, 185, 129, 0.5), 0 0 60px rgba(16, 185, 129, 0.3);
        border-color: rgba(16, 185, 129, 1);
    }
}

@keyframes blink-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes blink-success {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---------------------------------------------------------------------------
   Visualizations page — filter sections (static/viz.js)
   --------------------------------------------------------------------------- */
.viz-page-hint {
    margin: 0 0 12px;
    color: var(--text-muted, #64748b);
    font-size: 0.9rem;
}

.viz-filters {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-height: none;
}

.viz-filter-section {
    background: var(--surface, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 16px 18px;
}

.viz-filter-title {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text, #0f172a);
}

.viz-filter-desc {
    margin: 0 0 14px;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--text-muted, #64748b);
}

.viz-canvas-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 900px) {
    .viz-canvas-grid {
        grid-template-columns: 1fr;
    }
}

.viz-canvas-cell {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.viz-canvas-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #64748b);
}

.viz-canvas {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    background: #0f172a;
    border: 1px solid var(--border, #e2e8f0);
}
