/**
 * table.css — FacultyPage Theme
 *
 * Covers every Drupal table context:
 *   - Standard content tables (fp-table)
 *   - Striped variant (fp-table--striped)
 *   - Bordered variant (fp-table--bordered)
 *   - Compact / dense variant (fp-table--compact)
 *   - Sortable column headers (tableheader.js)
 *   - Draggable rows (tabledrag.js)
 *   - Views admin tables
 *   - Responsive horizontal scroll wrapper
 *   - Status / badge cells
 *   - Sticky header (position: sticky)
 *   - Empty state row
 *   - Caption styling
 */

/* ════════════════════════════════════════════════════════════
   TABLE WRAPPER
   Provides horizontal scroll on small screens without
   breaking the outer layout.
   ════════════════════════════════════════════════════════════ */
.fp-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1.5px solid var(--fp-border);
  border-radius: var(--fp-radius-lg);
  background: var(--fp-white);
  box-shadow: var(--fp-shadow-sm);
}

/* Fade hint on right edge when overflowing */
.fp-table-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
  pointer-events: none;
  border-radius: 0 var(--fp-radius-lg) var(--fp-radius-lg) 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.fp-table-wrap.is-overflowing::after { opacity: 1; }
.fp-table-wrap { position: relative; }

/* ════════════════════════════════════════════════════════════
   BASE TABLE
   ════════════════════════════════════════════════════════════ */
.fp-table,
table.fp-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.95rem;
  color: var(--fp-charcoal);
  background: var(--fp-white);
}

/* ── CAPTION ── */
.fp-table caption,
table.fp-table caption {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--fp-charcoal);
  text-align: left;
  padding: 1.25rem 1.5rem 0.75rem;
  letter-spacing: -0.02em;
  caption-side: top;
  border-bottom: 1px solid var(--fp-border);
}
.fp-table caption .fp-table-caption-sub,
table.fp-table caption .fp-table-caption-sub {
  display: block;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--fp-light);
  margin-top: 0.2rem;
  letter-spacing: 0;
}

/* ── COLUMN GROUPS ── */
.fp-table colgroup col { }

/* ════════════════════════════════════════════════════════════
   TABLE HEAD
   ════════════════════════════════════════════════════════════ */
.fp-table thead,
table.fp-table thead {
  background: var(--fp-paper);
  position: relative;
}

.fp-table thead th,
table.fp-table thead th {
  padding: 0.8rem 1.25rem;
  font-family: 'Space Mono', monospace;
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fp-mid);
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid var(--fp-border-strong);
  vertical-align: middle;
  user-select: none;
}

/* First / last column padding */
.fp-table thead th:first-child,
.fp-table tbody td:first-child,
.fp-table tfoot td:first-child {
  padding-left: 1.5rem;
}
.fp-table thead th:last-child,
.fp-table tbody td:last-child,
.fp-table tfoot td:last-child {
  padding-right: 1.5rem;
}

/* ── STICKY HEADER ── */
.fp-table--sticky thead th,
table.fp-table--sticky thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--fp-paper);
  box-shadow: 0 1px 0 var(--fp-border-strong);
}

/* ════════════════════════════════════════════════════════════
   SORTABLE COLUMNS (Drupal tableheader.js)
   ════════════════════════════════════════════════════════════ */
.fp-table thead th a,
table.fp-table thead th a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s;
}
.fp-table thead th a:hover,
table.fp-table thead th a:hover {
  color: var(--fp-terra);
}

/* Sort indicator pseudo-element */
.fp-table thead th.is-active,
.fp-table thead th[aria-sort],
table.fp-table thead th.is-active {
  color: var(--fp-terra-dark);
  background: var(--fp-terra-pale);
}
.fp-table thead th.is-active a,
table.fp-table thead th.is-active a {
  color: var(--fp-terra-dark);
}

/* Arrow indicators */
.fp-table thead th[aria-sort="ascending"] a::after  { content: ' ↑'; font-size: 0.7rem; }
.fp-table thead th[aria-sort="descending"] a::after { content: ' ↓'; font-size: 0.7rem; }
.fp-table thead th[aria-sort="none"] a::after       { content: ' ⇅'; font-size: 0.7rem; color: var(--fp-sand); }

/* Drupal core tableheader classes */
.fp-table th.active,
table.fp-table th.active {
  color: var(--fp-terra-dark);
  background: var(--fp-terra-pale);
}
.fp-table th.active a,
table.fp-table th.active a {
  color: var(--fp-terra-dark);
}

/* ════════════════════════════════════════════════════════════
   TABLE BODY
   ════════════════════════════════════════════════════════════ */
.fp-table tbody tr,
table.fp-table tbody tr {
  border-bottom: 1px solid var(--fp-border);
  transition: background 0.12s;
}
.fp-table tbody tr:last-child,
table.fp-table tbody tr:last-child {
  border-bottom: none;
}
.fp-table tbody tr:hover,
table.fp-table tbody tr:hover {
  background: var(--fp-off-white);
}

.fp-table tbody td,
table.fp-table tbody td {
  padding: 0.85rem 1.25rem;
  vertical-align: middle;
  line-height: 1.5;
  color: var(--fp-charcoal);
}

/* ── STRIPED VARIANT ── */
.fp-table--striped tbody tr:nth-child(even),
table.fp-table--striped tbody tr:nth-child(even) {
  background: var(--fp-off-white);
}
.fp-table--striped tbody tr:nth-child(even):hover,
table.fp-table--striped tbody tr:nth-child(even):hover {
  background: var(--fp-paper);
}

/* ── BORDERED VARIANT ── */
.fp-table--bordered td,
.fp-table--bordered th,
table.fp-table--bordered td,
table.fp-table--bordered th {
  border: 1px solid var(--fp-border);
}

/* ── COMPACT / DENSE VARIANT ── */
.fp-table--compact thead th,
.fp-table--compact tbody td,
.fp-table--compact tfoot td,
table.fp-table--compact thead th,
table.fp-table--compact tbody td {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
}

/* ── HIGHLIGHTED ROW ── */
.fp-table tbody tr.is-highlighted,
table.fp-table tbody tr.is-highlighted {
  background: var(--fp-terra-pale);
}
.fp-table tbody tr.is-highlighted td,
table.fp-table tbody tr.is-highlighted td {
  color: var(--fp-terra-dark);
}

/* ── SELECTED ROW (checkboxes) ── */
.fp-table tbody tr.is-selected,
table.fp-table tbody tr.is-selected {
  background: var(--fp-blue-pale);
  border-left: 3px solid var(--fp-blue);
}

/* ════════════════════════════════════════════════════════════
   TABLE FOOTER
   ════════════════════════════════════════════════════════════ */
.fp-table tfoot,
table.fp-table tfoot {
  background: var(--fp-paper);
  border-top: 2px solid var(--fp-border-strong);
}
.fp-table tfoot td,
table.fp-table tfoot td {
  padding: 0.75rem 1.25rem;
  font-size: 0.82rem;
  color: var(--fp-mid);
  font-weight: 500;
}

/* ════════════════════════════════════════════════════════════
   CELL CONTENT HELPERS
   ════════════════════════════════════════════════════════════ */

/* Primary text inside a cell */
.fp-td-primary {
  font-weight: 600;
  color: var(--fp-charcoal);
}

/* Secondary / muted text (sub-line inside a cell) */
.fp-td-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--fp-light);
  margin-top: 0.15rem;
  line-height: 1.4;
}

/* Monospace value (IDs, codes, dates) */
.fp-td-mono {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: var(--fp-mid);
}

/* Avatar + name combo cell */
.fp-td-avatar-name {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Numeric / right-aligned cells */
.fp-table td.fp-td-num,
.fp-table th.fp-th-num {
  text-align: right;
  font-family: 'Space Mono', monospace;
  font-size: 0.8rem;
}

/* Actions cell — always right-aligned, never wraps */
.fp-table td.fp-td-actions {
  text-align: right;
  white-space: nowrap;
}
.fp-td-actions-group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.fp-td-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.65rem;
  font-size: 0.74rem;
  font-weight: 500;
  border-radius: var(--fp-radius-sm);
  border: 1.5px solid var(--fp-border);
  background: transparent;
  color: var(--fp-mid);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.fp-td-action-btn:hover {
  border-color: var(--fp-charcoal);
  color: var(--fp-charcoal);
  background: var(--fp-off-white);
}
.fp-td-action-btn--danger:hover {
  border-color: var(--fp-terra);
  color: var(--fp-terra-dark);
  background: var(--fp-terra-pale);
}
.fp-td-action-btn--primary:hover {
  border-color: var(--fp-terra);
  color: white;
  background: var(--fp-terra);
}

/* ════════════════════════════════════════════════════════════
   STATUS BADGES (inside table cells)
   ════════════════════════════════════════════════════════════ */
.fp-badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--fp-radius-pill);
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.fp-badge-status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.fp-badge-status--published,
.fp-badge-status--active,
.fp-badge-status--success {
  background: var(--fp-green-pale);
  color: var(--fp-green);
}
.fp-badge-status--published::before,
.fp-badge-status--active::before,
.fp-badge-status--success::before {
  background: var(--fp-green);
}

.fp-badge-status--unpublished,
.fp-badge-status--inactive,
.fp-badge-status--draft {
  background: var(--fp-paper);
  color: var(--fp-light);
}
.fp-badge-status--unpublished::before,
.fp-badge-status--inactive::before,
.fp-badge-status--draft::before {
  background: var(--fp-light);
}

.fp-badge-status--pending,
.fp-badge-status--review {
  background: #fff8e6;
  color: #8a6500;
}
.fp-badge-status--pending::before,
.fp-badge-status--review::before {
  background: #d4a017;
}

.fp-badge-status--error,
.fp-badge-status--blocked,
.fp-badge-status--danger {
  background: var(--fp-terra-pale);
  color: var(--fp-terra-dark);
}
.fp-badge-status--error::before,
.fp-badge-status--blocked::before,
.fp-badge-status--danger::before {
  background: var(--fp-terra);
}

.fp-badge-status--info,
.fp-badge-status--blue {
  background: var(--fp-blue-pale);
  color: var(--fp-blue);
}
.fp-badge-status--info::before,
.fp-badge-status--blue::before {
  background: var(--fp-blue);
}

/* ════════════════════════════════════════════════════════════
   DRAGGABLE ROWS (Drupal tabledrag.js)
   ════════════════════════════════════════════════════════════ */
.fp-table tbody tr.draggable,
table.fp-table tbody tr.draggable {
  cursor: grab;
}
.fp-table tbody tr.draggable:active,
table.fp-table tbody tr.draggable:active {
  cursor: grabbing;
}
.fp-table .tabledrag-handle,
table.fp-table .tabledrag-handle {
  width: 20px;
  cursor: grab;
  color: var(--fp-sand);
  font-size: 1rem;
  text-align: center;
  transition: color 0.15s;
  user-select: none;
}
.fp-table .tabledrag-handle:hover,
table.fp-table .tabledrag-handle:hover {
  color: var(--fp-mid);
}
.fp-table tbody tr.drag,
table.fp-table tbody tr.drag {
  background: var(--fp-terra-pale) !important;
  outline: 2px dashed var(--fp-terra);
  outline-offset: -2px;
  opacity: 0.85;
}
.fp-table tbody tr.drag-previous,
table.fp-table tbody tr.drag-previous {
  background: var(--fp-off-white);
  border-bottom: 2px dashed var(--fp-border-strong);
}

/* Indent levels for hierarchical drag */
.fp-table .indentation,
table.fp-table .indentation {
  display: inline-block;
  height: 1em;
  width: 1.5rem;
  margin: -0.4em 0.25rem -0.4em 0;
  padding: 0.42em 0 0.42em 0;
  border-left: 2px solid var(--fp-border);
  vertical-align: middle;
}
.fp-table .tree-child,
.fp-table .tree-child-last,
.fp-table .tree-child-horizontal {
  background: none;
}

/* ════════════════════════════════════════════════════════════
   EMPTY STATE ROW
   ════════════════════════════════════════════════════════════ */
.fp-table tbody .fp-table-empty,
table.fp-table tbody .fp-table-empty {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--fp-light);
}
.fp-table-empty-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}
.fp-table-empty-message {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fp-mid);
  display: block;
  margin-bottom: 0.3rem;
}
.fp-table-empty-sub {
  font-size: 0.8rem;
  color: var(--fp-light);
}

/* ════════════════════════════════════════════════════════════
   TABLE TOOLBAR (search + filter row above table)
   ════════════════════════════════════════════════════════════ */
.fp-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--fp-border);
  flex-wrap: wrap;
  background: var(--fp-white);
  border-radius: var(--fp-radius-lg) var(--fp-radius-lg) 0 0;
}
.fp-table-toolbar-title {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--fp-charcoal);
  letter-spacing: -0.02em;
}
.fp-table-toolbar-title span {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--fp-light);
  margin-left: 0.5rem;
  letter-spacing: 0.05em;
}
.fp-table-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.fp-table-search {
  position: relative;
}
.fp-table-search input {
  background: var(--fp-off-white);
  border: 1.5px solid var(--fp-border);
  border-radius: var(--fp-radius);
  padding: 0.42rem 0.9rem 0.42rem 2.2rem;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.82rem;
  color: var(--fp-charcoal);
  outline: none;
  width: 220px;
  transition: border-color 0.15s, width 0.25s;
}
.fp-table-search input:focus {
  border-color: var(--fp-terra);
  width: 270px;
}
.fp-table-search input::placeholder { color: var(--fp-sand); }
.fp-table-search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fp-light);
  font-size: 0.8rem;
  pointer-events: none;
}
.fp-table-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--fp-mid);
  border: 1.5px solid var(--fp-border);
  border-radius: var(--fp-radius);
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.fp-table-filter-btn:hover,
.fp-table-filter-btn.is-active {
  border-color: var(--fp-terra);
  color: var(--fp-terra-dark);
  background: var(--fp-terra-pale);
}

/* ════════════════════════════════════════════════════════════
   TABLE FOOTER PAGINATION ROW
   ════════════════════════════════════════════════════════════ */
.fp-table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  border-top: 1px solid var(--fp-border);
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--fp-white);
  border-radius: 0 0 var(--fp-radius-lg) var(--fp-radius-lg);
}
.fp-table-count {
  font-size: 0.78rem;
  color: var(--fp-light);
}
.fp-table-count strong {
  color: var(--fp-charcoal);
  font-weight: 600;
}

/* ════════════════════════════════════════════════════════════
   DRUPAL CORE OVERRIDES
   Targets default Drupal admin and content tables.
   ════════════════════════════════════════════════════════════ */

/* Views admin list tables */
.views-table,
.views-admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.855rem;
}
.views-table th,
.views-admin-table th {
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fp-mid);
  padding: 0.8rem 1rem;
  border-bottom: 2px solid var(--fp-border-strong);
  background: var(--fp-paper);
  text-align: left;
}
.views-table td,
.views-admin-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--fp-border);
  vertical-align: middle;
}
.views-table tbody tr:hover,
.views-admin-table tbody tr:hover {
  background: var(--fp-off-white);
}

/* Drupal core content list table (admin/content) */
.tableresponsive-processed {
  width: 100%;
}

/* Checkbox column — keep narrow */
.fp-table th.fp-th-check,
.fp-table td.fp-td-check {
  width: 40px;
  padding-left: 1.25rem;
  padding-right: 0.5rem;
}
.fp-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--fp-terra);
  cursor: pointer;
}

/* Select all checkbox state */
.fp-table thead th .fp-select-all {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — CARD STACKING ON MOBILE
   Below 640px, data-label each cell so it reads as a card.
   Requires data-label attributes on <td> elements.
   ════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .fp-table--responsive,
  table.fp-table--responsive {
    border: none;
    background: transparent;
    box-shadow: none;
  }
  .fp-table--responsive thead,
  table.fp-table--responsive thead {
    display: none;
  }
  .fp-table--responsive tbody tr,
  table.fp-table--responsive tbody tr {
    display: block;
    background: var(--fp-white);
    border: 1.5px solid var(--fp-border);
    border-radius: var(--fp-radius-lg);
    margin-bottom: 0.85rem;
    padding: 0.5rem 0;
    box-shadow: var(--fp-shadow-sm);
  }
  .fp-table--responsive tbody tr:hover,
  table.fp-table--responsive tbody tr:hover {
    border-color: var(--fp-border-strong);
  }
  .fp-table--responsive tbody td,
  table.fp-table--responsive tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--fp-border);
    font-size: 0.84rem;
  }
  .fp-table--responsive tbody td:last-child,
  table.fp-table--responsive tbody td:last-child {
    border-bottom: none;
  }
  .fp-table--responsive tbody td[data-label]::before,
  table.fp-table--responsive tbody td[data-label]::before {
    content: attr(data-label);
    font-family: 'Space Mono', monospace;
    font-size: 0.58rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--fp-light);
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 0.15rem;
  }
  .fp-table--responsive td.fp-td-actions,
  table.fp-table--responsive td.fp-td-actions {
    justify-content: flex-end;
  }

  /* Toolbar stacks on mobile */
  .fp-table-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .fp-table-toolbar-right { width: 100%; }
  .fp-table-search input  { width: 100%; }
  .fp-table-search        { width: 100%; }
}

/* ════════════════════════════════════════════════════════════
   PRINT
   ════════════════════════════════════════════════════════════ */
@media print {
  .fp-table-toolbar,
  .fp-table-footer,
  .fp-td-actions,
  .fp-td-action-btn { display: none !important; }

  .fp-table,
  table.fp-table {
    border: 1px solid #ccc;
    font-size: 11pt;
  }
  .fp-table thead th,
  table.fp-table thead th {
    background: #f5f5f5;
    border-bottom: 2px solid #ccc;
  }
  .fp-table tbody tr,
  table.fp-table tbody tr {
    border-bottom: 1px solid #ddd;
  }
  .fp-table tbody tr:nth-child(even),
  table.fp-table tbody tr:nth-child(even) {
    background: #fafafa;
  }
}
