/* chart-widget.css — Oyamori Chart Widget
 * Chrome uses var(--cw-*) tokens from chart-theme.css (with literal fallbacks so the
 * widget survives if the token layer loads late or is missing).
 * Candle / EMA / VWAP / S-R DATA colors stay literal (teal #26a69a, red #ef5350, amber). */
.cw-wrap {
  position: relative;
  background: var(--cw-surface, #111111);
  border: 1px solid var(--cw-border, #222222);
  border-radius: var(--cw-radius-card, 12px);
  overflow: hidden;
  font-family: var(--cw-font, 'Inter', system-ui, -apple-system, sans-serif);
  color: var(--cw-text, #f0f0f0);
  transition: border-color .15s, background .15s;
}
.cw-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cw-border, #222222);
  flex-wrap: wrap;
}
.cw-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cw-text, #f0f0f0);
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-sym  { font-family: var(--cw-mono, 'JetBrains Mono', monospace); font-weight: 600; color: var(--cw-text, #f0f0f0); }
.cw-price { font-family: var(--cw-doto, 'Doto', monospace); font-weight: 700; color: var(--cw-text, #f0f0f0); font-size: 14px; letter-spacing: .02em; }
.cw-chg  { font-family: var(--cw-mono, 'JetBrains Mono', monospace); font-size: 12px; font-weight: 500; }
.cw-tf-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--cw-surface, #111);
  border-bottom: 1px solid var(--cw-border, #222);
}
.cw-tf-btn {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222222);
  background: transparent;
  color: var(--cw-muted, #888888);
  cursor: pointer;
  font-family: var(--cw-mono, 'JetBrains Mono', monospace);
  transition: color .15s, background .15s, border-color .15s;
}
.cw-tf-btn:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }
.cw-tf-btn:focus-visible { outline: 2px solid var(--cw-brand, #D5477F); outline-offset: 1px; }
.cw-tf-btn.active { color: #fff; background: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }
.cw-status {
  display: inline-flex; align-items: center; gap: 4px; cursor: default;
  padding: 2px 7px; border-radius: 999px; line-height: 1;
  font-size: 9px; font-weight: 700; letter-spacing: .05em;
  color: var(--cw-subtle, #888); background: color-mix(in srgb, var(--cw-subtle, #888) 14%, transparent);
}
.cw-status.open    { color: #10b981; background: color-mix(in srgb, #10b981 15%, transparent); }
.cw-status.delayed { color: #f59e0b; background: color-mix(in srgb, #f59e0b 15%, transparent); }
.cw-status.closed  { color: var(--cw-subtle, #888); background: color-mix(in srgb, var(--cw-subtle, #888) 13%, transparent); }
.cw-status.err     { color: #ef5350; background: color-mix(in srgb, #ef5350 15%, transparent); }
.cw-status-txt { white-space: nowrap; }
.cw-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.cw-dot.live { background: #10b981; box-shadow: 0 0 5px #10b981; animation: cw-pulse 1.8s ease-in-out infinite; }
.cw-dot.err  { background: #ef5350; }
@keyframes cw-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.cw-chart { width: 100%; }
.cw-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: color-mix(in srgb, var(--cw-surface, #111111) 85%, transparent);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.cw-spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--cw-border, #222222);
  border-top-color: var(--cw-brand, #D5477F);
  border-radius: 50%;
  animation: cw-spin .7s linear infinite;
}
@keyframes cw-spin { to { transform: rotate(360deg); } }
.cw-loading-msg { font-size: 11px; color: var(--cw-muted, #888888); }

/* ── Date range bar ──────────────────────────────────────────────────────── */
.cw-date-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-bottom: 1px solid var(--cw-border, #222222);
  background: var(--cw-bg, #0a0a0a);
  flex-wrap: wrap;
}
.cw-date-label {
  font-size: 10px;
  color: var(--cw-subtle, #444444);
  white-space: nowrap;
}
.cw-date-input {
  font-size: 11px;
  font-family: var(--cw-mono, monospace);
  padding: 2px 7px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222222);
  background: transparent;
  color: var(--cw-text, #e2e8f0);
  cursor: pointer;
  color-scheme: dark;
  outline: none;
  transition: border-color .15s;
}
.cw-date-input:focus { border-color: var(--cw-brand, #D5477F); }
.cw-date-btn {
  font-size: 10px;
  padding: 2px 10px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-brand, #D5477F);
  background: transparent;
  color: var(--cw-brand, #D5477F);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.cw-date-btn:hover { background: var(--cw-brand, #D5477F); color: #fff; }
.cw-date-clear {
  border-color: var(--cw-border, #222222);
  color: var(--cw-muted, #888888);
}
.cw-date-clear:hover { background: transparent; color: var(--cw-text, #e2e8f0); border-color: var(--cw-muted, #888888); }
.cw-date-pill {
  font-size: 10px; font-weight: 600; letter-spacing: .04em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--cw-brand, #D5477F) 50%, transparent);
  background: color-mix(in srgb, var(--cw-brand, #D5477F) 14%, transparent);
  color: var(--cw-brand, #D5477F);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.cw-date-pill:hover { background: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); color: #fff; }
.cw-date-hint {
  font-size: 10px;
  color: var(--cw-subtle, #444444);
  font-family: var(--cw-mono, monospace);
  margin-left: 4px;
}

/* ── Sub-panel switcher bar ──────────────────────────────────────────────── */
.cw-sp-bar {
  display: none;
}
.cw-sp-label { font-size: 10px; color: var(--cw-subtle, #444444); margin-right: 2px; white-space: nowrap; }
.cw-sp-btn {
  font-size: 10px;
  padding: 2px 9px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222222);
  background: transparent;
  color: var(--cw-muted, #888888);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
}
.cw-sp-btn:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }
.cw-sp-btn:focus-visible { outline: 2px solid var(--cw-brand, #D5477F); outline-offset: 1px; }
.cw-sp-btn.active { color: #fff; background: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }

/* ── Shared icon button (patterns 🕯, AI 🤖, expand ⛶) ──────────────────── */
.cw-pat-chip, .cw-ai-chip, .cw-expand-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 5px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222);
  background: transparent;
  color: var(--cw-muted, #888);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  font-size: 13px; line-height: 1;
  transition: color .15s, border-color .15s, background .15s;
}
.cw-pat-chip:hover, .cw-ai-chip:hover, .cw-expand-btn:hover {
  color: var(--cw-text, #f0f0f0); border-color: var(--cw-muted, #888);
}
.cw-pat-chip.on {
  color: var(--cw-brand, #D5477F);
  border-color: color-mix(in srgb, var(--cw-brand, #D5477F) 60%, transparent);
  background: color-mix(in srgb, var(--cw-brand, #D5477F) 12%, transparent);
}

/* ── Candlestick pattern bar ───────────────────────────────────────────────── */
.cw-pat-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;       /* collapsed = single row, no wrap */
  padding: 4px 14px;
  border-bottom: 1px solid var(--cw-border, #222222);
  background: var(--cw-bg, #0a0a0a);
  overflow: hidden;
}
.cw-pat-bar.expanded { flex-wrap: wrap; }

/* Collapse/expand toggle button */
.cw-pat-toggle {
  font-family: var(--cw-mono, monospace);
  font-size: 10px; padding: 2px 6px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222);
  background: transparent;
  color: var(--cw-muted, #888); cursor: pointer; white-space: nowrap;
  transition: color .15s, border-color .15s;
  flex-shrink: 0;
}
.cw-pat-toggle:hover { color: var(--cw-text, #f0f0f0); border-color: var(--cw-muted, #888); }
.cw-pat-count {
  font-family: var(--cw-mono, monospace);
  color: var(--cw-brand, #D5477F); margin: 0 2px;
}
.cw-pat-chev { font-size: 9px; color: var(--cw-brand, #D5477F); }
.cw-chev-flip { display: inline-block; transform: rotate(180deg); }
.cw-pat-header {
  display: flex; align-items: center; gap: 5px;
  width: 100%; flex-shrink: 0;
}
.cw-pat-collapse-end {
  margin-left: auto; flex-shrink: 0;
  font-size: 13px; line-height: 1; padding: 2px 6px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222);
  background: transparent; color: var(--cw-muted, #888);
  cursor: pointer; transition: color .15s, border-color .15s;
}
.cw-pat-collapse-end:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }

.cw-pat-pill {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--pc, var(--cw-border));
  color: var(--pc, var(--cw-muted));
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s, background .15s;
}
.cw-pat-pill:hover { background: color-mix(in srgb, var(--pc, #888) 15%, transparent); }
.cw-pat-pill.off { opacity: .35; }
.cw-pat-pill .cnt { color: var(--cw-muted, #888); font-family: var(--cw-mono, monospace); }
.cw-pat-ctl {
  font-size: 10px; padding: 2px 8px; border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222); background: transparent;
  color: var(--cw-muted, #888); cursor: pointer; white-space: nowrap;
}
.cw-pat-ctl:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }
/* ── Pattern scorecard (§E) ─────────────────────────────────────────────── */
.cw-pat-scorecard {
  width: 100%; margin: 4px 0 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--cw-border, #1e1e1e);
  border-radius: var(--cw-radius-btn, 6px);
  display: flex; flex-direction: column; gap: 5px;
}
.cw-pat-sc-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--cw-muted, #888);
}
.cw-pat-sc-lbl {
  font-size: 8px; color: #374151; letter-spacing: 0.06em;
  min-width: 28px; flex-shrink: 0;
}
.cw-pat-sc-bar {
  display: flex; height: 5px; border-radius: 3px; overflow: hidden;
  width: 100px; flex-shrink: 0; background: #111;
}
.cw-pat-sc-bar .b { background: #26a69a; }
.cw-pat-sc-bar .n { background: #374151; }
.cw-pat-sc-bar .r { background: #ef5350; }
.cw-pat-sc-counts { font-family: var(--cw-mono, monospace); font-size: 9px; }
.cw-pat-sc-spark  { font-size: 11px; letter-spacing: 2px; line-height: 1; }

.cw-pat-qchip {
  font-size: 9px; padding: 1px 6px; border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #333); background: transparent;
  color: var(--cw-muted, #666); cursor: pointer; white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.cw-pat-qchip.on {
  color: #facc15; border-color: #854d0e; background: rgba(250,204,21,0.08);
}
.cw-pat-qchip:hover { color: #fde047; border-color: #a16207; }

/* ── Gear button ─────────────────────────────────────────────────────────── */
.cw-gear-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; min-width: 28px; padding: 0 7px;
  background: transparent;
  border: 1px solid var(--cw-border, #222222);
  border-radius: var(--cw-radius-btn, 6px);
  color: var(--cw-muted, #888888);
  cursor: pointer; font-size: 14px; line-height: 1;
  transition: color .15s, background .15s, border-color .15s;
  flex-shrink: 0;
}
.cw-gear-btn:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); background: color-mix(in srgb, var(--cw-brand, #D5477F) 12%, transparent); }
.cw-gear-btn:focus-visible { outline: 2px solid var(--cw-brand, #D5477F); outline-offset: 1px; }

/* Feed status badge styles live in feed-status.css — loaded alongside this file. */

/* ── Modal backdrop ──────────────────────────────────────────────────────── */
.cw-modal-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 60;          /* above AI panel (z-index 50) — settings always on top */
  align-items: center;
  justify-content: center;
  border-radius: var(--cw-radius-card, 12px);
}
.cw-modal-backdrop.open { display: flex; }

/* ── Modal box ───────────────────────────────────────────────────────────── */
.cw-modal {
  background: var(--cw-surface, #111111);
  border: 1px solid var(--cw-border, #222222);
  border-radius: var(--cw-radius-card, 12px);
  min-width: 240px;
  max-width: 300px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  overflow: hidden;
}
.cw-modal-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--cw-border, #222222);
  gap: 8px;
}
.cw-modal-head h3 { font-size: 13px; font-weight: 600; color: var(--cw-text, #f0f0f0); flex: 1; margin: 0; }
.cw-modal-body { padding: 4px 0; }
.cw-modal-section { border-bottom: 1px solid var(--cw-border, #222222); padding: 6px 0 8px; }
.cw-modal-section:last-of-type { border-bottom: none; }
.cw-section-label { font-size: 10px; color: var(--cw-subtle, #444444); text-transform: uppercase; letter-spacing: .07em; padding: 6px 16px 4px; }
.cw-data-grid { padding: 2px 0 4px; }
.cw-data-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 16px; gap: 12px; }
.cw-data-key { font-size: 12px; color: var(--cw-muted, #888888); white-space: nowrap; }
.cw-data-val { font-size: 11px; color: var(--cw-brand, #D5477F); font-family: var(--cw-mono, 'JetBrains Mono', monospace); text-align: right; }
.cw-data-val.ok    { color: #10b981; }
.cw-data-val.warn  { color: #f59e0b; }
.cw-data-val.muted { color: var(--cw-subtle, #888); }
.cw-data-val em { font-style: normal; opacity: .8; }
.cw-modal-foot {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--cw-border, #222222);
}

/* ── Toggle rows ─────────────────────────────────────────────────────────── */
.cw-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .1s;
}
.cw-toggle-row:hover { background: color-mix(in srgb, var(--cw-brand, #D5477F) 8%, transparent); }
.cw-toggle-label { font-size: 12px; color: var(--cw-text, #f0f0f0); flex: 1; }

/* pill toggle */
.cw-toggle-row input[type=checkbox] { display: none; }
.cw-pill {
  width: 34px; height: 18px;
  background: var(--cw-border, #222222);
  border-radius: 9px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.cw-pill::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--cw-subtle, #444444);
  transition: transform .2s, background .2s;
}
.cw-toggle-row input:checked ~ .cw-pill { background: color-mix(in srgb, var(--cw-brand, #D5477F) 30%, transparent); }
.cw-toggle-row input:checked ~ .cw-pill::after { background: var(--cw-brand, #D5477F); transform: translateX(16px); }

/* modal buttons */
.cw-modal-btn {
  flex: 1;
  padding: 6px 0;
  border-radius: var(--cw-radius-btn, 6px);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--cw-border, #222222);
  background: transparent;
  color: var(--cw-muted, #888888);
  transition: color .15s, background .15s, border-color .15s;
}
.cw-modal-btn:hover { color: var(--cw-text, #f0f0f0); border-color: var(--cw-subtle, #444444); }
.cw-modal-btn:focus-visible { outline: 2px solid var(--cw-brand, #D5477F); outline-offset: 1px; }
.cw-modal-btn.primary { color: #fff; border-color: var(--cw-brand, #D5477F); background: var(--cw-brand, #D5477F); }
.cw-modal-btn.primary:hover { background: color-mix(in srgb, var(--cw-brand, #D5477F) 88%, #000); }

/* ── AI Chip states (base style shared with .cw-pat-chip above) ──────────── */
.cw-ai-chip.loading { opacity: .6; cursor: wait; animation: cw-spin .9s linear infinite; }
.cw-ai-chip.error   { color: #ef5350; border-color: color-mix(in srgb,#ef5350 50%,transparent); }
.cw-ai-chip.on      { font-family: var(--cw-mono, monospace); font-size: 11px; border-color: color-mix(in srgb, currentColor 50%, transparent); }
.cw-ai-chip.ai-badge-buy   { color: #10b981; background: color-mix(in srgb,#10b981 12%,transparent); }
.cw-ai-chip.ai-badge-sell  { color: #ef4444; background: color-mix(in srgb,#ef4444 12%,transparent); }
.cw-ai-chip.ai-badge-hold  { color: #f59e0b; background: color-mix(in srgb,#f59e0b 12%,transparent); }
.cw-ai-chip.ai-badge-watch { color: #3b82f6; background: color-mix(in srgb,#3b82f6 12%,transparent); }

/* ── AI Panel (slide-up overlay inside .cw-wrap) ────────────────────────── */
.cw-airead-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  max-height: 55%; min-height: 180px;
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--cw-surface, #111) 97%, transparent);
  border-top: 1px solid var(--cw-border, #222);
  z-index: 50;
  animation: aiPanelUp .18s ease-out;
}
@keyframes aiPanelUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.ai-panel-inner { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.ai-panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-bottom: 1px solid var(--cw-border, #222);
  flex-shrink: 0;
}
.ai-panel-title {
  font-family: var(--cw-mono, monospace); font-size: 11px;
  font-weight: 600; color: var(--cw-text, #f0f0f0); flex: 1;
}
.ai-cache-note { font-size: 10px; color: var(--cw-subtle, #444); white-space: nowrap; }
.ai-panel-close, .ai-undock-btn {
  width: 24px; height: 24px; border-radius: 4px;
  border: 1px solid var(--cw-border, #222); background: transparent;
  color: var(--cw-muted, #888); cursor: pointer; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s; flex-shrink: 0;
}
.ai-panel-close { font-size: 16px; }
.ai-panel-close:hover, .ai-undock-btn:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }

/* ── Undocked panel — flows below the chart, inside the same cell ────────── */
/* The wrap becomes a flex column so the (now relative) panel stacks below the
   chart canvas. The cell grows in height but keeps its grid column + width. */
.cw-wrap-undocked {
  display: flex;
  flex-direction: column;
}
.cw-airead-panel.undocked {
  position: relative;
  bottom: auto; left: auto; right: auto;
  max-height: none; min-height: 0;
  width: 100%;
  border-top: 2px solid var(--cw-brand, #D5477F);
  animation: none;
}
.ai-panel-body { flex: 1; overflow-y: auto; padding: 10px 14px 8px; }
/* ── Strategy selector bar ───────────────────────────────────────────────── */
.ai-strat-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 14px; border-bottom: 1px solid var(--cw-border, #222);
  background: color-mix(in srgb, var(--cw-surface, #111) 80%, transparent);
  flex-shrink: 0;
}
.ai-strat-label {
  font-size: 10px; color: var(--cw-subtle, #444);
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; margin-right: 2px;
}
.ai-strat-chip {
  font-family: var(--cw-mono, monospace); font-size: 10px;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--cw-border, #222);
  background: transparent; color: var(--cw-muted, #888);
  cursor: pointer; white-space: nowrap;
  transition: color .12s, border-color .12s, background .12s;
}
.ai-strat-chip:hover { color: var(--cw-text, #f0f0f0); border-color: var(--cw-muted, #888); }
.ai-strat-chip.active {
  color: var(--cw-brand, #D5477F);
  border-color: color-mix(in srgb, var(--cw-brand, #D5477F) 60%, transparent);
  background: color-mix(in srgb, var(--cw-brand, #D5477F) 12%, transparent);
}
.ai-strat-chip.suggested:not(.active) {
  border-style: dashed; color: var(--cw-subtle, #555);
}
.ai-analyze-btn {
  margin-left: auto; font-family: var(--cw-mono, monospace); font-size: 10px;
  padding: 3px 10px; border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-brand, #D5477F);
  background: color-mix(in srgb, var(--cw-brand, #D5477F) 14%, transparent);
  color: var(--cw-brand, #D5477F); cursor: pointer; white-space: nowrap;
  transition: background .12s;
}
.ai-analyze-btn:hover { background: color-mix(in srgb, var(--cw-brand, #D5477F) 28%, transparent); }

/* ── Panel body states ───────────────────────────────────────────────────── */
.ai-loading-state, .ai-empty-state, .ai-error-state {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 24px 14px; font-size: 11px; color: var(--cw-muted, #888);
}
.ai-error-state { color: #ef5350; }
.ai-spinner {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--cw-border, #222);
  border-top-color: var(--cw-brand, #D5477F);
  animation: cw-spin .7s linear infinite;
}

.ai-summary {
  font-size: 11px; color: var(--cw-muted, #888); margin-bottom: 8px; line-height: 1.5;
}

/* ── Consensus banner ────────────────────────────────────────────────────── */
.ai-consensus {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 6px 10px; margin-bottom: 10px; border-radius: 6px;
  border: 1px solid var(--cw-border, #222);
  font-family: var(--cw-mono, monospace);
}
.ai-consensus.ai-buy   { background: color-mix(in srgb,#10b981 14%,transparent); border-color: color-mix(in srgb,#10b981 45%,transparent); }
.ai-consensus.ai-sell  { background: color-mix(in srgb,#ef4444 14%,transparent); border-color: color-mix(in srgb,#ef4444 45%,transparent); }
.ai-consensus.ai-hold  { background: color-mix(in srgb,#f59e0b 14%,transparent); border-color: color-mix(in srgb,#f59e0b 45%,transparent); }
.ai-consensus.ai-watch { background: color-mix(in srgb,#3b82f6 14%,transparent); border-color: color-mix(in srgb,#3b82f6 45%,transparent); }
.ai-consensus-verdict { font-size: 12px; font-weight: 700; }
.ai-consensus.ai-buy   .ai-consensus-verdict { color: #10b981; }
.ai-consensus.ai-sell  .ai-consensus-verdict { color: #ef4444; }
.ai-consensus.ai-hold  .ai-consensus-verdict { color: #f59e0b; }
.ai-consensus.ai-watch .ai-consensus-verdict { color: #3b82f6; }
.ai-consensus-detail { font-size: 10px; color: var(--cw-muted, #888); }

/* ── Entry type tag ──────────────────────────────────────────────────────── */
.ai-entry-tag {
  font-size: 8px; text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 5px; border-radius: 3px; margin-left: 4px; font-weight: 600;
}
.ai-entry-tag.market { background: color-mix(in srgb,#10b981 20%,transparent); color: #10b981; }
.ai-entry-tag.limit  { background: color-mix(in srgb,#f59e0b 20%,transparent); color: #f59e0b; }

/* Strategy cards */
.ai-cards { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.ai-card {
  flex: 1 1 180px; min-width: 160px;
  border: 1px solid var(--cw-border, #222); border-radius: 8px; overflow: hidden;
}
.ai-card-head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; font-size: 11px; font-weight: 600;
}
.ai-card-head.ai-buy   { background: color-mix(in srgb,#10b981 16%,transparent); color: #10b981; }
.ai-card-head.ai-sell  { background: color-mix(in srgb,#ef4444 16%,transparent); color: #ef4444; }
.ai-card-head.ai-hold  { background: color-mix(in srgb,#f59e0b 16%,transparent); color: #f59e0b; }
.ai-card-head.ai-watch { background: color-mix(in srgb,#3b82f6 16%,transparent); color: #3b82f6; }
.ai-card-label { flex: 1; }
.ai-card-conf  { font-family: var(--cw-mono, monospace); font-size: 10px; opacity: .8; }
.ai-card-body  { padding: 8px 10px; }
.ai-row {
  display: flex; justify-content: space-between;
  font-size: 10px; padding: 2px 0; color: var(--cw-muted, #888);
  border-bottom: 1px solid var(--cw-border, #222);
}
.ai-row:last-of-type { border-bottom: none; }
.ai-row span:last-child { font-family: var(--cw-mono, monospace); color: var(--cw-text, #f0f0f0); }
.ai-reason { font-size: 10px; color: var(--cw-muted, #888); margin-top: 6px; line-height: 1.5; }

/* Footer */
.ai-footer {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px solid var(--cw-border, #222);
  font-size: 10px;
}
.ai-levels { flex: 1; color: var(--cw-subtle, #444); font-family: var(--cw-mono, monospace); }
.ai-risk { padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 10px; }
.ai-tf-warn {
  padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 10px;
  background: color-mix(in srgb,#ef5350 18%,transparent); color: #ef5350;
  border: 1px solid color-mix(in srgb,#ef5350 50%,transparent);
}
.ai-risk-low    { background: color-mix(in srgb,#10b981 15%,transparent); color: #10b981; }
.ai-risk-medium { background: color-mix(in srgb,#f59e0b 15%,transparent); color: #f59e0b; }
.ai-risk-high   { background: color-mix(in srgb,#ef4444 15%,transparent); color: #ef4444; }
.ai-reanalyze {
  font-family: var(--cw-mono, monospace); font-size: 10px;
  padding: 2px 8px; border-radius: 4px;
  border: 1px solid var(--cw-border, #222); background: transparent;
  color: var(--cw-muted, #888); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.ai-reanalyze:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }

/* ── Annotation Bar (bottom of widget, collapsible) ───────────────────────── */
.cw-ann-bar {
  border-top: 1px solid var(--cw-border, #222222);
  background: var(--cw-bg, #0a0a0a);
}
.cw-ann-expanded {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  flex-wrap: wrap;
}
.cw-ann-bar.collapsed .cw-ann-expanded { display: none; }
.cw-ann-collapsed-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
}
.cw-ann-bar.collapsed .cw-ann-collapsed-row { display: flex; }
.cw-ann-chips { display: flex; flex-wrap: wrap; gap: 5px; flex: 1; }
.cw-ann-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--cw-border, #2a3040);
  background: transparent;
  color: var(--cw-muted, #888);
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap; font-family: var(--cw-font, inherit);
}
.cw-ann-chip:hover { color: var(--cw-text, #f0f0f0); border-color: var(--cw-muted, #888); }
.cw-ann-chip.on {
  background: color-mix(in srgb, var(--cw-brand, #D5477F) 15%, transparent);
  color: var(--cw-brand, #D5477F);
  border-color: var(--cw-brand, #D5477F);
}
.cw-ann-group {
  display: flex;
}
.cw-ann-group .cw-ann-chip:first-child {
  border-radius: 999px 0 0 999px;
  border-right: none;
}
.cw-ann-sub {
  padding: 3px 8px;
  border-radius: 0 999px 999px 0;
  border-left: 1px solid var(--cw-border, #2a3040);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
}
.cw-ann-tog {
  flex-shrink: 0; margin-left: auto;
  font-size: 13px; line-height: 1; padding: 2px 6px;
  border-radius: var(--cw-radius-btn, 6px);
  border: 1px solid var(--cw-border, #222);
  background: transparent; color: var(--cw-muted, #888);
  cursor: pointer; transition: color .15s, border-color .15s;
}
.cw-ann-tog:hover { color: var(--cw-brand, #D5477F); border-color: var(--cw-brand, #D5477F); }
.cw-ann-csum { font-size: 11px; color: var(--cw-muted, #888); }
.cw-ann-count { color: var(--cw-text, #f0f0f0); font-weight: 600; }

/* ── AI chip teal variant ── */
.cw-ann-chip.teal { background: rgba(38,166,154,.12); color: #26a69a; border-color: rgba(38,166,154,.4); }

/* ── AI Read toolbar button ── */
.cw-airead-btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 28px; padding: 0 9px;
  background: rgba(213,71,127,.1); border: 1px solid rgba(213,71,127,.4);
  color: var(--cw-brand, #D5477F); border-radius: var(--cw-radius-btn, 6px);
  font-size: 11px; font-weight: 600; font-family: inherit;
  cursor: pointer; flex-shrink: 0; white-space: nowrap;
  transition: background .15s;
}
.cw-airead-btn:hover, .cw-airead-btn.active { background: rgba(213,71,127,.22); }

/* ── Chart row — chart fills full width; panel overlays right edge ── */
.cw-chart-row { position: relative; }

/* ── AI Strip ── */
.cw-airead-strip {
  display: flex; align-items: center; gap: 8px;
  background: #080c17; border-bottom: 1px solid #14203a;
  padding: 5px 12px; font-family: monospace; min-height: 26px; overflow: hidden;
}
.cw-airead-badge {
  background: rgba(213,71,127,.15); color: var(--cw-brand, #D5477F);
  border: 1px solid rgba(213,71,127,.3); border-radius: 3px;
  padding: 1px 6px; font-size: 9px; letter-spacing: .06em; white-space: nowrap; flex-shrink: 0;
}
.cw-airead-ticker {
  flex: 1; overflow: hidden; white-space: nowrap;
  mask-image: linear-gradient(to right, transparent, black 20px, black calc(100% - 20px), transparent);
}
.cw-airead-text { display: inline-block; font-size: 10px; color: #8090aa; }
.cw-airead-meta { font-size: 9px; color: #334; white-space: nowrap; flex-shrink: 0; }

/* ── AI Panel — absolute overlay on right side of chart ── */
.cw-airead-panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 5;
  width: 270px;
  background: rgba(9,13,24,.95); border-left: 1px solid #14203a;
  display: flex; flex-direction: column; font-family: monospace;
  overflow-y: auto;
}
.cw-aip-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; background: #0d1525; border-bottom: 1px solid #14203a;
  flex-shrink: 0;
}
.cw-aip-title { color: var(--cw-brand,#D5477F); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.cw-aip-meta  { font-size: 8px; color: #445; font-weight: 400; letter-spacing: 0; text-transform: none; margin-left: 4px; }
.cw-aip-acts  { display: flex; gap: 5px; }
.cw-aip-close, .cw-aip-refresh, .cw-aip-live {
  background: none; border: none; color: #334; cursor: pointer; font-size: 12px; line-height: 1; padding: 2px 3px;
}
.cw-aip-close:hover { color: #888; }
.cw-aip-refresh:hover { color: var(--cw-brand,#D5477F); }
.cw-aip-live { color: #3b82f6; font-size: 9px; letter-spacing: .04em; }
.cw-aip-live:hover { color: #60a5fa; }
/* F3 — replay badge */
.cw-aip-replay-badge {
  font-size: 8px; letter-spacing: .06em; text-transform: uppercase;
  color: #f59e0b; background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3);
  border-radius: 3px; padding: 1px 5px; margin-right: 4px; white-space: nowrap;
}

.cw-aip-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }

/* Loading */
.cw-aip-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 40px 20px; color: #334; flex: 1;
}
.cw-aip-spin {
  width: 20px; height: 20px; border: 2px solid #14203a; border-top-color: var(--cw-brand,#D5477F);
  border-radius: 50%; animation: cw-spin .8s linear infinite;
}
@keyframes cw-spin { to { transform: rotate(360deg); } }
.cw-aip-load-msg { font-size: 10px; color: #445; text-align: center; line-height: 1.7; }

/* Section */
.cw-aip-section { display: flex; flex-direction: column; gap: 5px; }
.cw-aip-sec-title {
  font-size: 8px; color: #445; letter-spacing: .1em; text-transform: uppercase;
  display: flex; align-items: center; gap: 5px;
}
.cw-aip-sec-title::after { content: ''; flex: 1; height: 1px; background: #14203a; }

/* Situation */
.cw-aip-sit-summary { font-size: 10px; color: #7a8499; line-height: 1.5; margin-bottom: 3px; }
.cw-aip-rows { display: flex; flex-direction: column; gap: 3px; }
.cw-aip-row  { display: flex; justify-content: space-between; align-items: flex-start; gap: 4px; }
.cw-aip-key  { font-size: 9px; color: #445; text-transform: uppercase; letter-spacing: .07em; flex-shrink: 0; }
.cw-aip-val  { font-size: 10px; color: #7a8499; text-align: right; line-height: 1.4; }
.cw-aip-val.bull { color: #26a69a; }
.cw-aip-val.bear { color: #ef5350; }
.cw-aip-val.warn { color: #f59e0b; }
.cw-aip-val.neu  { color: #f59e0b; }

/* Setups */
.cw-aip-setup {
  border-radius: 4px; padding: 6px 8px; margin-bottom: 4px;
  border-left: 3px solid;
}
.cw-aip-setup.primary   { border-color: #26a69a; background: rgba(38,166,154,.06); }
.cw-aip-setup.secondary { border-color: #f59e0b; background: rgba(245,158,11,.05); }
.cw-aip-setup.tail      { border-color: #4a5568; background: rgba(74,85,104,.05); }
.cw-aip-setup-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cw-aip-setup-name { font-size: 10px; font-weight: 700; }
.cw-aip-setup-name.bull { color: #26a69a; }
.cw-aip-setup-name.bear { color: #ef5350; }
.cw-aip-setup-name.neu  { color: #f59e0b; }
.cw-aip-prob { display: flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 700; }
.cw-aip-prob.bull { color: #26a69a; }
.cw-aip-prob.bear { color: #ef5350; }
.cw-aip-prob.neu  { color: #4a5568; }
.cw-aip-prob-bar  { display: inline-block; width: 32px; height: 3px; background: #14203a; border-radius: 2px; vertical-align: middle; }
.cw-aip-prob-fill { display: block; height: 3px; border-radius: 2px; }
.cw-aip-prob-fill.bull { background: #26a69a; }
.cw-aip-prob-fill.bear { background: #ef5350; }
.cw-aip-prob-fill.neu  { background: #4a5568; }
.cw-aip-trigger { font-size: 9px; color: #556; margin-bottom: 4px; line-height: 1.4; }
.cw-aip-trigger b { color: #7a8499; }
.cw-aip-outcomes { display: flex; gap: 5px; }
.cw-aip-out { flex: 1; background: #0a0d14; border-radius: 3px; padding: 3px 5px; }
.cw-aip-out-lbl { font-size: 8px; color: #445; display: block; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 1px; }
.cw-aip-out-val { font-size: 9px; color: #7a8499; font-weight: 600; }
.cw-aip-out-val.bull { color: #26a69a; }
.cw-aip-out-val.bear { color: #ef5350; }

/* Next bar */
.cw-aip-nb { background: #0d1525; border: 1px solid #14203a; border-radius: 5px; padding: 7px 8px; }
.cw-aip-nb-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.cw-aip-nb-bias { font-size: 11px; font-weight: 700; }
.cw-aip-nb-bias.bull { color: #26a69a; }
.cw-aip-nb-bias.bear { color: #ef5350; }
.cw-aip-nb-bias.neu  { color: #f59e0b; }
.cw-aip-nb-conf { font-size: 9px; color: #556; }
.cw-aip-nb-range { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
.cw-aip-nb-range .bull { font-size: 10px; font-weight: 600; color: #26a69a; }
.cw-aip-nb-range .bear { font-size: 10px; font-weight: 600; color: #ef5350; }
.cw-aip-nb-track { flex: 1; height: 5px; background: #14203a; border-radius: 3px; position: relative; overflow: hidden; }
.cw-aip-nb-fill  { position: absolute; top:0; left:20%; right:15%; height: 5px; background: linear-gradient(to right,rgba(38,166,154,.4),#26a69a); border-radius: 3px; }
.cw-aip-nb-watch { font-size: 9px; color: #556; line-height: 1.4; }
.cw-aip-nb-watch b { color: #7a8499; }

/* Quality */
/* Candle Read section */
.cw-aip-candle { background: rgba(90,60,20,.12); border: 1px solid rgba(245,158,11,.18); border-radius: 4px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.cw-aip-candle-bar { display: flex; align-items: center; gap: 6px; }
.cw-aip-candle-name { font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.cw-aip-candle-sig  { font-size: 8px; text-transform: uppercase; letter-spacing: .09em; opacity: .7; padding: 1px 4px; border-radius: 2px; background: rgba(255,255,255,.05); }
.cw-aip-candle-meaning { font-size: 9px; color: #8090aa; line-height: 1.5; }
.cw-aip-candle-form    { font-size: 9px; color: #f59e0b; opacity: .85; }
.cw-aip-candle-impl    { font-size: 9px; color: #7a8499; font-style: italic; line-height: 1.4; border-top: 1px solid rgba(255,255,255,.05); padding-top: 3px; }

.cw-aip-quality { display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: #0d1525; border-radius: 4px; border: 1px solid #14203a; }
.cw-aip-q-dots  { font-size: 10px; color: #26a69a; letter-spacing: 2px; }
.cw-aip-q-txt   { font-size: 9px; color: #445; margin-left: auto; }
