.bam-chat-widget-shell {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    padding: 10px;
    background: rgba(3, 7, 18, 0.88);
    color: #e2e8f0;
}

.bam-chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.bam-chat-widget-header-copy h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
}

.bam-chat-widget-header-copy {
    min-width: 0;
    flex: 1 1 auto;
}

.bam-chat-widget-status {
    margin: 4px 0 0;
    font-size: 11px;
    color: #94a3b8;
}

.bam-chat-widget-status.error {
    color: #fca5a5;
}

.bam-chat-widget-threadbar {
    position: relative;
    display: flex;
    gap: 6px;
    align-items: center;
    min-width: 0;
    flex: 0 1 auto;
}

.bam-chat-widget-thread-toggle,
.bam-chat-widget-thread-new,
.bam-chat-widget-thread-row-select,
.bam-chat-widget-thread-row-delete,
.bam-chat-widget-composer button {
    border: 1px solid rgba(71, 85, 105, 0.6);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.7);
    color: #cbd5e1;
    font-size: 11px;
    padding: 6px 10px;
    cursor: pointer;
}

.bam-chat-widget-thread-toggle {
    max-width: 220px;
    min-width: 130px;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow: hidden;
}

.bam-chat-widget-thread-toggle span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bam-chat-widget-thread-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 30;
    width: min(320px, 55vw);
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid rgba(71, 85, 105, 0.8);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.96);
    padding: 6px;
    box-shadow: 0 10px 26px rgba(2, 6, 23, 0.45);
}

.bam-chat-widget-thread-menu.hidden {
    display: none;
}

.bam-chat-widget-thread-new {
    width: 100%;
    text-align: left;
    margin-bottom: 6px;
}

.bam-chat-widget-thread-items {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bam-chat-widget-thread-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
}

.bam-chat-widget-thread-row.active .bam-chat-widget-thread-row-select {
    border-color: rgba(59, 130, 246, 0.7);
    color: #dbeafe;
}

.bam-chat-widget-thread-row-select {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bam-chat-widget-thread-row-delete {
    width: 30px;
    padding: 6px 0;
}

.bam-chat-widget-thread-toggle:hover,
.bam-chat-widget-thread-new:hover,
.bam-chat-widget-thread-row-select:hover,
.bam-chat-widget-thread-row-delete:hover,
.bam-chat-widget-composer button:hover {
    background: rgba(30, 41, 59, 0.9);
}

.bam-chat-widget-composer button:disabled {
    opacity: 0.65;
    cursor: default;
}

.bam-chat-widget-shell.interaction-locked .bam-chat-widget-history {
    opacity: 0.72;
}

.bam-chat-widget-thread-items.disabled {
    opacity: 0.7;
}

.bam-chat-widget-history {
    border: 1px solid rgba(51, 65, 85, 0.85);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.62);
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.bam-chat-widget-empty {
    color: #94a3b8;
    font-size: 12px;
    margin: 2px 0;
}

.bam-chat-widget-item {
    border-radius: 8px;
    padding: 7px 8px;
    font-size: 12px;
    line-height: 1.35;
    white-space: pre-wrap;
    word-break: break-word;
}

.bam-chat-widget-item.user {
    background: #1d4ed8;
    color: #dbeafe;
}

.bam-chat-widget-item.assistant {
    background: rgba(34, 197, 94, 0.24);
    color: #dcfce7;
}

.bam-chat-widget-item.assistant.thinking {
    background: rgba(15, 23, 42, 0.7);
    color: #cbd5e1;
}

.bam-chat-widget-item.system {
    background: rgba(67, 56, 202, 0.45);
    color: #e0e7ff;
}

.bam-chat-widget-meta {
    display: block;
    opacity: 0.85;
    font-size: 10px;
    margin-bottom: 4px;
}

.bam-chat-widget-thinking-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.bam-chat-widget-thinking-spinner {
    width: 11px;
    height: 11px;
    border: 2px solid #94a3b8;
    border-top-color: transparent;
    border-radius: 50%;
    animation: bam-chat-widget-spin 0.85s linear infinite;
}

@keyframes bam-chat-widget-spin {
    to {
        transform: rotate(360deg);
    }
}

.bam-chat-widget-composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.bam-chat-widget-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #cbd5e1;
    padding: 0 2px;
}

.bam-chat-widget-loading.hidden {
    display: none;
}

.bam-chat-widget-loading-spinner {
    width: 11px;
    height: 11px;
    border: 2px solid #94a3b8;
    border-top-color: transparent;
    border-radius: 50%;
    animation: bam-chat-widget-spin 0.85s linear infinite;
}

.bam-chat-widget-composer textarea {
    border: 1px solid rgba(51, 65, 85, 0.9);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.72);
    color: #e2e8f0;
    font-size: 12px;
    padding: 8px;
    resize: none;
    min-height: 58px;
    max-height: 180px;
    font-family: inherit;
}

.bam-chat-widget-composer textarea:focus {
    outline: 1px solid #3b82f6;
    border-color: #3b82f6;
}

.bam-chat-widget-composer textarea:disabled {
    background: rgba(15, 23, 42, 0.7);
    color: #94a3b8;
    cursor: not-allowed;
}
