/* ── DocMixer ──
 * Scoped styles extracted from the <style> blocks of tools/doc_mixer/{new,edit}
 * and inline style= attributes. Everything is scoped under .dm-shell (the page
 * root, shared by new + edit; streamed broadcast partials and the chat-form /
 * files-panel replacements all render inside it). Bare element selectors
 * (textarea, input[type=submit]) are scoped too. The `spin` keyframe is renamed
 * dm-spin to avoid colliding with lea_raw/personal_agent's global `spin`.
 * JS-toggled display:none states stay inline in the Haml (behavioural, not styling).
 */

body:has(.dm-shell) { margin: 0; font-family: system-ui, sans-serif; background: #f5f5f5; }

/* ── Shell ── */
.dm-shell { display: flex; height: calc(100dvh - 80px); overflow: hidden; }

/* ── Sidebar ── */
.dm-shell .dm-sidebar { width: 240px; flex-shrink: 0; background: #fff; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; overflow-y: auto; }
.dm-shell .dm-sidebar__new { display: block; margin: 0.75rem; padding: 0.5rem 0.75rem; background: #465A64; color: #fff; border-radius: 0.5rem; font-size: 0.85rem; font-weight: 600; text-decoration: none; text-align: center; }
.dm-shell .dm-sidebar__new:hover { background: #1d4ed8; }
.dm-shell .dm-sidebar__item { display: block; padding: 0.6rem 0.75rem; border-bottom: 1px solid #f3f4f6; text-decoration: none; color: inherit; transition: background 0.1s; }
.dm-shell .dm-sidebar__item:hover { background: #f9fafb; }
.dm-shell .dm-sidebar__item--active { background: #eff6ff; border-left: 3px solid #465A64; }
.dm-shell .dm-sidebar__item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.dm-shell .dm-sidebar__label { font-size: 0.8rem; font-weight: 600; color: #374151; }
.dm-shell .dm-sidebar__badge { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; padding: 0.1rem 0.4rem; border-radius: 9999px; }
.dm-shell .dm-sidebar__badge--running { background: #e5eced; color: #1d4ed8; }
.dm-shell .dm-sidebar__badge--completed { background: #dcfce7; color: #15803d; }
.dm-shell .dm-sidebar__badge--failed { background: #fee2e2; color: #991b1b; }
.dm-shell .dm-sidebar__badge--queued { background: #f3f4f6; color: #6b7280; }
.dm-shell .dm-sidebar__meta { font-size: 0.7rem; color: #9ca3af; display: flex; gap: 0.25rem; flex-wrap: wrap; }
.dm-shell .dm-sidebar__dot { color: #d1d5db; }
.dm-shell .dm-sidebar__empty { padding: 1rem 0.75rem; font-size: 0.8rem; color: #9ca3af; }

/* ── New: upload page ── */
.dm-shell .dm-main-upload { flex: 1; overflow-y: auto; }
.dm-shell .dm-page { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.dm-shell .dm-header { margin-bottom: 2rem; }
.dm-shell .dm-header h1 { font-size: 1.75rem; font-weight: 700; margin: 0 0 0.5rem; }
.dm-shell .dm-header p { color: #6b7280; margin: 0; }
.dm-shell .dm-zones { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }
@media (max-width: 600px) { .dm-shell .dm-zones { grid-template-columns: 1fr; } }
.dm-shell .dm-zone { background: #fff; border: 2px dashed #d1d5db; border-radius: 0.75rem; padding: 1.5rem; }
.dm-shell .dm-zone.drag-over { border-color: #465A64; background: #eff6ff; }
.dm-shell .dm-zone__title { font-weight: 700; font-size: 1rem; margin-bottom: 0.25rem; }
.dm-shell .dm-zone__subtitle { font-size: 0.8rem; color: #6b7280; margin-bottom: 1rem; }
.dm-shell .dm-zone__drop { border: 1.5px dashed #d1d5db; border-radius: 0.5rem; padding: 2rem 1rem; text-align: center; color: #9ca3af; font-size: 0.875rem; cursor: pointer; margin-bottom: 0.75rem; transition: border-color 0.15s, background 0.15s; }
.dm-shell .dm-zone__drop:hover { border-color: #465A64; color: #465A64; background: #eff6ff; }
.dm-shell .dm-zone__input { display: none; }
.dm-shell .dm-zone__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.dm-shell .dm-zone__file { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 0.375rem; padding: 0.35rem 0.6rem; }
.dm-shell .dm-zone__file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-shell .dm-zone__file-size { color: #9ca3af; white-space: nowrap; }
.dm-shell .dm-zone__remove { background: none; border: none; cursor: pointer; color: #ef4444; font-size: 1rem; line-height: 1; padding: 0; flex-shrink: 0; }
.dm-shell .dm-modes { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.dm-shell .dm-mode-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; cursor: pointer; }
.dm-shell .dm-mode-label input { cursor: pointer; }
.dm-mode-hint { font-size: 0.75rem; color: #9ca3af; }
.dm-shell .dm-actions { display: flex; align-items: center; gap: 1rem; }
.dm-shell .dm-btn { padding: 0.65rem 1.75rem; border-radius: 0.5rem; font-size: 0.95rem; font-weight: 600; cursor: pointer; border: none; }
.dm-shell .dm-btn--primary { background: #465A64; color: #fff; }
.dm-shell .dm-btn--primary:hover { background: #1d4ed8; }
.dm-shell .dm-btn--primary:disabled { background: #93c5fd; cursor: not-allowed; }
.dm-shell .dm-hint { font-size: 0.8rem; color: #9ca3af; }
.dm-shell .dm-prompt { margin-top: 1.5rem; }
.dm-shell .dm-prompt__label { font-size: 0.875rem; font-weight: 600; color: #374151; margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.75rem; }
.dm-shell .dm-prompt__reset { font-size: 0.75rem; font-weight: 400; color: #465A64; cursor: pointer; background: none; border: none; padding: 0; }
.dm-shell .dm-prompt__reset:hover { text-decoration: underline; }
.dm-shell .dm-prompt__textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.8rem; line-height: 1.5; color: #374151; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 0.5rem; padding: 0.75rem; box-sizing: border-box; resize: vertical; }
.dm-shell .dm-prompt__textarea:focus { outline: none; border-color: #465A64; background: #fff; }
.dm-shell .dm-prompt__hint { font-size: 0.75rem; color: #9ca3af; margin-top: 0.4rem; }

/* ── Edit: main chat area ── */
.dm-shell .dm-main { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; min-width: 0; }
.dm-shell .messages { flex: 1; overflow-y: auto; padding: 1rem; padding-bottom: 160px; display: flex; flex-direction: column; gap: 0.75rem; }
.dm-shell .chat-form-wrapper { position: absolute; bottom: 12px; left: 12px; right: 12px; background: #fff; border-radius: 12px; box-shadow: 0 2px 16px rgba(0,0,0,.10); padding: 0.75rem 1rem 1rem; z-index: 10; }
.dm-shell #status { padding: 0.25rem 1rem; font-size: 0.75rem; color: #888; min-height: 1.5rem; }

/* ── Workspace result card ── */
.dm-shell .dm-result-card { border-radius: 1rem; border: 1px solid #e5e7eb; background: #fff; overflow: hidden; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.dm-shell .dm-result-card__header { background: linear-gradient(135deg, #f0fdf4 0%, #eff6ff 100%); border-bottom: 1px solid #e5e7eb; padding: 0.9rem 1.25rem 0.75rem; display: flex; align-items: center; gap: 0.5rem; }
.dm-result-card__emoji { font-size: 1.2rem; }
.dm-shell .dm-result-card__title { font-size: 0.9rem; font-weight: 700; color: #111827; }
.dm-shell .dm-result-card__body { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; }
.dm-shell .dm-flow__box { padding: 1rem 1.25rem; min-height: 80px; }
.dm-shell .dm-flow__box--sources  { border-top: 3px solid #6366f1; }
.dm-shell .dm-flow__box--template { border-top: 3px solid #f59e0b; }
.dm-shell .dm-flow__box--output   { border-top: 3px solid #10b981; background: #f0fdf4; }
.dm-shell .dm-flow__box--empty    { opacity: 0.45; }
.dm-shell .dm-flow__arrow { display: flex; align-items: center; justify-content: center; padding: 0 0.5rem; color: #d1d5db; font-size: 1.25rem; border-top: 1px solid #f3f4f6; }
.dm-shell .dm-flow__label { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.6rem; }
.dm-shell .dm-flow__box--sources  .dm-flow__label { color: #6366f1; }
.dm-shell .dm-flow__box--template .dm-flow__label { color: #d97706; }
.dm-shell .dm-flow__box--output   .dm-flow__label { color: #059669; }
.dm-shell .dm-flow__file { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.25rem; }
.dm-shell .dm-flow__link { font-size: 0.78rem; font-family: monospace; color: #465A64; text-decoration: none; }
.dm-shell .dm-flow__link:hover { text-decoration: underline; }
.dm-shell .dm-flow__badge { font-size: 0.58rem; font-weight: 700; padding: 0.15rem 0.4rem; border-radius: 9999px; white-space: nowrap; flex-shrink: 0; }
.dm-shell .dm-flow__badge--final  { background: #d1fae5; color: #065f46; }
.dm-shell .dm-flow__badge--script { background: #ede9fe; color: #4c1d95; }
.dm-shell .dm-flow__divider { border: none; border-top: 1px solid #e5e7eb; margin: 0.5rem 0; }
.dm-shell .dm-flow__sublabel { font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #9ca3af; margin-bottom: 0.3rem; }
.dm-shell .dm-flow__empty-hint { font-size: 0.75rem; color: #9ca3af; font-style: italic; }
.dm-shell .dm-result-card__footer { padding: 0.75rem 1.25rem; border-top: 1px solid #e5e7eb; background: #fafafa; display: flex; align-items: center; gap: 1rem; }
.dm-shell .dm-verify-btn { padding: 0.45rem 1.1rem; background: #f0fdf4; border: 1px solid #6ee7b7; border-radius: 0.5rem; font-size: 0.85rem; font-weight: 600; color: #065f46; cursor: pointer; display: flex; align-items: center; gap: 0.4rem; }
.dm-shell .dm-verify-btn:hover { background: #dcfce7; border-color: #34d399; }
.dm-shell .dm-verify-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.dm-shell .dm-verify-hint { font-size: 0.75rem; color: #9ca3af; }

/* ── Event bubbles ── */
.dm-shell .event-row { display: flex; gap: 1rem; align-items: flex-start; }
.dm-shell .event-time { font-size: 0.7rem; color: #9ca3af; font-family: monospace; white-space: nowrap; padding-top: 0.8rem; min-width: 5.5rem; text-align: right; }
.dm-shell .event-body { flex: 1; min-width: 0; }
.dm-shell .event-bubble { border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem; line-height: 1.6; }
.dm-shell .event-label { font-weight: 700; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.3rem; }
.dm-shell .bubble--streaming { opacity: 0.85; }
.dm-shell .event-start { background: #e5eced; border-left: 3px solid #5a7280; }
.dm-shell .event-start .event-label { color: #1d4ed8; }
.dm-shell .event-start .event-content { color: #1e3a8a; white-space: pre-wrap; }
.dm-shell .event-text { background: #fff; border: 1px solid #e5e7eb; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.dm-shell .event-text .event-content { color: #374151; overflow-wrap: break-word; word-break: break-word; }
.dm-shell .event-tool { background: #fffbeb; border-left: 3px solid #f59e0b; }
.dm-shell .event-tool .event-label { color: #b45309; }
.dm-shell .event-tool .event-content { font-family: monospace; font-size: 0.8rem; color: #78350f; }
.dm-shell .event-thinking { background: #f3f4f6; border-left: 3px solid #9ca3af; }
.dm-shell .event-thinking .event-label { color: #6b7280; }
.dm-shell .event-thinking .event-content { color: #4b5563; font-style: italic; white-space: pre-wrap; }
.dm-shell .event-tool-result { background: #f9fafb; border-left: 3px solid #d1d5db; }
.dm-shell .event-tool-result .event-label { color: #6b7280; }
.dm-shell .event-tool-result .event-content { color: #374151; white-space: pre-wrap; }
.dm-shell .event-error { background: #fee2e2; border-left: 3px solid #ef4444; }
.dm-shell .event-error .event-label { color: #991b1b; }
.dm-shell .event-error .event-content { color: #7f1d1d; font-family: monospace; font-size: 0.8rem; word-break: break-all; }
.dm-shell .event-other { background: #f9fafb; border: 1px solid #f3f4f6; }
.dm-shell .event-other .event-label { color: #9ca3af; }
.dm-shell .event-md > *:first-child { margin-top: 0; }
.dm-shell .event-md > *:last-child { margin-bottom: 0; }
.dm-shell .event-md h1, .dm-shell .event-md h2, .dm-shell .event-md h3 { font-weight: 700; margin: 1em 0 0.4em; line-height: 1.3; }
.dm-shell .event-md h1 { font-size: 1.25em; }
.dm-shell .event-md h2 { font-size: 1.1em; }
.dm-shell .event-md h3 { font-size: 1em; }
.dm-shell .event-md p { margin: 0.4em 0; }
.dm-shell .event-md ul, .dm-shell .event-md ol { margin: 0.4em 0; padding-left: 1.5em; }
.dm-shell .event-md li { margin: 0.1em 0; }
.dm-shell .event-md code { background: #f3f4f6; border-radius: 0.2em; padding: 0.1em 0.3em; font-family: monospace; font-size: 0.85em; }
.dm-shell .event-md pre { background: #f3f4f6; border-radius: 0.375rem; padding: 0.75em 1em; overflow-x: auto; margin: 0.5em 0; }
.dm-shell .event-md pre code { background: none; padding: 0; font-size: 0.8em; }
.dm-shell .event-md hr { border: none; border-top: 1px solid #e5e7eb; margin: 0.75em 0; }
.dm-shell .event-md strong { font-weight: 700; }
.dm-shell .event-md em { font-style: italic; }
.dm-shell .event-md blockquote { border-left: 3px solid #d1d5db; margin: 0.5em 0; padding: 0 0.75em; color: #6b7280; }
.dm-shell .event-md table { border-collapse: collapse; width: 100%; margin: 0.6em 0; font-size: 0.875em; }
.dm-shell .event-md th, .dm-shell .event-md td { border: 1px solid #e5e7eb; padding: 0.4em 0.75em; text-align: left; }
.dm-shell .event-md th { background: #f9fafb; font-weight: 600; }
.dm-shell .event-md tr:nth-child(even) { background: #f9fafb; }

/* ── Chat form ── */
.dm-shell .dm-main textarea { width: 100%; box-sizing: border-box; padding: 0.6rem 0.75rem; border: 1px solid #ccc; border-radius: 0.5rem; resize: none; font-size: 1rem; font-family: inherit; line-height: 1.4; }
.dm-shell .dm-main textarea:focus { outline: none; border-color: #465A64; }
.dm-shell .dm-main textarea:disabled { background: #f9f9f9; color: #aaa; }
.dm-shell .form-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 0.4rem; }
.dm-shell .form-modes { display: flex; gap: 1rem; font-size: 0.8rem; color: #6b7280; }
.dm-shell .form-modes label { display: flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.dm-form-send-row { display: flex; gap: 0.5rem; align-items: center; }
.dm-shell .dm-main input[type=submit] { padding: 0.5rem 1.2rem; background: #465A64; color: #fff; border: none; border-radius: 0.5rem; cursor: pointer; font-size: 0.9rem; }
.dm-shell .dm-main input[type=submit]:disabled { background: #93c5fd; cursor: not-allowed; }

/* ── Files drawer ── */
.dm-shell .dm-files-btn { padding: 0.45rem 0.85rem; background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 0.5rem; font-size: 0.85rem; font-weight: 500; color: #374151; cursor: pointer; white-space: nowrap; }
.dm-shell .dm-files-btn:hover { background: #e5e7eb; }
.dm-shell .dm-files-btn--active { background: #eff6ff; border-color: #465A64; color: #465A64; }
.dm-shell .dm-files-drawer { overflow-y: auto; max-height: 180px; margin-bottom: 0.25rem; }
.dm-shell .dm-files-list { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; padding: 0.25rem 0; }
.dm-shell .dm-files-group { min-width: 130px; }
.dm-shell .dm-files-group__label { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: #9ca3af; margin-bottom: 0.3rem; }
.dm-shell .dm-files-group__label--sources { color: #6366f1; }
.dm-shell .dm-files-group__label--goals   { color: #d97706; }
.dm-shell .dm-files-group__label--output  { color: #059669; }
.dm-shell .dm-files-group__label--scripts { color: #7c3aed; }
.dm-shell .dm-files-item { display: block; font-size: 0.78rem; font-family: monospace; color: #465A64; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; padding: 0.1rem 0; }
.dm-shell .dm-files-item:hover { text-decoration: underline; }
.dm-shell .dm-files-item--final { font-weight: 700; color: #059669; }
.dm-shell .dm-files-item--script { color: #7c3aed; }
.dm-shell .dm-files-empty { font-size: 0.8rem; color: #9ca3af; font-style: italic; padding: 0.5rem 0; }
.dm-shell .spinner { display: inline-block; width: 0.7em; height: 0.7em; border: 2px solid #bbb; border-top-color: #555; border-radius: 50%; animation: dm-spin 0.7s linear infinite; margin-left: 0.4rem; vertical-align: middle; }
@keyframes dm-spin { to { transform: rotate(360deg); } }
.dm-shell .waiting-placeholder { display: flex; align-items: center; gap: 0.5rem; justify-content: center; color: #9ca3af; font-size: 0.875rem; padding: 2rem 0; }
.dm-shell .waiting-placeholder:not(:only-child) { display: none; }
