/* ============================================================
   Plickers Clone - Global Styles
   ============================================================ */

:root {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-dark: #3730A3;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --border: #E2E8F0;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);

    /* Answer colors */
    --color-a: #4F46E5;
    --color-b: #10B981;
    --color-c: #F59E0B;
    --color-d: #EF4444;
}

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

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

/* ============================================================
   Layout
   ============================================================ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 24px 32px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header .subtitle {
    font-size: 14px;
    opacity: 0.85;
    margin-top: 4px;
}

/* ============================================================
   Cards (UI cards, not ArUco cards)
   ============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-info:
 background: #3B82F6;
    color: white;
}

.btn-info:hoer {
    background: #2563EB;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================
   Forms
   ============================================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    color: var(--text);
    transition: border-color 0.2s;
    background: var(--surface);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

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

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ============================================================
   Grid Layout
   ============================================================ */
.grid {
    display: grid;
    gap: 20px;
}

.grid-2 {
    grid-template-columns: 1fr 1fr;
}

.grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.grid-4 {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

/* ============================================================
   Stats Display
   ============================================================ */
.stats-row {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    flex: 1;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.stat-card.stat-a::before { background: var(--color-a); }
.stat-card.stat-b::before { background: var(--color-b); }
.stat-card.stat-c::before { background: var(--color-c); }
.stat-card.stat-d::before { background: var(--color-d); }

.stat-label {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.stat-a .stat-label { color: var(--color-a); }
.stat-b .stat-label { color: var(--color-b); }
.stat-c .stat-label { color: var(--color-c); }
.stat-d .stat-label { color: var(--color-d); }

.stat-value {
    font-size: 48px;
    font-weight: 800;
    line-height: 1;
}

.stat-percent {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============================================================
   Progress Bars
   ============================================================ */
.bar-chart {
    margin: 20px 0;
}

.bar-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.bar-label {
    font-size: 16px;
    font-weight: 700;
    width: 24px;
    text-align: center;
}

.bar-track {
    flex: 1;
    height: 32px;
    background: #F1F5F9;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    padding: 0 12px;
    min-width: 0;
}

.bar-fill-a { background: var(--color-a); }
.bar-fill-b { background: var(--color-b); }
.bar-fill-c { background: var(--color-c); }
.bar-fill-d { background: var(--color-d); }

.bar-count {
    font-size: 13px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
}

/* ============================================================
   Quiz Status Badges
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-draft { background: #F1F5F9; color: var(--text-secondary); }
.badge-active { background: #DCFCE7; color: #166534; }
.badge-closed { background: #FEE2E2; color: #991B1B; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.active {
    background: var(--success);
    animation: pulse 1.5s infinite;
}

.status-dot.inactive {
    background: var(--text-secondary);
}

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

/* ============================================================
   Student List
   ============================================================ */
.student-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.student-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: #F8FAFC;
    border-radius: 8px;
    font-size: 13px;
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.student-chip.answered {
    background: #DCFCE7;
    border-color: #86EFAC;
}

.student-chip .card-num {
    font-weight: 700;
    color: var(--primary);
    font-size: 11px;
}

.student-chip .answer-badge {
    margin-left: auto;
    font-weight: 700;
    font-size: 12px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: white;
}

.answer-badge.ans-a { background: var(--color-a); }
.answer-badge.ans-b { background: var(--color-b); }
.answer-badge.ans-c { background: var(--color-c); }
.answer-badge.ans-d { background: var(--color-d); }

/* ============================================================
   Connection Status
   ============================================================ */
.ws-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    background: #F1F5F9;
}

.ws-status.connected {
    background: #DCFCE7;
    color: #166534;
}

.ws-status.disconnected {
    background: #FEE2E2;
    color: #991B1B;
}

/* ============================================================
   Scanner Styles (H5)
   ============================================================ */
.scanner-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.scanner-container video {
    width: 100%;
    border-radius: var(--radius);
    background: #000;
}

.scanner-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scan-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    pointer-events: none;
}

.scan-result-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .stats-row {
        flex-wrap: wrap;
    }

    .stat-card {
        min-width: calc(50% - 8px);
    }

    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .student-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
}

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

/* ============================================================
   Student Table
   ============================================================ */
.student-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.student-table thead th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    background: #F8FAFC;
    position: sticky;
    top: 0;
}

.student-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.student-table tbody tr:hover {
    background: #F1F5F9;
}

.student-table tbody td {
    padding: 10px 12px;
    vertical-align: middle;
}

.student-table .card-id {
    font-weight: 700;
    color: var(--primary);
    font-size: 13px;
    background: #EEF2FF;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.student-table .student-name {
    font-weight: 600;
    color: var(--text);
}

.student-table .actions {
    display: flex;
    gap: 6px;
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
    position: relative;
    margin-top: 80px;
    padding: 36px 0 32px;
    border-top: 1px solid rgba(79, 70, 229, 0.08);
    text-align: center;
    background: linear-gradient(180deg, transparent 0%, rgba(79, 70, 229, 0.015) 100%);
    z-index: 1;
}
.footer-tagline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.footer-tagline-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.3px;
}
.footer-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.footer-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
    background: rgba(79, 70, 229, 0.06);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.1);
    transition: all 0.25s;
}
.footer-badge:hover {
    background: rgba(79, 70, 229, 0.1);
    border-color: rgba(79, 70, 229, 0.2);
    transform: translateY(-1px);
}
.footer-badge i {
    font-size: 11px;
    opacity: 0.8;
}
.footer-divider {
    width: 40px;
    height: 2px;
    background: rgba(79, 70, 229, 0.15);
    border-radius: 1px;
    margin: 0 auto 16px;
}
.footer-info {
    font-size: 12px;
    color: #94a3b8;
    line-height: 2;
    letter-spacing: 0.2px;
}
.footer-info a {
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.2s;
    border-bottom: 1px solid transparent;
}
.footer-info a:hover {
    color: var(--primary);
    border-bottom-color: rgba(79, 70, 229, 0.3);
}
/* Quiz Enhanced Styles */
.student-chip.correct { border-left: 3px solid #10B981 !important; background: rgba(16,185,129,0.08); }
.student-chip.incorrect { border-left: 3px solid #EF4444 !important; background: rgba(239,68,68,0.08); }
.status-correct { color: #10B981; font-size: 12px; font-weight: 600; }
.status-pending { font-size: 11px; color: #94A3B8; }
.quiz-stats-bar { display: flex; gap: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.stat-item { display: flex; flex-direction: column; align-items: center; padding: 12px 20px; background: linear-gradient(135deg, #F8FAFC 0%, #EEF2FF 100%); border-radius: 12px; min-width: 100px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: #64748B; margin-top: 4px; }
.stat-progress { width: 100%; height: 6px; background: #E2E8F0; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.stat-progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), #818CF8); border-radius: 3px; transition: width 0.5s ease; }
.correct-rate { font-size: 18px; font-weight: 700; color: #10B981; }
.chart-bar { display: flex; align-items: flex-end; gap: 8px; height: 80px; justify-content: center; margin-top: 12px; }
.chart-bar-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar-fill { width: 36px; background: var(--primary); border-radius: 4px 4px 0 0; transition: height 0.5s ease; }
.chart-bar-fill.correct { background: #10B981; }
.chart-bar-label { font-size: 12px; font-weight: 600; }
.chart-bar-count { font-size: 11px; color: #64748B; }
.answer-reveal { margin-top: 16px; padding: 16px; background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%); border-radius: 12px; border: 1px solid #10B981; text-align: center; }
.answer-reveal-label { font-size: 13px; color: #059669; margin-bottom: 4px; }
.answer-reveal-value { font-size: 28px; font-weight: 800; color: #059669; }
.btn-reveal { position: fixed; bottom: 24px; right: 24px; z-index: 100; }

/* Merged dashboard - progress + options side by side */
.merged-dashboard { display:flex; gap:16px; align-items:stretch; }
.compact-stats { display:flex; gap:12px; }
.compact-stat { text-align:center; min-width:55px; }
.compact-stat-value { font-size:20px; font-weight:700; }
.compact-stat-label { font-size:10px; color:var(--text-secondary); margin-top:2px; letter-spacing:0.5px; text-transform:uppercase; }
.compact-options { display:flex; gap:6px; align-items:center; }
.compact-option { display:flex; flex-direction:column; align-items:center; padding:6px 10px; border-radius:8px; min-width:48px; font-weight:600; font-size:12px; }
.compact-option.stat-a { background:rgba(79,70,229,0.1); color:var(--color-a); }
.compact-option.stat-b { background:rgba(16,185,129,0.1); color:var(--color-b); }
.compact-option.stat-c { background:rgba(245,158,11,0.1); color:var(--color-c); }
.compact-option.stat-d { background:rgba(239,68,68,0.1); color:var(--color-d); }
.compact-option .opt-pct { font-size:10px; opacity:0.7; }
.mini-bar { height:6px; border-radius:3px; background:#E2E8F0; overflow:hidden; }
.mini-bar-fill { height:100%; border-radius:3px; transition:width 0.5s ease; }
.mini-bar-count { font-size:9px; color:white; padding-left:4px; line-height:6px; }

@media (max-width:640px) {
  .merged-dashboard { flex-direction:column; }
}

/* Profile Modal */
.profile-modal-content { background:white; border-radius:16px; max-width:560px; width:90%; max-height:90vh; overflow-y:auto; padding:24px; box-shadow:0 20px 60px rgba(0,0,0,0.3); animation:modalIn 0.25s ease; }
@keyframes modalIn { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }
.profile-modal-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:16px; }
.profile-stats-row { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.profile-stat-card { background:#F8FAFC; border-radius:10px; padding:12px; text-align:center; }
.profile-stat-value { font-size:22px; font-weight:800; }
.profile-stat-label { font-size:11px; color:#94A3B8; margin-top:2px; font-weight:500; }

/* Quiz Running Mode - Pending badge */
.pending-badge { display:inline-flex; align-items:center; gap:4px; padding:2px 10px; border-radius:12px; font-size:11px; font-weight:600; background:#E2E8F0; color:#64748B; }
.student-chip.answered .pending-badge { background:#DBEAFE; color:#3B82F6; }

/* Student grid layout */
.quiz-student-grid-wrap { display:grid; grid-template-columns:repeat(auto-fill,minmax(140px,1fr)); gap:8px; }

/* Top stats bar - dashboard style */
.dashboard-stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-bottom:16px; }
.dashboard-stat-card { background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:16px; text-align:center; }
.dashboard-stat-value { font-size:28px; font-weight:700; }
.dashboard-stat-label { font-size:12px; color:var(--text-secondary); margin-top:2px; }

/* Quiz action bar */
.quiz-action-bar { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0; }
