/* Navegación inspirada en SAP Fiori Horizon.
   Esta capa es exclusivamente visual: no cambia el orden, rutas ni permisos. */
:root {
  --fiori-nav-canvas: #f7f7f7;
  --fiori-nav-surface: #ffffff;
  --fiori-nav-border: #d5dadd;
  --fiori-nav-text: #1d2d3e;
  --fiori-nav-muted: #556b82;
  --fiori-nav-accent: #0a6ed1;
  --fiori-nav-active: #eaf3fc;
  --fiori-nav-hover: #edf5fc;
}

#appView .sidebar {
  gap: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--fiori-nav-canvas);
  border-right: 1px solid var(--fiori-nav-border);
  box-shadow: 2px 0 8px rgba(34, 53, 72, 0.12);
  scrollbar-color: #a8b3bd transparent;
}

#appView .sidebar .brand {
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  min-height: 72px;
  margin: 0;
  padding: 12px 16px;
  background: var(--fiori-nav-surface);
  border-bottom: 1px solid var(--fiori-nav-border);
}

#appView .sidebar .brand::after {
  display: none;
}

#appView .sidebar .brand-logo {
  width: 68px;
  max-height: 48px;
  object-fit: contain;
}

#appView .sidebar .brand strong {
  color: var(--fiori-nav-text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

#appView .sidebar .brand small {
  margin-top: 3px;
  color: var(--fiori-nav-muted);
  font-size: 12px;
  font-weight: 500;
}

#appView .sidebar-search {
  min-height: 38px;
  margin: 12px 12px 8px;
  padding: 0 8px 0 10px;
  background: var(--fiori-nav-surface);
  border: 1px solid #89919a;
  border-radius: 4px;
  color: var(--fiori-nav-muted);
  box-shadow: none;
}

#appView .sidebar-search:focus-within {
  background: var(--fiori-nav-surface);
  border-color: var(--fiori-nav-accent);
  box-shadow: inset 0 0 0 1px var(--fiori-nav-accent);
}

#appView .sidebar-search input,
#appView .sidebar-search input:focus {
  min-height: 36px;
  color: var(--fiori-nav-text);
  font-size: 13px;
  font-weight: 500;
}

#appView .sidebar-search .nav-icon {
  width: 17px;
  height: 17px;
  color: var(--fiori-nav-muted);
}

#appView .sidebar-search button:hover {
  color: var(--fiori-nav-accent);
  background: var(--fiori-nav-hover);
}

#appView .sidebar-search-empty {
  margin: 0 12px 8px;
  border-radius: 4px;
}

#appView .sidebar .nav {
  gap: 2px;
  padding: 0 8px 16px;
}

#appView .sidebar .nav-item,
#appView .sidebar .submenu button {
  position: relative;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--fiori-nav-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: none;
}

#appView .sidebar .nav-item:hover,
#appView .sidebar .submenu button:hover {
  background: var(--fiori-nav-hover);
  border-color: transparent;
  color: #074b78;
}

#appView .sidebar .nav-item.active,
#appView .sidebar .submenu button.active {
  background: var(--fiori-nav-active);
  border-color: transparent;
  color: #004b76;
  box-shadow: inset 3px 0 0 var(--fiori-nav-accent);
}

#appView .sidebar .nav-item.active::after,
#appView .sidebar .submenu button.active::after {
  display: none;
}

#appView .sidebar .nav-icon {
  width: 19px;
  height: 19px;
  color: currentColor;
  stroke-width: 1.9;
}

#appView .sidebar .nav-label {
  gap: 10px;
}

#appView .sidebar .nav-caret {
  color: #5b738b;
  font-size: 13px;
}

#appView .sidebar .submenu {
  gap: 1px;
  margin: 0 0 4px 12px;
  padding: 2px 0 2px 6px;
  border-left: 1px solid var(--fiori-nav-border);
}

#appView .sidebar .submenu button {
  min-height: 36px;
  padding: 7px 9px;
  font-size: 13px;
  font-weight: 500;
}

#appView .sidebar .submenu .nav-icon {
  width: 17px;
  height: 17px;
}

#appView #productionMenu .production-section {
  margin: 1px 0;
}

#appView #productionMenu .production-section-toggle {
  min-height: 36px;
  margin: 1px 0;
  padding: 7px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--fiori-nav-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: none;
}

#appView #productionMenu .production-section-toggle:hover,
#appView #productionMenu .production-section-toggle.active {
  background: #eef1f3;
  border-color: transparent;
  color: var(--fiori-nav-text);
}

#appView #productionMenu .production-section-menu {
  margin: 0 0 4px 10px;
  padding: 1px 0 2px 6px;
  border-left: 1px solid var(--fiori-nav-border);
}

#appView .sidebar .session {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr);
  gap: 8px;
  margin-top: auto;
  padding: 12px;
  background: var(--fiori-nav-surface);
  border: 0;
  border-top: 1px solid var(--fiori-nav-border);
  border-radius: 0;
}

#appView .sidebar .session span {
  grid-column: 1 / -1;
  padding: 0;
  color: var(--fiori-nav-text);
  font-size: 12px;
  font-weight: 700;
}

#appView .sidebar .session button {
  min-height: 34px;
  padding: 7px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  box-shadow: none;
}

#appView .sidebar .session .session-secondary {
  color: #075985;
  background: #fff;
  border-color: #91c8f6;
}

#appView .sidebar .session #logoutButton {
  color: #aa0808;
  background: #fff;
  border-color: #ffb3b3;
}

@media (min-width: 1181px) {
  #appView.app {
    grid-template-columns: 272px minmax(0, 1fr);
  }
}

@media (max-width: 1180px) {
  #appView .sidebar {
    width: min(320px, calc(100vw - 42px));
    padding: 0;
    background: var(--fiori-nav-canvas);
    box-shadow: 12px 0 32px rgba(34, 53, 72, 0.26);
  }

  #appView .sidebar .brand {
    position: sticky;
    top: 0;
    z-index: 5;
  }

  #appView .sidebar-search {
    position: sticky;
    top: 72px;
    z-index: 4;
    margin: 10px 12px 8px;
    box-shadow: 0 5px 10px rgba(34, 53, 72, 0.08);
  }

  #appView .sidebar .nav {
    padding-right: 8px;
    padding-left: 8px;
  }
}

@media (max-width: 430px) {
  #appView .sidebar {
    width: min(304px, calc(100vw - 28px));
  }

  #appView .sidebar .brand {
    grid-template-columns: 58px minmax(0, 1fr);
    min-height: 66px;
    padding: 9px 12px;
  }

  #appView .sidebar .brand-logo {
    width: 58px;
  }

  #appView .sidebar-search {
    top: 66px;
  }
}

/* Capa final de prioridad.
   La aplicación aplica estados visuales al navegar; estas reglas garantizan que
   esos estados conserven el tema Fiori sin modificar display, eventos o permisos. */
html body #appView.app .sidebar {
  gap: 0 !important;
  padding: 0 !important;
  background: var(--fiori-nav-canvas) !important;
  border-right: 1px solid var(--fiori-nav-border) !important;
  box-shadow: 2px 0 8px rgba(34, 53, 72, 0.12) !important;
}

html body #appView.app .sidebar .brand {
  grid-template-columns: 68px minmax(0, 1fr) !important;
  gap: 12px !important;
  min-height: 72px !important;
  margin: 0 !important;
  padding: 12px 16px !important;
  background: var(--fiori-nav-surface) !important;
  border-bottom: 1px solid var(--fiori-nav-border) !important;
}

html body #appView.app .sidebar .brand-logo {
  width: 68px !important;
  max-height: 48px !important;
}

html body #appView.app .sidebar-search {
  min-height: 38px !important;
  margin: 12px 12px 8px !important;
  padding: 0 8px 0 10px !important;
  background: var(--fiori-nav-surface) !important;
  border: 1px solid #89919a !important;
  border-radius: 4px !important;
  box-shadow: none !important;
}

html body #appView.app .sidebar .nav {
  gap: 2px !important;
  padding: 0 8px 16px !important;
}

html body #appView.app .sidebar .nav-item,
html body #appView.app .sidebar .submenu button {
  min-height: 40px !important;
  padding: 8px 10px !important;
  border: 0 !important;
  border-radius: 4px !important;
  background: transparent !important;
  color: var(--fiori-nav-text) !important;
  font-weight: 600 !important;
  box-shadow: none !important;
}

html body #appView.app .sidebar .nav-item:hover,
html body #appView.app .sidebar .submenu button:hover {
  background: var(--fiori-nav-hover) !important;
  color: #074b78 !important;
}

html body #appView.app .sidebar .nav-item.active,
html body #appView.app .sidebar .submenu button.active {
  background: var(--fiori-nav-active) !important;
  color: #004b76 !important;
  box-shadow: inset 3px 0 0 var(--fiori-nav-accent) !important;
}

html body #appView.app .sidebar .nav-item.active::after,
html body #appView.app .sidebar .submenu button.active::after {
  display: none !important;
}

html body #appView.app .sidebar .submenu {
  gap: 1px !important;
  margin: 0 0 4px 12px !important;
  padding: 2px 0 2px 6px !important;
  border-left: 1px solid var(--fiori-nav-border) !important;
}

html body #appView.app #productionMenu .production-section-toggle {
  min-height: 36px !important;
  margin: 1px 0 !important;
  padding: 7px 9px !important;
  border: 0 !important;
  border-radius: 4px !important;
  background: transparent !important;
  color: var(--fiori-nav-muted) !important;
  font-weight: 700 !important;
  box-shadow: none !important;
}

html body #appView.app #productionMenu .production-section-toggle:hover,
html body #appView.app #productionMenu .production-section-toggle.active {
  background: #eef1f3 !important;
  color: var(--fiori-nav-text) !important;
}

html body #appView.app .sidebar .session {
  margin-top: auto !important;
  padding: 12px !important;
  background: var(--fiori-nav-surface) !important;
  border: 0 !important;
  border-top: 1px solid var(--fiori-nav-border) !important;
  border-radius: 0 !important;
}

@media (min-width: 1181px) {
  html body #appView.app {
    grid-template-columns: 272px minmax(0, 1fr) !important;
  }
}

/* iPad y tabletas grandes en horizontal.
   Mantiene el escritorio sin cambios y convierte solo la navegación táctil en
   un panel temporal, para que los formularios aprovechen todo el ancho. */
@media screen {
  html body.tablet-navigation #appView.app {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  html body.tablet-navigation #appView.app .content {
    width: 100% !important;
    min-width: 0 !important;
    padding: 66px 16px 24px !important;
    overflow-x: hidden !important;
  }

  html body.tablet-navigation #appView.app .topbar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: 0 !important;
    z-index: 40 !important;
    min-height: 58px !important;
    margin: 0 !important;
    padding: 9px 16px 9px 68px !important;
  }

  html body.tablet-navigation #appView.app .topbar .page-icon {
    display: none !important;
  }

  html body.tablet-navigation #appView.app .mobile-menu-button {
    position: fixed !important;
    top: 11px !important;
    left: 12px !important;
    z-index: 80 !important;
    display: grid !important;
    width: 44px !important;
    height: 44px !important;
    padding: 10px !important;
    place-items: center !important;
    gap: 4px !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 7px !important;
    background: var(--app-header) !important;
    box-shadow: 0 5px 15px rgba(12, 48, 34, 0.2) !important;
  }

  html body.tablet-navigation #appView.app .mobile-menu-button span {
    display: block !important;
    width: 22px !important;
    height: 2px !important;
    border-radius: 999px !important;
    background: #fff !important;
  }

  html body.tablet-navigation #appView.app .sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    z-index: 70 !important;
    width: min(330px, calc(100vw - 42px)) !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-y: auto !important;
    transform: translateX(-105%) !important;
    transition: transform 0.22s ease !important;
    box-shadow: 18px 0 44px rgba(12, 38, 25, 0.22) !important;
  }

  html body.tablet-navigation.menu-open #appView.app .sidebar {
    transform: translateX(0) !important;
  }

  html body.tablet-navigation #appView.app .sidebar-overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 60 !important;
    display: none !important;
    border: 0 !important;
    background: rgba(8, 26, 17, 0.48) !important;
    backdrop-filter: blur(2px) !important;
  }

  html body.tablet-navigation.menu-open #appView.app .sidebar-overlay {
    display: block !important;
  }
}

/* iPad workflow alignment.
   Wide operational tables must scroll inside their own container; they must
   never enlarge the page or leave the form parked after the hidden sidebar. */
@media screen {
  html body.tablet-navigation {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  html body.tablet-navigation #appView,
  html body.tablet-navigation #appView.app,
  html body.tablet-navigation #appView.app .content,
  html body.tablet-navigation #appView.app .view,
  html body.tablet-navigation #appView.app .view.active-view {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-right: 0 !important;
    margin-left: 0 !important;
  }

  html body.tablet-navigation #appView.app .view.active-view {
    animation: none !important;
    transform: none !important;
  }

  html body.tablet-navigation #entrada-pt-auto,
  html body.tablet-navigation #transfer-checkout,
  html body.tablet-navigation #transfer-checkout-detail,
  html body.tablet-navigation #transfer-checkin,
  html body.tablet-navigation #transfer-checkin-detail,
  html body.tablet-navigation #entrada-pt-auto > .automatic-receipt-panel,
  html body.tablet-navigation #transfer-checkout > .panel,
  html body.tablet-navigation #transfer-checkout-detail > .panel,
  html body.tablet-navigation #transfer-checkin > .panel,
  html body.tablet-navigation #transfer-checkin-detail > .panel {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  html body.tablet-navigation #entrada-pt-auto .automatic-receipt-fields,
  html body.tablet-navigation #entrada-pt-auto .automatic-receipt-fields > *,
  html body.tablet-navigation #transfer-checkout-detail .transfer-detail-info,
  html body.tablet-navigation #transfer-checkin-detail .transfer-detail-info {
    min-width: 0 !important;
  }

  html body.tablet-navigation #entrada-pt-auto .automatic-receipt-table-wrap,
  html body.tablet-navigation #transfer-checkout .transfer-operation-list-table,
  html body.tablet-navigation #transfer-checkout-detail .table-wrap,
  html body.tablet-navigation #transfer-checkin .transfer-operation-list-table,
  html body.tablet-navigation #transfer-checkin-detail .table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  html body.tablet-navigation #entrada-pt-auto .automatic-receipt-actions {
    right: max(18px, env(safe-area-inset-right)) !important;
    left: max(18px, env(safe-area-inset-left)) !important;
    width: auto !important;
    max-width: none !important;
  }
}

/* Safari on iPad can delay or omit the JavaScript device class while restoring
   a tab. The touch-only media query keeps the layout safe during that instant. */
@media (hover: none) and (pointer: coarse) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  html body #appView.app {
    display: block !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  html body #appView.app .content,
  html body #appView.app .view,
  html body #appView.app .panel {
    max-width: 100% !important;
    min-width: 0 !important;
  }

  html body #entrada-pt-auto .automatic-receipt-table-wrap,
  html body #transfer-checkout .transfer-operation-list-table,
  html body #transfer-checkout-detail .table-wrap,
  html body #transfer-checkin .transfer-operation-list-table,
  html body #transfer-checkin-detail .table-wrap {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: auto !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
}
