/* style-r5-chat.css - design round 5, JOB 1: CHAT BUBBLES, message layout, compose bar. Loaded last. Pure CSS (no logic, no ids changed).
   Row markup (js/05c-message-render.js): .msg-row[.mine] > .msg.(mine|theirs|kappy|claude|hermes|system) [.meta .body .original-toggle .original-text img.attachment] + .avatar (after the bubble in the DOM).
   Grouping is done with sibling selectors: runs of same-side messages are tight, only the last bubble of a run gets the tail, my avatar shows once per run. */
:root { --r5-mine1: #27984F; --r5-mine2: #1E7A42; --r5-gap: 3px; }

/* ---------- the message list ---------- */
#messages { gap: var(--r5-gap); padding: 14px 10px 10px; scroll-behavior: auto; overscroll-behavior: contain;
  background: radial-gradient(120% 60% at 50% 0, rgba(6, 199, 85, .05), transparent 60%), #121212;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px); mask-image: linear-gradient(to bottom, transparent 0, #000 16px); }
.msg-row { gap: 8px; align-items: flex-end; }
.msg-row.mine { flex-direction: row; justify-content: flex-end; }               /* bubble, then my avatar at the right edge */
.msg-row:not(.mine) > .avatar { order: -1; }                                   /* their avatar goes to the LEFT of their bubble */
.msg-row:not(.mine):has(> .msg.system) { justify-content: center; margin: 8px 0; }
.msg-row.mine + .msg-row:not(.mine), .msg-row:not(.mine) + .msg-row.mine { margin-top: 9px; }
.msg-row:not(.mine) + .msg-row:not(.mine) { margin-top: 5px; }
.msg-row .avatar { width: 30px; height: 30px; font-size: 12px; margin-bottom: 1px; }
.msg-row.mine:has(+ .msg-row.mine) > .avatar { visibility: hidden; }          /* my avatar once per run */

/* ---------- the bubble ---------- */
.msg { --bub1: #2A2A2D; --bub2: #242427; position: relative; display: flex; flex-direction: column; max-width: calc(100% - 42px); min-width: 0; padding: 8px 12px 7px;
  border-radius: 20px; line-height: 1.4; letter-spacing: .003em; background: linear-gradient(165deg, var(--bub1), var(--bub2)); box-shadow: 0 1px 2px rgba(0, 0, 0, .35); transform-origin: bottom; }
.msg .body, .msg .original-text { overflow-wrap: anywhere; word-break: normal; }
.msg a { color: inherit; text-decoration-color: rgba(255, 255, 255, .45); text-underline-offset: 2px; }
.msg.mine { --bub1: var(--r5-mine1); --bub2: var(--r5-mine2); color: #F2FFF2; box-shadow: 0 2px 8px rgba(30, 122, 66, .3); }
.msg.theirs { --bub1: #2D2D31; --bub2: #252528; color: #EEE; border: 1px solid rgba(255, 255, 255, .06); }
.msg.kappy { --bub1: #4B3573; --bub2: #3A2A55; color: #EEE2FF; font-style: normal; border: 1px solid rgba(190, 150, 255, .22); }
.msg.claude { --bub1: #25496F; --bub2: #1F3A5C; color: #D4EAFF; border: 1px solid rgba(120, 190, 255, .2); }
.msg.hermes { --bub1: #4D3724; --bub2: #3D2A1F; color: #FFE6C4; border: 1px solid rgba(255, 190, 110, .22); }
.msg.system { background: rgba(255, 255, 255, .06); color: #A5A5AB; font-size: 12.5px; padding: 4px 14px; border-radius: 99px; box-shadow: none; text-align: center; max-width: 88%; }

/* runs: inner corners tight, the last bubble gets the tail */
.msg-row.mine + .msg-row.mine > .msg.mine { border-top-right-radius: 7px; }
.msg-row.mine:has(+ .msg-row.mine) > .msg.mine { border-bottom-right-radius: 7px; }
.msg-row:not(.mine) + .msg-row:not(.mine) > .msg:not(.system) { border-top-left-radius: 7px; }
.msg-row:not(.mine):has(+ .msg-row:not(.mine)) > .msg:not(.system) { border-bottom-left-radius: 7px; }
.msg-row.mine:not(:has(+ .msg-row.mine)) > .msg.mine { border-bottom-right-radius: 5px; }
.msg-row:not(.mine):not(:has(+ .msg-row:not(.mine))) > .msg:not(.system) { border-bottom-left-radius: 5px; }
.msg-row.mine:not(:has(+ .msg-row.mine)) > .msg.mine::after, .msg-row:not(.mine):not(:has(+ .msg-row:not(.mine))) > .msg:not(.system)::after {
  content: ""; position: absolute; bottom: 0; width: 11px; height: 13px; background: var(--bub2); }
.msg-row.mine > .msg.mine::after { right: -6px; clip-path: path("M0 0 L0 13 L11 13 C5 12 1 8 0 0 Z"); }
.msg-row:not(.mine) > .msg:not(.system)::after { left: -6px; clip-path: path("M11 0 L11 13 L0 13 C6 12 10 8 11 0 Z"); }

/* ---------- name / time line ---------- */
.msg .meta { gap: 10px; margin-bottom: 2px; font-size: 11px; letter-spacing: .01em; color: rgba(255, 255, 255, .5); align-items: center; }
.msg .meta-name { font-weight: 700; color: rgba(255, 255, 255, .78); gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.msg.kappy .meta-name { color: #D5B8FF; } .msg.claude .meta-name { color: #9CCBFF; } .msg.hermes .meta-name { color: #FFC47A; }
.msg .meta-time { font-variant-numeric: tabular-nums; font-size: 10.5px; opacity: .7; }
.msg.mine .meta { order: 9; margin: 3px 0 -1px; justify-content: flex-end; color: rgba(234, 251, 233, .65); }
.msg.mine .meta-time { opacity: .75; }
.msg.mine .meta-name:empty { display: none; }
.read-aloud-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-left: 0; border-radius: 50%; background: rgba(255, 255, 255, .1); color: #9CF2B8; font-size: 12px; transition: background-color .15s, transform .1s; }
.read-aloud-btn:active { background: rgba(255, 255, 255, .22); transform: scale(.9); }
.read-aloud-btn.playing { background: rgba(255, 107, 96, .22); color: #FF9A92; animation: r5Beat 1s ease-in-out infinite; }

/* ---------- translation = the hero, original = a quiet pill ---------- */
.msg .body { font-size: var(--chat-font-size); }
.msg .original-toggle { align-self: flex-start; margin-top: 6px; padding: 3px 10px; border: 0; border-radius: 99px; background: rgba(255, 255, 255, .09); font-size: 11px; opacity: .85; min-height: 22px; line-height: 16px; transition: background-color .15s; }
.msg .original-toggle:active { background: rgba(255, 255, 255, .18); }
.msg .original-text { margin-top: 6px; padding-left: 9px; border-left: 2px solid rgba(255, 255, 255, .25); font-size: 12.5px; font-style: italic; opacity: .8; }
.msg .body.pending-translation { background: linear-gradient(90deg, rgba(255, 255, 255, .35) 0, rgba(255, 255, 255, .9) 50%, rgba(255, 255, 255, .35) 100%) 0 0 / 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; font-style: normal; opacity: 1; animation: r5Shimmer 1.4s linear infinite; }

/* ---------- attachments ---------- */
.msg:has(> img.attachment), .msg:has(> video.attachment) { padding: 5px 5px 7px; width: min(calc(100% - 42px), 300px); }
.msg:has(> img.attachment) > .meta, .msg:has(> video.attachment) > .meta { padding: 3px 7px 0; }
.msg img.attachment, .msg video.attachment { width: 100%; max-height: 260px; object-fit: cover; margin-top: 3px; border-radius: 15px; border: 1px solid rgba(255, 255, 255, .12); box-shadow: 0 4px 14px rgba(0, 0, 0, .4); background: #0B0B0C; }
.msg audio.attachment { width: min(100%, 260px); height: 40px; margin-top: 4px; border-radius: 20px; }
.msg .attachment-pdf { padding: 10px 12px; border-radius: 14px; background: rgba(0, 0, 0, .22); border: 1px solid rgba(255, 255, 255, .1); font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Kappy's order card + request cards stay loud: the card stands alone, no purple bubble around it ---------- */
.msg.kappy:has(.host-card) { background: none; border: 0; box-shadow: none; padding: 0; width: min(100%, 330px); max-width: calc(100% - 42px); }
.msg.kappy:has(.host-card)::after { display: none; }
.msg.kappy:has(.host-card) > .meta { padding: 0 4px 3px; }
.msg:has(.host-card) .host-card { margin: 0; }

/* ---------- typing ---------- */
#typing-indicator { padding: 3px 16px 5px; font-size: 12.5px; font-style: normal; color: #A5A5AB; display: flex; align-items: center; }
#typing-indicator:not(.hidden)::after { content: ""; display: inline-block; height: 6px; width: 24px; margin-left: 8px; background: radial-gradient(circle 3px at 3px 3px, #8E8E93 98%, transparent) 0 0 / 8px 6px repeat-x; animation: r5Dots 1.1s steps(4, jump-none) infinite; }

/* ---------- new messages pop in (only the newest few rows, so opening a long chat doesn't jitter) ---------- */
.msg-row:nth-last-child(-n+5) { animation: r5Pop .26s var(--r4-ease, cubic-bezier(.2, .8, .2, 1)) both; }
.msg-row.mine:nth-last-child(-n+5) { transform-origin: bottom right; } .msg-row:not(.mine):nth-last-child(-n+5) { transform-origin: bottom left; }
@keyframes r5Pop { from { opacity: 0; transform: translateY(10px) scale(.92); } }
@keyframes r5Dots { from { width: 0; } to { width: 24px; } }
@keyframes r5Beat { 50% { transform: scale(1.12); } }
@keyframes r5Shimmer { to { background-position: -200% 0; } }

/* ---------- the compose bar: a floating rounded pill ---------- */
.send-bar { gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(to top, #121212 70%, rgba(18, 18, 18, 0)); border-top: 0; align-items: flex-end; }
.send-bar .icon-btn { width: 40px; height: 40px; min-width: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 19px; background: rgba(255, 255, 255, .06); color: #D8D8DC; transition: background-color .15s, transform .1s; }
.send-bar .icon-btn:active { background: rgba(255, 255, 255, .16); transform: scale(.92); }
.send-bar textarea { min-height: 44px; border-radius: 22px; padding: 11px 16px; background: #232326; border: 1px solid #3A3A3C; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); }
.send-bar textarea:focus { border-color: #06C755; box-shadow: 0 0 0 3px rgba(6, 199, 85, .2), 0 2px 10px rgba(0, 0, 0, .35); outline: none; }
.send-bar button[type=submit], #btn-send { flex: none; width: 44px; height: 44px; min-width: 44px; padding: 0; border-radius: 50%; font-size: 0; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #1BDB6D, #06C755); box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 4px 12px rgba(6, 199, 85, .4); transition: transform .12s, filter .15s; }
.send-bar.expanded #btn-send { padding: 0; min-width: 44px; }
#btn-send::before { content: ""; width: 22px; height: 22px; background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2308170D' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5M5 12l7-7 7 7'/%3E%3C/svg%3E"); }
#btn-send:active { transform: scale(.9); }
#recording-surface { border-radius: 22px; min-height: 44px; box-shadow: 0 4px 14px rgba(6, 199, 85, .35); }
#recording-surface.active { box-shadow: 0 4px 14px rgba(255, 107, 96, .4); }
#emoji-picker { border-radius: 18px 18px 0 0; background: #1C1C1E; } #emoji-picker span { border-radius: 10px; min-height: 40px; display: grid; place-items: center; }
#attach-menu { border-radius: 16px; }

@media (min-width: 700px) { .msg { max-width: min(560px, calc(100% - 42px)); } }
@media (prefers-reduced-motion: reduce) { .msg-row, .read-aloud-btn.playing, #typing-indicator::after, .msg .body.pending-translation { animation: none !important; } #messages { scroll-behavior: auto; } .msg-row { opacity: 1 !important; } }

/* ---------- wide screens: the conversation is a centred column, not edge to edge ---------- */
@media (min-width: 900px) {
  #messages { padding-left: max(16px, calc((100% - 780px) / 2)); padding-right: max(16px, calc((100% - 780px) / 2)); }
  .send-bar { padding-left: max(10px, calc((100% - 780px) / 2)); padding-right: max(10px, calc((100% - 780px) / 2)); }
  #typing-indicator { padding-left: max(16px, calc((100% - 780px) / 2)); }
  .msg { max-width: min(560px, calc(100% - 42px)); }
}

/* "Load earlier messages" button at the top of a long chat (audit H5) */
.load-older-btn { display: block; margin: 6px auto 10px; padding: 7px 16px; border-radius: 999px; border: 1px solid var(--border, #8884); background: transparent; color: inherit; font: inherit; font-size: 13px; opacity: .8; cursor: pointer; }
.load-older-btn:disabled { opacity: .4; }
