/* WickChart demo — page chrome around the <wick-chart> component */

:root {
  --bg: #0b0d12;
  --panel: #11141c;
  --panel-2: #151923;
  --border: rgba(148, 163, 184, 0.14);
  --text: #cbd5e1;
  --text-muted: #7c8598;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --up: #16c784;
  --down: #ea3943;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

[data-theme='light'] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --border: rgba(15, 23, 42, 0.12);
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-2: #0891b2;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 7px 16px 8px;
}

.topbar-row + .topbar-row {
  border-top: 1px solid var(--border);
  padding-top: 7px;
}

/* flat control clusters separated by divider rules — one visual line each */
.cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.topbar-second .cluster + .cluster,
.topbar-main .cluster + .cluster {
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

/* studies take their natural width, shrink (and scroll) only when crowded */
.cluster-studies {
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding-bottom: 1px;
}
.cluster-studies::-webkit-scrollbar { display: none; }
.cluster-studies .chips,
.cluster-studies .script-row { flex: 0 0 auto; }
.cluster-studies .script-row { margin-left: 2px; }

.cluster-view { gap: 4px; }
.cluster-trade { margin-left: auto; }

/* view toggles are icon-only; labels stay for screen readers + tooltips */
.cluster-view .icon-btn {
  position: relative;
  padding: 7px 9px;
  min-height: 32px;
}
.cluster-view .icon-btn span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand-name b {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tag {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.topbar-main .brand { align-self: center; margin-right: 4px; }

.seg {
  display: flex;
  align-items: stretch;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: 600 12.5px var(--font);
  padding: 6px 12px;
  min-height: 30px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 160ms ease, background 160ms ease;
  white-space: nowrap;
}

.seg button:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.seg button.active {
  color: #fff;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 80%, #000));
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent);
}

.chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chips button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: 600 11.5px var(--font);
  padding: 5px 10px;
  min-height: 30px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.chips button i {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: currentColor;
  opacity: 0.35;
  transition: opacity 160ms ease, background 160ms ease;
}

.chips button:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.chips button.on {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.chips button.on i { opacity: 1; }

.script-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 260px;
}

.script-row input[type='text'] {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: 500 11.5px var(--font);
  padding: 5px 10px;
  min-height: 30px;
  width: clamp(150px, 16vw, 240px);
  border-radius: 999px;
  transition: border-color 160ms ease;
}

.script-row input[type='text']:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

.script-row input[type='text']::placeholder { color: var(--text-muted); opacity: 0.7; }

.script-pane {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 600 12px var(--font);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.script-add {
  appearance: none;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: 600 11.5px var(--font);
  padding: 5px 10px;
  min-height: 30px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}

.script-add:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.script-error { font: 500 11px var(--font); color: #ff6b6b; max-width: 340px; }

.topbar-right {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-muted);
  font: 600 12.5px var(--font);
  padding: 7px 12px;
  min-height: 34px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}

.icon-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.icon-btn[aria-pressed='true'] #ico-play { display: none; }
.icon-btn[aria-pressed='false'] #ico-pause { display: none; }
.icon-btn[aria-pressed='false'] #ico-play { display: block; }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent);
  animation: pulse 2s ease-out infinite;
}

.icon-btn[aria-pressed='false'] .live-dot {
  background: var(--text-muted);
  animation: none;
  box-shadow: none;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* focus rings */
button:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

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

.chart-area {
  flex: 1;
  min-height: 0;
  padding: 10px 12px 4px;
}

wick-chart {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--panel);
  /* theme the component with its CSS variables */
  --wick-bg: var(--panel);
  --wick-up: var(--up);
  --wick-down: var(--down);
  --wick-accent: var(--accent-2);
  --wick-text: var(--text-muted);
  --wick-text-strong: var(--text);
}

/* ---------------- status bar ---------------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 7px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  flex-wrap: wrap;
}

.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.dot.ok { background: var(--up); }
.dot.warn { background: #f59e0b; }
.dot.off { background: var(--text-muted); }

.range { font-variant-numeric: tabular-nums; }
.hint { margin-left: auto; opacity: 0.75; }

@media (max-width: 760px) {
  .hint { display: none; }
  .brand-tag { display: none; }

  /* The toolbar is a row of nowrap clusters, which on a phone laid the page
     out 970px wide — the browser then zoomed the whole demo out to fit. Let
     the clusters and the segmented groups inside them wrap instead; the
     dividers and the trade cluster's auto margin only make sense on one line. */
  .cluster,
  .seg,
  .chips { flex-wrap: wrap; }
  /* Both axes, not just overflow-x: a visible axis paired with a clipped one
     computes back to auto, which would leave the cluster a scroller and give
     its chips unlimited width to lay out in — so they would never wrap. */
  .cluster-studies { overflow: visible; }
  /* and they must be allowed to shrink, or each group keeps its max-content
     width and the wrap never happens */
  .cluster-studies .chips,
  .cluster-studies .script-row { flex: 1 1 auto; min-width: 0; }
  .topbar-second .cluster + .cluster,
  .topbar-main .cluster + .cluster { padding-left: 0; border-left: none; }
  .cluster-trade { margin-left: 0; }
  .script-row { min-width: 0; }
}

/* ---------------- AI summary panel ---------------- */

.chart-area { position: relative; }

.explain-panel {
  position: absolute;
  right: 22px;
  bottom: 14px;
  width: min(520px, calc(100% - 44px));
  max-height: min(60%, 420px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg, #11141c) 92%, #fff);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 20;
  overflow: hidden;
}

/* the display: flex above beats the UA [hidden] rule — keep ✕ and the
   initial hidden attribute actually working */
.explain-panel[hidden] { display: none; }

.explain-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  font: 700 12px var(--font);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.explain-actions { display: inline-flex; gap: 6px; }

.explain-actions button {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: 600 11px var(--font);
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.explain-actions button:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.explain-panel pre {
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  font: 500 11.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.explain-hint {
  margin: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font: 500 11px var(--font);
  color: var(--text-muted);
}

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed;
  bottom: 46px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  color: var(--text);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  animation: toast-in 200ms ease;
  max-width: 340px;
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
