:root {
  --listing-color: #059669;
  --listing-soft: #ecfdf5;
  --delisting-color: #dc2626;
  --delisting-soft: #fef2f2;
  --mixed-color: #64748b;
}

.eqw-page-header {
  align-items: flex-start;
  flex-wrap: wrap;
}

.legend-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: #fff;
}

.legend-badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.legend-badge.listing { background: var(--listing-color); }
.legend-badge.delisting { background: var(--delisting-color); }
.legend-badge svg { width: 9px; height: 9px; }

.legend-badge.mixed {
  width: 30px;
  border-radius: 999px;
  display: flex;
  padding: 0;
  overflow: hidden;
}

.legend-badge.mixed span {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-badge.mixed span:first-child { background: var(--listing-color); }
.legend-badge.mixed span:last-child { background: var(--delisting-color); }
.legend-badge.mixed svg { width: 8px; height: 8px; }

.eqw-chart-card {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;   /* chỉ đặt ở đây, không đặt ở .site-main */
}

.eqw-chart-container {
  flex: 1 1 auto;
  min-height: 440px; /* sàn tối thiểu, không co nhỏ hơn */
  height: auto; /* bỏ height: 440px cố định */
  position: relative;
}

/* ------------------------------------------------------------
   Chart toolbar (Latest + viewport note + Fit button)
   ------------------------------------------------------------ */

.chart-toolbar {
  min-height: 60px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chart-toolbar,
.range-panel {
  flex-shrink: 0; /* giữ nguyên kích thước, không bị co bởi flex */
}

.toolbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.latest {
  padding-right: 12px;
  border-right: 1px solid var(--border-soft);
}

.latest-label {
  display: block;
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.latest-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.latest-change {
  margin-left: 6px;
  font-weight: 600;
  font-size: 13px;
}

.latest-change.is-up { color: var(--listing-color); }
.latest-change.is-down { color: var(--delisting-color); }
.latest-change.is-flat { color: var(--text-muted); }

.toolbar-note {
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-note strong {
  color: var(--text-primary);
}

.fit-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: #fff;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.fit-btn:hover {
  background: var(--brand-blue-soft);
  color: var(--brand-navy);
  border-color: hsl(214 80% 82%);
}

.fit-btn:active {
  transform: translateY(1px);
}

/* ------------------------------------------------------------
   Range panel: visible-range summary + draggable timeline + presets
   ------------------------------------------------------------ */

.range-panel {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border-soft);
  background: #fcfdff;
}

.range-summary {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin-bottom: 14px;
}

.range-kicker {
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.065em;
  text-transform: uppercase;
}

.range-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.range-main strong {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.range-main .divider {
  color: var(--border-strong, #cbd5e1);
}

.range-main .count {
  color: var(--text-secondary);
  font-size: 13px;
}

.range-progress {
  text-align: right;
}

.range-progress strong {
  display: block;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.range-progress span {
  color: var(--text-secondary);
  font-size: 12px;
}

.timeline {
  position: relative;
  height: 54px;
  user-select: none;
}

.timeline-track {
  position: absolute;
  left: 2px;
  right: 2px;
  top: 18px;
  height: 8px;
  border-radius: 999px;
  background: repeating-linear-gradient(
    to right,
    #e9eef5 0,
    #e9eef5 2px,
    #f3f6fa 2px,
    #f3f6fa 6px
  );
}

.timeline-window {
  position: absolute;
  top: 18px;
  height: 8px;
  border-radius: 999px;
  background: var(--brand-blue);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.handle {
  position: absolute;
  top: 11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--brand-blue);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
  cursor: ew-resize;
  touch-action: none;
}

.timeline-labels {
  position: absolute;
  inset: 39px 0 auto;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 10px;
}

.range-actions {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.range-hint {
  color: var(--text-secondary);
  font-size: 12px;
}

.presets {
  display: flex;
  gap: 6px;
}

.preset {
  border: 1px solid var(--border-soft);
  background: #fff;
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.preset:hover,
.preset.active {
  border-color: hsl(214 80% 82%);
  color: var(--brand-navy);
  background: var(--brand-blue-soft);
}

@media (max-width: 640px) {
  .chart-toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .toolbar-note {
    display: none;
  }

  .range-summary {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .range-progress {
    text-align: left;
  }

  .range-actions {
    align-items: flex-start;
    flex-direction: column;
  }
}

.event-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

.event-connector {
  position: absolute;
  width: 1px;
  border-left: 1.5px dashed var(--connector-color, var(--text-muted));
  opacity: 0.55;
  transform: translateX(-50%);
}

.event-connector::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--connector-color, var(--text-muted));
  transform: translateX(-50%);
  opacity: 0.9;
}

.event-marker {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: filter 0.12s ease;
}

.event-marker:hover {
  filter: brightness(0.92);
}

.event-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25), 0 0 0 2px #fff;
  position: relative;
}

.event-badge.listing { background: var(--listing-color); }
.event-badge.delisting { background: var(--delisting-color); }
.event-badge svg { width: 10px; height: 10px; }

.event-count {
  position: absolute;
  top: -6px;
  right: -7px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: #fff;
  color: var(--text-primary);
  font-size: 9.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1.5px currentColor;
}

.event-badge.listing .event-count { color: var(--listing-color); }
.event-badge.delisting .event-count { color: var(--delisting-color); }

.event-badge.mixed {
  width: 38px;
  border-radius: 999px;
  display: flex;
  padding: 0;
  overflow: hidden;
}

.event-badge.mixed .event-half {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.event-badge.mixed .event-half.listing { background: var(--listing-color); }
.event-badge.mixed .event-half.delisting { background: var(--delisting-color); }

.event-badge.mixed .event-half .event-count {
  top: -6px;
  right: -3px;
}

.event-tooltip {
  position: absolute;
  display: none;
  padding: 12px 14px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 12.5px;
  border-radius: 10px;
  box-shadow: 0 12px 24px -8px rgba(15, 23, 42, 0.45);
  pointer-events: none;
  z-index: 50;
  line-height: 1.5;
  min-width: 190px;
  transform: translate(-50%, calc(-100% - 14px));
}

.event-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: #1e293b;
  transform: translateX(-50%) rotate(45deg);
}

.event-tooltip.is-below {
  transform: translate(-50%, 14px);
}

.event-tooltip.is-below::after {
  top: -5px;
  bottom: auto;
}

.event-tooltip-date {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.event-tooltip-group + .event-tooltip-group {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.event-tooltip-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 11.5px;
  margin-bottom: 6px;
}

.event-tooltip-label.listing { color: #34d399; }
.event-tooltip-label.delisting { color: #f87171; }
.event-tooltip-label svg { width: 9px; height: 9px; }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.01em;
}