#products-view .product-compact-toggle { display: none; }
#products-view .product-secondary-tools { display: contents; }

/* Keep the everyday product workflow short: search, status, filter, add. */
#products-view .product-filter-toggle { display: inline-flex; align-items: center; justify-content: center; }
#products-view .product-filter-drawer { display: none; }
#products-view .product-filter-drawer.is-expanded {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}
#products-view .product-filter-drawer .product-category-filter-panel,
#products-view .product-filter-drawer .product-origin-filter-row,
#products-view .product-filter-drawer .product-type-buttons,
#products-view .product-filter-drawer .product-inactive-controls { grid-column: 1 / -1; }
#products-view .product-active-filters { display: flex; grid-column: 1 / -1; flex-wrap: wrap; align-items: center; gap: 6px; }
#products-view .product-active-filters > span { padding: 5px 9px; border-radius: 999px; background: #e7f5f2; color: #0f766e; font-size: 12px; font-weight: 700; }
#products-view .product-active-filters .product-active-filters-label { background: transparent; color: var(--muted); padding-left: 0; }
#products-view .product-active-filters button { min-height: 32px; padding: 4px 9px; margin-left: auto; font-size: 12px; }

#products-view .product-card-details { margin-top: 10px; }
#products-view .product-card-details > summary,
#products-view .product-action-menu > summary {
  cursor: pointer;
  list-style: none;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #0f766e;
  font-weight: 700;
}
#products-view .product-card-details > summary::-webkit-details-marker,
#products-view .product-action-menu > summary::-webkit-details-marker { display: none; }
#products-view .product-card-details[open] > summary { margin-bottom: 10px; }
#products-view .product-action-menu { min-width: 0; position: relative; }
#products-view .product-action-menu > div { display: grid; gap: 7px; margin-top: 7px; }
#products-view .product-action-menu > div button { width: 100%; }
/* Raised controls stay scoped to product management, including desktop. */
#products-view .action-cell button {
  border-radius: 10px;
  border-bottom-width: 3px;
  box-shadow: 0 3px 0 #cbd5e1, 0 5px 9px rgb(15 23 42 / 10%);
  transition: transform 100ms ease, box-shadow 100ms ease;
}
#products-view .action-cell button.secondary { background: linear-gradient(#fff, #eef2f7); }
#products-view .action-cell button[data-toggle-product] { color: #92400e; border-color: #e8c17b; background: linear-gradient(#fffbeb, #fef3c7); box-shadow: 0 3px 0 #d6b16c, 0 5px 9px rgb(15 23 42 / 10%); }
#products-view .action-cell button.danger { color: #b91c1c; border-color: #fecaca; background: linear-gradient(#fff, #fff1f2); }
#products-view .action-cell button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 transparent; }
#products-view .action-cell button:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
#products-view .action-cell button:disabled { box-shadow: none; opacity: .65; }
@media (prefers-reduced-motion: reduce) {
  #products-view .action-cell button { transition: none; }
}

/* Product cards must not inherit the desktop column picker's inline min-width. */
@media (max-width: 1180px), (max-width: 1400px) and (pointer: coarse) {
  #products-view .table-wrap { overflow: visible; background: transparent; border: 0; }
  #products-view .products-table { display: block; width: 100%; min-width: 0 !important; }
  #products-view .products-table thead { display: none; }
  #products-view .products-table tbody { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; width: 100%; }
  #products-view .products-table tr { display: flex; flex-direction: column; min-width: 0; width: 100%; margin: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
  #products-view .products-table td:not(.product-mobile-summary):not(.action-cell) { display: none; }
  #products-view .products-table .product-mobile-summary { display: block; width: 100%; min-width: 0; padding: 14px; border: 0; }
  #products-view .product-mobile-summary::before,
  #products-view .action-cell::before { display: none; }
  #products-view .product-mobile-head { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; align-items: start; }
  #products-view .product-mobile-head .product-management-image { width: 112px; height: 112px; max-width: 100%; object-fit: contain; background: #fff; border-radius: 12px; }
  #products-view .product-mobile-title { min-width: 0; }
  #products-view .product-mobile-title strong,
  #products-view .product-mobile-title > span { display: block; line-height: 1.4; overflow-wrap: anywhere; }
  #products-view .product-mobile-title strong { font-size: 17px; }
  #products-view .product-mobile-title > span { font-size: 13px; color: var(--muted); margin-top: 4px; }
  #products-view .product-mobile-statuses { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  #products-view .product-mobile-stock { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 7px 9px; border: 1px solid #a7f3d0; border-radius: 8px; background: #ecfdf5; color: #047857; }
  #products-view .product-mobile-stock span { font-size: 12px; }
  #products-view .product-mobile-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
  #products-view .product-mobile-tags span { max-width: 100%; overflow-wrap: anywhere; padding: 5px 8px; border-radius: 8px; font-size: 12px; background: #f1f5f9; color: #475569; }
  #products-view .product-mobile-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0 0; }
  #products-view .product-mobile-details > div { display: block; width: auto; min-width: 0; padding: 9px; background: #f8fafc; border: 1px solid #eef2f7; border-radius: 8px; }
  #products-view .product-mobile-details dt { font-size: 12px; color: var(--muted); font-weight: 600; margin: 0 0 4px; }
  #products-view .product-mobile-details dd { width: auto; margin: 0; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
  #products-view .product-mobile-details .product-calculation { font-size: 11px; }
  #products-view .products-table .action-cell { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; min-width: 0; margin-top: auto; padding: 12px 14px; background: #f8fafc; border: 0; border-top: 1px solid var(--line); }
  #products-view .action-cell button { width: 100%; min-width: 0; min-height: 44px; padding: 8px; font-size: 14px; white-space: normal; }
}

@media (min-width: 768px) and (max-width: 1180px), (min-width: 768px) and (max-width: 1400px) and (pointer: coarse) {
  #products-view .product-mobile-head { grid-template-columns: 128px minmax(0, 1fr); }
  #products-view .product-mobile-head .product-management-image { width: 128px; height: 128px; }
  #products-view .products-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
  #products-view .products-toolbar > * { min-width: 0; max-width: 100%; }
  #products-view .hq-product-search-control,
  #products-view #open-bulk-classification,
  #products-view .product-category-filter-panel,
  #products-view .product-origin-filter-row,
  #products-view .product-type-buttons,
  #products-view .product-status-buttons,
  #products-view .product-launch-buttons,
  #products-view .product-supplier-filter,
  #products-view .product-inactive-controls { grid-column: 1 / -1; }
  #products-view .hq-product-search-control { display: grid; grid-template-columns: minmax(0, 1fr); }
  #products-view .hq-product-search-row {
    align-items: stretch;
    display: grid !important;
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) 96px;
    min-width: 0;
    width: 100%;
  }
  #products-view .hq-product-search-row > input,
  #products-view .hq-product-search-row > button {
    grid-column: auto;
    margin: 0;
    min-width: 0;
    width: 100%;
  }
  #products-view .hq-screen-keyboard-toggle {
    padding-left: 8px;
    padding-right: 8px;
    white-space: nowrap;
  }
  #products-view .hq-screen-keyboard { grid-column: 1 / -1; }
  #products-view .products-toolbar input { width: 100%; min-width: 0; }
  #products-view .products-toolbar .toolbar-spacer { display: none; }
  #products-view .products-toolbar .segments { display: flex; flex-wrap: wrap; }
  #products-view .products-toolbar .segment { flex: 1 1 auto; min-width: 0; }
  #products-view .products-toolbar button,
  #products-view .products-toolbar summary,
  #products-view .products-toolbar select { min-height: 44px; font-size: 14px; white-space: normal; }
  #products-view .product-column-picker summary { justify-content: center; }
  #products-view .product-column-picker-menu { width: min(340px, 80vw); max-height: 60dvh; overflow-y: auto; }
  #products-view .inventory-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 768px) and (max-width: 1180px) and (orientation: portrait) {
  #products-view .product-mobile-details { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #products-view .products-table .action-cell { display: flex; flex-wrap: wrap; }
  #products-view .action-cell button { flex: 0 1 auto; width: auto; min-width: 110px; }
}

@media (min-width: 1000px) and (max-width: 1180px) and (orientation: landscape), (min-width: 1000px) and (max-width: 1400px) and (orientation: landscape) and (pointer: coarse) {
  #products-view .products-table tbody { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
}

/* Keep products near the top: extra tools and statistics expand on demand. */
@media (max-width: 1180px), (max-width: 1400px) and (pointer: coarse) {
  #products-view .product-compact-toggle { display: block; }
  #products-view .products-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
  #products-view .products-toolbar > * { min-width: 0; max-width: 100%; }
  #products-view .hq-product-search-control,
  #products-view #open-bulk-classification,
  #products-view .product-category-filter-panel,
  #products-view .product-origin-filter-row,
  #products-view .product-type-buttons,
  #products-view .product-status-buttons,
  #products-view .product-supplier-filter,
  #products-view .product-inactive-controls { grid-column: 1 / -1; }
  #products-view .products-toolbar .segments { display: flex; flex-direction: row; flex-wrap: nowrap; gap: 4px; width: 100%; overflow: visible; }
  #products-view .products-toolbar .segments .segment { flex: 1 1 0; width: 0; min-width: 0; max-width: none; margin: 0; padding: 6px 4px; min-height: 44px; font-size: 13px; white-space: normal; box-shadow: none; }
  #products-view .products-toolbar button,
  #products-view .products-toolbar summary { min-height: 44px; font-size: 13px; padding: 7px; }
  #products-view .products-toolbar input { min-width: 0; width: 100%; min-height: 44px; font-size: 14px; }
  #products-view .products-toolbar .toolbar-spacer { display: none; }
  #products-view .product-supplier-filter { flex-direction: row; align-items: center; padding: 0 8px; gap: 8px; }
  #products-view .product-supplier-filter select { min-width: 0; flex: 1; width: 0; min-height: 44px; border: 0; font-size: 14px; padding: 6px; }
  #products-view .product-origin-filter-row .product-supplier-filter { grid-column: auto; min-width: 0; width: 100%; }
  #products-view .product-secondary-tools { display: none; }
  #products-view .product-secondary-tools.is-expanded { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  #products-view .product-secondary-tools .product-launch-buttons { grid-column: 1 / -1; }
  #products-view .product-column-picker { min-width: 0; }
  #products-view .product-column-picker-menu { position: static; min-width: 0; width: 100%; grid-template-columns: minmax(0, 1fr); max-height: 50dvh; }
  #products-view .product-column-picker-menu input { width: 18px; min-height: 18px; flex: 0 0 18px; }
  #products-view .inventory-summary-panel { padding: 6px 10px; margin-bottom: 10px; }
  #products-view .inventory-summary-heading { display: flex; flex-direction: row; flex-wrap: wrap; margin: 0; gap: 6px; align-items: center; }
  #products-view .inventory-summary-heading h2 { flex: 1; width: auto; min-width: 0; font-size: 15px; }
  #products-view #product-inventory-toggle { margin-left: auto; min-height: 44px; padding: 6px 12px; font-size: 13px; }
  #products-view .inventory-summary-panel:not(.is-expanded) .inventory-summary-heading p,
  #products-view .inventory-summary-panel:not(.is-expanded) .inventory-metrics { display: none; }
  #products-view .inventory-summary-panel.is-expanded .inventory-metrics { margin-top: 10px; }
}

@media (max-width: 767px) {
  #products-view .hq-product-search-row {
    display: grid !important;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 72px;
    min-width: 0;
    width: 100%;
  }
  #products-view .hq-product-search-row > input,
  #products-view .hq-product-search-row > button {
    grid-column: auto;
    margin: 0;
    min-width: 0;
    width: 100%;
  }
  #products-view .product-origin-filter-row {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #products-view .product-origin-filter-row .product-supplier-filter {
    align-items: stretch;
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(0, 1fr);
    padding: 8px;
  }
  #products-view .product-origin-filter-row .product-supplier-filter select {
    border: 1px solid var(--line);
    width: 100%;
  }
}

/* Tool collections are opt-in on every screen size. */
#products-view #product-tools-toggle { display: inline-flex; align-items: center; justify-content: center; }
#products-view .product-secondary-tools { display: none; }
#products-view .product-secondary-tools.is-expanded {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
#products-view .product-secondary-tools .product-launch-buttons { grid-column: 1 / -1; }

@media (max-width: 767px) {
  #products-view .products-toolbar { grid-template-columns: minmax(0, 1fr) minmax(88px, .32fr); }
  #products-view .hq-product-search-control { grid-column: 1 / -1; }
  #products-view .product-status-buttons,
  #products-view .product-active-filters,
  #products-view .product-filter-drawer,
  #products-view #product-tools-toggle,
  #products-view .product-secondary-tools { grid-column: 1 / -1; }
  #products-view .product-filter-drawer.is-expanded { grid-template-columns: minmax(0, 1fr); }
  #products-view .products-table .action-cell { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #products-view .product-action-menu > summary { min-height: 44px; font-size: 13px; padding: 7px; }
  #products-view .product-pagination-controls label,
  #products-view #product-total-pages,
  #products-view #product-go-page { display: none; }
  #products-view .product-pagination-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #products-view #product-previous-page,
  #products-view #product-next-page { width: 100%; }
}
