/* ============================================================
   Rich text editor (js-rich) + LaTeX math + tables
   ============================================================ */
.rte-wrap{border:1px solid var(--line,#e2e8f0);border-radius:10px;overflow:hidden;background:#fff}
.rte-wrap.focus{border-color:var(--primary,#4173af);box-shadow:0 0 0 3px rgba(65,115,175,.12)}
.rte-toolbar{display:flex;flex-wrap:wrap;gap:2px;padding:6px;background:#f8fafc;border-bottom:1px solid var(--line,#e2e8f0)}
.rte-toolbar button{border:0;background:transparent;width:32px;height:30px;border-radius:6px;cursor:pointer;color:#334155;font-size:14px;display:inline-flex;align-items:center;justify-content:center;transition:background .12s}
.rte-toolbar button:hover{background:#e2e8f0}
.rte-toolbar button.on{background:var(--primary,#4173af);color:#fff}
.rte-toolbar .rte-sep{width:1px;background:#e2e8f0;margin:3px 4px}
.rte-toolbar button[data-cmd="h2"],.rte-toolbar button[data-cmd="h3"]{width:auto;padding:0 8px;font-weight:700;font-size:13px}
.rte-area{min-height:150px;max-height:520px;overflow:auto;padding:12px 14px;font-size:15px;line-height:1.7;color:var(--ink,#1e293b);outline:none}
.rte-area:empty:before{content:attr(data-ph);color:#94a3b8}
.rte-area h2{font-size:22px;margin:.6em 0 .3em}
.rte-area h3{font-size:18px;margin:.6em 0 .3em}
.rte-area ul,.rte-area ol{padding-left:26px;margin:.4em 0}
.rte-area blockquote{border-left:4px solid var(--primary,#4173af);margin:.6em 0;padding:6px 14px;color:#475569;background:#f8fafc;border-radius:0 6px 6px 0}
.rte-area a{color:var(--primary,#4173af);text-decoration:underline}
.rte-area hr{border:0;border-top:2px solid #e2e8f0;margin:1em 0}
.rte-area table,.rich-content table{border-collapse:collapse;margin:.6em 0;min-width:60%}
.rte-area td,.rte-area th,.rich-content td,.rich-content th{border:1px solid #cbd5e1;padding:6px 10px;min-width:40px}
.rte-area th,.rich-content th{background:#f1f5f9;font-weight:700}
.rte-area table.sel-tbl{outline:2px dashed var(--primary,#4173af)}

/* display-side rendered rich content */
.rich-content{line-height:1.7}
.rich-content h2{font-size:22px;margin:.6em 0 .3em}
.rich-content h3{font-size:18px;margin:.6em 0 .3em}
.rich-content ul,.rich-content ol{padding-left:26px;margin:.4em 0}
.rich-content blockquote{border-left:4px solid var(--primary,#4173af);margin:.6em 0;padding:6px 14px;color:#475569;background:#f8fafc;border-radius:0 6px 6px 0}
.rich-content a{color:var(--primary,#4173af);text-decoration:underline}
.rich-content hr{border:0;border-top:2px solid #e2e8f0;margin:1em 0}
.rich-content table{overflow-x:auto}

/* answer-option cards (question editors) */
.ans-head{font-weight:700;letter-spacing:.04em;color:var(--muted,#64748b);font-size:12.5px;margin-bottom:2px}
.opt-card{border:1.5px solid var(--line,#e2e8f0);border-radius:12px;padding:12px 14px;margin-bottom:12px;transition:border-color .15s,background .15s}
.opt-card.selected{border-color:var(--success,#16a34a);background:#f0fdf4}
.opt-head{display:flex;align-items:center;gap:10px;margin-bottom:8px}
.opt-head b{font-size:15px}
.opt-dot{width:22px;height:22px;border-radius:50%;border:2px solid #cbd5e1;cursor:pointer;position:relative;flex:none;transition:border-color .15s}
.opt-dot:hover{border-color:var(--primary,#4173af)}
.opt-card.selected .opt-dot{border-color:var(--success,#16a34a)}
.opt-card.selected .opt-dot:after{content:"";position:absolute;inset:3px;border-radius:50%;background:var(--success,#16a34a)}
.opt-correct{display:none;color:var(--success,#16a34a);font-weight:700;font-size:12px;letter-spacing:.03em}
.opt-card.selected .opt-correct{display:inline-flex;align-items:center;gap:4px}
.opt-card .rte-wrap{margin-top:0}

/* images inside editor + display */
.rte-area img,.rich-content img{max-width:100%;height:auto;border-radius:8px;margin:6px 0}
.rich-content figure{margin:.8em 0}
.rich-content figcaption{font-size:13px;color:#64748b;text-align:center;margin-top:4px}

/* image upload dropzone (inside modal) */
.rte-imgdrop{border:2px dashed #cbd5e1;border-radius:10px;padding:22px;text-align:center;cursor:pointer;color:#64748b;background:#f8fafc;transition:.15s}
.rte-imgdrop.drag{border-color:var(--primary,#4173af);background:#eef4fb;color:var(--primary,#4173af)}
.rte-imgdrop i{font-size:24px;display:block;margin-bottom:6px}

/* rendered inline math */
.math-tex{display:inline-block;padding:0 2px;cursor:default}
.rte-area .math-tex{background:#eef4fb;border-radius:4px;cursor:pointer}
.rte-area .math-tex:hover{outline:1px solid var(--primary,#4173af)}
.math-tex .katex{font-size:1.05em}

/* table context bar */
.rte-tablebar{display:none;gap:4px;padding:6px;background:#eef4fb;border-top:1px solid var(--line,#e2e8f0);flex-wrap:wrap}
.rte-tablebar.show{display:flex}
.rte-tablebar button{border:1px solid #cbd5e1;background:#fff;border-radius:6px;padding:4px 9px;font-size:12px;cursor:pointer;color:#334155}
.rte-tablebar button:hover{background:#f1f5f9}
.rte-tablebar button.danger{color:#dc2626;border-color:#fecaca}

/* ---- modal (formula + link + table) ---- */
.rte-modal{position:fixed;inset:0;background:rgba(15,23,42,.6);z-index:9000;display:none;align-items:flex-start;justify-content:center;padding:40px 16px;overflow:auto}
.rte-modal.show{display:flex}
.rte-dialog{background:#fff;border-radius:14px;width:100%;max-width:760px;box-shadow:0 20px 60px rgba(0,0,0,.3)}
.rte-dialog.sm{max-width:440px}
.rte-dhead{display:flex;justify-content:space-between;align-items:center;padding:14px 18px;border-bottom:1px solid #e2e8f0}
.rte-dhead h3{margin:0;font-size:17px}
.rte-dhead .x{border:0;background:transparent;font-size:20px;cursor:pointer;color:#64748b;width:32px;height:32px;border-radius:8px}
.rte-dhead .x:hover{background:#f1f5f9}
.rte-dbody{padding:16px 18px}
.rte-dbody label{display:block;font-size:13px;font-weight:600;margin:0 0 5px;color:#334155}
.rte-dbody input[type=text],.rte-dbody textarea{width:100%;padding:9px 11px;border:1px solid #cbd5e1;border-radius:8px;font-size:14px;font-family:inherit}
.rte-dbody textarea.latex{font-family:ui-monospace,Menlo,Consolas,monospace;min-height:70px}
.rte-preview{margin-top:12px;padding:16px;border:1px dashed #cbd5e1;border-radius:8px;background:#f8fafc;min-height:56px;text-align:center;overflow:auto}
.rte-preview .err{color:#dc2626;font-size:13px}
.rte-quick{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px}
.rte-quick button{border:1px solid #cbd5e1;background:#fff;border-radius:20px;padding:4px 12px;font-size:12px;cursor:pointer;color:#334155}
.rte-quick button:hover{background:var(--primary,#4173af);color:#fff;border-color:var(--primary,#4173af)}
.rte-dfoot{display:flex;justify-content:flex-end;gap:8px;padding:14px 18px;border-top:1px solid #e2e8f0}
.rte-dfoot .btn{padding:8px 18px;border-radius:8px;font-size:14px;cursor:pointer;border:1px solid #cbd5e1;background:#fff}
.rte-dfoot .btn.primary{background:var(--primary,#4173af);color:#fff;border-color:var(--primary,#4173af)}

/* reference panel */
.rte-ref{margin-top:18px;border-top:1px solid #e2e8f0;padding-top:14px}
.rte-ref>.hd{font-weight:700;font-size:14px;margin-bottom:8px}
.rte-ref .search{width:100%;padding:8px 11px;border:1px solid #cbd5e1;border-radius:8px;font-size:13px;margin-bottom:10px}
.rte-tabs{display:flex;gap:4px;flex-wrap:wrap;margin-bottom:10px}
.rte-tabs button{border:1px solid #e2e8f0;background:#f8fafc;border-radius:20px;padding:5px 13px;font-size:12px;cursor:pointer;color:#475569}
.rte-tabs button.on{background:var(--primary,#4173af);color:#fff;border-color:var(--primary,#4173af)}
.rte-reflist{max-height:230px;overflow:auto;display:grid;grid-template-columns:1fr 1fr;gap:6px}
.rte-refitem{display:flex;align-items:center;justify-content:space-between;gap:8px;border:1px solid #e2e8f0;border-radius:8px;padding:7px 10px;cursor:pointer;background:#fff}
.rte-refitem:hover{border-color:var(--primary,#4173af);background:#f8fafc}
.rte-refitem .lbl{font-size:12px;color:#334155}
.rte-refitem .rnd{min-width:44px;text-align:right}
.rte-refitem code{font-size:11px;color:#64748b;background:#f1f5f9;padding:1px 5px;border-radius:4px}
@media(max-width:620px){.rte-reflist{grid-template-columns:1fr}}
