/* =====================================================
   BASE
   ===================================================== */
html {
    font-size: 14px;
    height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: #f1f5f9;
    color: #1e293b;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #3b82f6;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* =====================================================
   APP LAYOUT
   ===================================================== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
}

.content-area {
    flex: 1;
    padding: 1.5rem;
}

.app-footer {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: #94a3b8;
    background: #fff;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
#sidebar {
    width: 260px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: sticky;
    top: 56px;                       /* navbar height */
    height: calc(100vh - 56px);
}

#sidebar.collapsed {
    width: 0;
}

/* ── Header ── */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    min-height: 58px;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    font-weight: 700;
    font-size: 1rem;
    color: #60a5fa;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.sidebar-brand i {
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* ── Tree container ── */
.sidebar-menu-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.sidebar-menu-container::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}

/* ── Footer ── */
.sidebar-footer {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    color: #64748b;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-footer i {
    font-size: 1rem;
    flex-shrink: 0;
}

/* =====================================================
   jsTREE — DARK SIDEBAR OVERRIDES
   ===================================================== */

/* Container */
#sidebarTree .jstree-default {
    background: transparent !important;
    font-size: 0.85rem;
}

/* Each row */
#sidebarTree .jstree-default .jstree-wholerow {
    border-radius: 8px;
    margin: 1px 6px;
}

/* Hover — mismo patrón que clicked para evitar fondo claro del tema por defecto */
#sidebarTree .jstree-default .jstree-wholerow-hovered,
.jstree-wholerow-ul .jstree-wholerow-hovered {
    background: rgba(96, 165, 250, 0.18) !important;
    border-radius: 8px;
    border-left: 3px solid rgba(96, 165, 250, 0.45) !important;
}

/* Nodo seleccionado — fondo sólido oscuro para que el texto siempre sea visible */
#sidebarTree .jstree-default .jstree-wholerow-clicked,
.jstree-wholerow-ul .jstree-wholerow-clicked {
    background: #1d4ed8 !important;
    background: linear-gradient(90deg, #1e40af 0%, #1d4ed8 100%) !important;
    border-radius: 8px;
    border-left: 3px solid #60a5fa !important;
}

/* Anchor (text + icon row) */
#sidebarTree .jstree-default .jstree-anchor {
    color: #cbd5e1 !important;
    padding: 6px 10px 6px 4px !important;
    border-radius: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.4;
}

#sidebarTree .jstree-default .jstree-hovered {
    background: transparent !important;
    color: #93c5fd !important;
    box-shadow: none !important;
}

#sidebarTree .jstree-default .jstree-clicked {
    background: transparent !important;
    color: #ffffff !important;
    box-shadow: none !important;
}

/* Disclosure arrow */
#sidebarTree .jstree-default .jstree-icon.jstree-ocl {
    color: #475569 !important;
}

/* Node icon */
#sidebarTree .jstree-default .jstree-icon:not(.jstree-ocl) {
    color: #94a3b8;
}

#sidebarTree .jstree-default .jstree-clicked .jstree-icon:not(.jstree-ocl) {
    color: #60a5fa;
}

/* No background / border on hover for individual anchor */
#sidebarTree a.jstree-anchor:hover {
    text-decoration: none;
}

/* Module nodes — bolder, uppercase label */
#sidebarTree .jstree-default .sidebar-node-module > .jstree-anchor {
    font-weight: 600;
    color: #e2e8f0 !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.72rem;
}

/* Icon colors by node type — class injected directly on the <i> by the controller */
#sidebarTree .sidebar-icon-module {
    color: #60a5fa !important;
}

#sidebarTree .sidebar-icon-function {
    color: #ffffff !important;
}

/* Function nodes */
#sidebarTree .jstree-default .sidebar-node-function > .jstree-anchor {
    color: #94a3b8 !important;
}

#sidebarTree .jstree-default .sidebar-node-function:hover > .jstree-anchor,
#sidebarTree .jstree-default .sidebar-node-function > .jstree-anchor.jstree-hovered {
    color: #93c5fd !important;
}

#sidebarTree .jstree-default .sidebar-node-module > .jstree-anchor.jstree-hovered {
    color: #93c5fd !important;
}

/* Active / current page function */
#sidebarTree .jstree-default .sidebar-node-function > .jstree-anchor.jstree-clicked {
    color: #ffffff !important;
}

/* Module node selected */
#sidebarTree .jstree-default .sidebar-node-module > .jstree-anchor.jstree-clicked {
    color: #ffffff !important;
}

/* Icon color when node is selected */
#sidebarTree .jstree-default .jstree-clicked .jstree-icon:not(.jstree-ocl),
#sidebarTree .jstree-default .sidebar-node-function > .jstree-anchor.jstree-clicked .jstree-icon,
#sidebarTree .jstree-default .sidebar-node-module > .jstree-anchor.jstree-clicked .jstree-icon {
    color: #bfdbfe !important;
}

/* Indentation lines removal for cleaner look */
#sidebarTree .jstree-default-no-dots .jstree-node,
#sidebarTree .jstree-default .jstree-node {
    background-image: none;
}

/* =====================================================
   DATATABLES
   ===================================================== */

/* Alinear el input de búsqueda */
.dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    justify-content: flex-end;
}

.dataTables_filter input {
    width: 200px;
}

/* Grupo de botones de exportación */
.dt-buttons {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: center;
}

.dt-buttons .btn {
    white-space: nowrap;
}

/* Colores explícitos (no dependientes de custom properties de Bootstrap)
   para que texto/ícono sean legibles en reposo, no solo en hover */
.dt-buttons .btn.btn-outline-secondary {
    color: #495057;
    background-color: #fff;
    border-color: #adb5bd;
}

.dt-buttons .btn.btn-outline-secondary:hover,
.dt-buttons .btn.btn-outline-secondary:focus {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.dt-buttons .btn.btn-outline-secondary i {
    color: inherit;
}

/* Columna de acciones sin salto de línea */
table.dt-table td:last-child {
    white-space: nowrap;
}

/* Info + paginación bien alineados */
.dataTables_info {
    padding-top: 0.5rem;
    font-size: 0.85rem;
    color: #64748b;
}

/* Eliminar el borde extra que agrega el wrapper */
.dataTables_wrapper .table {
    margin-bottom: 0;
}

/* =====================================================
   CARDS — view panels
   ===================================================== */
.card {
    border-radius: 0.625rem;
}

.card-header {
    border-radius: calc(0.625rem - 1px) calc(0.625rem - 1px) 0 0 !important;
}

/* Compact dl labels in cards */
.info-list dt {
    font-weight: 600;
    color: #64748b;
    font-size: 0.875rem;
}

.info-list dd {
    color: #1e293b;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

/* Page breadcrumb + title header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header .breadcrumb {
    font-size: 0.8125rem;
}

/* =====================================================
   RESPONSIVE — collapse sidebar on small screens
   ===================================================== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 56px;
        z-index: 1020;
        height: calc(100vh - 56px);
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    #sidebar:not(.collapsed) {
        transform: translateX(0);
        width: 260px;
    }

    #sidebar.collapsed {
        width: 260px;
        transform: translateX(-100%);
    }
}

/* =====================================================
   SPLIT PANEL — panel izquierdo/derecho redimensionable
   Uso: contenedor .split-panel con hijos .split-panel-start,
   .split-panel-handle y .split-panel-end
   ===================================================== */
.split-panel {
    display: flex;
    align-items: stretch;
}

.split-panel-start {
    flex: 0 0 auto;
    min-width: 0;
}

.split-panel-end {
    flex: 1 1 auto;
    min-width: 0;
}

.split-panel-handle {
    flex: 0 0 10px;
    cursor: col-resize;
    position: relative;
}

.split-panel-handle::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 4px;
    width: 2px;
    background-color: var(--bs-border-color, #dee2e6);
    border-radius: 1px;
    transition: background-color 0.15s ease;
}

.split-panel-handle:hover::after,
.split-panel-handle.dragging::after {
    background-color: var(--bs-primary, #0d6efd);
}

/* =====================================================
   SEARCHABLE SELECT — combo con filtro tipo "contiene"
   Uso: agregar data-searchable a un <select>; ver
   wwwroot/js/searchable-select.js
   ===================================================== */
.searchable-select-wrapper {
    position: relative;
}

.searchable-select-hidden {
    display: none !important;
}

.searchable-select-menu {
    display: none;
    position: absolute;
    z-index: 1055;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.searchable-select-menu.show {
    display: block;
}

.searchable-select-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.375rem 0.75rem;
    background: none;
    border: none;
    font-size: 0.9rem;
}

.searchable-select-item:hover,
.searchable-select-item.active {
    background-color: #e9ecef;
}

.searchable-select-empty {
    padding: 0.375rem 0.75rem;
    color: #6c757d;
    font-style: italic;
    font-size: 0.9rem;
}
