/* ============================================================================
   DELPHOS · CANVAS / ARTIFACT VIEWER  (canvas-artifact.css)
   Modern document card for AI-written emails, letters, essays and notices.
   Theme-aware (light + dark) via the app's CSS variables, with graceful
   fallbacks so it looks right even before a theme is applied.
   ========================================================================== */

.dc-canvas {
    --dc-border: color-mix(in srgb, var(--text-color, #e6e6e6) 12%, transparent);
    --dc-surface: var(--secondary-color, rgba(255, 255, 255, 0.03));
    --dc-surface-2: color-mix(in srgb, var(--text-color, #fff) 6%, transparent);
    --dc-muted: color-mix(in srgb, var(--text-color, #cfcfcf) 58%, transparent);
    /* Card chrome follows the app's accent (warm clay) for consistency. */
    --dc-accent: var(--accent, var(--accent-color, #b7795c));
    /* Diff uses the universal blue/grey language (like ChatGPT), independent of
       the app accent, so changes read clearly to everyone. */
    --dc-add: #2f6bff;
    --dc-add-bg: rgba(47, 107, 255, 0.09);
    --dc-add-rail: rgba(47, 107, 255, 0.55);
    --dc-remove: color-mix(in srgb, var(--text-color, #8a8a8a) 52%, transparent);
    --dc-pill: color-mix(in srgb, var(--text-color, #000) 8%, var(--dc-surface));

    position: relative;
    margin: 14px 0 8px;
    border: 1px solid var(--dc-border);
    border-radius: 16px;
    background: var(--dc-surface);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 30px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
    /* GPU-friendly for the save flash */
    will-change: box-shadow;
    /* Gentle entrance so the card settling in after a reply feels intentional. */
    animation: dc-appear 0.3s ease both;
}

/* Dark theme: lift the diff blue so it stays legible on dark surfaces. */
body.dark-mode .dc-canvas {
    --dc-add: #7fb2ff;
    --dc-add-bg: rgba(96, 150, 255, 0.13);
    --dc-add-rail: rgba(120, 165, 255, 0.65);
    --dc-remove: color-mix(in srgb, var(--text-color, #9a9aa2) 62%, transparent);
    --dc-pill: color-mix(in srgb, #ffffff 10%, rgba(20, 20, 24, 0.9));
}

@keyframes dc-appear {
    from { opacity: 0; transform: translateY(8px) scale(0.995); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .dc-canvas { animation: none; }
}

.dc-canvas:hover {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 12px 40px rgba(0, 0, 0, 0.10);
}

.dc-canvas.is-just-saved {
    border-color: color-mix(in srgb, var(--dc-accent) 55%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dc-accent) 18%, transparent);
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.dc-canvas-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px 8px 12px;
    border-bottom: 1px solid var(--dc-border);
    background: color-mix(in srgb, var(--text-color, #fff) 3%, transparent);
    backdrop-filter: blur(4px);
}

.dc-head-left,
.dc-head-right {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.dc-canvas-head .material-symbols-rounded {
    font-size: 19px;
    line-height: 1;
}

/* Ghost pill button (Edit / Cancel / Save) */
.dc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px 0 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--text-color, #e8e8e8);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.08s ease;
    -webkit-tap-highlight-color: transparent;
}

.dc-btn:hover { background: var(--dc-surface-2); }
.dc-btn:active { transform: scale(0.97); }
.dc-btn .dc-btn-label { white-space: nowrap; }

.dc-btn--primary {
    background: var(--dc-accent);
    color: #fff;
    border-color: transparent;
}

.dc-btn--primary:hover {
    background: color-mix(in srgb, var(--dc-accent) 88%, #000);
}

/* Round icon buttons (copy / send / download) */
.dc-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--dc-muted);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
    -webkit-tap-highlight-color: transparent;
}

.dc-icon-btn:hover {
    background: var(--dc-surface-2);
    color: var(--text-color, #fff);
}

.dc-icon-btn:active { transform: scale(0.92); }

.dc-primary-btn:hover {
    background: color-mix(in srgb, var(--dc-accent) 16%, transparent);
    color: var(--dc-accent);
}

/* Document type chip */
.dc-type-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    background: var(--dc-surface-2);
    color: var(--dc-muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.dc-type-chip .material-symbols-rounded { font-size: 15px; }

.dc-editing-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--dc-accent);
    font-size: 13px;
    font-weight: 600;
}

.dc-editing-label .material-symbols-rounded { font-size: 18px; }

/* ── Body ────────────────────────────────────────────────────────────────── */
.dc-canvas-body {
    padding: 6px 20px 20px;
    font-size: 15px;
    line-height: 1.7;
    overflow-x: auto;
}

/* Tighten the first heading so the title hugs the top of the card. */
.dc-canvas-body > :first-child { margin-top: 10px; }
.dc-canvas-body > :last-child { margin-bottom: 0; }

.dc-canvas-body h1,
.dc-canvas-body h2 {
    font-size: 1.28rem;
    font-weight: 700;
    margin: 4px 0 12px;
}

/* ── Markdown editor ─────────────────────────────────────────────────────── */
.dc-editor {
    display: block;
    width: 100%;
    min-height: 160px;
    box-sizing: border-box;
    padding: 16px 20px 20px;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text-color, #e8e8e8);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    tab-size: 2;
}

.dc-editor::placeholder { color: var(--dc-muted); }

.dc-canvas.is-editing {
    border-color: color-mix(in srgb, var(--dc-accent) 45%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dc-accent) 12%, transparent);
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media screen and (max-width: 640px) {
    .dc-canvas-body { padding: 4px 14px 16px; font-size: 14.5px; }
    .dc-editor { padding: 12px 14px 16px; }
    .dc-type-chip { display: none; }          /* keep the toolbar tidy on phones */
    .dc-btn { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .dc-canvas, .dc-btn, .dc-icon-btn { transition: none; }
}


/* ============================================================================
   AI EDIT — instruction bar
   ========================================================================== */
.dc-canvas-head--edit {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
}

.dc-ask {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.dc-ask-ico {
    display: inline-flex;
    color: var(--dc-accent);
    flex: 0 0 auto;
}
.dc-ask-ico .material-symbols-rounded { font-size: 20px; }

.dc-ask-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--dc-border);
    border-radius: 10px;
    background: var(--dc-surface-2);
    color: var(--text-color, #eaeaea);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.dc-ask-input:focus {
    border-color: color-mix(in srgb, var(--dc-accent) 60%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dc-accent) 14%, transparent);
}
.dc-ask-input:disabled { opacity: 0.6; }

.dc-ask-send,
.dc-ask-close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease;
}
.dc-ask-send { background: var(--dc-accent); color: #fff; }
.dc-ask-send:hover { background: color-mix(in srgb, var(--dc-accent) 88%, #000); }
.dc-ask-send:active { transform: scale(0.94); }
.dc-ask-close { background: transparent; color: var(--dc-muted); }
.dc-ask-close:hover { background: var(--dc-surface-2); color: var(--text-color, #fff); }
.dc-ask .material-symbols-rounded { font-size: 20px; }

.dc-ask-row2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}
.dc-ask-suggests { display: flex; gap: 6px; flex-wrap: wrap; }

.dc-chip {
    padding: 5px 11px;
    border: 1px solid var(--dc-border);
    border-radius: 999px;
    background: transparent;
    color: var(--dc-muted);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.dc-chip:hover {
    background: var(--dc-surface-2);
    color: var(--text-color, #fff);
    border-color: color-mix(in srgb, var(--dc-accent) 40%, transparent);
}

.dc-manual-link {
    border: none;
    background: transparent;
    color: var(--dc-muted);
    font-size: 12.5px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}
.dc-manual-link:hover { color: var(--text-color, #fff); }

/* Loading state on the ask bar */
.dc-canvas-head--edit.is-loading .dc-ask-input { opacity: 0.6; }
.dc-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: dc-spin 0.7s linear infinite;
}
@keyframes dc-spin { to { transform: rotate(360deg); } }

/* ============================================================================
   DIFF REVIEW — accept / reject
   ========================================================================== */
.dc-canvas-head--diff .dc-diff-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-color, #eaeaea);
    opacity: 0.82;
    font-size: 13px;
    font-weight: 600;
}
.dc-canvas-head--diff .dc-diff-label .material-symbols-rounded { font-size: 18px; opacity: 0.75; }

/* Accept-all uses the diff-blue so the "changes = blue" language is consistent. */
.dc-canvas-head--diff .dc-diff-acceptall { background: var(--dc-add); }
.dc-canvas-head--diff .dc-diff-acceptall:hover { background: color-mix(in srgb, var(--dc-add) 86%, #000); }

.dc-canvas.is-diffing .dc-canvas-body { padding-top: 10px; }

/* Unchanged paragraphs read exactly like the normal document. */
.dc-diff-equal { margin: 2px 0; }

/* A change flows INLINE with the document — no heavy box. The old text sits
   above the new, with the accept/reject controls floating to the right. */
.dc-hunk {
    position: relative;
    margin: 10px 0;
    padding-right: 74px;                 /* room for the floating pill */
    transition: opacity 0.2s ease;
}

/* Removed content — quiet grey strikethrough, no background, no border. */
.dc-del {
    display: block;
    color: var(--dc-remove);
    text-decoration: line-through;
    text-decoration-color: color-mix(in srgb, var(--dc-remove) 70%, transparent);
    text-decoration-thickness: 1px;
}
.dc-del * { text-decoration: line-through; }
.dc-del p, .dc-del li { color: inherit; }

/* Added content — clear diff-blue on a soft blue band with a left rail. */
.dc-ins {
    display: block;
    margin-top: 4px;
    padding: 4px 12px;
    border-radius: 8px;
    border-left: 3px solid var(--dc-add-rail);
    background: var(--dc-add-bg);
    color: var(--dc-add);
}
.dc-ins p, .dc-ins li, .dc-ins strong { color: inherit; }
.dc-ins strong { font-weight: 700; }

/* Keep del/ins blocks compact — no oversized paragraph gaps. */
.dc-del > :first-child, .dc-ins > :first-child { margin-top: 0; }
.dc-del > :last-child, .dc-ins > :last-child { margin-bottom: 0; }
.dc-del p, .dc-ins p { margin: 0; }
.dc-del p + p, .dc-ins p + p { margin-top: 6px; }

/* Floating accept/reject pill (ChatGPT-style), elevated over the change. */
.dc-hunk-actions {
    position: absolute;
    top: 2px;
    right: 0;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
    background: var(--dc-pill);
    border: 1px solid var(--dc-border);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    z-index: 2;
}
.dc-hunk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
    color: var(--dc-muted);
    transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
}
.dc-hunk-btn .material-symbols-rounded { font-size: 18px; }
.dc-hunk-btn:active { transform: scale(0.9); }
.dc-hunk-accept:hover { background: color-mix(in srgb, var(--dc-add) 20%, transparent); color: var(--dc-add); }
.dc-hunk-reject:hover { background: color-mix(in srgb, var(--dc-remove) 26%, transparent); color: var(--text-color, #fff); }

/* Resolved hunks collapse to just the kept text, rendered plainly. */
.dc-hunk--accepted .dc-del,
.dc-hunk--rejected .dc-ins { display: none; }
.dc-hunk--accepted .dc-ins {
    color: var(--text-color, #eaeaea);
    background: transparent;
    border-left: none;
    padding: 0;
    margin-top: 0;
}
.dc-hunk--rejected .dc-del {
    text-decoration: none;
    color: var(--text-color, #eaeaea);
}
.dc-hunk--rejected .dc-del * { text-decoration: none; }
.dc-hunk--accepted, .dc-hunk--rejected { padding-right: 0; }
.dc-hunk--accepted .dc-hunk-actions,
.dc-hunk--rejected .dc-hunk-actions {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ============================================================================
   LIVE CARD FRAME (while a document reply streams)
   ========================================================================== */
.message.incoming.dc-live .stream-body {
    position: relative;
    margin-top: 30px;
    padding: 16px 18px;
    border: 1px solid color-mix(in srgb, var(--text-color, #e6e6e6) 14%, transparent);
    border-radius: 16px;
    background: var(--secondary-color, rgba(255, 255, 255, 0.03));
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    animation: dc-appear 0.3s ease both;
}

/* Live "document" pill sitting on the frame's top edge. */
.message.incoming.dc-live .stream-body::before {
    content: attr(data-live) " · writing…";
    position: absolute;
    top: -12px;
    left: 14px;
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--dc-accent, var(--primary-color, #3b82f6));
    color: #fff;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--primary-color, #3b82f6) 40%, transparent);
}

@media (prefers-reduced-motion: reduce) {
    .dc-spinner { animation-duration: 1.4s; }
    .message.incoming.dc-live .stream-body { animation: none; }
}


/* ============================================================================
   EMAIL SEND PANEL (native send via connected accounts)
   ========================================================================== */
.dc-send-panel {
    padding: 12px 14px 14px;
    border-bottom: 1px solid var(--dc-border);
    background: color-mix(in srgb, var(--text-color, #fff) 3%, transparent);
    animation: dc-appear 0.22s ease both;
}

.dc-send-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.dc-send-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-color, #eaeaea);
}
.dc-send-title .material-symbols-rounded { font-size: 18px; color: var(--dc-accent); }
.dc-send-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border: none; border-radius: 8px;
    background: transparent; color: var(--dc-muted); cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.dc-send-close:hover { background: var(--dc-surface-2); color: var(--text-color, #fff); }
.dc-send-close .material-symbols-rounded { font-size: 18px; }

.dc-send-field { display: block; margin-bottom: 10px; }
.dc-send-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--dc-muted);
    margin-bottom: 5px;
}
.dc-send-to {
    width: 100%;
    box-sizing: border-box;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--dc-border);
    border-radius: 10px;
    background: var(--dc-surface-2);
    color: var(--text-color, #eaeaea);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.dc-send-to:focus {
    border-color: color-mix(in srgb, var(--dc-accent) 60%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dc-accent) 14%, transparent);
}
.dc-send-to.dc-send-invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16);
}

.dc-send-senders { display: flex; flex-direction: column; gap: 6px; }
.dc-send-loading {
    display: inline-flex; align-items: center; gap: 8px;
    color: var(--dc-muted); font-size: 13px; padding: 4px 0;
}
.dc-send-loading .dc-spinner { border-color: color-mix(in srgb, var(--text-color, #888) 30%, transparent); border-top-color: var(--dc-accent); }

.dc-sender {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--dc-border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-color, #eaeaea);
    font-size: 13.5px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.dc-sender:hover { background: var(--dc-surface-2); }
.dc-sender .material-symbols-rounded { font-size: 19px; color: var(--dc-muted); }
.dc-sender-label { flex: 1 1 auto; }
.dc-sender-ext {
    font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em;
    color: var(--dc-muted); text-transform: uppercase;
    padding: 2px 7px; border-radius: 999px; background: var(--dc-surface-2);
}
.dc-sender-check { display: none; color: var(--dc-accent); }
.dc-sender-check .material-symbols-rounded { color: var(--dc-accent); font-size: 20px; }
.dc-sender.is-selected {
    border-color: color-mix(in srgb, var(--dc-accent) 60%, transparent);
    background: color-mix(in srgb, var(--dc-accent) 8%, transparent);
}
.dc-sender.is-selected .dc-sender-check { display: inline-flex; }
.dc-sender.is-selected .material-symbols-rounded { color: var(--dc-accent); }

.dc-send-hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--dc-muted);
    line-height: 1.5;
}

.dc-send-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}
.dc-send-panel.is-sending { opacity: 0.85; }

@media (prefers-reduced-motion: reduce) {
    .dc-send-panel { animation: none; transition: none; }
}

