/* ═══════════════════════════════════════════════════
   RioCheck — chat-first student UI + teacher dashboard
   ═══════════════════════════════════════════════════ */

:root {
    --bg: #f4f6fa;
    --bg-white: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff4ff;
    --bot-bubble: #ffffff;
    --me-bubble: #2563eb;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --radius: 14px;
    --radius-sm: 8px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; margin: .5rem 0; }
h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: .75rem; }
h4 { font-size: .95rem; font-weight: 600; margin-bottom: .25rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.spacer { flex: 1; }
.label { font-size: .85rem; color: var(--text-muted); margin-bottom: .25rem; }

/* ── Buttons & inputs ── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem; padding: .55rem .95rem; border-radius: 999px;
    border: 1px solid var(--border); background: var(--bg-white); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; transition: var(--transition); white-space: nowrap; font-size: .95rem;
}
.btn:hover:not(:disabled) { border-color: #cbd5e1; box-shadow: var(--shadow); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.icon { padding: .55rem .7rem; }
.btn.danger { color: var(--danger); }
.link { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.link:disabled { color: var(--text-light); cursor: default; }
.input {
    width: 100%; padding: .6rem .85rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit;
    background: var(--bg-white); color: var(--text); transition: var(--transition);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.input.tiny { width: 5.5rem; }
.input.inline { width: auto; display: inline-block; margin-left: .5rem; }
.input.otp { letter-spacing: .4em; font-size: 1.25rem; text-align: center; font-variant-numeric: tabular-nums; }
.input.code { text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
textarea.input { resize: vertical; min-height: 2.5rem; }
label { display: block; font-size: .9rem; color: var(--text-muted); margin-bottom: .6rem; }
label > .input { margin-top: .25rem; color: var(--text); }
label input[type=checkbox] { margin-right: .4rem; accent-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .65rem; }
.chip { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #f1f5f9; color: var(--text-muted); }
.chip-success { background: #dcfce7; color: #166534; }
.chip-warning { background: #fef3c7; color: #92400e; }
.chip-danger { background: #fee2e2; color: #991b1b; }
.chip-info { background: #e0f2fe; color: #075985; }
.code-pill { background: var(--primary-light); color: var(--primary); padding: .15rem .5rem; border-radius: 6px; font-weight: 600; letter-spacing: .05em; }
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); background: var(--primary-light); color: var(--text); margin: .75rem 0; font-size: .95rem; }
.alert-warning { background: #fef3c7; }
.alert-danger { background: #fee2e2; }
.card { background: var(--bg-white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.card.empty { text-align: center; padding: 3rem 1.5rem; }
.card.empty i { font-size: 2.2rem; color: var(--text-light); margin-bottom: .75rem; }
.page-center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.empty-shell { min-height: 100vh; }

/* ── Chat shell (student) ── */
.chat-shell { min-height: 100vh; display: flex; flex-direction: column; max-width: 680px; margin: 0 auto; background: var(--bg); }
.chat-header {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
    padding: .8rem 1rem; background: rgba(244,246,250,.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--primary); display: inline-flex; align-items: center; gap: .45rem; }
.chat-nav { display: flex; gap: .25rem; }
.chat-nav a { padding: .4rem .6rem; border-radius: 999px; color: var(--text-muted); font-size: .9rem; transition: var(--transition); }
.chat-nav a:hover { background: var(--bg-white); color: var(--text); }
.chat-main { flex: 1; display: flex; flex-direction: column; }
.thread { flex: 1; padding: 1rem 1rem 1.5rem; display: flex; flex-direction: column; gap: .6rem; }
.bubble-row { display: flex; gap: .5rem; align-items: flex-end; animation: pop .18s ease; }
.bubble-row.me { justify-content: flex-end; }
.bubble-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: .8rem; flex-shrink: 0; }
.bubble {
    max-width: 88%; padding: .7rem .95rem; border-radius: 18px; background: var(--bot-bubble); box-shadow: var(--shadow); font-size: .97rem;
    border-bottom-left-radius: 6px;
}
.bubble-row.me .bubble { background: var(--me-bubble); color: #fff; border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.bubble > div + div { margin-top: .15rem; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.composer { position: sticky; bottom: 0; padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom)); background: rgba(244,246,250,.95); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.composer-row { display: flex; gap: .5rem; align-items: center; }
.composer-row .input { flex: 1; border-radius: 999px; padding-left: 1.1rem; }
.composer-row .btn { border-radius: 999px; }
.composer-hint { display: flex; gap: .5rem; justify-content: center; margin-top: .5rem; font-size: .85rem; color: var(--text-muted); }

.exam-card { background: var(--primary-light); border-radius: var(--radius-sm); padding: .75rem .9rem; margin: .35rem 0 .6rem; }
.exam-title { font-weight: 700; font-size: 1.05rem; }

.upload-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .7rem 0; }
.upload-btn {
    display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .8rem .4rem; border: 1.5px dashed #c7d2fe; border-radius: var(--radius-sm);
    background: var(--primary-light); color: var(--primary); font-weight: 600; font-size: .85rem; cursor: pointer; text-align: center; margin: 0; transition: var(--transition);
}
.upload-btn:hover { background: #e0e9ff; }
.upload-btn i { font-size: 1.3rem; }
.upload-btn input[type=file] { display: none; }

.page-strip { display: flex; gap: .6rem; overflow-x: auto; padding: .4rem .1rem .6rem; scroll-snap-type: x proximity; }
.page-thumb {
    position: relative; flex: 0 0 auto; width: 104px; border-radius: var(--radius-sm); overflow: hidden; background: #e5e7eb;
    box-shadow: var(--shadow); scroll-snap-align: start; cursor: grab; border: 2px solid transparent; transition: var(--transition);
}
.page-thumb.dragging { opacity: .5; }
.page-thumb img { width: 100%; height: 132px; object-fit: cover; }
.page-strip.readonly .page-thumb { width: 84px; cursor: pointer; }
.page-strip.readonly .page-thumb img { height: 108px; }
.page-thumb.blank img { opacity: .45; }
.blank-badge { position: absolute; left: 4px; right: 4px; bottom: 30px; border: none; border-radius: 6px; padding: .2rem .3rem; font: inherit; font-size: .68rem; font-weight: 600; background: rgba(255,255,255,.92); color: var(--warning); cursor: pointer; box-shadow: var(--shadow); }
.page-thumb:not(.blank) .blank-badge { color: var(--success); }
.page-num { position: absolute; top: 5px; left: 5px; background: rgba(0,0,0,.6); color: #fff; font-size: .7rem; font-weight: 700; padding: .05rem .4rem; border-radius: 999px; }
.page-actions { display: flex; justify-content: space-between; background: var(--bg-white); }
.page-actions button { flex: 1; border: none; background: none; padding: .3rem 0; font-size: .75rem; color: var(--text-muted); cursor: pointer; }
.page-actions button:hover:not(:disabled) { color: var(--primary); background: var(--primary-light); }
.page-actions button.danger:hover { color: var(--danger); }
.page-actions button:disabled { opacity: .3; cursor: default; }

.scan-overlay { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 1rem; }
.scan-overlay video { width: 100%; max-width: 480px; aspect-ratio: 3/4; object-fit: cover; border-radius: var(--radius); }
.scan-hint { color: #fff; text-align: center; font-size: .95rem; }

.sub-list { display: flex; flex-direction: column; margin: .25rem -0.4rem; }
.sub-item { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .65rem .4rem; border-bottom: 1px solid var(--border); transition: var(--transition); border-radius: var(--radius-sm); }
.sub-item:last-child { border-bottom: none; }
.sub-item:hover { background: var(--bg); }
.sub-title { font-weight: 600; }
.sub-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }

/* ── Result card ── */
.result-card { margin: .25rem 0; }
.result-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.result-score { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.result-score span { font-size: 1rem; color: var(--text-muted); font-weight: 500; }
.result-ratings { font-size: .85rem; color: var(--text-muted); text-align: right; }
.result-ratings b { color: var(--warning); letter-spacing: .05em; margin-left: .3rem; }
.progress { height: 8px; background: #e5e7eb; border-radius: 999px; margin: .75rem 0 1rem; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #60a5fa); border-radius: 999px; transition: width .6s ease; }
.q-list { display: flex; flex-direction: column; gap: .6rem; }
.q-row { display: flex; gap: .7rem; }
.q-num { flex: 0 0 2.6rem; font-weight: 700; color: var(--primary); }
.q-body { flex: 1; }
.q-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.q-feedback { font-size: .92rem; color: var(--text); margin-top: .1rem; }
.q-note { font-size: .88rem; color: var(--info); margin-top: .25rem; }
.q-evidence { font-size: .88rem; color: var(--text-muted); background: var(--bg); padding: .5rem .7rem; border-radius: var(--radius-sm); margin-top: .4rem; font-style: italic; }
.result-summary { margin: 1rem 0 .5rem; font-size: .95rem; }
.result-lists { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; font-size: .9rem; }
.result-lists ul { padding-left: 1.1rem; }
@media (max-width: 480px) { .result-lists { grid-template-columns: 1fr; } }

/* ── Teacher shell ── */
.teacher-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; flex-shrink: 0; background: var(--bg-white); border-right: 1px solid var(--border); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1.25rem;
    position: sticky; top: 0; height: 100vh;
}
.sidebar nav { display: flex; flex-direction: column; gap: .2rem; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; transition: var(--transition); }
.sidebar nav a:hover { background: var(--bg); color: var(--text); }
.sidebar nav a.active { background: var(--primary-light); color: var(--primary); }
.sidebar nav a i { width: 1.1rem; text-align: center; }
.sidebar-user { display: flex; align-items: center; gap: .6rem; }
.sidebar-user .name { font-weight: 600; font-size: .95rem; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.sidebar-foot { margin-top: auto; }
.teacher-content { flex: 1; padding: 1.5rem 2rem 3rem; max-width: 1280px; min-width: 0; }
.menu-toggle { display: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .chips { margin-top: 0; }
.page-head .chip { margin-left: .35rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.table-card { padding: .5rem 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem 1.25rem; }
.grid-2.top { gap: 1rem; align-items: stretch; margin-bottom: 1rem; }
.grid-2.top .card { margin-bottom: 0; }
.check-row { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin: .5rem 0; }
.check-row label { display: inline-flex; align-items: center; margin: 0; }
.step-no { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--primary); color: #fff; font-size: .8rem; margin-right: .4rem; }
.q-edit { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1rem .4rem; margin-bottom: .9rem; background: #fafbfd; }
.q-edit-head { display: flex; gap: .75rem; align-items: center; margin-bottom: .4rem; }
.q-edit-head label { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.weights { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .75rem; }
.weights label { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.form-actions { display: flex; gap: .6rem; align-items: center; margin: 1rem 0; }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; }
.code-card .big-code { font-size: 2.6rem; font-weight: 700; letter-spacing: .12em; color: var(--primary); font-family: ui-monospace, Menlo, Consolas, monospace; margin: .25rem 0; }
.qr-card { display: grid; place-items: center; }
.qr-card img { width: 180px; height: 180px; image-rendering: pixelated; }
.print-header { display: none; }

/* ── Social login ── */
.social-row { display: flex; gap: .5rem; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: .65rem; }
.btn.social { background: var(--bg-white); }
.btn.social .fa-google { color: #ea4335; }
.btn.social .fa-microsoft { color: #0078d4; }

/* ── Admin settings ── */
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.settings-nav { padding: .5rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 1rem; }
.settings-nav a { display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; }
.settings-nav a:hover { background: var(--bg); color: var(--text); }
.settings-nav a.active { background: var(--primary-light); color: var(--primary); }
.settings-nav a i { width: 1.1rem; text-align: center; }
.settings-body .card { max-width: 760px; }
.field { margin-bottom: 1.1rem; }
.field > label { font-weight: 500; color: var(--text); margin-bottom: .3rem; display: flex; align-items: center; gap: .5rem; }
.field .help { margin-top: .3rem; }
.field .input.narrow { width: 12rem; }
.field .input.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; }
.source-badge { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 999px; background: #f1f5f9; color: var(--text-light); }
.switch { display: inline-flex !important; align-items: center; gap: .5rem; margin: 0 !important; }
.switch input { width: 2.6rem; height: 1.4rem; appearance: none; background: #cbd5e1; border-radius: 999px; position: relative; cursor: pointer; transition: var(--transition); margin: 0 !important; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 1.1rem; height: 1.1rem; background: #fff; border-radius: 50%; transition: var(--transition); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: calc(100% - 1.25rem); }
.secret-row { display: flex; gap: .75rem; align-items: center; }
.secret-row .input { flex: 1; }
.secret-row label { margin: 0; white-space: nowrap; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; } }

/* ── Usage ── */
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat-row .card { margin-bottom: 0; }
.stat-value { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; }
.stat-value.small-value { font-size: .95rem; font-weight: 600; }
.progress-fill.near { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.progress-fill.over { background: var(--danger); }
.table.compact th, .table.compact td { padding: .4rem .5rem; }
@media (max-width: 900px) { .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── Review ── */
.review-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.review-pages { display: flex; flex-direction: column; gap: 1rem; }
.review-page { background: var(--bg-white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.review-page-head { padding: .5rem .9rem; font-weight: 600; font-size: .9rem; border-bottom: 1px solid var(--border); }
.review-page img { width: 100%; }
.ocr-text { white-space: pre-wrap; font-size: .8rem; padding: .75rem .9rem; background: #fafbfd; border-top: 1px solid var(--border); max-height: 280px; overflow: auto; font-family: inherit; }
.review-eval { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; padding-right: .25rem; }
.q-review-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .3rem; }
.q-override { display: flex; gap: .75rem; align-items: flex-end; margin-top: .6rem; }
.q-override label { margin: 0; }
.q-override .grow { flex: 1; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s ease; box-shadow: var(--shadow-md); }
    .sidebar.open { left: 0; }
    .menu-toggle { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-white); margin-bottom: 1rem; cursor: pointer; }
    .teacher-content { padding: 1rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .review-grid { grid-template-columns: 1fr; }
    .review-eval { position: static; max-height: none; }
}

/* ── Print (exam header with QR) ── */
@media print {
    body { background: #fff; }
    .sidebar, .page-head, .grid-2.top, .table-card, .menu-toggle, .chips { display: none !important; }
    .teacher-content { padding: 0; }
    .print-header { display: block; text-align: center; padding: 2rem; border: 2px solid #000; }
    .print-header .ph-title { font-size: 1.8rem; font-weight: 700; }
    .print-header .ph-meta { margin: .25rem 0 1rem; }
    .print-header .ph-code { font-size: 1.3rem; margin-bottom: 1rem; letter-spacing: .05em; }
    .print-header img { width: 160px; height: 160px; margin: 0 auto; }
}
