/* ============================================================
   CoreRoom — agent chat rework. Robust scroll (JS-sized thread),
   proper message rendering, file-download cards, and a composer with
   file/image attachments + voice. Layered on the prototype's styles.
   ============================================================ */

/* The thread height is set explicitly by JS (coreroom-chat.js) so scrolling
   never depends on a fragile flex/grid chain. */
.thread { overflow-y: auto; overflow-x: hidden; }
/* The thread is a flex column with a fixed height — its children must NOT shrink,
   or they get compressed to fit (squished/empty bubbles) and it never overflows to
   scroll. Pin every message to its natural height so the thread scrolls instead. */
.thread > * { flex: 0 0 auto; }

/* message bodies */
.thread .bubble p { margin: 0 0 8px; }
.thread .bubble p:last-child { margin-bottom: 0; }
.thread .bubble a { color: var(--accent-ink); text-decoration: underline; word-break: break-word; }
.thread .bubble code { font-family: var(--mono); font-size: 12px; background: rgba(120,110,95,0.12); padding: 1px 5px; border-radius: 5px; }
.thread .bubble pre { font-family: var(--mono); font-size: 12px; background: var(--ink); color: #f3efe7; padding: 10px 12px; border-radius: 9px; overflow-x: auto; margin: 8px 0; }

/* file-download card (agent outputs + user attachments) */
.cr-file { display: flex; align-items: center; gap: 10px; border: 1px solid var(--hairline); border-radius: 10px; background: var(--surface-warm); padding: 9px 11px; margin-top: 8px; text-decoration: none; }
.cr-file:hover { border-color: var(--accent); }
.cr-file .cf-ic { width: 30px; height: 30px; flex: none; border-radius: 7px; background: var(--accent-soft); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.cr-file .cf-ic svg { width: 16px; height: 16px; }
.cr-file .cf-meta { min-width: 0; }
.cr-file .cf-name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-file .cf-sub { font-size: 11px; color: var(--faint); font-family: var(--mono); }
.cr-file .cf-dl { margin-left: auto; color: var(--muted); flex: none; }
.cr-file img.cf-thumb { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; flex: none; }

/* composer attachments row */
.cr-attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.cr-chip { display: flex; align-items: center; gap: 6px; background: var(--surface-warm); border: 1px solid var(--hairline); border-radius: 8px; padding: 4px 6px 4px 8px; font-size: 12px; color: var(--ink); max-width: 200px; }
.cr-chip img { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; }
.cr-chip .cc-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-chip .cc-x { cursor: pointer; color: var(--faint); display: flex; }
.cr-chip.uploading { opacity: 0.6; }

/* composer tool buttons */
.cr-tools { display: flex; align-items: center; gap: 2px; }
.cr-tool { width: 32px; height: 32px; border: none; background: transparent; border-radius: 8px; cursor: pointer; color: var(--muted); display: flex; align-items: center; justify-content: center; transition: background 0.14s, color 0.14s; }
.cr-tool:hover { background: rgba(120,110,95,0.1); color: var(--ink); }
.cr-tool svg { width: 18px; height: 18px; }
.cr-tool.rec { color: #fff; background: var(--accent); animation: cr-pulse 1.2s ease-in-out infinite; }
@keyframes cr-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
.composer-box { align-items: center; }
.composer-box textarea { align-self: center; }
/* drag files over the composer to attach them (paste also works) */
.composer.cr-dragover { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 12px; background: rgba(180,83,9,0.05); }

/* ---- a slightly wider, cleaner agent panel ---- */
.app { --agent-w: 420px; }
/* The topbar (z3) can overflow its column and spill its "Agent" button ~100px into
   the panel, clipping the "CoreRoom Agent" title. Paint the panel above it. When the
   panel is collapsed it has zero width, so the topbar button is still reachable. */
.agent { position: relative; z-index: 4; }
.agent-head { padding: 14px 14px 14px 18px; gap: 11px; }
.agent-head .ah-name { font-size: 14.5px; letter-spacing: -0.01em; }

/* chat-session toolbar in the header */
.cr-chatbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 18px; border-bottom: 1px solid var(--hairline-soft); flex: none; }
.cr-chatbar .cr-sess { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; background: transparent; border: 1px solid var(--hairline); border-radius: 9px; padding: 6px 10px; cursor: pointer; font-family: var(--sans); font-size: 13px; color: var(--ink); }
.cr-chatbar .cr-sess:hover { background: var(--surface-warm); }
.cr-chatbar .cr-sess .cs-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.cr-chatbar .cr-sess svg { width: 14px; height: 14px; color: var(--faint); flex: none; }
.cr-chatbar .cr-new { flex: none; display: flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-ink); border: 1px solid rgba(180,83,9,0.18); border-radius: 9px; padding: 6px 11px; cursor: pointer; font-family: var(--sans); font-size: 13px; font-weight: 600; }
.cr-chatbar .cr-new:hover { background: #F1DCC6; }
.cr-chatbar .cr-new svg { width: 15px; height: 15px; }

/* sessions dropdown */
.cr-sessmenu { position: absolute; z-index: 40; background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; box-shadow: var(--glass-shadow); padding: 6px; min-width: 260px; max-height: 320px; overflow-y: auto; }
.cr-sessmenu .csm-item { display: block; width: 100%; text-align: left; border: none; background: transparent; border-radius: 8px; padding: 9px 11px; cursor: pointer; }
.cr-sessmenu .csm-item:hover { background: var(--surface-warm); }
.cr-sessmenu .csm-item.on { background: var(--accent-soft); }
.cr-sessmenu .csm-title { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-sessmenu .csm-sub { font-size: 11px; color: var(--faint); font-family: var(--mono); margin-top: 2px; }
.cr-sessmenu .csm-empty { font-size: 12.5px; color: var(--muted); padding: 10px 11px; }

/* ---- real, generic agent-setup ---- */
.ac-help { font-size: 12px; color: var(--muted); line-height: 1.5; padding: 0 16px 4px; margin: -2px 0 6px; }
.ac-eff { display: flex; gap: 9px; align-items: flex-start; font-size: 12px; color: var(--muted); line-height: 1.5; }
.ac-eff-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; margin-top: 4px; box-shadow: 0 0 0 3px rgba(63,98,18,0.14); }
.ac-seg button { font-weight: 600; }

/* ---- remove the stray left rule on agent messages (the "line" gremlin) ---- */
.thread .msg { border: 0; }

/* ---- tighter, smaller, more professional chat + settings ---- */
.thread { padding: 18px 18px; gap: 16px; }
.thread .from { font-size: 9.5px; letter-spacing: 0.14em; }
.thread .bubble { font-size: 13px; line-height: 1.55; }
.thread .msg.agent .bubble { padding: 11px 13px; }
.agent-head .ah-name { font-size: 14px; }
.agent-head .ah-sub { font-size: 11px; }

.agent-config .ac-head { padding: 11px 16px; }
.agent-config .ac-title { font-size: 12.5px; }
.agent-config .ac-summary { font-size: 12px; }
.agent-config.open .ac-body { padding: 2px 16px 14px; } /* collapsed stays flush (no gap) */
.agent-config label { font-size: 10px; letter-spacing: 0.12em; }
.agent-config .ac-field { margin-bottom: 12px; }
.ac-seg button { font-size: 11.5px; padding: 7px 0; }
.ac-help { font-size: 11px; line-height: 1.45; padding: 2px 0 0; margin: -6px 0 10px; }
.ac-eff { font-size: 11px; line-height: 1.45; }

/* capability + connector chips (small) */
.ac-caps, .ac-conns { display: flex; flex-wrap: wrap; gap: 6px; }
.ac-cap, .ac-conn { display: inline-flex; align-items: center; gap: 6px; font-family: var(--sans); font-size: 11.5px; padding: 5px 10px; border: 1px solid var(--hairline); border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); transition: 0.14s; }
.ac-cap .cap-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.ac-cap.on { background: var(--accent-soft); border-color: rgba(180,83,9,0.2); color: var(--accent-ink); }
.ac-cap.on .cap-dot { background: var(--ok); }
.ac-conn.on { background: var(--surface-warm); border-color: var(--accent); color: var(--ink); font-weight: 500; }

/* ---- drag-to-resize handle on the panel's left edge ---- */
.cr-resize { position: absolute; left: -3px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 6; }
.cr-resize::after { content: ''; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background 0.15s; }
.cr-resize:hover::after, .cr-resize.drag::after { background: var(--accent); }
.app.cr-resizing, .app.cr-resizing * { cursor: col-resize !important; user-select: none; }

/* ---- plan zone (shown first, above the thinking panel) ---- */
.cr-plan { margin: 0 0 11px; padding: 8px 11px 9px; border: 1px solid var(--hairline); border-radius: 9px; }
.cr-plan[hidden] { display: none; }
.cr-plan-label { display: block; font-family: var(--sans); font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); margin-bottom: 5px; }
.cr-plan-body { font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.cr-plan-body p { margin: 0 0 6px; text-wrap: pretty; }
.cr-plan-body p:last-child { margin-bottom: 0; }
.cr-plan-body ul, .cr-plan-body ol { margin: 3px 0 0; padding-left: 16px; }
.cr-plan-body li { margin: 1.5px 0; }

/* ---- live reasoning breakdown (Claude-style: thinking + tool steps) ---- */
.cr-reason { margin: 0 0 11px; border-left: 2px solid var(--hairline); padding: 1px 0 1px 12px; }
.cr-reason-head { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 1px 0; outline: none; }
.cr-reason-head::-webkit-details-marker { display: none; }
.cr-reason-head::after { content: '⌄'; margin-left: auto; color: var(--faint); font-size: 13px; line-height: 1; transition: transform 0.15s; }
.cr-reason[open] .cr-reason-head::after { transform: rotate(180deg); }
.cr-reason-spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--hairline); border-top-color: var(--accent); animation: crSpin 0.8s linear infinite; flex: none; }
.cr-reason.done .cr-reason-spin { border: none; animation: none; display: inline-flex; align-items: center; justify-content: center; }
.cr-reason.done .cr-reason-spin::before { content: '✓'; color: #3F8F4F; font-size: 12px; font-weight: 700; }
.cr-reason-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* usage / credits meter */
.cr-usage { margin-top: 6px; display: flex; justify-content: flex-end; }
.cr-usage-c { font-size: 10.5px; color: var(--muted); opacity: 0.78; cursor: default; letter-spacing: 0.01em; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 9%, transparent); }
.cr-usage-c:hover { opacity: 1; }
.cr-session-meter { margin-left: auto; align-self: center; font-size: 11px; font-weight: 600; color: var(--accent, #B45309); white-space: nowrap; padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--accent, #B45309) 11%, transparent); cursor: default; }
.cr-session-meter .csm-lab { font-weight: 500; opacity: 0.7; }
.cr-reason-body { margin-top: 7px; }
.cr-reason:not([open]) .cr-reason-body { display: none; }
.cr-reason-think { max-height: 230px; overflow-y: auto; font-size: 12.5px; line-height: 1.55; color: var(--muted); padding-right: 4px; }
.cr-reason-think p { margin: 0 0 8px; text-wrap: pretty; }
.cr-reason-steps { list-style: none; margin: 8px 0 0; padding: 0; }
.cr-reason-steps:empty { display: none; }
.cr-step { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 2.5px 0; }
.cr-step-ic { width: 13px; min-width: 13px; height: 13px; display: inline-flex; align-items: center; justify-content: center; text-align: center; flex: none; color: #3F8F4F; font-size: 11px; font-weight: 700; }
.cr-step.run .cr-step-ic { border-radius: 50%; border: 2px solid var(--hairline); border-top-color: var(--accent); animation: crSpin 0.8s linear infinite; width: 11px; height: 11px; min-width: 11px; }
.cr-step.done { color: var(--ink); }
@keyframes crSpin { to { transform: rotate(360deg); } }

/* markdown headings + lists in agent answers (crRenderMd) */
.thread .bubble .cr-md-h { font-weight: 700; line-height: 1.3; margin: 12px 0 5px; color: var(--ink); }
.thread .bubble .cr-md-h:first-child { margin-top: 0; }
.thread .bubble h3.cr-md-h { font-size: 15px; }
.thread .bubble h4.cr-md-h { font-size: 14px; }
.thread .bubble h5.cr-md-h, .thread .bubble h6.cr-md-h { font-size: 13px; color: var(--muted, var(--ink)); }
.thread .bubble .cr-md-list { margin: 6px 0; padding-left: 20px; }
.thread .bubble .cr-md-list li { margin: 2px 0; }
.thread .bubble .cr-md-list li::marker { color: var(--muted); }
/* tables, blockquotes, rules, fenced code, strikethrough (full GFM) */
.thread .bubble .cr-md-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 9px 0; display: block; overflow-x: auto; }
.thread .bubble .cr-md-table th { background: var(--surface-warm); text-align: left; font-weight: 600; padding: 6px 10px; border: 1px solid var(--hairline); white-space: nowrap; }
.thread .bubble .cr-md-table td { padding: 6px 10px; border: 1px solid var(--hairline); vertical-align: top; }
.thread .bubble .cr-md-q { margin: 9px 0; padding: 7px 12px; border-left: 3px solid var(--accent); background: var(--surface-warm); border-radius: 0 8px 8px 0; }
.thread .bubble .cr-md-hr { border: none; border-top: 1px solid var(--hairline); margin: 13px 0; }
.thread .bubble .cr-md-pre { background: var(--ink); color: #f3efe7; font-family: var(--mono); font-size: 12px; line-height: 1.5; padding: 11px 13px; border-radius: 9px; overflow-x: auto; margin: 9px 0; }
.thread .bubble .cr-md-pre code { background: none; border: none; padding: 0; color: inherit; font-size: 12px; }
.thread .bubble del { opacity: 0.65; }

/* ask_user — clarifying-question card + option chips */
.cr-ask { border: 1px solid var(--hairline); border-radius: 10px; padding: 12px 14px; background: var(--surface-warm); }
.cr-ask-q { font-weight: 600; font-size: 13.5px; color: var(--ink); line-height: 1.5; }
.cr-ask-opts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.cr-ask-opt { font-family: var(--sans); font-size: 12.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--hairline); border-radius: 999px; padding: 6px 13px; cursor: pointer; transition: background 0.14s, border-color 0.14s, color 0.14s; }
.cr-ask-opt:hover { border-color: var(--accent); color: var(--accent-ink, var(--accent)); }
.cr-ask-opt.chosen { background: var(--accent); border-color: var(--accent); color: #fff; }
.cr-ask-opt:disabled { cursor: default; opacity: 0.55; }
.cr-ask-opt.chosen:disabled { opacity: 1; }

/* paused-run card — elapsed/steps/credits + continue/abort */
.cr-pause { margin-top: 10px; padding: 12px 14px; border: 1px solid rgba(180, 83, 9, 0.35); border-radius: 12px; background: rgba(180, 83, 9, 0.05); }
.cr-pause-h { font-size: 13px; font-weight: 650; color: var(--ink); display: flex; align-items: center; gap: 7px; }
.cr-pause-ic { font-size: 14px; }
.cr-pause-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.cr-pause-sub { font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.cr-pause-acts { display: flex; gap: 8px; margin-top: 10px; }
.cr-pause-go { padding: 7px 14px; border-radius: 9px; border: none; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.cr-pause-go:hover { filter: brightness(1.06); }
.cr-pause-x { padding: 7px 12px; border-radius: 9px; border: 1px solid var(--hairline); background: transparent; color: var(--muted); font-size: 12.5px; cursor: pointer; font-family: inherit; }
.cr-pause-x:hover { border-color: #9E1B1B; color: #9E1B1B; }
