/* Custom Styles for MR Repuestos */

:root {
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #0dcaf0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
}

/* Login Page */
#login-view {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

#login-view .card {
    border: none;
    border-radius: 15px;
}

/* Navbar */
.navbar-brand {
    font-weight: bold;
    font-size: 1.5rem;
}

.nav-link {
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

/* Product Search Dropdown */
.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 2px;
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.search-result-item:hover {
    background-color: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

.result-code {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 600;
}

.result-name {
    font-size: 0.95rem;
    color: #212529;
    margin: 2px 0;
}

.result-price {
    font-size: 0.85rem;
    color: #0d6efd;
    font-weight: 600;
}

.no-results {
    padding: 15px;
    text-align: center;
    color: #6c757d;
    font-size: 0.9rem;
}

/* Numeric Input Alignment */
input[type="number"],
.text-end {
    text-align: right !important;
}

table td:has(input[type="number"]),
table th:nth-child(3), /* Cantidad */
table th:nth-child(4), /* Precio Unit. */
table th:nth-child(5), /* Subtotal */
table th:nth-child(7), /* Total */
table td:nth-child(3),
table td:nth-child(4),
table td:nth-child(5),
table td:nth-child(7) {
    text-align: right !important;
}

/* Asegurar que columnas de totales se alineen a la derecha */
.total-value,
.totals-row span {
    text-align: right;
    display: inline-block;
}

/* Cards */
.stat-card {
    border-left: 4px solid;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.stat-card.primary {
    border-left-color: var(--primary-color);
}

.stat-card.success {
    border-left-color: var(--success-color);
}

.stat-card.warning {
    border-left-color: var(--warning-color);
}

.stat-card.danger {
    border-left-color: var(--danger-color);
}

.stat-card .stat-icon {
    font-size: 3rem;
    opacity: 0.3;
}

/* Tables */
.table-actions {
    white-space: nowrap;
}

.table-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    margin: 0 2px;
}

/* Badges */
.badge {
    padding: 0.5em 0.75em;
    font-weight: 500;
}

/* Buttons */
.btn {
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

/* DataTables Custom */
.dataTables_wrapper .dataTables_filter input {
    border-radius: 20px;
    padding: 0.375rem 1rem;
}

.dataTables_wrapper .dataTables_length select {
    border-radius: 5px;
}

/* ========================================
   GLOBAL TABLE ALIGNMENT FIX
   Corrección de alineación thead/tbody
   ======================================== */

/* Reglas base para todas las tablas */
table,
table.table,
table.dataTable,
table.table-corporate,
table.table-sales {
  width: 100% !important;
  table-layout: fixed !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

/* Contenedores de tabla con scroll */
.table-responsive,
.dataTables_wrapper,
.sales-table-container,
.purchases-table-container,
.suppliers-table-container,
.customers-table-container,
.products-table-container,
.warehouses-table-container,
.categories-table-container,
.inquiries-table-container,
.inventory-table-container,
.reports-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  position: relative;
}

/* Forzar ancho 100% en tabla dentro de DataTables */
.dataTables_wrapper table,
.dataTables_wrapper table.dataTable {
  width: 100% !important;
  margin: 0 !important;
}

/* Alineación consistente thead */
table thead,
table.dataTable thead,
table.table-corporate thead,
table.table-sales thead {
  width: 100%;
  display: table-header-group;
}

table thead tr,
table.dataTable thead tr,
table.table-corporate thead tr,
table.table-sales thead tr {
  width: 100%;
  display: table-row;
}

table thead th,
table.dataTable thead th,
table.table-corporate thead th,
table.table-sales thead th {
  display: table-cell;
  box-sizing: border-box;
  padding: 1rem !important;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Alineación consistente tbody */
table tbody,
table.dataTable tbody,
table.table-corporate tbody,
table.table-sales tbody {
  width: 100%;
  display: table-row-group;
}

table tbody tr,
table.dataTable tbody tr,
table.table-corporate tbody tr,
table.table-sales tbody tr {
  width: 100%;
  display: table-row;
}

table tbody td,
table.dataTable tbody td,
table.table-corporate tbody td,
table.table-sales tbody td {
  display: table-cell;
  box-sizing: border-box;
  padding: 1rem !important;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Prevenir desalineación por sorting de DataTables */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
  padding-right: 30px !important;
}

table.dataTable thead th.sorting::before,
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::before,
table.dataTable thead th.sorting_asc::after,
table.dataTable thead th.sorting_desc::before,
table.dataTable thead th.sorting_desc::after {
  right: 8px;
  opacity: 0.3;
}

/* Responsive - mantener alineación en pantallas pequeñas */
@media screen and (max-width: 767px) {
  table thead th,
  table tbody td,
  table.dataTable thead th,
  table.dataTable tbody td {
    padding: 0.75rem 0.5rem !important;
    font-size: 0.875rem;
    min-width: 80px;
  }
  
  .table-responsive {
    border: 1px solid #dee2e6;
    border-radius: 8px;
  }
}

@media screen and (max-width: 575px) {
  table thead th,
  table tbody td,
  table.dataTable thead th,
  table.dataTable tbody td {
    padding: 0.5rem 0.375rem !important;
    font-size: 0.8125rem;
    min-width: 70px;
  }
}

/* Anchos específicos para columnas comunes */
table th:has(.btn-action),
table td:has(.btn-action),
table th.actions-column,
table td.actions-column {
  width: 120px;
  min-width: 120px;
  max-width: 120px;
}

table th.status-column,
table td.status-column {
  width: 130px;
  min-width: 130px;
  max-width: 130px;
}

table th.date-column,
table td.date-column {
  width: 110px;
  min-width: 110px;
  max-width: 110px;
}

table th.number-column,
table td.number-column {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  text-align: right;
}

/* Modal */
.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #0056b3 100%);
    color: white;
}

.modal-header .btn-close {
    filter: brightness(0) invert(1);
}

/* Forms */
.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Loading Spinner */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

/* Stock Status */
.stock-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

.stock-status.normal {
    background-color: #d1e7dd;
    color: #0f5132;
}

.stock-status.low {
    background-color: #fff3cd;
    color: #664d03;
}

.stock-status.out {
    background-color: #f8d7da;
    color: #842029;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    margin-bottom: 2rem;
}

/* Responsive */
@media (max-width: 1200px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 991px) {
    .navbar-brand {
        font-size: 1.3rem;
    }
    
    .navbar-collapse {
        margin-top: 1rem;
    }
    
    .stat-card .stat-icon {
        font-size: 2.5rem;
    }
    
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-xl {
        max-width: calc(100% - 1rem);
    }
}

@media (max-width: 768px) {
    .navbar-brand {
        font-size: 1.2rem;
    }
    
    .stat-card .stat-icon {
        font-size: 2rem;
    }
    
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .table-actions {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .table-actions .btn {
        width: 100%;
        margin: 0;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
}

@media (max-width: 576px) {
    .navbar-brand {
        font-size: 1rem;
    }
    
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .form-control,
    .form-select {
        font-size: 0.875rem;
    }
    
    .modal-header,
    .modal-footer {
        padding: 0.75rem;
    }
    
    .table {
        font-size: 0.75rem;
    }
    
    .badge {
        font-size: 0.7rem;
        padding: 0.35em 0.5em;
    }
}

/* Toastr Custom */
.toast-success {
    background-color: var(--success-color) !important;
}

.toast-error {
    background-color: var(--danger-color) !important;
}

.toast-warning {
    background-color: var(--warning-color) !important;
}

.toast-info {
    background-color: var(--info-color) !important;
}

/* Print Styles */
@media print {
    .navbar,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .container-fluid {
        padding: 0 !important;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}