@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap");

:root {
  --bg: #090909;
  --panel: #121212;
  --panel-2: #0f0f0f;
  --line: #2a2a2a;
  --line-strong: #3a3a3a;
  --ink: #f2f2f2;
  --muted: #a8a8a8;
  --price-line: #8ec5ff;
  --marker-buy: #7dffbc;
  --marker-sell: #ffd67f;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.tv-shell {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.tv-topbar {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.45);
  flex-wrap: wrap;
}

.tv-left,
.tv-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tv-right {
  margin-left: 0;
  width: 100%;
  justify-content: flex-start;
}

.tv-muted { color: var(--muted); }

.tv-input,
#authToken,
#authForm button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 0 10px;
  font-family: inherit;
}

.tv-input { cursor: pointer; }

.tv-segment {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel-2);
}

.tv-segment-btn {
  border: 0;
  border-right: 1px solid var(--line);
  height: 28px;
  min-width: 44px;
  background: var(--panel-2);
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}

.tv-segment-btn:last-child { border-right: 0; }
.tv-segment-btn.is-active { background: #2962ff; color: #fff; }
.tv-segment-btn.is-active {
  background: #f2f2f2;
  color: #090909;
  font-weight: 700;
}

.tv-summary {
  border: 1px solid var(--line);
  border-top: 1px solid var(--line);
  border-radius: 16px;
  margin-top: 12px;
  padding: 8px 10px;
  color: var(--muted);
  background: var(--panel);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.45);
}

.tv-legend-help {
  border: 1px solid var(--line);
  border-top: 1px solid var(--line);
  border-radius: 16px;
  margin-top: 12px;
  padding: 7px 10px;
  color: #b8c1d4;
  background: var(--panel);
  font-size: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}

.legend-title {
  color: #d9dff0;
  font-weight: 700;
}

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

.legend-toggle {
  border: 1px solid var(--line);
  background: #141414;
  color: #b8c1d4;
  border-radius: 999px;
  padding: 3px 8px;
  cursor: pointer;
  font: inherit;
}

.legend-toggle.is-on {
  border-color: var(--line-strong);
  background: #151515;
  color: var(--ink);
}

.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.swatch-price { background: #f2f2f2; }
.swatch-ema5 { background: #c5f27d; }
.swatch-ema20 { background: #00c853; }
.swatch-ma50 { background: #448aff; }
.swatch-ma200 { background: #e5ff4f; }
.swatch-vwap { background: rgba(255, 138, 101, 0.9); }
.swatch-macro-trend { background: rgba(186, 147, 255, 0.95); }
.swatch-trend-mid { background: #c6b5ff; }
.swatch-trend-upper { background: #68b8ff; }
.swatch-trend-lower { background: #78efac; }

.legend-marker {
  font-style: normal;
  font-weight: 700;
  line-height: 1;
}

.marker-buy { color: #7dffbc; }
.marker-sell { color: #ffd67f; }

@media (max-width: 900px) {
  .tv-legend-help {
    font-size: 10px;
    gap: 8px 10px;
  }
  .legend-swatch {
    width: 12px;
  }
}

.tv-chart-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-top: 12px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.45);
  position: relative;
}

.tv-main {
  display: grid;
  grid-template-columns: 1fr 84px;
}

.tv-crosshair-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% - 84px);
  height: 700px;
  pointer-events: none;
  z-index: 5;
}

.tv-scroll {
  overflow-x: scroll;
  overflow-y: hidden;
  height: 700px;
  background: #121212;
  scrollbar-color: #495066 transparent;
  position: relative;
}

.tv-scroll::-webkit-scrollbar { height: 8px; }
.tv-scroll::-webkit-scrollbar-track { background: transparent; }
.tv-scroll::-webkit-scrollbar-thumb { background: #495066; border-radius: 999px; }

.tv-chart {
  display: block;
  min-height: 700px;
  background: linear-gradient(180deg, #111 0%, #0c0c0c 100%);
  image-rendering: auto;
}

.tv-crosshair-overlay {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tv-axis-right {
  display: block;
  width: 84px;
  min-height: 700px;
  background: #111;
  border-left: 1px solid var(--line);
}

.tv-x-axis {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
  height: 20px;
  align-items: center;
  padding-right: 84px;
  border-top: 0;
  color: #b7bdcb;
  font-size: 10px;
  background: #121212;
}

.tv-crosshair-date,
.tv-crosshair-price {
  position: absolute;
  pointer-events: none;
  font-size: 11px;
  font-weight: 500;
  color: #f2f2f2;
  background: rgba(14, 14, 14, 0.95);
  border: 1px solid #4f5666;
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1.2;
  white-space: nowrap;
  z-index: 4;
}

.tv-crosshair-date {
  top: calc(700px + 1px);
  transform: translateX(-50%);
}

.tv-crosshair-price {
  right: 4px;
  transform: translateY(-50%);
}

.tv-crosshair-date.is-hidden,
.tv-crosshair-price.is-hidden {
  display: none;
}

.tv-x-axis-cell {
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-line {
  stroke: #20232d;
  stroke-width: 1;
}

.axis-label {
  fill: #cfcfcf;
  font-size: 11px;
}

.axis-date {
  text-anchor: middle;
}

.marker-buy,
.marker-sell {
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
}

.marker-buy { fill: var(--marker-buy); }
.marker-sell { fill: var(--marker-sell); }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(7, 9, 13, 0.8);
}

.auth-gate.is-hidden { display: none; }

.auth-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

#authForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#authMessage {
  margin: 0;
  color: #f08b94;
  min-height: 16px;
}

@media (max-width: 900px) {
  .tv-shell { padding: 10px 8px calc(18px + env(safe-area-inset-bottom, 0px)); }
  .tv-main { grid-template-columns: 1fr 62px; }
  .tv-axis-right { width: 62px; }
  .tv-x-axis { padding-right: 62px; }
  .tv-scroll {
    height: 700px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    scrollbar-width: none;
  }
  .tv-scroll::-webkit-scrollbar { height: 0; }
  .axis-label { font-size: 10px; }
  .tv-crosshair-date,
  .tv-crosshair-price {
    font-size: 9px;
    padding: 2px 5px;
  }
  .tv-crosshair-layer {
    width: calc(100% - 62px);
  }
}
