/*
 * Pipali Styles - Messages Component
 * Includes: message layout, content formatting, streaming animation
 */

/* Messages */
.messages {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

/* User messages styled as contained bubbles */
.user-message {
    align-self: flex-end;
    max-width: 85%;
}

.user-message .message-content {
    background: var(--color-bg-muted);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
}

.message-attachments {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--color-text-muted);
}

.message-attachments svg {
    flex-shrink: 0;
}

/* "Queued" pill on user messages waiting behind an in-flight run */
.message-queued {
    align-self: flex-end;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    padding: 2px 8px;
    border-radius: var(--radius-full, 9999px);
    background: var(--color-bg-muted);
    color: var(--color-text-muted);
    font-size: 11px;
    line-height: 1.4;
    font-style: italic;
}

.message-queued svg {
    flex-shrink: 0;
    opacity: 0.85;
}

/* Assistant messages remain open/clean */
.assistant-message {
    align-self: flex-start;
    max-width: 100%;
}

/* Message action buttons - horizontal bar at bottom-right */
.message-actions {
    position: absolute;
    bottom: -4px;
    right: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.message-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.message-action-btn:hover {
    background: var(--bg-hover);
    color: var(--color-text-secondary);
}

.message-action-btn:active {
    background: var(--bg-active);
}

.message-content {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--color-text);
}

.run-error-message {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 8px;
}

.run-error-message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.run-error-message-icon {
    display: flex;
    color: var(--color-error);
}

.run-error-message-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-error-text);
}

.run-error-message-icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    margin-left: auto;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.run-error-message-icon-button:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--color-text);
}

.run-error-message-text {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--color-text);
    line-height: 1.5;
}

.run-error-message-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.run-error-message-action,
.run-error-message-details-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.run-error-message-action {
    background: var(--color-error);
    color: white;
    border: none;
}

.run-error-message-action:hover {
    background: var(--color-error-text);
}

.run-error-message-details-toggle {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.run-error-message-details-toggle:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.run-error-message-details {
    margin: 12px 0 0 0;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 12px;
    line-height: 1.5;
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.message-content ::selection {
    background: var(--color-selection-bg);
    color: var(--color-selection-text);
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    font-family: var(--font-heading);
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    margin: var(--space-6) 0 var(--space-3) 0;
    color: var(--color-text);
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content h1 { font-size: var(--text-2xl); }
.message-content h2 { font-size: var(--text-xl); }
.message-content h3 { font-size: var(--text-lg); }
.message-content h4 { font-size: var(--text-base); }

.message-content p {
    margin: 0 0 12px 0;
}

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

.message-content pre {
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    margin: 16px 0;
}

.message-content code {
    background: var(--color-bg-muted);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 13px;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content ul, .message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 6px 0;
}

/* Task list checkboxes (GitHub-style checkboxes from remarkGfm) */
.message-content .contains-task-list {
    list-style: none;
    padding-left: 0;
}

.message-content .task-list-item {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
}

.message-content .task-list-item > ul,
.message-content .task-list-item > ol {
    width: 100%;
    margin: 0;
    margin-left: 24px;
}

.message-content .task-list-item > input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    min-width: 16px;
    margin: 3px 0 0 0;
    border: 2px solid var(--color-text-secondary);
    border-radius: 3px;
    background: transparent;
    cursor: default;
    position: relative;
}

.message-content .task-list-item > input[type="checkbox"]:checked {
    background: var(--color-success);
    border-color: var(--color-success);
}

.message-content .task-list-item > input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.message-content a {
    color: var(--color-link);
    text-decoration: none;
}

.message-content a:visited {
    color: var(--color-link-visited);
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
}

.message-content th,
.message-content td {
    padding: 10px 12px;
    text-align: left;
    border: 1px solid var(--color-border);
}

.message-content th {
    background: var(--color-bg-muted);
    font-weight: 600;
    color: var(--color-text);
}

.message-content td {
    background: var(--color-bg-elevated);
}

.message-content tr:hover td {
    background: var(--color-bg-muted);
}

.message-content tbody tr:nth-child(even) td {
    background: var(--color-bg);
}

.message-content tbody tr:nth-child(even):hover td {
    background: var(--color-bg-muted);
}

.message-inline-image {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

/* Message Navigator - floating pill for jumping between user messages */
.message-navigator {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--z-sticky);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

.message-navigator:hover,
.message-navigator.message-navigator-visible {
    opacity: 0.4;
    pointer-events: auto;
}

.message-navigator:hover {
    opacity: 1;
}

.message-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 26px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: color var(--transition-fast), background var(--transition-fast);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.message-nav-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--color-text);
}

.message-nav-btn:active:not(:disabled) {
    background: var(--bg-active);
}

.message-nav-btn-disabled,
.message-nav-btn:disabled {
    color: var(--color-text-muted);
    opacity: 0.35;
    cursor: default;
}

.message-nav-counter {
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
    line-height: 1;
    padding: 0 2px;
    white-space: nowrap;
}

.message-nav-separator {
    opacity: 0.5;
    margin: 0 0.5px;
}

/* Hide navigator on narrow viewports where there's no room in the margin */
@media (max-width: 960px) {
    .message-navigator {
        display: none;
    }
}

/* Streaming Animation */
.streaming {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.streaming-dot {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite;
}

.streaming-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.streaming-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}
