/* GoldSignals chart — app shell (forked from dtnexus-charts).
 *
 * Everything inside the chart itself is painted by TradingView's own theme
 * (driven from src/theme.js via widget.changeTheme). These rules cover the
 * header, the chart frame, the loading / error overlays and the signal panel
 * — on the same two palettes, so the seam between shell and chart is
 * invisible. The signal colours (long, short, stop, target, the level kinds)
 * are the ones the overlay draws with, declared once in src/signals/palette.js
 * and mirrored here.
 */

:root {
  --brand-red: #e8232a;
  --gold: #c9971c;
  --long: #1f9d7a;
  --short: #d3455b;
  --stop: #d3455b;
  --target: #1f9d7a;
  --block-bull: #2f6fd6;
  --block-bear: #d97b1f;
  --gap: #8a63d2;
  --swing: #7a8290;
  --panel-width: 380px;

  /* Light palette (matches TradingView's light theme surfaces). */
  --bg: #ffffff;
  --surface: #ffffff;
  --header-bg: #ffffff;
  --border: #e0e3eb;
  --text: #131722;
  --text-muted: #6a7185;
  --hover: #f0f3fa;
}

:root[data-theme="dark"] {
  /* Dark palette (matches TradingView's dark theme surfaces). */
  --bg: #131722;
  --surface: #1e222d;
  --header-bg: #1e222d;
  --border: #2a2e39;
  --text: #d1d4dc;
  --text-muted: #868993;
  --hover: #2a2e39;
  --gold: #e0b03a;
}

* {
  box-sizing: border-box;
}

/* The panel's sections are flex boxes; `hidden` must still win. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  /* dvh keeps the chart off the mobile URL bar as it collapses; the vh line
     above it is the fallback for browsers without dvh. */
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------------------------------------------- header */

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
  padding: 0 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand__mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe08a, var(--gold) 60%, #8a6210);
  flex: 0 0 auto;
}

.brand__name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand__name-accent {
  color: var(--gold);
}

.brand__divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex: 0 0 auto;
}

.brand__sub {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ----------------------------------------------------------- theme toggle */

.theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  background: var(--hover);
}

.theme-toggle:focus-visible,
.icon-button:focus-visible,
.panel__tab:focus-visible,
.signal-row:focus-visible,
.link-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.theme-toggle__icon {
  width: 18px;
  height: 18px;
}

/* Show the icon for the mode the button switches *to*. */
.theme-toggle__icon--sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

/* ----------------------------------------------------------------- chart */

.app-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.chart-shell {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chart-shell__chart {
  width: 100%;
  height: 100%;
}

/* -------------------------------------------------------------- overlays */

.chart-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}

.chart-overlay[hidden] {
  display: none;
}

.chart-overlay__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chart-overlay__text {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 40ch;
}

.chart-overlay__button {
  margin-top: 4px;
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: var(--gold);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

/* ----------------------------------------------------------- feed notice */

.feed-notice {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 18%);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.feed-notice--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 480px) {
  .app-header {
    height: 48px;
    padding: 0 12px;
  }

  .brand__divider,
  .brand__sub {
    display: none;
  }
}

/* ---------------------------------------------------------------- header */

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: center;
}

.status-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill[data-state="ok"] {
  color: var(--long);
  border-color: color-mix(in srgb, var(--long) 50%, var(--border));
}

.status-pill[data-state="warn"] {
  color: var(--block-bear);
  border-color: color-mix(in srgb, var(--block-bear) 50%, var(--border));
}

.status-pill[data-state="down"] {
  color: var(--short);
  border-color: color-mix(in srgb, var(--short) 50%, var(--border));
}

.status-pill:empty {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.icon-button:hover {
  background: var(--hover);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button[aria-pressed="false"] {
  color: var(--text-muted);
}

.icon-button--small {
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
}

/* ----------------------------------------------------------------- panel */

.panel {
  flex: 0 0 var(--panel-width);
  width: var(--panel-width);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

.panel[hidden] {
  display: none;
}

.panel__tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}

.panel__tab {
  flex: 1 1 0;
  padding: 10px 8px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.panel__tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--gold);
}

.panel__view {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel__view[hidden] {
  display: none;
}

.panel__section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.panel__hint {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.45;
}

.link-button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ----------------------------------------------------------- signal list */

.signal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.signal-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.signal-row:hover {
  background: var(--hover);
}

.signal-row[aria-current="true"] {
  border-color: var(--gold);
  background: var(--hover);
}

.signal-row--refused {
  opacity: 0.62;
}

.signal-row__time {
  grid-row: 1 / span 2;
  font-weight: 600;
  font-size: 13px;
}

.signal-row__side {
  font-weight: 600;
}

.signal-row__side[data-dir="1"] {
  color: var(--long);
}

.signal-row__side[data-dir="-1"] {
  color: var(--short);
}

.signal-row__geom {
  color: var(--text-muted);
  font-size: 12px;
  grid-column: 2;
}

.signal-row__status {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text-muted);
}

.badge--published {
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 55%, var(--border));
}

.badge--suppressed {
  color: var(--block-bear);
}

.badge--tp {
  color: var(--long);
  border-color: color-mix(in srgb, var(--long) 55%, var(--border));
}

.badge--sl {
  color: var(--short);
  border-color: color-mix(in srgb, var(--short) 55%, var(--border));
}

.badge--time,
.badge--no_fill,
.badge--break {
  color: var(--text-muted);
}

.badge--strong {
  color: var(--long);
  border-color: color-mix(in srgb, var(--long) 55%, var(--border));
}

.badge--moderate {
  color: var(--block-bull);
  border-color: color-mix(in srgb, var(--block-bull) 55%, var(--border));
}

.badge--weak {
  color: var(--text-muted);
}

.badge--none {
  color: var(--text-muted);
  border-style: dashed;
}

/* ------------------------------------------------------------- detail */

.detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.45;
}

.detail__headline {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.detail__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  row-gap: 3px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.detail__facts dt {
  color: var(--text-muted);
}

.detail__facts dd {
  margin: 0;
}

.claim {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-left: 3px solid var(--border);
  background: color-mix(in srgb, var(--hover) 55%, transparent);
  border-radius: 0 6px 6px 0;
}

.claim[data-strength="strong"] {
  border-left-color: var(--long);
}

.claim[data-strength="moderate"] {
  border-left-color: var(--block-bull);
}

.claim[data-strength="none"] {
  border-left-style: dashed;
}

.claim__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.claim__text {
  margin: 0;
}

.claim__basis {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.claim__cite {
  font-size: 11px;
  color: var(--text-muted);
}

.claim__cite summary {
  cursor: pointer;
}

.claim__cite ul {
  margin: 4px 0 0;
  padding-left: 16px;
}

.detail__note {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.grade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
}

/* ----------------------------------------------------------- day picker */

.day-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.day-picker select,
.levels-controls select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.day-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
}

.stat__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat__value {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__value--pos {
  color: var(--long);
}

.stat__value--neg {
  color: var(--short);
}

.levels-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  cursor: pointer;
}

.check--select {
  gap: 8px;
}

.check:has(input:disabled),
.check:has(select:disabled),
.day-picker:has(select:disabled) {
  opacity: 0.5;
}

/* ---------------------------------------------------------- performance */

.perf {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.perf__books {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.perf__table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.perf__table th,
.perf__table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.perf__table th:first-child,
.perf__table td:first-child {
  text-align: left;
}

.perf__table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.perf__scroll {
  overflow-x: auto;
}

.bars {
  width: 100%;
  height: 120px;
  display: block;
}

.bars text {
  fill: var(--text-muted);
  font-size: 10px;
}

.bars .axis {
  stroke: var(--border);
}

.bars .up {
  fill: var(--long);
}

.bars .down {
  fill: var(--short);
}

.equity {
  width: 100%;
  height: 100px;
  display: block;
}

.equity path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.5;
}

/* ------------------------------------------------------- overlay notice */

.overlay-notice {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 6;
  max-width: min(80%, 360px);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 4px 16px rgb(0 0 0 / 14%);
}

.overlay-notice[hidden] {
  display: none;
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .app-body {
    flex-direction: column;
  }

  .panel {
    flex: 0 0 46%;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .header-status {
    display: none;
  }

  .day-summary,
  .perf__books {
    grid-template-columns: repeat(2, 1fr);
  }
}

