/* Авто-адаптивный табличный движок (1..15+ колонок), липкая первая колонка и защита степпера ±50 ₽ */

.bb-table-shell {
  container-type: inline-size;
  width: 100%;
  min-width: 0;
}

.bb-tbl-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
}

.bb-table-scroll {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

.bb-tbl-wide-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.bb-data-table {
  width: 100%;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.bb-data-table.is-single-col,
.bb-data-table.is-compact-cols {
  width: 100%;
  min-width: 0;
  table-layout: auto;
}

.bb-data-table:not(.is-compact-cols):not(.is-wide-cols) {
  width: 100%;
  min-width: min(100%, calc(var(--bb-col-count, 5) * 124px));
  table-layout: auto;
}

.bb-data-table.is-wide-cols {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.bb-data-table th {
  white-space: nowrap;
  text-align: left;
}

.bb-data-table td {
  vertical-align: top;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

.bb-data-table:not(.is-single-col) td > .stack,
.bb-data-table:not(.is-single-col) td .stack {
  grid-template-columns: minmax(min-content, 1fr);
  min-width: min-content;
}

.bb-data-table td .bb-tbl-st,
.bb-data-table td .bb-tbl-act-btn,
.bb-data-table td b.num,
.bb-data-table td span.num {
  white-space: nowrap;
}

/* Липкая первая колонка для широких таблиц 7..15+ колонок */
.bb-data-table.is-wide-cols th:first-child,
.bb-data-table.is-wide-cols td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 6px 0 12px -8px rgba(0, 0, 0, .18);
}

.bb-data-table.is-wide-cols th:first-child {
  background: var(--surface-2);
  z-index: 3;
}

.bb-data-table.is-wide-cols tbody tr:hover td:first-child {
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}

/* Компактная 1-колоночная карточка */
.bb-tbl-single-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  min-width: 0;
}

.bb-tbl-single-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1 1 220px;
}

.bb-tbl-single-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

/* Починка сжатия степпера ±50 ₽ внутри табличных ячеек */
.bb-data-table td .hh-price-stepper.compact {
  display: inline-grid;
  grid-template-columns: auto minmax(78px, max-content) auto;
  width: max-content;
  max-width: none;
  min-width: 0;
  gap: 3px;
  padding: 3px;
  min-height: 34px;
  white-space: nowrap;
  align-items: center;
}

.bb-data-table td .hh-price-stepper.compact .hh-step-btn {
  flex-shrink: 0;
  white-space: nowrap;
  min-width: max-content;
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.bb-data-table td .hh-price-stepper.compact .hh-step-readout {
  white-space: nowrap;
  min-height: 28px;
  padding: 0 6px;
}

.bb-data-table td .hh-price-stepper.compact .hh-step-readout b {
  font-size: 13px;
  white-space: nowrap;
}

/* Мобильная карточная адаптация 1..15 колонок */
@container (max-width: 640px) {
  .bb-tbl-wide-bar {
    display: none;
  }

  .bb-table-shell .table-wrap,
  .bb-table-shell .bb-table-scroll {
    overflow: visible;
    border: 0;
    background: transparent;
    padding: 0;
    border-radius: 0;
  }

  .bb-data-table.is-adaptive {
    display: block;
    width: 100%;
    min-width: 0 !important;
    border-collapse: separate;
  }

  .bb-data-table.is-adaptive thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .bb-data-table.is-adaptive tbody {
    display: grid;
    gap: 10px;
    width: 100%;
  }

  .bb-data-table.is-adaptive tr {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    min-width: 0;
  }

  .bb-data-table.is-wide-cols th:first-child,
  .bb-data-table.is-wide-cols td:first-child {
    position: static;
    box-shadow: none;
    background: transparent;
  }

  .bb-data-table.is-adaptive tbody tr:hover td,
  .bb-data-table.is-wide-cols tbody tr:hover td:first-child {
    background: transparent;
  }

  .bb-tbl-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    width: 100%;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .bb-tbl-filters::-webkit-scrollbar {
    display: none;
  }

  .bb-tbl-filters .chip-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0 11px;
    min-height: 34px;
    font-size: 12.5px;
  }

  .bb-data-table.is-adaptive td {
    display: grid;
    grid-template-columns: minmax(90px, 36%) minmax(0, 1fr);
    align-items: start;
    gap: 6px 12px;
    padding: 8px 0;
    min-width: 0;
    width: 100%;
    text-align: right;
    white-space: normal;
    border-bottom: 1px dashed color-mix(in srgb, var(--line) 75%, transparent);
  }

  .bb-data-table.is-adaptive td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .bb-data-table.is-adaptive td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    line-height: 1.35;
    min-width: 0;
    overflow-wrap: break-word;
  }

  .bb-data-table.is-single-col td,
  .bb-data-table.is-adaptive td[colspan] {
    grid-template-columns: minmax(0, 1fr);
    text-align: left;
  }

  .bb-data-table.is-adaptive td[colspan] {
    text-align: center;
  }

  .bb-data-table.is-single-col td::before,
  .bb-data-table.is-adaptive td[colspan]::before {
    display: none;
  }

  .bb-data-table.is-single-col .bb-tbl-single-card {
    width: 100%;
  }

  .bb-data-table.is-adaptive td > * {
    max-width: 100%;
    min-width: 0 !important;
    justify-self: end;
  }

  .bb-data-table.is-adaptive:not(.is-single-col) td > .stack,
  .bb-data-table.is-adaptive:not(.is-single-col) td .stack,
  .bb-data-table.is-adaptive td > .stack,
  .bb-data-table.is-adaptive td .stack {
    width: 100%;
    min-width: 0 !important;
    grid-template-columns: minmax(0, 1fr);
    justify-items: end;
  }

  .bb-data-table.is-adaptive td .row {
    justify-content: flex-end;
    max-width: 100%;
    min-width: 0;
  }

  .bb-data-table.is-adaptive td .chip {
    max-width: 100%;
    white-space: normal;
    height: auto;
    min-height: 24px;
    padding: 3px 9px;
    line-height: 1.25;
    text-align: right;
  }

  .bb-data-table.is-adaptive td .field {
    width: 100%;
    justify-self: stretch;
    text-align: left;
  }

  .bb-data-table.is-adaptive td .input,
  .bb-data-table.is-adaptive td select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .bb-data-table.is-adaptive td .btn {
    max-width: 100%;
    box-sizing: border-box;
  }

  .bb-data-table.is-adaptive td .hh-price-stepper,
  .bb-data-table.is-adaptive td .hh-price-stepper.compact {
    display: grid;
    grid-template-columns: auto minmax(88px, 1fr) auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .bb-data-table.is-adaptive td .bb-tbl-st {
    justify-self: end;
  }

  .bb-data-table.is-adaptive td .bb-tbl-st-cell,
  .bb-data-table.is-adaptive td .msg-channel-bar,
  .bb-data-table.is-adaptive td .auto-ch-bar,
  .bb-data-table.is-adaptive td .bb-msg-links {
    justify-content: flex-end;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell {
    grid-template-columns: minmax(0, 1fr);
    text-align: left;
    gap: 8px;
    padding-top: 10px;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell > *,
  .bb-data-table.is-adaptive:not(.is-single-col) td.bb-tbl-actions-cell > .stack,
  .bb-data-table.is-adaptive td.bb-tbl-actions-cell > .stack {
    width: 100%;
    justify-self: stretch;
    justify-items: stretch;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bb-tbl-st {
    justify-self: start;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .msg-channel-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .msg-channel-bar .btn-msg {
    width: 100%;
    min-width: 0;
    justify-content: center;
    padding: 0 6px;
    min-height: 34px;
    border-radius: 10px;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-pending-btns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-secondary-btn,
  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-pending-btns .btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 720px) {
  .bb-tbl-wide-bar {
    display: none;
  }

  .bb-table-shell .table-wrap,
  .bb-table-shell .bb-table-scroll {
    overflow: visible;
    border: 0;
    background: transparent;
    padding: 0;
    border-radius: 0;
  }

  .bb-tbl-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    width: 100%;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .bb-tbl-filters::-webkit-scrollbar {
    display: none;
  }

  .bb-tbl-filters .chip-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0 11px;
    min-height: 34px;
    font-size: 12.5px;
  }

  .bb-data-table.is-wide-cols th:first-child,
  .bb-data-table.is-wide-cols td:first-child {
    position: static;
    box-shadow: none;
    background: transparent;
  }

  .bb-data-table.is-adaptive tbody tr:hover td,
  .bb-data-table.is-wide-cols tbody tr:hover td:first-child {
    background: transparent;
  }

  .bb-data-table.is-adaptive td {
    display: grid;
    grid-template-columns: minmax(90px, 36%) minmax(0, 1fr);
    align-items: start;
    gap: 6px 12px;
    padding: 8px 0;
    min-width: 0;
    width: 100%;
    text-align: right;
    white-space: normal;
    border-bottom: 1px dashed color-mix(in srgb, var(--line) 75%, transparent);
  }

  .bb-data-table.is-adaptive td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .bb-data-table.is-adaptive td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    line-height: 1.35;
    min-width: 0;
    overflow-wrap: break-word;
  }

  .bb-data-table.is-single-col td,
  .bb-data-table.is-adaptive td[colspan] {
    grid-template-columns: minmax(0, 1fr);
    text-align: left;
  }

  .bb-data-table.is-adaptive td[colspan] {
    text-align: center;
  }

  .bb-data-table.is-single-col td::before,
  .bb-data-table.is-adaptive td[colspan]::before {
    display: none;
  }

  .bb-data-table.is-single-col .bb-tbl-single-card {
    width: 100%;
  }

  .bb-data-table.is-adaptive td > * {
    max-width: 100%;
    min-width: 0 !important;
    justify-self: end;
  }

  .bb-data-table.is-adaptive:not(.is-single-col) td > .stack,
  .bb-data-table.is-adaptive:not(.is-single-col) td .stack,
  .bb-data-table.is-adaptive td > .stack,
  .bb-data-table.is-adaptive td .stack {
    width: 100%;
    min-width: 0 !important;
    grid-template-columns: minmax(0, 1fr);
    justify-items: end;
  }

  .bb-data-table.is-adaptive td .row {
    justify-content: flex-end;
    max-width: 100%;
    min-width: 0;
  }

  .bb-data-table.is-adaptive td .chip {
    max-width: 100%;
    white-space: normal;
    height: auto;
    min-height: 24px;
    padding: 3px 9px;
    line-height: 1.25;
    text-align: right;
  }

  .bb-data-table.is-adaptive td .btn {
    max-width: 100%;
    box-sizing: border-box;
  }

  .bb-data-table.is-adaptive td .hh-price-stepper,
  .bb-data-table.is-adaptive td .hh-price-stepper.compact {
    display: grid;
    grid-template-columns: auto minmax(88px, 1fr) auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell {
    grid-template-columns: minmax(0, 1fr);
    text-align: left;
    gap: 8px;
    padding-top: 10px;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell > *,
  .bb-data-table.is-adaptive:not(.is-single-col) td.bb-tbl-actions-cell > .stack,
  .bb-data-table.is-adaptive td.bb-tbl-actions-cell > .stack {
    width: 100%;
    justify-self: stretch;
    justify-items: stretch;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bb-tbl-st {
    justify-self: start;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .msg-channel-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .msg-channel-bar .btn-msg {
    width: 100%;
    min-width: 0;
    justify-content: center;
    padding: 0 6px;
    min-height: 34px;
    border-radius: 10px;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-pending-btns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-secondary-btn,
  .bb-data-table.is-adaptive td.bb-tbl-actions-cell .bk-tbl-pending-btns .btn {
    width: 100%;
    justify-content: center;
  }
}
