/* ==========================================================
   UI compartida – Juicio de Experto (web del experto + admin)
   ========================================================== */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #17202e;
  --muted: #566173;
  --border: #dde3ea;
  --accent: #0b5cad;
  --accent-hover: #094b8e;
  --accent-soft: #e5effa;
  --accent-contrast: #ffffff;
  --ok: #12775a;
  --ok-soft: #e4f5ee;
  --warn: #9a5a06;
  --warn-soft: #fdf2df;
  --danger: #b42318;
  --danger-soft: #fdebe9;
  --chip-asr-bg: #dbeafe;
  --chip-asr-fg: #1e40af;
  --chip-adr-bg: #ede9fe;
  --chip-adr-fg: #5b21b6;
  --chip-tactica-bg: #dcfce7;
  --chip-tactica-fg: #166534;
  --chip-componente-bg: #e5e7eb;
  --chip-componente-fg: #374151;
  --chart-1: #0b5cad;
  --chart-2: #12a37f;
  --chart-3: #8b5cf6;
  --chart-grid: rgba(23, 32, 46, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
  --focus: 0 0 0 3px rgba(11, 92, 173, 0.35);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1e2732;
    --text: #e6ebf1;
    --muted: #9aa6b5;
    --border: #2c3644;
    --accent: #5aa2ec;
    --accent-hover: #7cb6f1;
    --accent-soft: #15283d;
    --accent-contrast: #0b1520;
    --ok: #4cc79c;
    --ok-soft: #12302a;
    --warn: #f0b45a;
    --warn-soft: #33270f;
    --danger: #f08479;
    --danger-soft: #3a1b18;
    --chip-asr-bg: #1c2f52;
    --chip-asr-fg: #a9c7ff;
    --chip-adr-bg: #2d2350;
    --chip-adr-fg: #cdbbff;
    --chip-tactica-bg: #173b26;
    --chip-tactica-fg: #9be3b6;
    --chip-componente-bg: #2b313a;
    --chip-componente-fg: #cdd3db;
    --chart-1: #5aa2ec;
    --chart-2: #4cc79c;
    --chart-3: #b197fc;
    --chart-grid: rgba(230, 235, 241, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
    --focus: 0 0 0 3px rgba(90, 162, 236, 0.45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.9em; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, pre { font-family: var(--mono); font-size: 0.875rem; }
pre {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  white-space: pre;
}
ul, ol { padding-left: 1.3em; margin: 0 0 1em; }
li + li { margin-top: 0.3em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 6px; }
.skip-link:focus { left: 8px; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.container.wide { max-width: 1320px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .container { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand strong { font-size: 0.98rem; }
.brand span { font-size: 0.8rem; color: var(--muted); }
.topbar .spacer { flex: 1; }
main { padding: 24px 0 64px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.prose p:last-child { margin-bottom: 0; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.soft { background: var(--surface-2); box-shadow: none; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72rem; font-weight: 650; color: var(--muted); margin: 0 0 4px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; font-size: 0.94rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Chips de trazabilidad ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 650; letter-spacing: 0.02em;
  background: var(--chip-componente-bg); color: var(--chip-componente-fg);
  white-space: nowrap; cursor: default;
}
.chip[data-tip-title] { cursor: help; }
.chip[data-tip-title]:hover, .chip[data-tip-title]:focus-visible { filter: brightness(0.95); outline: 1px solid currentColor; outline-offset: 0; }
.chip-asr { background: var(--chip-asr-bg); color: var(--chip-asr-fg); }
.chip-adr { background: var(--chip-adr-bg); color: var(--chip-adr-fg); }
.chip-tactica { background: var(--chip-tactica-bg); color: var(--chip-tactica-fg); }
.chip-componente { background: var(--chip-componente-bg); color: var(--chip-componente-fg); }
.chip-tooltip {
  position: fixed; z-index: 80; max-width: min(300px, calc(100vw - 16px));
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  font-size: 0.84rem; line-height: 1.45; pointer-events: none;
}
.chip-tooltip .tt-clase { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.75; font-weight: 650; }
.chip-tooltip .tt-titulo { font-weight: 650; margin: 1px 0 3px; }
.chip-tooltip .tt-desc { opacity: 0.92; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); align-items: center; }

/* ---------- Badges y avisos ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.notice {
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--accent-soft); border-left: 4px solid var(--accent);
}
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.notice.danger { background: var(--danger-soft); border-color: var(--danger); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }

/* ---------- Formularios ---------- */
label { font-weight: 550; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.hint { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: 9px 12px; min-height: 42px;
  font: inherit; font-size: 0.95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input:disabled, textarea:disabled, select:disabled { opacity: 0.7; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); align-items: end; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 20px; scrollbar-width: thin; }
.tab {
  flex: 0 0 auto; padding: 10px 14px;
  background: none; border: 0; border-bottom: 3px solid transparent;
  font: inherit; font-weight: 550; font-size: 0.94rem; color: var(--muted); cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge { margin-left: 6px; }

/* ---------- Acordeón ---------- */
details.acc { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.acc + details.acc { margin-top: 10px; }
details.acc > summary {
  list-style: none; cursor: pointer; padding: 14px 18px;
  display: flex; align-items: center; gap: 10px; font-weight: 600;
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "▸"; margin-left: auto; transition: transform 0.15s; color: var(--muted); }
details.acc[open] > summary::after { transform: rotate(90deg); }
details.acc > .acc-body { padding: 0 18px 18px; }

/* ---------- Pasos / progreso ---------- */
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 8px; overflow-x: auto; }
.steps li { margin: 0; flex: 1 1 0; min-width: 92px; }
.steps button {
  width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 10px; border: 0; border-top: 4px solid var(--border);
  background: none; color: var(--muted); font: inherit; font-size: 0.82rem; text-align: left; cursor: pointer;
}
.steps button:disabled { cursor: default; }
.steps .num { font-weight: 700; font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; }
.steps .done button { border-top-color: var(--ok); color: var(--text); }
.steps .current button { border-top-color: var(--accent); color: var(--accent); font-weight: 650; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }

/* ---------- Preguntas ---------- */
.question { border: 1px solid var(--border); margin: 0; padding: 20px; }
.question + .question { margin-top: 16px; }
.question legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-weight: 600; font-size: 1.02rem; }
.question legend + * { clear: both; }
.question .q-id { display: inline-block; min-width: 2.2em; color: var(--accent); font-weight: 700; }
.question .req { color: var(--danger); margin-left: 2px; }
.question .q-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.question .help { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.question .q-block { margin-top: 16px; }
.question .q-block > .label { display: block; font-weight: 550; margin-bottom: 8px; font-size: 0.93rem; }
.question.invalid { border-color: var(--danger); }
.q-error { color: var(--danger); font-size: 0.88rem; margin: 10px 0 0; font-weight: 550; }

.scale { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.scale.compact { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); max-width: 420px; }
.opt { position: relative; display: flex; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt .opt-box {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 48px; padding: 8px 6px; text-align: center;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  font-size: 0.82rem; font-weight: 500; line-height: 1.25; color: var(--muted); transition: all 0.12s;
}
.opt .opt-num { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.opt:hover .opt-box { border-color: var(--accent); }
.opt input:checked + .opt-box { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.opt input:checked + .opt-box .opt-num { color: var(--accent); }
.opt input:focus-visible + .opt-box { box-shadow: var(--focus); }
.opt input:disabled + .opt-box { cursor: default; opacity: 0.7; }
.scale-hint { display: none; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 0.78rem; color: var(--muted); }
.scale-hint span:last-child { text-align: right; }
.checks { display: grid; gap: 8px; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-weight: 450; cursor: pointer; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }

/* ---------- Diagramas ---------- */
.dg-card { display: flex; flex-direction: column; gap: 12px; }
.dg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.dg-head h3 { margin: 0; }
.dg-canvas {
  width: 100%; overflow-x: auto; overflow-y: hidden;
  min-height: 140px; padding: 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.dg-canvas svg { display: block; width: 100%; height: auto; min-width: 560px; margin: 0 auto; }
/* Las secuencias tienen muchos participantes: ancho mínimo legible y desplazamiento horizontal */
.dg-canvas svg[aria-roledescription="sequence"] { min-width: 1100px; }
.dg-canvas .dg-loading { color: var(--muted); font-size: 0.9rem; margin: 40px 0; text-align: center; }
.dg-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dg-code { display: flex; flex-direction: column; gap: 8px; }
.dg-code pre { max-height: 360px; }
.dg-error { padding: 12px; color: var(--danger); }
.dg-error pre { margin-top: 8px; color: var(--text); }

/* ---------- Modales ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; box-shadow: var(--shadow-lg);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(10, 15, 25, 0.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 1.1rem; }
.dlg-body { padding: 18px; overflow: auto; max-height: calc(100vh - 180px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--border); }
dialog.dg-full { width: calc(100vw - 24px); height: calc(100vh - 24px); max-width: none; max-height: none; }
dialog.dg-full[open] { display: flex; flex-direction: column; }
.dg-full-body { flex: 1; min-height: 0; background: var(--surface-2); touch-action: none; overflow: hidden; }
.dg-full-body svg { width: 100%; height: 100%; }
.close-x { font-size: 1.4rem; line-height: 1; padding: 4px 10px; }

/* ---------- Panel lateral (diagrama junto a la pregunta) ---------- */
.drawer {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0;
  width: min(760px, 52vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 1rem; }
.drawer-body { flex: 1; overflow: auto; padding: 16px; }
.drawer-body .dg-card { box-shadow: none; border: 0; padding: 0; }
@media (max-width: 860px) {
  .drawer { top: auto; left: 0; width: 100%; height: 78vh; border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; }
}

/* ---------- Tablas ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); font-weight: 650; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- KPIs ---------- */
.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 0.82rem; color: var(--muted); font-weight: 550; }
.kpi .kpi-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 0.82rem; color: var(--muted); }

/* ---------- Toast ---------- */
.toast-region { position: fixed; z-index: 60; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 0.92rem; font-weight: 500; animation: toast-in 0.2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Estado de guardado ---------- */
.save-status { font-size: 0.82rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.save-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.save-status.saved::before { background: var(--ok); }
.save-status.saving::before { background: var(--warn); }
.save-status.offline::before { background: var(--danger); }

@media (max-width: 640px) {
  .card { padding: 16px; }
  .question { padding: 16px; }
  main { padding-top: 16px; }
  /* En la escala numérica se ocultan las etiquetas largas y se muestra la leyenda de los extremos;
     las escalas compactas (Sí/No, Baja/Media/Alta) conservan su texto */
  .scale:not(.compact) { grid-template-columns: repeat(5, 1fr); }
  .scale:not(.compact) .opt-lbl { display: none; }
  .scale-hint { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; color: #000; }
  .topbar, .no-print, .toast-region, .drawer, dialog { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; border-color: #ccc; }
  main { padding: 0; }
  a { color: inherit; text-decoration: none; }
}
