/* ============================================================
   AutoDeal360 — Módulo Consulta de OT (v2)
   Identidad AD360 estándar (igual que clientes_listado.css):
   navy #20376A / azul #004B94 / acento amarillo #FECA05
   ============================================================
   NOTA: este archivo remodela SOLO la tabla principal, filtros,
   estadísticas y paginación. El modal de detalle de OT (repuestos,
   historial, PDF, etc.) sigue viviendo en ot.css y no se toca aquí.
   ============================================================ */

/* ── Layout sticky: filtros fijos, scroll solo en tabla ── */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    padding: 15px;
    box-sizing: border-box;
    background: #f5f7fa;
    font-family: 'Roboto', sans-serif;
}

.module-header {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.module-title {
    font-size: 22px;
    color: #004B94;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}
.module-title i { color: #FECA05; }

.card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 20px;
    margin-bottom: 0;
}

/* ── FILTROS ── */
.filters {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.filters select,
.filters input[type="date"] {
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: #2d3748;
    background: #fff;
    height: 42px;
    box-sizing: border-box;
    transition: all .15s;
}
.filters select:focus,
.filters input[type="date"]:focus {
    outline: none;
    border-color: #004B94;
    box-shadow: 0 0 0 3px rgba(0,75,148,.12);
}

.date-filter {
    display: flex;
    align-items: center;
    gap: 10px;
}
#customDateRange {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Búsqueda — mismo patrón que clientes (ícono a la izquierda vía ::before) */
.search-container {
    position: relative;
    flex-grow: 1;
    min-width: 220px;
    max-width: 420px;
}
.search-container::before {
    content: '\f002';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 14px;
    pointer-events: none;
}
#searchInput {
    padding: 0 14px 0 35px;
    width: 100%;
    height: 42px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}
#searchInput:focus {
    outline: none;
    border-color: #004B94;
    box-shadow: 0 0 0 3px rgba(0,75,148,.12);
}
.search-icon { display: none; } /* el ícono real lo pinta el ::before de arriba */

/* Botón Actualizar — estándar de botón secundario AD360 */
#refreshBtn {
    padding: 0 20px;
    height: 42px;
    background-color: #fff;
    border: 1px solid #ddd;
    color: #495057;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all .15s;
    flex-shrink: 0;
}
#refreshBtn:hover { background: #f8f9fa; border-color: #004B94; color: #004B94; }
#refreshBtn i { transition: transform .3s; }
#refreshBtn:hover i { transform: rotate(180deg); }

/* ── ESTADÍSTICAS ── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin: 4px 0 16px;
    flex-shrink: 0;
}

.stat-card {
    background: white;
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    text-align: center;
    border: 1px solid #e9ecef;
    transition: all .2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #004B94;
    margin-bottom: 4px;
    display: block;
}

.stat-label {
    font-size: 12px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 500;
}

/* ── CONTROLES DE TABLA / PAGINACIÓN ── */
.table-controls {
    flex-shrink: 0;
    padding-bottom: 14px;
    border-bottom: 1px solid #e9ecef;
}

.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.rows-per-page {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #495057;
}
.rows-per-page select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    font-family: inherit;
}

.pagination-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}
.pagination-buttons button {
    padding: 6px 10px;
    min-width: 34px;
    height: 34px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    color: #495057;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.pagination-buttons button:hover:not(:disabled) {
    background: #eef5fc;
    border-color: #004B94;
    color: #004B94;
}
.pagination-buttons button:disabled { opacity: .5; cursor: not-allowed; }

#pageInfo { font-size: 13px; color: #495057; margin: 0 6px; min-width: 95px; text-align: center; }

/* ── TABLA PRINCIPAL ── */
.table-wrapper {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e9ecef;
    margin-top: 14px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-container {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: white;
    width: 100%;
}

#ordersTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

#ordersTable thead th {
    background: #004B94;
    color: white;
    padding: 12px 14px;
    text-align: left;
    position: sticky;
    top: 0;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: .5px;
    white-space: nowrap;
    z-index: 2;
}
#ordersTable thead th.sortable { cursor: pointer; user-select: none; }
#ordersTable thead th.sortable:hover { background: #20376A; }
#ordersTable thead th.sorted-asc::after  { content: ' ▲'; font-size: 10px; }
#ordersTable thead th.sorted-desc::after { content: ' ▼'; font-size: 10px; }

#ordersTable td {
    padding: 10px 14px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #2d3748;
}

#ordersTable tbody tr:nth-child(even) { background-color: #f8f9fa; }
#ordersTable tbody tr:hover           { background-color: #fffbea; }

/* Anchos de columna (16 columnas: # + 14 datos + acciones) */
#ordersTable th:nth-child(1),  #ordersTable td:nth-child(1)  { width: 46px;  text-align: center; }
#ordersTable th:nth-child(2),  #ordersTable td:nth-child(2)  { width: 90px;  }
#ordersTable th:nth-child(3),  #ordersTable td:nth-child(3)  { width: 90px;  }
#ordersTable th:nth-child(4),  #ordersTable td:nth-child(4)  { width: 100px; }
#ordersTable th:nth-child(5),  #ordersTable td:nth-child(5)  { width: 110px; }
#ordersTable th:nth-child(6),  #ordersTable td:nth-child(6)  { width: 65px;  text-align: center; }
#ordersTable th:nth-child(7),  #ordersTable td:nth-child(7)  { width: 140px; }
#ordersTable th:nth-child(8),  #ordersTable td:nth-child(8)  { width: 75px;  text-align: right; }
#ordersTable th:nth-child(9),  #ordersTable td:nth-child(9)  { width: 100px; }
#ordersTable th:nth-child(10), #ordersTable td:nth-child(10) { width: 170px; }
#ordersTable th:nth-child(11), #ordersTable td:nth-child(11) { width: 95px;  text-align: right; }
#ordersTable th:nth-child(12), #ordersTable td:nth-child(12) { width: 130px; }
#ordersTable th:nth-child(13), #ordersTable td:nth-child(13) { width: 100px; }
#ordersTable th:nth-child(14), #ordersTable td:nth-child(14) { width: 110px; }
#ordersTable th:nth-child(15), #ordersTable td:nth-child(15) { width: 100px; }
#ordersTable th:nth-child(16), #ordersTable td:nth-child(16) { width: 190px; text-align: center; white-space: normal; }

/* Enlace clickeable del Nro OT (usado por consultav2.js) */
.ot-link {
    color: #004B94;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}
.ot-link:hover { color: #20376A; text-decoration: underline; }

/* ── BADGES DE ESTADO (paleta AD360, reemplaza los colores saturados de ot.css) ── */
.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
    color: #fff;
}
.status-citado          { background: #004B94; }
.status-taller          { background: #198754; }
.status-proceso         { background: #f59e0b; }
.status-cerrado         { background: #6c757d; }
.status-cerrado_pagado  { background: #20376A; }
.status-cerrado_cobrar  { background: #dc3545; }

/* ── ACCIONES EN TABLA ── */
.acciones-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 3px;
    flex-wrap: nowrap;
}

.btn-accion {
    background: none;
    border: none;
    padding: 6px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    border-radius: 5px;
    color: #495057;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.btn-accion:hover { background: #eef5fc; color: #004B94; transform: translateY(-1px); }
.btn-accion i { font-size: 13px; }

/* Colores de acento al hover, por acción (igual criterio que ot.css original) */
.btn-accion[title="Editar OT"]:hover        { color: #fd7e14; background: #fff4e8; }
.btn-accion[title="Editar Pedido"]:hover    { color: #004B94; background: #eef5fc; }
.btn-accion[title="Abonos"]:hover           { color: #198754; background: #eafaf1; }
.btn-accion[title="Aceite"]:hover           { color: #f59e0b; background: #fff8e8; }
.btn-accion[title="Visto Bueno"]:hover      { color: #0dcaf0; background: #e8fbff; }
.btn-accion[title="Correctivos"]:hover      { color: #6f42c1; background: #f3ecfc; }
.btn-accion[title="Check Engine"]:hover     { color: #dc3545; background: #fdecec; }

/* Estado vacío de la tabla */
#ordersTable td[colspan] {
    text-align: center;
    padding: 40px !important;
    color: #a0aec0;
    white-space: normal;
}

/* ── LOADING ── */
.loading {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,.85);
    display: none;
    justify-content: center; align-items: center;
    z-index: 5000;
}
.loading.show, .loading[style*="flex"] { display: flex; }

.loading p { margin-top: 10px; color: #495057; font-size: 14px; }

.spinner {
    border: 4px solid rgba(0,75,148,.15);
    border-top: 4px solid #004B94;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: ad360-spin 1s linear infinite;
    margin: 0 auto 10px;
}

.spinner.small {
    width: 20px;
    height: 20px;
    border-width: 2px;
    margin: 0 auto 10px;
}

@keyframes ad360-spin {
    to { transform: rotate(360deg); }
}

/* ── RESPONSIVE ── */
@media (max-width: 992px) {
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
    .filters { flex-direction: column; align-items: stretch; }
    .search-container { max-width: none; }
    .stats-bar { grid-template-columns: 1fr; }
    .pagination-controls { flex-direction: column; align-items: stretch; }
}