/* ============================================================ */
/* Prompt View — chat-style redesign                            */
/* Uses tokens from common.css. All new classes prefixed pv-.   */
/* ============================================================ */

/* ---------- Page container ---------- */
.pv-page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 4px;
}

/* ---------- Card ---------- */
.pv-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    margin-bottom: 16px;
}

/* ---------- Prompt details card ---------- */
.pv-prompt-card {
    padding: 14px 18px;
}

.pv-prompt-card__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.pv-prompt-card__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
}

.pv-id-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-panel-alt);
    padding: 2px 8px;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Form row (label + control) ---------- */
.pv-form-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 8px 14px;
    align-items: center;
    margin-bottom: 8px;
}

.pv-form-row > label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0;
}

.pv-form-row textarea.form-control {
    resize: vertical;
}

.pv-form-row--modal {
    grid-template-columns: 140px 1fr;
    align-items: start;
}

.pv-form-row--modal > label {
    padding-top: 7px;
}

/* Image output sub-row */
.pv-inline-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.pv-inline-pair__field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pv-inline-pair__field label {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin: 0;
}

/* Model label is clickable (opens model selector modal) */
.ams-open-link {
    cursor: pointer;
    color: var(--link);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}
.ams-open-link:hover {
    color: var(--link-hover);
}

/* ---------- Prompt actions row ---------- */
.pv-prompt-card__actions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.pv-action-buttons {
    display: flex;
    gap: 8px;
}

.pv-link-btn {
    background: none;
    border: none;
    color: var(--link);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 6px 4px;
}
.pv-link-btn:hover {
    text-decoration: underline;
    color: var(--link-hover);
}

/* Dirty Update button — subtle glow when changes are pending */
#update_prompt_btn:not(:disabled) {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

/* ---------- Conversation card ---------- */
.pv-conversation-card {
    padding: 0;
    overflow: hidden;
}

.pv-conversation-card__header {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---------- Message log ---------- */
.pv-messages {
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.pv-messages:empty {
    padding: 0;
}

.pv-msg-row {
    display: flex;
    width: 100%;
}
.pv-msg-row--user {
    justify-content: flex-end;
}
.pv-msg-row--assistant,
.pv-msg-row--system,
.pv-msg-row--chatbot_template {
    justify-content: flex-start;
}

.pv-bubble {
    max-width: 90%;
    border-radius: 12px;
    padding: 8px 12px 10px;
    position: relative;
    border: 1px solid;
    font-size: 0.95rem;
}

.pv-msg-row--user .pv-bubble {
    background: #dcf2dc;
    border-color: #bee4be;
    color: var(--text-body);
    border-bottom-right-radius: 4px;
}

.pv-msg-row--assistant .pv-bubble,
.pv-msg-row--chatbot_template .pv-bubble {
    background: #eef0f3;
    border-color: #dde1e6;
    color: var(--text-body);
    border-bottom-left-radius: 4px;
}

.pv-msg-row--system .pv-bubble {
    background: var(--bg-panel-alt);
    border-color: var(--border-subtle);
    color: var(--text-body);
    border-bottom-left-radius: 4px;
}

/* Edit mode: bubble takes the full width of the conversation card */
.pv-msg-row--editing {
    justify-content: stretch;
}
.pv-msg-row--editing .pv-bubble {
    max-width: 100%;
    width: 100%;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

/* Bottom-row layout: meta (left) + toolbar (right) */
.pv-bubble-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    flex-wrap: wrap;
}

/* Per-message toolbar (rating, comment, edit, delete) — bottom right of bubble */
.pv-msg-toolbar {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 0 0 auto;
    margin-left: auto;
}

.pv-msg-toolbar button {
    background: transparent;
    border: 1px solid transparent;
    height: 24px;
    min-width: 24px;
    padding: 0 6px;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 0.85rem;
    line-height: 1;
}
.pv-msg-toolbar button:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-strong);
}
.pv-msg-toolbar button.pv-msg-toolbar__delete:hover {
    color: var(--status-error);
}
.pv-msg-toolbar .pv-rating-btn.is-rated {
    color: #c98900;
}
.pv-msg-toolbar .pv-rating-btn .pv-rating-value {
    font-size: 0.75rem;
    font-weight: 600;
}

.pv-msg-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.pv-msg-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Rating modal — large numeric pick buttons */
.pv-rating-options {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}
.pv-rating-option {
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border-muted);
    border-radius: 8px;
    background: var(--bg-panel);
    color: var(--text-body);
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
}
.pv-rating-option:hover {
    background: var(--bg-panel-alt);
}
.pv-rating-option.is-active {
    background: var(--link);
    color: var(--text-on-dark);
    border-color: var(--link);
}
.pv-rating-option--clear {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Inline edit textarea inside a bubble */
.pv-msg-edit-textarea {
    width: 100%;
    border: 1px solid var(--border-muted);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    margin-top: 4px;
    resize: vertical;
    min-height: 15em; /* ~10 lines at 1.5 line-height */
}
.pv-msg-edit-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 6px;
}

/* Message attachments inside bubbles */
.pv-msg-assets {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.pv-asset-thumb {
    position: relative;
    display: inline-block;
}
.pv-asset-thumb img {
    height: 140px;
    width: auto;
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    display: block;
    object-fit: contain;
}
.pv-asset-thumb__remove {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--bg-panel);
    border: 1px solid var(--border-muted);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 0.7rem;
    color: var(--status-error);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

/* ---------- Composer ---------- */
.pv-composer {
    border-top: 1px solid var(--border-subtle);
    padding: 12px 18px 14px;
    background: var(--bg-canvas-a);
}

.pv-composer__input {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border-muted);
    border-radius: 10px;
    padding: 8px 10px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.pv-composer__input:focus-within {
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.pv-composer__textarea {
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 4px 2px;
    min-height: 44px;
    max-height: 60vh;
    background: transparent;
    color: var(--text-body);
    width: 100%;
    field-sizing: content;
}

.pv-composer__attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding-top: 2px;
}

.pv-composer__attachments .pv-asset-thumb img {
    height: 140px;
}

.pv-add-asset-btn {
    background: transparent;
    border: 1px dashed var(--border-muted);
    color: var(--text-muted);
    height: 26px;
    width: 26px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.pv-add-asset-btn:hover {
    border-color: var(--link);
    color: var(--link);
}

.pv-composer__buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Disabled state for composer buttons */
.pv-composer__buttons .btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---------- Thinking state ---------- */
.pv-composer__thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px;
    color: var(--text-secondary);
    font-style: italic;
    background: #ffe2c2;
    border: 1px solid #f0b97a;
    border-radius: 10px;
}

.pv-thinking__icon {
    font-size: 1.25rem;
    color: var(--badge-assistant);
    animation: pv-pulse 1.5s ease-in-out infinite;
}

.pv-thinking__label {
    font-size: 0.9rem;
}

.pv-thinking__dots {
    display: flex;
    gap: 4px;
}

.pv-thinking__dots span {
    width: 7px;
    height: 7px;
    background-color: var(--badge-assistant);
    border-radius: 50%;
    animation: pv-bounce 1.4s ease-in-out infinite;
}
.pv-thinking__dots span:nth-child(2) { animation-delay: 0.2s; }
.pv-thinking__dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pv-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.6; transform: scale(1.1); }
}

@keyframes pv-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
    .pv-page {
        padding: 0;
    }
    .pv-form-row,
    .pv-form-row--modal {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .pv-form-row > label,
    .pv-form-row--modal > label {
        padding-top: 0;
    }
    .pv-inline-pair {
        grid-template-columns: 1fr;
    }
    .pv-prompt-card__actions {
        flex-direction: column;
        align-items: stretch;
    }
    .pv-action-buttons {
        justify-content: space-between;
    }
    .pv-action-buttons .btn {
        flex: 1;
    }
    .pv-bubble {
        max-width: 92%;
    }
}
