/* Refinement UI Styles (Sidebars and Tooltips) */

/* Refinement Sidebar */
.refine-sidebar {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border-light);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.refine-sidebar.active {
    transform: translateX(0);
}

.refine-sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.refine-sidebar-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.refine-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.refine-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: var(--space-3);
    letter-spacing: 0.05em;
}

.refine-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.refine-suggestion-chip {
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.refine-suggestion-chip:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
    color: var(--color-text-primary);
}

.refine-input-wrapper {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-top: auto;
}

.refine-input-wrapper:focus-within {
    border-color: var(--color-gray-700);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.refine-sidebar-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    min-height: 80px;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
}

.refine-sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--color-border-light);
}

/* Floating Selection Refinement */
.selection-refine-bar {
    position: fixed;
    background: var(--color-surface-elevated);
    backdrop-filter: blur(12px);
    border: 1px solid var(--color-border-medium);
    border-radius: 100px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 6px;
    padding-left: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.selection-refine-icon {
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 4px;
}

.selection-refine-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
}

.selection-refine-divider {
    width: 1px;
    height: 16px;
    background: var(--color-border-medium);
    margin: 0 4px;
}

.selection-refine-input {
    background: transparent;
    border: none;
    padding: 4px 8px;
    font-size: 14px;
    width: 220px;
    outline: none;
    color: var(--color-text-primary);
    font-weight: 500;
}

#selection-refine-submit {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
}

#selection-refine-submit:hover {
    transform: scale(1.1);
    background: var(--color-primary-hover);
}

#selection-refine-submit svg {
    width: 16px;
    height: 16px;
    stroke-width: 3;
}

/* Temporary highlight for selection */
.temp-selection-highlight {
    background-color: rgba(var(--color-primary-rgb), 0.2);
    border-bottom: 2px solid var(--color-primary);
    border-radius: 2px;
    transition: background-color 0.3s ease;
}

/* Integrated Refinement Sidebar */
.chat-interface.refining .chat-messages {
    padding-right: var(--space-2);
}

.chat-interface.refining .chat-messages-inner,
.chat-interface.refining .chat-message-ai {
    max-width: 1100px;
    width: 100%;
}

.chat-interface.refining .chat-message-ai .message-bubble {
    max-width: 100%;
    width: 100%;
}

.message-script-body {
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    min-height: 0;
    flex: 1;
}

.message-script-content-container {
    width: 720px;
    /* Adjusted to match original 80% of 900px max-width */
    max-width: 100%;
    /* Ensure it doesn't overflow on small screens */
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Adjust for smaller desktop/laptops */
@media (max-width: 1280px) {
    .message-script-content-container {
        width: 640px;
        /* Slightly narrower to fit sidebars better */
    }
}

@media (max-width: 1024px) {
    .message-script-content-container {
        width: 560px;
        /* More compact for small desktops */
    }
}

.integrated-refine-container {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    flex-shrink: 0;
    position: sticky;
    top: var(--space-4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.refine-suggestions-box,
.refine-input-box {
    background: var(--color-bg-secondary);
    border-radius: 28px;
    padding: var(--space-5) var(--space-6);
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
}

.refine-box-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: var(--space-4);
    text-transform: uppercase;
}

.integrated-refine-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.integrated-refine-suggestion-item {
    font-size: 14px;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-1) 0;
    transition: all 0.2s;
    line-height: 1.5;
}

.integrated-refine-suggestion-item:hover {
    color: var(--color-primary);
    transform: translateX(4px);
}

.integrated-refine-input {
    width: 100%;
    min-height: 80px;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: 14px;
    resize: none;
    outline: none;
    padding: 0;
}

.integrated-refine-submit-pill {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.integrated-refine-submit-pill:hover:not(:disabled) {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
}

.integrated-refine-submit-pill:disabled {
    cursor: not-allowed;
    background: var(--color-gray-200);
    color: var(--color-text-tertiary);
}

[data-theme='dark'] .integrated-refine-submit-pill:disabled {
    background: rgba(255, 255, 255, 0.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Refinement Preview – match editor structure so preview looks like final script */
.message-script-wrapper.in-preview .message-script-content {
    cursor: default;
}

.message-script-wrapper.in-preview .add-section-divider {
    display: none;
}

.message-script-wrapper.in-preview .script-section-wrapper,
.message-script-wrapper.in-preview .refinement-preview-title-block {
    padding: var(--space-2) 0;
}

.message-script-wrapper.in-preview .script-section-wrapper {
    background: transparent;
    border-radius: var(--radius-md);
}

.message-script-wrapper.in-preview .script-section-title.preview-diff,
.message-script-wrapper.in-preview .script-section-content.preview-diff,
.message-script-wrapper.in-preview .message-script-title-text.preview-diff {
    pointer-events: none;
    user-select: none;
}

.message-script-wrapper.in-preview .script-section-title,
.message-script-wrapper.in-preview .script-section-content,
.message-script-wrapper.in-preview .message-script-title-inline .message-script-title-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.35;
}

.message-script-wrapper.in-preview .script-section-content {
    font-size: 1.05rem;
    font-weight: 400;
    color: var(--color-text-secondary);
    line-height: 1.7;
}

/* Per-section Accept / Reject */
.refinement-section-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding: var(--space-2) 0;
    flex-wrap: wrap;
}

/* Hide Accept/Reject after user has chosen for this section or title */
.refinement-section-actions.resolved,
.refinement-title-actions.resolved {
    display: none;
}

.refinement-section-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.refinement-section-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

.refinement-section-btn i,
.refinement-section-btn svg {
    width: 14px;
    height: 14px;
}

.accept-section-btn:hover {
    border-color: var(--color-success);
    color: var(--color-success);
}

.reject-section-btn:hover {
    border-color: var(--color-error);
    color: var(--color-error);
}

.refinement-preview-title-block {
    margin-bottom: var(--space-4);
}

.refinement-title-actions {
    margin-top: var(--space-2);
}

/* Global refinement bar – compact, consistent with app */
.refinement-preview-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    margin-top: var(--space-4);
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    z-index: 10;
    animation: refinementBarIn 0.25s ease-out;
}

.refinement-preview-label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
}

.refinement-preview-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.refinement-discard-all-btn {
    color: var(--color-text-secondary);
}

.refinement-discard-all-btn:hover {
    color: var(--color-error);
}

.refinement-apply-btn {
    min-width: 100px;
}

@keyframes refinementBarIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
