:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --accent: #2d9e4c;
  --accent-2: #f9ab00;
  --danger: #d93025;
  --shadow: 0 1px 2px rgba(32, 33, 36, 0.12);
  --row-height: 30px;
  --topbar-height: 98px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 30px;
  padding: 5px 9px;
}

button:hover {
  border-color: #b0b4ba;
  background: #f8f9fa;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.ghost {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding-inline: 4px;
}

input,
select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 8px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafcfd;
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: var(--topbar-height);
  box-shadow: inset 0 -1px 0 rgba(32, 33, 36, 0.04);
}

.topbar-main,
.topbar-secondary {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.topbar-secondary {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 320px;
  min-width: 0;
}

.topbar-title > div {
  min-width: 0;
  flex: 1 1 auto;
}

.sidebar-toggle {
  width: 32px;
  min-width: 32px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
}

.sidebar-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-primary,
.view-controls,
.table-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.view-controls {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(130px, 180px) 112px 110px;
  justify-content: start;
  width: min(100%, 690px);
}

.topbar-action {
  min-width: 92px;
}

#pageSize.topbar-action {
  width: 112px;
}

#viewSelect.topbar-action {
  min-width: 180px;
}

.view-controls select.topbar-action,
.view-controls input.topbar-action,
.view-controls button.topbar-action {
  width: 100%;
}

.primary-action {
  border-color: #b8d4c0;
  color: #137333;
  font-weight: 650;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-width: 148px;
  min-height: 30px;
  border: 1px solid #cfd6d1;
  border-radius: 6px;
  background: #eef2ee;
  overflow: hidden;
}

.mode-toggle button {
  min-width: 0;
  min-height: 28px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #4f5b55;
  padding: 4px 8px;
}

.mode-toggle button + button {
  border-left: 1px solid #d9dedb;
}

.mode-toggle button.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px #bad2c1;
  font-weight: 700;
}

.user-menu {
  display: grid;
  grid-template-columns: minmax(70px, auto) auto;
  align-items: center;
  gap: 6px;
  min-height: 30px;
}

.user-menu[hidden] {
  display: none;
}

#userBadge {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logoutBtn,
#usersBtn,
.tools-menu-panel button {
  min-width: 54px;
  min-height: 28px;
  padding: 4px 7px;
  color: var(--muted);
}

#usersBtn[hidden] {
  display: none;
}

.tools-menu {
  position: relative;
  justify-self: end;
  min-width: 126px;
}

.tools-menu summary {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 10px;
  cursor: pointer;
  list-style: none;
}

.tools-menu summary::-webkit-details-marker {
  display: none;
}

.tools-menu summary::after {
  content: "▾";
  margin-left: 8px;
  color: var(--muted);
}

.tools-menu[open] summary {
  border-color: #b8c2bc;
  background: #ffffff;
}

.tools-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 80;
  width: 210px;
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(32, 33, 36, 0.14);
}

.tools-menu-panel button {
  width: 100%;
  text-align: left;
  justify-content: start;
}

@media (max-width: 1024px) {
  :root {
    --topbar-height: 168px;
  }

  .topbar {
    gap: 8px;
  }

  .topbar-main,
  .topbar-secondary {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar-primary,
  .table-controls {
    justify-content: start;
    flex-wrap: wrap;
  }

  .view-controls {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #viewSelect.topbar-action,
  .mode-toggle.topbar-action {
    min-width: 0;
  }

  .mode-toggle.topbar-action {
    min-width: 0;
  }
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  height: calc(100vh - var(--topbar-height));
  min-height: 0;
  transition: grid-template-columns 0.18s ease;
  position: relative;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .filters-panel {
  padding-inline: 0;
  border-right: 0;
  overflow: hidden;
}

.app-shell.sidebar-collapsed .filters-panel[aria-hidden="true"] {
  pointer-events: none;
  user-select: none;
}

.filters-panel {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
  overflow: auto;
  max-height: 100%;
  position: sticky;
  top: var(--topbar-height);
}

@media (max-width: 1024px) {
  .filters-panel {
    top: var(--topbar-height);
  }
}

.panel-section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.label,
.section-title {
  display: block;
  color: var(--ink);
  font-weight: 650;
  margin-bottom: 8px;
}

.section-row,
.table-toolbar,
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-row .section-title {
  margin-bottom: 0;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.section-actions .ghost {
  min-height: 24px;
  padding: 4px 8px;
  white-space: nowrap;
}

.add-filter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.active-filters {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.filter-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.filter-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.filter-title {
  font-weight: 650;
  line-height: 1.25;
}

.filter-type {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.filter-body {
  padding: 10px;
}

.numeric-filter {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.filter-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.value-list {
  display: grid;
  gap: 2px;
  max-height: 190px;
  overflow: auto;
  margin-top: 8px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 7px;
  align-items: center;
  padding: 5px 2px;
  color: #2f3834;
}

.check-row input {
  min-height: 16px;
  width: 16px;
}

.check-count {
  color: var(--muted);
  font-size: 12px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.column-list {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  max-height: 48vh;
  overflow: auto;
  overflow-x: hidden;
}

.column-item {
  display: grid;
  grid-template-columns: 20px 18px 1fr;
  gap: 7px;
  align-items: center;
  min-width: 0;
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
}

.column-item > span:last-child {
  min-width: 0;
  overflow: hidden;
}

.column-item:hover {
  background: var(--surface-2);
}

.column-item.dragging {
  opacity: 0.45;
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  text-align: center;
}

.column-item input {
  width: 16px;
  min-height: 16px;
}

.column-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-group {
  display: block;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: flex;
  flex-direction: column;
  padding: 10px 12px 14px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.table-toolbar {
  min-height: 24px;
  margin-bottom: 2px;
  padding: 2px 2px;
  font-size: 12px;
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar-actions select {
  width: 104px;
}

.dirty-marker {
  color: var(--accent-2);
  margin-left: 8px;
  font-size: 11px;
  white-space: nowrap;
}

.table-toolbar strong {
  font-size: 12px;
  color: var(--ink);
}

.table-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: auto;
  scrollbar-gutter: stable;
  height: auto;
  scrollbar-width: thin;
  scrollbar-color: #c4ccc7 transparent;
}

.table-frame::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.table-frame::-webkit-scrollbar-track {
  background: transparent;
}

.table-frame::-webkit-scrollbar-thumb {
  background-color: #c8d0ca;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.table-frame::-webkit-scrollbar-thumb:hover {
  background-color: #b6c0b8;
}

.table-frame::-webkit-scrollbar-corner {
  background: transparent;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

th,
td {
  position: relative;
  border-bottom: 1px solid #e8ece7;
  border-right: 1px solid #edf0ec;
  max-width: 280px;
  min-width: 118px;
  height: var(--row-height);
  max-height: var(--row-height);
  padding: 0 8px;
  text-align: left;
  vertical-align: middle;
  line-height: 1.28;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #252a28;
}

.row-select-header,
.row-select-cell {
  position: sticky;
  left: 0;
  width: 28px;
  min-width: 28px;
  max-width: 28px;
  text-align: center;
  padding: 1px 3px;
}

.row-select-header {
  z-index: 11;
  background: #e8eee9;
  border-right: 1px solid #cfd7d0;
  box-shadow: 1px 0 0 #cfd7d0;
}

.row-select-cell {
  z-index: 4;
  background: #ffffff;
  border-right: 1px solid #cfd7d0;
  box-shadow: 1px 0 0 #cfd7d0;
}

.row-actions-header,
.row-actions-cell {
  position: sticky;
  left: 28px;
  width: 72px;
  min-width: 72px;
  max-width: 72px;
  text-align: center;
  padding: 2px 4px;
}

.row-actions-header {
  z-index: 10;
  background: #e8eee9;
  border-right: 1px solid #c7d0cb;
  box-shadow: 1px 0 0 #c7d0cb;
}

.row-actions-cell {
  z-index: 3;
  background: #ffffff;
  border-right: 1px solid #c7d0cb;
  box-shadow: 1px 0 0 #c7d0cb;
}

tr:hover .row-select-cell,
tr:hover .row-actions-cell {
  background: #f6f8f5;
}

.data-row.selected .row-select-cell,
.data-row.selected .row-actions-cell {
  background: #f3f8df;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #eef2ee;
  color: #26302b;
  font-size: 11px;
  font-weight: 720;
  line-height: 1.28;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.header-label-row th {
  top: var(--row-height);
}

.total-row th {
  top: 0;
  background: #e7f0ea;
  color: #254437;
  font-weight: 750;
  cursor: default;
  border-bottom: 1px solid #bdd0c3;
}

.total-row .row-select-header,
.total-row .row-actions-header {
  background: #dfeae4;
}

.total-row .row-select-header {
  z-index: 13;
}

.total-row .row-actions-header {
  z-index: 12;
}

.total-cell {
  font-size: 11px;
}

.total-cell.numeric {
  text-align: right;
  color: #17683b;
}

th.header-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 3;
}

th.header-cell {
  height: var(--row-height);
  max-height: var(--row-height);
  overflow: hidden;
  padding-right: 34px;
}

th.sku-header-cell {
  padding-right: 58px;
}

.header-label-text {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.header-filter-button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 20px;
  width: 20px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}

.header-filter-button:hover,
.header-cell.filtered .header-filter-button {
  border-color: #b8c2bc;
  background: #ffffff;
  color: var(--accent);
}

.sku-pin-button {
  position: absolute;
  right: 29px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 20px;
  width: 20px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: #6f7974;
  line-height: 1;
}

.sku-pin-button svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  display: block;
  margin: 0 auto;
}

.sku-pin-button:hover,
.sku-pin-button.active {
  border-color: #b8c2bc;
  background: #ffffff;
  color: var(--accent);
}

.sku-pinned-cell {
  position: sticky;
  left: 100px;
  background: #ffffff;
  border-right: 1px solid #b9c5be;
  box-shadow: 2px 0 0 rgba(60, 64, 67, 0.12);
}

th.sku-pinned-cell {
  z-index: 9;
  background: #eaf2ec;
}

td.sku-pinned-cell {
  z-index: 2;
}

tr:hover td.sku-pinned-cell {
  background: #f6f8f5;
}

.data-row.selected td.sku-pinned-cell,
.data-row.selected:hover td.sku-pinned-cell {
  background: #f3f8df;
}

.header-cell.filtered {
  box-shadow: inset 0 -2px 0 var(--accent);
}

th.dragging {
  opacity: 0.45;
}

td {
  background: var(--surface);
  font-size: 11px;
  line-height: 1.28;
}

tr:hover td {
  background: #f6f8f5;
}

.data-row.selected td {
  background: #f3f8df;
}

.data-row.selected:hover td {
  background: #edf6c6;
}

.row-select-dot {
  width: 12px;
  min-width: 12px;
  min-height: 12px;
  height: 12px;
  padding: 0;
  border-radius: 50%;
  border-color: #b8c2bc;
  background: #ffffff;
}

.row-select-dot:hover {
  border-color: var(--accent);
}

.data-row.selected .row-select-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px #ffffff;
}

td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td a {
  color: var(--accent);
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

.mp-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}

.mp-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  min-height: 18px;
  border: 1px solid #cfd7d1;
  border-radius: 5px;
  background: #ffffff;
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 780;
  line-height: 1;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 0 auto;
}

.mp-link:hover {
  border-color: var(--accent);
  background: #edf5f1;
  text-decoration: none;
}

.mp-link.disabled {
  color: #a4aca7;
  background: #f2f4f1;
  cursor: not-allowed;
}

.filter-popover {
  position: fixed;
  z-index: 50;
  width: min(330px, calc(100vw - 16px));
  max-width: calc(100vw - 16px);
  max-height: min(620px, calc(100vh - 24px));
  overflow: auto;
  background: #ffffff;
  border: 1px solid #cfd7d1;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(31, 37, 35, 0.18);
  padding: 10px;
}

.popover-head,
.popover-selection-row,
.popover-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.popover-title {
  font-weight: 720;
  line-height: 1.25;
}

.popover-meta,
.popover-selected-count {
  color: var(--muted);
  font-size: 12px;
}

.popover-close {
  min-height: 28px;
  width: 28px;
  padding: 0;
}

.popover-sort {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.popover-section {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.popover-label {
  color: #343d39;
  font-weight: 680;
  font-size: 12px;
}

.condition-value-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.condition-value-row input {
  width: 100%;
}

.popover-values {
  display: grid;
  gap: 2px;
  max-height: min(230px, calc(100vh - 360px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px;
}

.popover-value-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  font-size: 13px;
}

.popover-value-row input {
  min-height: 16px;
  width: 16px;
}

.popover-actions {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 10px;
  position: sticky;
  bottom: -10px;
  z-index: 2;
  background: #ffffff;
}

.popover-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.popover-selection-row button[disabled] {
  color: var(--muted);
  border-color: #d4dad6;
  cursor: not-allowed;
  opacity: 0.75;
}

.popover-loading,
.popover-error {
  padding: 12px;
  color: var(--muted);
}

.empty-state {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
}

.empty-state.visible {
  display: flex;
}

.pager {
  flex: 0 0 auto;
  min-height: 24px;
  padding-top: 2px;
  gap: 10px;
  font-size: 12px;
}

.pager button {
  min-height: 24px;
  min-width: 58px;
  padding: 4px 10px;
}

.pager button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 64px;
  max-width: 360px;
  padding: 10px 12px;
  background: #1f2523;
  font-size: 12px;
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-height: 72px;
  overflow: auto;
}

.column-status-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 4px 8px;
  border: 1px solid #cfd7d1;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 6px 18px rgba(31, 37, 35, 0.08);
  color: var(--ink);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: auto;
  user-select: text;
  transition: opacity 120ms ease;
}

.column-status-bar.is-hidden {
  opacity: 0;
  display: none;
}

.column-status-bar:not(.is-hidden) {
  opacity: 1;
}

.column-status-bar .status-title {
  color: var(--accent);
  max-width: min(34%, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-values {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  margin-left: auto;
  width: 100%;
  text-align: right;
}

.status-values span {
  color: #34423c;
  white-space: nowrap;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(248, 249, 250, 0.92);
  backdrop-filter: blur(6px);
  padding: 20px;
}

.login-overlay[hidden] {
  display: none;
}

.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(32, 33, 36, 0.16);
}

.login-card h2 {
  margin: 0;
  font-size: 20px;
}

.login-card p {
  margin: -4px 0 4px;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 5px;
  font-weight: 650;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form button {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.auth-switch {
  justify-self: start;
  min-height: 24px;
  color: var(--accent);
}

.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 33, 36, 0.22);
}

.modal-backdrop[hidden] {
  display: none;
}

.users-modal,
.alerts-modal,
.actions-modal,
.sku-modal,
.quality-modal {
  width: min(820px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(32, 33, 36, 0.24);
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-head p {
  margin: 3px 0 0;
  color: var(--muted);
}

#closeUsersBtn {
  min-width: 30px;
  width: 30px;
  padding: 0;
  font-size: 18px;
}

#closeQualityBtn {
  min-width: 30px;
  width: 30px;
  padding: 0;
  font-size: 18px;
}

#closeAlertsBtn,
#closeActionsBtn,
#closeBriefBtn,
#closeSkuBtn {
  min-width: 30px;
  width: 30px;
  padding: 0;
  font-size: 18px;
}

.alerts-list,
.actions-list,
.sku-content {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.alert-row {
  display: grid;
  grid-template-columns: 76px minmax(110px, 0.7fr) minmax(0, 1.5fr) 130px auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #edf0ec;
}

.action-row {
  display: grid;
  grid-template-columns: 86px minmax(110px, 0.65fr) minmax(0, 1fr) 112px 112px auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #edf0ec;
}

.action-row:last-child {
  border-bottom: 0;
}

.priority-badge {
  display: inline-flex;
  justify-content: center;
  min-width: 70px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2ee;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.priority-badge.high,
.priority-badge.critical {
  background: #fde7e5;
  color: var(--danger);
}

.alert-row:last-child {
  border-bottom: 0;
}

.alert-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-severity {
  display: inline-flex;
  justify-content: center;
  min-width: 58px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  background: #fff5d9;
  color: #8a5a00;
}

.alert-severity.high {
  background: #fde7e5;
  color: var(--danger);
}

.sku-content {
  display: grid;
  gap: 12px;
  padding: 10px;
}

.sku-section {
  display: grid;
  gap: 6px;
}

.sku-section h3 {
  margin: 0;
  font-size: 14px;
}

.sku-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.sku-field {
  padding: 7px 8px;
  border: 1px solid #edf0ec;
  border-radius: 6px;
  background: #fbfcfb;
  min-width: 0;
}

.sku-field span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-field strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-note-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.brief-content {
  display: grid;
  gap: 12px;
  overflow: auto;
}

.brief-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.quality-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quality-card {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
}

.quality-card strong {
  display: block;
  font-size: 15px;
  color: var(--ink);
}

.quality-card span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quality-events {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quality-event {
  display: grid;
  grid-template-columns: 86px 112px minmax(0, 1fr) 132px;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-bottom: 1px solid #edf0ec;
}

.quality-event:last-child {
  border-bottom: 0;
}

.quality-badge {
  display: inline-flex;
  justify-content: center;
  min-width: 68px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2ee;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.quality-badge.warning {
  background: #fff5d9;
  color: #8a5a00;
}

.quality-badge.error {
  background: #fde7e5;
  color: var(--danger);
}

.quality-message {
  min-width: 0;
}

.quality-message strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quality-message span,
.quality-time {
  color: var(--muted);
  font-size: 11px;
}

.user-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) minmax(120px, 0.7fr) auto;
  gap: 8px;
}

.users-list {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(120px, 0.8fr) 90px minmax(130px, 0.9fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #edf0ec;
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row .user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.user-row .user-active {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.user-row .user-active input {
  width: 16px;
  min-height: 16px;
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 980px) {
  .topbar {
    position: static;
  }

  .tools-menu {
    justify-self: start;
  }

  #viewSelect.topbar-action {
    min-width: 0;
  }

  .app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "workspace"
      "filters";
    grid-template-rows: minmax(0, 1fr) auto;
    height: auto;
    min-height: calc(100vh - 110px);
  }

  .app-shell:not(.sidebar-collapsed) .workspace,
  .app-shell.sidebar-collapsed .workspace {
    grid-area: workspace;
    min-height: 0;
  }

  .app-shell:not(.sidebar-collapsed) .filters-panel {
    grid-area: filters;
    width: 100%;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding-top: 8px;
  }

  .toast {
    right: 12px;
    left: 12px;
    bottom: 86px;
    max-width: none;
  }

  .filters-panel {
    position: static;
    max-height: min(42vh, 340px);
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
    overflow: auto;
  }

  .app-shell.sidebar-collapsed .filters-panel {
    height: 0;
    max-height: 0;
    min-height: 0;
    padding: 0;
    border-bottom: 0;
    opacity: 0;
    pointer-events: none;
  }

  .filter-popover {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: min(80vh, calc(100vh - 120px));
  }

  .popover-values {
    max-height: min(220px, calc(100vh - 340px));
  }
}

@media (max-width: 390px) {
  :root {
    --topbar-height: 206px;
  }

  body {
    font-size: 12px;
  }

  .topbar {
    padding: 6px 10px 7px;
    gap: 6px;
  }

  .topbar h1 {
    font-size: 15px;
  }

  .topbar p {
    font-size: 11px;
  }

  .view-controls {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }

  .topbar-action,
  #pageSize.topbar-action,
  #viewSelect.topbar-action,
  .mode-toggle.topbar-action {
    min-width: 0;
    font-size: 11.2px;
  }

  .app-shell {
    min-height: calc(100vh - 104px);
  }

  .workspace {
    padding: 8px;
  }

  .table-frame {
    min-height: min(60vh, calc(100vh - 320px));
    height: min(60vh, calc(100vh - 320px));
  }
}
