/* Advice Chat Widget */

.advice-widget {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 1040; /* Above content, below modals (1050) */
    font-family: inherit;
}

/* Toggle button */
.advice-toggle-btn {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: none;
    background: var(--bs-primary, #0d6efd);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.advice-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Resize handle — top-left corner of panel */
.advice-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 24px;
    cursor: nw-resize;
    z-index: 10;
}

.advice-resize-handle::after {
    content: "";
    position: absolute;
    top: 7px;
    left: 7px;
    width: 8px;
    height: 8px;
    border-top: 2px solid rgba(255, 255, 255, 0.4);
    border-left: 2px solid rgba(255, 255, 255, 0.4);
}

/* Chat panel */
.advice-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 400px;
    height: 500px;
    max-height: 80vh;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.75rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel header */
.advice-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bs-primary, #0d6efd);
    color: white;
    flex-shrink: 0;
}

.advice-panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.advice-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.advice-new-chat-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 0.375rem;
    opacity: 0.75;
    transition: opacity 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.advice-new-chat-btn:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.6);
}

.advice-panel-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.advice-panel-close:hover {
    opacity: 1;
}

/* Drag handle visual cue */
.advice-panel-header {
    cursor: grab;
}

.advice-panel-header:active {
    cursor: grabbing;
}

/* Messages area */
.advice-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.advice-welcome {
    text-align: center;
    padding: 1.5rem 0.5rem;
    color: var(--bs-secondary-color, #6c757d);
    font-size: 0.85rem;
}

.advice-welcome p:last-child {
    margin-bottom: 0;
}

/* Message bubbles */
.advice-msg {
    max-width: 85%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.advice-msg-user {
    align-self: flex-end;
    background: var(--bs-primary, #0d6efd);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.advice-msg-assistant {
    align-self: flex-start;
    background: var(--bs-secondary-bg, #e9ecef);
    color: var(--bs-body-color, #212529);
    border-bottom-left-radius: 0.25rem;
}

/* Markdown rendering in assistant messages */
.advice-msg-assistant p {
    margin-bottom: 0.5rem;
}

.advice-msg-assistant p:last-child {
    margin-bottom: 0;
}

.advice-msg-assistant ul,
.advice-msg-assistant ol {
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
}

.advice-msg-assistant code {
    font-size: 0.8rem;
    padding: 0.15rem 0.3rem;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 0.25rem;
}

.advice-msg-assistant pre {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 0.375rem;
    overflow-x: auto;
    font-size: 0.8rem;
}

.advice-msg-assistant pre code {
    background: none;
    padding: 0;
}

/* Streaming indicator */
.advice-msg-streaming::after {
    content: "\25CF"; /* bullet */
    animation: advice-blink 1s infinite;
    margin-left: 2px;
}

@keyframes advice-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Evidence items inline */
.advice-evidence {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.advice-evidence-item {
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.5rem;
    overflow: hidden;
}

.advice-evidence-item img {
    max-width: 200px;
    max-height: 150px;
    width: auto;
    height: auto;
    display: block;
    cursor: pointer;
    border-radius: 0.375rem;
}

.advice-evidence-item img:hover {
    opacity: 0.85;
}

.advice-evidence-caption {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    color: var(--bs-secondary-color, #6c757d);
    background: var(--bs-tertiary-bg, #f8f9fa);
}

/* Worker status bar */
.advice-worker-status {
    padding: 0.5rem 1rem;
    background: var(--bs-info-bg-subtle, #cff4fc);
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.advice-worker-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--bs-info-text-emphasis, #055160);
}

/* Input area */
.advice-input-area {
    padding: 0.75rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    flex-shrink: 0;
}

.advice-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.advice-input {
    flex: 1;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 1rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    overflow: hidden;
}

.advice-input:focus {
    border-color: var(--bs-primary, #0d6efd);
    box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.15);
}

.advice-send-btn {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: none;
    background: var(--bs-primary, #0d6efd);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.advice-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.advice-send-btn:hover:not(:disabled) {
    opacity: 0.85;
}

/* Error message style */
.advice-msg-error {
    align-self: center;
    background: var(--bs-danger-bg-subtle, #f8d7da);
    color: var(--bs-danger-text-emphasis, #58151c);
    font-size: 0.8rem;
    text-align: center;
}

/* Delegation acknowledgment */
.advice-msg-delegation {
    align-self: center;
    background: var(--bs-info-bg-subtle, #cff4fc);
    color: var(--bs-info-text-emphasis, #055160);
    font-size: 0.8rem;
    text-align: center;
    padding: 0.375rem 0.75rem;
}

/* Responsive: full-width on mobile */
@media (max-width: 576px) {
    .advice-widget {
        bottom: 0;
        right: 0;
        left: 0;
    }

    .advice-panel {
        width: 100%;
        max-height: 80vh;
        border-radius: 0.75rem 0.75rem 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .advice-toggle-btn {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
    }
}
