/* ========== Chart Analyzer ========== */
.chart-view {
  position: relative;
  width: 100vw;
  height: calc(100vh - 56px);
  max-width: none;
}

.chart-analyzer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 400px;
  background: #0B0C0F;
  border-radius: var(--radius-lg, 8px);
  overflow: hidden;
  border: 1px solid #1E2029;
}

/* Draggable Panel Upgrades for Chart Analyzer */
.draggable-panel.chart-analyzer {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(96vw, calc(100vw - 32px));
  height: calc(100vh - 56px - 32px);  /* viewport minus header minus margins */
  min-width: 600px;
  min-height: 400px;
  max-width: none;
  background: var(--bg-surface);
  box-shadow: var(--shadow-elevated);
  resize: both;
  overflow: hidden;
  z-index: 10;
  transition: box-shadow 0.2s;
  /* Add subtle bottom-right grabber indicator for resizing */
  background: linear-gradient(135deg, transparent 96%, rgba(255, 255, 255, 0.1) 96%, transparent 97%, rgba(255, 255, 255, 0.1) 98%) #0B0C0F;
}

.draggable-panel--dragging {
  box-shadow: var(--shadow-2xl), 0 0 0 1px var(--border-bright) inset;
}

/* Titlebar */
.chart-titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px;
  background: #0B0C0F;
  border-bottom: 1px solid #1E2029;
  height: 30px;
  flex-shrink: 0;
}

.chart-title-symbol {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 13px;
  font-weight: 600;
  color: #E6E8EE;
}

.chart-title-price {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 12px;
  color: #A7ACB8;
}
.chart-title-price--up   { color: #26a69a; }
.chart-title-price--down { color: #ef5350; }

.chart-title-bias {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}
.chart-title-bias--bull { color: #26a69a; background: rgba(38, 166, 154, 0.12); }
.chart-title-bias--bear { color: #ef5350; background: rgba(239, 83, 80, 0.12); }

.chart-title-r {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  margin-left: auto;
}
.chart-title-r--pos { color: #26a69a; background: rgba(38, 166, 154, 0.12); }
.chart-title-r--neg { color: #ef5350; background: rgba(239, 83, 80, 0.12); }

/* Confluence badge */
.chart-confluence {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  letter-spacing: 0.03em;
  cursor: help;
  margin-left: 8px;
}
.chart-confluence--aplus {
  color: #26a69a;
  background: rgba(38, 166, 154, 0.15);
  border: 1px solid rgba(38, 166, 154, 0.40);
}
.chart-confluence--a {
  color: #66BB6A;
  background: rgba(102, 187, 106, 0.12);
  border: 1px solid rgba(102, 187, 106, 0.35);
}
.chart-confluence--b {
  color: #FFA726;
  background: rgba(255, 167, 38, 0.12);
  border: 1px solid rgba(255, 167, 38, 0.35);
}
.chart-confluence--c {
  color: #9E9E9E;
  background: rgba(158, 158, 158, 0.10);
  border: 1px solid rgba(158, 158, 158, 0.25);
}

/* Status bar */
.chart-status {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  padding: 3px 14px;
  color: #545866;
  flex-shrink: 0;
}
.chart-status--loading { color: #A7ACB8; }
.chart-status--error   { color: #ef5350; }
.chart-status--empty   { color: #545866; }
.chart-status--ok      { color: #545866; }

/* Toolbar */
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: #0E0F13;
  border-bottom: 1px solid #1E2029;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.chart-toolbar__group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.chart-toolbar__group--right {
  margin-left: auto;
}

/* Guide "?" button */
.chart-pill--guide {
  background: rgba(255, 213, 79, 0.12);
  color: #FFD54F;
  border: 1px solid rgba(255, 213, 79, 0.30);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.chart-pill--guide:hover {
  background: rgba(255, 213, 79, 0.22);
  border-color: rgba(255, 213, 79, 0.50);
}

/* Pills (symbol, timeframe, overlay toggle) */
.chart-pill {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #545866;
  cursor: pointer;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}

.chart-pill:hover {
  color: #A7ACB8;
  background: rgba(255, 255, 255, 0.03);
}

.chart-pill:focus-visible {
  outline: 1px solid rgba(38, 198, 218, 0.6);
  outline-offset: 1px;
}

.chart-pill--active {
  color: #E6E8EE;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.chart-pill--overlay {
  font-size: 9px;
  padding: 2px 5px;
  position: relative;
}

/* Overlay pills: clear ON/OFF visual distinction */
.chart-pill--overlay:not(.chart-pill--active) {
  color: #3D4455;
  text-decoration: line-through;
  opacity: 0.6;
}

.chart-pill--overlay.chart-pill--active {
  color: #26c6da;
  border-color: rgba(38, 198, 218, 0.20);
}

.chart-pill__mode-dot {
  position: absolute;
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  display: none;
}

.chart-pill__mode-dot--green {
  display: block;
  background: #26a69a;
}

.chart-pill__mode-dot--amber {
  display: block;
  background: #ffb300;
}

/* Chart mount (main canvas area) */
.chart-mount {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Legend bar (OHLCV + overlay counts overlay) */
.chart-legend {
  position: absolute;
  top: 4px;
  left: 8px;
  z-index: 10;
  pointer-events: none;
  background: rgba(11, 12, 15, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
}

.chart-legend__row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-legend__ohlcv {
  font-size: 10px;
  color: #A7ACB8;
  margin-bottom: 1px;
}

.chart-legend__counts {
  font-size: 9px;
}

.chart-legend__label {
  color: #545866;
}

/* Loading skeleton */
.chart-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  background: #0E0F13;
}

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

.chart-skeleton__bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 60%;
  width: 70%;
}

.chart-skeleton__bar {
  flex: 1;
  background: #1E2029;
  border-radius: 2px 2px 0 0;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.chart-skeleton__bar:nth-child(even) {
  animation-delay: 0.3s;
}

.chart-skeleton__bar:nth-child(3n) {
  animation-delay: 0.6s;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

.chart-skeleton__label {
  margin-top: 12px;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  color: #545866;
}

/* Error card */
.chart-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  background: #1a1c22;
  border: 1px solid #2a2d38;
  border-radius: 6px;
  padding: 20px 28px;
  text-align: center;
}

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

.chart-error__icon {
  width: 28px;
  height: 28px;
  line-height: 28px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: rgba(239, 83, 80, 0.12);
  color: #ef5350;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 14px;
  font-weight: 700;
}

.chart-error__message {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  color: #A7ACB8;
  margin-bottom: 12px;
}

.chart-error__retry {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 10px;
  font-weight: 600;
  padding: 5px 16px;
  border: 1px solid rgba(38, 198, 218, 0.3);
  border-radius: 3px;
  background: rgba(38, 198, 218, 0.08);
  color: #26c6da;
  cursor: pointer;
  transition: background 0.12s;
}

.chart-error__retry:hover {
  background: rgba(38, 198, 218, 0.15);
}

/* ── SP5: Mobile + Touch Polish ─────────────────────────────────────────────── */

/* Overflow trigger — hidden by default, shown on small screens */
.chart-toolbar__overflow {
  display: none;
}

/* Responsive: medium (480-639px) — bigger touch targets */
@media (max-width: 639px) {
  .chart-pill {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .chart-pill--overlay { padding: 4px 6px; }
  .chart-toolbar { gap: 4px; padding: 4px 6px; }
  .chart-toolbar__group { gap: 1px; }
}

/* Responsive: small (<480px) — overlay pills move to bottom sheet */
@media (max-width: 479px) {
  .chart-toolbar__group--right { display: none; }
  .chart-toolbar__overflow { display: flex; }
}

/* Long-press visual feedback */
.chart-pill:active {
  transform: scale(0.95);
}

.chart-pill--longpress-flash {
  animation: pill-flash 300ms ease-out;
}

@keyframes pill-flash {
  0% { box-shadow: 0 0 0 0 rgba(38, 166, 154, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(38, 166, 154, 0.2); }
  100% { box-shadow: 0 0 0 0 rgba(38, 166, 154, 0); }
}

/* Orientation: landscape on mobile — single row toolbar, hide status */
@media (max-height: 480px) and (orientation: landscape) {
  .chart-toolbar { flex-wrap: nowrap; overflow-x: auto; }
  .chart-status { display: none; }
}

/* Bottom sheet for overlay toggles on narrow viewports */
.chart-bottomsheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.chart-bottomsheet--open {
  display: block;
}

.chart-bottomsheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.chart-bottomsheet__panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
  background: #0E0F13;
  border-top: 1px solid #1E2029;
  border-radius: 12px 12px 0 0;
  transform: translateY(100%);
  transition: transform 200ms ease-out;
  padding: 0 16px 20px;
}

.chart-bottomsheet--open .chart-bottomsheet__panel {
  transform: translateY(0);
}

.chart-bottomsheet__handle {
  width: 32px;
  height: 4px;
  background: #545866;
  border-radius: 2px;
  margin: 8px auto 12px;
}

.chart-bottomsheet__title {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  font-weight: 600;
  color: #A7ACB8;
  margin-bottom: 12px;
}

.chart-bottomsheet__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chart-bottomsheet__grid .chart-pill {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* Swipe indicator */
.chart-swipe-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 24px;
  font-weight: 700;
  color: #E6E8EE;
  background: rgba(11, 12, 15, 0.8);
  border-radius: 8px;
  padding: 8px 20px;
  pointer-events: none;
  animation: swipe-flash 600ms ease-out forwards;
}

@keyframes swipe-flash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
