/* ==========================================================
   PRESTAX · HISTORIAL DESKTOP COMPACTO P4
   - Una sola fila por documento desde 980 px.
   - Estado, fecha y acciones permanecen en la misma línea.
   - Los botones conservan texto accesible y usan icono visual compacto.
   - No modifica datos, estados fiscales ni llamadas de backend.
   ========================================================== */

.history-date-field-label--short {
  display: none;
}

@media (min-width: 980px) and (hover: hover) and (pointer: fine) {
  #fullHistoryModal .client-docs,
  #fullHistoryModal .history-flat-list {
    gap: 5px !important;
  }

  #fullHistoryModal li.li-doc-item,
  #fullHistoryModal li.li-doc-item.history-flat-doc-item,
  #fullHistoryModal .history-flat-list > li.li-doc-item.history-flat-doc-item {
    display: grid !important;
    grid-template-columns:
      54px
      minmax(170px, 1fr)
      minmax(118px, 138px)
      minmax(138px, 156px)
      max-content !important;
    grid-template-rows: 52px !important;
    align-items: center !important;
    column-gap: 6px !important;
    row-gap: 0 !important;
    min-width: 0 !important;
    min-height: 62px !important;
    margin: 0 !important;
    padding: 5px 7px !important;
    border-radius: 12px !important;
  }

  #fullHistoryModal li.li-doc-item > * {
    min-width: 0 !important;
  }

  #fullHistoryModal li.li-doc-item .history-date-badge,
  #fullHistoryModal li.li-doc-item.history-flat-doc-item .history-date-badge,
  #fullHistoryModal
    .history-flat-list
    > li.li-doc-item.history-flat-doc-item
    .history-date-badge {
    grid-column: 1 !important;
    grid-row: 1 !important;
    align-self: center !important;
    width: 54px !important;
    min-width: 54px !important;
    height: 52px !important;
    min-height: 52px !important;
    padding: 4px 3px !important;
    border-radius: 11px !important;
  }

  #fullHistoryModal .history-date-day {
    font-size: 1rem !important;
  }

  #fullHistoryModal .history-date-month,
  #fullHistoryModal .history-date-year {
    font-size: 0.62rem !important;
  }

  #fullHistoryModal li.li-doc-item span.doc-title,
  #fullHistoryModal li.li-doc-item.history-flat-doc-item span.doc-title,
  #fullHistoryModal
    .history-flat-list
    > li.li-doc-item.history-flat-doc-item
    span.doc-title {
    grid-column: 2 !important;
    grid-row: 1 !important;
    align-self: center !important;
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    line-height: 1.2 !important;
    font-size: 0.88rem !important;
  }

  #fullHistoryModal .doc-title .notainterna,
  #fullHistoryModal .doc-title .history-rectification-ref,
  #fullHistoryModal .doc-title .history-flat-client,
  #fullHistoryModal .doc-title .history-fiscal-badge {
    display: inline-flex !important;
    align-items: center !important;
    vertical-align: middle !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    margin-left: 5px !important;
  }

  #fullHistoryModal .doc-title .history-payment-summary,
  #fullHistoryModal .doc-title .history-due-summary {
    display: none !important;
  }

  #fullHistoryModal .doc-title .history-rectification-ref {
    max-width: 180px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.7rem !important;
  }

  #fullHistoryModal .history-flat-client {
    max-width: 210px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.72rem !important;
  }

  #fullHistoryModal .history-flat-client strong,
  #fullHistoryModal .history-flat-client em {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  #fullHistoryModal .history-fiscal-badge {
    max-width: 142px !important;
    padding: 2px 6px !important;
    font-size: 0.66rem !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #fullHistoryModal li.li-doc-item > .status-select,
  #fullHistoryModal
    .history-flat-list
    > li.li-doc-item.history-flat-doc-item
    .status-select {
    grid-column: 3 !important;
    grid-row: 1 !important;
    align-self: center !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 32px !important;
    height: 32px !important;
    margin: 0 !important;
    padding: 0 8px !important;
    border-radius: 10px !important;
    font-size: 0.75rem !important;
  }

  #fullHistoryModal li.li-doc-item > .muted:not(label) {
    grid-column: 3 / span 2 !important;
    grid-row: 1 !important;
    align-self: center !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.72rem !important;
  }

  #fullHistoryModal .history-date-field-label--long {
    display: none !important;
  }

  #fullHistoryModal .history-date-field-label--short {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    white-space: nowrap !important;
    font-size: 0.66rem !important;
    font-weight: 850 !important;
    line-height: 1 !important;
  }

  #fullHistoryModal label.history-paid-date-field,
  #fullHistoryModal label.history-due-date-field {
    grid-column: 4 !important;
    grid-row: 1 !important;
    align-self: center !important;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 4px !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
  }

  #fullHistoryModal label.history-due-date-field.is-overdue {
    color: #fb7185 !important;
  }

  #fullHistoryModal label.history-due-date-field .history-mobile-date-shell {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  #fullHistoryModal .history-paid-date-input,
  #fullHistoryModal .history-due-date-input {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 32px !important;
    height: 32px !important;
    margin: 0 !important;
    padding: 0 5px !important;
    border-radius: 9px !important;
    font-size: 0.7rem !important;
    line-height: 32px !important;
    box-sizing: border-box !important;
    color-scheme: light;
  }

  #fullHistoryModal li.li-doc-item .acciones-factura,
  #fullHistoryModal
    .history-flat-list
    > li.li-doc-item.history-flat-doc-item
    .acciones-factura {
    grid-column: 5 !important;
    grid-row: 1 !important;
    align-self: center !important;
    justify-self: end !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    width: max-content !important;
    min-width: 0 !important;
    margin: 0 !important;
    gap: 4px !important;
  }

  #fullHistoryModal .acciones-factura > button {
    flex: 0 0 34px !important;
    width: 60px !important;
    min-width: 120px !important;
    max-width: 150px !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 !important;
    border-radius: 10px !important;
    display: inline-grid !important;
    place-items: center !important;
    overflow: hidden !important;
  }

  #fullHistoryModal .acciones-factura .btn-mini svg {
    width: 19px !important;
    height: 19px !important;
  }

  #fullHistoryModal .acciones-factura .btn-minihist,
  #fullHistoryModal .acciones-factura .buttonclearhist {
    font-size: 10px !important;

    width: 2rem !important;

    min-width: 120px !important;
  }
  .regenerate-pdf {
    border: 1px solid rgba(196, 181, 253, 0.42) !important;
    background: rgba(124, 58, 237, 0.18) !important;
    color: #ede9fe !important;
  }
  #fullHistoryModal .acciones-factura .btn-minihist::before,
  #fullHistoryModal .acciones-factura .buttonclearhist::before {
    display: block !important;
    font-size: 1rem !important;
    font-weight: 900 !important;
    line-height: 1 !important;
  }

  #fullHistoryModal
    .acciones-factura
    [data-action="check-fiscal-status"]::before {
    content: "↻";
  }

  #fullHistoryModal
    .acciones-factura
    [data-action="complete-fiscal-emission"]::before {
    content: "✓";
  }

  #fullHistoryModal .acciones-factura [data-action="rectify-doc"]::before {
    content: "↳";
  }

  #fullHistoryModal .acciones-factura [data-action="delete-doc"]::before {
    content: "×";
  }

  #fullHistoryModal .acciones-factura > button:focus-visible {
    outline: 3px solid rgba(96, 165, 250, 0.72) !important;
    outline-offset: 2px !important;
  }
}

@media (min-width: 980px) and (max-width: 1120px) and (hover: hover) and (pointer: fine) {
  #fullHistoryModal li.li-doc-item,
  #fullHistoryModal li.li-doc-item.history-flat-doc-item,
  #fullHistoryModal .history-flat-list > li.li-doc-item.history-flat-doc-item {
    grid-template-columns:
      50px
      minmax(140px, 1fr)
      116px
      132px
      max-content !important;
    column-gap: 5px !important;
    padding-inline: 6px !important;
  }

  #fullHistoryModal li.li-doc-item .history-date-badge,
  #fullHistoryModal li.li-doc-item.history-flat-doc-item .history-date-badge {
    width: 50px !important;
    min-width: 50px !important;
  }

  #fullHistoryModal .history-flat-client em {
    display: none !important;
  }

  #fullHistoryModal .history-fiscal-badge {
    max-width: 122px !important;
  }

  #fullHistoryModal .acciones-factura > button {
    flex-basis: 32px !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
  }
}

/* P7 · Recuperación preventiva del PDF desde el JSON fuente. */
@media (min-width: 980px) and (hover: hover) and (pointer: fine) {
  #fullHistoryModal .acciones-factura [data-action="regenerate-pdf"]::before {
    content: "⟳";
  }
}

/* V46.25 R10 · Filas con muchas acciones (consolida la regla R9-2 del canje).
   Causa raíz: desde 980 px la fila es una rejilla de 5 pistas cuya última pista
   (acciones) es max-content, y cada botón conserva 120 px porque
   `.acciones-factura .btn-minihist { min-width: 120px !important }` gana a la
   regla de iconos de 32 px del tramo 980–1120. Con 4 botones (412 px) la rejilla
   desbordaba la fila en 980–1020 px (medido: 48/28/8 px) y con 5 botones (536 px)
   hasta 1121 px. R9-2 solo lo resolvía en las filas con «Canjear»; cualquier otra
   fila con 4 botones (p. ej. Ver + Copia PDF + Comprobar + Rectificativa)
   seguía desbordando.
   Solución por número de botones, no por botón concreto:
   - 980–1120 px y 4 o más botones: acciones de 248 px en líneas de 2 (igual
     que R9-2 para el canje, que queda cubierto).
   - Desde 1121 px y 5 o más botones: acciones de 372 px en líneas de 3.
   Filas con 3 botones o menos: sin cambios (medido). */
@media (min-width: 980px) and (max-width: 1120px) and (hover: hover) and (pointer: fine) {
  #fullHistoryModal
    #fullHistoryContent
    li.li-doc-item:has(> .acciones-factura > button:nth-of-type(4)) {
    grid-template-columns:
      50px
      minmax(140px, 1fr)
      190px
      132px
      248px !important;
    grid-template-rows: auto !important;
  }

  #fullHistoryModal
    #fullHistoryContent
    li.li-doc-item:has(> .acciones-factura > button:nth-of-type(4))
    > .acciones-factura {
    flex-wrap: wrap !important;
    width: 248px !important;
    max-width: 248px !important;
    row-gap: 4px !important;
  }
}

@media (min-width: 1121px) and (hover: hover) and (pointer: fine) {
  #fullHistoryModal
    #fullHistoryContent
    li.li-doc-item:has(> .acciones-factura > button:nth-of-type(5)) {
    grid-template-columns:
      54px
      minmax(170px, 1fr)
      minmax(118px, 138px)
      minmax(138px, 156px)
      372px !important;
    grid-template-rows: auto !important;
  }

  #fullHistoryModal
    #fullHistoryContent
    li.li-doc-item:has(> .acciones-factura > button:nth-of-type(5))
    > .acciones-factura {
    flex-wrap: wrap !important;
    width: 372px !important;
    max-width: 372px !important;
    row-gap: 4px !important;
  }
}
