/**
 * DOCAPI — bordes y marcos ~25 % más oscuros que Bootstrap 5.3 por defecto.
 * Fórmula: color-mix(base 75%, black 25%)
 */
:root {
  --docapi-border-base: #dee2e6;
  --docapi-border-subtle-base: #e9ecef;
  --docapi-border-secondary-base: #c4c8cb;
  --docapi-border-dark-subtle-base: #adb5bd;
  --docapi-border-translucent-alpha: 0.219;

  --bs-border-color: color-mix(in srgb, var(--docapi-border-base) 75%, #000 25%);
  --bs-border-color-translucent: rgba(0, 0, 0, var(--docapi-border-translucent-alpha));
  --bs-secondary-border-subtle: color-mix(
    in srgb,
    var(--docapi-border-secondary-base) 75%,
    #000 25%
  );
  --bs-light-border-subtle: color-mix(
    in srgb,
    var(--docapi-border-subtle-base) 75%,
    #000 25%
  );
  --bs-dark-border-subtle: color-mix(
    in srgb,
    var(--docapi-border-dark-subtle-base) 75%,
    #000 25%
  );
  --bs-card-border-color: var(--bs-border-color-translucent);
}

/* Fallback sin color-mix */
@supports not (color: color-mix(in srgb, #000 50%, #fff)) {
  :root {
    --bs-border-color: #a6a9ac;
    --bs-border-color-translucent: rgba(0, 0, 0, 0.219);
    --bs-secondary-border-subtle: #939699;
    --bs-light-border-subtle: #afb3b7;
    --bs-dark-border-subtle: #828890;
  }
}

.card,
.card-header,
.card-footer {
  border-color: var(--bs-border-color);
}

.form-control,
.form-select,
.form-check-input,
.input-group-text {
  border-color: var(--bs-border-color);
}

.form-control:disabled,
.form-select:disabled {
  border-color: var(--bs-border-color);
}

.table,
.table-bordered > :not(caption) > * > * {
  border-color: var(--bs-border-color);
}

.border,
.border-top,
.border-bottom,
.border-start,
.border-end,
.border-start-0,
.border-end-0 {
  border-color: var(--bs-border-color) !important;
}

.modal-content,
.modal-header,
.modal-footer,
.dropdown-menu,
.list-group-item,
.page-link,
.nav-tabs .nav-link,
.accordion-item,
.accordion-button {
  border-color: var(--bs-border-color);
}

hr,
.border-secondary,
.border-secondary-subtle {
  border-color: var(--bs-secondary-border-subtle) !important;
  opacity: 1;
}

.badge.border {
  border-color: var(--bs-border-color) !important;
}

.modal-dialog {
  max-width: 720px;
}

.modal-dialog.modal-dialog-wide {
  max-width: 900px;
}

/* Navbar compacto */
.docapi-navbar {
  min-height: 0;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
}

.docapi-navbar .navbar-brand {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding-top: 0;
  padding-bottom: 0;
}

.docapi-navbar .nav-link {
  padding: 0.2rem 0.55rem;
  font-size: 0.8125rem;
}

.docapi-navbar .navbar-text {
  font-size: 0.8125rem;
}

/* Modales discretos */
.modal-header {
  padding: 0.35rem 0.75rem;
  min-height: 0;
}

.modal-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
}

.modal-header .btn-close {
  width: 0.65em;
  height: 0.65em;
  padding: 0.35rem;
  margin: 0 0 0 auto;
  opacity: 0.55;
}

.modal-body {
  padding: 0.65rem 0.75rem;
}

.modal-footer {
  padding: 0.35rem 0.75rem;
  gap: 0.35rem;
}

.modal-footer .btn {
  --bs-btn-padding-y: 0.25rem;
  --bs-btn-padding-x: 0.55rem;
  --bs-btn-font-size: 0.8125rem;
  --bs-btn-border-radius: var(--bs-border-radius-sm);
}

.json-block-modal-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.json-block-modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 92vh;
}

.json-block-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
}

.json-block-modal-body::-webkit-scrollbar {
  width: 10px;
}

.json-block-modal-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 5px;
}

.json-block-editor-pane {
  flex: 0 0 80%;
  max-height: 80%;
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.json-block-editor-textarea {
  flex: 1 1 auto;
  min-height: 180px;
  height: 100%;
  resize: vertical;
}

.json-block-preview-box {
  flex: 1 1 auto;
  min-height: 180px;
  overflow-y: auto;
}

.json-block-details-pane {
  flex: 1 1 auto;
  min-height: 140px;
}

.docapi-modal-resize-handle,
.json-block-modal-resize-handle,
.txt-normalizar-modal-resize-handle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  opacity: 0.45;
  background: linear-gradient(135deg, transparent 50%, var(--bs-secondary) 50%);
  border-radius: 0 0 3px 0;
  z-index: 2;
}

.docapi-modal-resize-handle:hover,
.json-block-modal-resize-handle:hover,
.txt-normalizar-modal-resize-handle:hover {
  opacity: 0.85;
}

.docapi-modal-resizable-footer {
  justify-content: flex-end;
  gap: 0.5rem;
  position: relative;
  flex-shrink: 0;
}

.docapi-preview-modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.docapi-preview-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.docapi-preview-pre {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.docapi-modal-tabs .nav-link {
  padding: 0.3rem 0.7rem;
  font-size: 0.8125rem;
  line-height: 1.25;
}

.json-block-edited-dot {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #ffc107;
  border: 1px solid #e0a800;
  box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.25);
  z-index: 1;
}

.json-block-historial-scroll {
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.json-block-historial-scroll::-webkit-scrollbar {
  width: 8px;
}

.json-block-historial-scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.card-header {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  font-size: 0.875rem;
}

.json-doc-page {
  background: #fff;
  color: #212529;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  padding: 1.25rem 1.5rem;
  max-height: 72vh;
  overflow-y: auto;
  line-height: 1.55;
}

.json-doc-titulo {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
}

.json-doc-subtitulo {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0.85rem 0 0.4rem;
}

.json-doc-texto {
  margin: 0.45rem 0;
  white-space: pre-wrap;
}

.json-doc-lista {
  margin: 0.45rem 0 0.45rem 1rem;
  white-space: pre-wrap;
}

.json-doc-table-wrap {
  margin: 0.75rem 0;
  overflow-x: auto;
}

.json-doc-table-wrap table {
  width: 100%;
  font-size: 0.875rem;
}

.json-doc-table-wrap tr.row-unified-part {
  background: rgba(13, 110, 253, 0.1);
}

.json-doc-table-wrap.json-doc-table-unified {
  border-left: 3px solid var(--bs-primary);
  padding-left: 0.5rem;
}

.json-doc-table-wrap.json-doc-table-continuation {
  border-left: 3px solid var(--bs-secondary);
  padding-left: 0.5rem;
  margin-top: -0.35rem;
}

.json-doc-table-wrap.json-doc-table-head {
  border-left: 3px solid var(--bs-primary);
  padding-left: 0.5rem;
}

.json-doc-table-wrap.json-doc-table-link {
  border-left: 3px solid var(--bs-primary);
  padding-left: 0.5rem;
  margin-top: -0.35rem;
  border-radius: 0;
}

.json-doc-table-wrap.json-doc-table-tail {
  border-left: 3px solid var(--bs-secondary);
  padding-left: 0.5rem;
  margin-top: -0.35rem;
  background: rgba(108, 117, 125, 0.06);
}

.json-doc-table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.json-segment-union-head {
  border-bottom: none !important;
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  margin-bottom: 0 !important;
  border-left: 3px solid var(--bs-primary) !important;
}

.json-segment-union-link {
  border-top: none !important;
  border-bottom: none !important;
  border-radius: 0 !important;
  margin-top: -0.5rem !important;
  margin-bottom: 0 !important;
  border-left: 3px solid var(--bs-primary) !important;
  background: rgba(13, 110, 253, 0.04);
}

.json-segment-union-tail {
  border-top: none !important;
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
  margin-top: -0.5rem !important;
  margin-bottom: 0.75rem !important;
  border-left: 3px solid var(--bs-secondary) !important;
  background: rgba(108, 117, 125, 0.06);
}

.json-segment-union-origin {
  border-bottom: none !important;
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  margin-bottom: 0 !important;
  border-left: 3px solid var(--bs-primary) !important;
}

.json-segment-union-partner {
  border-top: none !important;
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
  margin-top: -0.5rem !important;
  margin-bottom: 0.75rem !important;
  border-left: 3px solid var(--bs-secondary) !important;
  background: rgba(108, 117, 125, 0.06);
}

.json-doc-image {
  margin: 0.75rem 0;
  text-align: center;
}

.json-doc-image img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.25rem;
}

.json-doc-salto {
  border-top: 1px dashed #adb5bd;
  margin: 0.5rem 0;
  padding-top: 0.35rem;
  color: #6c757d;
  font-size: 0.75rem;
  text-align: center;
}

.md-rendered {
  line-height: 1.6;
  max-width: 100%;
}

.md-rendered h1,
.md-rendered h2,
.md-rendered h3,
.md-rendered h4 {
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
}

.md-rendered pre {
  background: #f6f8fa;
  padding: 0.75rem;
  border-radius: 4px;
  overflow-x: auto;
}

.md-rendered table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
}

.md-rendered table th,
.md-rendered table td {
  border: 1px solid var(--bs-border-color);
  padding: 0.35rem 0.5rem;
}

.md-rendered img {
  max-width: 100%;
  height: auto;
}

.legaser-mark-block {
  border: 1px solid var(--bs-border-color);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  background: #fff;
}

.legaser-mark-header {
  border-left: 4px solid #dc3545;
  background: #fff5f5;
}

.legaser-mark-footer {
  border-left: 4px solid #ffc107;
  background: #fffbeb;
}

.legaser-mark-approved {
  opacity: 0.95;
}

.legaser-mark-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.legaser-mark-header .legaser-mark-badge {
  background: #dc3545;
  color: #fff;
}

.legaser-mark-footer .legaser-mark-badge {
  background: #ffc107;
  color: #212529;
}

.legaser-mark-content {
  font-family: inherit;
  margin: 0;
}

.legaser-txt-plain-segment {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.legaser-txt-lined-table td {
  vertical-align: top;
  padding: 0.1rem 0.35rem;
  border: none;
}

.legaser-line-gutter {
  width: 3.5rem;
  min-width: 3.5rem;
  padding-right: 0.75rem !important;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

.legaser-line-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.legaser-line-clickable {
  cursor: pointer;
}

.legaser-line-clickable:hover {
  background: rgba(255, 255, 255, 0.06);
}

.legaser-line-selected {
  background: rgba(13, 110, 253, 0.25) !important;
}

.legaser-line-anchor {
  outline: 1px dashed rgba(13, 202, 240, 0.8);
}

.legaser-line-marked {
  background: rgba(111, 66, 193, 0.18);
}

.legaser-line-tag {
  opacity: 0.55;
  font-style: italic;
}

.legaser-line-tag .legaser-line-gutter {
  opacity: 0.45;
}

.legaser-mark-manual {
  border-left: 4px solid #6f42c1;
  background: #f8f5ff;
}

.legaser-mark-manual .legaser-mark-badge {
  background: #6f42c1;
  color: #fff;
}

.legaser-mark-tag {
  font-size: 0.7rem;
  opacity: 0.85;
}

/* Preview marcadores IA (detección asistida) */
.ia-marcador-preview {
  border: 1px solid var(--bs-border-color);
  border-radius: 6px;
  padding: 0.75rem;
  background: #fafafa;
}

.ia-marcador-flow {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

.ia-marcador-texto {
  display: inline;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: inherit;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

.ia-marcador-chip-wrap {
  display: inline;
  vertical-align: baseline;
}

.ia-marcador-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.35rem 0.15rem 0.5rem;
  border-radius: 4px;
  margin: 0 0.15rem;
  vertical-align: middle;
  white-space: nowrap;
}

.ia-marcador-chip-label::before {
  content: "[ ";
}

.ia-marcador-chip-label::after {
  content: " ]";
}

.ia-marcador-chip-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  color: inherit;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
}

.ia-marcador-chip-close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.25);
}

.ia-marcador-chip-movable {
  cursor: pointer;
  user-select: none;
}

.ia-marcador-chip-movable:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.35);
}

.ia-marcador-chip-offset {
  font-size: 0.6rem;
  opacity: 0.9;
  font-weight: 600;
}

.ia-chip-titulo {
  background: #0d6efd;
  color: #fff;
}

.ia-chip-articulo {
  background: #198754;
  color: #fff;
}

.ia-chip-capitulo {
  background: #6f42c1;
  color: #fff;
}

.ia-chip-bloque {
  background: #fd7e14;
  color: #fff;
}

.ia-chip-seccion {
  background: #20c997;
  color: #fff;
}

.ia-chip-default {
  background: #6c757d;
  color: #fff;
}

/* Segmentación documental */
.seg-badges-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.15rem 0;
}

.seg-badges-clickable {
  cursor: pointer;
}

.seg-badge {
  font-size: 0.65rem;
  font-weight: 500;
}

.seg-badge-id {
  background: #0d6efd;
  color: #fff;
}

.seg-badge-titulo {
  background: #6610f2;
  color: #fff;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seg-badge-parte {
  background: #6f42c1;
  color: #fff;
}

.seg-badge-contexto {
  background: #20c997;
  color: #212529;
}

.seg-badge-marcador {
  background: #e9ecef;
  color: #495057;
  border: 1px solid #ced4da;
}

.seg-badge-vectorizar {
  background: #198754;
  color: #fff;
}

.seg-block-row:hover {
  background: #f8f9fa;
}

.chk-block-row:hover {
  background: #f8f9fa;
}

.chk-badge-id {
  background: #0dcaf0;
  color: #212529;
}

.chk-badge-titulo {
  background: #6f42c1;
  color: #fff;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chk-badge-aceptado,
.chk-badge-manual {
  background: #198754;
  color: #fff;
}

.chk-badge-sugerido {
  background: #ffc107;
  color: #212529;
}

.chk-badge-rechazado {
  background: #6c757d;
  color: #fff;
}

.chk-render-divider-line {
  border: 0;
  border-top: 1px solid #adb5bd;
  opacity: 0.65;
}

.chk-render-divider-label {
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  white-space: pre-line;
  line-height: 1.3;
}

.chk-block-highlight {
  outline: 2px solid #0d6efd;
  background: #e7f1ff !important;
}

.json-block-chrome {
  border-bottom: 1px dotted #dee2e6;
  padding-bottom: 0.2rem;
}

.txt-normalizar-modal .modal-dialog.modal-lg {
  max-width: 800px;
}

.docapi-preview-modal-dialog,
.txt-normalizar-modal-dialog {
  position: relative;
}

.txt-normalizar-modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.txt-normalizar-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.txt-normalizar-modal-footer {
  justify-content: flex-end;
  gap: 0.5rem;
}

.txt-normalizar-modal .txt-normalizar-preview {
  margin: 0;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  tab-size: 4;
}

.txt-normalizar-modal .txt-md-render {
  width: 100%;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.txt-normalizar-modal .txt-md-render .patron-micro-labels {
  display: inline;
  margin-right: 0.15rem;
  vertical-align: baseline;
}

.txt-normalizar-modal .txt-md-render .patron-micro-label {
  display: inline-block;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  padding: 0.05rem 0.28rem;
  margin-right: 0.12rem;
  border-radius: 0.2rem;
  cursor: help;
  white-space: nowrap;
  vertical-align: middle;
}

.txt-normalizar-modal .txt-md-render .patron-micro-label--sis {
  background: #e9ecef;
  color: #495057;
  border: 1px solid #ced4da;
}

.txt-normalizar-modal .txt-md-render .patron-micro-label--ia {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffecb5;
}

.txt-normalizar-modal .txt-md-render .patron-micro-label--man {
  background: #e7f1ff;
  color: #0b5ed7;
  border: 1px solid #b6d4fe;
}

.txt-normalizar-modal .txt-md-intermedio-path code {
  font-size: 0.75rem;
  word-break: break-all;
}

.txt-normalizar-split {
  min-height: 0;
  overflow: hidden;
}

.txt-normalizar-panel {
  font-size: 0.78rem;
}

.txt-normalizar-panel .patron-codigo-badge {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.12rem 0.28rem;
  vertical-align: middle;
}

.txt-normalizar-panel .patron-codigo-badge--sis {
  background: #e9ecef;
  color: #495057;
}

.txt-normalizar-panel .patron-codigo-badge--ia {
  background: #fff3cd;
  color: #856404;
}

.txt-normalizar-panel .patron-codigo-badge--man {
  background: #e7f1ff;
  color: #0b5ed7;
}

.txt-normalizar-panel .patron-codigo-badge--other {
  background: #f8f9fa;
  color: #6c757d;
}

.txt-normalizar-splitter {
  width: 5px;
  cursor: col-resize;
  background: #e9ecef;
  transition: background 0.15s;
}

.txt-normalizar-splitter:hover {
  background: #adb5bd;
}

.txt-normalizar-doc {
  min-height: 0;
  overflow: hidden;
}

.txt-plantilla-marca-bloque + .txt-plantilla-marca-bloque {
  margin-top: 1rem;
}

.txt-plantilla-marca-temporal {
  background: rgba(255, 193, 7, 0.22);
  border-left: 3px solid #ffc107;
  padding-left: 0.35rem;
  margin-left: -0.35rem;
}

.txt-plantilla-marca-etiqueta {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: #856404;
  margin-right: 0.35rem;
}

.txt-plantilla-marca-micro {
  display: inline-block;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: #664d03;
  background: rgba(255, 193, 7, 0.35);
  border: 1px solid rgba(255, 193, 7, 0.65);
  border-radius: 0.2rem;
  padding: 0.05rem 0.3rem;
  margin-right: 0.35rem;
  vertical-align: baseline;
  white-space: nowrap;
}

.txt-plantilla-preview-list {
  max-height: 10rem;
  overflow-y: auto;
  font-size: 0.65rem;
  line-height: 1.35;
}

.txt-plantilla-preview-hit {
  padding: 0.2rem 0.15rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.txt-plantilla-preview-hit:last-child {
  border-bottom: none;
}

.txt-plantilla-preview-text {
  display: block;
  margin-top: 0.1rem;
  color: var(--bs-body-color);
  word-break: break-word;
}
