/* Instrument Widget Styles - точная копия макета со скрина */

.instrument-widget {
  width: 100%;
  background: #1a1a1a;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #ffffff;
  box-sizing: border-box;
}

/* Header: название и цена слева, изменение и стрелка справа */
.instrument-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  position: relative;
  margin-bottom: 12px;
  gap: 12px;
}

/* Левая часть header: название и цена */
.instrument-widget-header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

/* Цена в header (под названием) */
.instrument-widget-header-price {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.2;
}

/* Правая часть header: изменение и стрелка */
.instrument-widget-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Badge для суммы изменения + процента (закругленная обертка) - без обводки */
.instrument-widget-header-change-badge {
  background: #2a2a2a;
  /* color устанавливается через inline style в JS для перекрытия родительского .instrument-widget { color: #ffffff } */
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  border: none; /* Убираем обводку */
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px; /* Отступ между иконкой и текстом */
  box-sizing: border-box;
}

/* Иконка стрелки внутри badge */
.instrument-widget-header-change-arrow-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.instrument-widget-header-change-arrow-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  margin: 0;
  padding: 0;
  vertical-align: middle;
}

/* Текст изменения внутри badge */
.instrument-widget-header-change-text {
  display: inline-block;
  /* КРИТИЧНО: Наследуем цвет от родительского badge */
  color: inherit !important;
}

.instrument-widget-header-change-badge.positive {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981 !important; /* КРИТИЧНО: Явно устанавливаем цвет текста для перекрытия родительского color */
}

.instrument-widget-header-change-badge.negative {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444 !important; /* КРИТИЧНО: Явно устанавливаем цвет текста для перекрытия родительского color */
}

/* КРИТИЧНО: Перекрываем правило .message.ai .message-bubble * { color: #ffffff !important; } из chat.css */
.message.ai .message-bubble .instrument-widget-header-change-badge.positive,
.message.ai .message-bubble .instrument-widget .instrument-widget-header-change-badge.positive {
  color: #10b981 !important;
}

.message.ai .message-bubble .instrument-widget-header-change-badge.positive *,
.message.ai .message-bubble .instrument-widget .instrument-widget-header-change-badge.positive * {
  color: #10b981 !important;
}

.message.ai .message-bubble .instrument-widget-header-change-badge.negative,
.message.ai .message-bubble .instrument-widget .instrument-widget-header-change-badge.negative {
  color: #ef4444 !important;
}

.message.ai .message-bubble .instrument-widget-header-change-badge.negative *,
.message.ai .message-bubble .instrument-widget .instrument-widget-header-change-badge.negative * {
  color: #ef4444 !important;
}

/* Стрелка в цветной обертке (круг) - УДАЛЕНО, теперь стрелка внутри badge */
/* Старый класс оставлен для обратной совместимости, но не используется */
.instrument-widget-header-change-arrow-circle {
  display: none; /* Скрываем старый элемент, если он где-то остался */
}

.instrument-widget-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.instrument-widget-name {
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
}

.instrument-widget-ticker {
  font-size: 14px;
  font-weight: 400;
  color: #9ca3af;
}

.instrument-widget-badge {
  background: #2a2a2a;
  color: #ffffff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Большая цена */
.instrument-widget-price {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

/* Строка изменения */
.instrument-widget-change-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.instrument-widget-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
}

.instrument-widget-change.positive {
  color: #10b981;
}

.instrument-widget-change.negative {
  color: #ef4444;
}

.instrument-widget-change-icon {
  display: flex;
  align-items: center;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.instrument-widget-change-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.instrument-widget-last-updated {
  font-size: 12px;
  color: #6b7280;
  font-weight: 400;
}

/* Таймфреймы */
.instrument-widget-timeframes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.instrument-widget-timeframe {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  position: relative;
  padding-bottom: 8px;
}

.instrument-widget-timeframe:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.05);
}

.instrument-widget-timeframe.active {
  color: #ffffff;
}

.instrument-widget-timeframe.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: #ffffff;
  border-radius: 2px 2px 0 0;
}

/* График */
.instrument-widget-chart-container {
  width: 100%;
  height: 280px;
  margin-top: 8px;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: transparent;
  pointer-events: auto !important; /* КРИТИЧНО: Разрешаем события мыши для hover-эффекта */
}

.instrument-widget-chart {
  width: 100%;
  height: 100%;
  display: block;
  position: relative;
  pointer-events: auto !important; /* КРИТИЧНО: Разрешаем события мыши для hover-эффекта */
  cursor: crosshair; /* Курсор для интерактивного графика */
}

/* Hover-эффект для графика: вертикальная линия (crosshair) */
.instrument-widget-chart-crosshair {
  pointer-events: none;
  transition: opacity 0.1s ease;
}

/* Hover-эффект для графика: точка на графике (индикатор позиции курсора) */
.instrument-widget-chart-hover-point {
  pointer-events: none;
  transition: opacity 0.1s ease;
  /* КРИТИЧНО: Обеспечиваем круглую форму (не овальную) через CSS transform */
  /* Используем scale для компенсации деформации SVG при preserveAspectRatio='none' */
  transform-origin: center;
}

/* Дополнительная защита от деформации через CSS */
.instrument-widget-chart {
  /* viewBox установлен как "0 0 100 100" - квадратный */
  /* preserveAspectRatio='none' растягивает SVG, но мы компенсируем это для круга через JS */
}

/* Tooltip для отображения цены и даты при hover */
.instrument-widget-chart-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: none;
  transition: opacity 0.1s ease;
}

.instrument-widget-chart-tooltip-price {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 2px;
}

.instrument-widget-chart-tooltip-time {
  font-size: 11px;
  font-weight: 400;
  color: #9ca3af;
  margin-top: 2px;
}

/* Кнопка "Открыть график" - полностью закругленная без обводки */
.instrument-widget-open-chart-btn {
  background: #2a2a2a;
  color: #ffffff;
  border: none;
  border-radius: 50px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  margin: 12px 0 0 0;
  line-height: 1.4;
  width: 100%;
  text-align: center;
  outline: none;
}

.instrument-widget-open-chart-btn:hover {
  background: #3a3a3a;
  color: #ffffff;
}

.instrument-widget-open-chart-btn:active {
  background: #2a2a2a;
  transform: translateY(1px);
}

.instrument-widget-open-chart-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}

/* Skeleton для loading состояния */
.instrument-widget-loading {
  opacity: 0.7;
}

.instrument-widget-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-header,
.skeleton-price,
.skeleton-change,
.skeleton-timeframes,
.skeleton-chart {
  background: linear-gradient(
    90deg,
    #2a2a2a 0%,
    #3a3a3a 50%,
    #2a2a2a 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

.skeleton-header {
  height: 24px;
  width: 60%;
}

.skeleton-price {
  height: 40px;
  width: 50%;
}

.skeleton-change {
  height: 20px;
  width: 40%;
}

.skeleton-timeframes {
  height: 32px;
  width: 100%;
}

.skeleton-chart {
  height: 280px;
  width: 100%;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Light theme support */
body.light-theme .instrument-widget {
  background: #f5f5f5;
  color: #000000;
}

body.light-theme .instrument-widget-name {
  color: #000000;
}

body.light-theme .instrument-widget-ticker {
  color: #6b7280;
}

body.light-theme .instrument-widget-header-price {
  color: #000000;
}

body.light-theme .instrument-widget-header-change-badge {
  background: #e5e5e5;
  /* Цвет текста устанавливается через inline style в JS для перекрытия родительского color */
  border: none; /* Убираем обводку */
}

body.light-theme .instrument-widget-header-change-badge.positive {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981 !important; /* КРИТИЧНО: Явно устанавливаем цвет текста для перекрытия родительского color */
}

body.light-theme .instrument-widget-header-change-badge.negative {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444 !important; /* КРИТИЧНО: Явно устанавливаем цвет текста для перекрытия родительского color */
}

body.light-theme .instrument-widget-badge {
  background: #e5e5e5;
  color: #000000;
}

body.light-theme .instrument-widget-timeframe {
  color: #6b7280;
}

body.light-theme .instrument-widget-timeframe:hover {
  color: #000000;
  background: rgba(0, 0, 0, 0.05);
}

body.light-theme .instrument-widget-timeframe.active {
  color: #000000;
}

body.light-theme .instrument-widget-timeframe.active::after {
  background: #000000;
}

body.light-theme .instrument-widget-last-updated {
  color: #9ca3af;
}

body.light-theme .instrument-widget-open-chart-btn {
  background: #e5e5e5;
  color: #000000;
  border: none;
}

body.light-theme .instrument-widget-open-chart-btn:hover {
  background: #d5d5d5;
}

body.light-theme .instrument-widget-chart line {
  stroke: #9ca3af;
}

body.light-theme .instrument-widget-chart-tooltip {
  background: rgba(255, 255, 255, 0.95);
  color: #000000;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

body.light-theme .instrument-widget-chart-tooltip-price {
  color: #000000;
}

body.light-theme .instrument-widget-chart-tooltip-time {
  color: #6b7280;
}

/* Адаптивность для маленьких экранов */
@media (max-width: 480px) {
  .instrument-widget-price {
    font-size: 28px;
  }

  .instrument-widget-chart-container {
    height: 240px;
  }

  .instrument-widget-timeframes {
    gap: 6px;
  }

  .instrument-widget-timeframe {
    font-size: 12px;
    padding: 5px 10px;
  }
}
