/* =========================================================
   SalesPro Design System — SPDS 1.5 / Consolidación visual
   ERP 3.2.6.45
   Correcciones transversales posteriores a la migración.
   ========================================================= */

/* 1. Base estable: evita desbordes y diferencias de cálculo entre módulos. */
.spds-admin *, .spds-admin *::before, .spds-admin *::after,
.spds-store *, .spds-store *::before, .spds-store *::after { box-sizing:border-box; }

.spds-admin, .spds-store { min-width:0; }
.spds-admin :where(main,section,article,aside,header,footer,div,form,fieldset),
.spds-store :where(main,section,article,aside,header,footer,div,form,fieldset) { min-width:0; }
.spds-admin :where(img,svg,video,canvas),
.spds-store :where(img,svg,video,canvas) { max-width:100%; }
.spds-admin img, .spds-store img { height:auto; }

/* 2. Tipografía: elimina saltos extraños en controles y títulos operativos. */
.spds-admin :where(h1,h2,h3,h4,h5,h6),
.spds-store :where(h1,h2,h3,h4,h5,h6) { margin-top:0; overflow-wrap:anywhere; }
.spds-admin :where(p:last-child), .spds-store :where(p:last-child) { margin-bottom:0; }
.spds-admin :where(.page-head,.spds-page-head) h1 { line-height:1.08; }

/* 3. Controles: corrige la regla heredada width:100% en tipos especiales. */
.spds-admin :where(input[type="hidden"],input[type="checkbox"],input[type="radio"],input[type="button"],input[type="submit"],input[type="reset"],input[type="color"],input[type="range"]),
.spds-store :where(input[type="hidden"],input[type="checkbox"],input[type="radio"],input[type="button"],input[type="submit"],input[type="reset"],input[type="color"],input[type="range"]) {
  width:auto; min-height:0; padding:0;
}
.spds-admin input[type="color"], .spds-store input[type="color"] { width:44px; height:44px; border-radius:var(--sp-radius-8); padding:4px; }
.spds-admin input[type="file"], .spds-store input[type="file"] { min-height:var(--sp-control-md); padding:7px 10px; }
.spds-admin :where(input,select,textarea)::placeholder,
.spds-store :where(input,select,textarea)::placeholder { color:var(--sp-text-muted); opacity:.78; }
.spds-admin :where(select), .spds-store :where(select) { text-overflow:ellipsis; }

/* 4. Botones: conserva botones de icono y evita que grupos se deformen. */
.spds-admin :where(.btn,.sp-btn,button.btn,a.btn),
.spds-store :where(.sp-store-btn) { max-width:100%; white-space:nowrap; }
.spds-admin :where(.btn-icon,.icon-btn,.action-btn,.modal-close,.close-btn,[aria-label][class*="close"]) {
  width:var(--sp-control-md); min-width:var(--sp-control-md); padding:0; flex:0 0 auto;
}
.spds-admin :where(.actions,.page-actions,.toolbar-actions,.row-actions,.hb-head-actions),
.spds-store :where(.actions,.store-actions) { display:flex; align-items:center; flex-wrap:wrap; gap:var(--sp-space-8); }
.spds-admin :where(.btn svg,.sp-btn svg), .spds-store :where(.sp-store-btn svg) { width:18px; height:18px; flex:0 0 auto; }

/* 5. Tarjetas y paneles: una tarjeta anidada no duplica sombra/borde exterior. */
.spds-admin :where(.sp-card,.sp-panel,.card,.panel,.table-card) :where(.sp-card,.sp-panel) { box-shadow:none; }
.spds-admin :where(.sp-card,.card,.panel,.table-card),
.spds-store :where(.sp-card,.sp-store-card) { background-clip:padding-box; }
.spds-admin :where(.card,.panel,.table-card) > :first-child,
.spds-store :where(.sp-store-card) > :first-child { margin-top:0; }
.spds-admin :where(.card,.panel,.table-card) > :last-child,
.spds-store :where(.sp-store-card) > :last-child { margin-bottom:0; }

/* 6. Tablas: evita borde y sombra duplicados y mantiene acciones visibles. */
.spds-admin :where(.table-wrap,.sp-table-wrap,.table-card) table { margin:0; }
.spds-admin .table-card:has(> table),
.spds-admin .table-card:has(> .table-wrap) { padding:0; }
.spds-admin :where(.table-wrap,.sp-table-wrap) :where(.table-wrap,.sp-table-wrap) { border:0; border-radius:0; box-shadow:none; }
.spds-admin table :where(th,td) { overflow-wrap:normal; }
.spds-admin table td:last-child :where(.actions,.row-actions) { justify-content:flex-end; flex-wrap:nowrap; }

/* 7. Modales: tamaño predecible y scroll interno, no de toda la pantalla. */
.spds-admin :where(.modal-card,.sp-modal__dialog,.product-search-dialog,.simple-qr-card),
.spds-store :where(.modal-card,.sp-modal__dialog) {
  max-width:min(720px,calc(100vw - 32px)); max-height:calc(100dvh - 32px); overflow:auto;
}
.spds-admin :where(.modal,.sp-modal,.pos-modal,.product-search-modal),
.spds-store :where(.modal,.sp-modal) { padding:var(--sp-space-16); }

/* 8. Estados: foco consistente sin desplazar componentes. */
.spds-admin :where(a,button,input,select,textarea,[tabindex]):focus-visible,
.spds-store :where(a,button,input,select,textarea,[tabindex]):focus-visible {
  outline:2px solid color-mix(in srgb,var(--sp-color-secondary) 58%,transparent);
  outline-offset:2px;
}
.spds-admin :where(.btn,.sp-btn,button.btn,a.btn):focus-visible,
.spds-store :where(.sp-store-btn):focus-visible { outline:0; }

/* 9. Carga, estados vacíos y avisos: dimensiones y jerarquía homogéneas. */
.spds-admin :where(.empty-state,.no-results,.loading-state),
.spds-store :where(.empty-state,.no-results,.loading-state) {
  padding:var(--sp-space-32); text-align:center; color:var(--sp-text-muted);
}
.spds-admin :where(.alert,.notice,.sp-alert) + :where(.alert,.notice,.sp-alert),
.spds-store :where(.alert,.notice,.sp-alert) + :where(.alert,.notice,.sp-alert) { margin-top:var(--sp-space-12); }

/* 10. Dark mode: controles nativos y recursos de fondo blanco. */
[data-theme="dark"] .spds-admin :where(input,select,textarea),
[data-theme="dark"] .spds-store :where(input,select,textarea) { color-scheme:dark; }
[data-theme="dark"] .spds-store :where(.product-card img,.product-gallery img,.cart-item img) { background:#fff; }

/* 11. Responsive: elimina scroll horizontal accidental sin ocultar tablas deliberadas. */
@media (max-width:900px) {
  .spds-admin :where(.page-head,.spds-page-head) { align-items:stretch; }
  .spds-admin :where(.page-actions,.toolbar-actions,.hb-head-actions) { width:100%; }
  .spds-admin :where(.page-actions,.toolbar-actions,.hb-head-actions) > :where(.btn,.sp-btn,a.btn,button.btn) { flex:1 1 auto; }
}
@media (max-width:640px) {
  .spds-admin :where(.card,.sp-card,.data-card,.quote-card,.catalog-card),
  .spds-store :where(.sp-card,.sp-store-card) { border-radius:var(--sp-radius-16); }
  .spds-admin :where(.card,.sp-card,.data-card,.quote-card,.catalog-card) { padding:var(--sp-space-16); }
  .spds-admin :where(.modal-card,.sp-modal__dialog,.product-search-dialog,.simple-qr-card),
  .spds-store :where(.modal-card,.sp-modal__dialog) { max-width:calc(100vw - 16px); max-height:calc(100dvh - 16px); border-radius:var(--sp-radius-16); }
  .spds-admin :where(.modal,.sp-modal,.pos-modal,.product-search-modal),
  .spds-store :where(.modal,.sp-modal) { padding:8px; }
  .spds-admin table td:last-child :where(.actions,.row-actions) { justify-content:flex-start; }
}

@media (prefers-reduced-motion:reduce) {
  .spds-admin *, .spds-admin *::before, .spds-admin *::after,
  .spds-store *, .spds-store *::before, .spds-store *::after {
    scroll-behavior:auto!important; animation-duration:.01ms!important; animation-iteration-count:1!important; transition-duration:.01ms!important;
  }
}
