/* ── Reset & Variables ─────────────────────────────────────────── */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --text: #e1e4ed;
    --text-dim: #8b8fa3;
    --primary: #6c7bf0;
    --primary-hover: #8590f5;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding: 12px 20px;
    max-width: 1800px;
    margin: 0 auto;
}

h1 { font-size: 1.6rem; font-weight: 600; margin-bottom: 12px; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 10px; color: var(--text-dim); }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--border); }
.btn-secondary:hover { background: #3a3d4a; }
.btn-success { background: #059669; }
.btn-success:hover { background: #047857; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; border: none; border-radius: 4px; background: var(--border); color: var(--text); cursor: pointer; }
.btn-sm:hover { background: #3a3d4a; }
.btn-sm.btn-danger { background: #7f1d1d; color: #fca5a5; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

/* ── Tables ───────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
th { color: var(--text-dim); font-weight: 500; }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-created { background: #1e3a5f; color: #60a5fa; }
.badge-calibrated { background: #1a3a2a; color: #6ee7b7; }
.badge-recording { background: #5c2121; color: #fca5a5; }
.badge-completed { background: #1a3a2a; color: var(--success); }

/* ── Upload ───────────────────────────────────────────────────── */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    color: var(--text-dim);
    transition: border-color 0.15s;
    margin-bottom: 10px;
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); color: var(--text); }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 400px;
    max-width: 90vw;
}
.modal label { display: block; margin-bottom: 12px; font-size: 0.875rem; color: var(--text-dim); }
.modal input, .modal select {
    display: block; width: 100%; margin-top: 4px; padding: 8px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    color: var(--text); font-size: 0.875rem;
}
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ── Recording page ───────────────────────────────────────────── */
.record-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.record-header h1 { margin: 0; }

.record-layout { display: flex; gap: 12px; }

.record-sidebar { width: 240px; flex-shrink: 0; }

.webcam-container {
    position: relative;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 8px;
}
.webcam-container video { width: 100%; display: block; }

.face-indicator {
    position: absolute; top: 8px; right: 8px;
    padding: 2px 8px; border-radius: 4px;
    font-size: 0.75rem; font-weight: 600;
    background: rgba(220,38,38,0.8); color: #fff;
}
.face-indicator.face-ok { background: rgba(5,150,105,0.8); }

.calibration-panel .btn { font-size: 0.8rem; padding: 6px 12px; }

.calibration-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.calibration-panel .btn { display: block; width: 100%; margin-top: 8px; }

.calib-status { font-size: 0.85rem; margin-bottom: 8px; padding: 8px; border-radius: 4px; }
.calib-info { background: #1e3a5f; color: #93c5fd; }
.calib-success { background: #1a3a2a; color: #6ee7b7; }
.calib-error { background: #5c2121; color: #fca5a5; }

.record-main { flex: 1; min-width: 0; }

.video-wrapper {
    position: relative;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    height: calc(100vh - 140px);
    min-height: 400px;
}
.video-wrapper video { width: 100%; height: 100%; object-fit: contain; }
.video-wrapper canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}

.calib-dot {
    position: absolute;
    top: 50%; left: 50%;
    width: 20px; height: 20px;
    margin: -10px 0 0 -10px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 12px var(--danger);
    animation: pulse 1.5s infinite;
    z-index: 10;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

.record-controls {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0;
}
.record-controls span { font-size: 0.9rem; color: var(--text-dim); }

/* ── Results page ─────────────────────────────────────────────── */
.results-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.results-header h1 { margin: 0; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
    padding: 8px 16px; border: none; border-radius: 6px 6px 0 0;
    background: var(--border); color: var(--text-dim);
    cursor: pointer; font-size: 0.875rem;
}
.tab.active { background: var(--surface); color: var(--text); }

.viz-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    padding: 16px;
}

.viz-panel { display: flex; justify-content: center; }

.viz-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
}
.viz-wrapper video {
    display: block;
    max-width: 100%;
    max-height: 500px;
    border-radius: 4px;
}
.viz-overlay {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: contain;
    pointer-events: none;
    opacity: 0.75;
}

.viz-controls { margin-top: 12px; display: flex; gap: 8px; align-items: center; }
.viz-controls label { font-size: 0.85rem; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.viz-controls input {
    width: 100px; padding: 4px 8px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    color: var(--text); font-size: 0.85rem;
}

.export-section { margin-top: 16px; display: flex; gap: 8px; align-items: center; }
.export-section h3 { margin: 0; margin-right: 8px; }

.raw-data-section { margin-top: 16px; }
.raw-table-container { max-height: 400px; overflow-y: auto; }

.loading { text-align: center; padding: 60px; color: var(--text-dim); font-size: 1.1rem; }

/* ── AWRI Integration ─────────────────────────────────────────── */
.awri-container { max-width: 1600px; margin: 0 auto; }

.awri-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.awri-header h1 {
    font-size: 1.4rem;
    color: var(--primary);
    margin: 0;
}
.awri-participant {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.awri-error {
    text-align: center;
    padding: 60px 20px;
    color: var(--danger);
}
.awri-error p {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.awri-results {
    text-align: center;
    padding: 60px 20px;
}
.awri-results-icon {
    font-size: 4rem;
    color: var(--success);
    margin-bottom: 16px;
}
.awri-results h2 {
    font-size: 1.6rem;
    color: var(--text);
    margin-bottom: 8px;
}
.awri-results p {
    color: var(--text-dim);
    margin-bottom: 16px;
}
.awri-results-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 24px 0;
}
.awri-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.awri-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.awri-stat-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 4px;
}
.awri-results-note {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 24px;
}
.awri-return-btn {
    font-size: 1.1rem;
    padding: 12px 32px;
}

/* ── Countdown overlay (auto-calibration) ────────────────────── */
.calib-dot.countdown-active {
    width: 80px;
    height: 80px;
    margin: -40px 0 0 -40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    color: #fff;
    background: rgba(248, 113, 113, 0.9);
    box-shadow: 0 0 30px rgba(248, 113, 113, 0.6);
    animation: none;
}

.calib-dot.countdown-tick {
    animation: countdown-pop 0.4s ease-out;
}

@keyframes countdown-pop {
    0% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 900px) {
    .record-layout { flex-direction: column; }
    .record-sidebar { width: 100%; }
}
