/* #1121 Engage Assist cards — one card per finding or question. Shown beside the letter in the gray canvas
   (.ea-rail, laid out by the editor next to each passage) and, on narrow layouts, stacked in the insights-panel tab
   (.ea-stack). Design tokens only; no purple/indigo. */

/* ── Margin rail ── */
.ea-rail {
    position: relative;
    flex: 0 0 320px;
    width: 320px;
    align-self: stretch;
    font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary, #374151);
}

/* #1135: the header block (status line + client terms documents) stays put while the rail scrolls. */
.ea-rail > [data-assist-head] {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--border-primary, #e5e7eb);
}

.ea-rail-head {
    /* Cards scroll up under the header with their passage: keep it on top, on the page-gray. */
    position: relative;
    z-index: 1;
    background: var(--border-primary, #e5e7eb);
    padding-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 2px 0;
    font-size: 12px;
    color: var(--text-tertiary, #6b7280);
}
.ea-rail-head .ea-name { font-size: 14px; }
.ea-rail-head .ea-link { white-space: nowrap; }
/* The status line under the title (wraps rather than being cut off). */
.ea-rail-status {
    padding: 2px 2px 0 32px;
    font-size: 12px;
    color: var(--text-tertiary, #6b7280);
}
/* A check is running: a visible bar with the step it is on. */
.ea-rail-checking {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--color-primary-bg, #eff6ff);
    color: var(--color-primary, #2563eb);
    font-size: 12px;
    font-weight: 500;
}
.ea-rail-checking .ea-typing { padding: 0; }
.ea-rail-checking .ea-typing span { background: var(--color-primary, #2563eb); }

/* Cards in the rail are positioned by the editor (top = their passage's top, pushed below the card above). */
.ea-rail .ea-card {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    transition: top .12s ease;
    /* #1135: cards show at full height and the RAIL scrolls (wheel / trackpad). Cards are no longer scroll boxes of
       their own: a card that captured the wheel (overscroll-behavior: contain) made scrolling the rail stall or skip
       depending on which card was under the pointer. */
}
.ea-rail .ea-card > * { flex-shrink: 0; }
/* No re-stack animation while the letter scrolls (the cards follow it frame by frame). */
.ea-rail.ea-scrolling .ea-card { transition: none; }
.ea-earlier { align-self: flex-start; padding: 0; }

/* ── Panel fallback ── */
.ea-stack {
    font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Card ── */
.ea-card {
    box-sizing: border-box;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-primary, #e5e7eb);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ea-card:hover { border-color: var(--border-strong, #d1d5db); }
.ea-card-active {
    border-color: var(--border-strong, #d1d5db);
    box-shadow: var(--shadow-md, 0 4px 14px rgba(17, 24, 39, .08));
    cursor: default;
}
.ea-card-done { padding: 10px 14px; gap: 4px; }

.ea-who {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.ea-spacer { flex: 1 1 auto; }
.ea-name {
    font-weight: 600;
    color: var(--text-primary, #111827);
    white-space: nowrap;
}

.ea-av {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full, 9999px);
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-primary, #e5e7eb);
    padding: 3px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ea-av img { width: 100%; height: 100%; object-fit: contain; }
.ea-av-sm { width: 18px; height: 18px; padding: 2px; }

.ea-av-user {
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    box-sizing: border-box;
    border-radius: var(--radius-full, 9999px);
    background: var(--color-teal, #0d9488);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Area · subject label, e.g. "INTAKE · Fee arrangement". */
.ea-area {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--text-tertiary, #6b7280);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ea-area-warn { color: var(--color-warning-text, #92400e); }

.ea-done {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-success-text, #065f46);
    white-space: nowrap;
}

.ea-text { color: var(--text-secondary, #374151); overflow-wrap: anywhere; }
.ea-text strong { color: var(--text-primary, #111827); }
.ea-text-muted { color: var(--text-tertiary, #6b7280); }

/* The highlighted text a question card is about. */
.ea-quote {
    border-left: 2px solid var(--color-amber-strong, #f59e0b);
    padding-left: 8px;
    color: var(--text-tertiary, #6b7280);
    font-size: 12.5px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Suggested change ── */
.ea-diff {
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary, #111827);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ea-diff-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary, #6b7280);
}
.ea-diff del {
    background: var(--color-danger-bg, #fee2e2);
    color: var(--color-danger-dark, #991b1b);
    border-radius: 3px;
    padding: 0 2px;
}
.ea-diff ins {
    background: var(--color-success-bg, #d1fae5);
    color: var(--color-success-text, #065f46);
    text-decoration: none;
    border-radius: 3px;
    padding: 0 2px;
}

/* ── Suggested clause ── */
.ea-clause {
    border: 1px solid var(--border-primary, #e5e7eb);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.ea-clause-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--text-primary, #111827);
}
.ea-clause-conf {
    font-weight: 500;
    font-size: 11px;
    color: var(--color-warning-text, #92400e);
}
.ea-clause-preview { color: var(--text-tertiary, #6b7280); }
.ea-clause-added { color: var(--color-success-text, #065f46); }

.ea-source { font-size: 12px; color: var(--text-tertiary, #6b7280); }

/* Source conflicts: the sources disagree about a finding — each source's value, no suggested change. */
.ea-conflict {
    font-size: 12px;
    color: var(--color-warning-text, #92400e);
    background: var(--color-warning-bg, #fef3c7);
    border-radius: 6px;
    padding: 6px 8px;
}
.ea-conflict-head { display: flex; gap: 6px; align-items: center; font-weight: 600; margin-bottom: 4px; }
.ea-choice { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.ea-choice + .ea-choice { border-top: 1px solid var(--color-warning); }
.ea-choice-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ea-choice-head strong { color: var(--text-primary, #111827); overflow-wrap: anywhere; }
.ea-choice-src { font-weight: 500; min-width: 76px; }
.ea-choice-note { font-size: 11px; color: var(--text-tertiary, #6b7280); }

.ea-agree {
    display: flex;
    gap: 4px;
    align-items: center;
    font-size: 12px;
    color: var(--color-success-text, #065f46);
}

.ea-error {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    font-size: 12px;
    color: var(--color-danger-dark, #991b1b);
    background: var(--color-danger-bg-subtle, #fef2f2);
    border-radius: 6px;
    padding: 6px 8px;
}

.ea-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.ea-link {
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-primary, #2563eb);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
.ea-link:hover { color: var(--color-primary-hover, #1d4ed8); text-decoration: underline; }
.ea-link:disabled { color: var(--text-faint, #9ca3af); cursor: default; text-decoration: none; }

/* Handled cards put away: the "N handled" / "Hide handled" link in the rail and panel headers. */
.ea-handled-toggle { color: var(--text-tertiary, #6b7280); white-space: nowrap; }
.ea-handled-toggle[aria-pressed="true"] { color: var(--color-primary, #2563eb); }

.ea-icon {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary, #6b7280);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.ea-icon:hover { background: var(--bg-secondary, #f3f4f6); color: var(--text-primary, #111827); }

/* ── Reply box ── */
.ea-reply {
    display: flex;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--border-strong, #d1d5db);
    border-radius: 8px;
    padding: 4px 4px 4px 10px;
    background: var(--bg-primary, #fff);
    cursor: text;
}
.ea-reply:focus-within { border-color: var(--color-primary, #2563eb); }
.ea-reply input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 13px;
    color: var(--text-primary, #111827);
}
.ea-reply .ea-send { padding: 3px 7px; }

.ea-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ── Typing indicator ── */
.ea-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 6px 2px;
}
.ea-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint, #d1d5db);
    animation: ea-bounce 1s infinite;
}
.ea-typing span:nth-child(2) { animation-delay: .15s; }
.ea-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes ea-bounce {
    0%, 60%, 100% { opacity: .35; }
    30% { opacity: 1; }
}

/* #1135: client terms documents (AssistTermsDocuments) — attached Terms of Business / OCG files checked with the
   Intapp terms. A compact drop zone + one chip per document; sits under the Engage Assist header. */
.ea-docs { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 8px; }
.ea-docs-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ea-doc-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    font-size: 12px;
    color: var(--color-info-text, #1e40af);
    background: var(--color-info-bg, #eff6ff);
    border-radius: 12px;
    padding: 2px 4px 2px 9px;
}
.ea-doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.ea-doc-count { color: var(--text-tertiary, #6b7280); white-space: nowrap; }
.ea-doc-remove {
    border: 0;
    background: transparent;
    color: var(--text-tertiary, #6b7280);
    width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.ea-doc-remove:hover { background: var(--bg-primary, #fff); color: var(--text-primary, #111827); }
.ea-doc-remove:disabled { cursor: default; opacity: .5; }
.ea-docs-drop {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-tertiary, #6b7280);
    border: 1px dashed var(--border-strong, #d1d5db);
    border-radius: 8px;
    padding: 7px 10px;
    cursor: pointer;
    background: var(--bg-primary, #fff);
}
.ea-docs-drop:hover,
.ea-docs-drop:focus-within { border-color: var(--color-primary, #2563eb); color: var(--color-primary, #2563eb); }
.ea-docs-drop.busy { cursor: default; color: var(--text-secondary, #4b5563); }
/* The file input covers the zone so dropped files land on it. */
.ea-docs-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.ea-docs-input:disabled { cursor: default; }
.ea-docs-error {
    font-size: 12px;
    color: var(--color-danger-dark, #991b1b);
    background: var(--color-danger-bg-subtle, #fef2f2);
    border-radius: 6px;
    padding: 5px 8px;
}
.ea-docs-stale { font-size: 12px; color: var(--text-secondary, #4b5563); }

/* #1135: a compact open card in a crowded margin — its title in full under the source label; click to open. */
.ea-compact-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary, #111827);
    line-height: 1.35;
}

/* #1135: Undo beside a handled card's status, separated by a dot. */
.ea-undo { margin-left: 2px; }
.ea-undo::before { content: "·"; color: var(--text-faint, #9ca3af); margin-right: 6px; }

/* #1135: text to add (something missing from the letter) — dragged into the letter where it belongs. */
.ea-insert {
    border: 1px dashed var(--color-primary, #2563eb);
    border-radius: 8px;
    background: var(--color-primary-bg-subtle, #eff6ff);
    padding: 8px 10px;
}
.ea-insert-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-primary, #2563eb);
    margin-bottom: 4px;
}
.ea-insert-text {
    color: var(--text-primary, #111827);
    white-space: pre-wrap;
    cursor: grab;
    border-radius: 4px;
}
.ea-insert-text:hover { background: var(--bg-primary, #fff); }
.ea-insert-text:active { cursor: grabbing; }
.ea-insert-off { border-color: var(--border-strong, #d1d5db); background: var(--bg-secondary, #f9fafb); }
.ea-insert-off .ea-insert-head { color: var(--text-tertiary, #6b7280); }
.ea-insert-off .ea-insert-text { cursor: default; }
