/*
 * Capa responsive localizada. Se carga al final para corregir límites del
 * layout sin reescribir el rediseño ni ocultar desbordamientos.
 */
html {
  box-sizing: border-box;
  min-width: 0;
  overflow-x: auto;
}

*, *::before, *::after { box-sizing: inherit; }

body.app-redesign,
body.app-redesign .app-header-wrapper,
body.app-redesign .main-content,
body.app-redesign .section-content,
body.app-redesign .section-heading,
body.app-redesign .section-heading-copy {
  min-width: 0;
  max-width: 100%;
}

body.app-redesign {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: env(safe-area-inset-bottom);
}

body.app-redesign img,
body.app-redesign svg,
body.app-redesign canvas,
body.app-redesign video { max-width: 100%; }

body.app-redesign .pos-loading-state {
  display: flex;
  align-items: center;
  min-height: 3rem;
  padding: .85rem 1rem;
  color: var(--text-muted, #a1a1aa);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .01em;
}

/* First paint follows the same global frame and POS regions as the mounted view. */
.app-boot-placeholder {
  position: fixed;
  inset: 0;
  z-index: 4500;
  overflow: auto;
  padding: 0 0 1rem;
  color: var(--text-muted, #a1a1aa);
  background: var(--bg-main, #111318);
}
.boot-shell-skeleton { width: min(100%, 1440px); min-height: 100%; margin: 0 auto; }
.boot-header-skeleton { display: grid; grid-template-columns: 44px minmax(8rem, 1fr) minmax(12rem, 1.5fr) 8rem; align-items: center; gap: .85rem; min-height: 92px; padding: 1rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.boot-brand-mark { width: 44px; height: 44px; border-radius: 50%; }
.boot-brand-copy { display: grid; gap: .4rem; }
.boot-brand-copy i { width: 75%; height: .65rem; }
.boot-brand-copy i + i { width: 52%; height: .5rem; }
.boot-context-title { width: min(16rem, 90%); height: 1.15rem; justify-self: center; }
.boot-header-action { width: 100%; height: 2.5rem; border-radius: 999px; }
.boot-mobile-nav-skeleton { display: none; }
.boot-pos-skeleton { display: grid; gap: .8rem; padding: 1rem 1.25rem; }
.boot-search { width: min(100%, 640px); height: 2.8rem; justify-self: center; border-radius: 999px; }
.boot-accounts-skeleton, .boot-products-skeleton { display: grid; gap: .75rem; padding: 1rem; border: 1px solid rgba(255,255,255,.08); border-radius: 1rem; background: rgba(255,255,255,.025); }
.boot-accounts-skeleton > i, .boot-products-skeleton > i { width: 7rem; height: .9rem; }
.boot-accounts-skeleton > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: .6rem; }
.boot-accounts-skeleton b { height: 5rem; border-radius: .8rem; }
.boot-products-skeleton > div { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: .6rem; }
.boot-products-skeleton b { height: 5rem; border-radius: .8rem; }
.boot-loading-label { display: block; padding: 0 1.25rem; text-align: center; font-size: .75rem; font-weight: 700; }

body.app-redesign .pos-accounts-loading { display: grid; grid-template-columns: minmax(0, 1fr); gap: .55rem; width: 100%; padding: .1rem 0 .4rem; }
body.app-redesign .pos-accounts-loading > span { min-width: 0; height: 4rem; border-radius: .8rem; }
body.app-redesign .pos-products-loading { display: block; width: 100%; padding: 0; }
.pos-products-loading-compact { display: none; }
.pos-products-loading-catalog { width: 100%; }
.pos-products-loading-catalog > span { display: block; width: 7rem; height: 1rem; margin: .2rem 0 .8rem; }
.pos-products-loading-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: .55rem; }
.pos-products-loading-grid > i { height: 5.5rem; border-radius: .8rem; }

body.app-redesign .full-width-products > .pos-loading-state {
  min-height: 7rem;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  background: rgba(255,255,255,.025);
}

@media (max-width: 600px) {
  .boot-header-skeleton { grid-template-columns: 38px minmax(0, 1fr) 5rem; min-height: 76px; padding: .75rem; gap: .55rem; }
  .boot-brand-mark { width: 38px; height: 38px; }
  .boot-context-title { display: none; }
  .boot-header-action { height: 2rem; }
  .boot-mobile-nav-skeleton { position: fixed; right: 0; bottom: 0; left: 0; z-index: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; min-height: calc(4rem + env(safe-area-inset-bottom)); padding: .7rem .85rem max(.7rem, env(safe-area-inset-bottom)); border-top: 1px solid rgba(255,255,255,.08); background: var(--color-surface, #171a20); }
  .boot-mobile-nav-skeleton i { min-height: 2.25rem; border-radius: .7rem; }
  .boot-pos-skeleton { gap: .55rem; padding: .65rem .75rem; }
  .boot-accounts-skeleton, .boot-products-skeleton { padding: .7rem; border-radius: .85rem; }
  .boot-accounts-skeleton > div { grid-template-columns: 1fr; }
  .boot-accounts-skeleton b { height: 3.5rem; }
  .boot-products-skeleton > div { display: none; }
  .boot-products-skeleton::after { content: ""; display: block; width: 100%; height: 3.4rem; border-radius: .75rem; background: linear-gradient(90deg, var(--color-surface-raised) 25%, var(--color-surface-hover) 50%, var(--color-surface-raised) 75%); background-size: 200% 100%; animation: ui-shimmer 1.35s ease-in-out infinite; }
  .pos-products-loading-compact { display: grid; grid-template-columns: 2rem minmax(0, 1fr) 1rem; align-items: center; gap: .65rem; min-height: 54px; }
  .pos-products-loading-compact > span { width: 2rem; height: 2rem; border-radius: .55rem; }
  .pos-products-loading-compact > i { width: min(10rem, 100%); height: 1rem; }
  .pos-products-loading-compact > b { width: 1rem; height: 1rem; }
  .pos-products-loading-catalog { display: none; }
  body.app-redesign .pos-accounts-loading { grid-template-columns: 1fr; }
  body.app-redesign .pos-accounts-loading > span { height: 3.5rem; }
}

body.app-redesign button,
body.app-redesign input,
body.app-redesign select,
body.app-redesign textarea { max-width: 100%; }

/* El menú de perfil se ancla al botón visible, no al ancho comprimido de la
   celda del encabezado. Así permanece junto a la tarjeta y dentro del viewport. */
body.app-redesign #profileMenu {
  position: fixed !important;
  top: var(--profile-menu-top, 4.5rem) !important;
  right: var(--profile-menu-right, .65rem) !important;
  left: auto !important;
  width: min(var(--profile-menu-width, 18rem), calc(100vw - 1rem)) !important;
  max-width: calc(100vw - 1rem) !important;
  max-height: calc(100dvh - var(--profile-menu-top, 4.5rem) - .75rem) !important;
  overflow-y: auto;
}

/* Eliminar queda dentro de la tarjeta, separado del nombre y de la etiqueta
   de servicio; así no se corta ni parece flotar fuera del pedido. */
body.app-redesign .open-accounts-scroll .account-chip {
  position: relative;
  overflow: hidden;
}

body.app-redesign .open-accounts-scroll .account-chip:not(.account-chip-add-btn) .account-chip-main {
  padding-right: 1.85rem;
}

body.app-redesign .open-accounts-scroll .btn-chip-close {
  top: .45rem;
  right: .45rem;
  width: 1.65rem;
  height: 1.65rem;
  border-width: 1px;
  font-size: .82rem;
}

body.app-redesign button,
body.app-redesign [role="button"],
body.app-redesign input[type="button"],
body.app-redesign input[type="submit"] {
  min-height: 44px;
}

body.app-redesign .modal-overlay {
  align-items: flex-start;
  justify-content: center;
  min-height: 100dvh;
  padding: max(.75rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
  overflow-y: auto;
}

body.app-redesign .modal-card {
  width: min(100%, 760px);
  min-width: 0;
  max-width: 100%;
  max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
}

body.app-redesign .modal-header,
body.app-redesign .modal-footer,
body.app-redesign .modal-body,
body.app-redesign .modal-content,
body.app-redesign .form-row,
body.app-redesign .form-grid,
body.app-redesign .card-grid,
body.app-redesign .dashboard-grid,
body.app-redesign .history-grid,
body.app-redesign .shifts-squares-grid {
  min-width: 0;
  max-width: 100%;
}

body.app-redesign .modal-header,
body.app-redesign .modal-footer { flex-wrap: wrap; }

body.app-redesign .modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
}

body.app-redesign .table-responsive,
body.app-redesign .history-table-wrap,
body.app-redesign .data-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

body.app-redesign table { min-width: 0; }
body.app-redesign th,
body.app-redesign td { overflow-wrap: anywhere; }

body.app-redesign .nav-tabs,
body.app-redesign .section-heading,
body.app-redesign .modal-actions,
body.app-redesign .form-actions { gap: .6rem; }

@media (max-width: 768px) {
  body.app-redesign .main-content { padding-inline: clamp(.65rem, 3vw, 1.1rem); }
  body.app-redesign .modal-card { border-radius: 14px; }
  body.app-redesign .modal-footer,
  body.app-redesign .modal-actions,
  body.app-redesign .form-actions { align-items: stretch; }
  body.app-redesign .modal-footer > button,
  body.app-redesign .modal-actions > button,
  body.app-redesign .form-actions > button { flex: 1 1 10rem; }
}

@media (max-width: 412px) {
  body.app-redesign .main-content { padding-inline: .55rem; }
  body.app-redesign .modal-overlay { padding-inline: .45rem; }
  body.app-redesign .modal-card { width: 100%; max-height: calc(100dvh - .9rem); }
  body.app-redesign .modal-header,
  body.app-redesign .modal-footer,
  body.app-redesign .modal-body { padding-inline: .8rem; }
  body.app-redesign .modal-footer > button,
  body.app-redesign .modal-actions > button,
  body.app-redesign .form-actions > button { width: 100%; flex-basis: 100%; }
}

@media (max-height: 560px) and (orientation: landscape) {
  body.app-redesign .modal-overlay { align-items: flex-start; }
  body.app-redesign .modal-card { margin-block: .35rem; }
  body.app-redesign .modal-body { max-height: calc(100dvh - 5rem); }
}

@media (min-width: 769px) {
  body.app-redesign .main-content { width: 100%; max-width: none; margin-inline: 0; }
}

@media (prefers-reduced-motion: reduce) {
  body.app-redesign *, body.app-redesign *::before, body.app-redesign *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

/* Píldora IA: controles en una sola fila, con caja propia y separación
   constante para evitar botones superpuestos en pantallas estrechas. */
body.app-redesign .ai-floating-widget {
  left: auto !important;
  right: max(.75rem, env(safe-area-inset-right)) !important;
  bottom: max(.75rem, env(safe-area-inset-bottom)) !important;
  max-width: calc(100vw - 1.5rem);
  align-items: flex-end !important;
}

body.app-redesign .ai-pill-bar {
  display: grid !important;
  grid-template-columns: auto auto auto auto;
  align-items: center;
  gap: .28rem;
  width: max-content;
  max-width: 100%;
  min-height: 2.35rem;
  box-sizing: border-box;
  padding: .22rem .3rem .22rem .42rem;
}

body.app-redesign .ai-pill-bar > * {
  min-width: 0;
  flex: none;
}

body.app-redesign .btn-ai-pill-main,
body.app-redesign .btn-ai-pill-mic,
body.app-redesign .btn-ai-pill-flip {
  min-height: 0 !important;
  min-width: 0;
  margin: 0 !important;
  box-sizing: border-box;
}

body.app-redesign .btn-ai-pill-mic,
body.app-redesign .btn-ai-pill-flip {
  flex: 0 0 auto;
  width: 2rem !important;
  height: 2rem !important;
  padding: 0 !important;
}

body.app-redesign .open-accounts-scroll .btn-chip-close {
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
}

@media (max-width: 620px) {
  body.app-redesign .ai-floating-widget {
    right: max(.6rem, env(safe-area-inset-right)) !important;
    bottom: max(.6rem, env(safe-area-inset-bottom)) !important;
    max-width: calc(100vw - 1.2rem);
  }

  body.app-redesign .ai-pill-bar {
    gap: .2rem;
    padding-inline: .3rem;
  }
}

/* La tabla de prioridad necesita conservar su estructura en escritorio. En
   móvil se convierte en tarjetas: cada dato mantiene su etiqueta y deja de
   pelear por unas pocas columnas estrechas. */
body.app-redesign .inventory-priority-table {
  min-width: 680px;
  table-layout: fixed;
}

body.app-redesign .inventory-priority-name-cell,
body.app-redesign .inventory-priority-action-cell {
  display: table-cell;
  overflow-wrap: normal;
}

body.app-redesign .inventory-priority-name-cell .inventory-visual-group,
body.app-redesign .inventory-priority-name-cell strong {
  display: block;
  overflow-wrap: anywhere;
}

body.app-redesign .inventory-priority-action-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-width: 0;
}

body.app-redesign .inventory-priority-action-content > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  body.app-redesign .inventory-priority-table-wrap {
    overflow: visible;
    border: 0;
  }

  body.app-redesign .inventory-priority-table {
    display: block;
    width: 100%;
    min-width: 0;
    table-layout: auto;
  }

  body.app-redesign .inventory-priority-table thead {
    display: none;
  }

  body.app-redesign .inventory-priority-table tbody {
    display: grid;
    gap: .75rem;
  }

  body.app-redesign .inventory-priority-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: .7rem .8rem;
    padding: .8rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
  }

  body.app-redesign .inventory-priority-row td,
  body.app-redesign .inventory-priority-name-cell,
  body.app-redesign .inventory-priority-action-cell {
    display: block;
    width: auto;
    min-width: 0;
    padding: 0 !important;
    vertical-align: initial;
  }

  body.app-redesign .inventory-priority-name-cell {
    grid-column: 1 / -1;
    padding-bottom: .65rem !important;
    border-bottom: 1px solid var(--border-color);
  }

  body.app-redesign .inventory-priority-name-cell::before,
  body.app-redesign .inventory-priority-stock-cell::before,
  body.app-redesign .inventory-priority-minimum-cell::before,
  body.app-redesign .inventory-priority-row td:nth-child(4)::before,
  body.app-redesign .inventory-priority-action-cell::before {
    display: block;
    margin-bottom: .25rem;
    color: var(--text-muted);
    font-size: .61rem;
    font-weight: 900;
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  body.app-redesign .inventory-priority-name-cell::before { content: 'Insumo'; }
  body.app-redesign .inventory-priority-stock-cell::before { content: 'Existencia'; }
  body.app-redesign .inventory-priority-minimum-cell::before { content: 'Mínimo'; }
  body.app-redesign .inventory-priority-row td:nth-child(4)::before { content: 'Estado'; }
  body.app-redesign .inventory-priority-action-cell::before { content: 'Acción'; }

  body.app-redesign .inventory-priority-name-cell strong,
  body.app-redesign .priority-major .inventory-priority-name-cell strong {
    font-size: .96rem;
    line-height: 1.25;
  }

  body.app-redesign .inventory-priority-stock-cell .inventory-table-bar-button {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: .45rem;
    width: 100%;
    min-width: 0;
    padding: 0;
  }

  body.app-redesign .inventory-priority-stock-cell .inventory-table-bar-scale {
    flex: 0 0 16px;
    width: 16px;
    height: 42px;
  }

  body.app-redesign .inventory-priority-stock-cell .inventory-table-bar-track {
    width: 13px;
  }

  body.app-redesign .inventory-priority-stock-cell .inventory-table-quantity {
    align-items: flex-start;
  }

  body.app-redesign .inventory-priority-minimum-cell strong {
    font-size: 1.05rem;
    text-align: left;
  }

  body.app-redesign .inventory-priority-row td:nth-child(4),
  body.app-redesign .inventory-priority-action-cell {
    grid-column: 1 / -1;
  }

  body.app-redesign .inventory-priority-row td:nth-child(4) .inventory-visual-status {
    display: inline-flex;
    margin-top: .05rem;
    font-size: .68rem;
  }

  body.app-redesign .inventory-priority-action-cell {
    padding-top: .65rem !important;
    border-top: 1px solid var(--border-color);
  }

  body.app-redesign .inventory-priority-action-content {
    align-items: center;
    gap: .7rem;
  }

  body.app-redesign .inventory-priority-action-content > span {
    white-space: normal;
    font-size: .78rem;
    line-height: 1.3;
  }

  body.app-redesign .btn-inventory-table-edit {
    padding: .42rem .65rem;
    font-size: .72rem;
  }
}
