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

:root {
  --font-mono: 'Space Mono', monospace;
  --font-title: var(--font-mono);
  --font-body: 'Stack Sans Text', sans-serif;
  --font-ticker: var(--font-mono);
  --map-inset-top: 46px;
  --map-inset-bottom: 46px;
  --accent: #48b892;
  --accent-border: #58c9a0;
  --accent-soft: rgba(72, 184, 146, 0.18);
  --accent-soft-strong: rgba(72, 184, 146, 0.24);
  --accent-chart: #62c9a6;
  --accent-chart-soft: rgba(72, 184, 146, 0.12);
}

@media (max-width: 900px) {
  :root {
    --map-inset-top: 78px;
  }
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #131722;
  color: #d1d4dc;
  font-family: var(--font-body);
}

body.modal-open {
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 1fr;
  width: 100vw;
  height: 100vh;
  position: relative;
}

#toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: rgba(30, 34, 45, 0.88);
  border-bottom: 1px solid rgba(42, 46, 57, 0.8);
  font-size: 13px;
  min-height: 34px;
  backdrop-filter: blur(4px);
  flex-wrap: wrap;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.size-mode-group {
  display: inline-flex;
  border: 1px solid #434651;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.size-mode-btn {
  background: transparent;
  border: none;
  color: #787b86;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  padding: 4px 10px;
  cursor: pointer;
  border-right: 1px solid #434651;
}

.size-mode-btn:last-child {
  border-right: none;
}

.size-mode-btn:hover {
  color: #d1d4dc;
  background: rgba(255, 255, 255, 0.05);
}

.size-mode-btn.active {
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.stock-search-wrap {
  position: relative;
  flex: 1;
  max-width: 280px;
  min-width: 120px;
}

#stock-search {
  width: 100%;
  background: #131722;
  border: 1px solid #434651;
  border-radius: 4px;
  color: #d1d4dc;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 10px;
  outline: none;
}

#stock-search:focus {
  border-color: var(--accent-border);
}

#stock-search::placeholder {
  color: #787b86;
}

.stock-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: rgba(30, 34, 45, 0.98);
  border: 1px solid #434651;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 20;
}

.stock-search-results.hidden {
  display: none;
}

.stock-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(67, 70, 81, 0.5);
  color: #d1d4dc;
  font-family: var(--font-body);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.stock-search-item:last-child {
  border-bottom: none;
}

.stock-search-item:hover,
.stock-search-item.active {
  background: var(--accent-soft);
}

.stock-search-item .search-symbol {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-search-item .search-name {
  color: #787b86;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-search-empty {
  padding: 10px;
  color: #787b86;
  font-size: 12px;
  text-align: center;
}

g.stock.is-search-highlight .stock-cell {
  stroke: #fff;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

@media (max-width: 900px) {
  #toolbar {
    align-items: flex-start;
  }

  .toolbar-center {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .stock-search-wrap {
    max-width: none;
  }
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-title {
  color: #fff;
  font-family: var(--font-title);
  font-size: 1.2em;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.title-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid #434651;
  color: #fff;
  font-family: var(--font-title);
  font-size: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  width: auto;
}

#source-title {
  white-space: nowrap;
}

.title-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.title-btn .chevron {
  color: #787b86;
  font-size: 11px;
}

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
}

.breadcrumb-item {
  color: #787b86;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: var(--font-title);
  font-weight: 400;
}

.breadcrumb-item:hover {
  color: #fff;
  background: #2a2e39;
}

.breadcrumb-item.active {
  color: #fff;
  cursor: default;
  font-weight: 700;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb-sep {
  color: #434651;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: #787b86;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  flex-shrink: 0;
  min-width: 0;
}

#status {
  max-width: min(340px, 38vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#countdown {
  min-width: 48px;
  text-align: right;
}

#map-container {
  position: relative;
  width: 100%;
  height: 100%;
  padding-top: var(--map-inset-top);
  padding-bottom: var(--map-inset-bottom);
  overflow: hidden;
  grid-row: 1;
  touch-action: none;
}

#map {
  display: block;
  width: 100%;
  height: 100%;
}

#map.is-zoomable {
  cursor: grab;
}

#map-container.is-panning #map {
  cursor: grabbing;
}

#chart-svg text {
  font-family: var(--font-body);
}

input,
button,
select,
textarea {
  font-family: var(--font-body);
}

.sector-group rect.sector-bg {
  fill: #1e222d;
  stroke: #2a2e39;
  stroke-width: 1;
}

.sector-label-bg {
  fill: rgba(19, 23, 34, 0.92);
  pointer-events: none;
}

.sector-label {
  fill: #d1d4dc;
  font-family: var(--font-title);
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stock-cell {
  cursor: pointer;
  stroke: none;
}

.stock-label {
  fill: #fff;
  font-family: var(--font-ticker);
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.stock-change {
  fill: rgba(255, 255, 255, 0.85);
  font-family: var(--font-body);
  font-weight: 500;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(30, 34, 45, 0.96);
  border: 1px solid #434651;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  z-index: 1000;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#tooltip.hidden {
  display: none;
}

.tooltip-symbol {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tooltip-name {
  color: #787b86;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.tooltip-row span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
  text-align: right;
}

.tooltip-positive {
  color: #26a69a;
}

.tooltip-negative {
  color: #ef5350;
}

#legend {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: rgba(30, 34, 45, 0.88);
  border: 1px solid rgba(42, 46, 57, 0.8);
  border-radius: 4px;
  font-size: 11px;
  backdrop-filter: blur(4px);
}

.legend-gradient {
  width: 180px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    #f87171,
    #52525b,
    #4ade80
  );
}

.legend-label {
  color: #787b86;
}

.legend-hint {
  color: #787b86;
  font-size: 10px;
  margin-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(320px, 42vw);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: relative;
  background: #fff;
  color: #131722;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 12px;
  gap: 16px;
  min-width: 0;
}

.modal-header h2 {
  font-family: var(--font-title);
  font-size: 18px;
  font-weight: 700;
  color: #131722;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: #787b86;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: #131722;
}

.source-panel {
  width: min(720px, 100%);
  background: #1e222d;
  color: #d1d4dc;
  border: 1px solid #2a2e39;
}

.source-panel .modal-header h2 {
  font-family: var(--font-title);
  font-weight: 700;
  color: #fff;
}

.source-panel .modal-close {
  color: #787b86;
}

.source-panel .modal-close:hover {
  color: #fff;
}

.source-search-wrap {
  position: relative;
  padding: 0 24px;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute;
  left: 36px;
  top: 50%;
  transform: translateY(-50%);
  color: #787b86;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
}

#source-search {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid #434651;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  line-height: 18px;
  color: #d1d4dc;
  background: #131722;
}

#source-search::placeholder {
  color: #787b86;
}

#source-search:focus {
  outline: none;
  border-color: var(--accent-border);
  background: #131722;
}

.source-list {
  overflow-y: auto;
  padding: 0 24px 24px;
  flex: 1;
  scrollbar-color: #434651 transparent;
}

.source-list::-webkit-scrollbar {
  width: 8px;
}

.source-list::-webkit-scrollbar-thumb {
  background: #434651;
  border-radius: 4px;
}

.source-country {
  margin-top: 18px;
}

.source-country:first-child {
  margin-top: 0;
}

.source-country-label {
  font-family: var(--font-title);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #787b86;
  margin-bottom: 8px;
}

.source-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: 400;
  color: #d1d4dc;
  width: 100%;
  min-width: 0;
}

.source-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-item:hover {
  background: #2a2e39;
}

.source-item.active {
  background: var(--accent-soft-strong);
  color: #fff;
}

.source-flag {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: #2a2e39;
}

.source-item.active .source-flag {
  background: rgba(255, 255, 255, 0.12);
}

.chart-panel {
  width: min(900px, 100%);
  background: #1e222d;
  color: #d1d4dc;
}

.chart-panel .modal-header h2,
#chart-symbol {
  font-family: var(--font-title);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chart-panel .modal-header {
  min-width: 0;
}

.chart-header-info {
  min-width: 0;
  overflow: hidden;
}

.chart-header-info p {
  color: #787b86;
  font-size: 13px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-panel .modal-close {
  color: #787b86;
}

.chart-panel .modal-close:hover {
  color: #fff;
}

.chart-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 0 24px 10px;
  font-size: 13px;
}

.chart-ohlc {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 0 24px 12px;
  font-size: 12px;
  min-height: 20px;
}

.chart-ohlc-item {
  display: flex;
  gap: 6px;
}

.chart-ohlc-label {
  color: #787b86;
}

.chart-ohlc-value {
  color: #d1d4dc;
  font-variant-numeric: tabular-nums;
}

.chart-ohlc-value.positive {
  color: #26a69a;
}

.chart-ohlc-value.negative {
  color: #ef5350;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 0 24px 12px;
}

.chart-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.chart-tool-btn {
  background: #131722;
  border: 1px solid #434651;
  color: #787b86;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.chart-tool-btn:hover {
  color: #d1d4dc;
  border-color: #787b86;
}

.chart-tool-btn.active {
  background: var(--accent-soft-strong);
  border-color: var(--accent-border);
  color: #fff;
}

.chart-select {
  background: #131722;
  border: 1px solid #434651;
  color: #d1d4dc;
  font: inherit;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.chart-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #787b86;
  cursor: pointer;
  user-select: none;
}

.chart-check input {
  accent-color: var(--accent);
}

.chart-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #787b86;
  white-space: nowrap;
}

.chart-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #26a69a;
  animation: chart-pulse 1.5s ease-in-out infinite;
}

@keyframes chart-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.chart-stat-label {
  color: #787b86;
  margin-right: 6px;
}

.chart-stat-positive {
  color: #26a69a;
}

.chart-stat-negative {
  color: #ef5350;
}

.chart-image-wrap {
  position: relative;
  padding: 0 16px 16px;
  background: #131722;
  margin: 0 16px 16px;
  border-radius: 6px;
}

/* Chart modal — ads sit outside the popup panel */
#chart-modal {
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.chart-modal-stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
}

#chart-modal.chart-ad-layout-bottom .chart-modal-stage {
  max-height: calc(100vh - 48px - 100px);
}

.chart-ad-outside {
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(19, 23, 34, 0.92);
  border: 1px dashed rgba(67, 70, 81, 0.85);
}

.chart-ad-banner.chart-ad-outside {
  width: min(900px, calc(100% - 48px));
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.chart-ad-side.chart-ad-outside {
  width: 160px;
  min-height: 280px;
  max-height: calc(100vh - 96px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-ad-placeholder {
  color: #9ca3af;
  font-size: 11px;
  text-align: center;
  padding: 12px;
  line-height: 1.4;
}

#chart-modal.chart-ad-layout-sides .chart-ad-banner.chart-ad-on-sides-fallback {
  display: none;
}

@media (max-width: 1100px) {
  #chart-modal.chart-ad-layout-sides .chart-ad-side {
    display: none !important;
  }

  #chart-modal.chart-ad-layout-sides .chart-ad-banner.chart-ad-on-sides-fallback {
    display: flex !important;
  }

  #chart-modal.chart-ad-layout-sides .chart-modal-stage {
    max-height: calc(100vh - 48px - 100px);
  }
}

.chart-market-status {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 4px 9px;
  border-radius: 4px;
  margin-left: auto;
  white-space: nowrap;
}

.chart-market-status.is-open {
  color: #26a69a;
  background: rgba(38, 166, 154, 0.14);
  border: 1px solid rgba(38, 166, 154, 0.45);
}

.chart-market-status.is-closed {
  color: #787b86;
  background: rgba(120, 123, 134, 0.12);
  border: 1px solid rgba(120, 123, 134, 0.35);
}

#chart-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 320px;
  cursor: crosshair;
}

#chart-svg.is-panning {
  cursor: grabbing;
}

.chart-panel-line {
  fill: none;
  stroke-width: 1.5;
  pointer-events: none;
}

.chart-panel-area {
  pointer-events: none;
}

.chart-volume-bar {
  pointer-events: none;
}

.chart-indicator-line {
  fill: none;
  stroke-width: 1.2;
  pointer-events: none;
}

.chart-bollinger-band {
  fill: var(--accent-chart-soft);
  pointer-events: none;
}

.chart-rsi-zone {
  pointer-events: none;
}

.chart-macd-bar {
  pointer-events: none;
}

.chart-zoom-overlay {
  cursor: grab;
}

.chart-zoom-overlay:active {
  cursor: grabbing;
}

.chart-crosshair-v,
.chart-crosshair-h {
  stroke: #787b86;
  stroke-width: 1;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.chart-focus-candle {
  pointer-events: none;
}

.chart-price-label {
  fill: #1e222d;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
}

.chart-price-label-bg {
  fill: #787b86;
  pointer-events: none;
}

.chart-date-label {
  fill: #1e222d;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  pointer-events: none;
}

.chart-date-label-bg {
  fill: #787b86;
  pointer-events: none;
}

@media (max-width: 640px) {
  .source-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 12px;
  }
}
