/* ── Cadeo Chat (v1.1.34) — open conversation surface. Inherits the
   .day-planner-panel slide-up geometry; only the visual chrome
   inside changes. Slightly wider than the planner because chat
   benefits from horizontal room for message bodies. ── */
.cadeo-chat-sheet {
    width: min(560px, calc(100vw - 32px));
    max-height: min(80vh, 720px);
    /* v1.2.0 — lock to a stable height when a conversation is active.
       Without this the sheet collapses/expands on every renderSheet
       (each phase strip update, each suppression flush, each recursion
       of agent.followup) — the chain produces ~10 rebuilds in quick
       succession and the sheet visibly oscillates. The `.is-active`
       class is added by renderSheet() when there are messages; the
       empty state keeps its content-sized geometry. */
    transition: height var(--duration-normal) var(--ease-in-out);
}
.cadeo-chat-sheet.is-active {
    height: min(80vh, 720px);
}
@media (max-width: 768px) {
    .cadeo-chat-sheet { width: calc(100vw - 24px); }
}

.cadeo-chat-phase {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(80vh, 720px);
}

/* Header — same flex pattern as .dp-header but with a thread chip
   + Keep this pin button. */
.cadeo-chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.cadeo-chat-header-icon {
    width: 24px;
    height: 24px;
    color: var(--accent-blue);
    flex-shrink: 0;
}
.cadeo-chat-header-icon svg { width: 100%; height: 100%; }
.cadeo-chat-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cadeo-chat-thread-chip {
    flex-shrink: 0;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cadeo-chat-pin-btn,
.cadeo-chat-newthread-btn,
.cadeo-chat-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) var(--ease-in-out),
                color var(--duration-fast) var(--ease-in-out);
}
.cadeo-chat-pin-btn svg,
.cadeo-chat-newthread-btn svg,
.cadeo-chat-close-btn svg { width: 16px; height: 16px; }
.cadeo-chat-pin-btn:hover,
.cadeo-chat-newthread-btn:hover,
.cadeo-chat-close-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.cadeo-chat-pin-btn.is-pinned { color: var(--accent-blue); }

/* Body — scrollable message list */
.cadeo-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

/* Empty state */
.cadeo-chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-tertiary);
    padding: 24px 16px;
    max-width: 380px;
}
.cadeo-chat-empty-icon {
    width: 36px;
    height: 36px;
    color: var(--accent-blue);
    margin: 0 auto 12px;
    opacity: 0.7;
}
.cadeo-chat-empty-icon svg { width: 100%; height: 100%; }
.cadeo-chat-empty-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 6px;
}
.cadeo-chat-empty-sub {
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    margin: 0 0 18px;
    line-height: 1.5;
}
.cadeo-chat-empty-examples {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid var(--border-light);
    padding-top: 14px;
    margin-top: 6px;
}
.cadeo-chat-empty-eyebrow {
    font-size: var(--font-size-2xs);
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}
.cadeo-chat-example {
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    padding: 6px 0;
    border-radius: var(--radius-sm);
}
.cadeo-chat-example:hover { color: var(--accent-blue); }

/* v1.2.0 — Plus upsell banner on chat empty state for free-tier users.
   Card-style so it reads as a distinct affordance, not page chrome.
   `position: relative` anchors the dismiss button to the top-right corner. */
.cadeo-chat-upgrade-banner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    text-align: left;
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.08), rgba(74, 144, 217, 0.02));
    border: 1px solid rgba(74, 144, 217, 0.25);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 0 0 18px;
}
.cadeo-chat-upgrade-dismiss {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.55;
    transition: opacity var(--duration-fast) var(--ease-in-out), background var(--duration-fast) var(--ease-in-out);
}
.cadeo-chat-upgrade-dismiss:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.04);
}
.cadeo-chat-upgrade-dismiss svg {
    width: 14px;
    height: 14px;
}
.cadeo-chat-upgrade-copy strong {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.cadeo-chat-upgrade-copy p {
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    line-height: 1.45;
}
.cadeo-chat-upgrade-cta {
    align-self: flex-start;
}
.cadeo-chat-example:focus-visible { outline: var(--focus-outline); outline-offset: var(--focus-outline-offset); }

/* Messages */
.cadeo-chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}
.cadeo-chat-message-role {
    font-size: var(--font-size-2xs);
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.cadeo-chat-message-body {
    font-size: var(--font-size-sm);
    line-height: 1.55;
    color: var(--text-primary);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

/* v1.1.61 — rich-text rendering for AI messages. The builder's
   renderMarkdownToDom emits <p>, <ul>, <strong>, <em> elements; the
   browser defaults add too much margin / padding so override them to
   sit tightly inside the message bubble. */
.cadeo-chat-message-body p.cadeo-chat-md-p {
    margin: 0 0 8px;
    white-space: normal; /* parent's pre-wrap, but the parser handled inter-block whitespace */
}
.cadeo-chat-message-body p.cadeo-chat-md-p:last-child {
    margin-bottom: 0;
}
.cadeo-chat-message-body ul.cadeo-chat-md-list {
    margin: 0 0 8px;
    padding-left: 20px;
    list-style: disc;
}
.cadeo-chat-message-body ul.cadeo-chat-md-list:last-child {
    margin-bottom: 0;
}
.cadeo-chat-message-body ul.cadeo-chat-md-list li {
    margin: 0 0 2px;
    white-space: normal;
}
.cadeo-chat-message-body strong { font-weight: 600; }
.cadeo-chat-message-body em { font-style: italic; }
/* v1.1.81 — headings + entity-reference chips. The model formats
   workspace references as [Title](cadeo://type/id); the renderer marks
   them with .cadeo-chat-entity-link and a delegated click handler on
   the chat sheet dispatches to the existing openXModal() globals. */
.cadeo-chat-message-body h2.cadeo-chat-md-heading {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin: 12px 0 6px;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}
.cadeo-chat-message-body h3.cadeo-chat-md-heading {
    font-size: var(--font-size-14);
    font-weight: 600;
    margin: 10px 0 4px;
    color: var(--text-primary);
}
.cadeo-chat-message-body h4.cadeo-chat-md-heading {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin: 8px 0 4px;
    color: var(--text-secondary);
}
.cadeo-chat-message-body h2.cadeo-chat-md-heading:first-child,
.cadeo-chat-message-body h3.cadeo-chat-md-heading:first-child,
.cadeo-chat-message-body h4.cadeo-chat-md-heading:first-child {
    margin-top: 0;
}
.cadeo-chat-entity-link {
    display: inline-block;
    padding: 1px 8px;
    margin: 0 1px;
    background: rgba(74, 144, 217, 0.10);
    color: var(--accent-blue);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-in-out), color var(--duration-fast) var(--ease-in-out);
    line-height: 1.4;
}
.cadeo-chat-entity-link:hover {
    background: rgba(74, 144, 217, 0.18);
    color: var(--accent-blue-dark, #357ABD);
}
.cadeo-chat-entity-link:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
}
/* Regular external links keep the default underlined treatment so
   they're visibly different from entity chips. */
.cadeo-chat-message-body a:not(.cadeo-chat-entity-link) {
    color: var(--accent-blue);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.cadeo-chat-message-user .cadeo-chat-message-role { color: var(--accent-blue); }
.cadeo-chat-message-ai .cadeo-chat-message-role { color: var(--text-secondary); }
.cadeo-chat-message-ai .cadeo-chat-stream-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--accent-blue);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cadeo-chat-blink 1s steps(2, end) infinite;
}
@keyframes cadeo-chat-blink { 50% { opacity: 0; } }
