/* ═══════════════════════════════════════════════════════════════════════════
   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;
}

.market-topbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

#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;
}

.market-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

#market-trading-day-badge {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--badge-warn-bg);
  color: var(--badge-warn-fg);
  font-size: 0.74rem;
  font-weight: 500;
  white-space: nowrap;
}
#market-trading-day-badge.visible { display: flex; }

#market-disclaimer {
  font-size: 0.74rem;
  color: var(--txt-4);
  padding: 0 4px;
  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: var(--bg);
  background: var(--primary);
  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;
  flex-direction: column;
  gap: 10px;
  color: var(--txt-3);
  font-size: 0.85rem;
}
#market-error.visible { display: flex; }

#market-retry-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 22px;
  border-radius: 7px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

#market-retry-btn:hover {
  background: var(--primary-dk);
  border-color: var(--primary-dk);
}

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

@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;
  }

  #market-disclaimer {
    display: none;
  }
}
