/* Personal Agent — extracted from the inline <style> blocks in new/edit.html.haml,
   following the tools/prompt_rules.css pattern. Scoped to .pa-shell (page roots
   carry .pa-shell--start / .pa-shell--chat) because the dm-* class names are
   shared with DocMixer, which must not pick these rules up. */

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

/* ── Shell + sidebar (both pages) ──────────────────────────────────────── */

.pa-shell { display: flex; height: calc(100dvh - 80px); overflow: hidden; }

.pa-shell .dm-sidebar { width: 240px; flex-shrink: 0; background: #fff; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; overflow-y: auto; }
.pa-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; }
.pa-shell .dm-sidebar__new:hover { background: #374151; }
.pa-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; }
.pa-shell .dm-sidebar__item:hover { background: #f9fafb; }
.pa-shell .dm-sidebar__item--active { background: #eff6ff; border-left: 3px solid #465A64; }
.pa-shell .dm-sidebar__label { font-size: 0.8rem; font-weight: 600; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.2rem; }
.pa-shell .dm-sidebar__meta { font-size: 0.7rem; color: #9ca3af; }
.pa-shell .dm-sidebar__empty { padding: 1rem 0.75rem; font-size: 0.8rem; color: #9ca3af; }

/* ── Start page (new) ──────────────────────────────────────────────────── */

.pa-shell--start .pa-main { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 2rem 2rem; overflow-y: auto; }
.pa-shell--start .pa-start__inner { width: 100%; max-width: 760px; }
.pa-shell--start .pa-start__heading { font-size: 1.5rem; font-weight: 700; color: #111827; margin-bottom: 0.4rem; }
.pa-shell--start .pa-start__sub { font-size: 0.95rem; color: #6b7280; margin-bottom: 2rem; }
.pa-shell--start .pa-start__form { background: #fff; border-radius: 1rem; box-shadow: 0 2px 16px rgba(0,0,0,.08); padding: 1.25rem 1.5rem 1.5rem; }
.pa-shell--start textarea {
  width: 100%; box-sizing: border-box; padding: 0.75rem 1rem;
  border: 1px solid #d1d5db; border-radius: 0.5rem;
  resize: none; font-size: 1rem; font-family: inherit; line-height: 1.5;
  min-height: 220px; color: #111827;
}
.pa-shell--start textarea:focus { outline: none; border-color: #465A64; box-shadow: 0 0 0 3px rgba(70,90,100,0.1); }
.pa-shell--start textarea.textarea--default { color: #9ca3af; }
.pa-shell--start .pa-start__actions { display: flex; justify-content: flex-end; margin-top: 0.75rem; }
.pa-shell--start input[type=submit] { padding: 0.6rem 1.5rem; background: #465A64; color: #fff; border: none; border-radius: 0.5rem; cursor: pointer; font-size: 0.95rem; font-weight: 600; }
.pa-shell--start input[type=submit]:hover { background: #374151; }

/* ── Chat page (edit): main area ───────────────────────────────────────── */

.pa-shell--chat .dm-main { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; min-width: 0; }
.pa-shell--chat .messages { flex: 1; overflow-y: auto; padding: 1rem; padding-bottom: 280px; display: flex; flex-direction: column; gap: 0.75rem; }
.pa-shell--chat .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; }

/* ── Event bubbles ─────────────────────────────────────────────────────── */

.pa-shell--chat .event-row { display: flex; gap: 1rem; align-items: flex-start; }
.pa-shell--chat .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; }
.pa-shell--chat .event-body { flex: 1; min-width: 0; }
.pa-shell--chat .event-bubble { border-radius: 0.75rem; padding: 0.75rem 1rem; font-size: 0.875rem; line-height: 1.6; }
.pa-shell--chat .event-label { font-weight: 700; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.3rem; }
.pa-shell--chat .bubble--streaming { opacity: 0.85; }

.pa-shell--chat .event-start { background: #e5eced; border-left: 3px solid #5a7280; }
.pa-shell--chat .event-start .event-label { color: #1d4ed8; }
.pa-shell--chat .event-start .event-content { color: #1e3a8a; white-space: pre-wrap; }

.pa-shell--chat .event-text { background: #fff; border: 1px solid #e5e7eb; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.pa-shell--chat .event-text .event-content { color: #374151; overflow-wrap: break-word; word-break: break-word; }

.pa-shell--chat .event-tool { background: #fffbeb; border-left: 3px solid #f59e0b; }
.pa-shell--chat .event-tool .event-label { color: #b45309; }
.pa-shell--chat .event-tool .event-content { font-family: monospace; font-size: 0.8rem; color: #78350f; }

.pa-shell--chat .event-thinking { background: #f3f4f6; border-left: 3px solid #9ca3af; }
.pa-shell--chat .event-thinking .event-label { color: #6b7280; }
.pa-shell--chat .event-thinking .event-content { color: #4b5563; font-style: italic; white-space: pre-wrap; }

.pa-shell--chat .event-tool-result { background: #f9fafb; border-left: 3px solid #d1d5db; }
.pa-shell--chat .event-tool-result .event-label { color: #6b7280; }
.pa-shell--chat .event-tool-result .event-content { color: #374151; white-space: pre-wrap; }

.pa-shell--chat .event-error { background: #fee2e2; border-left: 3px solid #ef4444; }
.pa-shell--chat .event-error .event-label { color: #991b1b; }
.pa-shell--chat .event-error .event-content { color: #7f1d1d; font-family: monospace; font-size: 0.8rem; word-break: break-all; }

.pa-shell--chat .event-other { background: #f9fafb; border: 1px solid #f3f4f6; }
.pa-shell--chat .event-other .event-label { color: #9ca3af; }

/* ── Markdown ──────────────────────────────────────────────────────────── */

.pa-shell--chat .event-md > *:first-child { margin-top: 0; }
.pa-shell--chat .event-md > *:last-child { margin-bottom: 0; }
.pa-shell--chat .event-md h1, .pa-shell--chat .event-md h2, .pa-shell--chat .event-md h3 { font-weight: 700; margin: 1em 0 0.4em; line-height: 1.3; }
.pa-shell--chat .event-md h1 { font-size: 1.25em; }
.pa-shell--chat .event-md h2 { font-size: 1.1em; }
.pa-shell--chat .event-md h3 { font-size: 1em; }
.pa-shell--chat .event-md p { margin: 0.4em 0; }
.pa-shell--chat .event-md ul, .pa-shell--chat .event-md ol { margin: 0.4em 0; padding-left: 1.5em; }
.pa-shell--chat .event-md li { margin: 0.1em 0; }
.pa-shell--chat .event-md code { background: #f3f4f6; border-radius: 0.2em; padding: 0.1em 0.3em; font-family: monospace; font-size: 0.85em; }
.pa-shell--chat .event-md pre { background: #f3f4f6; border-radius: 0.375rem; padding: 0.75em 1em; overflow-x: auto; margin: 0.5em 0; }
.pa-shell--chat .event-md pre code { background: none; padding: 0; font-size: 0.8em; }
.pa-shell--chat .event-md hr { border: none; border-top: 1px solid #e5e7eb; margin: 0.75em 0; }
.pa-shell--chat .event-md strong { font-weight: 700; }
.pa-shell--chat .event-md em { font-style: italic; }
.pa-shell--chat .event-md blockquote { border-left: 3px solid #d1d5db; margin: 0.5em 0; padding: 0 0.75em; color: #6b7280; }
.pa-shell--chat .event-md table { border-collapse: collapse; width: 100%; margin: 0.6em 0; font-size: 0.875em; }
.pa-shell--chat .event-md th, .pa-shell--chat .event-md td { border: 1px solid #e5e7eb; padding: 0.4em 0.75em; text-align: left; }
.pa-shell--chat .event-md th { background: #f9fafb; font-weight: 600; }
.pa-shell--chat .event-md tr:nth-child(even) { background: #f9fafb; }

/* ── Drop zone + file chips ────────────────────────────────────────────── */

.pa-shell--chat .drop-zone { position: relative; }
.pa-shell--chat .drop-zone.drag-over textarea { border-color: #465A64; background: #f0f9ff; }
.pa-shell--chat .staged-files { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.3rem 0; min-height: 0; }
.pa-shell--chat .file-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.5rem 0.2rem 0.75rem; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 9999px; font-size: 0.8rem; color: #1d4ed8; }
.pa-shell--chat .file-chip button { background: none; border: none; cursor: pointer; color: #93c5fd; font-size: 0.75rem; padding: 0; line-height: 1; }
.pa-shell--chat .file-chip button:hover { color: #1d4ed8; }

.pa-shell--chat .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; }
.pa-shell--chat .dm-files-btn:hover { background: #e5e7eb; }
.pa-shell--chat .dm-files-btn--active { background: #eff6ff; border-color: #465A64; color: #465A64; }
.pa-shell--chat .dm-files-drawer { overflow-y: auto; min-height: 160px; max-height: 260px; margin-bottom: 0.25rem; border: 2px solid transparent; border-radius: 0.5rem; transition: border-color 0.15s, background 0.15s; }
.pa-shell--chat .dm-files-drawer.drag-over { border-color: #465A64; background: #f0f9ff; }
.pa-shell--chat .dm-files-list { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; padding: 0.25rem 0; }
.pa-shell--chat .dm-files-group { flex: 1; min-width: 160px; overflow: hidden; }
.pa-shell--chat .dm-files-group__label { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: #9ca3af; margin-bottom: 0.3rem; }
.pa-shell--chat .dm-files-item { display: block; font-size: 0.78rem; font-family: monospace; color: #465A64; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; padding: 0.1rem 0; }
.pa-shell--chat .dm-files-empty { font-size: 0.8rem; color: #9ca3af; font-style: italic; padding: 0.5rem 0; }

/* ── Form ──────────────────────────────────────────────────────────────── */

.pa-shell--chat 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; }
.pa-shell--chat textarea:focus { outline: none; border-color: #465A64; }
.pa-shell--chat textarea:disabled { background: #f9f9f9; color: #aaa; }
.pa-shell--chat .form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem; margin-top: 0.4rem; }
.pa-shell--chat input[type=submit] { padding: 0.5rem 1.2rem; background: #465A64; color: #fff; border: none; border-radius: 0.5rem; cursor: pointer; font-size: 0.9rem; }
.pa-shell--chat input[type=submit]:disabled { background: #93c5fd; cursor: not-allowed; }
.pa-shell--chat .btn-send { padding: 0.5rem 1.2rem; background: #465A64; color: #fff; border: none; border-radius: 0.5rem; cursor: pointer; font-size: 0.9rem; }
.pa-shell--chat .btn-send:disabled { background: #93c5fd; cursor: not-allowed; }
.pa-shell--chat .file-download-link { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.6rem; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 0.375rem; font-size: 0.8rem; color: #1d4ed8; text-decoration: none; font-family: monospace; }
.pa-shell--chat .file-download-link:hover { background: #dbeafe; }
.pa-shell--chat .spinner { display: inline-block; width: 0.7em; height: 0.7em; border: 2px solid #bbb; border-top-color: #555; border-radius: 50%; animation: spin 0.7s linear infinite; margin-left: 0.4rem; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.pa-shell--chat .waiting-placeholder { display: flex; align-items: center; gap: 0.5rem; justify-content: center; color: #9ca3af; font-size: 0.875rem; padding: 2rem 0; }
.pa-shell--chat .waiting-placeholder:not(:last-child) { display: none; }
