/* Simos Camp — Messages panel (owner: chat, prefix chat-).  js/ui/chatPanel.js
 * Mobile-first (≥ 360 px), 44 px touch targets, builds on css/base.css tokens (dark-mode variables included).
 */

/* the sheet keeps one calm height in every view; our own lists scroll, the composer stays pinned at the bottom */
.sc-panel.chat-panel { height: calc(100% - var(--safe-top, 0px) - 62px); min-width: 0; max-width: 100%; }
@media (min-width: 700px) { .sc-panel.chat-panel { height: min(86vh, 760px); } }
.chat-panel .ui-sheet-body.chat-body {
  display: flex; flex-direction: column; overflow: hidden;
  /* --chat-kb = height of an on-screen keyboard covering the page (set from visualViewport by chatPanel.js) */
  padding: 10px 12px calc(10px + var(--safe-bottom, 0px) + var(--chat-kb, 0px));
}
@media (min-width: 700px) { .chat-panel .ui-sheet-body.chat-body { padding: 12px 16px calc(14px + var(--chat-kb, 0px)); } }

.chat-root {
  --chat-good: #2f9a50; --chat-bad: #c23b3b; --chat-log-bg: rgba(255, 255, 255, .45); --chat-chip-ink: var(--turq-dark);
  flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 10px;
  pointer-events: auto; font-family: var(--font); color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chat-root { --chat-good: #9fe6b4; --chat-bad: #ffb3ab; --chat-log-bg: rgba(0, 0, 0, .14); --chat-chip-ink: var(--turq-light); }
}
:root[data-theme="dark"] .chat-root { --chat-good: #9fe6b4; --chat-bad: #ffb3ab; --chat-log-bg: rgba(0, 0, 0, .14); --chat-chip-ink: var(--turq-light); }

.chat-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 8px; padding: 2px 2px 8px;
}

/* ---------------------------------------------------------------- top bars */
.chat-top { flex: none; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.chat-top-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.chat-top-txt b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 13px; color: var(--ink-soft); }
.chat-new-btn.sc-btn { flex: none; min-height: 40px; }
.chat-search { flex: 1 1 auto; min-width: 0; }
.chat-back {
  flex: none; width: 44px; height: 44px; padding: 0 2px 4px 0; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--sand-dark); background: var(--paper); color: var(--ink); font: 700 30px/1 var(--font);
  cursor: pointer; box-shadow: 0 3px 0 var(--sand-dark); transition: transform .12s var(--ease-spring), box-shadow .12s;
}
.chat-back:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sand-dark); }

/* ---------------------------------------------------------------- inbox & picker rows */
.chat-row {
  flex: none; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 66px; padding: 8px 12px 8px 8px;
  border-radius: 18px; border: 2px solid var(--sand-dark); background: var(--paper); color: var(--ink);
  font-family: var(--font); text-align: left; cursor: pointer; box-shadow: 0 3px 0 var(--sand-dark);
  animation: chat-in .32s var(--ease-soft) backwards; transition: transform .12s var(--ease-spring), box-shadow .12s;
}
.chat-row:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sand-dark); }
.chat-row:focus-visible, .chat-back:focus-visible, .chat-who:focus-visible, .chat-chip:focus-visible, .chat-flag:focus-visible { outline: 3px solid var(--turq); outline-offset: 2px; }
.chat-row.unread {
  border-color: var(--turq); box-shadow: 0 3px 0 var(--turq-dark);
  background: linear-gradient(90deg, rgba(46, 196, 198, .16), rgba(46, 196, 198, 0) 65%), var(--paper);
}
.chat-pick { min-height: 58px; }
.chat-avatar { position: relative; flex: none; display: flex; }
.chat-dot {
  position: absolute; right: -1px; bottom: 1px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--green); border: 2.5px solid var(--paper); box-shadow: 0 1px 0 rgba(0, 0, 0, .15);
}
.chat-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-row-top, .chat-row-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-name { min-width: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-when { flex: none; margin-left: auto; font-size: 12px; color: var(--ink-faint); }
.chat-row.unread .chat-when { color: var(--turq-dark); font-weight: 700; }
.chat-preview { flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row.unread .chat-preview { color: var(--ink); font-weight: 600; }
.chat-badge {
  flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center;
  background: var(--red); color: #fff; font-size: 12px; font-weight: 700; box-shadow: 0 2px 0 var(--red-dark);
  animation: chat-pop .4s var(--ease-spring) backwards;
}
.chat-seen { flex: none; font-size: 12px; font-weight: 700; color: var(--turq-dark); }
.chat-go { flex: none; font-size: 18px; opacity: .75; }
.chat-sec { flex: none; display: flex; align-items: center; gap: 6px; margin: 8px 4px 0; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.chat-sec:first-child { margin-top: 2px; }
.chat-none { text-align: center; color: var(--ink-soft); padding: 26px 12px; font-size: 14.5px; }
.chat-foot {
  flex: none; display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: 14px;
  background: var(--sand); border: 2px dashed var(--sand-dark); color: var(--ink-soft); font-size: 12.5px; line-height: 1.35;
}

/* ---------------------------------------------------------------- conversation */
.chat-thead { flex: none; display: flex; align-items: center; gap: 8px; }
.chat-who {
  flex: 1 1 auto; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 3px 10px 3px 3px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink); font-family: var(--font); text-align: left; cursor: pointer;
  transition: background .15s;
}
.chat-who:hover, .chat-who:active { background: var(--sand); }
.chat-who-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.18; }
.chat-who-txt b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.on { color: var(--green-dark); font-weight: 600; }
.chat-more.sc-btn.round { flex: none; width: 44px; height: 44px; font-size: 20px; border-width: 2px; box-shadow: 0 3px 0 #cdb07a; }

.chat-msgs { gap: 3px; padding: 10px 8px; border-radius: 18px; background: var(--chat-log-bg); border: 2px solid var(--sand-dark); }
.chat-day { flex: none; align-self: center; margin: 8px 0 6px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.chat-day span { display: inline-block; padding: 2px 11px; border-radius: 999px; background: var(--sand); border: 1px solid var(--sand-dark); }
.chat-msg { flex: none; display: flex; flex-direction: column; max-width: 84%; }
.chat-msg.chat-new { animation: chat-msg-in .3s var(--ease-spring) backwards; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-bub {
  padding: 9px 13px; border-radius: 18px; font-size: 15.5px; line-height: 1.36;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; -webkit-user-select: text; user-select: text;
}
.chat-msg.mine .chat-bub {
  background: linear-gradient(180deg, #5fdad8, var(--turq)); color: #fff; border-bottom-right-radius: 6px;
  text-shadow: 0 1px 0 rgba(21, 113, 134, .45); box-shadow: 0 2px 0 #157186;
}
.chat-msg.theirs .chat-bub {
  background: var(--paper); color: var(--ink); border: 2px solid var(--sand-dark); border-bottom-left-radius: 6px;
  box-shadow: 0 2px 0 var(--sand-dark);
}
.chat-msg.theirs .chat-bub.chat-hidden { background: var(--sand); color: var(--ink-faint); font-style: italic; font-size: 14px; }
.chat-meta { display: flex; align-items: center; gap: 8px; margin: 2px 6px 5px; font-size: 11.5px; color: var(--ink-faint); }
.chat-rc { color: var(--ink-soft); }
.chat-rc.seen { color: var(--turq-dark); font-weight: 700; }
.chat-flag {
  min-height: 30px; margin: -6px -4px; padding: 5px 8px; border: 0; border-radius: 10px; background: transparent;
  color: var(--ink-faint); font: 600 11.5px var(--font); cursor: pointer; transition: color .15s, background .15s;
}
.chat-flag:hover, .chat-flag:active { color: var(--red-dark); background: rgba(255, 90, 90, .12); }

.chat-hello, .chat-blocked {
  margin: auto; max-width: 320px; padding: 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; color: var(--ink-soft);
}
.chat-hello .sc-face { border-width: 3px; animation: chat-bob 2.8s ease-in-out infinite; }
.chat-hello b, .chat-blocked b { color: var(--ink); font-size: 17px; }
.chat-hello p, .chat-blocked p { margin: 0; font-size: 13.5px; line-height: 1.42; }
.chat-blocked-ico { font-size: 44px; line-height: 1; }

/* ---------------------------------------------------------------- composer */
.chat-compose { flex: none; display: flex; flex-direction: column; gap: 6px; }
.chat-chips {
  /* width 0 + min-width 100%: the long nowrap row never widens the sheet — it scrolls sideways instead */
  width: 0; min-width: 100%;
  display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 2px 2px 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x; overscroll-behavior: contain;
}
.chat-chips::-webkit-scrollbar { display: none; }
.chat-chips-lbl { flex: none; font-size: 12px; font-weight: 700; color: var(--ink-faint); }
.chat-chip {
  flex: none; min-height: 36px; padding: 5px 13px; border-radius: 999px; white-space: nowrap; cursor: pointer;
  border: 2px solid var(--turq-light); background: var(--paper); color: var(--chat-chip-ink); font: 600 13.5px var(--font);
  box-shadow: 0 2px 0 var(--turq-light); transition: transform .12s var(--ease-spring), box-shadow .12s;
}
.chat-chip:active { transform: translateY(2px); box-shadow: 0 0 0 var(--turq-light); }
.chat-field { display: flex; align-items: flex-end; gap: 8px; }
.chat-input.sc-input {
  flex: 1 1 auto; min-width: 0; min-height: 48px; max-height: 112px; padding: 11px 15px; border-radius: 24px;
  resize: none; overflow-y: auto; font-size: 16px; line-height: 1.35;
}
.chat-send.sc-btn.round { flex: none; width: 48px; height: 48px; font-size: 20px; }
.chat-send span { display: inline-block; transform: translateX(2px); }
.chat-fbrow { display: flex; align-items: flex-start; gap: 8px; min-height: 18px; padding: 0 8px; }
.chat-fb { flex: 1 1 auto; min-width: 0; font-size: 13px; line-height: 1.3; color: var(--ink-soft); }
.chat-fb.good { color: var(--chat-good); font-weight: 600; }
.chat-fb.bad { color: var(--chat-bad); font-weight: 600; }
.chat-fb.live { animation: chat-fade .2s ease; }
.chat-count { flex: none; font-size: 12px; color: var(--ink-faint); }
.chat-count.near { color: var(--orange); font-weight: 700; }
.chat-shake { animation: chat-shake .42s ease; }

@media (min-width: 700px) {
  .chat-msg { max-width: 74%; }
  .chat-chips { flex-wrap: wrap; overflow: visible; }
}

@keyframes chat-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes chat-msg-in { from { opacity: 0; transform: translateY(8px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes chat-pop { 0% { opacity: 0; transform: scale(.4); } 70% { opacity: 1; transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes chat-fade { from { opacity: .35; } to { opacity: 1; } }
@keyframes chat-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes chat-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 45% { transform: translateX(6px); } 70% { transform: translateX(-3px); } 85% { transform: translateX(2px); } }
