/* ============================================================
   JobAi — Job listings table
   Targets the REAL Drupal Views markup as-emitted:
     <div class="table-responsive">
       <table class="cols-N table table-bordered"> … </table>
     </div>
   Column-count agnostic: matches cols-6, cols-8, or any cols-N via
   the [class*="cols-"] attribute selector, so adding/removing view
   columns never breaks the styling.
   No markup changes needed — just load this file (and table.js for the
   working-mode pills + empty-cell dashes + mobile field labels).
   Reuses styles.css tokens, with standalone fallbacks.
   ============================================================ */

:root {
  --tbl-bg: var(--surface, #fff);
  --tbl-ink: var(--ink, oklch(0.205 0.021 285));
  --tbl-soft: var(--ink-soft, oklch(0.38 0.018 285));
  --tbl-muted: var(--muted, oklch(0.53 0.016 285));
  --tbl-line: var(--line, oklch(0.905 0.009 285));
  --tbl-line-soft: var(--line-soft, oklch(0.94 0.007 285));
  --tbl-violet: var(--violet, oklch(0.515 0.205 285));
  --tbl-violet-700: var(--violet-700, oklch(0.445 0.198 285));
  --tbl-violet-50: var(--violet-50, oklch(0.968 0.022 285));
  --tbl-violet-100: var(--violet-100, oklch(0.93 0.045 285));
  --tbl-zebra: oklch(0.984 0.005 290);
  --tbl-radius: 16px;
  --tbl-serif: "Newsreader", Georgia, serif;
  --tbl-sans: "Schibsted Grotesk", system-ui, sans-serif;
}

/* ---------- The wrapper Drupal already emits ---------- */
.table-responsive:has(> table[class*="cols-"]) {
  border: 1px solid var(--tbl-line);
  border-radius: var(--tbl-radius);
  background: var(--tbl-bg);
  box-shadow:
    0 1px 2px oklch(0.3 0.05 285 / 0.05),
    0 14px 40px oklch(0.3 0.05 285 / 0.06);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Reset Bootstrap's bordered table & restyle ---------- */
table[class*="cols-"].table-bordered {
  --bs-table-bg: transparent;
  width: 100%;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  border: 0;
  font-family: var(--tbl-sans);
  color: var(--tbl-soft);
  font-size: 0.95rem;
  background: var(--tbl-bg);
}

/* Kill Bootstrap's per-cell borders; we use clean horizontal hairlines only */
table[class*="cols-"].table-bordered > :not(caption) > *,
table[class*="cols-"].table-bordered > :not(caption) > * > * {
  border: 0;
}

/* ---------- Header ---------- */
table[class*="cols-"] thead th {
  font-family: var(--tbl-sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tbl-muted);
  background: var(--tbl-tint, oklch(0.972 0.009 290));
  padding: 1.05rem 1.25rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--tbl-line) !important;
}
table[class*="cols-"] thead th:first-child {
  padding-left: 1.6rem;
}
table[class*="cols-"] thead th:last-child {
  padding-right: 1.6rem;
}

/* ---------- Sortable headers ---------- */
table[class*="cols-"] thead th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 2rem;
  transition:
    color 0.14s ease,
    background 0.14s ease;
}
table[class*="cols-"] thead th.sortable:hover {
  color: var(--tbl-violet-700);
}
table[class*="cols-"] thead th.sortable:focus-visible {
  outline: 2px solid var(--tbl-violet);
  outline-offset: -2px;
}
/* caret — dim double-chevron by default, solid violet single chevron when active.
   Drawn as inline SVG (no icon font needed). */
table[class*="cols-"] thead th.sortable::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  width: 12px;
  height: 12px;
  transform: translateY(-50%);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23c4c4d0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5l4-4 4 4M4 9.5l4 4 4-4'/%3E%3C/svg%3E");
  transition: opacity 0.14s ease;
}
table[class*="cols-"] thead th.sortable:hover::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%236E40E0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5l4-4 4 4M4 9.5l4 4 4-4'/%3E%3C/svg%3E");
}
table[class*="cols-"] thead th.sort-asc::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%236E40E0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 10l4-4 4 4'/%3E%3C/svg%3E");
}
table[class*="cols-"] thead th.sort-desc::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%236E40E0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}
table[class*="cols-"] thead th.is-sorted {
  color: var(--tbl-violet-700);
}
table[class*="cols-"] thead th:last-child.sortable {
  padding-right: 2.2rem;
}
table[class*="cols-"] thead th:last-child.sortable::after {
  right: 1.4rem;
}

/* ---------- Body cells ---------- */
table[class*="cols-"] tbody td {
  padding: 1.15rem 1.25rem;
  vertical-align: middle;
  border-top: 1px solid var(--tbl-line-soft) !important;
  color: var(--tbl-soft);
  line-height: 1.45;
}
table[class*="cols-"] tbody tr:first-child td {
  border-top: 0 !important;
}
table[class*="cols-"] tbody td:first-child {
  padding-left: 1.6rem;
}
table[class*="cols-"] tbody td:last-child {
  padding-right: 1.6rem;
}

/* Zebra + hover */
table[class*="cols-"] tbody tr {
  transition: background 0.16s ease;
}
table[class*="cols-"] tbody tr:nth-child(even) {
  background: var(--tbl-zebra);
}
table[class*="cols-"] tbody tr:hover,
table[class*="cols-"] tbody tr:nth-child(even):hover {
  background: var(--tbl-violet-50);
}

/* ---------- Title column (the job link) ---------- */
table[class*="cols-"] .views-field-title {
  min-width: 230px;
}
table[class*="cols-"] .views-field-title a {
  font-family: var(--tbl-serif);
  font-size: 1.18rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--tbl-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition:
    color 0.16s ease,
    gap 0.16s ease;
}
table[class*="cols-"] .views-field-title a::after {
  content: "\2192"; /* → */
  font-family: var(--tbl-sans);
  font-size: 0.95rem;
  color: var(--tbl-violet);
  opacity: 0;
  transform: translateX(-4px);
  transition:
    opacity 0.16s ease,
    transform 0.16s ease;
}
table[class*="cols-"] .views-field-title a:hover {
  color: var(--tbl-violet-700);
}
table[class*="cols-"] .views-field-title a:hover::after {
  opacity: 1;
  transform: none;
}

/* ---------- City & Country ---------- */
table[class*="cols-"] .views-field-field-city {
  font-weight: 600;
  color: var(--tbl-ink);
  white-space: nowrap;
}
table[class*="cols-"] .views-field-field-city:not(.is-empty)::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 0.45rem;
  vertical-align: -1px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 11px 11px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%236E40E0'%3E%3Cpath d='M8 0a5 5 0 0 0-5 5c0 3.6 4.4 10.2 4.6 10.5a.5.5 0 0 0 .8 0C8.6 15.2 13 8.6 13 5a5 5 0 0 0-5-5zm0 7a2 2 0 1 1 0-4 2 2 0 0 1 0 4z'/%3E%3C/svg%3E");
}
table[class*="cols-"] .views-field-field-country {
  color: var(--tbl-muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ---------- Duration & Extent ---------- */
table[class*="cols-"] .views-field-field-duration,
table[class*="cols-"] .views-field-field-extent {
  color: var(--tbl-muted);
  font-size: 0.9rem;
  max-width: 250px;
}

/* ---------- Applied column (application link) → pill ---------- */
table[class*="cols-"] .views-field-title-1 a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--tbl-violet-50);
  color: var(--tbl-violet-700);
  border: 1px solid var(--tbl-violet-100);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table[class*="cols-"] .views-field-title-1 a::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tbl-violet);
}
table[class*="cols-"] .views-field-title-1 a:hover {
  background: var(--tbl-violet-100);
}

/* ---------- Applied on (date) ---------- */
table[class*="cols-"] .views-field-created,
table[class*="cols-"] .views-field-created time {
  color: var(--tbl-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ---------- Working mode → pill badge (added by table.js) ---------- */
table[class*="cols-"] .views-field-field-working-mode {
  white-space: nowrap;
}
table[class*="cols-"] .mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--tbl-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--tbl-violet-700);
  background: var(--tbl-violet-50);
  border: 1px solid var(--tbl-violet-100);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  white-space: nowrap;
}
table[class*="cols-"] .mode-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tbl-violet);
}

/* ---------- Empty cells → tasteful em-dash ----------
   Real Drupal cells contain whitespace (so :empty won't match);
   table.js adds .is-empty. This rule also covers the rare truly-empty cell. */
table[class*="cols-"] tbody td.is-empty,
table[class*="cols-"] tbody td:empty {
  color: var(--tbl-line);
}
table[class*="cols-"] tbody td.is-empty::before {
  content: "\2014"; /* — */
  color: var(--tbl-line);
}

/* ---------- Optional heading row above the table ---------- */
.jobs-table-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.3rem;
}
.jobs-table-head h2 {
  font-family: var(--tbl-serif);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--tbl-ink);
  margin: 0;
}
.jobs-table-head .count {
  font-family: var(--tbl-sans);
  font-size: 0.88rem;
  color: var(--tbl-muted);
}
.jobs-table-head .count strong {
  color: var(--tbl-violet-700);
  font-weight: 700;
}

/* ---------- Responsive: stacked cards under 720px ---------- */
@media (max-width: 720px) {
  .table-responsive:has(> table[class*="cols-"]) {
    border: 0;
    box-shadow: none;
    background: transparent;
    overflow: visible;
  }
  table[class*="cols-"] thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  table[class*="cols-"],
  table[class*="cols-"] tbody,
  table[class*="cols-"] tr,
  table[class*="cols-"] td {
    display: block;
    width: 100%;
  }
  table[class*="cols-"] tbody tr {
    background: var(--tbl-bg) !important;
    border: 1px solid var(--tbl-line);
    border-radius: 14px;
    padding: 0.4rem 0.2rem 0.9rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 2px oklch(0.3 0.05 285 / 0.05);
  }
  table[class*="cols-"] tbody td {
    border: 0 !important;
    padding: 0.3rem 1.2rem !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }
  table[class*="cols-"] tbody td.views-field-title {
    padding-top: 0.9rem !important;
    margin-bottom: 0.3rem;
  }
  table[class*="cols-"] tbody td.views-field-title a {
    font-size: 1.22rem;
  }
  /* field label from the column header (table.js sets data-label) */
  table[class*="cols-"] tbody td:not(.views-field-title)::before {
    content: attr(data-label);
    font-family: var(--tbl-sans);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--tbl-muted);
    flex: none;
  }
  table[class*="cols-"] tbody td.is-empty {
    display: none;
  } /* hide empty rows in card view */
}
