/* ============================================
   Chat di test agent (/chat-test)
   ============================================ */

html:has(.chat-test-page),
html:has(.chat-test-page) body {
    height: 100%;
    overflow: hidden;
}

.chat-test-page {
    --ct-bg:        var(--color-bg, #f4f6fb);
    --ct-surface:   var(--color-surface, #ffffff);
    --ct-border:    var(--color-border, #e6e9f0);
    --ct-primary:   var(--color-primary, #4a6cf7);
    --ct-muted:     var(--color-text-muted, #6b7280);
    --ct-thought-bg: #f5f7fb;
    --ct-chat-width: 1120px;
    --dark-blue:    var(--color-primary, #4a6cf7);
    --white:        #ffffff;

    margin: 0;
    background: var(--ct-bg);
    color: var(--color-text, #1f2533);
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* ── Login ─────────────────────────────────────────────────────── */

.chat-test-login {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.chat-test-login-card {
    background: var(--ct-surface);
    border: 1px solid var(--ct-border);
    border-radius: var(--radius-lg, 18px);
    box-shadow: 0 12px 40px rgba(16, 24, 40, 0.10);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.chat-test-login-header h1 { font-size: 1.4rem; margin: 0.25rem 0 0.5rem; }

.chat-test-pin-input {
    text-align: center;
    letter-spacing: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    text-transform: uppercase;
}

.chat-test-alert {
    background: var(--color-danger-light, #fde8e8);
    color: var(--color-danger, #dc3545);
    border-radius: var(--radius, 10px);
    padding: 0.6rem 0.8rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    text-align: left;
}

.chat-test-login-footer { margin-top: 1.5rem; font-size: 0.8rem; }

/* ── Header ────────────────────────────────────────────────────── */

.chat-test-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.25rem;
    padding: 0.65rem 1.5rem;
    min-height: 64px;
    background: var(--ct-surface);
    border-bottom: 1px solid var(--ct-border);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-test-header-brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
}

.chat-test-header-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text, #1e293b);
    white-space: nowrap;
}

.chat-test-pin-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ct-muted);
    background: var(--ct-bg);
    border: 1px solid var(--ct-border);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-test-pin-badge i {
    font-size: 0.65rem;
    color: var(--color-primary, #2563eb);
    opacity: 0.9;
}

.chat-test-header-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-test-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-test-field-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ct-muted);
    line-height: 1;
    margin: 0;
}

.chat-test-agent-select {
    min-width: 240px;
    max-width: 320px;
    border-color: var(--ct-border);
    border-radius: var(--radius, 0.5rem);
    font-size: 0.82rem;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    background-color: var(--ct-bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-test-agent-select:focus {
    border-color: var(--color-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    background-color: #fff;
}

.chat-test-icon-btn.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    border-radius: var(--radius, 0.5rem);
    border: 1px solid var(--ct-border);
    background: var(--ct-bg);
    color: var(--ct-muted);
    line-height: 1;
    box-shadow: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chat-test-icon-btn.btn:hover,
.chat-test-icon-btn.btn:focus {
    background: #fff;
    border-color: #cbd5e1;
    color: var(--color-text, #1e293b);
    box-shadow: none;
}

.chat-test-logout-btn.btn:hover,
.chat-test-logout-btn.btn:focus {
    border-color: #fecaca;
    background: var(--color-danger-light, #fee2e2);
    color: var(--color-danger, #dc2626);
}

.chat-test-toolbar-divider {
    align-self: center;
    width: 1px;
    height: 28px;
    background: var(--ct-border);
    margin: 0 0.15rem;
    flex-shrink: 0;
}

/* ── Main / chat layout ────────────────────────────────────────── */

.chat-test-main {
    --ct-side-panel-width: 360px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    overflow: hidden;
    position: relative;
}

.chat-test-conversation {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#message-container {
    flex: 1;
    overflow-y: auto;
    scrollbar-gutter: stable;
    padding: 1.5rem 1rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
    max-width: var(--ct-chat-width);
    margin: 0 auto;
}

.chat-test-main.side-panels-open .chat-test-conversation {
    margin-right: var(--ct-side-panel-width);
}

.chat-test-main.side-panels-open #message-container,
.chat-test-main.side-panels-open .chat-test-composer {
    max-width: none;
}

.chat-test-main.side-panels-open chat-message .chat-message-container:not(.has-artifact) {
    max-width: 100%;
}

/* Composer */
.chat-test-composer {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: var(--ct-surface);
    border-top: 1px solid var(--ct-border);
    width: 100%;
    max-width: var(--ct-chat-width);
    margin: 0 auto;
    overflow: hidden;
    scrollbar-gutter: stable;
}

.chat-test-composer-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.chat-test-attachment-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.chat-test-file-chip,
chat-message .chat-message-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: #eef1f8;
    color: var(--ct-muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

.chat-test-file-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

chat-message a.chat-message-file-chip {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

chat-message a.chat-message-file-chip:hover {
    text-decoration: underline;
}

.chat-test-file-chip-remove {
    border: 0;
    background: transparent;
    color: inherit;
    padding: 0;
    width: 1rem;
    height: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-test-composer textarea {
    flex: 1;
    width: 100%;
    resize: none;
    overflow-y: auto;
    border: 1px solid var(--ct-border);
    border-radius: 12px;
    padding: 0.6rem 0.9rem;
    font-size: 0.92rem;
    font-family: inherit;
    line-height: 1.5;
    height: 44px;
    min-height: 44px;
    max-height: 12rem;
    box-sizing: border-box;
    background: var(--ct-bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-test-composer textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-test-composer textarea:focus {
    outline: none;
    border-color: var(--ct-primary);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.15);
    background: #fff;
}

.chat-test-composer .btn-primary {
    border-radius: 12px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    line-height: 1;
}

.chat-test-composer .btn-primary.is-busy {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-test-composer .chat-test-icon-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border-radius: 12px;
    flex-shrink: 0;
}

.chat-test-composer .chat-test-icon-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Typing indicator (attesa neutra) ──────────────────────────── */

.kbms-typing {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.1rem 0.1rem;
}

.kbms-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #c2c8d4;
    animation: kbms-bounce 1.2s infinite ease-in-out both;
}

.message-pending {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    margin-top: 0.35rem;
    padding: 0 0.1rem;
}

.message-pending .kbms-dot {
    width: 0.35rem;
    height: 0.35rem;
}

.kbms-dot:nth-child(1) { animation-delay: -0.24s; }
.kbms-dot:nth-child(2) { animation-delay: -0.12s; }

@keyframes kbms-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.chat-message-error .chat-message-text { color: var(--color-danger, #dc3545); }

/* ── Side panels ───────────────────────────────────────────────── */

.chat-test-side-panels {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: none;
    flex-direction: column;
    width: var(--ct-side-panel-width);
    max-width: min(50vw, 640px);
    min-width: 280px;
    min-height: 0;
    overflow: hidden;
    background: var(--ct-surface);
    border-left: 1px solid var(--ct-border);
    box-shadow: -12px 0 28px rgba(16, 24, 40, 0.08);
    pointer-events: none;
}

.chat-test-side-panels.open {
    display: flex;
    pointer-events: auto;
}

.chat-test-side-panels-resizer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    touch-action: none;
}

.chat-test-side-panels-resizer:hover,
.chat-test-side-panels-resizer:focus-visible,
body.is-resizing-side-panel .chat-test-side-panels-resizer {
    background: rgba(74, 108, 247, 0.16);
}

body.is-resizing-side-panel {
    cursor: col-resize;
    user-select: none;
}

.chat-test-citation-bar {
    min-height: 0;
    display: none;
    flex: 1 1 auto;
    flex-direction: column;
    overflow: hidden;
}

.chat-test-citation-bar.open { display: flex; }

/* Dati raccolti: colonna sinistra, collassabile in pill */

.data-collection-card {
    flex: 0 0 280px;
    width: 280px;
    max-width: 36%;
    min-width: 0;
    min-height: 0;
    align-self: flex-start;
    margin: 1rem 0 1rem 1rem;
    max-height: min(70%, 480px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--ct-surface);
    border: 1px solid var(--ct-border);
    border-radius: 14px;
}

.data-collection-card[hidden] {
    display: none;
}

.data-collection-card-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    background: linear-gradient(180deg, #fbfcfe 0%, #f6f8fd 100%);
    border-bottom: 1px solid var(--ct-border);
}

.data-collection-card-title {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--ct-muted);
}

.data-collection-card-title i {
    color: var(--ct-primary);
    font-size: 0.8rem;
}

.data-collection-count {
    min-width: 1.1rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: rgba(74, 108, 247, 0.12);
    color: var(--ct-primary);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.25rem;
}

.data-collection-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 0.3rem 0.85rem 0.6rem;
}

.data-collection-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid #f1f3f8;
}

.data-collection-row:last-child {
    border-bottom: none;
}

.data-collection-label {
    flex: 0 1 auto;
    color: var(--ct-muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: capitalize;
    line-height: 1.4;
}

.data-collection-value {
    flex: 1 1 auto;
    color: var(--color-text, #1f2533);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: right;
    word-break: break-word;
}

.data-collection-pill {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--ct-border);
    border-radius: 999px;
    background: var(--ct-surface);
    color: var(--ct-muted);
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.08);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.data-collection-pill i { color: var(--ct-primary); }

.data-collection-pill:hover {
    background: var(--ct-bg);
    color: var(--color-text, #1f2533);
}

.data-collection-pill[hidden] {
    display: none;
}

.side-panel-header {
    flex: 0 0 auto;
    min-height: 66px;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--ct-surface);
    border-bottom: 1px solid var(--ct-border);
}

.side-panel-header h2 {
    margin: 0.1rem 0 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--color-text, #1f2533);
}

.side-panel-eyebrow {
    display: block;
    color: var(--ct-muted);
    font-size: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.side-panel-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0.85rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.citation-bar-close,
.data-collection-close {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: var(--ct-muted);
    cursor: pointer;
    font-size: 1rem;
}

.citation-bar-row {
    border: 1px solid var(--ct-border);
    border-radius: 12px;
    padding: 0.7rem 0.8rem;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.citation-bar-row.is-clickable { cursor: pointer; }
.citation-bar-row.is-clickable:hover { background: var(--ct-bg); border-color: #d2d9f0; }

.citation-bar-row-title {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    color: var(--ct-primary);
}

.citation-bar-row-meta {
    display: block;
    font-size: 0.72rem;
    color: var(--ct-muted);
    margin-bottom: 0.35rem;
}

.citation-bar-row-link {
    color: var(--ct-primary);
    overflow-wrap: anywhere;
    text-decoration: underline;
}

.citation-bar-row-text {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text, #1f2533);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}

.citation-bar-row-error {
    display: block;
    margin-top: 0.55rem;
    color: var(--color-danger, #dc3545);
    font-size: 0.75rem;
    line-height: 1.35;
}

.artifact-archive-row {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.artifact-archive-row .artifact-card {
    border: 1px solid var(--ct-border);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
}

.artifact-archive-row .artifact-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem 0.45rem;
    background: linear-gradient(180deg, #f7f8ff 0%, #fff 100%);
    border-bottom: 1px solid #eef0f7;
}

.artifact-card-heading {
    min-width: 0;
    flex: 1 1 auto;
}

.artifact-card-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex: 0 0 auto;
}

.artifact-download-btn {
    border: 1px solid #d7dcf0;
    background: #fff;
    color: #3f51b5;
    border-radius: 999px;
    padding: 0.12rem 0.5rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    cursor: pointer;
}

.artifact-download-btn:hover {
    background: #eef1ff;
}

.artifact-card-id {
    color: #8a93a7;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0;
    word-break: break-all;
}

.artifact-archive-row .artifact-card-title {
    margin: 0.1rem 0 0;
    color: #496da6;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.3;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.artifact-archive-row .artifact-field {
    padding: 0.68rem 0.7rem;
    border-top: 1px solid #e6e9f4;
}

.artifact-archive-row h4.artifact-field-label,
.artifact-archive-row .artifact-field-label {
    margin: 0 0 0.2rem;
    color: #496da6;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.25;
    text-transform: none;
}

.artifact-archive-row .artifact-card-eyebrow {
    display: block;
    color: #5b6bd6;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.artifact-archive-row .artifact-prose {
    color: #1f2533;
    font-size: var(--base-len);
    line-height: 1.5;
}

.artifact-archive-row .artifact-prose:not(.is-markdown),
.artifact-archive-row .artifact-value :is(.is-markdown, .preserve-whitespace) {
    white-space: pre-wrap;
}

.artifact-archive-row .artifact-prose p {
    margin-bottom: 0.28rem;
}

.artifact-archive-row .artifact-prose :is(h1, h2, h3, h4, h5, h6),
.artifact-archive-row .artifact-prose :is(strong, b) {
    margin: 0.36rem 0 0.18rem;
    color: #1f2533;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.4;
}

.artifact-archive-row .artifact-prose :is(strong, b) {
    margin: 0;
    font-size: inherit;
    line-height: inherit;
    letter-spacing: 0;
}

.artifact-archive-row .artifact-prose :is(ul, ol) {
    margin: 0.16rem 0;
    padding-left: 1.15rem;
}

.artifact-archive-row .artifact-prose li {
    margin-bottom: 0.13rem;
    line-height: 1.5;
}

.artifact-archive-row .artifact-list {
    margin: 0;
    padding-left: 1.1rem;
}

.artifact-archive-row .artifact-list li {
    margin-bottom: 0.13rem;
    line-height: 1.5;
}

.artifact-archive-row .artifact-list :is(strong, b) {
    font-weight: 700;
    color: #1f2533;
}

.artifact-archive-row .artifact-metric {
    display: inline-flex;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: #eef1ff;
    color: #3f51b5;
    font-size: 0.78rem;
    font-weight: 700;
}

/* ── Source trace (agent → KB) ──────────────────────────────────── */

.source-trace-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-top: 0.45rem;
    padding-top: 0.35rem;
}

.source-trace-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--ct-muted);
}

.source-trace-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.source-trace-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    line-height: 1.2;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    border: 1px solid #dbe3f5;
    background: #f5f7fc;
    color: #334155;
    max-width: 100%;
    word-break: break-word;
    gap: 0.2rem;
}

.source-trace-part {
    position: relative;
}

.source-trace-part.is-interactive {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 0.15em;
}

.source-trace-part.is-interactive:hover,
.source-trace-part.is-interactive:focus-visible {
    color: #1e3a5f;
}

.integration-trace-bar {
    display: block;
    width: 100%;
    margin-top: 0.65rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--ct-border);
}

.integration-trace-bar > .source-trace-title {
    display: block;
    margin-bottom: 0.4rem;
}

.integration-trace-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.integration-trace-group {
    overflow: hidden;
    border: 1px solid #dde3ef;
    border-left: 3px solid #8798e8;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.72);
}

.integration-trace-heading {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.65rem 0.28rem;
}

.integration-trace-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 7px;
    background: #eef1ff;
    color: #5265c8;
    font-size: 0.68rem;
}

.integration-trace-identity {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 0;
}

.integration-trace-agent {
    overflow: hidden;
    color: #334155;
    font-size: 0.73rem;
    font-weight: 650;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.integration-trace-service {
    color: var(--ct-muted);
    font-size: 0.68rem;
    line-height: 1.25;
}

.integration-methods-disclosure {
    border-top: 1px solid #edf0f6;
}

.integration-methods-summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.38rem 0.65rem;
    color: #596579;
    font-size: 0.69rem;
    font-weight: 600;
    list-style: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.integration-methods-summary::-webkit-details-marker {
    display: none;
}

.integration-methods-summary::before {
    content: "";
    width: 5px;
    height: 5px;
    border: solid #8798e8;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}

.integration-methods-disclosure[open] > .integration-methods-summary::before {
    transform: rotate(45deg);
}

.integration-methods-summary:hover {
    background: #f8f9fc;
    color: #43518f;
}

.integration-method-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.1rem 0.55rem 0.5rem;
}

.integration-method-chip {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    max-width: 100%;
    padding: 0.38rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #f6f7fb;
    color: #43518f;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.46rem;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.integration-method-chip:hover,
.integration-method-chip:focus-visible {
    border-color: #b9c3f0;
    background: #eef1ff;
    color: #3446a4;
}

.integration-method-chip > span {
    overflow-wrap: anywhere;
}

.integration-method-chip > .fa-code {
    color: #8798e8;
    font-size: 0.58rem;
}

.integration-method-chip > .fa-chevron-right {
    color: #aab3c4;
    font-size: 0.52rem;
}

.integration-detail-label {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ct-muted);
}

.integration-detail-pre {
    margin: 0.3rem 0 0;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    background: var(--ct-bg);
    border: 1px solid var(--ct-border);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 40vh;
    overflow: auto;
}

.integration-detail-pre.is-json .json-key { color: #7c3aed; }
.integration-detail-pre.is-json .json-string { color: #087f5b; }
.integration-detail-pre.is-json .json-number { color: #2563eb; }
.integration-detail-pre.is-json .json-boolean { color: #c2410c; }
.integration-detail-pre.is-json .json-null { color: #64748b; font-style: italic; }

.source-trace-tooltip {
    position: absolute;
    left: 0;
    bottom: calc(100% + 6px);
    z-index: 30;
    width: max-content;
    max-width: min(22rem, calc(100vw - 2rem));
    max-height: 8.5rem;
    overflow: hidden;
    padding: 0.32rem 0.7rem;
    border-radius: 6px;
    background: #1e293b;
    color: #f8fafc;
    font-size: 0.72rem;
    line-height: 1.35;
    text-align: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
    pointer-events: none;
}

.source-trace-tooltip-name {
    display: block;
    font-weight: 700;
    margin-bottom: 0.12rem;
}

.source-trace-tooltip-body {
    display: -webkit-box;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #cbd5e1;
}

.source-info-name {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
}

.source-info-description {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #334155;
    white-space: pre-wrap;
    word-break: break-word;
}

.source-info-description.is-empty {
    color: var(--ct-muted);
    font-style: italic;
}

/* ── Thought panel (ragionamento agent) ────────────────────────── */

.thought-panel {
    align-self: flex-start;
    background: var(--ct-thought-bg);
    border: 1px solid #e4e8f2;
    border-radius: 10px;
    padding: 0.55rem 0.8rem;
    margin: 0.15rem 0 0.35rem;
    max-width: 86%;
    font-size: 0.82rem;
    color: var(--ct-muted);
}

.thought-panel.is-streaming {
    border-color: #d4daf0;
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.08);
}

.thought-panel.is-streaming .thought-panel-summary span::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 0.35rem;
    border-radius: 50%;
    background: #4a6cf7;
    animation: kbms-bounce 1.2s infinite ease-in-out both;
    vertical-align: middle;
}

.thought-panel-summary {
    cursor: pointer;
    font-weight: 700;
    user-select: none;
    color: #5b6472;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.thought-panel-summary::-webkit-details-marker { display: none; }
.thought-panel-summary i { color: #f0a500; }

.thought-panel-list {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.thought-line {
    display: flex;
    gap: 0.45rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 0.15rem 0;
    border-top: 1px solid #ebeef5;
}

.thought-line:first-child { border-top: none; }
.thought-ico { flex-shrink: 0; }
.thought-txt { min-width: 0; }

.thought-line code {
    background: rgba(74, 108, 247, 0.08);
    color: #3f51b5;
    padding: 0.05rem 0.3rem;
    border-radius: 0.3rem;
    font-size: 0.76rem;
    word-break: break-all;
}

.thought-todos .thought-txt { white-space: normal; }

.thought-todos-title {
    font-weight: 650;
    color: #475569;
    margin-bottom: 0.25rem;
}

.thought-todos-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.thought-todo {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    line-height: 1.4;
}

.thought-todo-status {
    flex: 0 0 auto;
    font-size: 0.68rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: #eef2f7;
    color: #64748b;
}

.thought-todo-name { min-width: 0; }

.thought-todo.is-in-progress .thought-todo-status {
    background: #e8eeff;
    color: #3f51b5;
}

.thought-todo.is-in-progress .thought-todo-name {
    color: #334155;
    font-weight: 600;
}

.thought-todo.is-completed .thought-todo-status {
    background: #e8f6ee;
    color: #1f7a46;
}

.thought-todo.is-completed .thought-todo-name {
    color: #64748b;
    text-decoration: line-through;
}

.thought-todo.is-cancelled .thought-todo-status {
    background: #f3f4f6;
    color: #94a3b8;
}

.thought-todo.is-cancelled .thought-todo-name {
    color: #94a3b8;
    text-decoration: line-through;
}

@media (max-width: 768px) {
    .chat-test-side-panels {
        min-width: 240px;
        max-width: min(50vw, 640px);
    }

    .data-collection-card {
        flex-basis: min(220px, 42vw);
        width: min(220px, 42vw);
        max-width: 42%;
        margin: 0.75rem 0 0.75rem 0.75rem;
    }

    .chat-test-main.side-panels-open .chat-test-conversation,
    .chat-test-main.data-collection-open .chat-test-conversation {
        margin-right: 0;
        margin-left: 0;
        display: flex;
    }

    .chat-test-main.side-panels-open #message-container,
    .chat-test-main.side-panels-open .chat-test-composer {
        max-width: var(--ct-chat-width);
    }

    .chat-test-main.side-panels-open chat-message .chat-message-container:not(.has-artifact) {
        max-width: 78%;
    }

    .chat-test-header {
        padding: 0.6rem 1rem;
        gap: 0.75rem;
    }

    .chat-test-header-brand {
        flex: 1;
        min-width: 0;
    }

    .chat-test-header-title {
        font-size: 0.95rem;
    }

    .chat-test-pin-badge {
        max-width: 140px;
    }

    .chat-test-header-toolbar {
        width: 100%;
        justify-content: flex-end;
    }

    .chat-test-agent-select {
        min-width: 0;
        flex: 1;
        max-width: none;
    }

    .chat-test-toolbar-divider { display: none; }
}
