/* Needlstack — dark-mode-first stylesheet */

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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --chip-bg: #1f3a5f;
  --chip-border: #388bfd;
  --danger: #f85149;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, monospace;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
}

.wordmark {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  text-decoration: none;
}

.wordmark span {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Main layout ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  overflow: hidden;
}

/* ── Controls ── */
#controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Search */
.search-wrapper {
  position: relative;
  flex-shrink: 0;
}

#ticker-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  height: 32px;
  padding: 0 10px;
  width: 180px;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.15s;
}

#ticker-input:focus {
  border-color: var(--accent);
}

#ticker-input::placeholder {
  text-transform: none;
  color: var(--text-muted);
}

/* Dropdown */
#ticker-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
}

#ticker-dropdown.open {
  display: block;
}

.dropdown-item {
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.dropdown-item:hover,
.dropdown-item.focused {
  background: var(--surface2);
}

.dropdown-ticker {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  min-width: 52px;
  font-weight: 600;
}

.dropdown-name {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-empty {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Chips */
#chip-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 20px;
  padding: 2px 10px 2px 10px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-hover);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 0 0 2px;
  transition: color 0.1s;
}

.chip-remove:hover {
  color: var(--danger);
}

/* Metrics */
.metrics-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.metrics-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

.metric-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  height: 28px;
  padding: 0 10px;
  transition: all 0.15s;
  white-space: nowrap;
}

.metric-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.metric-btn.active {
  background: var(--chip-bg);
  border-color: var(--chip-border);
  color: var(--accent-hover);
  font-weight: 500;
}

/* Date range presets */
.range-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.range-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  height: 28px;
  padding: 0 8px;
  transition: all 0.15s;
}

.range-btn:hover {
  color: var(--text);
  border-color: var(--border);
}

.range-btn.active {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--accent);
  font-weight: 600;
}

/* ── Chart area ── */
#chart-container {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 400px;
  position: relative;
}

#plotly-chart {
  position: absolute;
  inset: 0;
}

/* Empty / loading states */
#chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

#chart-placeholder svg {
  opacity: 0.3;
}

#chart-placeholder p {
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Status bar ── */
#status-bar {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

/* ── Scrollbar styling ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  main {
    padding: 10px 12px;
  }
  header {
    padding: 0 12px;
  }
  .controls-row {
    gap: 6px;
  }
}
