/* Componentes reutilizables (estilo Fluent). Capa: components.
   Estados de tono: ok | warn | bad (+ info | neutral en badges). Todos los tonos llevan
   texto además del color (badges, tiles, celdas): el color nunca es el único canal. */

@layer components {

  /* ---------- Botones ---------- */
  .btn,
  .btn--secondary,
  .btn--primary,
  .btn--ghost,
  .btn--text,
  .btn--danger,
  .primario,
  .peligro {
    --btn-bg: var(--surface);
    --btn-fg: var(--ink);
    --btn-bd: var(--control);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: 32px;
    padding: 0 var(--s-3);
    border-radius: var(--r-sm);
    border: 1px solid var(--btn-bd);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    justify-self: start;
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
  }
  @media (pointer: coarse) { .btn, .primario, .peligro { min-height: var(--hit); } }
  .btn span { min-width: 0; }
  .btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink-strong); }
  .btn:active:not(:disabled) { background: var(--surface-3); }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; }

  .btn--primary,
  .primario {
    --btn-bg: var(--brand);
    --btn-fg: var(--on-brand);
    --btn-bd: var(--brand);
  }
  .btn--primary:hover:not(:disabled),
  .primario:hover:not(:disabled) {
    background: color-mix(in srgb, var(--brand) 88%, var(--ink-strong));
    border-color: color-mix(in srgb, var(--brand) 88%, var(--ink-strong));
    color: var(--on-brand);
  }
  .btn--primary:active:not(:disabled),
  .primario:active:not(:disabled) {
    background: color-mix(in srgb, var(--brand) 76%, var(--ink-strong));
    color: var(--on-brand);
  }

  .btn--secondary { --btn-bd: var(--control); }

  .btn--ghost,
  .btn--text {
    --btn-bg: transparent;
    --btn-fg: var(--brand-ink);
    --btn-bd: transparent;
  }
  .btn--ghost:hover:not(:disabled),
  .btn--text:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand-ink); }

  .btn--danger,
  .peligro {
    --btn-bg: var(--surface);
    --btn-fg: var(--bad-ink);
    --btn-bd: var(--bad);
  }
  .btn--danger:hover:not(:disabled),
  .peligro:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad-ink); }

  .btn--sm { min-height: 28px; font-size: var(--fs-xs); padding: 0 var(--s-2); }
  .btn--md { }
  .btn-back {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    min-height: 32px;
    padding: 0 var(--s-2) 0 var(--s-1);
    margin-left: calc(var(--s-1) * -1);
    color: var(--brand-ink);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    border-radius: var(--r-sm);
  }
  .btn-back:hover { background: var(--brand-soft); }
  .btn-back svg { width: 16px; height: 16px; }

  .icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: var(--r-sm);
    color: var(--ink);
  }
  @media (pointer: coarse) { .icon-btn { width: var(--hit); height: var(--hit); min-width: var(--hit); } }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink-strong); }
  .icon-btn svg { width: 16px; height: 16px; }

  /* Chip de estado de cola: etiqueta de barra superior, no botón de acción */
  .chip {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 var(--s-2);
    border-radius: var(--r-sm);
    border: 1px solid var(--control);
    background: var(--surface);
    color: var(--ink-strong);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    white-space: nowrap;
  }
  .chip:hover { background: var(--surface-2); }
  .chip--bad {
    background: var(--bad-soft);
    border-color: var(--bad);
    color: var(--bad-ink);
  }

  /* ---------- Icono ---------- */
  svg[aria-hidden="true"]:not(.sparkline):not(.grafico) { flex: 0 0 auto; }
  .btn svg, .btn-foto svg { width: 16px; height: 16px; flex: 0 0 auto; }

  /* ---------- Segmentado (pestañas de vista: Todos / Locales / iCenters) ---------- */
  .segmented, .seg-toggle {
    display: flex;
    max-width: 100%;
    gap: 0;
    padding: 2px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--line);
    min-height: 36px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .segmented::-webkit-scrollbar, .seg-toggle::-webkit-scrollbar { display: none; }
  .segmented > button, .seg-toggle > button {
    flex: 1 0 auto;
    min-height: 30px;
    padding: 0 var(--s-3);
    border-radius: calc(var(--r-sm) - 2px);
    color: var(--ink);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    white-space: nowrap;
  }
  .segmented > button:hover, .seg-toggle > button:hover { background: var(--surface); color: var(--ink-strong); }
  .segmented > button[aria-pressed="true"], .seg-toggle > button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--ink-strong);
    font-weight: var(--fw-semibold);
    box-shadow: var(--shadow-1);
  }
  .segmented > button[aria-pressed="true"]::after { content: none; }

  /* ---------- Campos (field único; .campo y .check son alias de compatibilidad) ---------- */
  .field, .campo {
    display: grid;
    gap: var(--s-1);
    min-width: 0;
  }
  .field > label, .campo > span, .campo > label {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--ink-strong);
  }
  .campo > small, .field-help { font-size: var(--fs-xs); color: var(--muted); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
  select,
  textarea {
    width: 100%;
    min-height: 32px;
    padding: var(--s-1) var(--s-2);
    border-radius: var(--r-sm);
    border: 1px solid var(--control);
    border-bottom-color: var(--ink);
    background: var(--surface);
    color: var(--ink-strong);
    font-size: var(--fs-base);
    line-height: 1.3;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  }
  @media (pointer: coarse) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]), select { min-height: var(--hit); }
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):hover,
  select:hover, textarea:hover { border-color: var(--ink); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):focus,
  select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: inset 0 -1px 0 0 var(--brand);
  }
  textarea { min-height: 88px; resize: vertical; }
  select { appearance: auto; }
  input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
  input:disabled, select:disabled, textarea:disabled { opacity: 0.5; }
  .field--error input, .field--error select, .field--error textarea,
  input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
    border-color: var(--bad);
    border-bottom-color: var(--bad);
    box-shadow: inset 0 -1px 0 0 var(--bad);
  }
  .field-error, .error { color: var(--bad-ink); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
  .error-bloque {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-sm);
    background: var(--bad-soft);
    color: var(--bad-ink);
    border-left: 3px solid var(--bad);
  }

  .check {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    min-height: 32px;
    padding: var(--s-1) 0;
    font-size: var(--fs-md);
    cursor: pointer;
  }
  .check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    accent-color: var(--brand);
  }

  fieldset {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4) var(--s-4);
    display: grid;
    gap: var(--s-2);
  }
  legend { padding: 0 var(--s-1); font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--ink-strong); }

  /* ---------- Tarjetas ---------- */
  .card {
    position: relative;
    display: grid;
    gap: var(--s-3);
    min-width: 0;
    padding: var(--s-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
  }
  .card .card { background: var(--surface-2); box-shadow: none; }
  .card.estado-ok { box-shadow: inset 3px 0 0 var(--ok-fill), var(--shadow-1); }
  .card.estado-warn { box-shadow: inset 3px 0 0 var(--warn-fill), var(--shadow-1); }
  .card.estado-bad { box-shadow: inset 3px 0 0 var(--bad-fill), var(--shadow-1); }
  details.card { display: block; }
  details.card > :not(summary) { margin-top: var(--s-3); }
  .card > summary { list-style: none; }
  .card > summary::-webkit-details-marker { display: none; }
  details.card > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--hit);
    gap: var(--s-2);
  }
  details.card > summary::after {
    content: "";
    width: 7px; height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform var(--dur) var(--ease);
    flex: 0 0 auto;
  }
  details[open].card > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
  details.card > summary h2, details.card > summary strong { margin: 0; }
  details.card[open] > summary { margin-bottom: var(--s-1); }

  .section-title {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    color: var(--ink-strong);
    margin-top: var(--s-2);
  }
  .page-sub { color: var(--muted); font-size: var(--fs-sm); max-width: 66ch; }

  /* ---------- Cabecera de página ---------- */
  .page-head {
    display: grid;
    gap: var(--s-2);
    padding: var(--s-1) 0 var(--s-3);
    margin-bottom: var(--s-2);
  }
  .page-head-row { display: grid; gap: var(--s-3); align-items: start; }
  .page-head-texto { display: grid; gap: var(--s-1); min-width: 0; }
  .page-head-texto h1 { margin: 0; }
  .page-head-badge { margin-top: var(--s-1); }
  .page-head-accion { display: flex; flex-wrap: wrap; gap: var(--s-2); }

  /* ---------- Insignias (etiquetas Fluent: radio 4px, punto de color) ---------- */
  .badge {
    --b-bg: var(--neutral-soft);
    --b-fg: var(--neutral-ink);
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    min-height: 22px;
    padding: 1px var(--s-2);
    border-radius: var(--r-sm);
    background: var(--b-bg);
    color: var(--b-fg);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  .badge svg { width: 12px; height: 12px; }
  .badge::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
  }
  .badge--ok { --b-bg: var(--ok-soft); --b-fg: var(--ok-ink); }
  .badge--warn { --b-bg: var(--warn-soft); --b-fg: var(--warn-ink); }
  .badge--bad { --b-bg: var(--bad-soft); --b-fg: var(--bad-ink); }
  .badge--info { --b-bg: var(--brand-soft); --b-fg: var(--brand-ink); }
  .badge--neutral { --b-bg: var(--neutral-soft); --b-fg: var(--neutral-ink); }

  /* ---------- KPI (tile) ---------- */
  .tile {
    --t-fg: var(--ink-strong);
    display: grid;
    align-content: start;
    gap: var(--s-1);
    min-width: 0;
    min-height: 64px;
    padding: var(--s-3) var(--s-4);
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
  }
  .tile .etiqueta {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--muted);
    line-height: 1.3;
  }
  .tile .valor {
    font-size: var(--fs-2xl);
    font-weight: var(--fw-semibold);
    line-height: 1.1;
    color: var(--t-fg);
    font-variant-numeric: tabular-nums;
  }
  .tile .kpi-sub { font-size: var(--fs-xs); color: var(--muted); line-height: 1.35; }
  .tile.ok { --t-fg: var(--ok); box-shadow: inset 3px 0 0 var(--ok-fill), var(--shadow-1); }
  .tile.warn { --t-fg: var(--warn); box-shadow: inset 3px 0 0 var(--warn-fill), var(--shadow-1); }
  .tile.bad { --t-fg: var(--bad); box-shadow: inset 3px 0 0 var(--bad-fill), var(--shadow-1); }
  button.tile { cursor: pointer; font: inherit; color: inherit; }
  button.tile:hover { border-color: var(--control); background: var(--surface-2); }

  /* ---------- Progreso (barra fina Fluent) ---------- */
  .progress {
    --p-fill: var(--brand);
    position: relative;
    height: 4px;
    border-radius: 2px;
    background: var(--surface-3);
    overflow: hidden;
  }
  .progress-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--p-fill);
    transition: width 200ms var(--ease);
  }
  .progress--ok { --p-fill: var(--ok-fill); }
  .progress--warn { --p-fill: var(--warn-fill); }
  .progress--bad { --p-fill: var(--bad-fill); }
  .progress-marca { margin-top: var(--s-1); font-size: var(--fs-xs); color: var(--muted); }

  /* ---------- Acordeón ---------- */
  .acc {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    min-width: 0;
  }
  .acc.acc--ok { box-shadow: inset 3px 0 0 var(--ok-fill), var(--shadow-1); }
  .acc.acc--warn { box-shadow: inset 3px 0 0 var(--warn-fill), var(--shadow-1); }
  .acc.acc--bad { box-shadow: inset 3px 0 0 var(--bad-fill), var(--shadow-1); }
  .acc-h { font-size: inherit; color: inherit; margin: 0; }
  .acc-head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    width: 100%;
    min-height: 52px;
    padding: var(--s-2) var(--s-4);
    text-align: left;
    color: var(--ink-strong);
    border-radius: var(--r-lg);
  }
  .acc-head:hover { background: var(--surface-2); }
  .acc-num {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 var(--s-1);
    border-radius: var(--r-sm);
    background: var(--brand-soft);
    color: var(--brand-ink);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
  }
  .acc-texto { display: grid; gap: 2px; flex: 1 1 auto; min-width: 0; }
  .acc-title { font-weight: var(--fw-semibold); font-size: var(--fs-md); overflow-wrap: anywhere; }
  .acc-meta { font-size: var(--fs-xs); color: var(--muted); }
  .acc-chev { display: inline-grid; color: var(--muted); transition: transform var(--dur) var(--ease); }
  .acc-chev svg { width: 16px; height: 16px; }
  .acc.abierto .acc-chev { transform: rotate(180deg); }
  .acc-body { padding: 0 var(--s-4) var(--s-4); display: grid; gap: var(--s-3); }
  .acc-body[hidden] { display: none; }

  /* ---------- Tablas (encabezado fijo, orden por columna, scroll propio) ---------- */
  .table-wrap {
    width: 100%;
    max-width: 100%;
    max-height: 70vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-1);
  }
  table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-sm);
  }
  table.data th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--s-2) var(--s-3);
    background: var(--surface-2);
    color: var(--ink);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--control);
  }
  table.data th .th-orden {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    min-height: 24px;
    padding: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
  }
  table.data th .th-orden:hover { color: var(--ink-strong); }
  table.data th .th-orden svg { width: 12px; height: 12px; opacity: 0.5; }
  table.data th[aria-sort] .th-orden svg { opacity: 1; color: var(--brand); }
  table.data th[aria-sort="descending"] .th-orden svg { transform: rotate(180deg); }
  table.data td {
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    color: var(--ink);
    min-width: 0;
    overflow-wrap: anywhere;
  }
  table.data tbody tr:last-child td { border-bottom: 0; }
  table.data tbody tr:hover td { background: var(--surface-2); }
  table.data tbody tr[aria-selected="true"] td { background: var(--brand-soft); }
  table.data .tabla-num, table.data th.tabla-num { text-align: right; }
  table.data caption { caption-side: top; }
  td.tabla-num { font-variant-numeric: tabular-nums; }
  .celda-pct { font-weight: var(--fw-semibold); white-space: nowrap; }
  .celda-pct.ok { color: var(--ok); }
  .celda-pct.warn { color: var(--warn); }
  .celda-pct.bad { color: var(--bad); }

  /* ---------- Paginación ---------- */
  .pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-2) 0 0;
    color: var(--muted);
    font-size: var(--fs-sm);
  }
  .pager-controles { display: inline-flex; align-items: center; gap: var(--s-1); flex-wrap: wrap; }
  .pager-pagina {
    min-width: 32px;
    min-height: 32px;
    padding: 0 var(--s-2);
    border-radius: var(--r-sm);
    color: var(--ink);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }
  .pager-pagina:hover { background: var(--surface-2); color: var(--ink-strong); }
  .pager-pagina[aria-current="page"] {
    background: var(--brand);
    color: var(--on-brand);
    font-weight: var(--fw-semibold);
  }
  .pager-pagina:disabled { opacity: 0.4; cursor: not-allowed; }
  .pager-tamano { display: inline-flex; align-items: center; gap: var(--s-2); }
  .pager-tamano select { width: auto; min-height: 32px; }
  .pager-mas { width: 100%; justify-content: center; }

  /* ---------- Listas y definiciones ---------- */
  .list { list-style: none; padding: 0; margin: 0; display: grid; }
  .list-item { padding: var(--s-1) 0; border-bottom: 1px solid var(--line); }
  .list-item:last-child { border-bottom: 0; }
  .list-item > .btn { width: 100%; justify-content: flex-start; }

  .kv { display: grid; margin: 0; }
  .kv-fila {
    display: grid;
    grid-template-columns: minmax(96px, 40%) minmax(0, 1fr);
    gap: var(--s-3);
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--line);
    font-size: var(--fs-sm);
  }
  .kv-fila:last-child { border-bottom: 0; }
  .kv dt { color: var(--muted); }
  .kv dd { margin: 0; color: var(--ink-strong); overflow-wrap: anywhere; }

  /* ---------- Vacío, carga y superposiciones ---------- */
  .empty {
    display: grid;
    justify-items: center;
    gap: var(--s-2);
    padding: var(--s-8) var(--s-4);
    text-align: center;
    border: 1px dashed var(--control);
    border-radius: var(--r-lg);
    color: var(--muted);
  }
  .empty-icono {
    display: inline-grid;
    place-items: center;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--brand-ink);
  }
  .empty-icono svg { width: 20px; height: 20px; }
  .empty-titulo { font-weight: var(--fw-semibold); color: var(--ink-strong); font-size: var(--fs-md); }
  .empty-texto { font-size: var(--fs-sm); max-width: 44ch; }
  .empty-accion { margin-top: var(--s-2); }

  .skeleton { display: grid; gap: var(--s-3); padding: var(--s-4) 0; }
  .skeleton-linea {
    height: 12px;
    border-radius: var(--r-sm);
    background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
    background-size: 200% 100%;
    animation: pulso 1.2s var(--ease) infinite;
  }
  .skeleton-linea--corta { width: 60%; }
  @keyframes pulso { from { background-position: 100% 0; } to { background-position: -100% 0; } }

  .spinner {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2px solid var(--line);
    border-top-color: var(--brand);
    animation: girar 800ms linear infinite;
  }
  @keyframes girar { to { transform: rotate(360deg); } }

  .overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: var(--s-4);
    background: rgb(0 0 0 / 0.4);
  }
  .overlay-box {
    display: grid;
    justify-items: center;
    gap: var(--s-3);
    width: min(320px, 100%);
    padding: var(--s-6);
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
    text-align: center;
  }
  .overlay-box .progress { width: 100%; }

  /* Hoja modal: bottom sheet en móvil, centrada desde 600px */
  dialog#sheet:not([open]) { display: none; }
  dialog#sheet {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(88dvh, 100%);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  dialog#sheet[open] { animation: subir var(--dur) var(--ease); }
  dialog#sheet::backdrop { background: rgb(0 0 0 / 0.4); }
  @keyframes subir { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
  .sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
    min-height: 48px;
    padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
    border-bottom: 1px solid var(--line);
  }
  .sheet-head h2 { margin: 0; font-size: var(--fs-lg); }
  .sheet-body {
    display: grid;
    flex: 1 1 auto;
    min-height: 0;
    gap: var(--s-4);
    padding: var(--s-4);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: calc(var(--s-4) + env(safe-area-inset-bottom));
  }
  .sheet-body > form { display: grid; gap: var(--s-3); }
  dialog#sheet.cuenta .sheet-body { gap: var(--s-3); }

  .toasts {
    position: fixed;
    left: var(--s-4);
    right: var(--s-4);
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 70;
    display: grid;
    gap: var(--s-2);
    justify-items: center;
    pointer-events: none;
  }
  .toast {
    max-width: 480px;
    width: 100%;
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-sm);
    background: var(--ink-strong);
    color: var(--surface);
    box-shadow: var(--shadow-2);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
    animation: subir var(--dur) var(--ease);
  }
  .toast.ok { box-shadow: inset 3px 0 0 var(--ok-fill), var(--shadow-2); }
  .toast.bad { box-shadow: inset 3px 0 0 var(--bad-fill), var(--shadow-2); }
  .toast.saliendo { opacity: 0; transform: translateY(6px); }

  /* ---------- Gráficos ---------- */
  .grafico { width: 100%; height: auto; overflow: visible; }
  .grafico text.ejeTxt { fill: var(--muted); font-size: 12px; font-family: var(--font); }
  .grafico line.grid { stroke: var(--line); stroke-width: 1; }
  .grafico line.umbral { stroke-width: 1.5; stroke-dasharray: 4 3; }
  .grafico line.umbral.ok { stroke: var(--ok-fill); }
  .grafico line.umbral.warn { stroke: var(--warn-fill); }
  .grafico line.umbral.bad { stroke: var(--bad-fill); }
  .grafico circle.dot { stroke: var(--surface); stroke-width: 2; }
  .grafico circle.dot.ok { fill: var(--ok-fill); }
  .grafico circle.dot.warn { fill: var(--warn-fill); }
  .grafico circle.dot.bad { fill: var(--bad-fill); }
  .sparkline { width: 72px; height: 20px; }
  .sparkline polyline { fill: none; stroke: var(--brand); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }

  /* ---------- Escala de calificación (opciones) ---------- */
  .opciones {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--s-2);
  }
  .opciones.e5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .op {
    --o-fg: var(--ink-strong);
    --o-soft: var(--surface);
    --o-line: var(--control);
    min-height: 44px;
    padding: var(--s-1) var(--s-1);
    border-radius: var(--r-sm);
    border: 1px solid var(--o-line);
    background: var(--o-soft);
    color: var(--o-fg);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    text-align: center;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }
  .op:hover { background: var(--surface-2); }
  .op[aria-pressed="true"] {
    box-shadow: inset 0 0 0 2px var(--o-line);
    font-weight: var(--fw-bold);
  }
  .op.v-ok { --o-fg: var(--ok-ink); --o-line: var(--ok-fill); }
  .op.v-warn { --o-fg: var(--warn-ink); --o-line: var(--warn-fill); }
  .op.v-bad { --o-fg: var(--bad-ink); --o-line: var(--bad-fill); }
  .op.v-na { --o-fg: var(--neutral-ink); --o-line: var(--control); }
  .op.v-ok[aria-pressed="true"] { --o-soft: var(--ok-soft); }
  .op.v-warn[aria-pressed="true"] { --o-soft: var(--warn-soft); }
  .op.v-bad[aria-pressed="true"] { --o-soft: var(--bad-soft); }
  .op.v-na[aria-pressed="true"] { --o-soft: var(--neutral-soft); }
  .op[aria-pressed="true"]::after { content: none; }
  .ref {
    display: flex;
    justify-content: space-between;
    gap: var(--s-2);
    font-size: var(--fs-xs);
    color: var(--muted);
  }

  /* ---------- Stepper del formulario (stepper() de ui.js) ---------- */
  .stepper ol {
    display: flex;
    gap: var(--s-1);
    margin: 0;
    padding: 0 0 var(--s-1);
    list-style: none;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .stepper ol::-webkit-scrollbar { display: none; }
  .stepper-paso { flex: 0 0 auto; }
  .stepper-boton {
    display: grid;
    justify-items: center;
    gap: var(--s-1);
    min-width: 72px;
    min-height: var(--hit);
    padding: var(--s-1) var(--s-2);
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: var(--fs-2xs);
    font-weight: var(--fw-medium);
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
  }
  .stepper-boton:hover { background: var(--surface-2); color: var(--ink-strong); }
  .stepper-boton:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .stepper-marca {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--control);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
  }
  .stepper-marca svg { width: 14px; height: 14px; }
  .stepper-texto {
    display: -webkit-box;
    max-width: 9em;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .stepper-paso--completa .stepper-marca { background: var(--ok-fill); border-color: var(--ok-fill); color: var(--surface); }
  .stepper-paso--error .stepper-marca { background: var(--bad-fill); border-color: var(--bad-fill); color: var(--surface); }
  .stepper-paso--parcial .stepper-marca { border-color: var(--brand-ink); color: var(--brand-ink); }
  .stepper-paso.es-actual .stepper-boton { color: var(--ink-strong); border-bottom-color: var(--brand); background: var(--brand-soft); }
  .stepper-paso.es-actual .stepper-marca { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

  /* ---------- Calendario mensual (calendario() de ui.js) ---------- */
  .calendario { display: grid; gap: var(--s-3); }
  .cal-cabecera { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s-2); }
  .cal-titulo { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--ink-strong); text-align: center; }
  .cal-grilla { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--s-1); }
  .cal-semana {
    padding-bottom: var(--s-1);
    color: var(--muted);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    text-align: center;
    text-transform: capitalize;
  }
  .cal-vacio { min-height: var(--hit); }
  .cal-dia {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    min-height: var(--hit);
    padding: var(--s-1);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }
  .cal-dia:hover { background: var(--surface-2); color: var(--ink-strong); }
  .cal-dia:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .cal-dia[aria-pressed="true"] {
    border-color: var(--brand);
    background: var(--brand-soft);
    color: var(--brand-ink);
    font-weight: var(--fw-semibold);
  }
  .cal-hoy .cal-num { font-weight: var(--fw-bold); text-decoration: underline; text-underline-offset: 3px; }
  .cal-n {
    padding: 0 var(--s-1);
    border-radius: 999px;
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    line-height: 1.5;
  }
  .cal-bad .cal-n { background: var(--bad-soft); color: var(--bad-ink); }
  .cal-warn .cal-n { background: var(--warn-soft); color: var(--warn-ink); }
  .cal-neutral .cal-n { background: var(--neutral-soft); color: var(--neutral-ink); }
  .cal-detalle { display: grid; gap: var(--s-2); padding-top: var(--s-3); border-top: 1px solid var(--line); }
  .cal-detalle-titulo { margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--ink-strong); }

  /* ---------- Grabador de audio por punto (grabadorHTML() de vistas.js) ---------- */
  .grabador { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
  .grabador-estado {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    margin: 0;
    color: var(--bad-ink);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    font-variant-numeric: tabular-nums;
  }
  .grabador-punto {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bad-fill);
    animation: grabador-pulso 1.2s var(--ease) infinite;
  }
  @keyframes grabador-pulso { 50% { opacity: 0.3; } }
  .grabador-audio { width: 100%; min-height: var(--hit); }

  /* ---------- Fotos ---------- */
  .fotos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: var(--s-2);
  }
  .fotos-item { position: relative; }
  .fotos-ver {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--r-sm);
    overflow: hidden;
    border: 1px solid var(--line);
  }
  .fotos-ver img { width: 100%; height: 100%; object-fit: cover; }
  .fotos-borrar {
    position: absolute;
    top: 4px;
    right: 4px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--ink-strong);
    color: var(--surface);
    font-size: 12px;
    line-height: 1;
    box-shadow: var(--shadow-1);
  }
  .fotos-borrar:hover { background: var(--bad-ink); }
  .btn-foto {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: 88px;
    padding: var(--s-2);
    border: 1px dashed var(--control);
    border-radius: var(--r-sm);
    color: var(--brand-ink);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    text-align: center;
    cursor: pointer;
    position: relative;
  }
  .btn-foto:hover { background: var(--brand-soft); }
  .btn-foto:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
  .btn-foto input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
  }
}
