/* Atomic Alpha - Minimalist Heatmap Design */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Flat heatmap colors - inspired by Finviz */
  --green-5: #30c85e;
  --green-4: #3dd868;
  --green-3: #5ee085;
  --green-2: #8ceba6;
  --green-1: #c2f5d0;
  --neutral: #2a2e39;
  --red-1: #f5c2c2;
  --red-2: #eb8c8c;
  --red-3: #e05e5e;
  --red-4: #d83d3d;
  --red-5: #c83030;

  /* UI colors */
  --bg: #1a1d24;
  --surface: #22262f;
  --border: #333842;
  --text: #e8eaed;
  --text-muted: #8b9099;
  --text-dim: #5a6068;

  /* Category colors - very muted */
  --cat-default: #2a2e39;
}

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

body {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Header - ultra minimal */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text);
  text-transform: uppercase;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.view-toggle {
  display: flex;
  gap: 2px;
}

.view-toggle button {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 3px;
  transition: all 0.15s;
}

.view-toggle button.active {
  background: var(--surface);
  color: var(--text);
}

.view-toggle button:hover:not(.active) {
  color: var(--text);
}

.last-updated {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Main container */
.container {
  padding: 20px;
  max-width: 100%;
  overflow-x: auto;
}

/* Periodic Table Grid */
.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, 56px);
  grid-template-rows: repeat(10, 56px);
  gap: 2px;
  width: fit-content;
  margin: 0 auto;
}

/* Gap row between main table and lanthanides/actinides */
.periodic-table::before {
  content: '';
  grid-row: 8;
  grid-column: 1 / -1;
  height: 8px;
}

/* Element cell */
.element {
  width: 56px;
  height: 56px;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  background: var(--cat-default);
  transition: transform 0.1s, opacity 0.1s;
}

.element:hover {
  transform: scale(1.08);
  z-index: 10;
}

/* Price update flash animation */
.element.price-updated {
  animation: price-flash 0.6s ease-out;
}

@keyframes price-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5);
  }
  50% {
    box-shadow: 0 0 8px 2px rgba(255, 255, 255, 0.3);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.element .atomic-number {
  display: none;
}

.element .symbol {
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
}

.element .name {
  display: none;
}

.element .change {
  font-size: 10px;
  font-weight: 500;
  margin-top: 3px;
  color: var(--text);
  opacity: 0.9;
}

/* Non-tradeable elements - very subtle */
.element:not(.tradeable) {
  opacity: 0.25;
}

.element:not(.tradeable):hover {
  opacity: 0.5;
}

.element:not(.tradeable) .symbol {
  color: var(--text-muted);
}

/* Tradeable elements with heatmap colors - FLAT, no gradients */
.element.heatmap-positive-5 { background: var(--green-5); }
.element.heatmap-positive-4 { background: var(--green-4); }
.element.heatmap-positive-3 { background: var(--green-3); }
.element.heatmap-positive-2 { background: var(--green-2); }
.element.heatmap-positive-1 { background: var(--green-1); }
.element.heatmap-neutral { background: var(--neutral); }
.element.heatmap-negative-1 { background: var(--red-1); }
.element.heatmap-negative-2 { background: var(--red-2); }
.element.heatmap-negative-3 { background: var(--red-3); }
.element.heatmap-negative-4 { background: var(--red-4); }
.element.heatmap-negative-5 { background: var(--red-5); }

/* Text color adjustments for light backgrounds */
.element.heatmap-positive-1 .symbol,
.element.heatmap-positive-2 .symbol,
.element.heatmap-negative-1 .symbol,
.element.heatmap-negative-2 .symbol {
  color: #1a1d24;
}

.element.heatmap-positive-1 .change,
.element.heatmap-positive-2 .change,
.element.heatmap-negative-1 .change,
.element.heatmap-negative-2 .change {
  color: #1a1d24;
}

/* Markets Only View */
.periodic-table.markets-only {
  grid-template-columns: repeat(5, 80px);
  grid-template-rows: auto;
  gap: 3px;
  max-width: 450px;
}

.periodic-table.markets-only .element {
  grid-row: auto !important;
  grid-column: auto !important;
  width: 80px;
  height: 80px;
  opacity: 1;
}

.periodic-table.markets-only .element .symbol {
  font-size: 20px;
}

.periodic-table.markets-only .element .change {
  font-size: 12px;
  margin-top: 4px;
}

/* Legend - minimal inline scale */
.legend {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding: 12px;
}

.legend-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-title {
  display: none;
}

.legend-scale {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-scale span {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.legend-gradient {
  display: flex;
  gap: 2px;
}

.legend-swatch {
  width: 24px;
  height: 12px;
  border-radius: 2px;
}

.legend-categories {
  display: none;
}

/* Predict View */
.predict-view {
  width: 100%;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.predict-placeholder {
  text-align: center;
  padding: 48px 24px;
  max-width: 400px;
}

.predict-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.8;
}

.predict-placeholder h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.predict-placeholder p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.predict-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.predict-feature {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.feature-icon {
  font-size: 14px;
}

/* Tooltip - refined terminal aesthetic */
.tooltip {
  position: fixed;
  background: linear-gradient(135deg, rgba(34, 38, 47, 0.98) 0%, rgba(26, 29, 36, 0.98) 100%);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  transform: translateY(4px);
  min-width: 180px;
  max-width: 260px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.tooltip.active {
  opacity: 1;
  transform: translateY(0);
}

.tooltip-handle {
  display: none;
}

.tooltip-header {
  display: flex;
  flex-direction: column;
}

.tooltip-data {
  display: flex;
  flex-direction: column;
}

.tooltip-symbol {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.tooltip-name {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tooltip-divider {
  height: 1px;
  background: linear-gradient(90deg, var(--border) 0%, transparent 100%);
  margin: 12px 0 10px;
}

.tooltip-row {
  display: grid;
  grid-template-columns: 50px 1fr;
  align-items: baseline;
  font-size: 11px;
  margin-top: 6px;
  gap: 12px;
}

.tooltip-label {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-size: 9px;
  font-weight: 500;
}

.tooltip-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.tooltip-value.tooltip-price {
  font-size: 13px;
  letter-spacing: -0.3px;
}

.tooltip-value.tooltip-ticker {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.tooltip-value.tooltip-source {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  font-weight: 400;
}

.tooltip-value.positive {
  color: var(--green-4);
}

.tooltip-value.negative {
  color: var(--red-4);
}

/* Remove old modal styles - replaced with tooltip */
.element-modal,
.modal-overlay {
  display: none !important;
}

/* Touch device - disable hover scale, use tap */
@media (hover: none) {
  .element:hover {
    transform: none;
  }

  .element:active {
    transform: scale(0.95);
  }
}

/* Responsive */
@media (max-width: 1100px) {
  .periodic-table {
    grid-template-columns: repeat(18, 48px);
    grid-template-rows: repeat(10, 48px);
  }

  .element {
    width: 48px;
    height: 48px;
  }

  .element .symbol {
    font-size: 14px;
  }

  .element .change {
    font-size: 9px;
  }
}

@media (max-width: 920px) {
  .periodic-table {
    grid-template-columns: repeat(18, 40px);
    grid-template-rows: repeat(10, 40px);
    gap: 1px;
  }

  .element {
    width: 40px;
    height: 40px;
  }

  .element .symbol {
    font-size: 12px;
  }

  .element .change {
    font-size: 8px;
    margin-top: 2px;
  }

  .header {
    padding: 10px 16px;
  }

  .container {
    padding: 16px;
  }
}

/* Mobile - markets-only optimized */
@media (max-width: 768px) {
  .header {
    padding: 12px 16px;
  }

  .view-toggle button {
    padding: 8px 12px;
    font-size: 11px;
  }

  .container {
    padding: 12px;
  }

  /* Full table: horizontal scroll */
  .periodic-table {
    grid-template-columns: repeat(18, 36px);
    grid-template-rows: repeat(10, 36px);
    gap: 2px;
  }

  .element {
    width: 36px;
    height: 36px;
    border-radius: 2px;
  }

  .element .symbol {
    font-size: 11px;
  }

  .element .change {
    display: none;
  }

  /* Markets view: fill screen nicely */
  .periodic-table.markets-only {
    grid-template-columns: repeat(4, 1fr);
    max-width: 100%;
    gap: 4px;
  }

  .periodic-table.markets-only .element {
    width: auto;
    height: auto;
    aspect-ratio: 1;
    min-height: 72px;
  }

  .periodic-table.markets-only .element .symbol {
    font-size: 18px;
  }

  .periodic-table.markets-only .element .change {
    display: block;
    font-size: 11px;
    margin-top: 4px;
  }

  /* Legend smaller */
  .legend {
    margin-top: 16px;
  }

  .legend-swatch {
    width: 18px;
    height: 10px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .header h1 {
    font-size: 12px;
  }

  .last-updated {
    display: none;
  }

  .view-toggle button {
    padding: 6px 10px;
    font-size: 10px;
  }

  /* Full table even smaller */
  .periodic-table {
    grid-template-columns: repeat(18, 28px);
    grid-template-rows: repeat(10, 28px);
    gap: 1px;
  }

  .element {
    width: 28px;
    height: 28px;
  }

  .element .symbol {
    font-size: 9px;
  }

  /* Markets view: 3 columns on tiny screens */
  .periodic-table.markets-only {
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
  }

  .periodic-table.markets-only .element {
    min-height: 80px;
  }

  .periodic-table.markets-only .element .symbol {
    font-size: 20px;
  }

  .periodic-table.markets-only .element .change {
    font-size: 12px;
  }

  .legend-swatch {
    width: 14px;
    height: 8px;
  }

  .legend-scale span {
    font-size: 9px;
  }
}

/* Bottom sheet tooltip for mobile */
@media (max-width: 768px) {
  .tooltip {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
    padding: 12px 24px 32px;
    min-width: 100%;
    max-width: 100%;
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s;
    opacity: 1;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  }

  .tooltip.active {
    transform: translateY(0);
  }

  .tooltip-handle {
    display: block;
    width: 36px;
    height: 4px;
    background: var(--text-dim);
    border-radius: 2px;
    margin: 0 auto 16px;
    opacity: 0.5;
  }

  .tooltip-symbol {
    font-size: 28px;
  }

  .tooltip-name {
    font-size: 12px;
    margin-top: 4px;
  }

  .tooltip-divider {
    margin: 16px 0 14px;
  }

  .tooltip-row {
    grid-template-columns: 60px 1fr;
    font-size: 13px;
    margin-top: 10px;
    gap: 16px;
  }

  .tooltip-label {
    font-size: 10px;
  }

  .tooltip-source {
    max-width: none;
    white-space: normal;
    font-size: 12px;
  }

  .tooltip-ticker {
    font-size: 12px;
    padding: 3px 8px;
  }
}
