/*******************************
   TABULATOR EXTENSIONS
   Nested rows, toggle cells, detail holder and row highlight.
*******************************/

/* Data loading and error states */
.tabulator .tabulator-alert {
  box-sizing: border-box;
  padding: 1rem;
  background: color-mix(in srgb, var(--body-background-color) 72%, transparent);
  backdrop-filter: blur(1px);
}

.tabulator .tabulator-alert .tabulator-alert-msg.tabulator-alert-state-msg,
.tabulator .tabulator-alert .tabulator-alert-msg.tabulator-alert-state-error {
  display: flex;
  align-items: center;
  max-width: calc(100% - 2rem);
  margin: auto;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-subtle-color);
  border-radius: var(--bulma-radius);
  background: var(--surface-card);
  box-shadow: var(--bulma-box-shadow);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.35;
  white-space: normal;
}

.tabulator .tabulator-alert .tabulator-alert-msg.tabulator-alert-state-error {
  border-left: 3px solid var(--bulma-danger);
  color: var(--text-primary);
  text-align: left;
}

.order-sales-table.tabulator .tabulator-alert {
  align-items: flex-start;
  padding-top: 3.5rem;
}

.order-sales-table.tabulator .tabulator-alert .tabulator-alert-msg {
  margin: 0 auto;
}

.tabulator-load-status,
.tabulator .tabulator-alert .loader-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.tabulator .tabulator-alert .loader {
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  border-color: color-mix(in srgb, var(--bulma-primary) 35%, transparent);
  border-right-color: var(--bulma-primary);
  border-top-color: var(--bulma-primary);
}

.tabulator .tabulator-alert .loader-wrapper::after {
  content: "Daten werden geladen \2026";
  color: var(--text-secondary);
}

.tabulator-load-status.is-loading {
  color: var(--text-secondary);
}

.tabulator-load-status.is-error iconify-icon {
  flex: 0 0 auto;
  color: var(--bulma-danger);
  font-size: 1.4rem;
}

.tabulator-load-status.is-error span {
  display: grid;
  gap: 0.1rem;
}

.tabulator-load-status.is-error strong {
  color: var(--text-primary);
  font-weight: 600;
}

.tabulator-load-status.is-error small {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* Nested row / detail box */
.nested-wrap {
  width: 100%;
  max-width: calc(100vw - 280px);
  overflow-x: auto;
  overflow-y: hidden;
  background-color: #1b1b1b;
  border-top: 1px solid var(--bulma-border);
  box-shadow:
    inset 0 15px 15px -15px rgba(255, 255, 255, 0.15),
    inset 0 -15px 15px -15px rgba(255, 255, 255, 0.10);
  transition: box-shadow 0.2s ease;
}

.nested-wrap:hover {
  background-color: #1f1f1f;
  box-shadow:
    inset 0 15px 15px -15px rgba(255, 255, 255, 0.25),
    inset 0 -15px 15px -15px rgba(255, 255, 255, 0.20);
}

.nested-wrap.delivery-tours-nested-wrap {
  width: 100%;
  max-width: none;
}

#finance-import-table .finance-import-nested-wrap {
  max-width: none;
}

.delivery-tours-nested-wrap .nested-box,
.delivery-tours-nested-table {
  width: 100%;
}

.nested-grid {
  display: block;
  min-width: 100%;
}

.nested-box {
  min-width: 100%;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  padding-bottom: 0;
  color: var(--bulma-text);
  box-shadow: none;
}

.nested-box:last-child {
  padding-bottom: 1rem;
}

.nested-title {
  font-weight: 600;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--bulma-primary);
}

.nested-title-with-search {
  display: flex;
  margin-bottom: 0.75rem;
}

.nested-title-search-control {
  max-width: 18rem;
}

.nested-title-search-control .input {
  width: 100%;
}

@media screen and (max-width: 480px) {
  .nested-title-with-search {
    width: 100%;
  }
}

.nested-wrap .tabulator-placeholder-contents {
  font-size: 0.95rem !important;
  font-weight: 450 !important;
}

.order-sales-greeting-message-row .tabulator-cell {
  background: color-mix(in srgb, var(--surface-card) 78%, transparent);
  color: var(--text-secondary);
}

.order-sales-greeting-message-row .tabulator-cell[tabulator-field="product_label"] {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.sales-order-greeting-message {
  align-items: flex-start;
  display: flex;
  line-height: 1.35;
  padding-bottom: .2rem;
  padding-top: .2rem;
  white-space: pre-wrap;
}

.sales-order-greeting-message > iconify-icon {
  flex: 0 0 auto;
  margin-top: .1rem;
}

.sales-order-position-depth-1 {
  margin-left: 1.5rem;
}

.sales-order-position-depth-2 {
  margin-left: 3rem;
}

.purchase-order-positions-table .tabulator-tableholder {
  overflow-y: hidden;
}

.product-bundle-items-table .tabulator-tableholder,
.product-bundle-items-summary-table .tabulator-tableholder {
  scrollbar-gutter: stable;
}

/* Toggle cell */
.toggle-cell {
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  color: var(--bulma-primary);
  user-select: none;
}

.toggle-cell:hover {
  background-color: var(--bulma-primary-soft);
  color: var(--bulma-primary);
}

.toggle-cell iconify-icon {
  font-size: 1.2rem;
  vertical-align: middle;
}

.toggle-cell.is-loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

#table .tabulator-cell.toggle-cell {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

#table .tabulator-cell.toggle-cell .toggle-cell {
  height: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#table .tabulator-cell.toggle-cell iconify-icon {
  display: block;
  line-height: 1;
  vertical-align: middle;
}

#table .tabulator-cell.toggle-cell .toggle-cell.is-loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Kein Pointer auf ganzen Rows */
.tabulator-row,
.tabulator-row:hover {
  cursor: default !important;
}

/* Detail holder animation */
.js-detail-holder {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition:
    max-height 220ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

.js-detail-holder.is-open {
  opacity: 1;
  transform: translateY(0);
}

.js-detail-holder.is-preparing {
  visibility: hidden;
  position: relative;
}

/* Light theme deviations */
html[data-theme="light"] .nested-wrap {
  padding: 0.5rem 0.75rem 0.75rem;
  background-color: var(--bulma-scheme-main);
}

html[data-theme="light"] .nested-box {
  border: 0 solid var(--bulma-border);
}

/* Row highlight animation */
@keyframes tabRowFlashBg {
  0% {
    background-color: rgba(255, 230, 120, 0.42);
  }
  100% {
    background-color: rgba(255, 230, 120, 0);
  }
}

.tabulator-row.tabulator-highlight .tabulator-cell {
  animation: tabRowFlashBg var(--flash-ms, 2800ms) ease-out;
  outline: 1px solid transparent;
  outline-offset: -1px;
}
