/* ====== RESET BÁSICO Y LAYOUT GENERAL ====== */
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f6f9;
    color: #1f2933;
    display: flex;
    min-height: 100vh;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
}

/* ====== SIDEBAR ====== */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #111827 0%, #1f2937 60%, #111827 100%);
    color: #e5e7eb;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 2px 0 12px rgba(15, 23, 42, 0.45);
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar h3 {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.sidebar small {
    color: #9ca3af;
    font-size: 11px;
}

.sidebar button {
    width: 100%;
    margin: 1px 0;
    padding: 6px 10px;
    background: transparent;
    border-radius: 10px;
    border: 1px solid transparent;
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.sidebar button:hover {
    background: rgba(31, 41, 55, 0.9);
    border-color: rgba(55, 65, 81, 0.8);
}

.sidebar button:active {
    transform: scale(0.99);
}

.sidebar .notification {
    background: #ef4444;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.3);
}

/* ====== CONTENIDO PRINCIPAL ====== */
.content {
    flex: 1;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Soporte para .main por si se usa en otros HTML */
.main {
    flex: 1;
    padding: 24px 32px;
}

/* ====== TOPBAR ====== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    color: #111827;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.action-btn {
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    padding: 7px 14px;
    font-size: 13px;
    background: #f9fafb;
    color: #111827;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.action-btn:hover {
    background: #111827;
    color: #f9fafb;
    border-color: #111827;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.2);
}

.action-btn--danger {
    border-color: #fecaca;
    background: #fff1f2;
    color: #9f1239;
}

.action-btn--danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fef2f2;
}

.action-btn--success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.action-btn--success:hover {
    background: #166534;
    border-color: #166534;
    color: #f0fdf4;
}

.action-btn:active {
    transform: translateY(1px);
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.18);
}

/* ====== TARJETA PRINCIPAL (TABLA CLIENTES) ====== */
.card {
    background: #ffffff;
    border-radius: 14px;
    padding: 16px 18px 18px;
    box-shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
    border: 1px solid #e5e7eb;
}

.card table {
    width: 100%;
}

/* ====== TABLAS GENERALES ====== */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 13px;
}

thead {
    background: #f3f4f6;
}

th,
td {
    padding: 10px 10px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

th {
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #6b7280;
}

tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

tbody tr:hover {
    background-color: #eef2ff;
}

tbody tr td:first-child {
    width: 36px;
}

tbody input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ====== TABLAS DE CÁLCULO Y DETALLE ====== */
.tabla-calculo {
    background: #ffffff;
    border-radius: 12px;
    padding: 6px 10px 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    border: 1px solid #e5e7eb;
}

.tabla-calculo td:first-child {
    font-weight: 500;
}

.tabla-calculo td span {
    font-variant-numeric: tabular-nums;
}

/* Tabla de productos incrustada (editor) */
.tabla-productos {
    background: #f9fafb;
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.tabla-productos h3 {
    margin: 0 0 4px;
    font-size: 18px;
}

.tabla-productos p {
    margin: 0 0 12px;
    color: #6b7280;
    font-size: 13px;
}

.tabla-productos table {
    margin-top: 8px;
    background: #ffffff;
    border-radius: 10px;
    overflow: hidden;
}

.tabla-productos th,
.tabla-productos td {
    font-size: 13px;
}

.tabla-productos td .delete {
    background: #fee2e2;
    border-color: #fecaca;
    color: #b91c1c;
    padding: 4px 9px;
    font-size: 12px;
}

.tabla-productos td .delete:hover {
    background: #b91c1c;
    color: #fef2f2;
}

.tabla-productos #addProducto,
#addProducto {
    margin-top: 8px;
    border-radius: 999px;
    border: 1px dashed #9ca3af;
    background: #f9fafb;
    padding: 6px 12px;
    font-size: 12px;
    color: #4b5563;
    cursor: pointer;
}

.tabla-productos #addProducto:hover,
#addProducto:hover {
    background: #e5e7eb;
}

td[contenteditable="true"].producto {
    background-color: #f9fafb;
    border-radius: 6px;
}

td[contenteditable="true"].producto:focus-visible {
    outline: 1px solid #6366f1;
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.4);
}

input.precio,
input.cantidad {
    width: 90px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    font-size: 12px;
}

/* ====== BOTONES GENERALES ====== */
button#btnGenerarPDFCalculado {
    align-self: flex-start;
    margin-top: 8px;
}

/* ====== MODAL (SI SE USA) ====== */
.modal {
    display: none;
    position: fixed;
    z-index: 40;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(15, 23, 42, 0.55);
}

.modal-content {
    background-color: #ffffff;
    margin: 60px auto;
    padding: 20px 22px 22px;
    border: 1px solid #e5e7eb;
    width: min(720px, 94%);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
}

.modal-content h3 {
    margin-top: 0;
}

.close {
    color: #9ca3af;
    float: right;
    font-size: 22px;
    font-weight: 600;
    cursor: pointer;
}

.close:hover {
    color: #111827;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 960px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 14px 16px;
        position: static;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.3);
    }

    .sidebar button {
        width: auto;
        flex: 1;
    }

    .content,
    .main {
        padding: 16px;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 6px 8px;
    }
}

/* ====== COMPONENTES (ESTILO CRM) ====== */
.card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 12px;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #111827;
}

.card-meta {
    font-size: 12px;
    color: #6b7280;
    max-width: 520px;
}

.table-wrap {
    width: 100%;
    overflow: auto;
}

/* Botón Eliminar en historial */
.btnEliminarHistorial {
    border: 1px solid #fca5a5;
    background: #fff1f2;
    color: #b91c1c;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(185, 28, 28, 0.10);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
    white-space: nowrap;
}

.btnEliminarHistorial:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
    box-shadow: 0 14px 26px rgba(185, 28, 28, 0.18);
}

.btnEliminarHistorial:active {
    transform: translateY(1px);
}

.btnEliminarHistorial:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.55);
    outline-offset: 2px;
}

/* ====== BADGE DE ESTADO (CRM) ====== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1;
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-badge--aprobado {
    background: #ecfdf5;
    color: #166534;
    border-color: #bbf7d0;
}

.status-badge--denegado {
    background: #fff1f2;
    color: #b91c1c;
    border-color: #fecaca;
}

.status-badge--revisado {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.status-badge--entrada {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.status-badge--neutral {
    background: #f3f4f6;
    color: #374151;
    border-color: #e5e7eb;
}

/* Resumen de productos (tabla de abajo) */
#resumenProductosWrap {
    margin-top: 12px;
}

#tablaResumenProductos {
    margin-top: 0;
}

#tablaResumenProductos th {
    background: #f3f4f6;
    position: sticky;
    top: 0;
    z-index: 1;
}
