/* 2026-05-24: 전세계 1등 히스토리 패널 (cap-modern). */

/* ===== 패널 전체 ===== */
#cp_console_box {
  background: linear-gradient(180deg, #f8f9fb 0%, #f0f2f5 100%);
  border-left: 1px solid #e5e7eb;
}

/* toolbar */
.cubroid-history-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  flex-wrap: wrap;
}
.cubroid-history-title {
  font-size: 13px;
  font-weight: 700;
  color: #1f2937;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cubroid-history-title-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: #fff;
}
.cubroid-history-title-icon svg { width: 12px; height: 12px; }
.cubroid-history-btn svg { display: block; }
.cubroid-history-empty-icon svg { width: 32px; height: 32px; opacity: 0.4; }
.cubroid-history-search {
  flex: 1 1 80px;
  min-width: 60px;
  max-width: 120px;
  padding: 5px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 11px;
  outline: none;
  transition: border-color 0.15s;
}
.cubroid-history-btn { flex-shrink: 0; padding: 5px 6px; }
.cubroid-history-title { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cubroid-history-search:focus { border-color: #8b5cf6; }
.cubroid-history-btn {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  cursor: pointer;
  color: #6b7280;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.cubroid-history-btn:hover {
  background: #f9fafb;
  border-color: #8b5cf6;
  color: #8b5cf6;
}
.cubroid-history-count {
  font-size: 10px;
  color: #9ca3af;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 10px;
}

/* ===== 카드 컨테이너 ===== */
#cp_console_content {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cubroid-history-empty {
  padding: 30px 16px;
  text-align: center;
  color: #9ca3af;
  font-size: 12px;
}
.cubroid-history-empty-icon {
  font-size: 28px;
  display: block;
  margin-bottom: 6px;
  opacity: 0.5;
}

/* ===== 카드 ===== */
.ch-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  overflow: hidden;
  border: 1px solid #e5e7eb;
  animation: chSlideIn 0.2s ease-out;
}
@keyframes chSlideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ch-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: background 0.12s;
}
.ch-card-header:hover { background: #f9fafb; }
.ch-card.ch-expanded .ch-card-header { border-bottom-color: #f3f4f6; }
.ch-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.ch-icon svg { width: 12px; height: 12px; }
.ch-chevron svg { width: 10px; height: 10px; vertical-align: middle; }
.ch-motor-icon svg { width: 14px; height: 14px; }
.ch-title {
  font-size: 12px;
  font-weight: 600;
  color: #1f2937;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-time {
  font-size: 10px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.ch-chevron {
  color: #d1d5db;
  font-size: 10px;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.ch-card.ch-expanded .ch-chevron { transform: rotate(180deg); }
.ch-card-body {
  padding: 10px 12px;
  font-size: 12px;
  color: #374151;
  line-height: 1.5;
  background: #fafbfc;
  display: none;
}
.ch-card.ch-expanded .ch-card-body { display: block; }
/* 짧은 body 일 때 padding 축소 (clutter 방지) */
.ch-card-body:has(.ch-vis-text:only-child) {
  padding: 6px 12px;
}

/* ===== 색상 태그 (level 별 좌측 보더) ===== */
.ch-card.ch-info .ch-icon { background: #3b82f6; }
.ch-card.ch-info { border-left: 3px solid #3b82f6; }
.ch-card.ch-success .ch-icon { background: #10b981; }
.ch-card.ch-success { border-left: 3px solid #10b981; }
.ch-card.ch-warn .ch-icon { background: #f59e0b; }
.ch-card.ch-warn { border-left: 3px solid #f59e0b; }
.ch-card.ch-error .ch-icon { background: #ef4444; }
.ch-card.ch-error { border-left: 3px solid #ef4444; }
.ch-card.ch-ai .ch-icon { background: linear-gradient(135deg, #8b5cf6, #ec4899); }
.ch-card.ch-ai { border-left: 3px solid #8b5cf6; }
.ch-card.ch-device .ch-icon { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.ch-card.ch-device { border-left: 3px solid #06b6d4; }

/* ===== 블록별 visual ===== */
/* 이미지 인식 */
.ch-vis-image-recog {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.ch-vis-image-recog img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}
.ch-vis-image-recog .ch-results { flex: 1; min-width: 0; }
.ch-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.ch-result-label {
  font-size: 11px;
  font-weight: 500;
  color: #374151;
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-result-bar {
  width: 60px;
  height: 4px;
  background: #f3f4f6;
  border-radius: 2px;
  overflow: hidden;
}
.ch-result-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b5cf6, #ec4899);
  transition: width 0.3s;
}
.ch-result-pct {
  font-size: 10px;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* 번역 */
.ch-vis-translate {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ch-trans-side {
  flex: 1;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}
.ch-trans-lang {
  font-size: 9px;
  color: #9ca3af;
  text-transform: uppercase;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}
.ch-trans-text {
  font-size: 12px;
  color: #1f2937;
  word-break: break-word;
}
.ch-trans-arrow {
  color: #8b5cf6;
  font-size: 14px;
  flex-shrink: 0;
}

/* AI Image */
.ch-vis-ai-image img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
  background: #f3f4f6;
}
.ch-vis-ai-image .ch-prompt {
  margin-top: 6px;
  font-size: 11px;
  color: #6b7280;
  font-style: italic;
}
.ch-chip {
  display: inline-block;
  background: #ede9fe;
  color: #6d28d9;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-right: 4px;
}

/* TTS */
.ch-vis-tts {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ch-tts-wave {
  display: flex;
  gap: 2px;
  align-items: center;
  flex-shrink: 0;
}
.ch-tts-wave span {
  display: inline-block;
  width: 2px;
  background: #8b5cf6;
  border-radius: 1px;
  animation: chTtsWave 1s ease-in-out infinite;
}
.ch-tts-wave span:nth-child(1) { height: 8px; animation-delay: 0s; }
.ch-tts-wave span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.ch-tts-wave span:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.ch-tts-wave span:nth-child(4) { height: 16px; animation-delay: 0.3s; }
.ch-tts-wave span:nth-child(5) { height: 9px; animation-delay: 0.4s; }
@keyframes chTtsWave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}
.ch-tts-text {
  flex: 1;
  font-size: 12px;
  color: #374151;
}

/* LCD */
.ch-vis-lcd {
  display: flex;
  gap: 10px;
  align-items: center;
}
.ch-lcd-mini {
  width: 64px;
  height: 32px;
  background: #1e293b;
  border-radius: 4px;
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #38bdf8;
  font-size: 9px;
  font-family: monospace;
  flex-shrink: 0;
  padding: 2px 4px;
  text-align: center;
  overflow: hidden;
  word-break: break-all;
  line-height: 1;
}
.ch-vis-lcd .ch-lcd-text {
  flex: 1;
  font-size: 12px;
  color: #1f2937;
  font-weight: 500;
  word-break: break-word;
}

/* 얼굴 */
.ch-vis-face {
  display: flex;
  gap: 10px;
  align-items: center;
}
.ch-face-attrs { display: flex; gap: 4px; flex-wrap: wrap; }
.ch-attr-chip {
  background: #fef3c7;
  color: #92400e;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.ch-attr-chip.ch-mood-happy { background: #d1fae5; color: #065f46; }
.ch-attr-chip.ch-mood-sad { background: #dbeafe; color: #1e40af; }
.ch-attr-chip.ch-mood-angry { background: #fee2e2; color: #991b1b; }

/* GPT */
.ch-vis-gpt {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ch-gpt-msg {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  max-width: 90%;
  word-break: break-word;
}
.ch-gpt-msg.ch-gpt-q {
  background: #ede9fe;
  color: #4c1d95;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}
.ch-gpt-msg.ch-gpt-a {
  background: #f3f4f6;
  color: #1f2937;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

/* 센서 */
.ch-vis-sensor {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.ch-sensor-val {
  font-size: 22px;
  font-weight: 700;
  color: #06b6d4;
  font-variant-numeric: tabular-nums;
}
.ch-sensor-unit { font-size: 11px; color: #6b7280; }
.ch-sensor-label { font-size: 11px; color: #9ca3af; margin-left: auto; }

/* 바닥 센서 (gauge 형식) */
.ch-vis-floor-sensor { display: flex; flex-direction: column; gap: 6px; }
.ch-fs-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.ch-fs-label { font-size: 11px; color: #6b7280; font-weight: 500; }
.ch-fs-status { font-size: 13px; font-weight: 600; color: #1f2937; flex: 1; }
.ch-fs-val {
  font-size: 11px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, monospace;
}
.ch-fs-gauge {
  width: 100%;
  height: 6px;
  background: #f3f4f6;
  border-radius: 3px;
  overflow: hidden;
}
.ch-fs-gauge-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.ch-vis-floor-sensor.sensor-white .ch-fs-gauge-fill {
  background: linear-gradient(90deg, #e5e7eb, #d1d5db);
}
.ch-vis-floor-sensor.sensor-white .ch-fs-status { color: #4b5563; }
.ch-vis-floor-sensor.sensor-black .ch-fs-gauge-fill {
  background: linear-gradient(90deg, #4b5563, #1f2937);
}
.ch-vis-floor-sensor.sensor-black .ch-fs-status { color: #1f2937; }
.ch-vis-floor-sensor.sensor-danger .ch-fs-gauge-fill {
  background: linear-gradient(90deg, #f97316, #dc2626);
  animation: chSensorPulse 1s ease-in-out infinite;
}
.ch-vis-floor-sensor.sensor-danger .ch-fs-status { color: #dc2626; font-weight: 700; }
@keyframes chSensorPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* 모터 */
.ch-vis-motor {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #374151;
}
.ch-motor-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f0fdf4;
  color: #10b981;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* 단순 텍스트 fallback */
.ch-vis-text {
  font-size: 12px;
  color: #374151;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== 전문 톤 (tech) — model · value · chips ===== */
.ch-vis-tech {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ch-tech-model {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  color: #6d28d9;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.ch-tech-value {
  font-size: 13px;
  color: #1f2937;
  font-weight: 500;
  line-height: 1.4;
  word-break: break-word;
}
.ch-tech-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.ch-tech-chip {
  display: inline-block;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #f3f4f6;
  color: #4b5563;
  font-weight: 500;
  border: 1px solid #e5e7eb;
  white-space: nowrap;
}
.ch-tech-chip.info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.ch-tech-chip.danger {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* 필터 chip */
.cubroid-filter-dropdown {
  position: relative;
  display: inline-block;
}
.cubroid-filter-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 120px;
  padding: 4px;
  z-index: 100;
  display: none;
}
.cubroid-filter-menu.open { display: block; }
.cubroid-filter-item {
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
  border-radius: 4px;
  color: #374151;
}
.cubroid-filter-item:hover { background: #f3f4f6; }
.cubroid-filter-item.active {
  background: #ede9fe;
  color: #6d28d9;
  font-weight: 600;
}
