/**
 * TableMastWeb - Estilos para vistas CRUD
 */

.tablemast-container {
    padding: 0;
}

.tablemast-header {
    background: linear-gradient(135deg, var(--softia-bg-secondary) 0%, var(--softia-bg-primary) 100%);
    padding: 1.5rem;
    border-bottom: 2px solid var(--softia-accent);
    margin-bottom: 1rem;
}

.tablemast-header h2 {
    color: var(--softia-text-primary);
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.tablemast-header p {
    color: var(--softia-text-secondary);
    margin: 0.25rem 0 0 0;
    font-size: 0.875rem;
}

.tablemast-toolbar {
    background-color: var(--softia-bg-secondary);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--softia-border);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tablemast-toolbar .btn-sm {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* Nuevo */
.tablemast-toolbar .btn-primary {
    background-color: var(--softia-accent);
    border-color: var(--softia-accent);
    color: #fff;
}
.tablemast-toolbar .btn-primary:hover {
    background-color: var(--softia-accent-hover);
    border-color: var(--softia-accent-hover);
    color: #fff;
}

/* Editar */
.tablemast-toolbar .btn-secondary {
    background-color: transparent;
    border-color: var(--softia-accent);
    color: var(--softia-accent);
}
.tablemast-toolbar .btn-secondary:hover:not(:disabled) {
    background-color: var(--softia-accent);
    color: #fff;
}
.tablemast-toolbar .btn-secondary:disabled {
    border-color: var(--softia-border);
    color: var(--softia-text-secondary);
    opacity: 0.5;
}

/* Eliminar */
.tablemast-toolbar .btn-danger {
    background-color: transparent;
    border-color: #e74c3c;
    color: #e74c3c;
}
.tablemast-toolbar .btn-danger:hover:not(:disabled) {
    background-color: #e74c3c;
    color: #fff;
}
.tablemast-toolbar .btn-danger:disabled {
    border-color: var(--softia-border);
    color: var(--softia-text-secondary);
    opacity: 0.5;
}

/* Exportar */
.tablemast-toolbar .btn-success {
    background-color: transparent;
    border-color: #2ecc71;
    color: #2ecc71;
}
.tablemast-toolbar .btn-success:hover {
    background-color: #2ecc71;
    color: #fff;
}

/* Columnas */
.tablemast-toolbar .btn-info {
    background-color: transparent;
    border-color: var(--softia-text-secondary);
    color: var(--softia-text-secondary);
}
.tablemast-toolbar .btn-info:hover {
    background-color: var(--softia-text-secondary);
    color: var(--softia-bg-primary);
}

/* Filtro */
.tablemast-toolbar .btn-warning {
    background-color: transparent;
    border-color: #f0ad4e;
    color: #f0ad4e;
}
.tablemast-toolbar .btn-warning:hover {
    background-color: #f0ad4e;
    color: var(--softia-bg-primary);
}

.tablemast-grid {
    padding: 1.5rem;
}

/* DataTables customization */
.tablemast-grid .dataTables_wrapper {
    color: var(--softia-text-primary);
}

.tablemast-grid table.dataTable {
    border-collapse: collapse;
    width: 100% !important;
}

.tablemast-grid table.dataTable thead th {
    background-color: var(--softia-bg-secondary);
    color: var(--softia-text-primary);
    border-bottom: 2px solid var(--softia-accent);
    padding: 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
}

.tablemast-grid table.dataTable tbody td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--softia-border);
    color: var(--softia-text-primary);
    font-size: 0.875rem;
}

.tablemast-grid table.dataTable tbody tr {
    background-color: var(--softia-bg-primary);
    transition: background-color 0.2s;
}

.tablemast-grid table.dataTable tbody tr:hover {
    background-color: rgba(0, 191, 255, 0.05);
}

.tablemast-grid table.dataTable tbody tr.selected {
    background-color: rgba(0, 191, 255, 0.1);
}

/* DataTables controls */
.dataTables_length,
.dataTables_filter,
.dataTables_info,
.dataTables_paginate {
    color: var(--softia-text-primary);
}

.dataTables_length select,
.dataTables_filter input {
    background-color: var(--softia-bg-secondary);
    border: 1px solid var(--softia-border);
    color: var(--softia-text-primary);
    padding: 0.375rem 0.75rem;
    border-radius: 0.25rem;
}

.dataTables_filter input:focus {
    outline: none;
    border-color: var(--softia-accent);
}

.dataTables_paginate .paginate_button {
    color: var(--softia-text-primary) !important;
    background-color: var(--softia-bg-secondary);
    border: 1px solid var(--softia-border);
    padding: 0.375rem 0.75rem;
    margin: 0 0.125rem;
    border-radius: 0.25rem;
}

.dataTables_paginate .paginate_button:hover {
    background-color: var(--softia-accent) !important;
    border-color: var(--softia-accent) !important;
    color: white !important;
}

.dataTables_paginate .paginate_button.current {
    background-color: var(--softia-accent) !important;
    border-color: var(--softia-accent) !important;
    color: white !important;
}

.dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal customization */
.modal-content {
    background-color: var(--softia-bg-primary);
    border: 1px solid var(--softia-border);
}

.modal-header {
    background-color: var(--softia-bg-secondary);
    border-bottom: 2px solid var(--softia-accent);
    color: var(--softia-text-primary);
}

.modal-body {
    background-color: var(--softia-bg-primary);
    color: var(--softia-text-primary);
}

.modal-footer {
    background-color: var(--softia-bg-secondary);
    border-top: 1px solid var(--softia-border);
}

.modal-body .form-label {
    color: var(--softia-text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.modal-body .form-control,
.modal-body .form-select {
    background-color: var(--softia-bg-secondary);
    border: 1px solid var(--softia-border);
    color: var(--softia-text-primary);
}

.modal-body .form-control:focus,
.modal-body .form-select:focus {
    background-color: var(--softia-bg-secondary);
    border-color: var(--softia-accent);
    color: var(--softia-text-primary);
    box-shadow: 0 0 0 0.2rem rgba(0, 191, 255, 0.25);
}

.modal-body .form-control:read-only,
.modal-body .form-select:disabled {
    background-color: rgba(13, 33, 55, 0.5);
    border-color: var(--softia-border);
    color: var(--softia-text-secondary);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Checkbox styling */
input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

/* Estilos para el grid de columnas en el modal */
#columnsList .list-group-item {
    cursor: default;
    user-select: none;
}

#columnsList .form-check-input {
    cursor: pointer;
}

/* =====================================================
   Formulario con fondo claro (contraste con tema oscuro)
   Aplica a modales de edición: #editModal, #lineModal
   ===================================================== */

#editModal .modal-body,
#lineModal .modal-body {
    background-color: #f8f9fa;
    color: #212529;
}

#editModal .modal-body .form-label,
#lineModal .modal-body .form-label {
    color: #344054;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

#editModal .modal-body .form-control,
#editModal .modal-body .form-select,
#lineModal .modal-body .form-control,
#lineModal .modal-body .form-select {
    background-color: #ffffff;
    border: 1px solid #ced4da;
    color: #212529;
}

#editModal .modal-body .form-control:focus,
#editModal .modal-body .form-select:focus,
#lineModal .modal-body .form-control:focus,
#lineModal .modal-body .form-select:focus {
    background-color: #ffffff;
    border-color: #0d6efd;
    color: #212529;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

#editModal .modal-body .form-control:read-only,
#editModal .modal-body .form-select:disabled,
#lineModal .modal-body .form-control:read-only,
#lineModal .modal-body .form-select:disabled {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.8;
}

#editModal .modal-body .form-control::placeholder,
#lineModal .modal-body .form-control::placeholder {
    color: #adb5bd;
}

#editModal .modal-body .text-muted,
#lineModal .modal-body .text-muted {
    color: #6c757d !important;
}

#editModal .modal-body .text-danger,
#lineModal .modal-body .text-danger {
    color: #dc3545 !important;
}

#editModal .modal-body h6,
#lineModal .modal-body h6 {
    color: #344054;
}

#editModal .modal-body .border-bottom,
#lineModal .modal-body .border-bottom {
    border-color: #dee2e6 !important;
}

#editModal .modal-body .input-group .btn,
#lineModal .modal-body .input-group .btn {
    border-color: #ced4da;
    color: #495057;
    background-color: #e9ecef;
}

#editModal .modal-body .input-group .btn:hover,
#lineModal .modal-body .input-group .btn:hover {
    background-color: #dee2e6;
    color: #212529;
}

#editModal .modal-body .input-with-find .find-button,
#lineModal .modal-body .input-with-find .find-button {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #495057;
}

#editModal .modal-body .input-with-find .find-button:hover,
#lineModal .modal-body .input-with-find .find-button:hover {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #ffffff;
}

#editModal .modal-body .table {
    color: #212529;
}

#editModal .modal-body .table td,
#editModal .modal-body .table th {
    color: #212529;
    border-color: #dee2e6;
    background-color: #ffffff;
}

#editModal .modal-body .table thead th {
    background-color: #e9ecef;
    color: #344054;
    font-weight: 600;
}

#editModal .modal-body .table tbody tr:hover td {
    background-color: #f0f4f8;
}

#editModal .modal-body .detail-section h6,
#editModal .modal-body .totals-section strong {
    color: #344054;
}

#editModal .modal-body .btn-edit-line,
#editModal .modal-body .btn-delete-line {
    color: #495057;
}

#editModal .modal-header .btn-close,
#lineModal .modal-header .btn-close {
    filter: brightness(0) invert(1);
}

/* Estilos para formulario maestro-detalle */
.master-section {
    background-color: #f0f2f5;
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    border: 1px solid #dee2e6;
}

.detail-section {
    background-color: #ffffff;
    padding: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
}

.detail-toolbar {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
}

#detailTable {
    font-size: 0.875rem;
}

#detailTable thead th {
    background-color: #e9ecef;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

#detailTable tbody tr:hover {
    background-color: #f8f9fa;
}

.totals-section {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.375rem;
    border: 2px solid #0d6efd;
}

.totals-section table {
    margin-bottom: 0;
}

.totals-section .table-primary {
    background-color: #cfe2ff !important;
}

/* Estilos para modal de línea */
#lineModal .modal-dialog {
    max-width: 600px;
}

/* Botones de acción en detalle */
.btn-edit-line,
.btn-delete-line {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Responsive para modal maestro-detalle */
@media (max-width: 1200px) {
    .modal-xl {
        max-width: 95%;
    }
}

/* Scroll para tabla de detalle */
.detail-section .table-responsive {
    max-height: 400px;
    overflow-y: auto;
}

/* Indicador de campo calculado */
input[readonly].form-control {
    background-color: #e9ecef;
    cursor: not-allowed;
}

/* =====================================================
   Editor Inline - Reemplazo de modal
   ===================================================== */

.inline-editor {
    background-color: var(--softia-bg-primary);
    min-height: 100%;
}

.inline-editor-header {
    background-color: var(--softia-bg-secondary);
    border-bottom: 2px solid var(--softia-accent);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.inline-editor-header .breadcrumb {
    font-size: 0.9rem;
}

.inline-editor-header .breadcrumb-item a {
    color: var(--softia-accent);
    text-decoration: none;
}

.inline-editor-header .breadcrumb-item.active {
    color: var(--softia-text-primary);
    font-weight: 600;
}

.inline-editor-header .breadcrumb-item + .breadcrumb-item::before {
    color: var(--softia-text-secondary);
}

.inline-editor-actions {
    display: flex;
    gap: 0.5rem;
}

.inline-editor-actions .btn {
    font-size: 0.875rem;
    padding: 0.5rem 1.25rem;
}

.inline-editor-body {
    padding: 1.5rem;
    background-color: #f8f9fa;
    min-height: calc(100vh - 120px);
}

.inline-editor-body .form-label {
    color: #344054;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.inline-editor-body .form-control,
.inline-editor-body .form-select {
    background-color: #ffffff;
    border: 1px solid #ced4da;
    color: #212529;
}

.inline-editor-body .form-control:focus,
.inline-editor-body .form-select:focus {
    background-color: #ffffff;
    border-color: #0d6efd;
    color: #212529;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.inline-editor-body .form-control:read-only,
.inline-editor-body .form-select:disabled {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.8;
}

.inline-editor-body .form-control::placeholder {
    color: #adb5bd;
}

.inline-editor-body .text-muted {
    color: #6c757d !important;
}

.inline-editor-body .text-danger {
    color: #dc3545 !important;
}

.inline-editor-body h6 {
    color: #344054;
}

.inline-editor-body .border-bottom {
    border-color: #dee2e6 !important;
}

.inline-editor-body .input-with-find .find-button,
.inline-editor-body .input-group .find-button {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #495057;
    padding: 0.375rem 0.5rem;
    display: flex;
    align-items: center;
}

.inline-editor-body .input-with-find .find-button:hover,
.inline-editor-body .input-group .find-button:hover {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #ffffff;
}

.inline-editor-body .input-group {
    flex-wrap: nowrap;
}

.inline-editor-body .input-group .form-control {
    min-width: 0;
}

.inline-editor-body .master-section {
    background-color: #f0f2f5;
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    border: 1px solid #dee2e6;
}

.inline-editor-body .detail-section {
    background-color: #ffffff;
    padding: 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
}

.inline-editor-body .table {
    color: #212529;
}

.inline-editor-body .table td,
.inline-editor-body .table th {
    color: #212529;
    border-color: #dee2e6;
    background-color: #ffffff;
}

.inline-editor-body .table thead th {
    background-color: #e9ecef;
    color: #344054;
    font-weight: 600;
}

.inline-editor-body .table tbody tr:hover td {
    background-color: #f0f4f8;
}

.inline-editor-body .totals-section {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.375rem;
    border: 2px solid #0d6efd;
}

/* =====================================================
   Cálculos Automáticos
   ===================================================== */

.inline-editor-body .calculations-section {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.375rem;
    border: 2px solid #0d6efd;
}

.inline-editor-body .calculations-section h6 {
    color: #344054;
}

.inline-editor-body .calc-table {
    margin-bottom: 0;
}

.inline-editor-body .calc-table td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    border-color: #dee2e6;
}

.inline-editor-body .calc-table .calc-label {
    white-space: nowrap;
    color: #344054;
    font-size: 0.9rem;
}

.inline-editor-body .calc-table .calc-value {
    font-size: 1.05rem;
    font-weight: 600;
    color: #0d6efd;
    min-width: 120px;
}

.inline-editor-body .calc-table .calc-row-total td {
    border-top: 2px solid #0d6efd;
    background-color: #e7f1ff;
}

.inline-editor-body .calc-table .calc-row-total .calc-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #198754;
}

.inline-editor-body .calc-table .calc-field-input,
.inline-editor-body .calc-table .calc-percent-input {
    background-color: #ffffff;
    border: 1px solid #ced4da;
    color: #212529;
}

.inline-editor-body .calc-table .calc-field-input:focus,
.inline-editor-body .calc-table .calc-percent-input:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.15);
}

.inline-editor-body .calc-table .input-group-text {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #495057;
    font-size: 0.8rem;
}

/* =====================================================
   Campos tipo RUT
   ===================================================== */

.rut-field-group {
    max-width: 320px;
}

.rut-field-group .rut-input {
    font-family: monospace;
    letter-spacing: 0.5px;
}

.rut-field-group .rut-dv-input {
    font-family: monospace;
    text-align: center;
    font-weight: 700;
}

.rut-field-group .input-group-text {
    padding: 0.375rem 0.5rem;
    font-weight: 700;
}

.rut-error {
    font-size: 0.8rem;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .tablemast-toolbar {
        flex-direction: column;
    }
    
    .tablemast-toolbar .btn-group {
        width: 100%;
    }
    
    .tablemast-toolbar .btn {
        flex: 1;
    }
    
    .inline-editor-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
}
