/* ==========================================================================
   UNSLOTH-STYLE TOOLS SYSTEM (WEB SEARCH & PYTHON RUNNER)
   ========================================================================== */

/* Shimmer Effect */
@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.tool-shimmer {
    position: relative;
    overflow: hidden;
}

.tool-shimmer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
    animation: shimmer 1.6s infinite;
}

/* Web Search, Code & Canvas Toggle Pills in Composer (Exact Unsloth Pills) */
.tool-toggle-btn,
.composer-pill-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted, #94a3b8);
    padding: 5px 12px;
    border-radius: 9999px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    user-select: none;
    outline: none;
}

.tool-toggle-btn:hover,
.composer-pill-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main, #f3f4f6);
}

body:not(.dark-theme) .tool-toggle-btn:hover,
body:not(.dark-theme) .composer-pill-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #0f172a;
}

.tool-toggle-btn.active,
.composer-pill-btn.active {
    background: rgba(99, 102, 241, 0.14);
    color: var(--primary, #818cf8);
    border-color: rgba(99, 102, 241, 0.35);
}

body:not(.dark-theme) .tool-toggle-btn.active,
body:not(.dark-theme) .composer-pill-btn.active {
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
    border-color: rgba(99, 102, 241, 0.25);
}

.composer-pill-btn i {
    font-size: 13px;
}

/* Unsloth Plus Menu Dropdown */
.plus-dropdown-wrap {
    position: relative;
    display: inline-block;
}

.unsloth-plus-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    min-width: 220px;
    background: var(--bg-card, #141724);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 16px;
    padding: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: fadeIn 0.15s ease;
}

body:not(.dark-theme) .unsloth-plus-dropdown {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.plus-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main, #e2e8f0);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    width: 100%;
}

body:not(.dark-theme) .plus-menu-item {
    color: #1e293b;
}

.plus-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

body:not(.dark-theme) .plus-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.plus-menu-item.active {
    color: var(--primary, #818cf8);
}

body:not(.dark-theme) .plus-menu-item.active {
    color: #4f46e5;
}

.plus-menu-item i:first-child {
    font-size: 14px;
    width: 16px;
    text-align: center;
    color: var(--text-muted, #94a3b8);
}

.plus-menu-item.active i:first-child {
    color: var(--primary, #818cf8);
}

.plus-menu-item .menu-check {
    margin-left: auto;
    font-size: 12px;
    color: #10b981;
}

.plus-menu-divider {
    height: 1px;
    background: var(--border-color, rgba(255, 255, 255, 0.08));
    margin: 4px 6px;
}

/* Unsloth Generic Tool Card */
.unsloth-tool-card {
    background: var(--bg-card, rgba(255, 255, 255, 0.02));
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: 12px;
    margin: 8px 0;
    overflow: visible; /* Allows hover card to pop out without clipping */
    font-size: 13px;
    transition: all 0.2s ease;
}

body:not(.dark-theme) .unsloth-tool-card {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.unsloth-tool-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
    border-radius: 12px;
}

.unsloth-tool-trigger:hover {
    background: rgba(255, 255, 255, 0.04);
}

body:not(.dark-theme) .unsloth-tool-trigger:hover {
    background: rgba(0, 0, 0, 0.03);
}

.tool-trigger-left {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted, #94a3b8);
    font-size: 13px;
    min-width: 0;
    flex: 1;
}

.tool-status-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.tool-status-icon.running {
    color: var(--text-muted, #94a3b8);
}

.tool-status-icon.complete {
    color: #10b981;
}

.tool-status-icon.error {
    color: #ef4444;
}

.tool-trigger-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted, #94a3b8);
}

.tool-trigger-label strong {
    color: var(--text-main, #f3f4f6);
    font-weight: 500;
}

body:not(.dark-theme) .tool-trigger-label strong {
    color: #0f172a;
}

.tool-trigger-chevron {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    margin-left: 8px;
}

.unsloth-tool-card.collapsed .tool-trigger-chevron {
    transform: rotate(-90deg);
}

.unsloth-tool-card.collapsed .unsloth-tool-content {
    display: none;
}

.unsloth-tool-content {
    padding: 8px 12px 12px 34px; /* Unsloth pl-5 aligned under label */
    border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.05));
}

body:not(.dark-theme) .unsloth-tool-content {
    border-top-color: #f1f5f9;
}

/* Source Badges (Exact Unsloth Sources Group) */
.unsloth-sources-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    position: relative;
}

.source-badge-item {
    position: relative;
    display: inline-block;
}

.unsloth-source-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 9999px;
    padding: 3px 10px;
    color: var(--text-main, #e2e8f0);
    text-decoration: none;
    font-size: 12px;
    max-width: 240px;
    transition: all 0.15s ease;
}

body:not(.dark-theme) .unsloth-source-badge {
    background: #ffffff;
    border-color: #e2e8f0;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.unsloth-source-badge:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: var(--primary, #818cf8);
    color: #ffffff;
    transform: translateY(-1px);
}

body:not(.dark-theme) .unsloth-source-badge:hover {
    background: rgba(99, 102, 241, 0.08);
    color: #4f46e5;
}

.source-badge-favicon {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

.source-badge-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

/* Unsloth Sources "+N more" button */
.sources-more-btn {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px dashed var(--border-color, rgba(255, 255, 255, 0.15));
    border-radius: 9999px;
    padding: 3px 9px;
    color: var(--text-muted, #94a3b8);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sources-more-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main, #f3f4f6);
}

body:not(.dark-theme) .sources-more-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: #0f172a;
}

/* Rich Hover Card for Sources (Exact Unsloth Dark Popover) */
.source-hover-popover {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 288px;
    background: #000000 !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 1000;
}

.source-badge-item:hover .source-hover-popover {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.hover-header {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 6px;
}

.hover-favicon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    margin-top: 2px;
    flex-shrink: 0;
}

.hover-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    color: #ffffff;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hover-domain {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 1px;
}

.hover-snippet {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.45;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Code Run Button in Code Block Header */
.code-run-btn {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s ease;
}

.code-run-btn:hover {
    background: rgba(16, 185, 129, 0.25);
    color: #6ee7b7;
    transform: translateY(-1px);
}

.code-run-btn.running {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.4);
    color: #fbbf24;
    cursor: wait;
}

/* Terminal Console Output Component */
.tool-output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted, #94a3b8);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tool-output-copy-btn {
    background: transparent;
    border: none;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.tool-output-copy-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.unsloth-console-output {
    background: #090b10;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px 12px;
    max-height: 260px;
    overflow-y: auto;
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    line-height: 1.55;
    color: #f3f4f6;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.console-stderr {
    color: #f87171;
}

.console-images-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.console-img-artifact {
    max-width: 100%;
    max-height: 360px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ==========================================================================
   UNSLOTH AGENT TOOL STREAM PILLS (Used tool: edit_file / terminal)
   ========================================================================== */

.unsloth-tool-stream {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0 12px 0;
    width: 100%;
}

.unsloth-tool-item {
    border-radius: 8px;
    background: transparent;
    transition: all 0.15s ease;
    overflow: hidden;
    font-size: 13px;
}

.unsloth-tool-header {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    color: var(--text-muted, #94a3b8);
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.unsloth-tool-header:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main, #f3f4f6);
}

body:not(.dark-theme) .unsloth-tool-header {
    color: #475569;
}

body:not(.dark-theme) .unsloth-tool-header:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.unsloth-tool-header .tool-icon {
    font-size: 12px;
    color: #10b981; /* Green tick icon like Unsloth */
}

.unsloth-tool-header.terminal-header .tool-icon {
    color: #a855f7;
}

.unsloth-tool-header.running .tool-icon {
    color: var(--primary, #6366f1);
}

.unsloth-tool-header .tool-name-highlight {
    font-weight: 600;
    color: var(--text-main, #f3f4f6);
}

body:not(.dark-theme) .unsloth-tool-header .tool-name-highlight {
    color: #0f172a;
}

.unsloth-tool-header .tool-cmd-preview {
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 6px;
    border-radius: 4px;
}

body:not(.dark-theme) .unsloth-tool-header .tool-cmd-preview {
    background: #e2e8f0;
    color: #334155;
}

.unsloth-tool-header .tool-chevron {
    font-size: 10px;
    color: var(--text-muted, #64748b);
    transition: transform 0.2s ease;
    margin-left: 2px;
}

.unsloth-tool-item.open .unsloth-tool-header .tool-chevron {
    transform: rotate(90deg);
}

.unsloth-tool-body {
    display: none;
    margin-top: 6px;
    margin-left: 14px;
    border-left: 2px solid rgba(255, 255, 255, 0.12);
    padding-left: 12px;
    animation: fadeIn 0.2s ease;
}

body:not(.dark-theme) .unsloth-tool-body {
    border-left-color: #cbd5e1;
}

.unsloth-tool-item.open .unsloth-tool-body {
    display: block;
}

.tool-body-section {
    margin-bottom: 8px;
}

.tool-body-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

body:not(.dark-theme) .tool-body-label {
    color: #64748b;
}

.tool-body-code {
    background: #090b10;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    line-height: 1.5;
    color: #e2e8f0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 240px;
    overflow-y: auto;
}

body:not(.dark-theme) .tool-body-code {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #0f172a;
}

/* Run Automatically Pill in Composer (Unsloth Style) */
.auto-run-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted, #94a3b8);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.auto-run-pill:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main, #f3f4f6);
}

body:not(.dark-theme) .auto-run-pill {
    color: #64748b;
}

body:not(.dark-theme) .auto-run-pill:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.auto-run-pill.active {
    color: var(--text-main, #f3f4f6);
}

.auto-run-pill i.pill-auto-icon {
    font-size: 11px;
    color: #10b981;
}

.auto-run-pill i.chevron {
    font-size: 9px;
    opacity: 0.7;
}
