/* Facturación e Informes (agente DINERO). Usa los tokens de app.css; los colores de gráfica (--viz-*) están validados
   para daltonismo y contraste sobre --surface en claro y oscuro. */

:root {
  --viz-1: #2a78d6;
  --viz-2: #eb6834;
  --viz-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --viz-1: #3987e5;
    --viz-2: #d95926;
    --viz-3: #199e70;
  }
}
:root[data-tema="oscuro"] {
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-3: #199e70;
}

/* ───────── Filtros y estados de carga ───────── */
.din-filtros, .din-periodo { display: flex; flex-direction: column; gap: var(--sp-3); }
.din-fechas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); max-width: 420px; }
.din-rango-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); flex-wrap: wrap; }
.din-rango { color: var(--text-2); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.din-contenido { transition: opacity 0.15s; }
.din-contenido.is-cargando { opacity: 0.55; pointer-events: none; }
.din-buscador { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; }
.din-buscador .search { flex: 1 1 220px; }
.din-buscador .field { flex: 0 1 auto; }
.din-kv { grid-template-columns: minmax(0, 1fr) max-content; }
.din-kv dd { text-align: right; }
.table td.din-accion { text-align: right; white-space: nowrap; }
@media (max-width: 719px) {
  .table-cards td.din-accion { justify-content: flex-end; margin-top: var(--sp-2); }
  .table-cards td.din-accion .btn { flex: 1 1 auto; }
}

/* ───────── Líneas (vista) y totales ───────── */
.din-lineas-ver, .din-originales, .din-pagos { list-style: none; margin: 0; padding: 0; }
.din-lineas-ver > li, .din-originales > li, .din-pagos > li {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-2) 0; border-bottom: 1px solid var(--line);
}
.din-lineas-ver > li > .num { font-weight: 600; white-space: nowrap; }
.din-originales > li { align-items: center; }
.din-pagos { margin-top: var(--sp-3); font-size: var(--fs-sm); }
.din-pagos > li:last-child { border-bottom: 0; }
.din-lv-concepto { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.din-lv-det { color: var(--text-3); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.din-totales { display: flex; flex-direction: column; gap: var(--sp-1); margin-top: var(--sp-3); margin-left: auto; width: 100%; max-width: 360px; }
.din-tot-fila { display: flex; justify-content: space-between; gap: var(--sp-3); color: var(--text-2); font-size: var(--fs-sm); }
.din-tot-fila .num { font-variant-numeric: tabular-nums; }
.din-tot-total { margin-top: var(--sp-1); padding-top: var(--sp-2); border-top: 1px solid var(--line-strong); color: var(--text); font-size: var(--fs-lg); font-weight: 700; }
.din-tot-total .num { font-family: var(--font-num); font-size: var(--fs-xl); font-weight: 600; }
.din-neto { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ───────── Editor de líneas ───────── */
.din-editor { display: flex; flex-direction: column; gap: var(--sp-3); }
.din-lineas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.din-lineas-vacio { padding: var(--sp-3); border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--text-3); font-size: var(--fs-sm); }
.din-linea { padding: var(--sp-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); display: flex; flex-direction: column; gap: var(--sp-2); }
.din-l-head { display: flex; align-items: center; gap: var(--sp-2); }
.din-l-num {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); font-weight: 700; font-variant-numeric: tabular-nums;
}
.din-l-imp-label { margin-left: auto; color: var(--text-3); font-size: var(--fs-sm); }
.din-l-importe { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }
.din-l-quitar { margin-right: -6px; }
.din-l-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.din-l-grid .din-l-concepto { grid-column: 1 / -1; }
@media (min-width: 720px) {
  .din-l-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 0.9fr); }
  .din-l-grid .din-l-concepto { grid-column: auto; }
}

/* ───────── Elegir contrato (modal) ───────── */
.din-opciones { display: flex; flex-direction: column; gap: var(--sp-2); max-height: 280px; overflow-y: auto; }
.din-opcion {
  flex: none; display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); padding: var(--sp-3);
  border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer;
}
.din-opcion:hover { border-color: var(--line-strong); }
.din-opcion:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.din-opcion input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--primary); }
.din-opcion-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.din-opcion-title { font-weight: 650; overflow-wrap: anywhere; }
.din-opcion-sub { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; color: var(--text-3); font-size: var(--fs-sm); }
.din-opcion-total { flex: none; font-weight: 700; }
.din-preview { display: flex; flex-direction: column; gap: var(--sp-2); }
.din-preview:empty { display: none; }
.din-preview-title { font-size: var(--fs-md); font-weight: 650; }

/* ───────── Ficha de factura ───────── */
.din-titulo { display: inline-flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.din-titulo .badge { font-size: var(--fs-xs); letter-spacing: 0; }
.din-ficha { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.din-ficha-main, .din-ficha-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
@media (min-width: 1100px) { .din-ficha { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); } }

/* ───────── Informes ───────── */
.din-anio { display: flex; align-items: center; gap: var(--sp-2); }
.din-anio-num { min-width: 4ch; text-align: center; font-family: var(--font-num); font-size: var(--fs-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.din-informe-grid { align-items: start; }
.din-estados { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.din-estados > li { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.din-detalle { margin-top: var(--sp-3); }
.din-detalle > summary {
  display: inline-flex; align-items: center; min-height: var(--tap); cursor: pointer;
  color: var(--primary); font-weight: 600; list-style-position: inside;
}
.din-detalle[open] > summary { margin-bottom: var(--sp-2); }
.din-tabla-meses .table tbody tr { cursor: pointer; }

/* Barras horizontales (una serie, valor siempre en texto) */
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; gap: 6px var(--sp-3); align-items: center; }
.hbar-label { grid-area: label; display: flex; align-items: center; gap: var(--sp-2); min-width: 0; color: var(--text); font-size: var(--fs-sm); }
.hbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hbar-value { grid-area: value; display: flex; align-items: baseline; gap: var(--sp-2); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar-note { color: var(--text-3); font-size: var(--fs-xs); font-weight: 500; }
.hbar-track { grid-area: track; position: relative; height: 10px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; --pct: 0; }
.hbar-fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--pct) * 1%); background: var(--viz-1); border-radius: 0 4px 4px 0; }

/* ───────── Gráfica de columnas (SVG) ───────── */
.viz { margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.viz-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); color: var(--text-2); font-size: var(--fs-sm); }
.viz-legend li { display: inline-flex; align-items: center; gap: 6px; }
.viz-key { display: inline-block; flex: none; }
.viz-key-bar { width: 12px; height: 12px; border-radius: 3px; background: var(--viz-1); }
.viz-key-line { width: 16px; height: 2px; border-radius: 1px; background: var(--viz-3); }
.viz-key.viz-s1, .viz-tip-key.viz-s1 { background: var(--viz-1); }
.viz-key.viz-s2, .viz-tip-key.viz-s2 { background: var(--viz-2); }
.viz-key.viz-s3, .viz-tip-key.viz-s3 { background: var(--viz-3); }
.viz-plot { position: relative; min-width: 0; }
.viz-canvas { width: 100%; min-height: 120px; }
.viz-svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-grid line { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.viz-grid line.viz-zero { stroke: var(--line-strong); }
.viz-axis { fill: var(--text-3); font-family: var(--font-num); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz-band { fill: var(--surface-3); opacity: 0.7; }
.viz-bar.viz-s1 { fill: var(--viz-1); }
.viz-bar.viz-s2 { fill: var(--viz-2); }
.viz-bar.viz-s3 { fill: var(--viz-3); }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-line.viz-s1 { stroke: var(--viz-1); }
.viz-line.viz-s3 { stroke: var(--viz-3); }
.viz-dot { stroke: var(--surface); stroke-width: 2; }
.viz-dot.viz-s1 { fill: var(--viz-1); }
.viz-dot.viz-s3 { fill: var(--viz-3); }
.viz-hit { fill: transparent; cursor: pointer; outline: none; }
.viz-hit:focus-visible { stroke: var(--focus); stroke-width: 2; }
.viz-tip {
  position: absolute; top: 0; left: var(--x, 0); z-index: 5; pointer-events: none;
  min-width: 150px; max-width: 240px; padding: var(--sp-2) var(--sp-3);
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
}
.viz-tip-title { font-weight: 650; margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: var(--sp-2); }
.viz-tip-row strong { font-variant-numeric: tabular-nums; }
.viz-tip-key { display: inline-block; flex: none; }
.viz-tip-key.viz-key-bar { width: 10px; height: 10px; }
.viz-tip-name { color: var(--text-3); }
.viz-tip-hint { margin-top: 4px; color: var(--text-3); font-size: var(--fs-xs); }

@media (forced-colors: active) {
  .viz-bar, .viz-dot, .hbar-fill, .viz-key { forced-color-adjust: none; }
}
@media print {
  .din-filtros, .din-periodo, .viz-tip { display: none !important; }
}

/* Resumen de Informes: 8 cifras en filas completas (2 en móvil, 4 en PC) en lugar de 7 + 1. */
.stats.din-stats-8 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .stats.din-stats-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
