/* =========================================================
   Sources — SPQR
   ========================================================= */

/* ---------- Page primitives ---------- */
.page-head { margin: .5rem 0 1rem; }
.page-title {
  font-family: var(--font-sans);
  font-size: var(--fs-h1);
  margin: 0;
}
.page-sub { margin: .25rem 0 0; color: var(--muted, #666); }

.card { background: #fff; border-radius: 1rem; box-shadow: var(--shadow, 0 1px 6px rgba(0,0,0,.06)); }
.pad { padding: 1rem; }

/* ---------- Strong outer frame + soft inner grid ---------- */
.table-scroll {
  border: 1.5px solid rgba(0,0,0,0.5);
  border-radius: .75rem;
  overflow: auto;
  background: #fff;
}

/* Core table */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

/* Inner grid lines */
.table th + th,
.table td + td { border-left: 1px solid rgba(0,0,0,0.06); }
.table td { border-bottom: 1px solid rgba(0,0,0,0.06); }

/* Sticky header row and shared header typography */
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
}

/* Header/body padding (compact) */
.table thead th,
.table td { padding: .5rem .6rem; }

/* Links in headers */
.table th a { color: inherit; text-decoration: none; }
.table th a:hover { text-decoration: underline; }

/* Count alignment */
.table td.numeric { text-align: right; }          /* only body cells */
.table thead th.numeric { text-align: center; }   /* header centered */

/* Abbreviation monospace */
.abbr { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: .9em; }

/* Titles and chips */
.title-wrap { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.chip.link { display: inline-block; padding: .2rem .5rem; border-radius: 999px; background: var(--chip-bg, #f3f3f3); text-decoration: none; }

/* Column min/max widths */
.th-desc   { min-width: 18ch; }
.th-title  { min-width: 18ch; }
.th-books  { min-width: 20ch; }
.cell-desc { max-width: 40ch; }

/* Allow header labels to wrap */
.sources-table thead th .th-title {
  white-space: normal;
  line-height: 1.2;
  word-break: normal;
  overflow-wrap: anywhere;
}

/* Make table layout predictable and compact */
.sources-table { table-layout: fixed; width: 100%; font-size: .92rem; line-height: 1.25; }

/* Narrower Count column — centered */
.sources-table thead th.th-count,
.sources-table td.cell-count {
  width: 7ch; min-width: 6ch; max-width: 9ch;
  padding-left: .25rem; padding-right: .25rem;
  text-align: center;
}


@media (max-width: 768px) {
  .wrap .desktop-only { display: none; }
  .wrap .mobile-only  { display: block; }
  /* Mobile: show only 3 columns (author, title, and .as-third) */
  .sources-table.is-mobile th,
  .sources-table.is-mobile td { display: none; }
  .sources-table.is-mobile th[data-key="author"],
  .sources-table.is-mobile th[data-key="title"],
  .sources-table.is-mobile th.as-third,
  .sources-table.is-mobile td[data-key="author"],
  .sources-table.is-mobile td[data-key="title"],
  .sources-table.is-mobile td.as-third { display: table-cell; }

  .sources-table.is-mobile thead th,
  .sources-table.is-mobile td { padding: .45rem .5rem; white-space: normal; overflow-wrap: anywhere; }
}

/* Desktop: show 5 immutable + 1 selected "extra" */
@media (min-width: 769px) {
  .wrap .desktop-only { display: block; }
  .wrap .mobile-only  { display: none; }
  .sources-table.six-mode th,
  .sources-table.six-mode td { display: none; }

  /* immutable */
  .sources-table.six-mode th[data-key="author"],
  .sources-table.six-mode th[data-key="title"],
  .sources-table.six-mode th[data-key="abbreviation"],
  .sources-table.six-mode th[data-key="description"],
  .sources-table.six-mode th[data-key="count"],

  /* chosen extra */
  .sources-table.six-mode th.as-extra,

  .sources-table.six-mode td[data-key="author"],
  .sources-table.six-mode td[data-key="title"],
  .sources-table.six-mode td[data-key="abbreviation"],
  .sources-table.six-mode td[data-key="description"],
  .sources-table.six-mode td[data-key="count"],
  .sources-table.six-mode td.as-extra { display: table-cell; }
}

/* ---------- Toggle chips (shared for desktop & mobile) ---------- */
.columns-toggle { display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; }
.columns-toggle .chip.toggle {
  background: var(--chip-bg,#f3f3f3);
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 999px;
  padding: .28rem .7rem;
  cursor: pointer;
  user-select: none;
}
.columns-toggle .chip.toggle input { display:none; }
.columns-toggle .chip.toggle.on {
  background: #e6f5ea;                 /* pale green */
  border-color: #6bc38d;               /* greenish border */
  box-shadow: inset 0 0 0 1px #b8e5c9; /* subtle inner line */
  font-weight: 600;
}

/* ---------- Immutable vs Active header styling ---------- */

/* Thick dark-grey underline for ALL header cells by default */
.sources-table thead th { border-bottom: 3px solid #495561; }

/* Immutable header look: grey bg + muted text (still with 3px underline) */
.sources-table thead th[data-key="author"],
.sources-table thead th[data-key="title"],
.sources-table thead th[data-key="abbreviation"],
.sources-table thead th[data-key="description"],
.sources-table thead th[data-key="count"] {
  background: #f6f7f8;
  color: #60666d;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.06);
}

/* Active extra column header (desktop .as-extra, mobile .as-third) */
.sources-table thead th.as-extra,
.sources-table thead th.as-third {
  background: #e6f5ea;
  border-bottom-color: #6bc38d; /* keep 3px thickness, switch to green */
  color: #204d2e;
}

/* ---------- Top scrollbar stub (if you keep it) ---------- */
.table-top-scroll { overflow: auto; border-radius: .75rem; margin-bottom: .5rem; background: #fff; }
.table-top-scroll .top-scroll-inner { height: 12px; }
.table-top-scroll .scroll-spacer { height: 1px; }

/* =========================================================
   Floating header — aligned & styled like main header
   ========================================================= */

/* Offset from topbar; tweak as needed */
:root { --floatHeaderTop: 56px; }
@media (max-width: 768px) {
  :root { --floatHeaderTop: 5px; }  /* snug on mobile */
}

/* Floating header host */
.sources-float-header {
  position: fixed;
  top: var(--floatHeaderTop);
  z-index: 100;
  display: none;
  background: #fff;
  border: 1.5px solid rgba(0,0,0,0.5);
  border-bottom: none;                        /* avoid double line with table */
  border-radius: .75rem .75rem 0 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.08);
  overflow: hidden;                           /* keep rounded corners clean */
}

/* Ensure left edge is always visible even when inner track slides */
.sources-float-header::before {
  content: "";
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 1.5px; background: rgba(0,0,0,0.5); pointer-events: none;
  border-top-left-radius: .75rem;
}

/* Inner track that moves with horizontal scroll (JS sets width & transform) */
.sources-float-header .sfh-inner { position: relative; will-change: transform, width; }

/* Mini table inside the floating header */
.sources-float-header .table { width: auto; border-collapse: collapse; table-layout: fixed; }
.sources-float-header th {
  padding: .45rem .55rem;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  border-right: 1px solid rgba(0,0,0,0.06);  /* faint vertical separators to match grid */
}
.sources-float-header th:last-child { border-right: none; }
@media (max-width: 768px) { .sources-float-header th { padding: .4rem .45rem; } }

/* Immutable headers (floating) — grey bg + muted text */
.sources-float-header thead th[data-key="author"],
.sources-float-header thead th[data-key="title"],
.sources-float-header thead th[data-key="abbreviation"],
.sources-float-header thead th[data-key="description"],
.sources-float-header thead th[data-key="count"] {
  background: #f6f7f8 !important;
  color: #60666d !important;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.06);
  border-bottom: 3px solid #495561;          /* same thick underline as main */
}

/* Active extra column (floating) — green bg + green 3px underline */
.sources-float-header thead th.as-extra,
.sources-float-header thead th.as-third {
  background: #e6f5ea !important;
  border-bottom: 3px solid #6bc38d;
  color: #204d2e !important;
}



/* === Fix: keep header titles within their cell (no spill/oversize) === */

/* Make the header inner wrapper a shrinkable, full-width container */
.sources-table thead th .th-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;              /* <-- critical so children can shrink */
  box-sizing: border-box;
}

/* Title must never exceed the inner wrapper */
.sources-table thead th .th-title {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  text-align: center;
  white-space: nowrap;       /* default desktop: keep on one line */
  overflow: hidden;
  text-overflow: ellipsis;   /* … if too narrow */
  margin: 0;
}

/* If the title contains a link, cap that too */
.sources-table thead th .th-title a {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

/* Mobile: allow wrapping instead of ellipsis for long labels */
@media (max-width: 768px) {
  .sources-table thead th .th-title {
    white-space: normal;     /* wrap onto 2 lines if needed */
    line-height: 1.2;
    text-overflow: clip;
  }
}

/* Count header: ensure it centers and never overflows its narrow column */
.sources-table thead th.th-count .th-title {
  text-align: center !important;
  white-space: nowrap;       /* keep "Count" on one line */
  overflow: hidden;
  text-overflow: ellipsis;
}


/* === Row hover highlight (desktop only) === */
@media (min-width: 769px) {
  .sources-table tbody tr:hover {
    background: #fff9e6;           /* pale yellow-orange */
    transition: background 0.15s ease-in-out;
  }
}

/* Focus highlight when arriving from a link (#slug) */
.sources-table tbody tr.focus-row {
  outline: 2px solid #d49624;
  background: #fff9e6;                /* yellow tint */
  transition: background .4s ease, outline-color .4s ease;
}
