/* Shared final layout rules: content-driven sizing, touch and reduced motion. */
:root { --ui-ease:cubic-bezier(.2,.7,.2,1); --ui-fast:160ms; }
/* Give header actions their content width instead of two competing 45% columns. */
@media (min-width:641px) {
  .topbar { display:flex; flex-wrap:nowrap; gap:12px; }
  .topbar .brand { flex:1 1 auto; min-width:0; }
  .topbar .brand .mark { flex-shrink:0; }
  .topbar .brand-title { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .topbar .who { flex:0 1 auto; min-width:0; width:auto; flex-wrap:nowrap; gap:8px; }
  .topbar .who > span { min-width:0; max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .topbar .who > a, .topbar .who > button { flex:0 0 auto; white-space:nowrap; }
}
#secPartners { display:grid; gap:24px; }
.user-group-card { min-width:0; }
.user-group-card h2 { display:flex; align-items:center; gap:10px; }
.user-group-count { display:inline-flex; align-items:center; justify-content:center; min-width:28px; padding:2px 8px; border-radius:999px; background:var(--paper); color:var(--ink-soft); font-size:12px; font-weight:500; white-space:nowrap; }
.user-group-card .partner-header-actions { flex-wrap:wrap; justify-content:flex-end; }
.user-group-card .card-body { transition:opacity var(--ui-fast) var(--ui-ease); }
.user-group-card .card-body[aria-busy=true] { opacity:.55; pointer-events:none; }
.user-group-card td { overflow-wrap:anywhere; }
@media (prefers-reduced-motion:no-preference) {
  #secPartners:not(.hidden) .user-group-card { animation:uiContentIn 180ms var(--ui-ease); }
}
@media (max-width:640px) {
  .topbar:has(#adminName, #companyName) {
    display:grid;
    grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);
    align-items:center;
    gap:10px 7px;
  }
  .topbar:has(#adminName, #companyName) .brand,
  .topbar:has(#adminName, #companyName) .who { display:contents; }
  .topbar:has(#adminName, #companyName) :is(#adminName, #companyName) {
    grid-column:3;
    grid-row:1;
    min-width:0;
    max-width:none;
    text-align:left;
    white-space:normal;
    overflow-wrap:anywhere;
  }
  .topbar:has(#adminName, #companyName) .who > :not(#adminName, #companyName) { grid-row:2; }
  #secPartners { gap:16px; }
  .user-group-card .card-header { flex-direction:column; gap:12px; align-items:stretch; }
  .user-group-card .partner-header-actions { display:flex; width:100%; gap:8px; }
  .user-group-card .partner-header-actions > .combo { flex:1 1 0; width:auto; min-width:0; }
  .user-group-card .partner-header-actions > .btn { flex:1 1 0; min-height:44px; }
  .user-group-card .row-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); width:100%; gap:8px; }
  .user-group-card .row-actions .btn { width:100%; min-width:0; }
}
.grid-2 { grid-template-columns:repeat(2,minmax(0,1fr)); }
.grid-2 > *, .field, .card-body, .store-modal-body, .store-detail-info { min-width:0; }
.field input, .field select, .field textarea { max-width:100%; }
.row-actions, .order-actions { flex-wrap:wrap; }
.store-cart-item-name, .partner-cart-name, .store-detail-info h2,
.store-order-item-name, .stat .value { overflow-wrap:anywhere; }
.store-product-price-row { flex-wrap:wrap; gap:8px; }
.store-product-price { min-width:0; overflow-wrap:anywhere; }
.store-modal-header h3, .drawer-head strong { min-width:0; overflow-wrap:anywhere; }
.store-modal-close, .drawer-close-icon { flex-shrink:0; }
.modal, .store-modal, .store-specs-dialog { max-height:calc(100dvh - 24px); }
.modal, .store-modal-body, .store-specs-dialog { scroll-padding-block:16px; }
.combo-trigger, .store-combo-trigger { min-height:44px; }
.combo-panel, .store-combo-menu { max-height:min(280px,45dvh); overflow-y:auto; overscroll-behavior:contain; }
.combo-item { min-height:40px; }
.product-visibility label { transition:background-color var(--ui-fast) var(--ui-ease),border-color var(--ui-fast) var(--ui-ease); }
.btn, .store-btn, .dtabs button, .combo-trigger, .store-combo-trigger,
.store-add-cart-btn, .store-auth-tab, .drawer-close-icon, .store-modal-close {
  transition:background-color var(--ui-fast) var(--ui-ease),color var(--ui-fast) var(--ui-ease),border-color var(--ui-fast) var(--ui-ease),box-shadow var(--ui-fast) var(--ui-ease),opacity var(--ui-fast) var(--ui-ease);
}
@keyframes uiContentIn { from { opacity:.35; } to { opacity:1; } }
@media (prefers-reduced-motion:no-preference) {
  #secPartners:not(.hidden), #secProducts:not(.hidden), #secAdmins:not(.hidden),
  #secPrice:not(.hidden), #secOrders:not(.hidden),
  #storeLoginForm:not(.hidden), #storeRegisterForm:not(.hidden), .partner-cart-item, .store-cart-item {
    animation:uiContentIn 180ms var(--ui-ease);
  }
  /* Avoid long cascades each time search or pagination redraws the list. */
  .store-product-card:nth-child(n) { animation-duration:220ms; animation-delay:0ms; }
  .store-product-card:nth-child(2), .store-product-card:nth-child(3) { animation-delay:30ms; }
}
@media (hover:hover) and (pointer:fine) {
  .product-visibility label:hover { border-color:var(--teal); }
}
@media (max-width:1024px), (pointer:coarse) {
  .btn, .store-btn, .dtabs button, .store-add-cart-btn,
  .combo-item, .store-combo-menu button { min-height:44px; }
  .inline-discount-toggle { min-height:44px !important; }
  .store-cart-item-controls button, .partner-cart-controls button { min-width:40px; min-height:40px; }
  .store-cart-item-remove, .partner-cart-remove { min-height:40px; }
}
@media (max-width:640px) {
  .grid-2 { grid-template-columns:minmax(0,1fr); }
  .products-action-group { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); width:100%; gap:8px; }
  .products-action-group .btn { width:100%; min-width:0; padding:8px; white-space:normal; line-height:1.8; }
  .products-action-group #bulkDeleteButton { grid-column:1 / -1; }
  .products-selection-bar { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .products-selection-bar > :last-child { grid-column:1 / -1; }
  .products-selection-bar .btn { white-space:normal; }
  .store-product-price-row > .store-add-cart-btn { flex:1 0 100%; }
  .store-product-price-row > .price-updating { width:100%; min-height:44px; display:flex; align-items:center; justify-content:center; text-align:center; }
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font-size:16px; }
  .store-header-actions > button, .store-menu-toggle { min-height:44px; }
}
@media (max-width:480px) {
  .store-product-detail { grid-template-columns:minmax(0,1fr); gap:16px; }
  .store-detail-gallery, .store-detail-info, .store-detail-actions { grid-column:1; grid-row:auto; }
  .store-detail-gallery { width:100%; max-width:260px; justify-self:center; }
  .store-detail-image { min-height:0; }
  .store-detail-image > img { max-height:210px; }
  .store-detail-info { text-align:center; }
  .store-detail-price .store-product-current-price, .store-detail-price .store-old-price { align-self:center; }
  .store-detail-actions { grid-template-columns:minmax(0,1fr); }
  .store-detail-actions .store-btn { min-height:46px; }
}
@media (max-width:359px) {
  .store-products-grid { grid-template-columns:minmax(0,1fr); }
  .store-product-image { padding-top:0; height:200px; }
  .store-product-name { font-size:14px; }
}
@media (max-height:500px) {
  .modal-backdrop, .store-modal-backdrop { padding:8px; }
  .modal, .store-modal, #productModal > .store-modal, .store-specs-dialog { max-height:calc(100dvh - 16px); }
  .store-modal-header, .drawer-head { padding-block:10px; }
  .store-detail-image > img { max-height:200px; }
}
@supports (padding:env(safe-area-inset-bottom)) {
  .store-modal-body, .drawer-foot, .store-drawer-footer { padding-bottom:max(16px,env(safe-area-inset-bottom)); }
}
/* Shared finishing layer for all three applications. Keep motion on opacity and
   transforms; sizing changes must settle immediately when a device rotates. */
:root { --ui-enter:240ms; }
.container > [id^="sec"], .store-container > *, .store-field,
.store-order-item-row > div, .store-checkout-summary { min-width:0; }
.store-modal-header, .store-drawer-header { flex-shrink:0; gap:12px; }
.store-modal-body { min-height:0; overscroll-behavior:contain; }
.store-field, .store-order-card, .store-checkout-summary,
#specsModalBody, #productSpecsBody { overflow-wrap:anywhere; }
.store-payment-note svg { flex-shrink:0; }
.store-checkout-summary .summary-row { flex-wrap:wrap; gap:4px 12px; }
.store-checkout-summary .summary-row > span { min-width:0; }
.store-checkout-summary .summary-row > .num { margin-inline-start:auto; }
.store-order-card-header, .store-order-item-row, .store-order-total { flex-wrap:wrap; }
.store-order-item-row > div { flex:1 1 160px; }
.store-order-item-row > .num { margin-inline-start:auto; }
.store-footer-links { flex-wrap:wrap; row-gap:10px; }
.store-field input, .store-field textarea, .store-field select,
.field input, .field textarea, .field select {
  transition:border-color var(--ui-fast) var(--ui-ease),box-shadow var(--ui-fast) var(--ui-ease);
}
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline:2px solid var(--primary, var(--teal, #4054df));
  outline-offset:3px;
}
@keyframes uiPanelIn {
  from { opacity:0; transform:translateY(8px); }
  to { opacity:1; transform:translateY(0); }
}
@media (prefers-reduced-motion:no-preference) {
  html { scroll-behavior:smooth; }
  .container > [id^="sec"]:not(.hidden), #coPasswordField:not(.hidden),
  #ordersListBody > .store-order-card {
    animation:uiPanelIn var(--ui-enter) var(--ui-ease);
  }
  .store-product-card { transition:transform var(--ui-enter) var(--ui-ease),box-shadow var(--ui-enter) var(--ui-ease),border-color var(--ui-fast) var(--ui-ease); }
  .btn:active:not(:disabled), .store-btn:active:not(:disabled),
  .store-add-cart-btn:active:not(:disabled) { transform:translateY(1px); }
}
@media (hover:none), (pointer:coarse) {
  .store-product-card:hover, .store-footer-support:hover { transform:none; }
  .store-modal-close, .store-drawer-close, .drawer-close-icon,
  #cartDrawer .drawer-head button, #cartDrawer .store-drawer-close,
  .store-filter-toggle, .store-checkbox-row { min-height:44px; min-width:44px; }
  .store-cart-item-controls button, .partner-cart-controls button { min-width:44px; min-height:44px; }
}
/* Tall desktop monitors still use desktop controls and readable card widths. */
@media (min-width:901px) and (orientation:portrait) {
  .store-container, .container { padding-inline:clamp(20px, 3vw, 40px); }
  .store-products-grid { grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:18px; }
  .toolbar { display:flex; flex-wrap:wrap; }
  .toolbar > input[type=text] { flex:1 1 100%; }
  .toolbar > .combo, .toolbar > select { flex:1 1 180px; }
  .store-hero { padding-block:clamp(32px, 4vh, 64px); }
}
@media (min-width:641px) and (max-width:1024px) {
  .products-action-group { flex-wrap:wrap; }
  .grid-2 { gap:16px; }
}
@media (max-width:640px) {
  .store-modal-backdrop { padding:12px; }
  .store-modal-body { padding:16px; }
  .store-modal-close, .drawer-close-icon { min-width:44px; min-height:44px; }
  .store-checkout-summary { font-size:13px; }
  .store-order-total > .num { white-space:normal; overflow-wrap:anywhere; }
  .store-footer-links { padding-inline:12px; }
}
@media (max-height:500px) {
  .store-modal-backdrop { padding:8px; }
  .store-modal-body { padding-block:12px; }
  .store-header { position:relative; }
  #listDock, .store-list-dock { position:relative; bottom:auto; }
}
@supports (padding:env(safe-area-inset-left)) {
  .modal-backdrop, .store-modal-backdrop {
    padding-inline:max(12px,env(safe-area-inset-left),env(safe-area-inset-right));
  }
}
@media (prefers-reduced-motion:reduce) {
  .store-animate-in { opacity:1; transform:none; }
  *, *::before, *::after, dialog::backdrop {
    animation-duration:.001ms !important;
    animation-delay:0ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.001ms !important;
    transition-delay:0ms !important;
    scroll-behavior:auto !important;
  }
}
