/* ============================================================================
   TOOL CALL STYLES — Compact, color-coded redesign
   ============================================================================ */


/* ---------------------------------------------------------------------------
   COLOR VARIABLES — uniform accent, error only
   --------------------------------------------------------------------------- */

:root {
    --tc-accent:            var(--accent-color);
    --tc-accent-bg:         rgba(80, 250, 123, 0.04);
    --tc-error:             var(--error-color);
    --tc-error-bg:          rgba(255, 107, 107, 0.06);
}

[data-theme="light"] {
    --tc-accent:            #1a8a4a;
    --tc-accent-bg:         rgba(26, 138, 74, 0.05);
    --tc-error:             var(--error-color);
    --tc-error-bg:          rgba(255, 0, 0, 0.05);
}


/* ---------------------------------------------------------------------------
   BASE TOOL CALL — compact single-line
   --------------------------------------------------------------------------- */

.tool-call {
    position: relative;
    background-color: var(--tc-accent-bg);
    border-left: 2px solid var(--tc-accent);
    margin: 6px 0;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    line-height: 1;             /* prevent whitespace inflation in pre-wrap */
    max-width: 320px;
    transition: max-width 0.3s ease, background-color 0.2s ease;
}

.tool-call.expanded {
    max-width: 40vw !important;
}

/* Extra top margin when tool-call follows text (class set by MutationObserver) */
.tool-call.after-text {
    margin-top: 26px;
}


/* ---------------------------------------------------------------------------
   HEADER — single row: [icon label]  [spinner|duration] [chevron]
   --------------------------------------------------------------------------- */

.tool-call-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    line-height: 22px;          /* comfortable click target */
    min-width: 0;
    cursor: default;
}

.tool-call-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    color: var(--tc-accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.tool-call-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-call-right {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.tool-call-status {
    display: flex;
    align-items: center;
}


/* ---------------------------------------------------------------------------
   ICON — inherits color from parent .tool-call-action
   --------------------------------------------------------------------------- */

.tool-call .tool-icon {
    display: inline-block;
    vertical-align: middle;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    stroke: currentColor;
}


/* ---------------------------------------------------------------------------
   SPINNER — small, uses type color
   --------------------------------------------------------------------------- */

.tool-call .spinner {
    border: 1.5px solid var(--bg-tertiary);
    border-top-color: var(--tc-accent);
    border-radius: 50%;
    width: 8px;
    height: 8px;
    animation: spin 1s linear infinite;
}


/* ---------------------------------------------------------------------------
   COMPLETION MESSAGE — inline, muted
   --------------------------------------------------------------------------- */

.tool-call .completion-message {
    display: none;
    font-size: 10px;
    color: var(--text-tertiary);
    white-space: nowrap;
}


/* ---------------------------------------------------------------------------
   TOGGLE BUTTON (chevron)
   --------------------------------------------------------------------------- */

.thoughts-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    color: var(--text-tertiary);
    transition: color 0.15s, background-color 0.15s;
    line-height: 1;
}

.thoughts-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.chevron-icon {
    width: 10px;
    height: 10px;
    transition: transform 0.2s ease;
}


/* ---------------------------------------------------------------------------
   EXPANDABLE CONTAINERS — thoughts & results
   --------------------------------------------------------------------------- */

.thoughts-container,
.results-container {
    margin-top: 4px;
    padding: 6px 0 6px 10px;
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    line-height: 1.4;
    font-size: 11px;
}


/* ---------------------------------------------------------------------------
   AGENT flex layout (shared with .tool-start — preserved here as safety net)
   --------------------------------------------------------------------------- */

.agent {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}


/* ---------------------------------------------------------------------------
   TOOL START — agent/model separator line
   Moved here from styles.css. Remove the original block from styles.css.
   --------------------------------------------------------------------------- */

.tool-start {
    display: flex;
    align-items: center;
    margin: 6px 0 3px 0;
    font-size: 11px;
    line-height: 1.4;
    color: var(--system-message-text);
    position: relative;
    padding-bottom: 2px;
}

.tool-start::before,
.tool-start::after {
    content: "";
    flex-grow: 1;
    height: 1px;
    background-color: var(--system-message-text);
    opacity: 0.6;
}

.tool-start .agent {
    font-weight: bold;
    color: var(--system-message-text);
    display: flex;
    align-items: center;
    padding: 1px 4px 1px 8px;
    white-space: nowrap;
    margin-bottom: 0;
}

.tool-start .agent svg {
    margin-right: 4px;
}

.tool-start .model {
    color: var(--text-tertiary);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 1px 8px 1px 4px;
    white-space: nowrap;
}

[data-theme="dark"] .tool-start {
    opacity: 0.8;
}

.tool-start.loading .agent svg {
    animation: sparkle-pulse 1.5s ease-in-out infinite;
    transform-origin: center center;
}

/* Instructions button (appears alongside tool-start) */
.agent-instructions-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-tertiary);
    font-size: 10px;
    padding: 2px 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
    margin: 0 0 3px 0;
    vertical-align: middle;
    transition: color 0.15s, border-color 0.15s;
}

.agent-instructions-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.agent-instructions-btn svg {
    width: 10px;
    height: 10px;
}


/* ---------------------------------------------------------------------------
   THOUGHT CONTENT — flowing text, no per-item cards
   --------------------------------------------------------------------------- */

.thought-content {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 11px;
    line-height: 1.5;
    padding: 0;
    margin: 0;
}

/* Tighten markdown elements inside thoughts */
.thought-content p {
    margin: 2px 0;
}

.thought-content p:first-child {
    margin-top: 0;
}

.thought-content p:last-child {
    margin-bottom: 0;
}

.thought-content ul,
.thought-content ol {
    margin: 2px 0;
    padding-left: 16px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   CODE EXECUTION — dark terminal box with blinking cursor
   ═══════════════════════════════════════════════════════════════════════════ */

.tool-call.code-execution {
    border-left: 2px solid var(--tc-accent);
    background-color: #0d0d0d;
    border-radius: 4px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
    padding: 6px 10px 10px 10px;
    min-height: 52px;
}

.tool-call.code-execution .tool-call-action { color: var(--tc-accent); }
.tool-call.code-execution .spinner          { border-top-color: var(--tc-accent); }
.tool-call.code-execution .results-container { border-left: none; }
.tool-call.code-execution .completion-message { color: rgba(255, 255, 255, 0.35); }

/* Label in monospace to reinforce terminal feel */
.tool-call.code-execution .tool-call-label {
    font-family: 'Courier New', monospace;
}

/* Terminal cursor line */
.tool-call.code-execution .terminal-cursor-line {
    display: block;
    margin-top: 6px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--tc-accent);
    line-height: 1.4;
    opacity: 0.7;
}

.tool-call.code-execution .terminal-cursor-line .prompt-char {
    color: var(--tc-accent);
    margin-right: 2px;
}

.tool-call.code-execution .terminal-cursor-line .blinking-cursor {
    display: inline-block;
    width: 7px;
    height: 13px;
    background-color: var(--tc-accent);
    vertical-align: text-bottom;
    animation: terminal-blink 1s step-end infinite;
}

/* Hide cursor line once completed */
.tool-call.code-execution.completed .terminal-cursor-line {
    display: none;
}

@keyframes terminal-blink {
    0%, 100% { opacity: 0.8; }
    50%      { opacity: 0; }
}

[data-theme="light"] .tool-call.code-execution {
    background-color: #f0f2f1;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
    border-left-color: var(--tc-accent);
}

[data-theme="light"] .tool-call.code-execution .terminal-cursor-line {
    color: var(--tc-accent);
}

[data-theme="light"] .tool-call.code-execution .terminal-cursor-line .blinking-cursor {
    background-color: var(--tc-accent);
}

[data-theme="light"] .tool-call.code-execution .completion-message {
    color: var(--text-tertiary);
}


/* ═══════════════════════════════════════════════════════════════════════════
   ERROR STATE (applied dynamically by updateToolCallWithError)
   ═══════════════════════════════════════════════════════════════════════════ */

.tool-call.tool-call-error {
    border-left-color: var(--tc-error) !important;
    background-color: var(--tc-error-bg) !important;
}

.tool-call.tool-call-error .tool-call-action {
    color: var(--tc-error) !important;
}

.tool-call.tool-call-error .tool-icon {
    stroke: var(--tc-error) !important;
}

.tool-call.tool-call-error .completion-message {
    color: var(--tc-error) !important;
}

.tool-call.tool-call-error .thoughts-toggle:hover {
    color: var(--tc-error) !important;
}

.tool-call.tool-call-error .results-container {
    border-left-color: var(--tc-error);
}


/* ── Standalone error (no parent tool call) ── */

.tool-call-error-standalone {
    margin: 4px 0;
    padding: 4px 8px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--tc-error);
    border-left: 2px solid var(--tc-error);
    background-color: var(--tc-error-bg);
    border-radius: 2px;
}


/* ── Code execution result / error content (inside results-container) ── */

.code-result-content {
    font-style: italic;
    color: var(--text-secondary);
    background-color: transparent;
    padding: 2px 0;
    margin: 0;
    border-radius: 0;
    display: block;
    font-size: 11px;
    line-height: 1.4;
}

.code-result-content.error-result {
    color: var(--tc-error) !important;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-label {
    font-weight: 600;
    color: var(--text-primary);
    font-style: normal;
}

.code-label.error {
    color: var(--tc-error);
}


/* ── Search result content (inside results-container) ── */

.search-result-content {
    font-style: italic;
    color: var(--text-secondary);
    background-color: transparent;
    padding: 2px 0;
    margin: 0;
    border-radius: 0;
    display: block;
    font-size: 11px;
    line-height: 1.4;
}

.search-label {
    font-weight: 600;
    color: var(--text-primary);
    font-style: normal;
}

.search-code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 2px;
    font-family: monospace;
    font-size: 0.85em;
    font-style: normal;
}

[data-theme="dark"] .search-code {
    background: rgba(255, 255, 255, 0.06);
}


/* ── Assistant consultation content (inside results-container) ── */

.assistant-consultation-content {
    font-style: italic;
    color: var(--text-secondary);
    background-color: transparent;
    padding: 2px 0;
    margin: 0;
    border-radius: 0;
    display: block;
    font-size: 11px;
    line-height: 1.5;
}

.assistant-consultation-content p {
    margin: 2px 0;
}

.assistant-consultation-content p:first-child { margin-top: 0; }
.assistant-consultation-content p:last-child  { margin-bottom: 0; }

.assistant-consultation-content ul,
.assistant-consultation-content ol {
    margin: 2px 0;
    padding-left: 16px;
}

.assistant-consultation-content li       { margin-bottom: 2px; }
.assistant-consultation-content li:last-child { margin-bottom: 0; }

.assistant-consultation-content strong {
    color: var(--text-primary);
    font-style: normal;
}


/* ---------------------------------------------------------------------------
   DARK-THEME opacity for tool calls (matching tool-start treatment)
   --------------------------------------------------------------------------- */

[data-theme="dark"] .tool-call {
    opacity: 0.9;
}

[data-theme="dark"] .thought-content,
[data-theme="dark"] .search-result-content,
[data-theme="dark"] .code-result-content:not(.error-result),
[data-theme="dark"] .assistant-consultation-content {
    color: var(--text-secondary);
}

[data-theme="dark"] .code-label,
[data-theme="dark"] .search-label,
[data-theme="dark"] .assistant-consultation-content strong {
    color: var(--text-primary);
}


/* ---------------------------------------------------------------------------
   KEYFRAMES — sparkle-pulse for tool-start loading state
   Included here since the module owns .tool-start.loading animation.
   @keyframes spin is NOT included — it lives in styles.css and is shared
   by multiple components (loading overlay, file upload, etc.)
   --------------------------------------------------------------------------- */

@keyframes sparkle-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.15) rotate(15deg);
    }
}