/**
 * CoinAcademy Chart Module — Styles
 * Inspired by CoinGecko's chart layout, adapted to CoinAcademy's design system
 * BEM naming: .ca-chart, .ca-chart__element, .ca-chart__element--modifier
 *
 * CoinAcademy palette:
 *   Accent: #14CC9E (teal green — CTA, active states)
 *   Light: body #ffffff, text #000000
 *   Dark:  body #1c1c1c, text #ffffff, header #000000
 *   Up: #16c784, Down: #ea3943
 *
 * @version 2.2.0
 * @since 2026-02-24
 */

/* ── Reset WP Newsblock theme button overrides ── */
.ca-chart button,
.ca-chart button:hover,
.ca-chart button:focus,
.ca-chart button:active {
  background-color: transparent !important;
  box-shadow: none !important;
}

/* ── Container ── */
.ca-chart {
  position: relative;
  width: 100%;
  min-height: 480px;
  margin-bottom: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ── Toolbar ── */
.ca-chart__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 0 10px 0;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 4px;
}

.ca-chart__toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ca-chart__toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* ── Metric tabs (Prix / Market Cap) — CoinGecko-style text tabs ── */
.ca-chart__metric-group {
  display: flex;
  align-items: center;
  gap: 0;
}

.ca-chart__metric-btn {
  padding: 6px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #6b7280;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.ca-chart__metric-btn:hover {
  color: #111827;
  background-color: transparent !important;
}

.ca-chart__metric-btn--active {
  color: #111827;
  font-weight: 600;
  border-bottom-color: #14CC9E;
  background-color: transparent !important;
}

/* ── Chart type icons (Area / Candlestick) ── */
.ca-chart__type-group {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}

.ca-chart .ca-chart__type-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0 !important;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ca-chart .ca-chart__type-btn:hover {
  color: #374151;
  border-color: #d1d5db;
}

.ca-chart .ca-chart__type-btn--active {
  color: #111827;
  background: #f3f4f6;
  border-color: #d1d5db;
}

.ca-chart__type-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Separator ── */
.ca-chart__separator {
  width: 1px;
  height: 20px;
  background: #e5e7eb;
  margin: 0 4px;
}

/* ── Currency toggle ── */
.ca-chart__currency-group {
  display: flex;
  align-items: center;
  gap: 0;
  background: #f5f5f5;
  border-radius: 6px;
  padding: 2px;
}

.ca-chart__currency-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ca-chart__currency-btn--active {
  background: #ffffff;
  color: #111827;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ── Period buttons — CoinGecko-style clean text buttons ── */
.ca-chart__period-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ca-chart__period-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ca-chart__period-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

.ca-chart__period-btn--active {
  background: rgba(20, 204, 158, 0.1);
  color: #14CC9E;
}

/* ── Chart wrapper ── */
.ca-chart__wrapper {
  position: relative;
  width: 100%;
}

/* Fix Lightweight Charts default table styling conflict with WP themes */
.ca-chart__wrapper table {
  border-collapse: collapse;
  border: none;
  margin: 0;
  padding: 0;
}

.ca-chart__wrapper td {
  border: none;
  padding: 0;
}

/* Hide Lightweight Charts TradingView watermark */
.ca-chart__wrapper a[href*="tradingview"],
.ca-chart__wrapper div[style*="position: absolute"] a,
.ca-chart__wrapper div[style*="position: absolute"] svg,
.ca-chart__navigator-chart a[href*="tradingview"],
.ca-chart__navigator-chart div[style*="position: absolute"] a {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

/* ── Loading overlay ── */
.ca-chart__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  z-index: 10;
  border-radius: 8px;
  transition: opacity 0.2s ease;
}

.ca-chart__loading--hidden {
  opacity: 0;
  pointer-events: none;
}

.ca-chart__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: #14CC9E;
  border-radius: 50%;
  animation: ca-chart-spin 0.8s linear infinite;
}

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

/* ── Error state ── */
.ca-chart__error {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
  min-height: 420px;
}

.ca-chart__error--visible {
  display: flex;
}

.ca-chart__error-text {
  color: #6b7280;
  font-size: 14px;
}

.ca-chart__error-retry {
  padding: 8px 20px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ca-chart__error-retry:hover {
  background: #f9fafb;
  border-color: #14CC9E;
  color: #14CC9E;
}

/* ── Price info line ── */
.ca-chart__price-info {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0 4px;
  min-height: 32px;
}

.ca-chart__current-price {
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}

.ca-chart__price-change {
  font-size: 14px;
  font-weight: 600;
}

.ca-chart__price-change--up {
  color: #16c784;
}

.ca-chart__price-change--down {
  color: #ea3943;
}

/* ── Attribution ── */
.ca-chart__attribution {
  text-align: right;
  padding: 4px 0;
  font-size: 11px;
  color: #9ca3af;
}

.ca-chart__attribution a {
  color: #9ca3af;
  text-decoration: none;
}

.ca-chart__attribution a:hover {
  color: #14CC9E;
  text-decoration: underline;
}

/* ── Navigator (range selector) — CoinGecko-inspired ── */
.ca-chart__navigator {
  position: relative;
  width: 100%;
  height: 54px;
  margin-top: 4px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
}

.ca-chart__navigator-chart {
  width: 100%;
  height: 100%;
}

/* Fix Lightweight Charts default table styling in navigator */
.ca-chart__navigator-chart table {
  border-collapse: collapse;
  border: none;
  margin: 0;
  padding: 0;
}

.ca-chart__navigator-chart td {
  border: none;
  padding: 0;
}

/* Hide TradingView watermark in navigator */
.ca-chart__navigator-chart a[href*="tradingview"],
.ca-chart__navigator-chart div[style*="position: absolute"] a {
  display: none !important;
}

.ca-chart__navigator-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ca-chart__navigator-shade {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(128, 128, 128, 0.06);
  pointer-events: none;
}

.ca-chart__navigator-shade--left {
  left: 0;
}

.ca-chart__navigator-selection {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(102, 133, 194, 0.2);
  cursor: grab;
  pointer-events: auto;
  min-width: 20px;
  border-left: 1px solid rgba(102, 133, 194, 0.5);
  border-right: 1px solid rgba(102, 133, 194, 0.5);
}

.ca-chart__navigator-selection:active {
  cursor: grabbing;
}

.ca-chart__navigator-handle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 18px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 2px;
  cursor: ew-resize;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Grip lines inside handles */
.ca-chart__navigator-handle::before,
.ca-chart__navigator-handle::after {
  content: '';
  display: block;
  width: 1px;
  height: 8px;
  background: #94a3b8;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.ca-chart__navigator-handle::before {
  left: 2px;
}

.ca-chart__navigator-handle::after {
  right: 2px;
}

.ca-chart__navigator-handle--left {
  left: -4px;
}

.ca-chart__navigator-handle--right {
  right: -4px;
}

/* ══════════════════════════════════════════════
   DARK MODE — CoinAcademy palette
   body[data-scheme=dark] → body bg #1c1c1c
   ══════════════════════════════════════════════ */

/* Reset WP Newsblock theme button overrides (dark) */
body[data-scheme=dark] .ca-chart button,
body[data-scheme=dark] .ca-chart button:hover,
body[data-scheme=dark] .ca-chart button:focus,
body[data-scheme=dark] .ca-chart button:active {
  background-color: transparent;
  box-shadow: none;
}

body[data-scheme=dark] .ca-chart__toolbar {
  border-bottom-color: #333333;
}

/* Metric tabs (dark) */
body[data-scheme=dark] .ca-chart__metric-btn {
  color: #9ca3af;
}

body[data-scheme=dark] .ca-chart__metric-btn:hover {
  color: #e5e7eb;
}

body[data-scheme=dark] .ca-chart__metric-btn--active {
  color: #ffffff;
  border-bottom-color: #14CC9E;
}

/* Chart type icons (dark) — specificity (0,2,1) > light mode (0,2,0) */
body[data-scheme=dark] .ca-chart .ca-chart__type-btn {
  border-color: #333333;
  color: #6b7280;
}

body[data-scheme=dark] .ca-chart .ca-chart__type-btn:hover {
  color: #d1d5db;
  border-color: #444444;
}

body[data-scheme=dark] .ca-chart .ca-chart__type-btn--active {
  color: #ffffff;
  background: #2a2a2a;
  border-color: #444444;
}

/* Separator (dark) */
body[data-scheme=dark] .ca-chart__separator {
  background: #333333;
}

/* Currency toggle (dark) */
body[data-scheme=dark] .ca-chart__currency-group {
  background: #262626;
}

body[data-scheme=dark] .ca-chart__currency-btn {
  color: #9ca3af;
}

body[data-scheme=dark] .ca-chart__currency-btn--active {
  background: #333333;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Period buttons (dark) */
body[data-scheme=dark] .ca-chart__period-btn {
  color: #9ca3af;
}

body[data-scheme=dark] .ca-chart__period-btn:hover {
  background: #262626;
  color: #d1d5db;
}

body[data-scheme=dark] .ca-chart__period-btn--active {
  background: rgba(20, 204, 158, 0.12);
  color: #14CC9E;
}

/* Loading (dark) */
body[data-scheme=dark] .ca-chart__loading {
  background: rgba(28, 28, 28, 0.85);
}

body[data-scheme=dark] .ca-chart__spinner {
  border-color: #333333;
  border-top-color: #14CC9E;
}

/* Error (dark) */
body[data-scheme=dark] .ca-chart__error-text {
  color: #9ca3af;
}

body[data-scheme=dark] .ca-chart__error-retry {
  background: #262626;
  border-color: #333333;
  color: #d1d5db;
}

body[data-scheme=dark] .ca-chart__error-retry:hover {
  background: #333333;
  border-color: #14CC9E;
  color: #14CC9E;
}

/* Price display (dark) */
body[data-scheme=dark] .ca-chart__current-price {
  color: #ffffff;
}

/* Attribution (dark) */
body[data-scheme=dark] .ca-chart__attribution {
  color: #6b7280;
}

body[data-scheme=dark] .ca-chart__attribution a {
  color: #6b7280;
}

body[data-scheme=dark] .ca-chart__attribution a:hover {
  color: #14CC9E;
}

/* Navigator (dark) */
body[data-scheme=dark] .ca-chart__navigator {
  border-color: #333333;
}

body[data-scheme=dark] .ca-chart__navigator-shade {
  background: rgba(0, 0, 0, 0.2);
}

body[data-scheme=dark] .ca-chart__navigator-selection {
  background: rgba(102, 133, 194, 0.15);
  border-left-color: rgba(102, 133, 194, 0.4);
  border-right-color: rgba(102, 133, 194, 0.4);
}

body[data-scheme=dark] .ca-chart__navigator-handle {
  background: #2a2a2a;
  border-color: #555555;
}

body[data-scheme=dark] .ca-chart__navigator-handle::before,
body[data-scheme=dark] .ca-chart__navigator-handle::after {
  background: #777777;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */

@media (max-width: 768px) {
  .ca-chart {
    min-height: 380px;
  }

  .ca-chart__toolbar {
    gap: 6px;
    padding-bottom: 8px;
  }

  .ca-chart__toolbar-left {
    gap: 6px;
  }

  .ca-chart__metric-btn {
    padding: 4px 8px;
    font-size: 12px;
  }

  .ca-chart__type-btn {
    width: 28px;
    height: 28px;
  }

  .ca-chart__type-btn svg {
    width: 14px;
    height: 14px;
  }

  .ca-chart__period-btn {
    padding: 3px 7px;
    font-size: 11px;
  }

  .ca-chart__currency-btn {
    padding: 3px 8px;
    font-size: 11px;
  }

  .ca-chart__current-price {
    font-size: 18px;
  }

  .ca-chart__price-change {
    font-size: 12px;
  }

  .ca-chart__separator {
    display: none;
  }

  .ca-chart__navigator {
    height: 40px;
  }

  .ca-chart__navigator-handle {
    width: 6px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .ca-chart__toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .ca-chart__toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .ca-chart__period-group {
    flex-wrap: wrap;
  }
}
