/* Patrón global ALCAUR: reutiliza la misma rejilla floral rosa del login. */
:root {
  --alcaur-pink-bg: #fff0f6;
  --alcaur-pink-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='83' viewBox='0 0 48 83'%3E%3Cg transform='translate%280 0%29'%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%280%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%2860%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28120%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28180%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28240%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28300%29'/%3E%3Ccircle r='2.7' fill='%23fff4f8' fill-opacity='0.55'/%3E%3C/g%3E%3Cg transform='translate%2848 0%29'%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%280%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%2860%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28120%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28180%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28240%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28300%29'/%3E%3Ccircle r='2.7' fill='%23fff4f8' fill-opacity='0.55'/%3E%3C/g%3E%3Cg transform='translate%280 83%29'%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%280%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%2860%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28120%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28180%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28240%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28300%29'/%3E%3Ccircle r='2.7' fill='%23fff4f8' fill-opacity='0.55'/%3E%3C/g%3E%3Cg transform='translate%2848 83%29'%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%280%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%2860%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28120%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28180%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28240%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28300%29'/%3E%3Ccircle r='2.7' fill='%23fff4f8' fill-opacity='0.55'/%3E%3C/g%3E%3Cg transform='translate%2824 41.5%29'%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%280%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%2860%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28120%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28180%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28240%29'/%3E%3Cellipse cx='0' cy='-8' rx='4.2' ry='7.6' fill='%23e58fb0' fill-opacity='0.15' transform='rotate%28300%29'/%3E%3Ccircle r='2.7' fill='%23fff4f8' fill-opacity='0.55'/%3E%3C/g%3E%3C/svg%3E");
}

body.light-mode {
  background-color: var(--alcaur-pink-bg);
  background-image: var(--alcaur-pink-pattern);
  background-repeat: repeat;
  background-size: 48px 83px;
}

/* La pantalla de carga mantiene el patrón mientras corre la animación. */
#loading-overlay {
  background-color: var(--alcaur-pink-bg) !important;
  background-image: var(--alcaur-pink-pattern) !important;
  background-repeat: repeat;
  background-size: 48px 83px;
}

/* La suite conserva sus paneles y controles; solo se unifica la superficie de fondo. */
body.light-mode #market-app,
body.light-mode #market-app > div:first-child,
body.light-mode #market-app .app-container,
body.light-mode #market-app .main-content,
body.light-mode #market-app .right-sidebar,
body.light-mode #market-app .sidebar {
  background-color: rgba(255, 240, 246, 0.94) !important;
  background-image: var(--alcaur-pink-pattern) !important;
  background-repeat: repeat;
  background-size: 48px 83px;
}

/* Respeta las superficies de tarjetas, formularios y modales que contienen la información. */
body.light-mode #market-app .panel,
body.light-mode #market-app .form-card,
body.light-mode #market-app .product-card,
body.light-mode #market-app .invoice-card,
body.light-mode #market-app .modal,
body.light-mode #market-app .drawer,
body.light-mode #market-app .app-header {
  background-image: none !important;
}

/* Tema único de la aplicación: rosa claro, sin modo oscuro. */
body.light-mode {
  --black: #fff0f6;
  --black-2: #fbd8e6;
  --black-3: #f8cadb;
  --black-4: #f4bdd2;
  --black-5: #e9a9c2;
  --black-6: #d98fab;
  --adaptive-text: #24131b;
  --white: #24131b;
  --white-60: rgba(36, 19, 27, 0.68);
  --white-30: rgba(36, 19, 27, 0.42);
  --white-15: rgba(36, 19, 27, 0.20);
  --surface-border-current: rgba(161, 15, 98, 0.20);
  color: #24131b;
  background-color: var(--alcaur-pink-bg) !important;
  background-image: var(--alcaur-pink-pattern) !important;
}

#header-theme-toggle,
.header-theme-trigger,
.header-theme-tooltip {
  display: none !important;
}

body.light-mode #market-app,
body.light-mode #market-app > div:first-child,
body.light-mode #market-app .app-container,
body.light-mode #market-app .main-content,
body.light-mode #market-app .sidebar,
body.light-mode #market-app .right-sidebar,
body.light-mode #market-app .app-header,
body.light-mode #market-app .panel,
body.light-mode #market-app .form-card,
body.light-mode #market-app .product-card,
body.light-mode #market-app .invoice-card,
body.light-mode #market-app .conv-section,
body.light-mode #market-app .variety-counter,
body.light-mode #market-app .header-rates-panel,
body.light-mode #market-app .modal-content {
  background-color: rgba(255, 205, 222, 0.94) !important;
  background-image: var(--alcaur-pink-pattern) !important;
  background-repeat: repeat;
  background-size: 48px 83px;
  color: #24131b !important;
  border-color: rgba(161, 15, 98, 0.20) !important;
}

body.light-mode #market-app .app-header {
  background-color: rgba(250, 190, 211, 0.97) !important;
  box-shadow: 0 2px 12px rgba(161, 15, 98, 0.12) !important;
}

body.light-mode #market-app .sidebar,
body.light-mode #market-app .right-sidebar {
  background-color: rgba(248, 194, 215, 0.96) !important;
}

body.light-mode #market-app .panel:hover,
body.light-mode #market-app .product-card:hover,
body.light-mode #market-app .invoice-card:hover {
  border-color: rgba(161, 15, 98, 0.34) !important;
}

body.light-mode #market-app .nav-bar,
body.light-mode #market-app .top-nav,
body.light-mode #market-app .header-main-content {
  background: transparent !important;
}

/* Herramientas contextuales: el antiguo lateral derecho ahora vive bajo la barra superior. */
@media (min-width: 769px) {
  body .app-container,
  body.invoice-tools-visible .app-container,
  body.products-tools-visible .app-container {
    margin-right: 0 !important;
    width: 100% !important;
  }
}

#right-sidebar,
body:not(.context-tools-open) #right-sidebar {
  display: none !important;
  position: fixed !important;
  top: 104px !important;
  right: 16px !important;
  left: auto !important;
  width: min(430px, calc(100vw - 32px)) !important;
  height: min(680px, calc(100vh - 124px)) !important;
  max-height: calc(100vh - 124px) !important;
  z-index: 1400 !important;
  overflow: auto !important;
  border: 1px solid rgba(161, 15, 98, 0.24) !important;
  border-radius: 14px !important;
  background: rgba(255, 205, 222, 0.98) !important;
  background-image: var(--alcaur-pink-pattern) !important;
  box-shadow: 0 16px 38px rgba(161, 15, 98, 0.22) !important;
}

body.context-tools-open #right-sidebar {
  display: block !important;
}

#right-sidebar > .invoice-side-tools,
#right-sidebar > #stock-expiry-side-tools,
#right-sidebar > .product-side-tools {
  display: none !important;
  box-sizing: border-box;
  min-height: 100%;
}

body.context-tools-open #right-sidebar > .invoice-side-tools.context-tools-active,
body.context-tools-open #right-sidebar > #stock-expiry-side-tools.context-tools-active,
body.context-tools-open #right-sidebar > .product-side-tools.context-tools-active {
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  padding: 14px !important;
  gap: 10px !important;
}

body.light-mode #right-sidebar,
body.light-mode #right-sidebar .cashier-right-card,
body.light-mode #right-sidebar .clients-side-card,
body.light-mode #right-sidebar .stock-expiry-side-card,
body.light-mode #right-sidebar .product-side-tools .panel.expandable-panel {
  background-color: rgba(255, 205, 222, 0.98) !important;
  background-image: var(--alcaur-pink-pattern) !important;
  color: #24131b !important;
  border-color: rgba(161, 15, 98, 0.22) !important;
}

.header-context-trigger.open {
  background: rgba(161, 15, 98, 0.14) !important;
  color: #8f155e !important;
}

@media (max-width: 768px) {
  #right-sidebar {
    top: 78px !important;
    right: 10px !important;
    width: calc(100vw - 20px) !important;
    height: calc(100vh - 94px) !important;
    max-height: calc(100vh - 94px) !important;
  }
}

/* Corrección de apertura: el estado vive en #right-sidebar, no en body. */
#right-sidebar.context-tools-open {
  display: block !important;
}
#right-sidebar.context-tools-open > .invoice-side-tools.context-tools-active,
#right-sidebar.context-tools-open > #stock-expiry-side-tools.context-tools-active,
#right-sidebar.context-tools-open > .product-side-tools.context-tools-active {
  display: flex !important;
}

/* La regla heredada usa body:not(...); esta declaración tiene la misma especificidad y prevalece al abrir. */
body #right-sidebar.context-tools-open {
  display: block !important;
}
