/**
 * CLI Stream Viewer Styles
 * Right-side popup panel for viewing CLI streaming output
 */

/* ===== Overlay ===== */
.cli-stream-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.3);
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.cli-stream-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ===== Main Panel ===== */
.cli-stream-viewer {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 700px;
  max-width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  box-shadow: 0 8px 32px rgb(0 0 0 / 0.2);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cli-stream-viewer.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
}

/* ===== Header ===== */
.cli-stream-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.3);
}

.cli-stream-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.cli-stream-title svg,
.cli-stream-title i {
  width: 18px;
  height: 18px;
  color: hsl(var(--primary));
}

.cli-stream-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border-radius: 10px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.cli-stream-count-badge.has-running {
  background: hsl(var(--warning));
  color: hsl(var(--warning-foreground, white));
}

/* ===== Search Box ===== */
.cli-stream-search {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 6px;
  transition: all 0.2s;
}

.cli-stream-search:focus-within {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.1);
}

.cli-stream-search-input {
  width: 140px;
  padding: 2px 4px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 0.75rem;
  color: hsl(var(--foreground));
}

.cli-stream-search-input::placeholder {
  color: hsl(var(--muted-foreground));
}

.cli-stream-search-icon {
  width: 14px;
  height: 14px;
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
}

.cli-stream-search-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
}

.cli-stream-search:focus-within .cli-stream-search-clear,
.cli-stream-search-input:not(:placeholder-shown) + .cli-stream-search-clear {
  opacity: 1;
}

.cli-stream-search-clear:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.cli-stream-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cli-stream-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid hsl(var(--border));
  border-radius: 4px;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s;
}

.cli-stream-action-btn:hover {
  background: hsl(var(--hover));
  color: hsl(var(--foreground));
}

.cli-stream-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 4px;
  font-size: 1.25rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s;
}

.cli-stream-close-btn:hover {
  background: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
}

/* ===== Tab Bar ===== */
.cli-stream-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  padding: 8px 12px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.2);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Show scrollbar on hover for better UX */
.cli-stream-tabs::-webkit-scrollbar {
  height: 6px;
}

.cli-stream-tabs::-webkit-scrollbar-track {
  background: transparent;
}

.cli-stream-tabs::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 3px;
  transition: background 0.2s;
}

.cli-stream-tabs::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.5);
}

.cli-stream-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.cli-stream-tab:hover {
  background: hsl(var(--hover));
  color: hsl(var(--foreground));
  transform: translateY(-1px);
}

.cli-stream-tab.active {
  background: hsl(var(--card));
  border-color: hsl(var(--primary));
  color: hsl(var(--foreground));
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
  transform: translateY(-1px);
}

.cli-stream-tab.active .cli-stream-tab-tool {
  color: hsl(var(--primary));
}

.cli-stream-tab-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cli-stream-tab-status.running {
  background: hsl(var(--warning));
  animation: streamStatusPulse 1.5s ease-in-out infinite;
}

.cli-stream-tab-status.completed {
  background: hsl(var(--success));
}

.cli-stream-tab-status.error {
  background: hsl(var(--destructive));
}

@keyframes streamStatusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

.cli-stream-tab-tool {
  font-weight: 500;
  text-transform: capitalize;
}

.cli-stream-tab-mode {
  font-size: 0.625rem;
  padding: 1px 4px;
  background: hsl(var(--muted));
  border-radius: 3px;
  color: hsl(var(--muted-foreground));
}

.cli-stream-tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 4px;
  background: transparent;
  border: none;
  border-radius: 50%;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
}

.cli-stream-tab:hover .cli-stream-tab-close {
  opacity: 1;
}

.cli-stream-tab-close:hover {
  background: hsl(var(--destructive) / 0.2);
  color: hsl(var(--destructive));
}

.cli-stream-tab-close.disabled {
  cursor: not-allowed;
  opacity: 0.3 !important;
}

/* ===== Empty State ===== */
.cli-stream-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: hsl(var(--muted-foreground));
  text-align: center;
}

.cli-stream-empty svg,
.cli-stream-empty i {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.cli-stream-empty-title {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.cli-stream-empty-hint {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ===== Terminal Content ===== */
.cli-stream-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px;
  background: hsl(220 13% 8%);
  font-family: var(--font-mono, 'Consolas', 'Monaco', 'Courier New', monospace);
  font-size: 0.75rem;
  line-height: 1.6;
  scrollbar-width: thin;
}

.cli-stream-content::-webkit-scrollbar {
  width: 8px;
}

.cli-stream-content::-webkit-scrollbar-track {
  background: transparent;
}

.cli-stream-content::-webkit-scrollbar-thumb {
  background: hsl(0 0% 40%);
  border-radius: 4px;
}

.cli-stream-line {
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  padding: 2px 0;
  border-radius: 2px;
  transition: background-color 0.15s;
}

.cli-stream-line:hover {
  background: hsl(0 0% 100% / 0.03);
}

.cli-stream-line.stdout {
  color: hsl(0 0% 85%);
}

.cli-stream-line.stderr {
  color: hsl(8 75% 65%);
  background: hsl(8 75% 65% / 0.05);
}

.cli-stream-line.system {
  color: hsl(210 80% 65%);
  font-style: italic;
  padding-left: 8px;
  border-left: 2px solid hsl(210 80% 65% / 0.5);
}

.cli-stream-line.info {
  color: hsl(200 80% 70%);
}

/* ===== Formatted Message Types ===== */
.cli-stream-line.formatted {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 10px;
  margin: 2px 0;
  border-radius: 4px;
  transition: all 0.15s ease;
  color: hsl(0 0% 90%);  /* Ensure text is visible */
}

.cli-stream-line.formatted:hover {
  background: hsl(0 0% 100% / 0.05);
}

/* Message Badge */
.cli-msg-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.cli-msg-badge i,
.cli-msg-badge svg {
  width: 12px;
  height: 12px;
}

.cli-msg-content {
  flex: 1;
  word-break: break-word;
}

/* System Message */
.cli-stream-line.formatted.system {
  background: hsl(210 50% 20% / 0.3);
  border-left: 3px solid hsl(210 80% 55%);
}

.cli-msg-badge.cli-msg-system {
  background: hsl(210 80% 55% / 0.2);
  color: hsl(210 80% 70%);
}

/* Thinking Message */
.cli-stream-line.formatted.thinking {
  background: hsl(280 50% 20% / 0.3);
  border-left: 3px solid hsl(280 70% 65%);
  font-style: italic;
}

.cli-msg-badge.cli-msg-thinking {
  background: hsl(280 70% 65% / 0.2);
  color: hsl(280 70% 75%);
}

/* Response Message */
.cli-stream-line.formatted.response {
  background: hsl(145 40% 18% / 0.3);
  border-left: 3px solid hsl(145 60% 50%);
}

.cli-msg-badge.cli-msg-response {
  background: hsl(145 60% 50% / 0.2);
  color: hsl(145 60% 65%);
}

/* Result Message */
.cli-stream-line.formatted.result {
  background: hsl(160 50% 18% / 0.4);
  border-left: 3px solid hsl(160 80% 45%);
}

.cli-msg-badge.cli-msg-result {
  background: hsl(160 80% 45% / 0.25);
  color: hsl(160 80% 60%);
}

/* Error Message */
.cli-stream-line.formatted.error {
  background: hsl(0 50% 20% / 0.4);
  border-left: 3px solid hsl(0 70% 55%);
}

.cli-msg-badge.cli-msg-error {
  background: hsl(0 70% 55% / 0.25);
  color: hsl(0 70% 70%);
}

/* Warning Message */
.cli-stream-line.formatted.warning {
  background: hsl(45 60% 18% / 0.4);
  border-left: 3px solid hsl(45 80% 55%);
}

.cli-msg-badge.cli-msg-warning {
  background: hsl(45 80% 55% / 0.25);
  color: hsl(45 80% 65%);
}

/* Info Message */
.cli-stream-line.formatted.info {
  background: hsl(200 50% 18% / 0.3);
  border-left: 3px solid hsl(200 70% 60%);
}

.cli-msg-badge.cli-msg-info {
  background: hsl(200 70% 60% / 0.2);
  color: hsl(200 70% 70%);
}

/* ===== Backend ChunkType Badges (CliOutputUnit.type) ===== */

/* Thought/Thinking Message (from JSONL parser) */
.cli-stream-line.formatted.thought {
  background: hsl(280 50% 20% / 0.3);
  border-left: 3px solid hsl(280 70% 65%);
  font-style: italic;
}

.cli-msg-badge.cli-msg-thought {
  background: hsl(280 70% 65% / 0.2);
  color: hsl(280 70% 75%);
}

/* Code Block Message */
.cli-stream-line.formatted.code {
  background: hsl(220 40% 18% / 0.4);
  border-left: 3px solid hsl(220 60% 55%);
  font-family: var(--font-mono, 'Consolas', 'Monaco', 'Courier New', monospace);
}

.cli-msg-badge.cli-msg-code {
  background: hsl(220 60% 55% / 0.25);
  color: hsl(220 60% 70%);
}

/* File Diff Message */
.cli-stream-line.formatted.file_diff {
  background: hsl(35 50% 18% / 0.4);
  border-left: 3px solid hsl(35 80% 55%);
}

.cli-msg-badge.cli-msg-file_diff {
  background: hsl(35 80% 55% / 0.25);
  color: hsl(35 80% 65%);
}

/* Progress Message */
.cli-stream-line.formatted.progress {
  background: hsl(190 40% 18% / 0.3);
  border-left: 3px solid hsl(190 70% 50%);
}

.cli-msg-badge.cli-msg-progress {
  background: hsl(190 70% 50% / 0.2);
  color: hsl(190 70% 65%);
}

/* Metadata Message */
.cli-stream-line.formatted.metadata {
  background: hsl(250 30% 18% / 0.3);
  border-left: 3px solid hsl(250 50% 60%);
  font-size: 0.85em;
}

.cli-msg-badge.cli-msg-metadata {
  background: hsl(250 50% 60% / 0.2);
  color: hsl(250 50% 75%);
}

/* Tool Call Message (Gemini tool_use/tool_result) */
.cli-stream-line.formatted.tool_call {
  background: hsl(160 40% 18% / 0.3);
  border-left: 3px solid hsl(160 70% 50%);
  font-size: 0.85em;
}

.cli-msg-badge.cli-msg-tool_call {
  background: hsl(160 70% 50% / 0.2);
  color: hsl(160 70% 65%);
}

/* Stderr Message (Error) */
.cli-stream-line.formatted.stderr {
  background: hsl(0 50% 20% / 0.4);
  border-left: 3px solid hsl(0 70% 55%);
}

.cli-msg-badge.cli-msg-stderr {
  background: hsl(0 70% 55% / 0.25);
  color: hsl(0 70% 70%);
}

/* Inline Code */
.cli-inline-code {
  padding: 1px 5px;
  background: hsl(0 0% 25%);
  border-radius: 3px;
  font-family: var(--font-mono, 'Consolas', 'Monaco', 'Courier New', monospace);
  font-size: 0.85em;
  color: hsl(45 80% 70%);
}

/* JSON/Code syntax coloring in output */
.cli-stream-line .json-key {
  color: hsl(200 80% 70%);
}

.cli-stream-line .json-string {
  color: hsl(100 50% 60%);
}

.cli-stream-line .json-number {
  color: hsl(40 80% 65%);
}

/* Search highlight */
.cli-stream-highlight {
  background: hsl(50 100% 50% / 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* Filter result info */
.cli-stream-filter-info {
  display: inline-block;
  padding: 4px 10px;
  margin-bottom: 8px;
  background: hsl(var(--primary) / 0.15);
  color: hsl(var(--primary));
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
}

/* Auto-scroll indicator */
.cli-stream-scroll-btn {
  position: sticky;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: hsl(var(--primary));
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 0.625rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.cli-stream-content.has-new-content .cli-stream-scroll-btn {
  opacity: 1;
}

/* ===== Status Bar ===== */
.cli-stream-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.3);
  font-size: 0.6875rem;
  color: hsl(var(--muted-foreground));
}

.cli-stream-status-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cli-stream-status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cli-stream-status-item svg,
.cli-stream-status-item i {
  width: 12px;
  height: 12px;
}

.cli-stream-status-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cli-stream-toggle-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: transparent;
  border: 1px solid hsl(var(--border));
  border-radius: 3px;
  font-size: 0.625rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: all 0.15s;
}

.cli-stream-toggle-btn:hover {
  background: hsl(var(--hover));
}

.cli-stream-toggle-btn.active {
  background: hsl(var(--primary) / 0.1);
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
}

/* ===== Header Button & Badge ===== */
.cli-stream-btn {
  position: relative;
}

.cli-stream-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  background: hsl(var(--warning));
  color: white;
  border-radius: 7px;
  font-size: 0.5625rem;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
}

.cli-stream-badge.has-running {
  display: flex;
  animation: streamBadgePulse 1.5s ease-in-out infinite;
}

@keyframes streamBadgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .cli-stream-viewer {
    top: 8px;
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    height: calc(100vh - 16px);
  }
}
