/* RESET Y BASE */
* {
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

body {
    margin: 0;
    background-color: #f4f6f8;
    color: #333;
    overflow-x: hidden;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR */
nav.sidebar {
    width: 260px;
    background: #2c3e50;
    color: white;
    display: flex;
    flex-direction: column;
    padding: 0;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transition: width 0.3s ease;
    overflow: visible;
    /* Permitir que la lengüeta sobresalga */
}

.sidebar-inner {
    width: inherit;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: inherit;
}

nav.sidebar.collapsed {
    width: 0;
}

.brand {
    padding: 2rem 1.5rem;
    font-size: 1.4rem;
    font-weight: bold;
    color: #3498db;
    border-bottom: 1px solid #34495e;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .brand {
    padding: 2rem 0;
    font-size: 0.8rem;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: -30px;
    transform: translateY(-50%);
    background: white;
    color: #999;
    border: 1px solid #ddd;
    border-left: none;
    border-radius: 0 50% 50% 0;
    /* Forma curva */
    width: 30px;
    height: 80px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    transition: all 0.3s ease;
    padding: 0;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover {
    color: #2c3e50;
    width: 35px;
    /* Efecto expandir un poco */
}

.sidebar.collapsed .sidebar-toggle {
    right: -30px;
}

.sidebar-toggle::after {
    content: '❮';
    font-size: 14px;
    font-weight: bold;
}

.sidebar.collapsed .sidebar-toggle::after {
    content: '❯';
}

.menu {
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
    flex: 1;
    gap: 15px;
    /* Espacio entre grupos */
}

.menu-group {
    display: flex;
    flex-direction: column;
}

.menu-group-label {
    padding: 0 20px 8px 20px;
    font-size: 0.7rem;
    font-weight: bold;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.sidebar.collapsed .menu-group-label {
    display: none;
}

.menu button {
    background: transparent;
    border: none;
    color: #bdc3c7;
    margin: 0;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 15px 20px;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 15px;
    white-space: nowrap;
}

.sidebar.collapsed .menu button {
    padding: 15px 18px;
}

.sidebar.collapsed .menu button span:not(.icon) {
    display: none;
}

.menu button:hover {
    background: #34495e;
    color: white;
}

.menu button.active {
    background: #3498db;
    color: white;
    border-left: 4px solid #fff;
}

.btn-logout {
    margin-top: auto !important;
    border-top: 1px solid #34495e !important;
}

/* CONTENIDO PRINCIPAL */
.main-content {
    flex: 1;
    margin-left: 260px;
    /* Ancho del sidebar */
    padding: 20px;
    background: #f4f6f8;
    transition: margin-left 0.3s ease;
}

.app-wrapper:has(.sidebar.collapsed) .main-content {
    margin-left: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* PANELES (OCULTAR/MOSTRAR) */
.seccion {
    display: none;
    animation: fadeIn 0.3s;
}

.seccion-activa {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* TARJETAS Y FORMULARIOS */
.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

h2,
h3 {
    color: #2c3e50;
    margin-top: 0;
}

.badge {
    background: #f1c40f;
    color: #444;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    vertical-align: middle;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-row {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
}

input,
select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

input:focus,
select:focus {
    outline: none;
    border-color: #3498db;
}

/* TABLAS */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    background: #f8f9fa;
    padding: 10px;
    border-bottom: 2px solid #ddd;
}

td {
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.tabla-items input {
    padding: 5px;
}

/* BOTONES */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #2ecc71;
    color: white;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-danger {
    background: #e74c3c;
    color: white;
    padding: 5px 10px;
}

/* BOTONES DE ACCIÓN HISTORIAL */
.btn-facturar {
    background: #3498db;
    color: white;
    padding: 4px 8px;
    font-size: 11px;
}

.btn-ver-doc {
    background: #9b59b6;
    color: white;
    padding: 4px 8px;
    font-size: 11px;
}

.btn-anular {
    background: #e74c3c;
    color: white;
    padding: 4px 8px;
    font-size: 11px;
}

/* ESTADOS (BADGES) */
.badge-estado {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: bold;
    color: white;
    display: inline-block;
}

.estado-espera {
    background-color: #f1c40f;
    color: #333;
}

.estado-aprobada {
    background-color: #2ecc71;
}

.estado-facturada {
    background-color: #3498db;
}

.estado-anulada {
    background-color: #e74c3c;
}

/* TOTALES */
.totales-card {
    background: #ecf0f1;
}

.totales-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 30px;
    text-align: right;
    font-size: 1.1rem;
}

.total-fuerte {
    font-weight: bold;
    font-size: 1.4rem;
    color: #2c3e50;
}

/* VISTA PREVIA IMPRESIÓN (ESTILO PREMIUM) */
#hoja-cotizacion {
    display: none;
    background: white;
    width: 216mm;
    min-height: 279mm;
    margin: 20px auto;
    padding: 20mm;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    position: relative;
    font-family: 'Segoe UI', system-ui, sans-serif;
    color: #333;
}

/* Header Elegante */
.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 3px solid #2c3e50;
    padding-bottom: 20px;
    margin-bottom: 40px;
}

.empresa-info h2 {
    margin: 0;
    font-size: 28px;
    color: #2c3e50;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.empresa-info p {
    margin: 2px 0;
    font-size: 14px;
    color: #555;
}

.logo-pdf {
    max-height: 80px;
    margin-bottom: 15px;
    display: block;
}

.cotizacion-info {
    text-align: right;
}

.titulo-doc {
    background: #e74c3c;
    color: white;
    padding: 5px 15px;
    font-size: 18px;
    font-weight: bold;
    display: inline-block;
    border-radius: 4px;
    margin-bottom: 10px;
}

.folio-box,
.fecha-box,
.validez-box {
    margin-bottom: 4px;
    font-size: 14px;
}

.folio-box {
    font-size: 16px;
    color: #2c3e50;
    font-weight: bold;
}

/* Cliente */
.pdf-cliente {
    background: #f8f9fa;
    border-left: 5px solid #2c3e50;
    padding: 15px;
    margin-bottom: 30px;
    border-radius: 0 5px 5px 0;
}

.pdf-cliente h3 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 16px;
    text-transform: uppercase;
}

.cliente-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 14px;
}

.cliente-box p {
    margin: 0;
}

/* Tabla Items */
.pdf-cuerpo {
    margin-bottom: 30px;
}

.pdf-tabla {
    width: 100%;
    border-collapse: collapse;
}

.pdf-tabla th {
    background: #2c3e50;
    color: white;
    padding: 12px;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #1a252f;
    text-align: center;
}

.pdf-tabla th:first-child {
    text-align: left;
}

.pdf-tabla th:last-child {
    text-align: right;
}

.pdf-tabla td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    text-align: center;
    font-size: 14px;
}

.pdf-tabla td:first-child {
    text-align: left;
    font-weight: bold;
}

.pdf-tabla td:last-child {
    text-align: right;
    font-weight: bold;
}

/* Striped rows basic implementation for preview (JS handles it in PDF, pure CSS here) */
.pdf-tabla tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

/* Totales */
.pdf-totales {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 40px;
}

.totales-box {
    width: 300px;
}

.fila-total {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 14px;
}

.gran-total {
    font-size: 18px;
    font-weight: bold;
    border-top: 2px solid #333;
    margin-top: 10px;
    padding-top: 10px;
    color: #2c3e50;
}

/* Extras (Resumen y Terminos) */
#box-pdf-resumen,
#box-pdf-terminos {
    border-top: 1px solid #eee;
    padding-top: 15px;
    margin-bottom: 20px;
}

#box-pdf-resumen strong,
#box-pdf-terminos strong {
    color: #e74c3c;
    font-size: 14px;
    text-transform: uppercase;
    display: block;
    margin-bottom: 5px;
}

#pdf-resumen,
#pdf-terminos {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
    margin: 0;
}

/* Footer */
.pdf-footer {
    text-align: center;
    color: #999;
    font-size: 12px;
    margin-top: 50px;
    border-top: 1px solid #eee;
    padding-top: 20px;
}

.acciones-flotantes {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

/* DASHBOARD STYLES */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.dash-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border-left: 5px solid #bdc3c7;
}

.dash-card h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #7f8c8d;
    text-transform: uppercase;
}

.dash-value {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 5px;
}

.dash-sub {
    font-size: 13px;
    color: #95a5a6;
}

.dash-card.warning {
    border-left-color: #f1c40f;
}

.dash-card.success {
    border-left-color: #2ecc71;
}

.dash-card.info {
    border-left-color: #3498db;
}

.dash-detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 5px;
    color: #555;
}

.dash-detail-row.big {
    font-size: 16px;
    font-weight: bold;
    margin-top: 10px;
    border-top: 1px solid #eee;
    padding-top: 5px;
    color: #2c3e50;
}



/* REGLAS DE MEDIOS PARA IMPRESIÓN REAL */
@media print {
    body {
        background: white;
    }

    .no-print {
        display: none !important;
    }

    /* Ocultar menús, botones, dashboard */

    .container {
        display: none !important;
    }

    /* Ocultar la app completa */

    #hoja-cotizacion {
        display: block !important;
        /* Mostrar solo la hoja */
        box-shadow: none;
        margin: 0;
        width: 100%;
        height: auto;
        position: absolute;
        top: 0;
        left: 0;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    @page {
        margin: 0;
        size: auto;
    }

    /* Quitar márgenes navegador */
}

/* LOADING OVERLAY */
.overlay-carga {
    display: none;
    /* Oculto por defecto */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: white;
}

.overlay-activa {
    display: flex !important;
    animation: fadeIn 0.3s;
}

.loader-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    color: #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 300px;
}

.spinner {
    border: 5px solid #f3f3f3;
    /* Light grey */
    border-top: 5px solid #3498db;
    /* Blue */
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* BUSQUEDA PREDICTIVA */
.search-container {
    position: relative;
    width: 100%;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results div {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.search-results div:hover {
    background-color: #f1f8ff;
}

/* BUSQUEDA PREDICTIVA (Para OCs y otros campos) */
.predictive-container {
    position: relative;
    width: 100%;
}

.predictive-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1100;
    display: none;
}

.predictive-results div {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9em;
}

.predictive-results div:hover {
    background: #e1f5fe;
}

.search-results strong {
    color: #2c3e50;
    display: block;
}

.search-results span {
    font-size: 0.8em;
    color: #7f8c8d;
}

/* MODALES */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
}

.close-modal:hover {
    color: #e74c3c;
}

/* VISTA KANBAN */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* Forzamos 4 columnas para que se vea como Kanban */
    gap: 20px;
    align-items: start;
    margin-top: 20px;
}

.kanban-col {
    background: #ebedef;
    border-radius: 8px;
    padding: 15px;
    min-height: 500px;
    border-top: 5px solid #bdc3c7;
    display: flex;
    flex-direction: column;
}

.kanban-col#col-espera {
    border-top-color: #f1c40f;
}

.kanban-col#col-aprobada {
    border-top-color: #2ecc71;
}

.kanban-col#col-facturada {
    border-top-color: #3498db;
}

.kanban-col#col-anulada {
    border-top-color: #e74c3c;
}

.kanban-col h3 {
    font-size: 14px;
    text-transform: uppercase;
    text-align: center;
    color: #7f8c8d;
    margin: 10px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.kanban-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.kanban-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border-left: 5px solid #ddd;
    transition: all 0.2s ease;
}

.kanban-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.kanban-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.85em;
    color: #95a5a6;
}

.kanban-card-folio {
    font-weight: bold;
    color: #2c3e50;
}

.kanban-card-cliente {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 8px;
    display: block;
    color: #2c3e50;
}

.kanban-card-info {
    font-size: 0.9em;
    color: #7f8c8d;
    padding: 5px 0;
}

.kanban-card-actions {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-toggle {
    background: #ecf0f1;
    color: #7f8c8d;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
}

.btn-toggle.active {
    background: #3498db;
    color: white;
}

/* Responsivo para Kanban */
@media (max-width: 1000px) {
    .kanban-board {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .kanban-board {
        grid-template-columns: 1fr;
    }
}