/* ============================================================
   erp.css — Layout ERP: sidebar + topbar + contenido
   Usa las variables CSS definidas en app.css (estilos.css)
   ============================================================ */

/* ─── RESET LAYOUT ─── */
html, body {
    height: 100%;
    overflow: hidden;
}

/* ─── ESTRUCTURA PRINCIPAL ─── */
.erp-wrapper {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar content";
    height: 100vh;
    overflow: hidden;
}

/* ─── SIDEBAR ─── */
.erp-sidebar {
    grid-area: sidebar;
    background: var(--dark2);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid rgba(255,255,255,.06);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}

.erp-sidebar::-webkit-scrollbar { width: 4px; }
.erp-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

/* Logo / Brand */
.sidebar-brand {
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    text-decoration: none;
}

.sidebar-brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: 900;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: .82rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: -.2px;
    line-height: 1.2;
}

.sidebar-brand-tenant {
    font-size: .65rem;
    font-weight: 500;
    color: rgba(255,255,255,.4);
    display: block;
}

/* Secciones del nav */
.sidebar-section {
    padding: 16px 0 4px;
}

.sidebar-section-label {
    padding: 0 18px 6px;
    font-size: .58rem;
    font-weight: 800;
    color: rgba(255,255,255,.25);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

/* Ítem de nav */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;
    font-size: .78rem;
    font-weight: 600;
    color: rgba(255,255,255,.5);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all .15s ease;
    cursor: pointer;
    position: relative;
}

.sidebar-item:hover {
    color: rgba(255,255,255,.9);
    background: rgba(255,255,255,.04);
    border-left-color: rgba(255,255,255,.15);
}

.sidebar-item.active {
    color: #fff;
    background: rgba(255,107,61,.18);
    border-left-color: var(--primary);
}

.sidebar-item .item-icon {
    font-size: .9rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item .item-badge {
    margin-left: auto;
    background: var(--primary);
    color: #fff;
    font-size: .58rem;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 50px;
    min-width: 18px;
    text-align: center;
}

/* Submenú desplegable */
.sidebar-submenu {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
}

.sidebar-submenu.open {
    max-height: 300px;
}

.sidebar-subitem {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 18px 6px 46px;
    font-size: .73rem;
    font-weight: 600;
    color: rgba(255,255,255,.4);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all .15s ease;
}

.sidebar-subitem:hover { color: rgba(255,255,255,.8); }
.sidebar-subitem.active {
    color: var(--primary);
    border-left-color: var(--primary);
}

/* Footer del sidebar */
.sidebar-footer {
    margin-top: auto;
    padding: 12px 18px;
    border-top: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .68rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: .62rem;
    font-weight: 500;
    color: rgba(255,255,255,.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    color: rgba(255,255,255,.35);
    font-size: .85rem;
    cursor: pointer;
    transition: color .15s;
    text-decoration: none;
    padding: 4px;
}

.sidebar-logout:hover { color: var(--danger); }

/* ─── TOPBAR ─── */
.erp-topbar {
    grid-area: topbar;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 100;
}

.topbar-title {
    font-size: .88rem;
    font-weight: 800;
    color: var(--dark);
    flex: 1;
}

.topbar-breadcrumb {
    font-size: .75rem;
    color: var(--muted);
    font-weight: 500;
}

.topbar-breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ─── CONTENIDO PRINCIPAL ─── */
.erp-content {
    grid-area: content;
    overflow-y: auto;
    background: var(--bg);
    padding: 24px;
}

/* ─── CARDS GENERALES ─── */
.erp-card {
    background: var(--white);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 20px 24px;
    box-shadow: var(--shadow);
}

.erp-card-title {
    font-size: .88rem;
    font-weight: 800;
    color: var(--dark);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ─── TABLA ERP ─── */
.erp-table-wrap {
    background: var(--white);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.erp-table-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.erp-table-header-title {
    font-size: .85rem;
    font-weight: 800;
    color: var(--dark);
}

.erp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
}

.erp-table thead th {
    padding: 10px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-weight: 800;
    font-size: .72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    text-align: left;
    white-space: nowrap;
}

.erp-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

.erp-table tbody tr:last-child { border-bottom: none; }
.erp-table tbody tr:hover { background: var(--primary-light); }

.erp-table tbody td {
    padding: 10px 16px;
    color: var(--dark2);
    font-weight: 500;
    vertical-align: middle;
}

/* ─── BADGES / ESTADOS ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 50px;
    font-size: .68rem;
    font-weight: 700;
}

.badge-green   { background: #dcfce7; color: #15803d; }
.badge-yellow  { background: #fef9c3; color: #92400e; }
.badge-red     { background: #fee2e2; color: #b91c1c; }
.badge-blue    { background: #dbeafe; color: #1d4ed8; }
.badge-orange  { background: #ffedd5; color: #c2410c; }
.badge-gray    { background: #f1f5f9; color: #475569; }

/* ─── ALERTAS ─── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: #fef9c3; color: #92400e; border: 1px solid #fef08a; }
.alert-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: .5;
    padding: 0;
    color: inherit;
}

.alert-close:hover { opacity: 1; }

/* ─── FORMULARIOS ─── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: .78rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 5px;
}

.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: .82rem;
    font-weight: 500;
    color: var(--dark);
    background: var(--white);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
    -webkit-appearance: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255,107,61,.12);
}

.form-control.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.form-error {
    font-size: .72rem;
    color: var(--danger);
    font-weight: 600;
    margin-top: 4px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 20px;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0 20px;
}

.form-full { grid-column: 1 / -1; }

/* ─── BÚSQUEDA ─── */
.search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    transition: border-color .2s;
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255,107,61,.1);
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    font-family: 'Nunito', sans-serif;
    font-size: .8rem;
    font-weight: 500;
    color: var(--dark);
    width: 200px;
}

.search-icon { color: var(--muted); font-size: .85rem; }

/* ─── KPIs DASHBOARD ─── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--white);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all .2s;
}

.kpi-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.kpi-info { flex: 1; }

.kpi-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--dark);
    letter-spacing: -.5px;
    line-height: 1;
}

.kpi-label {
    font-size: .72rem;
    font-weight: 700;
    color: var(--muted);
    margin-top: 3px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
    .erp-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr;
        grid-template-areas:
            "topbar"
            "content";
    }

    .erp-sidebar { display: none; }
    .erp-content { padding: 16px; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* ================================================================
   MODAL GENÉRICO
   ================================================================ */
.erp-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeInOverlay .15s ease;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.erp-modal {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(15,23,42,.18), 0 4px 16px rgba(15,23,42,.1);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUpModal .2s cubic-bezier(.34,1.56,.64,1);
}

@keyframes slideUpModal {
    from { opacity: 0; transform: translateY(24px) scale(.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.erp-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.erp-modal-title {
    font-size: .95rem;
    font-weight: 800;
    color: var(--dark);
}

.erp-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--muted);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.erp-modal-close:hover {
    background: var(--border);
    color: var(--dark);
}

.erp-modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}

/* Los .erp-card dentro del modal no deben tener shadow extra */
.erp-modal-body .erp-card {
    box-shadow: none;
    border: 1px solid var(--border);
    max-width: 100% !important;
}

.erp-modal-loading {
    text-align: center;
    padding: 40px;
    color: var(--muted);
    font-size: .88rem;
}

/* Errores inline dentro del modal */
.erp-modal-body .field-error {
    font-size: .74rem;
    color: #b91c1c;
    font-weight: 600;
    margin-top: 3px;
}

/* ================================================================
   TOAST DE NOTIFICACIONES
   ================================================================ */
.erp-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: .85rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(15,23,42,.15);
    animation: toastIn .25s cubic-bezier(.34,1.56,.64,1);
    min-width: 220px;
    max-width: 380px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.erp-toast.toast-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.erp-toast.toast-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Modal wide para formularios más grandes */
.erp-modal.modal-wide { max-width: 760px; }

/* ================================================================
   DIÁLOGO DE CONFIRMACIÓN
   ================================================================ */
.erp-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeInOverlay .15s ease;
}

.erp-confirm-box {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
    width: 100%;
    max-width: 400px;
    padding: 24px;
    animation: slideUpModal .2s cubic-bezier(.34, 1.56, .64, 1);
}

.erp-confirm-message {
    font-size: .9rem;
    font-weight: 600;
    color: var(--dark);
    line-height: 1.5;
    margin: 0 0 20px;
    text-align: center;
}

.erp-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ================================================================
   BÚSQUEDA Y TABLA PAGINADA
   ================================================================ */
.erp-search-bar {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.erp-search-by {
    max-width: 160px;
    font-size: .82rem;
}

.erp-search-input {
    max-width: 320px;
    flex: 1;
    min-width: 180px;
}

.erp-search-count {
    margin-left: auto;
    font-size: .78rem;
    color: var(--muted);
    font-weight: 600;
}

.erp-search-hint {
    margin: -8px 0 12px;
    font-size: .78rem;
    color: var(--muted);
}

.erp-table-card {
    padding: 0;
    overflow: hidden;
}

.erp-table-footer {
    border-top: 1px solid var(--border);
    background: #f8fafc;
    padding: 14px 16px;
}

/* ================================================================
   PAGINADOR (ventana deslizante)
   ================================================================ */
.erp-pager {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.erp-pager-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.erp-pager-info {
    margin: 0;
    font-size: .78rem;
    color: var(--muted);
    font-weight: 600;
}

.erp-pager-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 800;
    background: color-mix(in srgb, var(--primary) 12%, white);
    color: var(--primary-dark, var(--primary));
    border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}

.erp-pager-perpage {
    font-size: .72rem;
    color: var(--muted);
    font-weight: 600;
}

.erp-pager-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.erp-pager-pages {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.erp-pager-page,
.erp-pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: .8rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid #ddd;
    background: var(--border);
    color: var(--dark);
    transition: background .15s, color .15s, border-color .15s;
}

.erp-pager-page:hover,
.erp-pager-btn:not(.is-disabled):hover {
    border-color: var(--primary);
    color: var(--primary);
}

.erp-pager-page.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 800;
}

.erp-pager-btn.is-disabled {
    opacity: .45;
    cursor: default;
    pointer-events: none;
}

.erp-pager-prev,
.erp-pager-next,
.erp-pager-edge {
    font-size: .75rem;
    font-weight: 700;
    min-width: auto;
    padding: 0 12px;
}

.erp-pager-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 32px;
    font-size: .85rem;
    color: var(--muted);
    user-select: none;
}

