/* ===== CONVERSATION VIEW ===== */
:root {
  --name-1: oklch(0.55 0.12 200); --name-2: oklch(0.55 0.12 150); --name-3: oklch(0.58 0.13 60);
  --name-4: oklch(0.56 0.14 20); --name-5: oklch(0.52 0.13 290); --name-6: oklch(0.54 0.12 330);
}
[data-theme="dark"] {
  --name-1: oklch(0.74 0.12 200); --name-2: oklch(0.74 0.12 150); --name-3: oklch(0.78 0.12 70);
  --name-4: oklch(0.74 0.13 25); --name-5: oklch(0.74 0.12 290); --name-6: oklch(0.76 0.11 330);
}

.chat-col-inner { display: flex; flex-direction: column; height: 100%; min-width: 0; background: var(--bg); position: relative; }
.drop-overlay { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(2px); pointer-events: none; }
.drop-card { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 40px; border: 2px dashed var(--primary); border-radius: 16px; background: var(--bg-tint, var(--bg)); color: var(--primary-strong, var(--primary)); font-weight: 700; font-size: 14.5px; box-shadow: 0 8px 30px rgba(0,0,0,.12); }

/* header */
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: color-mix(in oklab, var(--surface) 70%, transparent); backdrop-filter: blur(8px); z-index: 5; flex-shrink: 0; }
.chat-head-id { padding: 4px 6px; border-radius: var(--r-md); transition: background .12s; min-width: 0; }
.chat-head > .row:not(.chat-head-id) { flex-shrink: 0; } /* action buttons keep size; the title (.chat-head-id, also a .row) must stay shrinkable so the name truncates instead of pushing buttons off-screen */
.chat-head-id:hover { background: var(--surface-2); }
.chat-head-name { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.chat-head-sub { font-size: 12.5px; color: var(--text-3); }
.chat-head-sub.on { color: var(--success); font-weight: 600; }
.only-mobile { display: none; }

.enc-banner { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11.5px; color: var(--text-on-soft); background: var(--primary-softer); padding: 5px; flex-shrink: 0; }

/* in-chat search bar */
.chat-search { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; animation: fadeIn .14s; }
.chat-search-input { border: none; background: none; outline: none; font-size: 14px; color: var(--text); }
.chat-search-input::placeholder { color: var(--text-3); }
.chat-search .ib.sm[disabled] { opacity: .35; pointer-events: none; }
/* search hits: faint ring on every match, solid ring on the active one — covers bubbles AND system/date rows */
.search-hit > .msg-row .bubble,
.search-hit > .sys-line,
.search-hit > .event-line,
.search-hit > .date-sep span { transition: box-shadow .2s; box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 32%, transparent); }
.search-hit.active-hit > .msg-row .bubble,
.search-hit.active-hit > .sys-line,
.search-hit.active-hit > .event-line,
.search-hit.active-hit > .date-sep span { box-shadow: 0 0 0 2px var(--primary), var(--shadow-sm); }

/* read-only channel composer */
.channel-bar { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; padding: 11px 14px; background: var(--surface-2); border-radius: var(--r-lg); }

/* location card */
.loc-msg { width: 252px; border-radius: 12px; overflow: hidden; background: color-mix(in oklab, currentColor 6%, transparent); }
.b-mine .loc-msg { background: oklch(1 0 0 / .14); }
.loc-map { position: relative; height: 120px; display: flex; align-items: center; justify-content: center; }
.loc-pin { position: relative; z-index: 1; width: 40px; height: 40px; border-radius: 50%; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-md); }

/* transient flash confirmation */
.chat-flash { position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%); z-index: 8; display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border-radius: 99px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); animation: flashIn .2s; }
@keyframes flashIn { from { transform: translateX(-50%) translateY(8px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* bottom sheet (poll creation etc.) */
.sheet { width: min(440px, 94vw); background: var(--bg); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); overflow: hidden; animation: setIn .2s cubic-bezier(.2,.8,.2,1); }
.sheet.tall { height: min(620px, 90vh); display: flex; flex-direction: column; }
@media (max-width: 560px) {
  .sheet { width: 100%; max-width: 100%; align-self: flex-end; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .sheet.tall { height: 88vh; }
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }

/* people picker / creation */
.pick-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border-radius: var(--r-sm); transition: background .12s; }
.pick-row:hover { background: var(--surface-2); }
.pick-check { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--border-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.pick-check.on { background: var(--primary); box-shadow: none; color: var(--on-primary); }
.quick-actions { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px; }
.quick-act { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: var(--r-sm); font-weight: 600; font-size: 14.5px; color: var(--primary-strong); transition: background .12s; }
[data-theme="dark"] .quick-act { color: var(--primary-bright); }
.quick-act:hover { background: var(--surface-2); }
.quick-act-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--text-on-soft); flex-shrink: 0; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 4px; }
.member-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 6px 4px 11px; border-radius: 99px; background: var(--primary-soft); color: var(--text-on-soft); font-size: 13px; font-weight: 600; cursor: pointer; }

/* confirm dialog */
.confirm { width: min(380px, 92vw); background: var(--bg); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: 26px 24px 22px; display: flex; flex-direction: column; align-items: center; animation: setIn .2s cubic-bezier(.2,.8,.2,1); }
.confirm-ic { width: 56px; height: 56px; border-radius: 18px; }

/* timeline */
.timeline { flex: 1; padding: 8px 4vw 4px; background:
  radial-gradient(50% 40% at 80% 0%, color-mix(in oklab, var(--primary) 5%, transparent), transparent 70%), var(--bg); }
.timeline-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 2px; padding-bottom: 8px; }
.timeline-inner > div { display: flex; flex-direction: column; } /* per-message wrapper: let system/date rows' align-self:center take effect (msg-rows still stretch full width) */

/* message rows */
.msg-row { display: flex; gap: 9px; align-items: flex-end; margin-top: 10px; position: relative; }
.msg-row:hover { z-index: 6; } /* hovered row + its action toolbar float above neighbors */
.msg-row.grouped { margin-top: 2px; }
.msg-row.mine { flex-direction: row-reverse; }
.msg-av { width: 34px; flex-shrink: 0; }
.msg-main { display: flex; flex-direction: column; max-width: min(76%, 560px); min-width: 0; }
.msg-row.mine .msg-main { align-items: flex-end; }
.msg-name { font-size: 12.5px; font-weight: 700; margin: 0 0 2px 12px; }
.msg-cluster { position: relative; }

/* bubbles */
.bubble {
  position: relative; padding: 8px 12px 7px; border-radius: var(--bubble-r);
  font-size: calc(14.5px * var(--font-scale, 1)); line-height: 1.42; overflow-wrap: anywhere; word-break: break-word; box-shadow: var(--shadow-sm);
  width: fit-content; max-width: 100%;
}
/* "Tekis" (flat) chat style: drop the shadow + soften the radius for a flatter look */
[data-chat-style="flat"] .bubble { box-shadow: none; border-radius: 10px; }
[data-chat-style="flat"] .b-mine, [data-chat-style="flat"] .msg-row.grouped .b-mine { border-bottom-right-radius: 10px; border-top-right-radius: 10px; }
[data-chat-style="flat"] .b-other, [data-chat-style="flat"] .msg-row.grouped .b-other { border-bottom-left-radius: 10px; border-top-left-radius: 10px; }
.b-other { background: var(--bubble-other-bg); color: var(--bubble-other-text); border-bottom-left-radius: 5px; }
.msg-row.grouped .b-other { border-bottom-left-radius: var(--bubble-r); border-top-left-radius: 5px; }
.b-mine { background: var(--bubble-own-bg); color: var(--bubble-own-text); border-bottom-right-radius: 5px; }
.msg-row.grouped .b-mine { border-bottom-right-radius: var(--bubble-r); border-top-right-radius: 5px; }
.b-media { padding: 4px; overflow: hidden; }
.b-mine a { color: var(--bubble-own-text); text-decoration: underline; }
.msg-code { font-family: var(--mono); font-size: 12.5px; background: color-mix(in oklab, currentColor 12%, transparent); padding: 1px 5px; border-radius: 5px; }
.b-mine .msg-code { background: oklch(1 0 0 / .2); }
.msg-list { margin: 2px 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.msg-list li { padding-left: 2px; }

/* meta inside bubble */
.msg-meta { float: right; display: inline-flex; align-items: center; gap: 4px; margin: 4px 0 -2px 10px; transform: translateY(3px); white-space: nowrap; }
.msg-time { font-size: 10.5px; opacity: .78; font-family: inherit; font-variant-numeric: tabular-nums; }
.b-mine .msg-time { color: var(--bubble-own-meta); opacity: 1; }
.edited { font-size: 10.5px; opacity: .55; font-style: italic; }
.msg-retry { display: inline-flex; align-items: center; color: var(--danger, #d04545); cursor: pointer; }
.msg-meta-out { display: flex; align-items: center; gap: 4px; justify-content: flex-end; padding: 3px 4px 1px; white-space: nowrap; }
.msg-meta-out .msg-time { opacity: .65; }

/* reply quote */
.reply-quote { display: flex; gap: 8px; padding: 4px 8px 5px 0; margin-bottom: 4px; border-radius: 7px; }
.reply-bar { width: 3px; border-radius: 3px; background: var(--primary); flex-shrink: 0; align-self: stretch; }
.b-mine .reply-bar { background: var(--bubble-own-text); }
.reply-name { font-size: 12.5px; font-weight: 700; color: var(--primary-strong); }
.b-mine .reply-name { color: var(--bubble-own-text); }
[data-theme="dark"] .reply-name { color: var(--primary-bright); }
.reply-text { font-size: 12.5px; opacity: .75; }

/* voice */
.voice-play { width: 38px; height: 38px; border-radius: 50%; background: color-mix(in oklab, currentColor 14%, transparent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.b-mine .voice-play { background: oklch(1 0 0 / .22); }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; }
.voice-wave span { width: 3px; border-radius: 3px; min-height: 3px; transition: background .1s; }

/* image placeholders */
.img-ph { position: relative; background: var(--surface-2); overflow: hidden; display: flex; align-items: flex-end; }
.img-ph-lbl { position: relative; z-index: 1; margin: 8px; font-size: 11px; color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; background: color-mix(in oklab, var(--surface) 75%, transparent); padding: 3px 7px; border-radius: 6px; }
.img-failed { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; width: 220px; height: 120px; border-radius: 12px; background: var(--surface-2); color: var(--text-3); font-size: 12.5px; }
.gallery { display: grid; gap: 3px; border-radius: 14px; overflow: hidden; width: 280px; }
.gallery.g-1 { grid-template-columns: 1fr; }
.gallery.g-2 { grid-template-columns: 1fr 1fr; }
.gallery.g-3 { grid-template-columns: 1fr 1fr; }
.gallery.g-3 > :first-child { grid-column: 1 / -1; }
.gallery.g-4 { grid-template-columns: 1fr 1fr; }

/* file */
.file-msg { display: flex; align-items: center; gap: 11px; min-width: 240px; padding: 3px 2px; }
.file-ic { width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; }

/* poll */
.poll-opt { position: relative; display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 10px; overflow: hidden; background: color-mix(in oklab, currentColor 7%, transparent); text-align: left; }
.b-mine .poll-opt { background: oklch(1 0 0 / .14); }
.poll-fill { position: absolute; inset: 0; background: color-mix(in oklab, var(--primary) 22%, transparent); transition: width .5s cubic-bezier(.3,1,.4,1); z-index: 0; }
.b-mine .poll-fill { background: oklch(1 0 0 / .2); }
.poll-radio { position: relative; z-index: 1; width: 19px; height: 19px; border-radius: 50%; box-shadow: inset 0 0 0 2px color-mix(in oklab, currentColor 40%, transparent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.poll-opt.sel .poll-radio { background: var(--primary); box-shadow: none; color: #fff; }
.poll-opt > .grow, .poll-opt > .mono { position: relative; z-index: 1; }

/* link preview */
.link-prev { display: block; border-radius: 12px; overflow: hidden; background: color-mix(in oklab, currentColor 6%, transparent); width: 280px; color: inherit; }
.b-mine .link-prev { background: oklch(1 0 0 / .14); }

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin: 5px 4px 0; }
.react { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; border-radius: 99px; background: var(--surface-2); font-size: 13px; box-shadow: var(--shadow-sm); transition: transform .1s; }
.react:hover { transform: scale(1.06); }
.react .mono { font-size: 12px; font-weight: 600; color: var(--text-2); }
.react.mine { background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.react.mine .mono { color: var(--text-on-soft); }
.react-add { color: var(--text-3); padding: 0 7px; }

/* system / event / date */
.sys-line { align-self: center; display: inline-flex; align-items: center; gap: 7px; max-width: 480px; text-align: center; margin: 12px auto; font-size: 12.5px; color: var(--text-on-soft); background: var(--primary-softer); padding: 7px 14px; border-radius: 12px; }
.event-line { align-self: center; display: inline-flex; align-items: center; max-width: 80%; text-align: center; margin: 8px auto; font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 4px 12px; border-radius: 99px; }
.date-sep { display: flex; align-items: center; justify-content: center; margin: 14px 0 4px; position: sticky; top: 6px; z-index: 3; }
.date-sep span { font-size: 12px; font-weight: 700; color: var(--text-2); background: color-mix(in oklab, var(--surface) 86%, transparent); backdrop-filter: blur(6px); padding: 4px 13px; border-radius: 99px; box-shadow: var(--shadow-sm); }

.undec { display: inline-flex; align-items: center; gap: 7px; font-style: italic; opacity: .82; }
.undec svg { flex-shrink: 0; opacity: .7; }
.deleted-msg { display: inline-flex; align-items: center; gap: 6px; opacity: .6; font-style: italic; font-size: 13.5px; }
.b-deleted { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }

/* typing */
.typing-bubble { padding: 13px 14px; }

/* message actions (hover) */
.msg-actions { position: absolute; bottom: calc(100% - 4px); top: auto; z-index: 20; opacity: 0; pointer-events: none; transition: opacity .12s; } /* float above the bubble; -4px sits in the top padding, never over text */
.msg-row:hover .msg-actions, .msg-row:focus-within .msg-actions { opacity: 1; pointer-events: auto; } /* keyboard reveals the action toolbar */
.msg-actions.right { right: 0; }  /* mine: anchor to bubble's right edge, extend left (away from viewport edge) */
.msg-actions.left { left: 0; }    /* others: anchor to bubble's left edge, extend right into open space */
.msg-quick { display: flex; align-items: center; gap: 1px; background: var(--surface); border-radius: 99px; padding: 3px; box-shadow: var(--shadow-md); }
.qr { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--text-2); transition: background .1s, transform .1s; }
.qr:hover { background: var(--surface-2); transform: scale(1.15); }

.menu { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 5px; border: 1px solid var(--border); min-width: 180px; z-index: 50; animation: popIn .14s ease; }
.msg-menu { position: absolute; top: 30px; }
.msg-menu.up { top: auto; bottom: 30px; } /* flip upward near the viewport bottom */
.msg-menu.mr { left: 0; }
.msg-menu.ml { right: 0; }
.menu-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text); text-align: left; transition: background .1s; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: color-mix(in oklab, var(--danger) 12%, transparent); }

/* jump to latest */
.jump-latest { position: absolute; right: 22px; bottom: 92px; width: 46px; height: 46px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-md); display: flex; align-items: center; justify-content: center; color: var(--text-2); z-index: 6; }
.jump-latest:hover { color: var(--text); }
.jump-latest .badge { position: absolute; top: -4px; right: -2px; }

/* ===== COMPOSER ===== */
.composer-wrap { padding: 8px 4vw 12px; flex-shrink: 0; }
.composer-ctx { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto 7px; padding: 7px 10px; background: var(--surface-2); border-radius: var(--r-md); animation: fadeIn .15s; }
.composer { display: flex; align-items: flex-end; gap: 7px; max-width: 760px; margin: 0 auto; background: var(--surface); border-radius: var(--r-xl); padding: 6px; box-shadow: var(--shadow-md); border: 1px solid var(--border); }
.composer-field { display: flex; flex-direction: column; min-width: 0; }
.composer-input { border: none; background: none; resize: none; outline: none; font-size: 14.5px; line-height: 1.45; padding: 10px 4px 2px; max-height: 160px; width: 100%; }
.composer-input::placeholder { color: var(--text-3); }
.composer-fmt { display: flex; flex-wrap: wrap; gap: 1px; padding: 0 0 2px 0; opacity: 0; max-height: 0; transition: opacity .15s; }
.composer-fmt .ib.sm { flex-shrink: 0; } /* keep full tap size; wrap to a new row on tiny screens instead of squeezing */
.composer-field:focus-within .composer-fmt { opacity: 1; max-height: 96px; } /* fits up to 2 wrapped rows of 44px buttons on narrow phones */
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: var(--shadow-sm); transition: background .14s, transform .08s; }
.send-btn:hover { background: var(--primary-strong); }
.send-btn:active { transform: scale(.94); }
/* Touch devices: primary send + quick-reactions meet the tap-target guideline. */
@media (pointer: coarse) {
  .send-btn { width: 44px; height: 44px; }
  .qr { width: 36px; height: 36px; }
}

.composer.recording { align-items: center; gap: 12px; padding: 8px 10px; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--danger); animation: ringPulse 1.4s infinite; }
.rec-wave { display: flex; align-items: center; gap: 2px; height: 28px; overflow: hidden; }
.rec-wave span { width: 2.5px; border-radius: 3px; background: var(--text-3); min-height: 3px; }

/* emoji + attach popups */
.emoji-pop { position: absolute; bottom: 50px; right: 0; width: 300px; padding: 8px; }
.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; max-height: 200px; overflow-y: auto; }
.emoji-btn { font-size: 21px; aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: background .1s, transform .1s; }
.emoji-btn:hover { background: var(--surface-2); transform: scale(1.15); }
.emoji-tabs { display: flex; gap: 4px; padding-top: 6px; margin-top: 6px; border-top: 1px solid var(--border); }
.attach-pop { position: absolute; bottom: 50px; left: 0; }
.attach-ic { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; }

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .timeline, .composer-wrap { padding-left: 12px; padding-right: 12px; }
  .msg-main { max-width: 84%; }
}
