/* Companies list page — /companies
 *
 * The bulk of the design tokens (filter-bar pills, sort-arrow SVG, table
 * typography, marketcap cell, pagination) live in /investor-deck/css/style.css
 * which this page loads directly. The search input uses .news-search-wrapper
 * from /css/news.css so it matches the newsroom's rounded pill treatment.
 *
 * Rules here cover:
 *   - Page chrome (breadcrumb)
 *   - Two-row filter bar layout
 *   - Marketcap pill row (mirrors the Market pill pattern)
 *   - Sticky-zone scroll compression rules (mirrors investor-deck's)
 *   - Drawer overrides
 *
 * Anything you'd change on both /investor-deck and /companies belongs in
 * investor-deck/css/style.css, not here.
 */

/* Hide the shared "All market data is delayed..." fixed footer added
 * globally by nav.js (_addFooter). It obscures the pagination + last row
 * of the table on this discovery surface, and the disclaimer isn't
 * relevant here (marketcap values are ours; there's no live market data
 * on the page). Matches how /news + /investor-deck leave it in the layout
 * because those pages have dedicated bottom padding; on /companies the
 * table's borderless footer runs to the viewport bottom so we hide it. */
#_footer { display: none !important; }

/* Page background — same #f7f7f7 as /investor-deck. Without this the body's
 * default white makes the white .drill-intercepts-card blend in and its
 * rounded corners aren't visible.
 *
 * padding-top: 65px offsets the fixed site nav. The shared .pt utility
 * normally provides this but we're not using it (it stacked with the inner
 * wrapper padding on other surfaces); applying the offset directly on
 * #page-wrapper keeps the sticky filter zone from being covered by the nav. */
#page-wrapper {
  background-color: #f7f7f7;
  min-height: 100vh;
  padding-top: 65px;
}

/* Content width — wider than /investor-deck's 1200px because we host a
 * 320px right rail alongside the table. Target: ~1100px for the table
 * area (matches investor-deck's standalone table width) + 20px grid gap
 * + 320px rail + 48px page padding ≈ 1488px. Rounded to 1480px.
 *
 * If the rail ever gets removed or changed size, revisit — the goal is
 * for the table itself to feel the same width as /investor-deck. */
.companies-inner-wrapper {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px 24px 60px;
  color: #111827;
}

/* Breadcrumb */
.cp-breadcrumbs {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 10px;
}
.cp-breadcrumbs a {
  color: #6b7280;
  text-decoration: none;
}
.cp-breadcrumbs a:hover { color: var(--mh-teal, #0e7490); text-decoration: underline; }
.cp-breadcrumbs__sep { margin: 0 6px; color: #cbd5e1; }
.cp-breadcrumbs [aria-current="page"] { color: #111827; font-weight: 500; }

/* --------------------------------------------------------------------------
 * Filter bar
 *
 * Two rows:
 *   Row 1 (companies-primary-row): Market pills + Marketcap size chips + Actions
 *   Row 2 (companies-search-row):  Search input (news-search-wrapper style)
 *
 * .drilling-market-wrapper / .market-option / .reset-news-filter-btn /
 * .news-filter-btn / .filter-count-badge styles come from
 * investor-deck/css/style.css.
 * ------------------------------------------------------------------------ */

.filters-section .companies-primary-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

/* Override investor-deck's .filter-wrapper .label { width: 100px } — that
 * fixed width leaves a big empty gap between the Market/Marketcap label and
 * its pill row. We want the label to hug its text, with a small padding
 * separating it from the following controls. .drilling-market-wrapper
 * already gives 10px flex-gap; a slight padding-right on top reads clean. */
.filters-section .companies-primary-row .label {
  width: auto;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0;
  padding-right: 2px;
  white-space: nowrap;
}

/* Actions pushed right */
.filters-section .companies-primary-row .drilling-actions-wrapper {
  margin-left: auto;
}

/* Row 2 — search input row. Match /news treatment (rounded pill, ~320px
 * wide with a leading magnifier icon). news.css hides `.fa-search` globally
 * with !important, so the icon is an inline <svg> in the HTML positioned
 * absolutely inside the wrapper. */
.filters-section .companies-search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.filters-section .companies-search-row .news-search-wrapper {
  position: relative;
  width: 320px;
  max-width: 100%;
  flex: 0 0 auto;
}
.filters-section .companies-search-row .news-search-wrapper input {
  width: 100%;
  min-width: 0;
  padding-left: 36px;
}
.filters-section .companies-search-row .cp-search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 2;
  width: 16px;
  height: 16px;
}
.filters-section .companies-search-row .cp-search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: #6b7280;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 999px;
  z-index: 3;
}
.filters-section .companies-search-row .cp-search-clear:hover {
  background: #f3f4f6;
  color: #111827;
}

/* Marketcap pill row
 *
 * Mirrors the Market pill treatment (grey rounded rail with teal-filled
 * selected option) so the two adjacent filter groups read as one visual
 * language. #cp-marketcap-buttons-wrapper picks up the same styles that
 * investor-deck's style.css applies to #market-buttons-wrapper. The "All"
 * option is the default and always visible (clicking it clears the size
 * scope entirely). */
#cp-marketcap-buttons-wrapper {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
  background-color: #f1f5f9;
  border-radius: 1000px;
  padding: 6px;
}
#cp-marketcap-buttons-wrapper .market-option {
  border: 1px solid transparent;
  color: #1f2937;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  background: #f1f5f9;
  transition: all .15s ease;
  white-space: nowrap;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#cp-marketcap-buttons-wrapper .market-option.selected {
  background: #30a5bf;
  border-color: rgba(0, 0, 0, .04);
  color: #fff;
  box-shadow: 0 6px 18px rgba(48, 165, 191, .35);
}
#cp-marketcap-buttons-wrapper .market-option:hover:not(.selected) {
  background: #e2e8f0;
}
#cp-marketcap-buttons-wrapper .market-option__hint {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.75;
  margin-left: 2px;
}

/* Active filter chip strip */
.companies-active-filters {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 0 4px;
}
.companies-active-filters__label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.companies-active-filters__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.companies-active-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 10px;
  font-size: 12px;
  background: rgba(14,116,144,0.10);
  color: var(--mh-teal, #0e7490);
  border-radius: 12px;
  font-weight: 500;
}
.companies-active-tag button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}
.companies-active-tag button:hover { opacity: 1; }

/* --------------------------------------------------------------------------
 * Sticky-zone scroll compression
 *
 * sticky-filters.js publishes --mh-sticky-zone-h and toggles .is-scrolled
 * on the zone. The base .drill-intercepts-table thead sticky rule in
 * investor-deck/css/style.css uses that variable to pin the table header
 * directly below the compressed filter zone — the same effect as /investor-deck.
 *
 * .is-scrolled compresses the filter bar (tightens padding, hides Active
 * Filters strip) so the pinned strip stays compact. Rows below aren't hidden
 * (they're all still useful in the compressed state).
 * ------------------------------------------------------------------------ */

/* Base zone padding — matches the /investor-deck / /news feel. */
#companies-sticky-zone .filters-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  transition: padding 0.18s ease;
}

/* Full-viewport-width background trick — same technique investor-deck uses
 * so the sticky zone's grey background covers the full viewport width, not
 * just the 1400px inner wrapper. Without this the page's own background
 * (#f7f7f7 body) shows a horizontal seam at the wrapper edges when the
 * user scrolls past the zone. */
#companies-sticky-zone {
  isolation: isolate;
  padding-bottom: 8px;
}
#companies-sticky-zone::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 50vw);
  right: calc(50% - 50vw);
  background-color: #f7f7f7;
  z-index: -1;
  pointer-events: none;
}

/* Compressed state — tightens padding and drops the search row / active
 * filters strip so the pinned zone stays as short as possible. */
.mh-sticky-zone.is-scrolled #companies-sticky-zone,
#companies-sticky-zone.is-scrolled {
  padding-bottom: 0;
}
#companies-sticky-zone.is-scrolled .filters-section {
  padding: 8px 12px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
}
/* Hide the search row while scrolled — the primary filters + Actions are
 * enough while the user is skimming; they can scroll back up to search. */
#companies-sticky-zone.is-scrolled .companies-search-row {
  display: none;
}
/* Hide the active-filters strip while pinned — it's redundant with the
 * per-filter selected state in the primary row. */
#companies-sticky-zone.is-scrolled .companies-active-filters {
  display: none !important;
}
/* Tighten row 1 padding in the compressed state. */
#companies-sticky-zone.is-scrolled .companies-primary-row {
  gap: 8px 12px;
}

/* --------------------------------------------------------------------------
 * Table + card
 *
 * .drill-intercepts-card + .drill-intercepts-table + .drill-page-btn
 * styles come from investor-deck/css/style.css. The sticky thead there
 * already positions itself against --mh-sticky-zone-h — since sticky-filters.js
 * publishes that variable for us, the sticky column headers just work.
 * ------------------------------------------------------------------------ */

/* --------------------------------------------------------------------------
 * Body grid — table on the left, Featured Client rail on the right.
 *
 * At ≥1100px the rail sits alongside the table and pins to the viewport
 * (top offset accounts for the fixed nav + the sticky filter zone). Below
 * 1100px the rail moves above the table and drops sticky positioning so
 * mobile users still see the featured client but without competing with
 * their thumb-scroll of the table.
 * ------------------------------------------------------------------------ */
.companies-body-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 8px;
}
.companies-body-rail {
  min-width: 0;
}
.companies-body-main {
  min-width: 0;
}
@media (min-width: 1100px) {
  .companies-body-grid {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
  }
  .companies-body-rail {
    position: sticky;
    /* 65px nav offset + measured sticky filter zone height + 8px cushion.
     * --mh-sticky-zone-h is published by sticky-filters.js. */
    top: calc(65px + var(--mh-sticky-zone-h, 220px) + 8px);
    align-self: start;
    max-height: calc(100vh - 65px - var(--mh-sticky-zone-h, 220px) - 24px);
    overflow-y: auto;
    scrollbar-width: thin;
  }
}

.companies-tables-wrapper {
  /* overflow: visible so the sticky <thead> inside .drill-intercepts-card
   * can escape this wrapper's clipping (any ancestor with overflow != visible
   * establishes a scroll container that breaks position: sticky). Mirrors
   * investor-deck's #tables-wrapper. */
  overflow: visible;
}
.companies-tables-wrapper .drill-intercepts-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  /* MUST be visible (not hidden) so the sticky table <thead> can pin below
   * the sticky filter zone. See investor-deck/css/style.css comment on
   * #tables-wrapper .drill-intercepts-card. */
  overflow: visible;
}
/* Header inside the card — mirrors investor-deck's title + subtitle. */
.companies-tables-wrapper .drill-intercepts-header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid #f3f4f6;
}
.companies-tables-wrapper .drill-intercepts-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.01em;
}
.companies-tables-wrapper .drill-intercepts-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: #6b7280;
}

/* Countries cell — comma-separated list, wraps to 2 lines if needed. */
.cell-countries {
  color: #111827;
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.cell-countries--empty {
  color: #9ca3af;
  font-size: 12px;
  font-style: italic;
}

/* Commodity mini-chips */
.cell-commodities {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.cell-commodities .commodity-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  font-size: 12px;
  font-weight: 500;
  background: #f3f4f6;
  color: #111827;
  border-radius: 10px;
  white-space: nowrap;
}
.cell-commodities .commodity-chip .commodity-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.cell-commodities__empty { color: #9ca3af; font-size: 12px; font-style: italic; }

/* Numeric count cells */
.cell-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #111827;
}
.cell-count--zero { color: #9ca3af; font-weight: 400; }

/* Exchange tag */
.cell-exchange-tag {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  background: #f3f4f6;
  color: #6b7280;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

/* Company name + ticker stacked */
.cell-company-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Row pointer cursor */
.drill-intercepts-table tbody tr.companies-row {
  cursor: pointer;
}

/* No results */
.companies-no-results {
  padding: 60px 20px;
  text-align: center;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  margin-top: 12px;
}
.companies-no-results__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  background: #f3f4f6;
  border-radius: 50%;
  color: #9ca3af;
  margin-bottom: 16px;
}
.companies-no-results__title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 6px;
}
.companies-no-results__hint {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
}

/* --------------------------------------------------------------------------
 * Drawer
 * ------------------------------------------------------------------------ */
.cp-drawer::part(panel) { --size: 420px; }
.cp-drawer-section {
  margin-bottom: 20px;
}
.cp-drawer-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.cp-drawer-row--range {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cp-drawer-row--range sl-input { flex: 1 1 0; min-width: 0; }
.cp-range-sep { color: #9ca3af; }
.cp-drawer-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: #9ca3af;
}
.cp-drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Visitor blur */
.drill-intercepts-table tbody tr.visitor-blur {
  filter: blur(4px);
  user-select: none;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
 * Responsive
 * ------------------------------------------------------------------------ */

@media (max-width: 1024px) {
  .companies-inner-wrapper { padding: 12px 16px 40px; }
  .filters-section .companies-primary-row .drilling-actions-wrapper {
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  #cp-marketcap-buttons-wrapper { flex-wrap: wrap; }
  .filters-section .companies-search-row .news-search-wrapper {
    width: 100%;
    max-width: none;
  }
  .companies-tables-wrapper { overflow-x: auto; }
}

/* ─────────────────────────────────────────────────────────────────────
 * Skeleton loader — table-scoped shimmer.
 *
 * Replaces the shared `.loader-wrapper` full-viewport overlay pattern
 * (which dimmed the featured-company rail and empty space to the right).
 * Skeleton rows sit inside the real table structure so column widths,
 * row height, and header layout all match the loaded state — the swap
 * to real data is a low-motion tweak rather than a reflow.
 * ───────────────────────────────────────────────────────────────────── */
.companies-row--skeleton {
  pointer-events: none;
}
.companies-row--skeleton td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
}
.companies-row--skeleton .sk-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}
.companies-row--skeleton td[style*="right"] .sk-cell {
  align-items: flex-end;
}
.companies-row--skeleton .sk-bar {
  display: inline-block;
  height: 11px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    rgba(226, 232, 240, 0.55) 0%,
    rgba(226, 232, 240, 0.95) 45%,
    rgba(226, 232, 240, 0.55) 100%);
  background-size: 200% 100%;
  animation: sk-shimmer-cp 1.4s ease-in-out infinite;
}
.companies-row--skeleton .sk-bar:first-child { height: 13px; }
@keyframes sk-shimmer-cp {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .companies-row--skeleton .sk-bar { animation: none; }
}
