/* ------------------------------------------------------------------ */
/* Design tokens — Finviz-inspired dark palette                       */
/* ------------------------------------------------------------------ */

:root {
  --bg-page: #0d1117;
  --bg-panel: #161b22;
  --bg-label: #21262d;
  --border: #30363d;
  --border-hover: #58a6ff;
  --text-primary: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;

  --positive: #26a641;
  --positive-dark: #1a7f32;
  --negative: #da3633;
  --negative-dark: #8b1e1e;
  --neutral: #484f58;
  --neutral-dark: #3a4048;

  --gap: 2px;
  --radius: 2px;

  /* Neutral */
  --change-neutral: #484f58;
  --change-neutral-dark: #3a4048;
  /* Green tiers */
  --change-green-dark: #1e4620;
  --change-green-dark-deep: #0f2812;
  --change-green-medium: #2ea043;
  --change-green-medium-deep: #1a7f32;
  --change-green-bright: #0BDA51;
  --change-green-bright-deep: #3CB371;

  /* Red tiers */
  --change-red-dark: #5c2020;
  --change-red-dark-deep: #3a1212;
  --change-red-medium: #c93c37;
  --change-red-medium-deep: #8b1e1e;
  --change-red-bright: #f85149;
  --change-red-bright-deep: #da3633;
}

/* ------------------------------------------------------------------ */
/* Reset & base                                                       */
/* ------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-primary);
  background-color: var(--bg-page);
  overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Dashboard shell                                                    */
/* ------------------------------------------------------------------ */

.dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 8px;
  gap: 8px;
}

.dashboard-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 8px 12px;
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.dashboard-title h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.dashboard-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ------------------------------------------------------------------ */
/* Performance legend — continuous gradient bar                       */
/* ------------------------------------------------------------------ */

.legend--gradient {
  flex: 0 0 360px;
  min-width: 240px;
  max-width: 480px;
}

.legend-gradient-bar {
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(to right,
      var(--change-red-bright) 0%,
      var(--change-red-medium) 16.67%,
      var(--change-red-dark) 33.33%,
      var(--change-neutral) 50%,
      var(--change-green-dark) 66.67%,
      var(--change-green-medium) 83.33%,
      var(--change-green-bright) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.legend-gradient-label {
  flex: 1;
  text-align: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  line-height: 1.3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  user-select: none;
  pointer-events: none;
  position: relative
}

.legend-gradient-label:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 0;
  width: 1px;
  height: calc(100% - 6px);
  background: rgba(255, 255, 255, 0.35);
}


/* ------------------------------------------------------------------ */
/* Heatmap — D3 treemap canvas                                        */
/* ------------------------------------------------------------------ */

.heatmap {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.heatmap--treemap {
  display: block;
  isolation: isolate;
}

.sector-plate,
.industry-plate {
  position: absolute;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  pointer-events: none;
}

.sector-plate {
  background-color: var(--bg-panel);
}

.industry-plate {
  background-color: var(--bg-page);
}

/* ------------------------------------------------------------------ */
/* Pinned header bars (Part A)                                        */
/* ------------------------------------------------------------------ */

.sector-header,
.industry-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  background-color: var(--bg-label);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  user-select: none;
}

.sector-header {
  height: 22px;
  font-size: 0.6875rem;
}

.industry-header {
  height: 20px;
  font-size: 0.625rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ */
/* Treemap body regions (Part B)                                      */
/* ------------------------------------------------------------------ */

.sector-body,
.industry-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Stock blocks — absolute treemap cells                              */
/* ------------------------------------------------------------------ */

.stock-block {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 4px;
  min-width: 0;
  min-height: 0;
  padding: 4px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  cursor: default;
  overflow: hidden;
  transition: background 0.4s ease, outline-color 0.15s ease, filter 0.15s ease;
  pointer-events: auto;
}

.stock-block--medium .stock-change {
  display: none;
}

.stock-block--compact .stock-change {
  display: none;
}

.stock-block--micro .stock-symbol,
.stock-block--micro .stock-change {
  display: none;
}

.stock-block:hover {
  outline: 1px solid var(--border-hover);
  outline-offset: -1px;
  filter: brightness(1.12);
  z-index: 1;
}

.stock-block.change-neutral {
  background: linear-gradient(145deg, var(--change-neutral) 0%, var(--change-neutral-dark) 100%);
  color: var(--text-primary);
}

.stock-block.change-green-dark {
  background: linear-gradient(145deg, var(--change-green-dark) 0%, var(--change-green-dark-deep) 100%);
  color: #fff;
}

.stock-block.change-green-medium {
  background: linear-gradient(145deg, var(--change-green-medium) 0%, var(--change-green-medium-deep) 100%);
  color: #fff;
}

.stock-block.change-green-bright {
  background: linear-gradient(145deg, var(--change-green-bright) 0%, var(--change-green-bright-deep) 100%);
  color: #fff;
}

.stock-block.change-red-dark {
  background: linear-gradient(145deg, var(--change-red-dark) 0%, var(--change-red-dark-deep) 100%);
  color: #fff;
}

.stock-block.change-red-medium {
  background: linear-gradient(145deg, var(--change-red-medium) 0%, var(--change-red-medium-deep) 100%);
  color: #fff;
}

.stock-block.change-red-bright {
  background: linear-gradient(145deg, var(--change-red-bright) 0%, var(--change-red-bright-deep) 100%);
  color: #fff;
}

.stock-symbol {
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.1;
}

.stock-logo-wrap {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.stock-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stock-change {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  opacity: 0.95;
}

@keyframes stockFlash {
  0% {
    filter: brightness(1.6);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  }

  100% {
    filter: brightness(1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
}

.stock-block--flash {
  animation: stockFlash 0.6s ease-out;
}

/* ------------------------------------------------------------------ */
/* Stock hover tooltip                                                */
/* ------------------------------------------------------------------ */

.stock-tooltip {
  position: fixed;
  z-index: 100;
  min-width: 240px;
  max-width: 300px;
  padding: 10px 12px;
  background-color: #ffffff;
  color: #1f2328;
  border: 3px solid #000;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  font-size: 0.8125rem;
}

.stock-tooltip__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}

.stock-tooltip__symbol {
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: 0.04em;
  color: #1f2328;
}

.stock-tooltip__change {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.stock-tooltip__change--up {
  color: #2ea043;
}

.stock-tooltip__change--down {
  color: #c93c37;
}

.stock-tooltip__change--neutral {
  color: #656d76;
}

.stock-tooltip__name {
  color: #656d76;
  font-size: 0.75rem;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-tooltip__price-row {
  margin-bottom: 8px;
}

.stock-tooltip__price {
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #1f2328;
}

.stock-tooltip__chart {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
  border-radius: 4px;
  background: #f6f8fa;
}

.stock-tooltip__chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.stock-tooltip__chart-loading,
.stock-tooltip__chart-empty {
  color: #656d76;
  font-size: 0.75rem;
}

/* ------------------------------------------------------------------ */
/* Stock chart page                                                   */
/* ------------------------------------------------------------------ */

body.chart-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.chart-page__symbol {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
}

.chart-page__company {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.chart-page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chart-page__title-block {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.chart-page__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chart-page__logo-wrap {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
}

.chart-page__logo-wrap[hidden] {
  display: none;
}

.chart-page__logo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.chart-page__main {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 32px;
  flex: 1 1 auto;
  min-height: 0;
  background: #0f141b;
}

.chart-page__quote {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}

.chart-page__price {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.chart-page__change {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-page__change--up   { color: #2ea043; }
.chart-page__change--down { color: #c93c37; }
.chart-page__change--neutral { color: var(--text-muted); }

.chart-page__layout {
  display: flex;
  gap: 24px;
  width: min(100%, 1400px);
  height: 100%;
  align-items: stretch;
}

.chart-page__content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  height: min(100%, 65vh);
}

.chart-page__status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.9375rem;
  text-align: center;
}

.chart-page__status[hidden] {
  display: none;
}

.chart-page__container {
  width: 100%;
  flex: 1 1 auto;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.chart-page__container[hidden] {
  display: none;
}

.chart-page__range {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  align-self: flex-start;
  margin-bottom: 4px;
}

.chart-page__range-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chart-page__range-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.chart-page__range-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.chart-page__range-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chart-page__range-btn:disabled:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border-color: var(--border);
}

.chart-page__news {
  flex: 0 0 360px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.chart-page__news-heading {
  flex-shrink: 0;
  margin: 0;
  padding: 14px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.chart-page__news-feed {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-page__news-placeholder {
  margin: 0;
  padding: 16px 8px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.news-card {
  /* display: flow-root;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease; */
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.news-card:hover {
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.05);
}

.news-card__body {
  min-width: 0;
}

.news-card__headline {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  /* text-decoration: none; */
  line-height: 1.35;
  margin-bottom: 6px;
}

.news-card__headline:hover {
  color: var(--border-hover);
}

.news-card__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.news-card__summary {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0;
}

/* ------------------------------------------------------------------ */
/* Loading / error states                                             */
/* ------------------------------------------------------------------ */

.heatmap-status {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 24px;
  font-size: 0.9375rem;
  color: var(--text-muted);
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.heatmap-status--error {
  color: #f85149;
}

/* ------------------------------------------------------------------ */
/* Responsive — tablet                                                */
/* ------------------------------------------------------------------ */

@media (max-width: 1023px) {
  body {
    overflow: auto;
  }

  .dashboard {
    height: auto;
    min-height: 100dvh;
  }

  .heatmap {
    flex: none;
    min-height: 600px;
  }

  .sector-header {
    height: 20px;
    font-size: 0.625rem;
  }

  .industry-header {
    height: 18px;
    font-size: 0.5625rem;
  }
}

/* ------------------------------------------------------------------ */
/* Responsive — mobile                                                */
/* ------------------------------------------------------------------ */

@media (max-width: 767px) {
  .dashboard {
    padding: 4px;
    gap: 4px;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 8px;
  }

  .heatmap {
    min-height: 400px;
  }

  .sector-header,
  .industry-header {
    padding: 0 6px;
    letter-spacing: 0.04em;
  }

  .stock-block {
    padding: 2px;
  }

  .chart-page__header {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px;
  }

  .chart-page__symbol {
    font-size: 2rem;
  }

  .chart-page__logo-wrap {
    width: 88px;
    height: 88px;
  }

  .chart-page__layout {
    flex-direction: column;
  }

  .chart-page__news {
    flex: 0 0 auto;
    max-height: 40vh;
  }
}

/* ------------------------------------------------------------------ */
/* Responsive — very short viewports                                  */
/* ------------------------------------------------------------------ */

@media (max-height: 500px) and (min-width: 768px) {
  .dashboard-header {
    padding: 4px 8px;
  }

  .dashboard-title h1 {
    font-size: 1rem;
  }

  .dashboard-subtitle {
    display: none;
  }

  .legend--gradient {
    width: 100%;
    max-width: none;
  }

  .legend-gradient-label {
    font-size: 0.5625rem;
  }
}