:root {
    --brand: #7b1fa2;
    --brand-dark: #5a1178;
    --brand-soft: #f5e9fa;
    --ink: #1d1627;
    --muted: #6b6378;
    --line: #e4dfeb;
    --bg: #f5f3f8;
    --surface: #ffffff;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --err: #b91c1c;
    --err-soft: #fee2e2;
    --radius: 12px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    color: var(--ink);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--brand); }
h1 { font-size: 1.75rem; margin: 0 0 .3em; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 0 0 .6em; }
h3 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
h4 { font-size: .9rem; margin: 1.4em 0 .5em; color: var(--muted); }
code { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); font-weight: 700; }
.inline { display: inline; }

/* Barra superior */
.topbar { background: #1d1627; color: #fff; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 20px; height: 56px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 1.1rem; text-decoration: none; }
.brand span { font-weight: 500; color: #c9b8dc; font-size: .85rem; }
.brand-dark { color: var(--ink); }
.topnav { display: flex; align-items: center; gap: 20px; }
.topnav a, .linkbtn { color: #d9cde6; text-decoration: none; font-size: .92rem; }
.topnav a:hover, .linkbtn:hover { color: #fff; }
.topnav form { margin: 0; }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 20px 64px; }

/* Botones */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; min-height: 38px; font: inherit; font-weight: 600; font-size: .92rem;
    color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
    text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #faf8fc; border-color: #d3cadf; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-success:hover { background: #166534; border-color: #166534; }
.btn-warn { background: var(--warn-soft); border-color: #fcd34d; color: #92400e; }
.btn-warn:hover { background: #fde68a; border-color: #fbbf24; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost-danger { color: var(--err); }
.btn-ghost-danger:hover { background: var(--err-soft); border-color: #fca5a5; }
.btn-link { border-color: transparent; background: none; color: var(--brand); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: .84rem; }
.btn-block { width: 100%; }
.icon-btn { width: 30px; height: 30px; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; cursor: pointer; font-size: .75rem; color: var(--muted); }
.icon-btn:hover:not(:disabled) { color: var(--ink); border-color: #cfc5db; }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* Mensajes */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; }
.flash-success { background: var(--ok-soft); color: #14532d; }
.flash-error { background: var(--err-soft); color: #7f1d1d; }

/* Estructura */
.page-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.section-head h2 { margin: 0; }
.section-head p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form .actions { margin-top: 8px; }
.crumb { display: inline-block; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: 8px; }
.crumb:hover { color: var(--brand); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.narrow { max-width: 720px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.two-col.wide-right { grid-template-columns: minmax(260px, 1fr) 2fr; }
.two-col > .panel { margin-bottom: 0; }
.two-col + .panel { margin-top: 20px; }

.empty-state { text-align: center; background: var(--surface); border: 1px dashed #d3cadf; border-radius: var(--radius); padding: 48px 24px; }
.empty-state p { color: var(--muted); max-width: 460px; margin: 0 auto 18px; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .02em; background: #eee9f3; color: var(--muted); vertical-align: middle; }
.badge-open, .badge-active { background: var(--ok-soft); color: #166534; }
.badge-closed { background: #fde2e2; color: #991b1b; }
.badge-draft { background: #eee9f3; color: #5b536a; }
.badge-archived { background: #e5e7eb; color: #4b5563; }
.badge-type { background: var(--brand-soft); color: var(--brand-dark); }

/* Eventos */
.event-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.event-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
.event-card:hover { border-color: #cdb6dc; box-shadow: 0 8px 24px -14px rgba(90, 17, 120, .35); transform: translateY(-1px); }
.event-card.is-archived { opacity: .65; }
.event-card h2 { margin: 10px 0 12px; font-size: 1.15rem; }
.event-card-top { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; }
.event-card-stats { display: flex; gap: 18px; color: var(--muted); font-size: .9rem; }
.event-card-stats strong { color: var(--ink); }

.event-head { margin-bottom: 16px; }
.event-head h1 { margin: 0 0 4px; }
.event-head p { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 24px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Tarjetas de pregunta */
.q-card { display: grid; grid-template-columns: 40px minmax(0, 1fr) 150px; gap: 18px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid #d6cde2; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.q-card.status-open { border-left-color: var(--ok); }
.q-card.status-closed { border-left-color: #f87171; }
.q-card h3 { margin: 8px 0 12px; font-size: 1.1rem; }
.q-order { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.q-order form { margin: 0; }
.q-num { font-weight: 800; color: var(--muted); }
.q-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.q-actions { display: flex; flex-direction: column; gap: 8px; }
.q-actions form { margin: 0; }

.links { display: grid; gap: 6px; }
.link-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto auto auto; gap: 8px; align-items: center; }
.link-row > :last-child:nth-child(4) { grid-column: span 2; justify-self: start; }
.link-label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.link-url { background: #f7f5fa; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px -12px rgba(0,0,0,.25); padding: 6px; }
.menu-body form { margin: 0; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; font: inherit; cursor: pointer; color: inherit; text-decoration: none; }
.menu-item:hover:not(:disabled) { background: #f5f2f8; }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-item.danger { color: var(--err); }

/* Formularios */
.form { display: grid; gap: 16px; }
.form label, .form .label { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
input:not([type=radio]):not([type=checkbox]):not([type=file]), select, textarea {
    font: inherit; font-weight: 400; color: var(--ink); background: #fff;
    padding: 9px 12px; border: 1px solid #d6cfe0; border-radius: 9px; min-height: 40px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.help { font-weight: 400; font-size: .83rem; color: var(--muted); margin: 0; }
.field-error { font-weight: 500; font-size: .85rem; color: var(--err); }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; padding: 0; }
.radio, .checkbox { display: flex !important; flex-direction: row; gap: 10px; align-items: flex-start; font-weight: 400 !important; }
.radio input, .checkbox input { margin-top: 4px; accent-color: var(--brand); }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 180px; width: auto !important; }

.type-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.type-picker legend { grid-column: 1 / -1; }
.type-option { display: flex !important; flex-direction: row !important; gap: 12px; align-items: flex-start; border: 2px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; }
.type-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.type-option input { margin-top: 4px; accent-color: var(--brand); }
.type-option span { display: grid; gap: 2px; }
.type-option small { font-weight: 400; color: var(--muted); }
.type-picker:disabled .type-option { cursor: default; opacity: .7; }

.input-prefix { display: flex; align-items: stretch; }
.input-prefix span { display: flex; align-items: center; padding: 0 10px; background: #f3f0f7; border: 1px solid #d6cfe0; border-right: 0; border-radius: 9px 0 0 9px; font-weight: 400; color: var(--muted); font-size: .85rem; white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.input-prefix input { border-radius: 0 9px 9px 0 !important; font-family: ui-monospace, Menlo, Consolas, monospace; }

.options-editor { display: grid; gap: 8px; }
.options-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; counter-reset: opt; }
.option-row { display: grid; grid-template-columns: 24px 1fr 30px 30px; gap: 8px; align-items: center; counter-increment: opt; }
.option-row::before { content: counter(opt) "."; color: var(--muted); font-weight: 700; text-align: right; }
.options-editor .btn { justify-self: start; }

[data-show-for][hidden] { display: none !important; }

.file-drop { border: 2px dashed #d3cadf; border-radius: 12px; padding: 24px; text-align: center; background: #fcfbfd; }

/* Tablas */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #faf9fc; }
.table td { padding: 10px 12px; border-bottom: 1px solid #efebf3; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table-compact td, .table-compact th { padding: 7px 10px; }
.table tr.is-hidden td { opacity: .5; }
.table tr.is-hidden td:nth-child(3) { text-decoration: line-through; }
.table tr.is-new td { animation: flash 1.6s ease; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table th.num, .table td.num { text-align: right; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 220px; width: auto; }
.toolbar select { width: auto; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

.add-panel summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.add-panel[open] summary { margin-bottom: 14px; }

/* Estadísticas */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 2px; }
.stat-n { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-l { color: var(--muted); font-size: .88rem; }
.stat-l small { font-weight: 700; color: var(--brand); }
.stat-ok .stat-n { color: var(--ok); }
.stat-warn .stat-n { color: var(--warn); }

.meter { height: 8px; background: #efebf3; border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.meter-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .6s ease; }

/* Resultados */
.live-dot { font-size: .75rem; font-weight: 700; color: var(--ok); display: inline-flex; align-items: center; gap: 6px; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
.live-dot.stale { color: var(--muted); }
.word-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; max-height: 520px; overflow-y: auto; }
.word-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 5px 8px; border-radius: 7px; }
.word-list li:hover { background: #f7f4fa; }
.word-list .count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }
.admin-bars { display: grid; gap: 14px; }
.admin-bar-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; margin-bottom: 4px; }
.admin-bar-head span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.admin-bars .meter { height: 14px; }

.chips { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f1edf5; border-radius: 999px; padding: 3px 4px 3px 12px; font-size: .88rem; }
.chip form { margin: 0; }
.chip-x { width: 22px; height: 22px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 1rem; line-height: 1; }
.chip-x:hover { background: #e2d9ea; color: var(--ink); }

.answer-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.answer-list li { display: grid; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid #efebf3; }

.danger-zone { border-color: #fecaca; }
.danger-zone h2 { color: var(--err); }

/* Diálogo QR */
.dialog { border: 0; border-radius: 16px; padding: 24px 28px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); max-width: 420px; width: calc(100% - 32px); text-align: center; }
.dialog::backdrop { background: rgba(20, 12, 30, .55); }
.dialog h3 { margin: 0 0 14px; }
.dialog .actions { justify-content: center; margin-top: 12px; }
.dialog code { word-break: break-all; }
.dialog-close { position: absolute; right: 10px; top: 8px; margin: 0; }
.dialog-close button { border: 0; background: none; font-size: 1.6rem; color: var(--muted); cursor: pointer; }
.qr-preview canvas { width: 280px; height: 280px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 10px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: radial-gradient(900px 500px at 50% 0%, #efe0f7, var(--bg)); }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: 0 20px 50px -25px rgba(60, 10, 80, .35); }
.login-box h1 { font-size: 1.3rem; margin: 18px 0 20px; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes flash { from { background: #fef9c3; } }

@media (max-width: 900px) {
    .two-col, .two-col.wide-right { grid-template-columns: 1fr; }
    .q-card { grid-template-columns: 1fr; }
    .q-order { flex-direction: row; justify-content: flex-start; }
    .q-actions { flex-direction: row; flex-wrap: wrap; }
    .q-actions > * { flex: 1 1 120px; }
    .link-row { grid-template-columns: 1fr auto auto; }
    .link-label { grid-column: 1 / -1; }
    .type-picker { grid-template-columns: 1fr; }
    .topnav a[target] { display: none; }
}

/* Menú desplegable dentro de una fila de tabla (restablecer contraseña) */
.inline-menu { display: inline-block; text-align: left; }
.inline-menu .menu-body { min-width: 260px; padding: 14px; }

/* Invitados y emulador */
.badge-guest { background: #e0f2fe; color: #075985; }
.badge-emulated { background: #fef3c7; color: #92400e; }
.flash-warn { background: var(--warn-soft); color: #78350f; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.emulator { border-style: dashed; }
.emulator h3 { margin-top: 0; display: flex; align-items: center; gap: 8px; }
.emulator-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.emulator-form label { display: grid; gap: 4px; font-weight: 600; font-size: .85rem; }
.emulator-form input { width: 120px !important; }
.emulator-progress { margin-top: 14px; }
.emulator-progress .meter { height: 10px; }
.emulator-status { font-size: .88rem; color: var(--muted); margin: 6px 0 0; }
.emulator-status.running { color: var(--ok); font-weight: 600; }

/* Estado de la pregunta: franja con la acción principal */
.q-state { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 12px 14px; border-radius: 10px; margin: 0 0 14px; }
.q-state form { margin: 0; }
.q-state-text { display: grid; gap: 2px; min-width: 0; flex: 1 1 280px; }
.q-state-text span { font-size: .86rem; }
.q-state-draft { background: var(--warn-soft); border: 1px solid #fcd34d; color: #78350f; }
.q-state-closed { background: #f1f0f4; border: 1px solid #ddd8e4; color: #4b4556; }
.q-state-open { background: var(--ok-soft); border: 1px solid #86efac; color: #14532d; padding: 8px 14px; }
.btn-lg { min-height: 44px; padding: 10px 18px; font-size: 1rem; }

/* Tarjeta de pregunta no activa: se ve "apagada" salvo la franja de estado */
.q-card.status-draft { background: repeating-linear-gradient(-45deg, #fff, #fff 12px, #fcfaf5 12px, #fcfaf5 24px); border-left-color: #f59e0b; }
.q-card.status-draft h3, .q-card.status-closed h3 { color: var(--muted); }
.q-card.status-draft .links, .q-card.status-closed .links { opacity: .7; }
.q-description { margin: -6px 0 12px; color: var(--muted); font-size: .9rem; font-style: italic; }

/* Diálogo «Incrustar en Moodle» */
.dialog-wide { max-width: 640px; text-align: left; }
.embed-option { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.embed-option h4 { margin: 0 0 8px; color: var(--ink); font-size: .95rem; display: flex; align-items: center; gap: 8px; }
.embed-option ol { margin: 8px 0; padding-left: 20px; font-size: .9rem; }
.embed-option li { margin-bottom: 4px; }
.embed-url-row { display: flex; gap: 8px; margin: 0; }
.embed-url-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem !important; }
