/* =====================================================
   ENGAGE Redline - Styles
   =====================================================
   Track changes, comments, panels, and external review page styles.
   These styles apply OUTSIDE the TinyMCE iframe (the page-level UI).
   Iframe-internal styles are injected via content_style in redlineEditor.js.
   ===================================================== */

/* --------------------------------------------------
   Track Changes Colors
   -------------------------------------------------- */

/* Contributor track changes (teal palette) */
.track-insertion.contributor {
    background-color: rgba(20, 184, 166, 0.15);
    border-bottom: 2px solid #14b8a6;
    position: relative;
    text-decoration: none !important;
    padding: 0 1px;
}

.track-deletion.contributor {
    background-color: rgba(15, 118, 110, 0.12);
    text-decoration: line-through;
    color: #0f766e;
    position: relative;
    padding: 0 1px;
    cursor: default;
    user-select: none;
}

/* Reviewer track changes (green/red palette) */
.track-insertion.reviewer {
    background-color: #dcfce7;
    border-bottom: 2px solid #22c55e;
    position: relative;
    text-decoration: none !important;
    padding: 0 1px;
}

.track-deletion.reviewer {
    background-color: #fef2f2;
    text-decoration: line-through;
    color: #ef4444;
    position: relative;
    padding: 0 1px;
    cursor: default;
    user-select: none;
}

/* Fallback track changes (no author type) */
.track-insertion {
    background-color: #dcfce7;
    border-bottom: 2px solid #22c55e;
    position: relative;
    text-decoration: none !important;
    padding: 0 1px;
}

.track-deletion {
    background-color: #fef2f2;
    text-decoration: line-through;
    color: #ef4444;
    position: relative;
    padding: 0 1px;
    cursor: default;
    user-select: none;
}

/* #336: format changes — LIGHT BLUE underline (distinct from insert-green, delete-red, comment-amber),
   so a reformatted run reads as "changed styling". */
.track-format {
    background-color: #e0f2fe;
    border-bottom: 2px solid #0ea5e9;
    position: relative;
    padding: 0 1px;
}

/* Ensure insertion inside/after deletion does not inherit strikethrough */
.track-deletion .track-insertion,
.track-insertion {
    text-decoration: none !important;
}

/* --------------------------------------------------
   Change Initials Badges
   -------------------------------------------------- */
.change-initials {
    position: absolute;
    top: -16px;
    left: 0;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

.track-insertion.contributor .change-initials {
    background: #14b8a6;
}

.track-insertion.reviewer .change-initials {
    background: #22c55e;
}

.track-insertion .change-initials {
    background: #22c55e;
}

.track-deletion.contributor .change-initials {
    background: #0f766e;
    text-decoration: none !important;
}

.track-deletion.reviewer .change-initials {
    background: #ef4444;
    text-decoration: none !important;
}

.track-deletion .change-initials {
    background: #ef4444;
    text-decoration: none !important;
}

/* Highlighted state for scrolling to change */
.track-insertion.highlighted,
.track-deletion.highlighted {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
    border-radius: 2px;
}

/* --------------------------------------------------
   Comment Highlight Styles
   -------------------------------------------------- */
.comment-marker {
    font-size: 0;
    line-height: 0;
    width: 0;
    height: 0;
    display: inline;
}

.comment-highlight {
    background-color: rgba(250, 204, 21, 0.3);
    border-bottom: 2px solid #facc15;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.comment-highlight:hover {
    background-color: rgba(250, 204, 21, 0.5);
}

.comment-highlight.active {
    background-color: rgba(250, 204, 21, 0.6);
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.4);
    border-radius: 2px;
}

.comment-resolved {
    background-color: rgba(156, 163, 175, 0.15);
    border-bottom: 1px dashed #9ca3af;
}

/* --------------------------------------------------
   Redline Panel Layout
   -------------------------------------------------- */
.redline-container {
    display: flex;
    height: 100%;
    gap: 0;
    overflow: hidden;
}

.redline-editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.redline-sidebar {
    width: 340px;
    min-width: 280px;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color, #e5e7eb);
    background: var(--surface-color, #ffffff);
    overflow: hidden;
}

.redline-sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: var(--surface-secondary, #f9fafb);
    flex-shrink: 0;
}

.redline-sidebar-tab {
    flex: 1;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    color: var(--text-secondary, #6b7280);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.redline-sidebar-tab:hover {
    color: var(--text-primary, #1f2937);
    background: rgba(0, 0, 0, 0.02);
}

.redline-sidebar-tab.active {
    color: var(--color-primary, #3b82f6);
    border-bottom-color: var(--color-primary, #3b82f6);
}

.redline-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* --------------------------------------------------
   Changes Panel
   -------------------------------------------------- */
.redline-changes-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.redline-changes-summary {
    padding: 12px 16px;
    background: var(--surface-secondary, #f9fafb);
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.redline-changes-summary .count-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.redline-changes-summary .count-badge.insertions {
    background: rgba(20, 184, 166, 0.12);
    color: #0f766e;
}

.redline-changes-summary .count-badge.deletions {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.redline-changes-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.redline-change-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: 13px;
    line-height: 1.4;
}

.redline-change-item:hover {
    background: var(--surface-secondary, #f9fafb);
}

.redline-change-item.active {
    background: rgba(59, 130, 246, 0.06);
    box-shadow: inset 2px 0 0 var(--color-primary, #3b82f6);
}

.redline-change-item .change-type-indicator {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-top: 6px;
}

.redline-change-item .change-type-indicator.insertion {
    background: #14b8a6;
}

.redline-change-item .change-type-indicator.deletion {
    background: #ef4444;
}

.redline-change-item .change-content {
    flex: 1;
    min-width: 0;
}

.redline-change-item .change-text {
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.redline-change-item .change-text.insertion-text {
    color: #0f766e;
}

.redline-change-item .change-text.deletion-text {
    color: #ef4444;
    text-decoration: line-through;
}

.redline-change-item .change-meta {
    font-size: 11px;
    color: var(--text-tertiary, #9ca3af);
    margin-top: 2px;
}

.redline-change-item .change-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.redline-change-item:hover .change-actions {
    opacity: 1;
}

.redline-change-action-btn {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s ease;
    background: transparent;
}

.redline-change-action-btn.accept {
    color: #22c55e;
}

.redline-change-action-btn.accept:hover {
    background: #dcfce7;
    color: #16a34a;
}

.redline-change-action-btn.reject {
    color: #ef4444;
}

.redline-change-action-btn.reject:hover {
    background: #fef2f2;
    color: #dc2626;
}

/* --------------------------------------------------
   Comments Panel
   -------------------------------------------------- */
.redline-comments-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.redline-comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.redline-comment-item {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    background: var(--surface-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    cursor: pointer;
    transition: all 0.15s ease;
}

.redline-comment-item:hover {
    border-color: var(--color-primary, #3b82f6);
}

.redline-comment-item.active {
    border-color: #facc15;
    box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.3);
    background: rgba(250, 204, 21, 0.04);
}

.redline-comment-item.resolved {
    opacity: 0.6;
}

.redline-comment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.redline-comment-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary, #1f2937);
}

.redline-comment-author .author-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.redline-comment-author .author-badge.contributor {
    background: rgba(20, 184, 166, 0.12);
    color: #0f766e;
}

.redline-comment-author .author-badge.reviewer {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
}

.redline-comment-time {
    font-size: 11px;
    color: var(--text-tertiary, #9ca3af);
}

.redline-comment-selected-text {
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    background: rgba(250, 204, 21, 0.1);
    border-left: 3px solid #facc15;
    padding: 4px 8px;
    margin-bottom: 6px;
    border-radius: 0 4px 4px 0;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.redline-comment-body {
    font-size: 13px;
    color: var(--text-primary, #1f2937);
    line-height: 1.5;
    word-break: break-word;
}

.redline-comment-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.redline-comment-action {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 0;
    transition: color 0.15s ease;
}

.redline-comment-action:hover {
    color: var(--color-primary, #3b82f6);
}

.redline-comment-action.resolve:hover {
    color: #22c55e;
}

.redline-comment-action.delete:hover {
    color: #ef4444;
}

/* Replies within a comment */
.redline-comment-replies {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.redline-comment-reply {
    padding: 6px 0;
    font-size: 12px;
}

.redline-comment-reply .reply-author {
    font-weight: 600;
    color: var(--text-primary, #1f2937);
    margin-right: 4px;
}

.redline-comment-reply .reply-text {
    color: var(--text-secondary, #6b7280);
}

.redline-comment-reply .reply-time {
    font-size: 10px;
    color: var(--text-tertiary, #9ca3af);
    margin-left: 8px;
}

/* Comment input area */
.redline-comment-input-area {
    padding: 12px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--surface-color, #ffffff);
    flex-shrink: 0;
}

.redline-comment-input {
    width: 100%;
    min-height: 60px;
    max-height: 120px;
    padding: 8px 10px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s ease;
}

.redline-comment-input:focus {
    border-color: var(--color-primary, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.redline-comment-input-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.redline-comment-submit-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--color-primary, #3b82f6);
    color: #ffffff;
}

.redline-comment-submit-btn:hover {
    background: var(--color-primary-dark, #2563eb);
}

.redline-comment-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.redline-comment-cancel-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--surface-color, #ffffff);
    color: var(--text-secondary, #6b7280);
}

.redline-comment-cancel-btn:hover {
    background: var(--surface-secondary, #f9fafb);
}

/* Empty state */
.redline-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-tertiary, #9ca3af);
}

.redline-empty-state-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.redline-empty-state-text {
    font-size: 13px;
    line-height: 1.5;
}

/* --------------------------------------------------
   External Review Page Layout
   -------------------------------------------------- */
.external-review-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--background-color, #f3f4f6);
}

.external-review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface-color, #ffffff);
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    flex-shrink: 0;
    z-index: 10;
}

.external-review-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.external-review-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #1f2937);
}

.external-review-subtitle {
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
}

.external-review-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.external-review-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
}

.external-review-status-badge.in-progress {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
}

.external-review-status-badge.submitted {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.external-review-status-badge .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.external-review-body {
    flex: 1;
    overflow: hidden;
}

.external-review-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 24px;
    background: var(--surface-color, #ffffff);
    border-top: 1px solid var(--border-color, #e5e7eb);
    gap: 12px;
    flex-shrink: 0;
}

.external-review-btn {
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.external-review-btn.primary {
    background: var(--color-primary, #3b82f6);
    color: #ffffff;
}

.external-review-btn.primary:hover {
    background: var(--color-primary-dark, #2563eb);
}

.external-review-btn.secondary {
    background: var(--surface-color, #ffffff);
    color: var(--text-secondary, #6b7280);
    border: 1px solid var(--border-color, #e5e7eb);
}

.external-review-btn.secondary:hover {
    background: var(--surface-secondary, #f9fafb);
}

.external-review-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --------------------------------------------------
   Round indicator (multi-round review)
   -------------------------------------------------- */
.redline-round-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
}

/* --------------------------------------------------
   Author legend (shows who made which color changes)
   -------------------------------------------------- */
.redline-author-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: var(--surface-secondary, #f9fafb);
    font-size: 11px;
}

.redline-author-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.redline-author-legend-item .legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.redline-author-legend-item .legend-color.contributor {
    background: #14b8a6;
}

.redline-author-legend-item .legend-color.reviewer {
    background: #22c55e;
}

.redline-author-legend-item .legend-name {
    color: var(--text-secondary, #6b7280);
    font-weight: 500;
}

/* --------------------------------------------------
   Responsive adjustments
   -------------------------------------------------- */
@media (max-width: 768px) {
    .redline-sidebar {
        width: 100%;
        max-width: 100%;
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }

    .redline-sidebar.open {
        transform: translateX(0);
    }

    .redline-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 99;
    }

    .redline-sidebar.open ~ .redline-sidebar-overlay {
        display: block;
    }
}
