/*
 * MitigaTheme — Variables de color y correcciones
 *
 * Para cambiar los colores del tema, modifica las variables CSS
 * en el bloque :root a continuación.
 */

/* ====================================================
   VARIABLES DE COLOR — personalizar aquí
   ==================================================== */
:root {
    /* Sidebar */
    --mt-sidebar-bg:          #0424AA;
    --mt-sidebar-text:        #d0ddf7;
    --mt-sidebar-active-text: #ffffff;
    --mt-sidebar-hover-bg:    rgba(255, 255, 255, 0.06);
    --mt-sidebar-active-bg:   rgba(255, 255, 255, 0.10);

    /* Topbar */
    --mt-topbar-bg:           #ffffff;
    --mt-topbar-border:       #e5eaef;

    /* Fondo general */
    --mt-body-bg:             #f0f4ff;

    /* Color principal */
    --mt-primary:             #0424AA;
    --mt-primary-hover:       #0320a0;
}

/* ====================================================
   SIDEBAR — aplicar variables
   ==================================================== */
.left-sidebar {
    background-color: var(--mt-sidebar-bg) !important;
}

.sidebar-nav .sidebar-item .sidebar-link {
    color: var(--mt-sidebar-text) !important;
}

.sidebar-nav .sidebar-item .sidebar-link i,
.sidebar-nav .sidebar-item .sidebar-link span {
    color: var(--mt-sidebar-text) !important;
}

.sidebar-nav .sidebar-item .sidebar-link:hover,
.sidebar-nav .sidebar-item .sidebar-link:focus {
    background-color: var(--mt-sidebar-hover-bg) !important;
    color: var(--mt-sidebar-active-text) !important;
}

.sidebar-nav .sidebar-item .sidebar-link:hover i,
.sidebar-nav .sidebar-item .sidebar-link:hover span,
.sidebar-nav .sidebar-item .sidebar-link:focus i,
.sidebar-nav .sidebar-item .sidebar-link:focus span {
    color: var(--mt-sidebar-active-text) !important;
}

.sidebar-nav .sidebar-item .sidebar-link.active {
    background-color: var(--mt-sidebar-active-bg) !important;
    color: var(--mt-sidebar-active-text) !important;
}

.sidebar-nav .sidebar-item .sidebar-link.active i,
.sidebar-nav .sidebar-item .sidebar-link.active span {
    color: var(--mt-sidebar-active-text) !important;
}

/* ====================================================
   CORRECCIÓN: Flechas del sidebar (mismo color que el texto)
   ==================================================== */
.sidebar-nav .has-arrow::after {
    border-color: var(--mt-sidebar-text) !important;
}

.sidebar-nav li.active > .has-arrow::after,
.sidebar-nav li > .has-arrow.active::after,
.sidebar-nav .has-arrow[aria-expanded=true]::after {
    border-color: var(--mt-sidebar-active-text) !important;
}

.sidebar-nav ul .sidebar-item .sidebar-link:hover.has-arrow::after,
.sidebar-nav ul .sidebar-item .sidebar-link:focus.has-arrow::after {
    border-color: var(--mt-sidebar-active-text) !important;
}

/* ====================================================
   CORRECCIÓN: Texto del menú no se corta
   ==================================================== */
.sidebar-nav .hide-menu {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    word-break: break-word;
    line-height: 1.35;
}

.sidebar-nav .sidebar-link {
    align-items: flex-start !important;
    height: auto !important;
    min-height: 45px;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

/* ====================================================
   ALTURA DEL SIDEBAR — controlada por variable
   ==================================================== */
:root {
    --mt-sidebar-offset: 120px; /* Altura del bloque del logo en el sidebar */
}

.sidebar-nav.scroll-sidebar {
    height: calc(100vh - var(--mt-sidebar-offset));
}

/* ====================================================
   CORRECCIÓN: Scroll en el contenido principal
   ==================================================== */
html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--mt-body-bg) !important;
}

.page-wrapper {
    height: 100vh;
    overflow: hidden;
}

/* body-wrapper: flex column fijo, NO scrollea */
.body-wrapper {
    height: 100vh;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

/* body-wrapper-inner: el único scroll container */
.body-wrapper-inner {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important; /* anula el calc(100vh - 60px) de flexy */
    padding-bottom: 60px; /* espacio para la barra de debug */
}

/* ====================================================
   TOPBAR — sticky dentro del body-wrapper
   ==================================================== */
:root {
    --mt-topbar-height: 64px;
}

.app-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 200 !important;
    background-color: var(--mt-topbar-bg) !important;
    border-bottom: 1px solid var(--mt-topbar-border) !important;
}

/* ====================================================
   TABS STICKY — debajo del topbar
   ==================================================== */
ul.nav-tabs#mainTabs {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--mt-body-bg);
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 0;
}

/* ====================================================
   ANCHO DEL SIDEBAR — fijo 270px
   ==================================================== */
.left-sidebar {
    width: 270px !important;
}

@media (min-width: 1200px) {
    .body-wrapper {
        margin-left: 270px !important;
    }
}

/* ====================================================
   MINI SIDEBAR — toggle a modo compacto
   ==================================================== */
#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar {
    width: 70px !important;
}

@media (min-width: 1200px) {
    #main-wrapper[data-sidebartype="mini-sidebar"] .body-wrapper {
        margin-left: 70px !important;
    }
}

#main-wrapper[data-sidebartype="mini-sidebar"] .hide-menu {
    display: none !important;
}

#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar .has-arrow::after {
    display: none !important;
}

#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar .sidebar-link {
    justify-content: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar .sidebar-link .d-flex {
    justify-content: center !important;
    gap: 0 !important;
}

#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar .brand-logo img {
    width: 36px !important;
    height: 36px !important;
}

/* Ocultar elementos añadidos por plugins externos en la base del sidebar */
#main-wrapper[data-sidebartype="mini-sidebar"] .left-sidebar > div > :not(nav):not(.brand-logo) {
    display: none !important;
}

/* ====================================================
   OVERLAY MÓVIL — fondo oscuro al abrir sidebar
   - display:none/block en lugar de solo opacity (fiable en iOS)
   - translateZ(0) fuerza capa GPU en iOS Safari
   ==================================================== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

@media (max-width: 1199px) {
    .left-sidebar {
        z-index: 1001 !important;
    }
}

/* ====================================================
   TRANSICIONES SUAVES — sidebar y elementos
   ==================================================== */
.left-sidebar {
    transition: width 0.25s ease, transform 0.25s ease;
}

.body-wrapper {
    transition: margin-left 0.25s ease;
}

/* ====================================================
   ESTILOS DE IMPRESIÓN
   ==================================================== */
@media print {
    .left-sidebar,
    .app-header,
    .d-print-none {
        display: none !important;
    }

    .body-wrapper {
        margin-left: 0 !important;
        overflow: visible !important;
        height: auto !important;
        display: block !important;
    }

    .body-wrapper-inner {
        overflow: visible !important;
        height: auto !important;
    }

    .page-wrapper,
    html,
    body {
        overflow: visible !important;
        height: auto !important;
    }
}


/* Mini sidebar tooltips: gestionados por Bootstrap Tooltip (JS) con container:'body' */

/* ====================================================
   SKELETON LOADER — shimmer animation
   ==================================================== */
.mt-skeleton {
    position: relative;
    overflow: hidden;
    background: #e2e8f0;
    border-radius: 4px;
}

.mt-skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: -150%;
    width: 150%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
    animation: mt-shimmer 1.5s infinite;
}

@keyframes mt-shimmer {
    100% { left: 150%; }
}

.mt-skeleton-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--mt-body-bg, #f0f4ff);
    z-index: 50;
    padding: 24px;
}

.mt-skeleton-heading {
    height: 28px;
    width: 35%;
    margin-bottom: 20px;
    border-radius: 6px;
}

.mt-skeleton-row {
    display: flex;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

.mt-skeleton-cell {
    height: 16px;
    flex: 1;
    border-radius: 4px;
}

/* Subtle fade-in on page load */
.body-wrapper-inner {
    animation: mt-fade-in 0.15s ease-out;
}

@keyframes mt-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ====================================================
   EMPTY STATE — styled CTA for empty list views
   ==================================================== */
.mt-empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #6c757d;
}

.mt-empty-state i.fa-inbox {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.35;
    color: #adb5bd;
}

.mt-empty-state p {
    font-size: 1.05rem;
    margin-bottom: 16px;
}

/* ====================================================
   KEYBOARD SHORTCUTS — modal overlay
   ==================================================== */
.mt-shortcuts-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: mt-fade-in 0.15s ease-out;
}

.mt-shortcuts-modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px 28px;
    max-width: 440px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.mt-shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.mt-shortcut-row:last-child {
    border-bottom: none;
}

.mt-kbd {
    display: inline-block;
    background: #f1f3f5;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 2px 8px;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.82rem;
    color: #495057;
}

/* ====================================================
   COMMAND PALETTE — Ctrl+K
   ==================================================== */
.mt-palette-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    animation: mt-fade-in 0.1s ease-out;
}

.mt-palette-modal {
    background: #fff;
    border-radius: 12px;
    max-width: 560px;
    width: 92%;
    box-shadow: 0 16px 48px rgba(0,0,0,0.22);
    overflow: hidden;
}

.mt-palette-input-wrap {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e5eaef;
}

.mt-palette-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1rem;
    background: transparent;
    color: #212529;
}

.mt-palette-input::placeholder {
    color: #adb5bd;
}

.mt-palette-results {
    max-height: 380px;
    overflow-y: auto;
    padding: 6px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.12) transparent;
}

.mt-palette-group {
    padding: 8px 18px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
}

.mt-palette-item {
    display: flex;
    align-items: center;
    padding: 10px 18px;
    cursor: pointer;
    font-size: 0.92rem;
    color: #212529;
    transition: background 0.08s;
}

.mt-palette-item:hover,
.mt-palette-item.selected {
    background: var(--mt-body-bg, #f0f4ff);
}

.mt-palette-item i:first-child {
    width: 20px;
    text-align: center;
    color: #6c757d;
    font-size: 0.85rem;
}

.mt-palette-empty {
    padding: 24px;
    text-align: center;
    color: #adb5bd;
    font-size: 0.92rem;
}

/* ====================================================
   SIDEBAR FAVORITES — star icon + pinned section
   ==================================================== */
.mt-fav-star {
    margin-left: auto;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
    color: #adb5bd;
    cursor: pointer;
    padding: 4px;
}

.sidebar-link:hover .mt-fav-star,
.mt-fav-star.active {
    opacity: 1;
}

.mt-fav-star.active {
    color: #ffc107;
}

.mt-fav-header {
    padding: 8px 20px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--mt-sidebar-text, #d0ddf7);
    opacity: 0.7;
}

.mt-fav-list {
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
}

#mt-favorites-section {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 4px;
    padding-bottom: 4px;
}

/* ====================================================
   DYNAMIC BREADCRUMBS
   ==================================================== */
.mt-breadcrumbs {
    padding: 0;
    margin-bottom: 4px;
    font-size: 0.82rem;
}

.mt-breadcrumbs .breadcrumb {
    background: transparent;
    padding: 0;
}

.mt-breadcrumbs .breadcrumb-item a {
    color: var(--mt-primary, #0424AA);
    text-decoration: none;
}

.mt-breadcrumbs .breadcrumb-item a:hover {
    text-decoration: underline;
}

.mt-breadcrumbs .breadcrumb-item.active {
    color: #6c757d;
}

.mt-breadcrumbs .breadcrumb-item + .breadcrumb-item::before {
    content: '\203A';
    color: #adb5bd;
}

/* ====================================================
   STICKY ACTION BAR — fixed save/delete at bottom
   ==================================================== */
.mt-sticky-actions {
    position: fixed;
    bottom: 0;
    left: 270px;
    right: 0;
    background: #fff;
    border-top: 1px solid #e5eaef;
    padding: 10px 24px;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 200;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.mt-sticky-actions.visible {
    display: flex;
}

/* Mini sidebar: adjust sticky bar left */
#main-wrapper[data-sidebartype="mini-sidebar"] .mt-sticky-actions {
    left: 70px;
}

@media (max-width: 1199px) {
    .mt-sticky-actions {
        left: 0;
    }
}

/* ====================================================
   CUSTOM SCROLLBAR — thin, themed
   ==================================================== */
.mt-custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.mt-custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.mt-custom-scrollbar::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--mt-primary, #0424AA) 25%, transparent);
    border-radius: 3px;
}

.mt-custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--mt-primary, #0424AA) 50%, transparent);
}

/* Firefox */
.mt-custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--mt-primary, #0424AA) 25%, transparent) transparent;
}


