/* 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: var(--font-base); background: var(--grey-100); }

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

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

.pa-shell .dm-sidebar { width: 240px; flex-shrink: 0; background: var(--white); border-right: 1px solid var(--rule); display: flex; flex-direction: column; overflow-y: auto; }
.pa-shell .dm-sidebar__new { display: block; margin: 0.75rem; padding: 0.5rem 0.75rem; background: var(--bm-main); color: var(--white); border-radius: var(--radius-none); font-size: 0.85rem; font-weight: 600; text-decoration: none; text-align: center; }
.pa-shell .dm-sidebar__new:hover { background: var(--fill-primary); }
.pa-shell .dm-sidebar__item { display: block; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--grey-100); text-decoration: none; color: inherit; transition: background 0.1s; }
.pa-shell .dm-sidebar__item:hover { background: var(--grey-100); }
.pa-shell .dm-sidebar__item--active { background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); border-left: 3px solid var(--bm-main); }
.pa-shell .dm-sidebar__label { font-size: 0.8rem; font-weight: 600; color: var(--fill-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.2rem; }
.pa-shell .dm-sidebar__meta { font-size: 0.7rem; color: var(--grey-400); }
.pa-shell .dm-sidebar__empty { padding: 1rem 0.75rem; font-size: 0.8rem; color: var(--grey-400); }

/* ── 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: var(--fill-primary); margin-bottom: 0.4rem; }
.pa-shell--start .pa-start__sub { font-size: 0.95rem; color: var(--grey-600); margin-bottom: 2rem; }
.pa-shell--start .pa-start__form { background: var(--white); border-radius: var(--radius-none); box-shadow: none; padding: 1.25rem 1.5rem 1.5rem; }
.pa-shell--start textarea {
  width: 100%; box-sizing: border-box; padding: 0.75rem 1rem;
  border: 1px solid var(--rule); border-radius: var(--radius-none);
  resize: none; font-size: 1rem; font-family: inherit; line-height: 1.5;
  min-height: 220px; color: var(--fill-primary);
}
.pa-shell--start textarea:focus { outline: none; border-color: var(--bm-main); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bm-main) 10%, transparent); }
.pa-shell--start textarea.textarea--default { color: var(--grey-400); }
.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: var(--bm-main); color: var(--white); border: none; border-radius: var(--radius-none); cursor: pointer; font-size: 0.95rem; font-weight: 600; }
.pa-shell--start input[type=submit]:hover { background: var(--fill-primary); }

/* ── 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: var(--white); border-radius: var(--radius-none); box-shadow: none; 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: var(--grey-400); 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: var(--radius-none); 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: color-mix(in srgb, var(--bm-main) 12%, var(--white)); border-left: 3px solid var(--bm-main); }
.pa-shell--chat .event-start .event-label { color: var(--bm-main); }
.pa-shell--chat .event-start .event-content { color: var(--fill-primary); white-space: pre-wrap; }

.pa-shell--chat .event-text { background: var(--white); border: 1px solid var(--rule); box-shadow: none; }
.pa-shell--chat .event-text .event-content { color: var(--fill-primary); overflow-wrap: break-word; word-break: break-word; }

.pa-shell--chat .event-tool { background: color-mix(in srgb, var(--status-warn) 12%, var(--white)); border-left: 3px solid var(--status-warn); }
.pa-shell--chat .event-tool .event-label { color: var(--status-warn); }
.pa-shell--chat .event-tool .event-content { font-family: monospace; font-size: 0.8rem; color: var(--status-warn); }

.pa-shell--chat .event-thinking { background: var(--grey-100); border-left: 3px solid var(--grey-400); }
.pa-shell--chat .event-thinking .event-label { color: var(--grey-600); }
.pa-shell--chat .event-thinking .event-content { color: var(--grey-600); font-style: italic; white-space: pre-wrap; }

.pa-shell--chat .event-tool-result { background: var(--grey-100); border-left: 3px solid var(--rule); }
.pa-shell--chat .event-tool-result .event-label { color: var(--grey-600); }
.pa-shell--chat .event-tool-result .event-content { color: var(--fill-primary); white-space: pre-wrap; }

.pa-shell--chat .event-error { background: color-mix(in srgb, var(--status-error) 12%, var(--white)); border-left: 3px solid var(--status-error); }
.pa-shell--chat .event-error .event-label { color: var(--status-error); }
.pa-shell--chat .event-error .event-content { color: var(--status-error); font-family: monospace; font-size: 0.8rem; word-break: break-all; }

.pa-shell--chat .event-other { background: var(--grey-100); border: 1px solid var(--grey-100); }
.pa-shell--chat .event-other .event-label { color: var(--grey-400); }

/* ── 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: var(--grey-100); border-radius: var(--radius-none); padding: 0.1em 0.3em; font-family: monospace; font-size: 0.85em; }
.pa-shell--chat .event-md pre { background: var(--grey-100); border-radius: var(--radius-none); 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 var(--rule); 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 var(--rule); margin: 0.5em 0; padding: 0 0.75em; color: var(--grey-600); }
.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 var(--rule); padding: 0.4em 0.75em; text-align: left; }
.pa-shell--chat .event-md th { background: var(--grey-100); font-weight: 600; }
.pa-shell--chat .event-md tr:nth-child(even) { background: var(--grey-100); }

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

.pa-shell--chat .drop-zone { position: relative; }
.pa-shell--chat .drop-zone.drag-over textarea { border-color: var(--bm-main); background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); }
.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: color-mix(in srgb, var(--bm-main) 12%, var(--white)); border: 1px solid color-mix(in srgb, var(--bm-main) 30%, var(--white)); border-radius: var(--radius-none); font-size: 0.8rem; color: var(--bm-main); }
.pa-shell--chat .file-chip button { background: none; border: none; cursor: pointer; color: var(--bm-main); font-size: 0.75rem; padding: 0; line-height: 1; }
.pa-shell--chat .file-chip button:hover { color: var(--bm-main); }

.pa-shell--chat .dm-files-btn { padding: 0.45rem 0.85rem; background: var(--grey-100); border: 1px solid var(--rule); border-radius: var(--radius-none); font-size: 0.85rem; font-weight: 500; color: var(--fill-primary); cursor: pointer; white-space: nowrap; }
.pa-shell--chat .dm-files-btn:hover { background: var(--rule); }
.pa-shell--chat .dm-files-btn--active { background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); border-color: var(--bm-main); color: var(--bm-main); }
.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: var(--radius-none); transition: border-color 0.15s, background 0.15s; }
.pa-shell--chat .dm-files-drawer.drag-over { border-color: var(--bm-main); background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); }
.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: var(--grey-400); margin-bottom: 0.3rem; }
.pa-shell--chat .dm-files-item { display: block; font-size: 0.78rem; font-family: monospace; color: var(--bm-main); 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: var(--grey-400); 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 var(--rule); border-radius: var(--radius-none); resize: none; font-size: 1rem; font-family: inherit; line-height: 1.4; }
.pa-shell--chat textarea:focus { outline: none; border-color: var(--bm-main); }
.pa-shell--chat textarea:disabled { background: var(--grey-100); color: var(--grey-400); }
.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: var(--bm-main); color: var(--white); border: none; border-radius: var(--radius-none); cursor: pointer; font-size: 0.9rem; }
.pa-shell--chat input[type=submit]:disabled { background: var(--bm-main); cursor: not-allowed; }
.pa-shell--chat .btn-send { padding: 0.5rem 1.2rem; background: var(--bm-main); color: var(--white); border: none; border-radius: var(--radius-none); cursor: pointer; font-size: 0.9rem; }
.pa-shell--chat .btn-send:disabled { background: var(--bm-main); cursor: not-allowed; }
.pa-shell--chat .file-download-link { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.6rem; background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); border: 1px solid color-mix(in srgb, var(--bm-main) 30%, var(--white)); border-radius: var(--radius-none); font-size: 0.8rem; color: var(--bm-main); text-decoration: none; font-family: monospace; }
.pa-shell--chat .file-download-link:hover { background: color-mix(in srgb, var(--bm-main) 12%, var(--white)); }
.pa-shell--chat .spinner { display: inline-block; width: 0.7em; height: 0.7em; border: 2px solid var(--grey-400); border-top-color: var(--grey-600); border-radius: var(--radius-none); 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: var(--grey-400); font-size: 0.875rem; padding: 2rem 0; }
.pa-shell--chat .waiting-placeholder:not(:last-child) { display: none; }
