/* =============================================
   TABLAS COMO TARJETAS (teléfonos ≤600px)
   Cada fila se vuelve una tarjeta apilada y legible, sin scroll horizontal.
   ============================================= */
@media (max-width: 600px) {
  .table-wrapper {
    overflow-x: visible !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  .table-wrapper .table {
    min-width: 0 !important;
    width: 100% !important;
  }
  .table-wrapper .table thead {
    display: none; /* los encabezados se reemplazan por las etiquetas data-label */
  }
  .table-wrapper .table,
  .table-wrapper .table tbody,
  .table-wrapper .table tr,
  .table-wrapper .table td {
    display: block;
    width: 100%;
  }
  .table-wrapper .table tr {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    background: var(--bg-surface);
    border: none;
    border-left: 3px solid var(--border-strong); /* franja de acento; el color se define por tipo */
    border-radius: 4px var(--radius-md) var(--radius-md) 4px;
    box-shadow: none;
    margin-bottom: 0.7rem;
    padding: 0.3rem 1rem;
    overflow: hidden;
  }
  .table-wrapper .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    text-align: right;
    padding: 0.6rem 0 !important;
    border: none !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important; /* divisor sutil */
    background: transparent !important;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
  }
  .table-wrapper .table td:last-child {
    border-bottom: none !important;
  }
  /* ----- Acento de color según el tipo de registro ----- */
  #tablaIngresos tr {
    border-left-color: var(--accent-green);
  }
  #tablaGastos tr {
    border-left-color: var(--accent-red);
  }
  #tablaGastosMensuales tr {
    border-left-color: var(--accent-amber);
  }
  #tablaResumenCerrado tr,
  #tablaResumenProximo tr,
  #tablaCuotasTerminadas tr {
    border-left-color: var(--accent-amber);
  }
  #tablaAhorros tr {
    border-left-color: var(--accent-violet);
  }
  .table-wrapper .table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  .table-wrapper .table td.celda-acciones {
    justify-content: center;
    gap: 0.5rem;
    padding-top: 0.7rem !important;
  }
  .table-wrapper .table td[data-label="Próx. Pago"] {
    justify-content: stretch;
  }
  .table-wrapper .table td[data-label="Próx. Pago"] .btn {
    flex: 1;
  }
}

/* Ícono mobile oculto por defecto en desktop — el @media de abajo lo muestra */
.mov-cat-icon-mobile { display: none; }

/* =============================================
   TARJETA COMPACTA-EXPANDIBLE (mobile ≤600px)
   Solo para Ingresos, Gastos y Ahorros.
   Resumen: Categoría + Monto (línea 1), Fecha + chevron (línea 2).
   Al tocar (.expandida): aparece Descripción + Editar/Borrar.
   ============================================= */
@media (max-width: 600px) {
  #tablaIngresos tr,
  #tablaGastos tr,
  #tablaAhorros tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    position: relative;
    cursor: pointer;
    padding: 0.85rem 1rem;
    min-height: 3.4rem;
    column-gap: 0.75rem;
    row-gap: 0.3rem;
  }
  /* Ocultar etiquetas (data-label::before) en el resumen compacto */
  #tablaIngresos tr td::before,
  #tablaGastos tr td::before,
  #tablaAhorros tr td::before {
    display: none;
  }
  /* ── Flex line-break: fuerza Fecha+Monto a la línea 2 ── */
  #tablaIngresos tr::after,
  #tablaGastos tr::after,
  #tablaAhorros tr::after {
    content: "";
    order: 2;        /* entre Descripción (order 1) y Fecha/Monto (order 3) */
    flex-basis: 100%;
    height: 0;
  }
  /* ── GASTOS / INGRESOS: layout estilo mensuales ── */
  /* Línea 1: ícono categoría + descripción (truncada) + chevron */
  #tablaIngresos td[data-label="Descripción"],
  #tablaGastos td[data-label="Descripción"] {
    order: 1;
    flex: 1 1 100%;
    width: 100% !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-start;
    border-bottom: none !important;
    padding: 0 0 0.4rem 0 !important;
    text-align: left;
    overflow: hidden;
    min-width: 0;
  }
  #tablaIngresos td[data-label="Descripción"] .desc-text,
  #tablaGastos td[data-label="Descripción"] .desc-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
  }
  #tablaIngresos td[data-label="Descripción"]::after,
  #tablaGastos td[data-label="Descripción"]::after {
    content: "▾";
    margin-left: auto;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
    flex-shrink: 0;
  }
  /* Línea 2: Fecha izq + Monto der */
  #tablaIngresos td[data-label="Fecha"],
  #tablaGastos td[data-label="Fecha"] {
    order: 3;
    flex: 1 1 auto;
    width: auto !important;
    justify-content: flex-start;
    border-bottom: none !important;
    padding: 0 !important;
    min-width: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
  }
  #tablaIngresos td[data-label="Monto"],
  #tablaGastos td[data-label="Monto"] {
    order: 3;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    border-bottom: none !important;
    padding: 0 !important;
    font-size: 1rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  /* Categoría oculta en compacto (se muestra al expandir) */
  #tablaIngresos td[data-label="Categoría"],
  #tablaGastos td[data-label="Categoría"] {
    display: none !important;
  }

  /* ── AHORROS: renglón 1 = Fecha + Monto · renglón 2 = Categoría + Meta ──
     Chevron (solo si USD) abre el renglón 3 con el T. Cambio. */
  #tablaAhorros td[data-label="Fecha"] {
    order: 1;
    flex: 1 1 auto;
    width: auto !important;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    justify-content: flex-start;
    border-bottom: none !important;
    padding: 0 !important;
    min-width: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
  }
  /* Chevron de expandir: a la derecha de la fila, centrado verticalmente entre
     los dos renglones (patrón de lista expandible). El tr es position:relative. */
  .mov-chevron-ahorro {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
    pointer-events: none;
  }
  #tablaAhorros tr.expandida .mov-chevron-ahorro {
    transform: translateY(-50%) rotate(180deg);
  }
  /* Espacio a la derecha para que monto/meta no queden bajo el chevron */
  #tablaAhorros tr.movimiento-row { padding-right: 2rem !important; }
  #tablaAhorros td[data-label="Monto"] {
    order: 2;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    border-bottom: none !important;
    padding: 0 !important;
    font-size: 1.05rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  /* line-break tras renglón 1 */
  #tablaAhorros tr::after {
    content: "";
    order: 3;
    flex-basis: 100%;
    height: 0;
  }
  #tablaAhorros td[data-label="Categoría"] {
    order: 4;
    flex: 1 1 auto;
    width: auto !important;
    justify-content: flex-start;
    border-bottom: none !important;
    padding: 0.3rem 0 0 0 !important;
    min-width: 0;
  }
  #tablaAhorros td[data-label="Categoría"]::before { display: none; }
  #tablaAhorros td[data-label="Fecha"]::before { display: none; }
  #tablaAhorros td[data-label="Monto"]::before { display: none; }
  #tablaAhorros td[data-label="Meta"] {
    order: 4;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    margin-left: auto;
    border-bottom: none !important;
    padding: 0.3rem 0 0 0 !important;
    min-width: 0;
  }
  #tablaAhorros td[data-label="Meta"]::before { display: none; }
  /* Descripción, T. Cambio y acciones: ocultas en el resumen compacto */
  #tablaAhorros td[data-label="Descripción"],
  #tablaAhorros td[data-label="T. Cambio"],
  #tablaIngresos td.celda-acciones,
  #tablaGastos td.celda-acciones,
  #tablaAhorros td.celda-acciones {
    display: none;
  }
  /* ── Al expandir: descripción completa ── */
  #tablaIngresos tr.expandida td[data-label="Descripción"] .desc-text,
  #tablaGastos tr.expandida td[data-label="Descripción"] .desc-text {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  /* Al expandir: rotar chevron */
  #tablaIngresos tr.expandida td[data-label="Descripción"]::after,
  #tablaGastos tr.expandida td[data-label="Descripción"]::after {
    transform: rotate(180deg);
  }
  /* Al expandir (Ahorros): renglón 3 = T. Cambio (izq) + botones (der), misma línea.
     El line-break ::after (order 3) ya separó del renglón 2, y un line-break antes
     del renglón 3 lo logramos con margin-top en T. Cambio + flex-wrap del tr. */
  #tablaAhorros tr.expandida td[data-label="T. Cambio"] {
    display: flex;
    order: 6;
    flex: 1 1 auto;
    width: auto !important;
    justify-content: flex-start;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    border-bottom: none !important;
    margin-top: 0.4rem;
    padding-top: 0.55rem !important;
    text-align: left;
    font-size: 0.85rem;
  }
  #tablaAhorros tr.expandida td[data-label="T. Cambio"]::before {
    display: none;
  }
  /* Fondo de selección al expandir */
  #tablaIngresos tr.expandida,
  #tablaGastos tr.expandida,
  #tablaAhorros tr.expandida {
    background: var(--bg-hover) !important;
  }
  /* Los td deben permanecer transparentes (Bootstrap inyecta --bs-table-* que pisamos) */
  #tablaIngresos tr.expandida td,
  #tablaGastos tr.expandida td,
  #tablaAhorros tr.expandida td {
    background: transparent !important;
    --bs-table-bg: transparent;
    --bs-table-accent-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: transparent;
  }
  /* Ícono de categoría en descripción: visible en mobile */
  .mov-cat-icon-mobile {
    display: inline-flex;
    flex-shrink: 0;
  }
  /* Al expandir (Ahorros): botones editar/borrar en el renglón 3, a la DERECHA,
     en la misma línea que el T. Cambio. */
  #tablaAhorros tr.expandida td.celda-acciones {
    display: flex;
    order: 7;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.4rem;
    padding-top: 0.55rem !important;
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
  }
  /* line-break antes del renglón 3 (T.Cambio + acciones) */
  #tablaAhorros tr.expandida::before {
    content: "";
    order: 5;
    flex-basis: 100%;
    height: 0;
  }
  /* Expandida: line-break antes de la línea 3 (categoría + botones) */
  #tablaIngresos tr.expandida::before,
  #tablaGastos tr.expandida::before {
    content: "";
    order: 4;
    flex-basis: 100%;
    height: 0;
  }
  /* Línea 3 — categoría (nombre, sin ícono) a la izquierda */
  #tablaIngresos tr.expandida td[data-label="Categoría"],
  #tablaGastos tr.expandida td[data-label="Categoría"] {
    display: flex !important;
    order: 5;
    flex: 1 1 auto;
    width: auto !important;
    align-items: center;
    gap: 0.4rem;
    border-bottom: none !important;
    border-top: 1px solid var(--border) !important;
    margin-top: 0.5rem;
    padding: 0.5rem 0 0 0 !important;
    font-size: 0.85rem;
    color: var(--text-secondary);
  }
  /* Ocultar el ícono bubble de categoría al expandir (ya está arriba en descripción) */
  #tablaIngresos tr.expandida td[data-label="Categoría"] .cat-icon-bubble,
  #tablaGastos tr.expandida td[data-label="Categoría"] .cat-icon-bubble {
    display: none !important;
  }
  /* Sin la burbuja, el chip (fondo de píldora) no debe pintar padding vacío
     de más a la izquierda: colapsar a fondo transparente, solo queda el texto. */
  #tablaIngresos tr.expandida td[data-label="Categoría"] .movimiento-cat--chip,
  #tablaGastos tr.expandida td[data-label="Categoría"] .movimiento-cat--chip {
    background: transparent;
    padding: 0;
  }
  /* Línea 3 — botones a la derecha, alineados con la categoría */
  #tablaIngresos tr.expandida td.celda-acciones,
  #tablaGastos tr.expandida td.celda-acciones {
    display: flex !important;
    order: 6;
    flex: 0 0 auto;
    width: auto !important;
    align-items: center;
    border-top: 1px solid var(--border) !important;
    border-bottom: none !important;
    margin-top: 0.5rem;
    padding: 0.5rem 0 0 0 !important;
    justify-content: flex-end;
    gap: 0.25rem;
  }
  /* Botones touch 40×40 (editar/borrar/candado) */
  #tablaIngresos tr.expandida td.celda-acciones .btn-icon-ghost,
  #tablaGastos tr.expandida td.celda-acciones .btn-icon-ghost {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.05rem;
  }
}

/* =============================================
   TARJETA COMPACTA-EXPANDIBLE — Cuotas y Mensuales (mobile ≤600px)
   Botón de acción (Pagar / A Gastos) siempre visible en el resumen.
   ============================================= */
@media (max-width: 600px) {
  /* NOTA: #tablaResumenCerrado se excluye de este bloque porque ahora usa
     .vr-lineas-compactas (layout propio en components.css). */
  #tablaResumenProximo tr,
  #tablaCuotasTerminadas tr {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    position: relative;
    cursor: pointer;
    padding: 0.8rem 1rem;
    padding-right: 2.2rem;
    row-gap: 0.45rem;
    column-gap: 0.6rem;
    width: 100%;
    box-sizing: border-box;
  }
  /* Chevron arriba a la derecha (tablaResumenCerrado usa .vr-lineas-compactas,
     que muestra todo sin expandir, así que no lleva chevron) */
  #tablaResumenProximo tr::after,
  #tablaCuotasTerminadas tr::after {
    content: "▾";
    position: absolute;
    top: 0.7rem;
    right: 1rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
  }
  /* Fondo de selección al expandir */
  #tablaResumenCerrado tr.expandida,
  #tablaResumenProximo tr.expandida,
  #tablaCuotasTerminadas tr.expandida {
    background: var(--bg-hover) !important;
  }
  /* Los td deben permanecer transparentes */
  #tablaResumenCerrado tr.expandida td,
  #tablaResumenProximo tr.expandida td,
  #tablaCuotasTerminadas tr.expandida td {
    background: transparent !important;
    --bs-table-bg: transparent;
    --bs-table-accent-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: transparent;
  }
  #tablaResumenProximo tr.expandida::after,
  #tablaCuotasTerminadas tr.expandida::after {
    transform: rotate(180deg);
  }
  /* Reset general de celdas en estas tablas (tablaResumenCerrado excluida: usa
     .vr-lineas-compactas) */
  #tablaResumenProximo td,
  #tablaCuotasTerminadas td {
    border-bottom: none !important;
    padding: 0 !important;
    width: auto !important;
    display: flex;
  }
  #tablaResumenCerrado tr td::before,
  #tablaResumenProximo tr td::before,
  #tablaCuotasTerminadas tr td::before {
    display: none;
  }

  /* ---------- RESUMEN CERRADO / PRÓXIMO ---------- */

  /* Separador invisible entre línea 1 y línea 2 */
  #tablaResumenCerrado tr::before,
  #tablaResumenProximo tr::before {
    content: "";
    order: 2;
    flex-basis: 100%;
    height: 0;
  }

  /* Línea 1: Fecha (izq, chica) */
  #tablaResumenCerrado td[data-label="Fecha"],
  #tablaResumenProximo td[data-label="Fecha"] {
    order: 1;
    flex: 0 0 auto;
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
  }

  /* Línea 1: Descripción (crece, truncada) */
  #tablaResumenCerrado td[data-label="Descripción"],
  #tablaResumenProximo td[data-label="Descripción"] {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.88rem;
    color: var(--text-primary);
    padding-right: 1.5rem !important;
  }

  /* Línea 2: Progreso (izq) */
  #tablaResumenCerrado td[data-label="Progreso"],
  #tablaResumenProximo td[data-label="Progreso"] {
    order: 3;
    flex: 0 0 auto;
    font-size: 0.82rem;
  }

  /* Línea 2: Monto (extremo derecha, destacado) */
  #tablaResumenCerrado td[data-label="Monto"],
  #tablaResumenProximo td[data-label="Monto"] {
    order: 3;
    flex: 1 1 auto;
    font-size: 1.05rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    text-align: right !important;
    justify-content: flex-end;
  }

  /* Categoría: oculta en compacto */
  #tablaResumenCerrado td[data-label="Categoría"],
  #tablaResumenProximo td[data-label="Categoría"] {
    display: none;
  }

  /* Acciones: ocultas en compacto */
  #tablaResumenCerrado td.celda-acciones,
  #tablaResumenProximo td.celda-acciones {
    display: none;
  }

  /* Al expandir: Categoría */
  #tablaResumenCerrado tr.expandida td[data-label="Categoría"],
  #tablaResumenProximo tr.expandida td[data-label="Categoría"] {
    display: flex;
    order: 4;
    flex: 1 1 auto;
    font-size: 0.82rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    margin-top: 0.35rem;
    padding-top: 0.5rem !important;
  }

  /* Al expandir: Acciones */
  #tablaResumenCerrado tr.expandida td.celda-acciones,
  #tablaResumenProximo tr.expandida td.celda-acciones {
    display: flex;
    order: 4;
    flex: 0 0 auto;
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    margin-top: 0.35rem;
    padding-top: 0.5rem !important;
    justify-content: flex-end;
  }

  /* ---------- CUOTAS TERMINADAS ---------- */

  /* Flex line-break invisible entre línea 1 y línea 2 */
  #tablaCuotasTerminadas tr::before {
    content: "";
    order: 4;
    flex-basis: 100%;
    height: 0;
  }

  /* Línea 1: Fecha (izq, crece) */
  #tablaCuotasTerminadas td[data-label="Fecha"] {
    order: 1;
    flex: 1 1 auto;
    width: auto !important;
    justify-content: flex-start;
    font-size: 0.72rem;
    color: var(--text-muted);
  }

  /* Línea 1: Valor de cuota (destacado) */
  #tablaCuotasTerminadas td[data-label="Valor"] {
    order: 2;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    font-size: 1.05rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  /* Línea 1: Cuotas X/X (extremo derecha, chico) */
  #tablaCuotasTerminadas td[data-label="Cuotas"] {
    order: 3;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-end;
    font-size: 0.82rem;
  }

  /* Línea 2: Badge tarjeta */
  #tablaCuotasTerminadas td[data-label="Tarjeta"] {
    order: 5;
    flex: 0 0 auto;
    width: auto !important;
    justify-content: flex-start;
  }

  /* Línea 2: Descripción (llena el espacio restante, truncada) */
  #tablaCuotasTerminadas td[data-label="Descripción"] {
    order: 6;
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.88rem;
    color: var(--text-primary);
    padding-right: 1.5rem !important;
  }

  /* Oculto en resumen */
  #tablaCuotasTerminadas td[data-label="Total"],
  #tablaCuotasTerminadas td.celda-acciones {
    display: none;
  }

  /* Al expandir: Total */
  #tablaCuotasTerminadas tr.expandida td[data-label="Total"] {
    display: flex;
    order: 7;
    flex-basis: 100%;
    width: 100%;
    justify-content: space-between;
    font-size: 0.82rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    margin-top: 0.35rem;
    padding-top: 0.5rem !important;
  }
  #tablaCuotasTerminadas tr.expandida td[data-label="Total"]::before {
    display: inline;
  }

  /* Al expandir: botón Borrar */
  #tablaCuotasTerminadas tr.expandida td.celda-acciones {
    display: flex;
    order: 8;
    flex-basis: 100%;
    justify-content: center;
    margin-top: 0.4rem;
  }

}

/* Mensuales: fila expandible (estilos desktop; el layout mobile está en modules.css) */
.gm-expand-row { display: none; }
/* El ícono de categoría inline solo se usa en mobile (línea 1); en desktop hay columna propia */
.gm-cat-icon { display: none; }

.gm-expand-td {
  padding: 0 !important;
  border-top: none !important;
}
.gm-expand-body {
  padding: 0.75rem 1rem 1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
