:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --text: #15201f;
  --muted: #5b6b6a;
  --border: #d6dedd;
  --accent: #0f6b6c;
  --accent-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #6b4b00;
  --danger: #a3262a;
  --sim-bg: #e8e0ff;
  --sim-text: #3d2a8a;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514;
    --surface: #18201f;
    --text: #e6eeed;
    --muted: #94a5a3;
    --border: #2c3836;
    --accent: #4fb3b2;
    --accent-text: #08201f;
    --warn-bg: #3a2f10;
    --warn-text: #f5d98a;
    --danger: #f08a8d;
    --sim-bg: #2a2350;
    --sim-text: #cfc4ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav button { background: none; border-color: transparent; }
nav button[aria-current="page"] { background: var(--bg); border-color: var(--border); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.center { text-align: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { font-family: ui-monospace, Menlo, monospace; resize: vertical; }

fieldset.eye { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
fieldset.eye legend { font-size: 0.9rem; color: var(--muted); padding: 0; margin-bottom: 4px; }
.pill {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
}
.pill:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

button, .button {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  flex-direction: row;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar h1 { margin: 0; }
.spacer { flex: 1; }

.hint { font-size: 0.9rem; color: var(--muted); margin: 12px 0 0; }
.hint--warn { color: var(--warn-text); }
.muted { color: var(--muted); }

.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 0.92rem;
}
.banner--sim { background: var(--sim-bg); color: var(--sim-text); font-weight: 600; }

progress { width: 100%; height: 14px; accent-color: var(--accent); }

details summary { cursor: pointer; font-weight: 600; }

/* Informe */
.report__head {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 16px;
  margin-bottom: 16px;
}
.report__head div { display: flex; flex-direction: column; }
.k { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.report__maps { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.report__maps figure { margin: 0; text-align: center; }
.report__maps figcaption { font-size: 0.85rem; color: var(--muted); }
.field { width: 100%; max-width: 380px; height: auto; color: var(--text); }
.field .axis { stroke: currentColor; stroke-opacity: 0.35; stroke-width: 1; }
.field text { fill: currentColor; font-size: 11px; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }
.field text.bs { fill-opacity: 0.4; }
.field text.low { font-weight: 700; }
.field--gray { background: #fff; border-radius: 6px; }
.field--gray .axis { stroke: #000; }

.report__tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }
.report table, table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
td.lim { color: var(--muted); font-size: 0.82rem; }
tr.warn th, tr.warn td { color: var(--danger); font-weight: 600; }
.fineprint { font-size: 0.8rem; color: var(--muted); margin-top: 16px; }
.table-wrap { overflow-x: auto; }
td.actions { display: flex; gap: 6px; margin: 0; }

.profiles { list-style: none; padding: 0; margin: 0; }
.profiles li { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.profiles li button { margin-left: auto; }

.prose ul { padding-left: 20px; }

/* Formulario: opciones */
details.options { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
details.options > summary { margin-bottom: 14px; }
details.options > label { margin-top: 14px; }
.checks { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
.code-badge {
  display: inline-block;
  font: 600 1rem ui-monospace, Menlo, monospace;
  letter-spacing: 0.12em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 10px;
  color: var(--text);
}
.row-actions { margin-left: auto; display: flex; gap: 6px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form input { width: 12em; }
h3 { font-size: 1rem; margin: 16px 0 6px; }

/* Calibración de pantalla con tarjeta */
.card-fit { overflow-x: auto; padding: 8px 0 16px; }
.card-box {
  border: 2px dashed var(--accent);
  border-radius: 3.2mm;
  display: grid;
  place-items: center;
  color: var(--muted);
  max-width: none;
}

/* Informe: mapas de desviación y probabilidad */
.report__maps--4 { margin-top: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 560px) { .report__maps--4 { grid-template-columns: 1fr; } }
.field--prob { background: #fff; border-radius: 6px; }
.field--prob .axis { stroke: #000; }
.field .dot { fill: currentColor; fill-opacity: 0.55; }
.field--prob .dot { fill: #000; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend svg { background: #fff; }
.p { color: var(--danger); font-weight: 600; font-size: 0.85rem; margin-left: 6px; }
.report__gaze { margin-top: 16px; }
.gaze { width: 100%; height: 70px; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.gaze .axis { stroke: #000; stroke-opacity: 0.4; }
.gaze .gz-up { fill: #1d5f9e; }
.gaze .gz-down { fill: #a3262a; }

/* Monitor del operador */
.mon__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mon__clock { font: 700 2rem ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.mon__state { color: var(--muted); margin: 4px 0 10px; }
.mon__grid { display: grid; grid-template-columns: minmax(240px, 1.3fr) minmax(220px, 1fr); gap: 20px; margin-top: 14px; }
@media (max-width: 640px) { .mon__grid { grid-template-columns: 1fr; } }
.mon__map .field { max-width: 420px; }
.field--live .current { fill: none; stroke: var(--accent); stroke-width: 2; }
.mon__counters { width: 100%; border-collapse: collapse; }
.mon__recent { display: flex; flex-wrap: wrap; gap: 4px; margin: 14px 0; min-height: 14px; }
.mon__recent .r { width: 12px; height: 12px; border-radius: 3px; background: var(--border); }
.mon__recent .r--seen { background: var(--accent); }
.mon__recent .r--fixation, .mon__recent .r--falsePositive, .mon__recent .r--falseNegative { outline: 2px solid var(--warn-text); outline-offset: -2px; }
.mon__gaze, .mon__notice { font-size: 0.92rem; margin-bottom: 8px; }
.mon__gaze .bad { color: var(--danger); }
.mon__controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Consentimiento */
.consent { margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; }

/* Otras pruebas */
.test-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.test-card {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 14px;
  min-height: 110px;
}
.test-card span { color: var(--muted); font-size: 0.88rem; }
.test-card em { font-style: normal; font-size: 0.78rem; color: var(--accent); }
.test-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.big-result { display: flex; flex-wrap: wrap; gap: 28px; margin: 8px 0 16px; }
.big-result div { display: flex; flex-direction: column; }
.big-result b { font-size: 2rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.chart { width: 100%; max-width: 480px; height: auto; display: block; margin: 0 auto 12px; }
.chart .grid { stroke: var(--border); }
.chart .tick, .chart .axis-label { fill: var(--muted); font-size: 11px; text-anchor: middle; dominant-baseline: middle; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .series-dot { fill: var(--accent); }
.amsler { width: 100%; max-width: 320px; height: auto; }
.hess { width: 100%; max-width: 280px; height: auto; background: #fff; border-radius: 6px; }
.hess .grid line { stroke: #ddd; stroke-width: 0.6; }
.hess .ref { fill: none; stroke: #888; stroke-width: 1.2; stroke-dasharray: 3 3; }
.hess .ref-dot { fill: #888; }
.hess .meas { fill: none; stroke: #b3261e; stroke-width: 2; }
.hess .meas-dot { fill: #b3261e; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.bars { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 16px; }
.bar { display: grid; grid-template-columns: minmax(140px, 200px) 1fr 80px; align-items: center; gap: 10px; font-size: 0.92rem; }
.bar__track { height: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.bar__fill { display: block; height: 100%; }
.bar__fill--protan { background: #c0392b; }
.bar__fill--deutan { background: #2e8b57; }
.bar__fill--tritan { background: #2f6fbf; }
.bar__value { text-align: right; font-variant-numeric: tabular-nums; }
.summary-cell { max-width: 260px; font-size: 0.85rem; }

/* Examen en pantalla */
.screen-test { position: fixed; inset: 0; z-index: 10; background: #000; touch-action: none; cursor: none; }
.screen-test canvas { width: 100%; height: 100%; display: block; }
.screen-test__msg {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  max-width: min(90vw, 560px);
  padding: 14px 20px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  text-align: center;
  white-space: pre-line;
  font-weight: 600;
}

@media print {
  body { background: #fff; color: #000; }
  .topbar, .no-print, .banner:not(.banner--sim) { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; }
  .field { color: #000; }
  .report__maps { break-inside: avoid; }
  .report { font-size: 12px; }
}
