/* ==========================================
   SISTEMA JUZGADO DE FALTAS - ESTILO ESCRITORIO
   ========================================== */

/* Reseteo universal para evitar problemas de anchos con paddings */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: Tahoma, Arial, sans-serif;
    font-size: 12px;
    background-color: #e4e4e4;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- BARRAS SUPERIORES E INFERIORES --- */
.top-toolbar {
    background-color: #d4d0c8;
    border-bottom: 2px solid #808080;
    padding: 4px 8px;
    display: flex;
    gap: 5px;
    flex-wrap: nowrap; /* Evita que se apilen por defecto */
    align-items: center;
}

.toolbar-btn {
    background-color: transparent;
    border: 1px solid transparent;
    padding: 4px 8px;
    font-size: 12px;
    color: #333;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background-color 0.2s, border 0.1s;
    white-space: nowrap; /* Evita que el texto del botón se corte */
}

.toolbar-btn:hover {
    border: 1px outset #fff;
    background-color: #e4e4e4;
}

/* Botón de hamburguesa (Oculto en PC) */
.mobile-toggle-btn {
    display: none;
    background: none;
    border: 1px solid transparent;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 10px;
    color: #003366;
}

.status-bar {
    background-color: #d4d0c8;
    border-top: 2px solid #808080;
    padding: 4px 10px;
    font-size: 11px;
    color: #333;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 5px;
}

/* --- ESTRUCTURA DE PANELES --- */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative; /* Importante para el menú off-canvas */
}

.sidebar {
    width: 250px;
    background-color: #fff;
    border-right: 2px solid #808080;
    border-top: 2px solid #808080;
    padding: 10px;
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform 0.3s ease-in-out;
    z-index: 1000;
}

/* Fondo oscuro para móvil cuando el menú está abierto */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.content-area {
    flex: 1;
    background-color: #fff;
    border-top: 2px solid #808080;
    padding: 0;
    overflow-y: auto;
    overflow-x: auto;
}

.tree-list {
    list-style-type: none;
    padding-left: 15px;
    margin: 0;
}

.tree-list li {
    padding: 3px 0;
    cursor: pointer;
}

.tree-link { 
    text-decoration: none; 
    color: inherit; 
    display: block; 
    width: 100%;
    padding: 4px 5px;
    border-radius: 3px;
    transition: background-color 0.2s, color 0.2s;
}

.tree-link:hover {
    background-color: #003366;
    color: white;
}

/* --- TABLAS Y GRILLAS DE DATOS --- */
.table-lex {
    width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
}

.table-lex thead th {
    background-color: #003366;
    color: white;
    font-weight: normal;
    position: sticky;
    top: 0;
    padding: 6px 8px;
    border: 1px solid #808080;
    text-align: left;
    z-index: 10;
}

.table-lex tbody td {
    padding: 5px 8px;
    border: 1px solid #d4d0c8;
    vertical-align: middle;
    /* white-space: nowrap; (Removido para que los textos largos bajen de línea si es necesario) */
}

.table-lex tbody tr:nth-child(even) {
    background-color: #f5f5f5; /* Filas cebradas para mejor lectura */
}

.table-lex tbody tr:hover {
    background-color: #ffffcc;
}

/* --- FORMULARIOS Y CAJAS --- */
.panel-box {
    background-color: #fff;
    border: 2px inset #d4d0c8;
    padding: 15px;
    margin: 10px auto;
    width: 100%;
}

.panel-title {
    font-weight: bold;
    color: #003366;
    border-bottom: 1px solid #ccc;
    margin-bottom: 15px;
    padding-bottom: 5px;
    font-size: 14px;
}

.form-control-desktop, .form-select-desktop {
    font-size: 13px; /* Subido 1px para mejor legibilidad */
    border-radius: 0;
    border: 1px solid #999;
    padding: 6px 8px;
    width: 100%;
    background-color: #fff;
    transition: border-color 0.2s, background-color 0.2s;
}

.form-control-desktop:focus, .form-select-desktop:focus {
    border-color: #003366;
    outline: none;
    background-color: #ffffcc;
}

.btn-desktop {
    background-color: #d4d0c8;
    border: 2px outset #fff;
    color: #000;
    font-size: 12px;
    padding: 6px 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.1s;
    white-space: nowrap;
}

.btn-desktop:active {
    border: 2px inset #fff;
    background-color: #ccc;
}

/* --- VENTANA DE LOGIN (MODERNIZADA) --- */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #cfd9df 0%, #e2ebf0 100%);
    padding: 15px;
}

.login-dialog {
    background-color: #f8f9fa;
    border: 1px solid #ced4da;
    border-radius: 6px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    overflow: hidden;
}

.login-header {
    background-color: #003366;
    color: white;
    padding: 10px 15px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    letter-spacing: 0.5px;
}

.login-body {
    padding: 20px;
}

/* ==========================================
   RESPONSIVE DESIGN (TELÉFONOS Y TABLETS)
   ========================================== */
@media screen and (max-width: 768px) {
    body {
        overflow: auto;
    }

    /* Mostrar botón hamburguesa */
    .mobile-toggle-btn {
        display: block;
    }

    /* Navbar scrollable lateralmente */
    .top-toolbar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; 
        scrollbar-width: none; 
    }
    .top-toolbar::-webkit-scrollbar {
        display: none; 
    }

    /* SIDEBAR OFF-CANVAS (Deslizable) */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%); 
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
        border-top: none;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .panel-box {
        margin: 10px 0;
        width: 100%;
        border-left: none;
        border-right: none;
    }

    .form-control-desktop, .form-select-desktop, .btn-desktop {
        padding: 10px;
        font-size: 14px; 
    }

    /* --- NUEVAS MEJORAS --- */

    /* 1. Solución para Formularios y Botones Encimados */
    /* Forzamos a que los formularios en línea (como el buscador de Caja) se apilen verticalmente */
    .panel-box form[style*="display: flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .panel-box form > div {
        width: 100% !important;
        margin-bottom: 5px;
    }

    /* Hacemos que los botones ocupen todo el ancho para tocarlos con el dedo más fácilmente */
    .panel-box form .btn-desktop {
        display: block;
        width: 100%;
        text-align: center;
        margin-top: 5px;
        margin-bottom: 5px;
        box-sizing: border-box;
    }

    /* 2. Solución para Tablas (Scroll Horizontal Automático) */
   .table-lex {
        border: 0;
        min-width: unset;
    }

    .table-lex thead {
        display: none;
    }

    .table-lex,
    .table-lex tbody,
    .table-lex tr,
    .table-lex td {
        display: block;
        width: 100%;
    }

    .table-lex tr {
        margin-bottom: 15px;
        border: 1px solid #ccc;
        background: #fff;
        border-radius: 5px;
        overflow: hidden;
    }

    .table-lex td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        white-space: normal;
        border-bottom: 1px solid #eee;
        min-height: 40px;
    }

    .table-lex td:last-child {
        border-bottom: none;
    }

    .table-lex td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: 45%;
        font-weight: bold;
        text-align: left;
        color: #003366;
    }
}

/* ==========================================
   ESTILOS DE IMPRESIÓN GLOBALES
   ========================================== */
@media print {
    @page { 
        size: A4 portrait; 
        margin: 1cm; 
    }
    
    body { 
        background-color: white; 
        padding: 0 !important; 
        margin: 0 !important; 
    }
    
    .no-print { 
        display: none !important; 
    }
    
    .panel-box { 
        border: none !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        box-shadow: none !important; 
    }
    
    .table-lex th, .table-lex td { 
        padding: 5px 4px !important; 
        font-size: 11px !important; 
    }
    
    h2 { font-size: 16px !important; }
    tr { page-break-inside: avoid; }
}