/* MevvCrew conversations (Ali 20.11 12:23: "konuşma baloncuklu"): team channels, DMs, the project chat and a roadmap
 * item's discussion share one look. People talk in bubbles (the viewer's own on the right in the accent, others on the
 * left in a neutral bubble with the avatar outside); an agent's task updates and lines to other agents sit on a thin
 * work-log spine so people's words stand out; Crew's own lines are one quiet row. Colours are tokens with a light and a
 * dark set; every text/background pair is >= 4.5:1. Spacing comes from the --space-* scale. */
:root {
  --bubble-mine-bg: #265896; --bubble-mine-text: #ffffff; --bubble-mine-muted: #d4e2f6;
  --bubble-bg: #eef1f5; --bubble-text: #12141b; --bubble-muted: #5d6470;
  --bubble-code: rgba(18, 20, 27, .07); --bubble-mine-code: rgba(255, 255, 255, .16);
  --mention-bg: #dce7f7; --mention-text: #1b3f6c;
  --hash-bg: #e3e9f2; --hash-text: #1b3f6c;
  --spine: #d3dae4; --ev-update: #265896; --ev-say: #7a3aa0;
  --day-bg: #eef1f5; --day-text: #5d6470; --unread: #a3191d;
  --tip-bg: #12141b; --tip-text: #ffffff;
  --av-0: #265896; --av-1: #7a3aa0; --av-2: #1e6b30; --av-3: #a3191d; --av-4: #8a4b00; --av-5: #24606e;
  --bubble-r: 18px; --bubble-r-join: 6px; --bubble-r-tip: 4px;
}
:root[data-theme="dark"] {
  --bubble-mine-bg: #2d5a99; --bubble-mine-muted: #c9d9f2;
  --bubble-bg: #222836; --bubble-text: #e9ecef; --bubble-muted: #a3acb8;
  --bubble-code: rgba(255, 255, 255, .08); --bubble-mine-code: rgba(0, 0, 0, .22);
  --mention-bg: #243552; --mention-text: #cfe0ff;
  --hash-bg: #1d2840; --hash-text: #bcd3ff;
  --spine: #333a48; --ev-update: #8fb4ff; --ev-say: #c9a2ec;
  --day-bg: #1d222d; --day-text: #a3acb8; --unread: #ff8a8a;
  --tip-bg: #e9ecef; --tip-text: #12141b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bubble-mine-bg: #2d5a99; --bubble-mine-muted: #c9d9f2;
    --bubble-bg: #222836; --bubble-text: #e9ecef; --bubble-muted: #a3acb8;
    --bubble-code: rgba(255, 255, 255, .08); --bubble-mine-code: rgba(0, 0, 0, .22);
    --mention-bg: #243552; --mention-text: #cfe0ff;
    --hash-bg: #1d2840; --hash-text: #bcd3ff;
    --spine: #333a48; --ev-update: #8fb4ff; --ev-say: #c9a2ec;
    --day-bg: #1d222d; --day-text: #a3acb8; --unread: #ff8a8a;
    --tip-bg: #e9ecef; --tip-text: #12141b;
  }
}

/* --- the log: a list of rows, newest at the bottom. The rules here replace the old full-width rows of crew.css
   (ol.msgs, .msg, .msg-avatar, .msg-head, .msg-body code, .msg-actions), which stay there untouched for now. --- */
.msgs-log { min-width: 0; border-radius: 14px; }
.msgs-log:focus-visible { outline: 3px solid var(--link); outline-offset: 4px; }
ol.msgs { list-style: none; margin: 0; padding: 0 0 var(--space-1); display: flex; flex-direction: column; gap: 0; }
.msg { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 0 var(--space-2); margin-top: calc(var(--space-1) / 2);
  padding: 0; border-radius: 0; scroll-margin: var(--space-6); }
.msg:target { background: none; }
.msg.is-first { margin-top: var(--space-3); }
.msg:focus { outline: none; }
.msg-main { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }

/* Day separators and the unread divider. The divider stays in view at the top while the unread messages scroll. */
.msg-day { display: flex; justify-content: center; margin: var(--space-4) 0 var(--space-1); }
.msg-day:first-child { margin-top: var(--space-1); }
.msg-day span { padding: 3px var(--space-3); border-radius: 999px; background: var(--day-bg); color: var(--day-text); font-size: .75rem; font-weight: 600; }
.msg-unread { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3);
  padding: var(--space-1) 0; color: var(--unread); font-size: .75rem; font-weight: 700; background: linear-gradient(var(--card) 70%, transparent); }
.msg-unread::before, .msg-unread::after { content: ""; flex: 1 1 auto; height: 1px; background: currentColor; opacity: .45; }
.msg-unread span { flex: none; padding: 1px var(--space-3); border: 1px solid currentColor; border-radius: 999px; background: var(--card); }
@media (max-width: 600px) { .chat .msg-unread { top: 60px; } }

/* --- bubbles --- */
.msg-avatar { grid-column: 1; grid-row: 1 / span 2; align-self: start; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: #ffffff; font-size: .85rem; font-weight: 700; }
.msg .msg-avatar { background: transparent; }
.is-first > .av-0 { background: var(--av-0); } .is-first > .av-1 { background: var(--av-1); } .is-first > .av-2 { background: var(--av-2); }
.is-first > .av-3 { background: var(--av-3); } .is-first > .av-4 { background: var(--av-4); } .is-first > .av-5 { background: var(--av-5); }
.is-first > .msg-avatar-agent { background: var(--day-bg); }
.msg-avatar img { width: 22px; height: 22px; }
.msg > .msg-main { grid-column: 2; }
.msg-mine { grid-template-columns: minmax(0, 1fr); }
.msg-mine > .msg-main { grid-column: 1; align-items: flex-end; }

.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-2); margin: 0 0 calc(var(--space-1) / 2) calc(var(--space-1) / 2); font-size: .8rem; line-height: 1.35; }
.msg-author { font-size: inherit; font-weight: 650; color: var(--text); }
.agent-badge { letter-spacing: .02em; }
.msg .agent-badge { padding: 1px 7px; font-size: .66rem; font-weight: 650; }

.msg-line { display: flex; align-items: center; gap: var(--space-1); width: 100%; min-width: 0; }
.msg-mine .msg-line { flex-direction: row-reverse; } /* the tools follow the text for screen readers, sit left of the bubble */
.msg-bubble { position: relative; flex: 0 1 auto; min-width: 0; max-width: min(38rem, 88%); padding: 7px 12px; border-radius: var(--bubble-r);
  background: var(--bubble-bg); color: var(--bubble-text); line-height: 1.45; overflow-wrap: anywhere; }
.msg-mine .msg-bubble { max-width: min(38rem, 80%); background: var(--bubble-mine-bg); color: var(--bubble-mine-text); }
/* One sender's run reads as one shape: the group starts with a tip toward its sender, the joints are tight. */
.msg-theirs.is-first .msg-bubble { border-top-left-radius: var(--bubble-r-tip); }
.msg-theirs:not(.is-first) .msg-bubble { border-top-left-radius: var(--bubble-r-join); }
.msg-theirs:not(.is-last) .msg-bubble { border-bottom-left-radius: var(--bubble-r-join); }
.msg-mine.is-first .msg-bubble { border-top-right-radius: var(--bubble-r-tip); }
.msg-mine:not(.is-first) .msg-bubble { border-top-right-radius: var(--bubble-r-join); }
.msg-mine:not(.is-last) .msg-bubble { border-bottom-right-radius: var(--bubble-r-join); }
.msg:target .msg-bubble, .msg:target.msg-event .msg-main { box-shadow: 0 0 0 2px var(--link); }
.msg:focus-visible .msg-bubble, .msg-event:focus-visible .msg-main, .msg-system:focus-visible .msg-body { outline: 3px solid var(--link); outline-offset: 2px; }
.msg-deleted .msg-bubble { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }

/* The body: text, links, @mentions, code and commit hashes. */
.msg-body { min-width: 0; }
.msg-body::after { content: ""; display: block; clear: both; }
.msg-body a { color: var(--link); overflow-wrap: anywhere; }
.msg-mine .msg-body a { color: var(--bubble-mine-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.msg-body code { padding: 1px 5px; border: 0; border-radius: 6px; background: var(--bubble-code); font-family: var(--font-mono); font-size: .86em; }
.msg-mine .msg-body code { background: var(--bubble-mine-code); }
.msg-body pre { max-width: 100%; margin: var(--space-1) 0; padding: var(--space-2) var(--space-3); overflow-x: auto; border: 0; border-radius: 10px; background: var(--bubble-code); }
.msg-mine .msg-body pre { background: var(--bubble-mine-code); }
.msg-body pre code { padding: 0; background: none; white-space: pre; }
.msg-body code.hash { padding: 1px 6px; background: var(--hash-bg); color: var(--hash-text); font-size: .8em; font-weight: 600; letter-spacing: .02em; }
.msg-mine .msg-body code.hash { background: var(--bubble-mine-code); color: var(--bubble-mine-text); }
.msg-body .mention { padding: 0 4px; border-radius: 6px; background: var(--mention-bg); color: var(--mention-text); font-weight: 600; }
.msg-body .mention-self { background: var(--warn-bg); color: var(--warn-text); box-shadow: inset 0 -2px 0 currentColor; }
.msg-mine .msg-body .mention { background: var(--bubble-mine-code); color: var(--bubble-mine-text); }

/* The time in the bubble's bottom corner; the full timestamp shows on hover or focus. */
.msg-meta { float: right; display: inline-flex; align-items: baseline; gap: var(--space-1); margin: .55em calc(-1 * var(--space-1)) -.3em var(--space-3);
  color: var(--bubble-muted); font-size: .7rem; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-mine .msg-meta { color: var(--bubble-mine-muted); }
.msg-time::after { content: attr(data-full); position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 4; padding: 5px var(--space-2);
  border-radius: 8px; background: var(--tip-bg); color: var(--tip-text); font-size: .72rem; line-height: 1.2; white-space: nowrap;
  opacity: 0; pointer-events: none; transform: translateY(3px); transition: opacity .12s ease-out, transform .12s ease-out; }
.msg-mine .msg-time::after { left: auto; right: 0; }
.msg-bubble:hover .msg-time::after, .msg:focus .msg-time::after, .msg:focus-within .msg-time::after,
.msg-event .msg-main:hover .msg-time::after, .msg-system:hover .msg-time::after { opacity: 1; transform: none; }

/* A long message opens with "Devamını gör" (only with JS: the button is display none until .js-chat; without JS the whole text shows). */
.msg-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: calc(var(--space-1) / 2); }
.msg-foot .msg-meta { float: none; margin: 0 0 0 auto; }
.js-chat .msg-body[data-long]:not(.is-open):not(.fits) { max-height: calc(1.45em * 10); overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 72%, transparent); mask-image: linear-gradient(#000 72%, transparent); }
.js-chat .msg-event .msg-body[data-long]:not(.is-open):not(.fits) { max-height: calc(1.45em * 3); }
.js-chat .msg-body.fits ~ .msg-foot .msg-more { display: none; }
.msg-more { display: none; }
/* The shared ghost button (.btn ghost sm), in the bubble's own colour so it reads on both bubbles. */
.js-chat .msg-more { display: inline-flex; min-height: 36px; margin-left: calc(-1 * var(--space-3)); color: inherit; font-weight: 650; background: transparent; }
.js-chat .msg-more:hover { background: var(--bubble-code); color: inherit; }

/* Own message tools: beside the bubble, shown on hover or focus (a tap on a touch screen focuses the message). */
.msg-actions { flex: none; display: flex; align-items: center; gap: calc(var(--space-1) / 2); margin: 0; opacity: 0; pointer-events: none; transition: opacity .12s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg-actions form { margin: 0; }
.msg-act { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; min-height: 36px; padding: 0;
  border: 0; border-radius: 50%; background: var(--card); color: var(--muted); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.card .msg-actions button.msg-act { margin-top: 0; }
.msg-act:hover { color: var(--link); }
.msg-act.danger-text:hover { color: var(--brand-text); }
.msg-act .ico { margin: 0; width: 18px; height: 18px; }
/* A blocked person's message (lib/chat-safety): one quiet line, no text. */
.msg-blocked .msg-body em { color: var(--muted); }

/* --- agent events: a work-log spine; one dot per update, the agent's name once per run --- */
.msg-event .msg-main { position: relative; width: 100%; padding: 1px 0 3px; font-size: .88rem; }
.ev-dot { grid-column: 1; grid-row: 1 / span 2; justify-self: center; width: 10px; height: 10px; margin-top: .35em; border-radius: 50%;
  background: var(--card); box-shadow: 0 0 0 2px var(--ev-update); }
.msg-kind-say .ev-dot { box-shadow: 0 0 0 2px var(--ev-say); }
.msg-event:not(.is-first) .ev-dot { margin-top: .45em; }
.msg-event:not(.is-last)::before { content: ""; position: absolute; left: 15px; top: 19px; bottom: -6px; width: 2px; border-radius: 1px; background: var(--spine); }
.msg-event + .msg-event:not(.is-first) { margin-top: var(--space-1); }
.msg-event .msg-head { margin-left: 0; }
.ev-kind { color: var(--muted); font-size: .75rem; }
.msg-event .msg-body { width: 100%; color: var(--text); }
.msg-event .msg-meta { margin-right: 0; color: var(--muted); }

/* --- Crew's own lines --- */
.msg-system { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: var(--space-2); margin: var(--space-3) auto 0;
  max-width: 34rem; color: var(--muted); font-size: .8rem; text-align: center; }
.msg-system .msg-meta { float: none; margin: 0; color: var(--muted); }
.msg-system .msg-body::after { content: none; }

/* --- composer: one rounded box, the text grows with what is written, the send button inside --- */
.composer[data-composer] { position: sticky; bottom: 0; z-index: 3; display: grid; gap: var(--space-1); padding: var(--space-3) 0 calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft); background: var(--card); }
.composer-box { display: flex; align-items: flex-end; gap: var(--space-2); padding: 3px 3px 3px var(--space-4); border: 1px solid var(--line);
  border-radius: 24px; background: var(--input); }
.composer-box:focus-within { border-color: var(--link); box-shadow: 0 0 0 3px var(--chip-blue-bg); }
.composer[data-composer] .composer-box textarea { flex: 1 1 auto; width: auto; min-height: 40px; max-height: 40vh; margin: 0; padding: 9px 0; border: 0;
  border-radius: 0; background: transparent; box-shadow: none; resize: none; overflow-y: auto; line-height: 1.4; field-sizing: content; }
.composer-box textarea:focus-visible { outline: none; }
.composer-send { flex: none; width: 44px; height: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: var(--bubble-mine-bg); color: var(--bubble-mine-text); }
.card .composer[data-composer] .composer-send { margin-top: 0; }
.composer-send .ico { margin: 0; }
.composer-send:disabled { opacity: .55; cursor: progress; }
.composer-hint { margin: 0 var(--space-4); color: var(--muted); font-size: .75rem; }
@media (hover: none) and (pointer: coarse) { .composer-hint { display: none; } }
.composer-to { display: flex; align-items: center; gap: var(--space-2); font-size: .85rem; }
.composer-to label { margin: 0; color: var(--muted); font-weight: 600; }
.composer-to select { flex: 1 1 auto; width: auto; min-height: 40px; }
.composer[data-composer] .error { margin: 0 var(--space-4); }

/* --- where the log lives --- */
.chat-conv .msgs-log { padding: 0 2px; }
.item-composer[data-composer] { position: static; padding-bottom: 0; }
.pchat-panel .composer[data-composer] { border-top: 1px solid var(--line-soft); }
.pchat-scroll, .thread-scroll { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 0 2px; }
.thread-scroll { max-height: min(560px, 70vh); }
.pchat-panel .msg-bubble, .pchat-panel .msg-mine .msg-bubble { max-width: 92%; }

@media (max-width: 600px) {
  .msg { column-gap: var(--space-1); }
  .msg-bubble { max-width: 90%; }
  .msg-mine .msg-bubble { max-width: 84%; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-time::after, .msg-actions { transition: none; }
}
