/* ═══════════════════════════════════════════════════════════════════════════
   DNS Panopticon — Market Index page styles
   Follows the same design language as page-analyzer.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Page layout ─────────────────────────────────────────────────────────── */
/* body is flex column with min-height:100vh from base.css — no overrides needed */

/* <main> gets flex:1 from base.css; add column flex so grid-wrap can flex:1 */
.market-main {
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */

#market-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  min-height: 52px;
  position: sticky;
  top: var(--nav-height);
  z-index: 10;
}

#market-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--txt);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#market-title-icon {
  color: var(--primary);
  flex-shrink: 0;
}

#market-stats {
  font-size: 0.78rem;
  color: var(--txt-4);
  white-space: nowrap;
}

/* Links between published verticals (hidden until a second one is published). */
#market-verticals {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
#market-verticals[hidden] {
  display: none;
}
.market-vertical-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--txt-2);
  text-decoration: none;
  padding: 3px 10px;
  border: 1.5px solid var(--txt-4);
  border-radius: 999px;
  white-space: nowrap;
}
.market-vertical-link svg {
  flex-shrink: 0;
}
.market-vertical-link:hover {
  color: var(--txt);
  border-color: var(--txt-3);
}
.market-vertical-link--compare {
  border-style: dashed;
}
.market-vertical-link[aria-current="page"] {
  color: var(--primary);
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.market-cell-text {
  font-size: 0.8rem;
  color: var(--txt-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#market-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 160px;
  max-width: 300px;
}

#market-search {
  width: 100%;
  height: 30px;
  padding: 0 8px 0 28px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--txt);
  font-size: 0.8rem;
  outline: none;
  transition: border-color var(--t-fast);
}
#market-search:focus {
  border-color: var(--border-hi);
  background: var(--surface);
}

#market-search-wrap .search-icon {
  position: absolute;
  left: 8px;
  color: var(--txt-4);
  pointer-events: none;
}
#market-search-wrap {
  position: relative;
}

/* ── Results footer (matches Zone Analyzer's #statusbar) ─────────────────── */

/* Like Zone Analyzer with results, the status bar is the bottom of the page. */
.market-page #site-footer { display: none; }

#market-statusbar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  flex-shrink: 0;
  min-height: 32px;
}

.market-stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-right: 14px;
  color: var(--txt-3);
  white-space: nowrap;
}
.market-stat-item svg { color: var(--txt-4); flex-shrink: 0; }
.market-stat-item strong { color: var(--txt-2); font-weight: 600; }

/* Update time and disclaimer read as one note on the right, like Zone Analyzer's hint. */
#market-statusbar-note {
  margin-left: auto;
  min-width: 0;
  color: var(--txt-4);
  font-size: var(--text-compact);
  text-align: right;
}
#market-trading-day-badge { display: none; color: var(--txt-3); white-space: nowrap; }
#market-trading-day-badge.visible { display: inline; }
#market-trading-day-label::after { content: '.'; }
#market-trading-day-badge svg { color: var(--txt-4); vertical-align: -1px; margin-right: 4px; }

/* The vertical's support article, at the right end of the topbar. */
#market-guide-link {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--primary);
  white-space: nowrap;
}

/* ── Grid wrapper ────────────────────────────────────────────────────────── */

#market-grid-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}


/* Absolute fill so AG Grid always has a concrete pixel height regardless
   of when the browser resolves the parent's flex-grown dimensions. */
#myMarketGrid {
  position: absolute;
  inset: 0;
}

/* ── AG Grid theme overrides (match analyzer style) ─────────────────────── */

#myMarketGrid .ag-root-wrapper {
  border: none;
  border-radius: 0;
}

#myMarketGrid .ag-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#myMarketGrid .ag-header-cell {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--txt-3);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#myMarketGrid .ag-row {
  border-bottom: 1px solid var(--surface2);
  transition: background var(--t-fast);
}

#myMarketGrid .ag-row:hover {
  background: var(--surface2) !important;
}

#myMarketGrid .ag-row-even { background: var(--surface); }
#myMarketGrid .ag-row-odd  { background: var(--bg); }

/* AG Grid applies a focused-cell border when interactive content is clicked.
   For the Explore action column we rely on the button's own focus ring instead. */
#myMarketGrid .ag-cell-focus,
#myMarketGrid .ag-cell-focus:not(.ag-cell-range-selected):focus-within {
  border-color: transparent !important;
  box-shadow: none !important;
}

/* ── Cell renderers ──────────────────────────────────────────────────────── */

.market-cell-name {
  font-weight: 500;
  color: var(--txt);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.market-cell-name a,
.market-company-link {
  color: inherit;
  text-decoration: none;
}
.market-cell-name a:hover,
.market-company-link:hover {
  text-decoration: underline;
}

.market-cell-ticker {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  border-radius: 3px;
  padding: 1px 5px;
  letter-spacing: 0.05em;
}
.market-cell-ticker a {
  color: inherit;
  text-decoration: none;
}
.market-cell-ticker a:hover {
  text-decoration: underline;
}

.market-cell-company-mobile {
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.market-company-ticker-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.market-cell-domain a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.8rem;
}
.market-cell-domain a:hover {
  text-decoration: underline;
}

.market-cell-muted {
  color: var(--txt-4);
}

.market-cell-price {
  font-size: 0.82rem;
  color: var(--txt-2);
  text-align: right;
}
.market-cell-price.missing { color: var(--txt-4); }

.market-cell-score {
  display: flex;
  align-items: center;
  gap: 6px;
}

.market-score-numeric {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--txt-2);
}

.market-grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 18px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0 4px;
  letter-spacing: 0.02em;
}

.market-grade-badge.grade-aplus,
.market-grade-badge.grade-a {
  background: var(--badge-ok-bg);
  color: var(--badge-ok-fg);
}
.market-grade-badge.grade-b {
  background: color-mix(in srgb, #3b82f6 12%, transparent);
  color: #2563eb;
}
.market-grade-badge.grade-c {
  background: var(--badge-warn-bg);
  color: var(--badge-warn-fg);
}
.market-grade-badge.grade-d {
  background: color-mix(in srgb, #f97316 12%, transparent);
  color: #ea580c;
}
.market-grade-badge.grade-f {
  background: var(--badge-err-bg);
  color: var(--badge-err-fg);
}
.market-grade-badge.grade-none {
  background: var(--surface2);
  color: var(--txt-4);
}

/* Stale score indicator */
.market-stale-icon {
  display: inline-flex;
  align-items: center;
  color: var(--badge-warn-fg);
  cursor: help;
  flex-shrink: 0;
}

.market-cell-de-link {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  white-space: nowrap;
}

.market-cell-de-link .market-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-width: 72px;
  padding: 3px 8px;
  color: #fff;
  background: var(--primary-fill);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  border: 1px solid var(--primary);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
  transition: filter var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.market-cell-de-link .market-action-link span {
  transform: translateY(-0.5px);
}
.market-cell-de-link .market-action-link:hover,
.market-cell-de-link .market-action-link:focus-visible {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.26);
}
.market-cell-de-link .market-action-link:active {
  transform: translateY(0);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
}
.market-cell-de-link .market-action-link:focus-visible {
  outline: 2px solid var(--txt);
  outline-offset: 1px;
}

/* ── Loading / empty states ──────────────────────────────────────────────── */

#market-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 5;
  flex-direction: column;
  gap: 12px;
}
#market-loading.hidden { display: none; }

#market-loading .loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: market-spin 0.8s linear infinite;
}
#market-loading .loading-label {
  font-size: 0.85rem;
  color: var(--txt-4);
}

@keyframes market-spin {
  to { transform: rotate(360deg); }
}

#market-error {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 5;
  overflow: auto;
}
#market-error.visible { display: flex; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  #market-statusbar { padding: 6px 10px; flex-wrap: wrap; gap: 4px 0; }
  #market-statusbar-note { width: 100%; margin-left: 0; text-align: left; }
}

@media (max-width: 640px) {
  #market-topbar {
    padding: 8px 16px;
    gap: 8px;
  }

  #market-search-wrap {
    max-width: 100%;
    min-width: 0;
  }

  #market-search {
    height: 44px;
    padding: 0 12px 0 32px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
  }
}

/* Background loading never covers rows or changes the grid dimensions. */
#market-background-status {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 48px);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--txt-3);
  font-size: 0.78rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
  pointer-events: none;
}
#market-background-status[hidden],
#market-background-retry[hidden] { display: none; }
.market-background-spinner {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: market-spin 0.8s linear infinite;
}
#market-background-status.has-error .market-background-spinner { display: none; }
#market-background-retry {
  pointer-events: auto;
  color: var(--primary);
  background: transparent;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
  min-height: 32px;
}
@media (prefers-reduced-motion: reduce) {
  .market-background-spinner { animation: none; }
}
