/* ===========================
   Terminal / Output Viewer
   =========================== */

.terminal-container {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.terminal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.terminal-toolbar input {
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  outline: none;
  width: 180px;
  transition: border-color var(--transition);
}

.terminal-toolbar input:focus {
  border-color: var(--accent);
}

.terminal-toolbar input::placeholder {
  color: var(--text3);
}

.terminal-toolbar .match-info {
  color: var(--text2);
  font-size: 12px;
  white-space: nowrap;
}

.terminal-toolbar .toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.terminal-toolbar .toolbar-label {
  font-size: 12px;
  color: var(--text3);
}

.terminal-toolbar .line-count {
  font-size: 12px;
  color: var(--text3);
  margin-left: auto;
}

.terminal {
  background: #0a0c10;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.terminal .stdout {
  color: var(--text);
}

.terminal .stderr {
  color: var(--orange);
}

.terminal .search-highlight {
  background: #fdcb6e;
  color: #1a1d27;
  border-radius: 2px;
  padding: 0 2px;
}

.terminal .line-number {
  display: inline;
  color: var(--text3);
  user-select: none;
  min-width: 3ch;
  margin-right: 12px;
  text-align: right;
}

/* --- ANSI Color Classes --- */

.ansi-black { color: #3c3f4f; }
.ansi-red { color: #e17055; }
.ansi-green { color: #00b894; }
.ansi-yellow { color: #fdcb6e; }
.ansi-blue { color: #74b9ff; }
.ansi-magenta { color: #a29bfe; }
.ansi-cyan { color: #81ecec; }
.ansi-white { color: #e4e6ed; }

.ansi-bright-black { color: #5a5f72; }
.ansi-bright-red { color: #ff7675; }
.ansi-bright-green { color: #55efc4; }
.ansi-bright-yellow { color: #ffeaa7; }
.ansi-bright-blue { color: #a3d8ff; }
.ansi-bright-magenta { color: #c8b6ff; }
.ansi-bright-cyan { color: #a8f0ef; }
.ansi-bright-white { color: #ffffff; }

.ansi-bold { font-weight: 700; }

/* ANSI background colors */
.ansi-bg-black { background: #3c3f4f; }
.ansi-bg-red { background: #e17055; color: #fff; }
.ansi-bg-green { background: #00b894; color: #fff; }
.ansi-bg-yellow { background: #fdcb6e; color: #1a1d27; }
.ansi-bg-blue { background: #74b9ff; color: #1a1d27; }
.ansi-bg-magenta { background: #a29bfe; color: #1a1d27; }
.ansi-bg-cyan { background: #81ecec; color: #1a1d27; }
.ansi-bg-white { background: #e4e6ed; color: #1a1d27; }

/* ===========================
   Terminal Blocks - Rich Output
   =========================== */

.terminal-block {
  margin: 2px 0;
}

.terminal-block.terminal-stdout {
  /* Plain text - no extra styling */
}

.terminal-block-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px 4px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  user-select: none;
}

.terminal-block-label {
  white-space: nowrap;
}

.terminal-block-body {
  padding: 4px 8px 6px 24px;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 0 0 4px 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Thinking blocks */
.terminal-thinking {
  border-left: 3px solid #a29bfe;
  margin: 8px 0;
  background: rgba(162, 155, 254, 0.06);
  border-radius: 4px;
}
.terminal-thinking .terminal-block-header {
  color: #a29bfe;
  background: rgba(162, 155, 254, 0.1);
}
.terminal-thinking .terminal-block-body {
  color: #8a84c9;
  font-style: italic;
}

/* Collapsible thinking */
.terminal-collapsible.collapsed {
  max-height: 60px;
  overflow: hidden;
  position: relative;
}
.terminal-collapsible.collapsed::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30px;
  background: linear-gradient(transparent, rgba(10, 12, 16, 0.9));
}
.terminal-toggle {
  color: #a29bfe;
  font-size: 10px;
  cursor: pointer;
  margin-left: auto;
  opacity: 0.8;
}
.terminal-toggle:hover {
  opacity: 1;
}

/* Tool use blocks */
.terminal-tool {
  border-left: 3px solid #74b9ff;
  margin: 6px 0;
  background: rgba(116, 185, 255, 0.06);
  border-radius: 4px;
}
.terminal-tool .terminal-block-header {
  color: #74b9ff;
  background: rgba(116, 185, 255, 0.1);
}
.terminal-tool .terminal-block-body {
  color: #a0c4e8;
}

.terminal-tool-badge {
  background: rgba(116, 185, 255, 0.2);
  color: #74b9ff;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* Tool result blocks */
.terminal-tool-result {
  border-left: 3px solid #636e72;
  margin: 2px 0 6px 0;
  background: rgba(99, 110, 114, 0.06);
  border-radius: 4px;
}
.terminal-tool-result .terminal-block-header {
  color: #636e72;
  background: rgba(99, 110, 114, 0.08);
}
.terminal-tool-result .terminal-block-body {
  color: #8c9aa0;
  font-size: 11px;
  max-height: 120px;
  overflow-y: auto;
}

/* Question blocks */
.terminal-question {
  border-left: 3px solid #fdcb6e;
  margin: 8px 0;
  background: rgba(253, 203, 110, 0.08);
  border-radius: 4px;
}
.terminal-question .terminal-block-header {
  color: #fdcb6e;
  background: rgba(253, 203, 110, 0.12);
}
.terminal-question .terminal-block-body {
  color: #d4a84a;
}

/* Answer blocks */
.terminal-answer {
  border-left: 3px solid #00b894;
  margin: 2px 0 8px 0;
  background: rgba(0, 184, 148, 0.06);
  border-radius: 4px;
}
.terminal-answer .terminal-block-header {
  color: #00b894;
  background: rgba(0, 184, 148, 0.1);
}
.terminal-answer .terminal-block-body {
  color: #00d2a4;
}

/* System blocks */
.terminal-system {
  margin: 4px 0;
}
.terminal-system .terminal-block-header {
  color: #636e72;
}
.terminal-system .terminal-block-body {
  color: #636e72;
  font-size: 11px;
}

/* Result (final) blocks */
.terminal-result {
  border-left: 3px solid #00b894;
  margin: 8px 0;
  background: rgba(0, 184, 148, 0.06);
  border-radius: 4px;
}
.terminal-result .terminal-block-header {
  color: #00b894;
  background: rgba(0, 184, 148, 0.1);
}

/* Stderr blocks */
.terminal-stderr {
  border-left: 3px solid #e17055;
  margin: 4px 0;
  background: rgba(225, 112, 85, 0.06);
  border-radius: 4px;
}
.terminal-stderr .terminal-block-header {
  color: #e17055;
  background: rgba(225, 112, 85, 0.1);
}
.terminal-stderr .terminal-block-body {
  color: #e17055;
}

/* Live dot animation */
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00b894;
  display: inline-block;
  animation: live-pulse 1.5s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Terminal status indicator */
.terminal-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  transition: all 0.2s;
}
.terminal-status.pulse {
  animation: status-pulse 0.3s ease-out;
}
@keyframes status-pulse {
  0% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
.terminal-status-thinking { color: #a29bfe; background: rgba(162, 155, 254, 0.15); }
.terminal-status-tool { color: #74b9ff; background: rgba(116, 185, 255, 0.15); }
.terminal-status-stdout { color: var(--text2); }

/* Status badges */
/* Markdown rendered in terminal */
.terminal-md {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
}
.terminal-md h1, .terminal-md h2, .terminal-md h3 {
  color: var(--accent2);
  margin: 12px 0 8px;
}
.terminal-md h1 { font-size: 18px; }
.terminal-md h2 { font-size: 16px; }
.terminal-md h3 { font-size: 14px; }
.terminal-md p { margin: 6px 0; }
.terminal-md ul, .terminal-md ol { margin: 6px 0; padding-left: 20px; }
.terminal-md li { margin: 3px 0; }
.terminal-md code {
  background: rgba(116, 185, 255, 0.15);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.terminal-md pre {
  background: rgba(0,0,0,0.3);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.terminal-md pre code {
  background: none;
  padding: 0;
}
.terminal-md table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}
.terminal-md th, .terminal-md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 12px;
}
.terminal-md th { background: var(--bg3); }
.terminal-md blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text2);
  margin: 8px 0;
}
.terminal-md a { color: var(--accent2); }
.terminal-md strong { color: var(--green); }

.status-running {
  color: #00b894;
  background: rgba(0, 184, 148, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  animation: live-pulse 1.5s ease-in-out infinite;
}
