/* ==========================================================================
   Apebox Theme — table system
   --------------------------------------------------------------------------
   Ported from the arizto_web reference theme (sass/base/_table.scss), hand
   converted to plain CSS. Clean, minimal table styling built on the design
   tokens in styles.css; all colors flip automatically in dark mode.
   ========================================================================== */

/* Base table styles */
table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-lg);
  background-color: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  overflow-x: scroll;
  box-shadow: var(--shadow-sm);
}

/* Table header: flat, column titles in the accent color like btop. */
thead {
  background-color: transparent;
}

th,
td {
  font-size: var(--font-size-md);
  color: var(--color-text-primary);
  vertical-align: middle;
}

/* Cells share the universal border-to-text inset — every row is one
   grid row tall. */
th {
  padding: var(--box-pad-y) var(--box-pad-x);
  text-align: left;
  font-weight: 700;
  color: var(--color-link);
  border-bottom: 1px solid var(--color-border-medium);
}

td {
  padding: var(--box-pad-y) var(--box-pad-x);
}

/* Table body */
tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: background-color 0.2s ease;
}

tbody tr:last-child {
  border-bottom: none;
}

/* No striping — TUI lists are flat; the row hover highlight below and
   the hairline separators carry the structure. */
tbody tr:nth-child(odd),
tbody tr:nth-child(even) {
  background-color: transparent;
}

/* Hover effect */
tbody tr:hover {
  background-color: var(--color-bg-tertiary);
}

/* First column (ID column) styling */
td:first-child,
th:first-child {
  font-weight: 700;
  color: var(--color-text-primary);
}

/* Table footer */
tfoot {
  background-color: var(--color-bg-secondary);
  border-top: 2px solid var(--color-border-medium);
}

tfoot td {
  font-weight: 700;
  padding: calc(var(--row) / 2) var(--box-pad-x);
}

/* Responsive table wrapper */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Compact table variant (the grid is already compact; only type shrinks) */
table.table--compact th,
table.table--compact td {
  padding: var(--box-pad-y) var(--box-pad-x);
  font-size: var(--font-size-sm);
}

/* Bordered table variant */
table.table--bordered {
  border: 1px solid var(--color-border-light);
}

table.table--bordered th,
table.table--bordered td {
  border: 1px solid var(--color-border-light);
}

/* Striped table variant (no hover) */
table.table--striped tbody tr:hover {
  background-color: inherit;
}

/* Table with actions column */
td.table__actions {
  text-align: right;
  white-space: nowrap;
}

td.table__actions .button,
td.table__actions .btn {
  margin-left: 1ch;
}

/* Status badges in tables */
.table__status {
  display: inline-block;
  padding: 0 1ch;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.25ch;
}

.table__status--open {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.table__status--pending {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
}

.table__status--closed {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-muted);
}

.table__status--error {
  background-color: var(--color-error-light);
  color: var(--color-error);
}

/* Empty state */
.table__empty {
  text-align: center;
  padding: var(--row) 2ch;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Sortable column headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 3ch;
}

th.sortable:hover {
  background-color: var(--color-bg-tertiary);
}

th.sortable::after {
  content: '↕';
  position: absolute;
  right: 1ch;
  opacity: 0.5;
  font-size: var(--font-size-sm);
}

th.sortable--asc::after {
  content: '↑';
  opacity: 1;
}

th.sortable--desc::after {
  content: '↓';
  opacity: 1;
}

/* Dark mode: no overrides needed — base rules use tokens
   (--color-bg-primary/secondary etc.) that flip in dark mode. */

@media (max-width: 42.5em) {
  table .mobile-hide {
    display: none;
  }
}

/* Mobile responsive */
@media (max-width: 768px) {
  /* Stack table on mobile */
  table.table--responsive {
    border: 0;
  }

  table.table--responsive thead {
    display: none;
  }

  table.table--responsive tbody,
  table.table--responsive tr,
  table.table--responsive td {
    display: block;
    width: 100%;
  }

  table.table--responsive tr {
    margin-bottom: var(--space-lg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-md);
  }

  table.table--responsive td {
    padding: var(--space-sm) 0;
    text-align: left;
    border: none;
    position: relative;
    padding-left: 50%;
  }

  table.table--responsive td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    width: 45%;
    padding-right: 1ch;
    font-weight: 700;
    text-align: left;
  }
}

/* Paragraphs widget table cleanup (no-op unless paragraphs is installed) */
.node-form .field--widget-paragraphs table > thead th .label {
  display: inline-block;
}

.node-form .field--widget-paragraphs table > thead th .paragraphs-actions {
  margin-right: calc(var(--space-mld) * -1);
}

.node-form .field--widget-paragraphs table > thead th .paragraphs-dropdown-toggle {
  min-height: 40px;
}

.node-form .field--widget-paragraphs table td.field-multiple-drag {
  border-right-width: 0;
}

.node-form .field--widget-paragraphs table td.field-multiple-drag + td {
  border-width: 0;
  padding-right: var(--space-md, 1rem);
}

.node-form .field--widget-paragraphs .paragraph-type-label {
  font-weight: 700;
}

/* Dropdown button widget fix */
.dropbutton-wrapper .dropbutton-widget {
  padding: var(--space-xs);
}

/* Core's dropbutton.css spaces the widget with raw em values; restate them
   on the spacing tokens. (The 10em open-list reservation on
   .js td .dropbutton-multiple has no token equivalent and stays core's.) */
.js .dropbutton-multiple .dropbutton-widget {
  padding-right: var(--space-xl);
}

.js td .dropbutton-wrapper {
  min-height: var(--space-xl);
}

.js td .dropbutton-multiple {
  margin-right: var(--space-xl);
}

.dropbutton-wrapper.open .dropbutton-widget {
  border-radius: var(--radius-lg);
  background: var(--color-bg-secondary);
  padding-right: var(--size-s);
}

.dropbutton-wrapper .dropbutton-toggle {
  width: 1.75rem;
}

/* The toggle is a bare icon control, not a button: neutralise the global
   button styling, including its hover/focus/active states. */
.dropbutton-toggle button,
.dropbutton-toggle button:hover,
.dropbutton-toggle button:focus,
.dropbutton-toggle button:active {
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
}

/* Replace core's border-drawn triangle with the theme chevron icon (same
   asset the select fields use). Core draws the triangle via border-width on
   a zero-size span, so the border must be cleared in both states. */
.dropbutton-wrapper .dropbutton-toggle .dropbutton-arrow {
  right: 30%;
  width: 0.75rem;
  height: 0.4375rem;
  margin-top: -0.21875rem;
  border: 0;
  background: url(../icons/chevron-light.svg) center no-repeat;
  background-size: contain;
}

.dropbutton-wrapper.open .dropbutton-toggle .dropbutton-arrow {
  top: 50%;
  border: 0;
  transform: rotate(180deg);
}

/* Dark is the default scheme — the light chevron is already the default
   (set above); swap to the dark chevron on the light-terminal scheme. */
html[data-dark-mode="light"] .dropbutton-arrow {
  background-image: url(../icons/chevron.svg);
}

@media (prefers-color-scheme: light) {
  html:not([data-dark-mode]) .dropbutton-arrow {
    background-image: url(../icons/chevron.svg);
  }
}

/* Table drag icon fix */
a.tabledrag-handle .handle {
  width: 22px;
  height: 22px;
}
