/**
 * ACF-Feldtyp custom_table — eine Datei fuer Backend (ACF/Eingabe) und Frontend-Ausgabe.
 *
 * 1. ACF-/wp-admin-spezifische Fixes (pointer-events, z-index, stabilere Grid-Spalten).
 * 2. Gemeinsamer Editor (.acf-custom-table-editor …): wp-admin und acf_form im Frontend.
 * 3. Gelesene Tabellen (.custom-table …): keine ACF-Oberflaeche noetig.
 *
 * Themes `grey` / `lightblue`: helle Grundtoene; Kopfzeile Hellblau ohne Corporate-Dunkel (#003762).
 * Kopf- und Tabellentextfarbe explizit (guter Kontrast, kein Erbe vom Artikel-/Formularskin).
 */

/* ==========================================================================
   1. WP-Admin / ACF: Zuverlaessigkeit im Backend (ACF ohne Theme-style.css).
   ========================================================================== */

.acf-field[data-type="custom_table"] .acf-custom-table-editor,
.acf-field[data-type="custom_table"] .acf-custom-table-editor *,
.acf-field-custom_table .acf-custom-table-editor,
.acf-field-custom_table .acf-custom-table-editor * {
  pointer-events: auto !important;
}

.acf-field[data-type="custom_table"] .acf-custom-table-editor,
.acf-field-custom_table .acf-custom-table-editor {
  position: relative;
  z-index: 10010;
}

.acf-field[data-type="custom_table"] .acf-custom-table-editor__row,
.acf-field-custom_table .acf-custom-table-editor__row {
  display: grid !important;
  grid-template-columns: 28px repeat(var(--cols, 3), minmax(0, 1fr)) 36px;
  align-items: stretch;
  border-bottom: 1px solid #e5e5e5;
  box-sizing: border-box;
}

/* ==========================================================================
   2. Editor (Eingabe)
   ========================================================================== */

.acf-custom-table-editor {
  display: block;
  width: 100%;
}

.acf-custom-table-editor__instance-hint {
  margin: 0 0 8px;
  max-width: 48rem;
  font-size: 12px;
  line-height: 1.45;
  color: #646970;
}

.acf-custom-table-editor__mount {
  display: block;
}

.acf-custom-table-editor__toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 10px;
}

/* WP-Admin / ACF: label oft block + 100% Breite — Toolbar-Controls sonst gestapelt. */
.acf-custom-table-editor__tool {
  display: inline-flex !important;
  flex: 0 1 auto;
  width: auto !important;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #444;
}

.acf-custom-table-editor__tool-label {
  font-weight: 600;
  white-space: nowrap;
}

.acf-custom-table-editor__tool-input {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid #c3c4c7;
  border-radius: 3px;
  background: #fff;
  font-size: 13px;
  line-height: 1.3;
  box-sizing: border-box;
}

.acf-custom-table-editor__tool-select {
  min-width: 8rem;
  padding: 4px 22px 4px 6px;
  border: 1px solid #c3c4c7;
  border-radius: 3px;
  background: #fff;
  font-size: 13px;
  line-height: 1.3;
  box-sizing: border-box;
  cursor: pointer;
}

.acf-custom-table-editor__tool-checkbox {
  margin: 0;
}

.acf-custom-table-editor__tool--toggle {
  cursor: pointer;
}

.acf-custom-table-editor__grid {
  display: block;
  border: 1px solid #dcdcde;
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
}

.acf-custom-table-editor__grid--grey {
  border-color: #cfd6de;
}

.acf-custom-table-editor__grid--lightblue {
  border-color: #c0d4ea;
}

.acf-custom-table-editor__body {
  display: block;
}

.acf-custom-table-editor__row {
  display: grid;
  grid-template-columns: 28px repeat(var(--cols, 3), minmax(0, 1fr)) 36px;
  align-items: stretch;
  border-bottom: 1px solid #e5e5e5;
}

.acf-custom-table-editor__row:last-child {
  border-bottom: 0;
}

.acf-custom-table-editor__row.is-drag-over {
  background: rgba(0, 55, 98, 0.06);
}

.acf-custom-table-editor__row.is-dragging {
  opacity: 0.5;
}

.acf-custom-table-editor__row--header {
  background: #f6f7f7;
}

.acf-custom-table-editor__row--header .acf-custom-table-editor__input {
  font-weight: 700;
}

/* Admin-Vorschau der Design-Varianten (hell, luftig — entspricht Frontend). */
.acf-custom-table-editor__grid--grey .acf-custom-table-editor__row--header {
  background: #f0f2f4;
}

.acf-custom-table-editor__grid--grey .acf-custom-table-editor__row--header .acf-custom-table-editor__input {
  color: #1a202c;
  background: #ffffff;
  border-color: #c5cbd3;
}

.acf-custom-table-editor__grid--grey .acf-custom-table-editor__row--header .acf-custom-table-editor__input::placeholder {
  color: #5c6570 !important;
  opacity: 1;
}

.acf-custom-table-editor__grid--lightblue .acf-custom-table-editor__row--header {
  background: #eaf4fb;
}

.acf-custom-table-editor__grid--lightblue .acf-custom-table-editor__row--header .acf-custom-table-editor__input {
  color: #0f2844;
  background: #eaf4fb;
  border-color: #b8cce3;
}

.acf-custom-table-editor__grid--lightblue .acf-custom-table-editor__row--header .acf-custom-table-editor__input::placeholder {
  color: #3d546c !important;
  opacity: 1;
}

.acf-custom-table-editor__grid--lightblue .acf-custom-table-editor__row--header .acf-custom-table-editor__input:focus {
  background: #ffffff;
  color: #1a202c;
  border-color: #6a9dc4;
  outline-color: #6a9dc4;
}

.acf-custom-table-editor__cell {
  padding: 6px 8px;
  display: flex;
  align-items: stretch;
  box-sizing: border-box;
  border-right: 1px solid #eeeeee;
}

.acf-custom-table-editor__cell:last-child {
  border-right: 0;
}

.acf-custom-table-editor__cell--handle {
  cursor: grab;
  user-select: none;
  background: #f7f7f7;
  padding: 0;
  align-items: center;
  justify-content: center;
}

.acf-custom-table-editor__drag-icon {
  color: #9b9b9b;
  font-size: 14px;
  line-height: 1;
  letter-spacing: -2px;
}

.acf-custom-table-editor__cell--actions {
  padding: 0;
  align-items: center;
  justify-content: center;
  background: #fafafa;
}

.acf-custom-table-editor__input {
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid #dcdcde;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.4;
  resize: vertical;
  box-sizing: border-box;
  background: #fff;
  /* Eigener Text — verhindert Erbe von Theme-._text-* / Eltern (z. B. acf_form). */
  color: #1a1a1a;
}

/* theme admin.css: .acf-input ::placeholder { … !important } */
.acf-custom-table-editor__input::placeholder {
  color: #757575 !important;
  opacity: 1;
}

.acf-custom-table-editor__input:focus {
  border-color: #003762;
  outline: 1px solid #003762;
  outline-offset: 0;
}

.acf-custom-table-editor__remove {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid #c3c4c7;
  border-radius: 50%;
  background: #fff;
  color: #6f6f6f;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.acf-custom-table-editor__remove:hover {
  background: #b32d2e;
  border-color: #b32d2e;
  color: #fff;
}

.acf-custom-table-editor__footer {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
}

.acf-custom-table-editor__add {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid #003762;
  border-radius: 3px;
  background: #fff;
  color: #003762;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.acf-custom-table-editor__add:hover {
  background: #003762;
  color: #fff;
}

.acf-custom-table-editor__add[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.acf-custom-table-editor__add[disabled]:hover {
  background: #fff;
  color: #003762;
}

/* ==========================================================================
   3. Frontend-Ausgabe (gelesene Tabellen)
   ========================================================================== */

.custom-table-wrap {
  width: 100%;
  max-width: 100%;
  margin: 1.25em 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 4px;
  /* Fallback, wenn :has() nicht greift */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.custom-table-wrap:has(.custom-table--grey) {
  box-shadow: inset 0 0 0 1px rgba(55, 65, 78, 0.12);
}

.custom-table-wrap:has(.custom-table--lightblue) {
  box-shadow: inset 0 0 0 1px rgba(45, 100, 145, 0.13);
}

.custom-table {
  width: max-content;
  min-width: 100%;
  max-width: none;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
  table-layout: auto;
  color: #1a202c;
}

.custom-table caption {
  caption-side: top;
  padding: 0.5em 0;
  font-weight: 600;
  text-align: left;
}

.custom-table th,
.custom-table td {
  padding: 10px 14px;
  vertical-align: top;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.custom-table thead th {
  font-weight: 700;
  /* Themes mit variabler Schriftarte: ohne feste wght oft normal statt Bold trotz font-weight */
  font-variation-settings: "wght" 700;
}

.custom-table tbody th {
  font-weight: 700;
  font-variation-settings: "wght" 700;
}

.custom-table tbody tr + tr {
  border-top: 1px solid transparent;
}

.custom-table.custom-table--layout-equal,
.custom-table.custom-table--layout-first-wide {
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  table-layout: fixed;
}

.custom-table--layout-first-wide th:first-child:not(:only-child),
.custom-table--layout-first-wide td:first-child:not(:only-child) {
  width: 40%;
  min-width: 6rem;
}

.custom-table-wrap--no-wrap-mobile {
  --bdsf-ct-compare-min: 40rem;
}

@media (max-width: 991.98px) {
  .custom-table-wrap--no-wrap-mobile {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 991.98px) {
  .custom-table-wrap--no-wrap-mobile .custom-table {
    table-layout: auto;
    width: max-content;
    min-width: max(100%, var(--bdsf-ct-compare-min, 40rem));
    max-width: none;
    font-size: clamp(0.6875rem, calc(0.52rem + 0.7vw), 0.9375rem);
    line-height: 1.45;
  }

  .custom-table-wrap--no-wrap-mobile .custom-table th,
  .custom-table-wrap--no-wrap-mobile .custom-table td {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    hyphens: manual;
  }
}

@media (max-width: 767.98px) {
  .custom-table {
    font-size: 14px;
    line-height: 1.45;
  }

  .custom-table th,
  .custom-table td {
    padding: 8px 10px;
  }

  .custom-table-wrap--no-wrap-mobile .custom-table {
    font-size: clamp(0.625rem, calc(0.48rem + 0.85vw), 0.875rem);
  }
}

/* Design: Grau — Rahmen durchgehend grau-neutral, nur leicht Staerker als Flaeche */
.custom-table--grey {
  border: 1px solid #cfd6de;
}

.custom-table-wrap .custom-table--grey thead {
  background: #f0f2f4;
  color: #1a202c;
}

.custom-table-wrap .custom-table--grey thead th {
  color: #1a202c;
  border-bottom: 2px solid #c5ccd5;
  font-weight: 700;
  font-variation-settings: "wght" 700;
}

.custom-table--grey tbody tr {
  background: #ffffff;
}

.custom-table--grey.custom-table--striped tbody tr:nth-child(even) {
  background: #f8f9fb;
}

.custom-table--grey tbody td {
  border-bottom: 1px solid #dde2e9;
}

.custom-table--grey tbody tr:last-child td {
  border-bottom: 0;
}

/* Design: Hellblau — Rahmen leicht blau gegraut, dezent sichtbar */
.custom-table--lightblue {
  border: 1px solid #c0d4ea;
}

.custom-table-wrap .custom-table--lightblue thead {
  background: #eaf4fb;
  color: #0f2844;
}

.custom-table-wrap .custom-table--lightblue thead th {
  color: #0f2844;
  border-bottom: 2px solid #a8c4e3;
  font-weight: 700;
  font-variation-settings: "wght" 700;
}

.custom-table--lightblue tbody tr {
  background: #ffffff;
}

.custom-table--lightblue.custom-table--striped tbody tr:nth-child(even) {
  background: #f5f9fd;
}

.custom-table--lightblue tbody td {
  border-bottom: 1px solid #d0e3f5;
}

.custom-table--lightblue tbody tr:last-child td {
  border-bottom: 0;
}
