/* ===== AI Chart — Kronos forecast via lightweight-charts ==================
   View-only page (paid). The chart canvas colours come from chartOptions() in
   chart.js (light/dark presets); these rules cover the container + the HTML
   overlays (whale-level price labels and external-signal markers) and the
   Admin → Chart form. Dark mode follows the app's html[data-theme="dark"]. */

[data-tab="aichart"] .aichart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.aichart-caption {
  color: var(--muted);
  font-size: .85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 1.2em;
  margin: 6px 0 10px;
}

.aichart-status {
  font-size: .85rem;
  margin: 0 0 10px;
  min-height: 1.1em;
}
.aichart-status.info { color: var(--muted); }
.aichart-status.success { color: var(--primary); }
.aichart-status.error { color: var(--error); }

/* ----- Timeframe switcher (above the chart) ----- */
.aichart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
}
.aichart-toolbar .tab-group { display: flex; gap: 4px; }
/* Tabs read as plain labels; only the active one looks like a button. */
.aichart-toolbar .chart-tab {
  padding: 4px 12px;
  font: 600 .85rem/1 inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.aichart-toolbar .chart-tab:hover { color: var(--text); }
.aichart-toolbar .chart-tab.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.aichart-card { padding: 14px; }

#aiChart {
  position: relative;
  width: 100%;
  height: min(64vh, 600px);
  min-height: 380px;
}

#level-labels,
#signal-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
#level-labels { z-index: 5; }
#signal-labels { z-index: 6; }

.level-label {
  position: absolute;
  font: 600 10px/1 ui-monospace, SFMono-Regular, monospace;
  white-space: nowrap;
  transform: translate(-100%, -118%);
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .8);
}
html[data-theme="dark"] .level-label { background: rgba(24, 34, 56, .82); }

/* External-signal labels (TV-style label-up / label-down), placed by the rAF loop. */
.signal-label {
  position: absolute;
  font: 600 9px/1.18 ui-monospace, monospace;
  text-align: center;
  white-space: nowrap;
  padding: 2px 4px;
  border-radius: 3px;
  color: #fff;
}
.signal-label::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
}
/* LONG: green box BELOW the bar, pointer up. */
.signal-label.long { background: #26A69A; transform: translate(-50%, 9px); }
.signal-label.long::after { top: -9px; border-bottom-color: #26A69A; }
/* SHORT: red box ABOVE the bar, pointer down. */
.signal-label.short { background: #EF5350; transform: translate(-50%, calc(-100% - 9px)); }
.signal-label.short::after { bottom: -9px; border-top-color: #EF5350; }

.aichart-loading { display: none; color: var(--muted); font-size: .85rem; }
.aichart-loading.show { display: inline; }

.aichart-empty {
  color: var(--muted);
  padding: 40px 16px;
  text-align: center;
}

/* ----- Admin → Chart settings form ----- */
.chart-admin { max-width: 640px; }
.chart-admin .field { margin-bottom: 14px; }
.chart-admin select,
.chart-admin input[type="text"],
.chart-admin input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.chart-admin .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chart-admin .switch { display: flex; margin-bottom: 12px; }
.chart-admin .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.chart-admin .muted-status { font-size: .85rem; color: var(--muted); margin-top: 10px; min-height: 1.1em; }
.chart-admin hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
@media (max-width: 520px) { .chart-admin .row2 { grid-template-columns: 1fr; } }
