/* =============================================
   PILAY - Tabla de Datos
   ============================================= */

/* ===== TABLE WRAPPER ===== */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ===== TABLE HEADER (toolbar) ===== */
.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.table-title {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== TABLE CONTAINER ===== */
.table-container {
    overflow-x: auto;
    /* Barra de scroll siempre visible para dejar claro que es scrolleable */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.table-container::-webkit-scrollbar {
    height: 6px;
}
.table-container::-webkit-scrollbar-track {
    background: var(--bg-main);
}
.table-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* ===== DATA TABLE ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    /* Mínimo para evitar que aplaste columnas */
    min-width: 1100px;
}

/* ── Headers ── */
.data-table th {
    background: var(--pilay-primary-dark);
    color: white;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 0.875rem;
    white-space: nowrap;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
    border-right: 1px solid rgba(255,255,255,0.08);
}

.data-table th:last-child {
    border-right: none;
}

/* ── Celdas ── */
.data-table td {
    padding: 0.5rem 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--text-primary);
}

/* ── Hover / estados de fila ── */
.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: #f0f5ff;
}

.data-table tbody tr.has-error {
    background: var(--error-bg);
}

.data-table tbody tr.has-error:hover {
    background: #fecaca;
}

.data-table tbody tr.has-warning {
    background: var(--warning-bg);
}

.data-table tbody tr.has-warning:hover {
    background: #fde68a;
}

.data-table tbody tr.has-duplicate {
    background: #fdf4ff;
}

.data-table tbody tr.has-duplicate:hover {
    background: #f3e8ff;
}

/* ===== EDITABLE CELLS ===== */
.editable-cell {
    padding: 0.25rem 0.375rem !important;
}

.editable-cell input,
.editable-cell select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);   /* fuente normal, no mono */
    font-size: 0.8rem;
    background: transparent;
    color: var(--text-primary);
    transition: all var(--transition-fast);
    min-width: 0;
}

.editable-cell input:hover,
.editable-cell select:hover {
    background: rgba(0, 75, 238, 0.04);
    border-color: var(--border-color);
}

.editable-cell input:focus,
.editable-cell select:focus {
    outline: none;
    border-color: var(--pilay-primary);
    background: white;
    box-shadow: 0 0 0 2px rgba(0, 75, 238, 0.12);
}

.editable-cell input[type="number"] {
    text-align: right;
}

.editable-cell input[type="date"] {
    min-width: 120px;
}

.editable-cell select {
    cursor: pointer;
}

/* ===== CELL BADGES (confianza) ===== */
.cell-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.45rem;
    border-radius: var(--radius-full);
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
}

.cell-badge.high {
    background: var(--success-bg);
    color: var(--success-text);
}

.cell-badge.medium {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.cell-badge.low {
    background: var(--error-bg);
    color: var(--error-text);
}

/* ===== CELL STATUS (OK / Revisar) ===== */
.cell-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.cell-status .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cell-status.valid         { color: var(--success-text); }
.cell-status.valid .dot    { background: var(--success); }
.cell-status.error         { color: var(--error-text); }
.cell-status.error .dot    { background: var(--error); }
.cell-status.warning       { color: var(--warning-text); }
.cell-status.warning .dot  { background: var(--warning); }
.cell-status.duplicate     { color: #7c3aed; }
.cell-status.duplicate .dot { background: #8b5cf6; }

/* ===== SORTABLE HEADERS ===== */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    background: #002a7a;
}

.data-table th.sorted {
    background: #003599;
}

.sort-icon {
    font-style: normal;
    font-size: 0.7rem;
    margin-left: 4px;
    opacity: 0.6;
}

.data-table th.sorted .sort-icon {
    opacity: 1;
}

/* ===== TABLE FILTER INPUT ===== */
.table-filter-input {
    height: 32px;
    padding: 0 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.82rem;
    color: var(--text-primary);
    background: var(--bg-card);
    min-width: 200px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.table-filter-input:focus {
    outline: none;
    border-color: var(--pilay-primary);
    box-shadow: 0 0 0 2px rgba(0, 75, 238, 0.12);
}

.table-filter-input::placeholder {
    color: var(--text-muted);
}

/* ===== TOTALS ROW (tfoot) ===== */
.totals-row td {
    background: var(--pilay-primary-dark);
    color: white;
    font-weight: 600;
    font-size: 0.78rem;
    padding: 0.6rem 0.875rem;
    border-top: 2px solid rgba(255,255,255,0.15);
    position: sticky;
    bottom: 0;
}

.totals-label {
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.68rem;
    opacity: 0.85;
}

.totals-value {
    text-align: right;
    font-size: 0.85rem;
    font-weight: 700;
}

/* ===== ROW ACTIONS ===== */
.row-action-btn {
    background: none;
    border: none;
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
    font-size: 0.875rem;
    line-height: 1;
}

.row-action-btn:hover {
    background: var(--error-bg);
    color: var(--error);
}

.row-action-btn.preview:hover {
    background: var(--info-bg);
    color: var(--pilay-primary);
}

/* ===== EMPTY STATE ===== */
.table-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.table-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.table-empty h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.table-empty p {
    font-size: 0.875rem;
    margin-bottom: 0;
}

/* ===== COLUMN WIDTHS ===== */
/* Anchos pensados para que el contenido AFIP quepa sin cortarse */
.col-status     { width: 75px; }
.col-proveedor  { min-width: 220px; }
.col-cuit       { min-width: 135px; white-space: nowrap; }
.col-tipo       { width: 65px; text-align: center; }
.col-numero     { min-width: 145px; white-space: nowrap; }
.col-fecha      { min-width: 125px; }
.col-monto      { min-width: 115px; }
.col-confianza  { width: 85px; text-align: center; }
.col-cliente    { min-width: 210px; }
.col-codigo     { min-width: 90px; }
.col-referencia { min-width: 140px; }
.col-actions    { width: 48px; text-align: center; }

/* Centramos columnas de tipo y confianza */
.col-tipo input,
.col-tipo select {
    text-align: center;
}

/* ===== CHECKBOX COLUMN ===== */
.col-check {
    width: 36px;
    text-align: center;
    padding: 0.5rem 0.25rem !important;
}

.col-check input[type="checkbox"],
.row-checkbox {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--pilay-primary);
}

/* ===== BULK DELETE BAR ===== */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    background: #eff6ff;
    border-bottom: 1px solid #bfdbfe;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-size: 0.85rem;
    color: var(--pilay-primary);
    animation: fadeIn 0.2s ease;
}

/* ===== SOURCE SNIPPET HINT ===== */
.cell-inner {
    display: flex;
    align-items: center;
    gap: 2px;
    position: relative;
}

.cell-inner input,
.cell-inner select {
    flex: 1;
    min-width: 0;
}

.field-src-btn {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    font-size: 0.55rem;
    color: var(--pilay-primary);
    opacity: 0.35;
    cursor: help;
    line-height: 14px;
    text-align: center;
    border-radius: 50%;
    border: 1px solid currentColor;
    transition: opacity var(--transition-fast);
    font-style: normal;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.field-src-btn:hover { opacity: 1; }

.field-src-btn::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.4rem 0.6rem;
    border-radius: 5px;
    font-size: 0.7rem;
    white-space: pre-wrap;
    max-width: 260px;
    min-width: 120px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.15s;
    pointer-events: none;
    z-index: 9999;
    font-family: 'JetBrains Mono', monospace;
    font-style: normal;
    text-align: left;
    line-height: 1.4;
    word-break: break-all;
}

.field-src-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ===== AUTO-CORRECTION BADGE ===== */
.field-autocorr {
    flex-shrink: 0;
    font-size: 0.6rem;
    opacity: 0.7;
    cursor: help;
    title: 'Auto-corregido';
}

/* ===== ANOMALY BADGE ===== */
.cell-anomalia {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: help;
}

.cell-anomalia.alto {
    background: #fef2f2;
    color: #b91c1c;
}

.cell-anomalia.bajo {
    background: #f0fdf4;
    color: #15803d;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .data-table {
        font-size: 0.78rem;
    }

    .data-table th {
        padding: 0.625rem 0.625rem;
        font-size: 0.65rem;
    }

    .data-table td {
        padding: 0.375rem 0.5rem;
    }
}
