/* =========================================================
   Microsdata ERP - Tema Corporativo
   ========================================================= */

:root {
  --erp-primary: #2563eb;
  --erp-primary-dark: #1e40af;
  --erp-success: #15803d;
  --erp-danger: #b91c1c;
  --erp-dark: #1f2937;
  --erp-muted: #6b7280;
  --erp-border: #d1d5db;
  --erp-bg: #f4f6f9;
  --erp-card: #ffffff;
}

body {
  background: var(--erp-bg);
  color: #111827;
}

.erp-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 18px;
}

.erp-page-header {
  margin-bottom: 18px;
}

.erp-page-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: #111827;
}

.erp-page-subtitle {
  color: var(--erp-muted);
  margin: 0;
}

.erp-card {
  background: var(--erp-card);
  border: 1px solid var(--erp-border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  margin-bottom: 16px;
}

.erp-card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--erp-border);
  font-weight: 700;
  color: #111827;
  background: #f9fafb;
  border-radius: 12px 12px 0 0;
}

.erp-card-body {
  padding: 16px;
}

.erp-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #374151;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-erp-primary {
  background: var(--erp-primary);
  border-color: var(--erp-primary);
  color: #fff;
}

.btn-erp-primary:hover {
  background: var(--erp-primary-dark);
  border-color: var(--erp-primary-dark);
  color: #fff;
}

.btn-erp-secondary {
  background: #ffffff;
  border: 1px solid var(--erp-border);
  color: #374151;
}

.btn-erp-secondary:hover {
  background: #f3f4f6;
  color: #111827;
}

.btn-erp-export {
  background: var(--erp-dark);
  border-color: var(--erp-dark);
  color: #fff;
}

.btn-erp-export:hover {
  background: #111827;
  color: #fff;
}

.btn-erp-success {
  background: var(--erp-success);
  border-color: var(--erp-success);
  color: #fff;
}

.btn-erp-success:hover {
  background: #166534;
  color: #fff;
}

.btn-erp-danger {
  background: var(--erp-danger);
  border-color: var(--erp-danger);
  color: #fff;
}

.btn-erp-danger:hover {
  background: #991b1b;
  color: #fff;
}

.erp-table {
  font-size: 0.86rem;
}

.erp-table thead th {
  background: #f3f4f6;
  color: #374151;
  font-weight: 700;
  border-bottom: 1px solid var(--erp-border);
  white-space: nowrap;
}

.erp-table td {
  vertical-align: middle;
}

.erp-code {
  color: #be185d;
  font-weight: 700;
  font-size: 0.82rem;
}

.erp-actions-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.erp-muted {
  color: var(--erp-muted);
}

.erp-upload-zone {
  background: #f9fafb;
  border: 1px dashed #9ca3af;
  border-radius: 12px;
  padding: 16px;
}

/* =========================================================
   SIDEBAR ERP FIJO / SCROLL INTERNO
   ========================================================= */
.erp-layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 56px);
}

.erp-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 260px;
  max-width: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  scrollbar-width: thin;
}

.erp-main {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

/* Evita que el botón inferior tape contenido en formularios largos */
.erp-main .sticky-bottom {
  z-index: 20;
}

/* Scroll más limpio en Chrome/Safari */
.erp-sidebar::-webkit-scrollbar {
  width: 6px;
}

.erp-sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.25);
  border-radius: 8px;
}

.erp-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

/* =========================================================
   FIX RESPONSIVE SIDEBAR ERP - MÓVIL
   ========================================================= */
@media (max-width: 768px) {
  .erp-layout {
    display: block !important;
    min-height: auto !important;
  }

  .erp-sidebar {
    position: relative !important;
    top: auto !important;
    height: auto !important;
    min-width: 100% !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    display: block !important;
  }

  .erp-menu {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
    overflow-x: auto !important;
    padding: 12px !important;
    white-space: nowrap !important;
  }

  .erp-menu .menu-section {
    display: none !important;
  }

  .erp-menu .menu-item {
    flex: 0 0 auto !important;
    min-width: auto !important;
    white-space: nowrap !important;
  }

  .erp-main {
    width: 100% !important;
    overflow-x: auto !important;
  }

  .container,
  .container-fluid {
    max-width: 100% !important;
  }
}

/* =========================================================
   HARD FIX MOBILE ERP SIDEBAR
   ========================================================= */
@media screen and (max-width: 991.98px) {
  body {
    overflow-x: hidden !important;
  }

  .erp-layout {
    display: block !important;
    width: 100% !important;
    min-height: auto !important;
  }

  .erp-sidebar {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    height: auto !important;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    padding: 10px !important;
  }

  .erp-brand {
    margin-bottom: 8px !important;
  }

  .erp-menu {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    gap: 8px !important;
    padding: 8px 0 !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .erp-menu .menu-section {
    display: none !important;
  }

  .erp-menu .menu-item {
    flex: 0 0 auto !important;
    width: auto !important;
    max-width: none !important;
    white-space: nowrap !important;
    padding: 10px 14px !important;
    border-radius: 12px !important;
  }

  .erp-main {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    overflow-x: auto !important;
  }

  .erp-main .container,
  .erp-main .container-fluid {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}

/* =========================================================
   UX FINAL MÓVIL: OCULTAR SIDEBAR Y USAR NAVBAR SUPERIOR
   ========================================================= */
@media screen and (max-width: 991.98px) {
  .erp-layout {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .erp-sidebar {
    display: none !important;
  }

  .erp-main {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden !important;
  }

  .erp-main .container,
  .erp-main .container-fluid {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  body {
    overflow-x: hidden !important;
  }

  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* =========================================================
   OVERRIDE FINAL: SIDEBAR SOLO EN ESCRITORIO REAL
   ========================================================= */
@media screen and (max-width: 1200px), screen and (pointer: coarse) {
  aside.erp-sidebar {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  div.erp-layout {
    display: block !important;
  }

  main.erp-main {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
  }
}

/* =========================================================
   MOBILE UX ENTERPRISE FINAL
   ========================================================= */
@media screen and (max-width: 768px) {

  .navbar-brand {
    max-width: 70%;
  }

  .navbar-brand-title {
    font-size: 1.1rem !important;
    line-height: 1.1 !important;
  }

  .navbar-brand-subtitle {
    font-size: 0.78rem !important;
  }

  #topNav {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  .container,
  .container-fluid {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  h1, h2, h3 {
    font-size: 1.7rem !important;
    line-height: 1.15 !important;
    word-break: break-word !important;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 44px !important;
    font-size: 16px !important;
  }

  .d-flex.gap-2,
  .d-flex.gap-3 {
    flex-wrap: wrap !important;
  }

  .table-responsive {
    border-radius: 12px !important;
  }

  .card,
  .stat-card,
  .erp-card {
    border-radius: 16px !important;
  }

  .navbar-collapse {
    background: #161b22 !important;
    border-radius: 14px !important;
    padding: 10px !important;
    margin-top: 10px !important;
  }

  .navbar-nav .nav-link {
    padding: 12px 10px !important;
    border-radius: 10px !important;
  }

  .navbar-toggler {
    padding: 10px 12px !important;
  }
}

/* =========================================================
   MOBILE OFFCANVAS ERP FINAL
   ========================================================= */
@media screen and (max-width: 991.98px) {
  aside.erp-sidebar {
    display: none !important;
  }

  .navbar-collapse#topNav {
    display: none !important;
  }

  .offcanvas.mobile-erp-menu,
  .mobile-erp-menu {
    font-size: 1rem;
  }

  .mobile-erp-menu .list-group-item {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 6px;
  }

  .erp-main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body {
    overflow-x: hidden !important;
  }
}

@media screen and (min-width: 992px) {
  #mobileErpMenu {
    display: none !important;
  }
}

/* =========================================================
   Sidebar ejecutivo colapsable · Microsdata ERP
   ========================================================= */
.erp-brand-corporate {
  padding: 14px 14px 12px;
  gap: 10px;
}

.erp-sidebar-logo {
  height: 42px;
  max-width: 160px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 4px 8px;
}

.erp-menu-compact {
  padding: 8px 10px 18px;
}

.erp-menu-compact .menu-section {
  margin: 14px 8px 6px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(226,232,240,.58);
}

.menu-group {
  margin: 6px 0;
  border: 1px solid rgba(148,163,184,.16);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(15,23,42,.18);
}

.menu-group summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
  color: #e5e7eb;
  font-size: 13px;
  font-weight: 700;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.menu-group summary::-webkit-details-marker {
  display: none;
}

.menu-group summary::after {
  content: "›";
  font-size: 18px;
  color: #94a3b8;
  transition: transform .16s ease;
}

.menu-group[open] summary::after {
  transform: rotate(90deg);
}

.menu-group[open] summary {
  background: rgba(255,106,0,.12);
  color: #fff;
}

.erp-menu-compact .menu-item {
  margin: 3px 6px;
  padding: 8px 10px 8px 16px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.15;
}

.erp-menu-compact .menu-item.active {
  background: linear-gradient(90deg, rgba(255,106,0,.95), rgba(249,115,22,.74));
  color: #fff;
  box-shadow: 0 6px 18px rgba(255,106,0,.22);
}

.erp-menu-compact .menu-item.logout {
  color: #fecaca;
}

/* Fix logo sidebar facturación/ERP */
.erp-brand-corporate {
  min-height: 72px;
  align-items: center;
}

.erp-sidebar-logo {
  display: block !important;
  width: 52px !important;
  height: 52px !important;
  min-width: 52px !important;
  object-fit: contain !important;
  background: #ffffff !important;
  border-radius: 12px !important;
  padding: 4px !important;
}
