/* El Libro de las Hojas — «La Ventana Redonda».
   La página es una hoja de cuaderno sobre la mesa de una casa de la Comarca:
   luz de tarde, huerta afuera, tinta adentro.
   Todos los colores, fuentes y espaciados salen de tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--page);
  background-image: radial-gradient(1150px 460px at 50% -12%, var(--surface-garden), transparent 72%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

img {
  display: block;
  max-width: 100%;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: var(--border-2) solid var(--focus);
  outline-offset: var(--border-2);
}

::selection {
  background: var(--accent-wash);
  color: var(--ink-900);
}

.visually-hidden {
  position: absolute !important;
  width: var(--border-1);
  height: var(--border-1);
  margin: calc(-1 * var(--border-1));
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: calc(-1 * var(--space-9));
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: var(--border-1) solid var(--line-control);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: top var(--transition);
}

.skip-link:focus {
  top: var(--space-4);
}

/* ---------------------------------------------------------------- Masthead */

.masthead {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-5) var(--space-5);
}

.masthead-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.brand-seal {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--size-brand-seal);
  height: var(--size-brand-seal);
  border: var(--border-1) solid var(--moss-300);
  border-radius: var(--radius-full);
  color: var(--moss-600);
  background: var(--surface);
  box-shadow: inset 0 0 0 var(--space-1) var(--surface-garden);
}

.brand-seal svg {
  width: 58%;
  height: 58%;
}

.eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: var(--space-1) 0 0;
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 600;
  font-optical-sizing: auto;
  letter-spacing: -0.012em;
  line-height: 1.04;
  color: var(--text);
  text-wrap: balance;
}

.lede {
  max-width: var(--measure);
  margin: var(--space-5) 0 0;
  color: var(--text-soft);
  font-size: var(--text-lg);
  line-height: 1.55;
  text-wrap: pretty;
}

.status-chip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.status-chip[data-state="ok"] {
  color: var(--ok);
  border-color: currentColor;
}

.status-chip[data-state="down"] {
  color: var(--danger);
  border-color: currentColor;
}

.status-dot {
  width: var(--space-2);
  height: var(--space-2);
  flex: none;
  border-radius: var(--radius-full);
  background: currentColor;
}

/* ------------------------------------------------------- Horizonte (Comarca) */

.horizon {
  line-height: 0;
}

.horizon svg {
  display: block;
  width: 100%;
  height: var(--horizon-height);
}

.hill--far {
  fill: var(--sage-200);
}

.hill--mid {
  fill: var(--moss-300);
}

.hill--near {
  fill: var(--moss-600);
}

.door-frame {
  fill: var(--surface);
  stroke: var(--moss-900);
  stroke-width: 2;
}

.door-ring {
  fill: none;
  stroke: var(--moss-600);
  stroke-width: 1.5;
}

.door-step {
  fill: none;
  stroke: var(--moss-900);
  stroke-width: 2;
  stroke-linecap: round;
}

.door-knob {
  fill: var(--honey-800);
}

/* ------------------------------------------------------------------- Rule */

.rule {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.rule::before,
.rule::after {
  content: "";
  flex: 1;
  height: var(--border-1);
  background: var(--line-paper);
}

.rule span {
  width: var(--space-3);
  height: var(--space-3);
  flex: none;
  border-radius: 0 100% 0 100%;
  background: var(--moss-600);
  transform: rotate(-45deg);
}

/* ----------------------------------------------------------------- Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(var(--aside-width), 0.85fr);
  gap: var(--space-5);
  align-items: start;
  max-width: var(--app-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-9);
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-width: 0;
}

.panel {
  min-width: 0;
  padding: var(--space-5);
  background: var(--surface);
  border: var(--border-1) solid var(--line-paper);
  border-top: var(--border-rail) solid var(--moss-600);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.panel-head {
  margin-bottom: var(--space-4);
}

.panel-head--split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.result-heading {
  flex: 1 1 auto;
  min-width: 0;
}

.panel-head h2,
.result-heading h2 {
  margin: var(--space-1) 0 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.008em;
  color: var(--text);
  overflow-wrap: anywhere;
}

.section-title {
  margin: 0 0 var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.result-meta {
  margin: var(--space-2) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- Dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  background: var(--surface-garden);
  border: var(--border-2) dashed var(--line-control);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--moss-600);
  background: var(--surface-garden-strong);
}

.dropzone.is-dragover {
  box-shadow: inset 0 0 0 var(--border-2) var(--moss-600);
}

.dropzone:focus-within {
  border-style: solid;
  border-color: var(--moss-600);
}

.dropzone[aria-busy="true"] {
  border-style: solid;
  border-color: var(--moss-600);
  cursor: progress;
}

body[data-busy] .dropzone-seal {
  border-color: var(--moss-600);
}

.dropzone-seal {
  display: grid;
  place-items: center;
  width: var(--size-drop-seal);
  height: var(--size-drop-seal);
  margin-bottom: var(--space-1);
  border: var(--border-2) solid var(--accent-ornament);
  border-radius: var(--radius-full);
  color: var(--moss-600);
  background: var(--surface);
  box-shadow: inset 0 0 0 var(--space-1) var(--surface-garden);
}

.dropzone-seal svg {
  width: 54%;
  height: 54%;
}

.dropzone-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.004em;
}

.dropzone-hint {
  max-width: 46ch;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.dropzone .button {
  margin-top: var(--space-2);
}

/* ---------------------------------------------------------------- Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-touch);
  padding: var(--space-2) var(--space-4);
  border: var(--border-1) solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.button--primary {
  background: var(--button-bg);
  border-color: var(--button-bg);
  color: var(--button-text);
}

.button--primary:hover {
  background: var(--button-bg-hover);
  border-color: var(--button-bg-hover);
}

.button--ghost {
  background: var(--surface);
  border-color: var(--line-control);
  color: var(--text-soft);
}

.button--ghost:hover {
  background: var(--surface-garden);
  border-color: var(--moss-600);
  color: var(--text);
}

.button--danger {
  background: transparent;
  border-color: currentColor;
  color: var(--danger);
}

.button--danger:hover {
  background: var(--danger);
  color: var(--button-text);
}

.button:disabled {
  background: var(--surface-sunken);
  border-color: var(--line);
  color: var(--text-muted);
  cursor: not-allowed;
}

.icon-button {
  min-height: var(--size-touch);
  padding: 0 var(--space-2);
  border: 0;
  border-bottom: var(--border-1) solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.icon-button:hover {
  color: var(--text);
  border-bottom-color: var(--moss-600);
}

.icon-button--danger {
  color: var(--danger);
}

.icon-button--danger:hover {
  color: var(--danger);
  border-bottom-color: var(--danger);
}

.icon-button:disabled {
  color: var(--text-muted);
  opacity: 0.45;
  border-bottom-color: transparent;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ Alert */

.alert {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--alert-bg);
  border-left: var(--border-rail) solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text);
}

.alert strong {
  color: var(--danger);
}

.status-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0 0;
  padding: var(--space-2) var(--space-3);
  background: var(--accent-wash);
  border-left: var(--border-rail) solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: var(--text-sm);
}

.status-line .status-dot {
  background: var(--moss-600);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* ----------------------------------------------------------------- Result */

.result {
  scroll-margin-top: var(--space-4);
}

.seal {
  position: relative;
  flex: none;
  display: grid;
  place-content: center;
  gap: var(--space-1);
  width: var(--size-seal);
  height: var(--size-seal);
  padding: var(--space-2);
  border: var(--border-2) solid currentColor;
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ok);
  box-shadow: inset 0 0 0 var(--space-1) var(--surface), inset 0 0 0 calc(var(--space-1) + var(--border-1)) currentColor;
  text-align: center;
}

.seal::after {
  content: "";
  position: absolute;
  top: 50%;
  right: calc(-1 * var(--space-1) - var(--border-1));
  width: var(--space-2);
  height: var(--space-2);
  border: var(--border-1) solid var(--accent);
  border-radius: var(--radius-full);
  background: var(--accent-ornament);
  transform: translateY(-50%);
}

.seal--ok {
  color: var(--ok);
}

.seal--warn {
  color: var(--danger);
}

.seal-word {
  max-width: 100%;
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.25;
  text-transform: uppercase;
  text-wrap: balance;
}

.seal-sub {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.verdict-note {
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-wash);
  border-left: var(--border-rail) solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: var(--text-sm);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--metric-min), 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.metric {
  padding: var(--space-3) var(--space-4);
  background: var(--page);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-sm);
}

.metric-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-value {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--text);
}

.metric-unit {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.figure {
  margin: 0 0 var(--space-5);
}

.figure-frame {
  padding: var(--space-2);
  background: var(--surface-sunken);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-sm);
}

.figure-frame img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.legend {
  display: inline-flex;
  gap: var(--space-4);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.swatch {
  width: var(--size-swatch);
  height: var(--size-swatch);
  border: var(--border-1) solid var(--line-control);
  border-radius: var(--radius-sm);
}

.swatch--lesion {
  background: var(--data-lesion);
}

.swatch--vein {
  background: var(--data-vein);
}

.trace {
  margin-bottom: var(--space-4);
  padding-top: var(--space-3);
  border-top: var(--border-1) solid var(--line);
}

.trace summary {
  cursor: pointer;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.trace summary:hover {
  color: var(--text);
}

.trace summary::marker {
  color: var(--accent);
}

.trace-json {
  max-height: 17.5rem;
  margin: var(--space-3) 0 0;
  padding: var(--space-3);
  overflow: auto;
  background: var(--surface-sunken);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: var(--border-1) solid var(--line);
}

/* ----------------------------------------------------------------- Ledger */

.ledger-count {
  display: inline-flex;
  align-items: center;
  margin: calc(-1 * var(--space-1)) 0 var(--space-3);
  padding: var(--space-1) var(--space-2);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.ledger-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ledger-item {
  display: flex;
  align-items: center;
  border-bottom: var(--border-1) solid var(--line);
}

.ledger-item:last-child {
  border-bottom: 0;
}

.ledger-load {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: var(--size-touch);
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}

.ledger-load:hover {
  background: var(--page);
}

.ledger-load[aria-current="true"] {
  background: var(--surface-garden);
  box-shadow: inset var(--border-rail) 0 0 var(--moss-600);
}

.ledger-load img {
  flex: none;
  width: var(--size-thumb);
  height: var(--size-thumb);
  object-fit: cover;
  background: var(--surface-sunken);
  border: var(--border-1) solid var(--line);
  border-radius: var(--radius-sm);
}

.ledger-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ledger-text strong {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ledger-text span {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.ledger-delete {
  flex: none;
  width: var(--size-touch);
  height: var(--size-touch);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: var(--text-lg);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.ledger-delete:hover {
  background: var(--alert-bg);
  color: var(--danger);
}

.empty {
  margin: var(--space-3) 0 0;
  padding: var(--space-5) var(--space-3);
  border: var(--border-1) dashed var(--line-control);
  border-radius: var(--radius-sm);
  background: var(--page);
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.empty::before {
  content: "";
  display: block;
  width: var(--space-3);
  height: var(--space-3);
  margin: 0 auto var(--space-2);
  border-radius: 0 100% 0 100%;
  background: var(--moss-300);
  transform: rotate(-8deg);
}

.notes {
  background: var(--surface-garden);
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}

.notes-list dt {
  color: var(--text);
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.notes-list dd {
  margin: var(--space-1) 0 0;
  color: var(--text-soft);
  font-size: var(--text-sm);
}

/* ----------------------------------------------------------------- Footer */

.site-footer {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: 0 var(--space-5) var(--space-8);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.site-footer .rule {
  margin: 0 0 var(--space-4);
}

.site-footer p {
  margin: 0;
}

.site-footer .footer-note {
  margin-top: var(--space-1);
  font-style: italic;
}

/* ----------------------------------------------------------------- Dialog */

.dialog {
  width: calc(100% - var(--space-6));
  max-width: 30rem;
  padding: var(--space-5);
  background: var(--surface);
  border: var(--border-1) solid var(--line-paper);
  border-top: var(--border-rail) solid var(--moss-600);
  border-radius: var(--radius-md);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.dialog::backdrop {
  background: var(--backdrop);
}

.dialog h2 {
  margin: var(--space-1) 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.2;
}

.dialog p {
  margin: 0;
  color: var(--text-soft);
  font-size: var(--text-sm);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* ------------------------------------------------------------- Responsive */

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .status-chip {
    margin-left: 0;
  }

  .seal {
    width: var(--size-seal-sm);
    height: var(--size-seal-sm);
  }
}

@media (max-width: 560px) {
  .masthead {
    padding-top: var(--space-6);
  }

  .brand {
    align-items: flex-start;
  }

  .brand-seal {
    width: calc(var(--size-brand-seal) - var(--space-3));
    height: calc(var(--size-brand-seal) - var(--space-3));
  }

  .layout,
  .masthead,
  .site-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .panel {
    padding: var(--space-4);
  }

  .metrics {
    grid-template-columns: repeat(auto-fit, minmax(calc(var(--metric-min) - var(--space-4)), 1fr));
  }

  .result-actions .button {
    width: 100%;
  }

  .figure-frame {
    padding: var(--space-1);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .status-line .status-dot {
    animation: none;
  }
}

/* ------------------------------------------------- Informe del lote (almanaque) */
/*
   Una página del almanaque, no un tablero: papel crema, filetes de tinta,
   sellos y gráficos de trazo. Sin tarjetas flotantes ni sombras grandes.
   La jerarquía la sostienen el filete, el espaciado y la tipografía.
*/

.panel-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.icon-button--strong {
  color: var(--accent);
  border-bottom-color: var(--accent-wash);
}

.icon-button--strong:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.report-dialog {
  width: min(calc(100% - var(--space-6)), var(--report-width));
  max-width: var(--report-width);
  max-height: var(--report-height);
  margin: auto;
  padding: 0;
  overflow: hidden;
  background: var(--report-sheet);
  border: var(--border-1) solid var(--line-paper);
  border-radius: var(--radius-md);
  color: var(--text);
}

.report-dialog::backdrop {
  background: var(--backdrop);
}

.report-sheet {
  max-height: calc(var(--report-height) - var(--border-2));
  margin: 0;
  padding: var(--space-6) var(--space-7) var(--space-7);
  overflow-y: auto;
  background: var(--report-sheet);
}

/* --- Cabecera: cejilla, título, sello y acciones ---------------------- */

.report-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-4) var(--space-6);
  padding-top: var(--space-3);
  padding-bottom: var(--space-5);
  border-top: var(--border-rail) solid var(--moss-600);
  border-bottom: var(--border-2) solid var(--report-rule);
}

.report-heading {
  min-width: 0;
}

.report-title {
  margin: var(--space-1) 0 0;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.012em;
  color: var(--text);
  text-wrap: balance;
}

.report-subtitle {
  margin: var(--space-2) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.report-stamp-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-3);
}

.report-seal {
  display: grid;
  place-content: center;
  gap: var(--space-1);
  width: var(--report-seal-size);
  height: var(--report-seal-size);
  padding: var(--space-2);
  flex: none;
  border: var(--border-2) solid currentColor;
  border-radius: var(--radius-full);
  background: var(--report-sheet);
  color: var(--text-muted);
  box-shadow: inset 0 0 0 var(--space-1) var(--report-sheet), inset 0 0 0 calc(var(--space-1) + var(--border-1)) currentColor;
  text-align: center;
}

.report-seal[data-level="sano"] {
  color: var(--severity-sano);
}

.report-seal[data-level="leve"] {
  color: var(--severity-leve);
}

.report-seal[data-level="moderado"] {
  color: var(--severity-moderado);
}

.report-seal[data-level="severo"] {
  color: var(--severity-severo);
  border-width: var(--border-rail);
  border-style: double;
}

.report-seal-word {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-wrap: balance;
}

.report-seal-sub {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.report-warning {
  max-width: 30ch;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  background: var(--alert-bg);
  border-left: var(--border-rail) solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 700;
  text-align: left;
}

.report-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.report-save-status {
  flex-basis: 100%;
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-align: right;
}

.report-save-status:empty {
  display: none;
}

/* --- Estados --------------------------------------------------------- */

.report-states {
  margin-top: var(--space-5);
}

.report-state {
  margin: 0;
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.report-state--empty {
  background: var(--page);
  border: var(--border-1) dashed var(--line-control);
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.report-state--loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--accent-wash);
  border-left: var(--border-rail) solid var(--accent);
  color: var(--text-soft);
}

.report-state--loading .status-dot {
  background: var(--moss-600);
  animation: pulse 1.4s ease-in-out infinite;
}

.report-state--error {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  background: var(--alert-bg);
  border-left: var(--border-rail) solid var(--danger);
  color: var(--text);
}

.report-state--error strong {
  color: var(--danger);
}

/* --- Secciones: filetes, no tarjetas --------------------------------- */

.report-body {
  margin-top: var(--space-5);
}

.report-section {
  padding-top: var(--space-5);
  border-top: var(--border-1) solid var(--report-rule-soft);
}

.report-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.report-section + .report-section {
  margin-top: var(--space-5);
}

.report-section-head {
  margin-bottom: var(--space-3);
}

.report-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.report-section-title::after {
  content: "";
  flex: 1;
  height: var(--border-1);
  background: var(--report-rule-soft);
}

.report-section-note {
  max-width: var(--measure);
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.report-section-note--tight {
  margin-top: var(--space-2);
}

/* --- Cifras principales ---------------------------------------------- */

.report-figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--report-figure-min), 1fr));
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.report-figure {
  min-width: 0;
  padding-top: var(--space-3);
  border-top: var(--border-2) solid var(--report-rule);
}

.report-figure-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.report-figure-value {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--text);
}

.report-figure-unit {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.report-figure-name {
  margin: var(--space-1) 0 0;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-soft);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* --- Distribución por nivel: banda + sellos -------------------------- */

.sev--sano {
  --sev-color: var(--severity-sano);
  --sev-pattern: repeating-linear-gradient(
    0deg,
    transparent 0 var(--space-2),
    var(--surface) var(--space-2) calc(var(--space-2) + var(--border-1))
  );
}

.sev--leve {
  --sev-color: var(--severity-leve);
  --sev-pattern: repeating-linear-gradient(
    90deg,
    transparent 0 var(--space-2),
    var(--surface) var(--space-2) calc(var(--space-2) + var(--border-1))
  );
}

.sev--moderado {
  --sev-color: var(--severity-moderado);
  --sev-pattern: repeating-linear-gradient(
    45deg,
    transparent 0 var(--space-2),
    var(--surface) var(--space-2) calc(var(--space-2) + var(--border-1))
  );
}

.sev--severo {
  --sev-color: var(--severity-severo);
  --sev-pattern:
    repeating-linear-gradient(
      45deg,
      transparent 0 var(--space-2),
      var(--surface) var(--space-2) calc(var(--space-2) + var(--border-1))
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0 var(--space-2),
      var(--surface) var(--space-2) calc(var(--space-2) + var(--border-1))
    );
}

.report-band {
  display: flex;
  height: var(--space-4);
  margin-top: var(--space-3);
  overflow: hidden;
  background: var(--report-sheet);
  border: var(--border-1) solid var(--report-rule);
}

.report-band-seg {
  flex: 1 1 0;
  min-width: 0;
  background-color: var(--sev-color);
  background-image: var(--sev-pattern);
  border-right: var(--border-1) solid var(--report-rule);
}

.report-band-seg:last-child {
  border-right: 0;
}

.severity-stamps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--metric-min), 1fr));
  gap: var(--space-4);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}

.severity-stamp {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  padding-bottom: var(--space-3);
  border-bottom: var(--border-2) solid var(--sev-color);
}

.severity-stamp-strip {
  height: var(--space-2);
  background-color: var(--sev-color);
  background-image: var(--sev-pattern);
  border: var(--border-1) solid var(--sev-color);
}

.severity-stamp-label {
  margin-top: var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}

.severity-stamp-count {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--text);
}

.severity-stamp-unit {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.severity-stamp-meta {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* --- Gráficos dibujados por el JS (SVG) ------------------------------ */

.chart-figure {
  margin: 0 0 var(--space-3);
}

.chart {
  min-height: var(--chart-height);
  padding: var(--space-2) 0;
  border-top: var(--border-1) solid var(--line);
  border-bottom: var(--border-1) solid var(--line);
}

.chart--ranking {
  min-height: var(--chart-height-sm);
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart text {
  font-family: var(--font-mono);
}

.chart-grid {
  stroke: var(--chart-grid);
  stroke-width: var(--border-1);
}

.chart-baseline {
  stroke: var(--chart-baseline);
  stroke-width: var(--border-2);
}

.chart-tick {
  fill: var(--chart-axis);
  font-size: var(--text-2xs);
}

.chart-axis-title {
  fill: var(--text-soft);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
}

.chart-value {
  fill: var(--text);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}

.chart-bar {
  fill: var(--chart-bar);
}

.chart-bar--worst {
  fill: var(--severity-severo);
}

.chart-point {
  stroke: var(--report-sheet);
  stroke-width: var(--border-1);
}

.chart-point--sano {
  fill: var(--severity-sano);
}

.chart-point--leve {
  fill: var(--severity-leve);
}

.chart-point--moderado {
  fill: var(--severity-moderado);
}

.chart-point--severo {
  fill: var(--severity-severo);
  stroke: var(--report-rule);
  stroke-width: var(--border-2);
}

.chart-figure figcaption {
  justify-content: flex-start;
}

.report-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--text-soft);
  font-size: var(--text-sm);
}

.report-legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.legend-mark {
  width: var(--size-swatch);
  height: var(--size-swatch);
  flex: none;
}

.legend-mark--sano {
  fill: var(--severity-sano);
}

.legend-mark--leve {
  fill: var(--severity-leve);
}

.legend-mark--moderado {
  fill: var(--severity-moderado);
}

.legend-mark--severo {
  fill: var(--severity-severo);
  stroke: var(--report-rule);
  stroke-width: var(--border-1);
}

/* --- Tablas accesibles y tabla del lote ------------------------------ */

.report-data {
  margin-top: var(--space-3);
  padding-top: var(--space-2);
  border-top: var(--border-1) solid var(--line);
}

.report-data summary {
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.report-data summary:hover {
  color: var(--text);
}

.report-data[open] summary {
  margin-bottom: var(--space-2);
}

.report-table-wrap {
  margin-top: var(--space-3);
  overflow-x: auto;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.report-table caption {
  margin-bottom: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-align: left;
}

.report-table th,
.report-table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
}

.report-table th {
  border-bottom: var(--border-2) solid var(--report-rule);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.report-table td {
  border-bottom: var(--border-1) solid var(--line);
  color: var(--text);
}

.report-table tbody tr:hover {
  background: var(--surface-garden);
}

.report-table .is-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.report-row[data-severity="severo"] td:first-child {
  box-shadow: inset var(--border-rail) 0 0 var(--severity-severo);
}

.report-open {
  display: inline-flex;
  align-items: center;
  min-height: var(--size-touch);
  padding: var(--space-1) 0;
  background: none;
  border: 0;
  border-bottom: var(--border-1) solid transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.report-open:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Notas del lote y colofón ---------------------------------------- */

.report-notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--metric-min), 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-4);
}

.report-notes dt {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.report-notes dd {
  margin: var(--space-1) 0 0;
}

.report-note-list {
  margin: 0;
  padding-left: var(--space-4);
  color: var(--text-soft);
  font-size: var(--text-sm);
}

.report-note-list:empty::before {
  content: "Sin registros.";
  color: var(--text-muted);
  font-style: italic;
}

.report-colophon {
  margin: var(--space-4) 0 0;
  padding-top: var(--space-3);
  border-top: var(--border-1) solid var(--line);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.report-print-note {
  display: none;
}

/* --- Informe responsive ---------------------------------------------- */

@media (max-width: 920px) {
  .report-sheet {
    padding: var(--space-5);
  }

  .report-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .report-stamp-wrap {
    align-items: flex-start;
  }

  .report-actions {
    justify-content: flex-start;
  }

  .report-save-status {
    text-align: left;
  }
}

@media (max-width: 720px) {
  .report-dialog {
    width: calc(100% - var(--space-4));
  }

  .report-title {
    font-size: var(--text-xl);
  }

  .report-table--lot thead {
    position: absolute;
    width: var(--border-1);
    height: var(--border-1);
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .report-table--lot,
  .report-table--lot tbody,
  .report-table--lot tr,
  .report-table--lot td {
    display: block;
    width: 100%;
  }

  .report-table--lot tr {
    padding: var(--space-3) 0;
    border-bottom: var(--border-1) solid var(--line);
  }

  .report-table--lot td {
    display: grid;
    grid-template-columns: 40% minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-1) 0;
    border: 0;
  }

  .report-table--lot td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .report-table--lot td:first-child {
    display: block;
    padding-bottom: var(--space-2);
  }

  .report-table--lot td:first-child::before {
    display: none;
  }

  .report-table--lot tbody tr:hover {
    background: transparent;
  }

  .report-table--lot tr[data-severity="severo"] {
    box-shadow: inset var(--border-rail) 0 0 var(--severity-severo);
    padding-left: var(--space-3);
  }
}

@media (max-width: 560px) {
  .report-sheet {
    padding: var(--space-4);
  }

  .report-dialog {
    width: calc(100% - var(--space-2));
  }

  .report-actions .button {
    width: 100%;
  }

  .report-seal {
    width: calc(var(--report-seal-size) - var(--space-4));
    height: calc(var(--report-seal-size) - var(--space-4));
  }

  .report-figures,
  .severity-stamps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .chart {
    min-height: var(--chart-height-sm);
  }

  .report-table--lot td {
    grid-template-columns: 36% minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .report-state--loading .status-dot {
    animation: none;
  }
}

/* --- Impresión: sólo el informe, sin app, backdrop ni botones -------- */

@media print {
  @page {
    size: A4 portrait;
    margin: var(--print-margin);
  }

  .masthead,
  .horizon,
  .layout,
  .site-footer,
  .skip-link,
  #confirm-delete {
    display: none !important;
  }

  body {
    background: var(--surface);
    background-image: none;
  }

  .report-dialog {
    position: static;
    width: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: var(--report-sheet);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-dialog::backdrop {
    display: none !important;
  }

  .report-sheet {
    max-height: none;
    padding: 0;
    overflow: visible;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .report-actions,
  .report-data {
    display: none !important;
  }

  .report-print-note {
    display: block;
    margin-top: var(--space-4);
    padding-top: var(--space-2);
    border-top: var(--border-1) solid var(--line);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
  }

  .report-figures,
  .severity-stamps,
  .chart-figure,
  .report-figure,
  .report-row {
    break-inside: avoid;
  }

  .report-figures {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .report-section-head {
    break-after: avoid;
  }

  .report-section:has(.chart-figure) {
    break-inside: avoid;
  }

  .report-section--notes {
    break-inside: avoid;
  }

  /* En papel el nombre de la peor hoja no se recorta: la ficha puede crecer. */
  .report-figure-name {
    overflow: visible;
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
  }

  .report-table thead {
    display: table-header-group;
  }

  .report-table--lot {
    font-size: var(--text-xs);
  }

  .report-table--lot th,
  .report-table--lot td {
    padding: var(--space-1) var(--space-2);
  }

  /* La fecha completa en una línea evita filas de tres renglones. */
  .report-table--lot td:nth-child(2) {
    font-size: var(--text-2xs);
    white-space: nowrap;
  }

  .report-table--lot tr {
    break-inside: avoid;
  }

  .report-open {
    min-height: 0;
    padding: 0;
    border-bottom: 0;
  }

  .report-section-title {
    color: var(--text);
  }
}

/* Refuerzo de impresión: aunque el ancho de página active las reglas de
   pantalla estrecha, en papel la tabla del lote vuelve a ser una tabla. */
@media print {
  .report-table--lot {
    display: table;
  }

  .report-table--lot thead {
    position: static;
    display: table-header-group;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .report-table--lot tbody {
    display: table-row-group;
  }

  .report-table--lot tr {
    display: table-row;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .report-table--lot td {
    display: table-cell;
    width: auto;
    padding: var(--space-2) var(--space-3);
    border-bottom: var(--border-1) solid var(--line);
  }

  .report-table--lot td::before {
    content: none;
  }

  .report-table--lot td:first-child {
    display: table-cell;
    padding-bottom: var(--space-2);
  }

  .report-table--lot tr[data-severity="severo"] {
    padding-left: 0;
    box-shadow: none;
  }

  .report-table--lot tr[data-severity="severo"] td:first-child {
    box-shadow: inset var(--border-rail) 0 0 var(--severity-severo);
  }
}
