/**
 * FINTERM — Markets Module (shared table primitives)
 * ---------------------------------------------------------------
 * Inherits all theme tokens from theme.css. Renders instruments as
 * a dense, grouped table with a scrolling ticker strip — a
 * blotter read, not a card dashboard. Shared by both Markets
 * modules — Watchlist (watchlist.js/watchlist-ui.js) and Explorer
 * (explorer.js/explorer-ui.js) — since both use this same table/
 * ticker/star visual language. Explorer-only concerns (search,
 * filter tabs, detail panel) live in css/explorer.css instead of
 * duplicating these rules. Purely presentational; isolated from
 * the Data Engine.
 * ---------------------------------------------------------------
 */

.markets-screen,
.explorer-screen {
  margin-top: 1.5rem;
  /* Breaks out past the 960px shell so the table can actually be
     dense on wide screens, without touching --shell-max (which the
     login/OneDrive/user-card layouts still rely on). */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  padding: 0 20px;
}

.markets-panel {
  max-width: 1320px;
  margin: 0 auto;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px 8px;
  transition: border-color 120ms ease;
}

/* Explicit visual focus indicator (see panelFocus.js) — whichever
   panel currently owns arrow-key navigation gets a lit border, so
   it's never ambiguous which list ↑/↓ will move. */
.markets-screen.is-focused .markets-panel,
.explorer-screen.is-focused .markets-panel {
  border-color: var(--phosphor-dim);
}

/* ===============================================================
   Head
   =============================================================== */

.markets-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.markets-panel__title {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.markets-panel__eyebrow {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--phosphor-dim);
  margin: 0;
  text-transform: uppercase;
}

.markets-panel__count {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.markets-panel__controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.markets-panel__hint {
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 4px;
}

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-1);
  background: var(--bg-2);
  border: 1px solid var(--line-bright);
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 4px;
  line-height: 1.6;
}

.markets-panel__hint kbd { margin-left: 0; }

.btn--secondary.is-busy {
  opacity: 0.55;
  cursor: default;
}

/* ===============================================================
   Ticker strip — the one signature flourish for this panel
   =============================================================== */

.markets-ticker {
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  margin-bottom: 12px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}

.markets-ticker__track {
  display: inline-flex;
  white-space: nowrap;
  animation: markets-ticker-scroll 38s linear infinite;
  will-change: transform;
}

@keyframes markets-ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.markets-ticker__item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 22px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--line);
}

.markets-ticker__sym {
  color: var(--ink-0);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.markets-ticker__price {
  color: var(--ink-1);
}

.markets-ticker__item.is-up .markets-ticker__pct { color: var(--phosphor); }
.markets-ticker__item.is-down .markets-ticker__pct { color: var(--red); }
.markets-ticker__item.is-flat .markets-ticker__pct { color: var(--ink-2); }

/* ===============================================================
   Status line
   =============================================================== */

.markets-status {
  font-size: 12px;
  color: var(--ink-1);
  margin: 0 0 12px;
}

.markets-status.is-error {
  color: var(--red);
}

.markets-status.hidden {
  display: none;
}

/* ===============================================================
   Instrument table
   =============================================================== */

.markets-table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

.markets-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.markets-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-1);
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-bright);
  white-space: nowrap;
}

.markets-table .col-price,
.markets-table .col-chg,
.markets-table .col-chgpct,
.markets-table .col-time {
  text-align: right;
}

.markets-table .col-mkt,
.markets-table .col-status,
.markets-table .col-src {
  text-align: center;
}

.markets-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  color: var(--ink-1);
}

.markets-table .col-name {
  color: var(--ink-1);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Market group separators --- */

.markets-table__group td {
  padding: 10px 10px 6px;
  border-bottom: 1px solid var(--line-bright);
  background: var(--bg-0);
}

.markets-table__group:first-child td {
  padding-top: 4px;
}

.markets-table__group-name {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--phosphor-dim);
}

.markets-table__group-count {
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  margin-left: 10px;
}

.markets-table__empty {
  padding: 18px 10px !important;
  color: var(--ink-2);
  font-size: 12px;
  white-space: normal !important;
}

/* --- Instrument rows --- */

.markets-row {
  border-left: 2px solid transparent;
  transition: none;
}

.markets-row:hover {
  background: var(--bg-2);
}

.markets-row.is-selected {
  background: rgba(57, 255, 138, 0.07);
  border-left: 2px solid var(--phosphor);
}

.markets-row__symbol {
  color: var(--ink-0);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.markets-row__price {
  color: var(--ink-0);
  font-weight: 600;
}

.markets-row__ccy {
  color: var(--ink-2);
  font-size: 10px;
  margin-left: 4px;
}

.col-chg,
.col-chgpct {
  font-weight: 500;
}

.is-up { color: var(--phosphor); }
.is-down { color: var(--red); }
.is-flat { color: var(--ink-2); }

.col-status.is-open { color: var(--phosphor); }
.col-status.is-closed { color: var(--ink-2); }
.col-status.is-unknown { color: var(--amber); }

.markets-row__badge {
  font-size: 9px;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
}

.markets-row__badge.is-mock { color: var(--amber); }
.markets-row__badge.is-live { color: var(--phosphor); }

/* ===============================================================
   Star (watch) column — shared by Watchlist and Explorer
   =============================================================== */

.markets-table .col-star {
  width: 28px;
  text-align: center;
  padding-left: 8px;
  padding-right: 0;
}

.markets-star {
  background: none;
  border: none;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 2px;
}

.markets-star:hover {
  color: var(--ink-1);
}

.markets-star.is-watched {
  color: var(--amber);
}

/* ===============================================================
   Responsive
   =============================================================== */

@media (max-width: 640px) {
  .markets-screen {
    padding: 0 12px;
  }

  .markets-panel {
    padding: 18px 16px 4px;
  }

  .markets-panel__head {
    flex-direction: column;
    align-items: flex-start;
  }

  .markets-panel__hint {
    display: none;
  }

  .markets-table {
    font-size: 11px;
  }

  .markets-table .col-name {
    max-width: 120px;
  }
}
