/**
 * AI Chat Post Block Styles
 * 
 * Mirrors the styling patterns from ai-summary block.
 * Theme overrides can be applied as needed.
 */

/* Main container */
.st-ai-chat {
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 1.5rem;
    background: #fff;
    box-shadow: 0 10px 35px rgba(15, 23, 42, 0.05);
}

/* Header */
.st-ai-chat__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.st-ai-chat__header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
}

.st-ai-chat__header-icon svg {
    width: 25px;
    height: 25px;
}

.st-ai-chat__heading {
    margin: 0;
    flex-grow: 1;
    /* font styles inherited from theme */
}

.st-ai-chat__clear {
    position: relative;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 999px;
    transition: color 0.2s ease;
}

.st-ai-chat__clear:hover,
.st-ai-chat__clear:focus {
    color: #0f172a;
}

.st-ai-chat__clear[hidden] {
    display: none;
}

/* Messages area */
.st-ai-chat__messages {
    min-height: 150px;
    max-height: 350px;
    overflow-y: auto;
    margin-bottom: 1rem;
    font-size: 15px;
}

/* Welcome message */
.st-ai-chat__welcome {
    padding: 1.5rem 1rem;
    text-align: center;
    color: #64748b;
}

.st-ai-chat__welcome p {
    font-size: 0.9rem;
    margin: 0;
}

.st-ai-chat__welcome[hidden] {
    display: none;
}

/* Message bubbles */
.st-ai-chat__message {
    margin-bottom: 0.75rem;
}

.st-ai-chat__message--user {
    display: flex;
    justify-content: flex-end;
}

.st-ai-chat__message--user .st-ai-chat__bubble {
    background: #8ccde4;
    color: #fff;
    border-radius: 10px 10px 0 10px;
    max-width: 85%;
}

.st-ai-chat__message--assistant {
    display: flex;
    justify-content: flex-start;
}

.st-ai-chat__message--assistant .st-ai-chat__bubble {
    background: #f8fafc;
    color: #334155;
    border-radius: 10px 10px 10px 0;
    max-width: 90%;
    border: 1px solid #E5E7EB;
}

.st-ai-chat__bubble {
    padding: 0.75rem 1rem;
    line-height: 1.6;
}

.st-ai-chat__bubble p {
    margin-block-start: 0.5rem;
    margin-block-end: 0.5rem;
    font-size: 15px !important;
}

.st-ai-chat__bubble p:first-child {
    margin-block-start: 0;
}

.st-ai-chat__bubble p:last-child {
    margin-block-end: 0;
}

/* Typing indicator */
.st-ai-chat__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
}

.st-ai-chat__typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: st-chat-typing 1.4s infinite ease-in-out both;
}

.st-ai-chat__typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.st-ai-chat__typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Form */
.st-ai-chat__form {
    position: relative;
}

.st-ai-chat__input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 0.5rem;
    transition: border-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

.st-ai-chat__input-wrapper:focus-within {
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
}

.st-ai-chat__input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.5;
    color: inherit;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 0.375rem 0.5rem;
}

.st-ai-chat__input::placeholder {
    color: #94a3b8;
}

.st-ai-chat__input:focus {
    outline: none;
}

.st-ai-chat__submit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    color: #475569;
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    transition: color 0.3s ease-in-out, border-color 0.3s ease-in-out;
}

.st-ai-chat__submit::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background-image: var(--st-ai-gradient);
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    z-index: 0;
}

.st-ai-chat__submit > * {
    position: relative;
    z-index: 1;
    transition: color 0.3s ease-in-out;
}

.st-ai-chat__submit:hover:not(:disabled) {
    border-color: transparent;
    color: #fff;
}

.st-ai-chat__submit:hover:not(:disabled)::before {
    opacity: 1;
}

.st-ai-chat__submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.st-ai-chat__submit svg {
    width: 16px;
    height: 16px;
}

/* Status messages */
.st-ai-chat__status {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: #475569;
}

.st-ai-chat__status:empty {
    display: none;
}

.st-ai-chat__status--error {
    color: #f04438;
}

/* Footer */
.st-ai-chat__footer {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e5e7eb;
}

.st-ai-chat__disclaimer {
    font-size: 0.75rem;
    color: #6b7280;
    margin: 0;
    text-align: center;
}

/* Editor preview state */
.st-ai-chat--editor {
    opacity: 0.6;
    pointer-events: none;
}

/* Disabled state */
.st-ai-chat--disabled {
    opacity: 0.6;
}

.st-ai-chat--disabled .st-ai-chat__form {
    pointer-events: none;
}

/* Loading state for submit button */
.st-ai-chat__submit.is-loading {
    opacity: 0.8;
    cursor: wait;
}

.st-ai-chat__spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    animation: st-rotate 0.8s linear infinite;
}

.st-ai-chat__submit:not(.is-loading) .st-ai-chat__spinner {
    display: none;
}

@keyframes st-rotate {
    to {
        transform: rotate(360deg);
    }
}

/* Streaming cursor */
.st-ai-chat__cursor {
    display: inline-block;
    margin-left: 2px;
    vertical-align: text-bottom;
}

@keyframes st-chat-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Links in chat bubbles */
.st-ai-chat__bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.st-ai-chat__bubble a:hover {
    opacity: 0.8;
}

.st-ai-chat__message--assistant .st-ai-chat__bubble a {
    color: #0f172a;
    font-weight: 500;
}

/* Lists in chat bubbles */
.st-ai-chat__bubble ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.st-ai-chat__bubble li {
    margin-bottom: 0.25rem;
}

.st-ai-chat__bubble li:last-child {
    margin-bottom: 0;
}
