/* Cloud Chaburah Live: the docked discussion panel (live-chaburah-ui.js).
   Uses the page's own colour variables, so it follows whichever theme the page wears.

   Desktop: a drawer on the right; on a wide window the page makes room for it
   (body.live-open), otherwise it sits over the page. Phone: a bottom sheet. It scrolls
   independently of the Gemara and the video, and never moves either. */

.live-toggle {
  position: fixed; right: 18px; bottom: 18px; z-index: 880;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong, var(--line)); background: var(--card-strong, #fff); color: var(--text);
  box-shadow: 0 10px 30px rgba(19, 34, 56, .18); font-weight: 600; font-size: 14px;
}
.live-toggle[hidden] { display: none; }
.live-toggle:hover { border-color: var(--accent-strong); }
.live-toggle-dot { width: 9px; height: 9px; border-radius: 50%; background: #2e9d62; box-shadow: 0 0 0 3px rgba(46, 157, 98, .2); }
.live-toggle-count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--accent-strong); color: #fff; font-size: 12px; text-align: center; }
.live-toggle-count[hidden] { display: none; }
body.live-open .live-toggle { display: none; }

.live-panel {
  position: fixed; z-index: 900; top: 0; right: 0; bottom: 0; width: min(420px, 100vw);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--card-strong, #fff); color: var(--text);
  border-left: 1px solid var(--line-strong, var(--line)); box-shadow: -18px 0 50px rgba(19, 34, 56, .16);
}
.live-panel[hidden] { display: none; }

/* Room for the drawer on a wide window; over the page in Split View, which is full-screen. */
@media (min-width: 1240px) {
  body.live-open:not(.split-view-active) { padding-right: 420px; }
}

.live-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.live-head-text { min-width: 0; }
.live-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-strong); }
.live-title { margin: 2px 0 0; font-size: 18px; line-height: 1.25; }
.live-presence { margin-top: 3px; font-size: 12px; color: var(--muted); }
.live-presence[hidden] { display: none; }
.live-icon-button { flex: none; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 20px; line-height: 1; cursor: pointer; }
.live-icon-button:hover { background: var(--accent-soft); }

.live-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.live-view[hidden] { display: none; }
.live-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px 12px; }

.live-controls { display: flex; gap: 8px; align-items: center; padding: 10px 12px 0; }
.live-sort { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 13px; }
.live-start-button, .live-primary { padding: 8px 12px; border-radius: 10px; border: 0; background: var(--accent-strong); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.live-start-button:hover, .live-primary:hover { filter: brightness(1.1); }
.live-primary:disabled, .live-send:disabled { opacity: .55; cursor: default; }
.live-secondary { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 13px; cursor: pointer; }
.live-status { margin: 0; font-size: 12px; color: var(--muted); }
.live-status:empty { display: none; }

.live-threads { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.live-card {
  display: grid; gap: 4px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; font: inherit;
}
.live-card:hover { border-color: var(--accent-strong); background: var(--accent-soft); }
.live-card-quote { font-family: "Frank Ruhl Libre", "Times New Roman", serif; font-size: 18px; line-height: 1.4; color: var(--accent-strong); font-weight: 600; }
.live-card-preview { font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.live-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.live-badge { padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.live-badge-answered { background: rgba(46, 157, 98, .15); color: #1f7a4a; }
.live-unread { padding: 1px 8px; border-radius: 999px; background: var(--accent-strong); color: #fff; font-size: 11px; font-weight: 700; }
.live-pulse { width: 8px; height: 8px; border-radius: 50%; background: #2e9d62; box-shadow: 0 0 0 3px rgba(46, 157, 98, .2); }

.live-empty { padding: 18px 8px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.5; }
.live-empty:empty { display: none; }
.live-empty p { margin: 0 0 8px; }
.live-empty-title { color: var(--text); font-weight: 700; }

.live-admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.live-admin-bar[hidden] { display: none; }
.live-link { background: none; border: 0; padding: 0; color: var(--accent-strong); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: underline; }

/* Chat */
.live-chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.live-anchor {
  flex: 1; min-width: 0; text-align: right; padding: 4px 6px; border: 0; background: transparent; cursor: pointer;
  font-family: "Frank Ruhl Libre", "Times New Roman", serif; font-size: 18px; font-weight: 600; color: var(--accent-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.live-anchor:hover { text-decoration: underline; }
.live-chat-tools { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.live-chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 12px; cursor: pointer; }
.live-chip:hover { background: var(--accent-soft); }
.live-chip-danger { color: var(--danger); }
.live-chat-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 6px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.live-offline { color: var(--muted); font-style: italic; }

.live-messages-scroll { position: relative; display: flex; flex-direction: column; }
.live-more { align-self: center; margin-bottom: 8px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--accent-strong); font-size: 12px; cursor: pointer; }
.live-more[hidden], .live-new-below[hidden] { display: none; }
.live-messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.live-message { display: flex; }
.live-message.live-mine { justify-content: flex-end; }
.live-bubble { max-width: 86%; padding: 8px 11px; border-radius: 14px 14px 14px 4px; background: var(--bg-soft, #eef3f9); border: 1px solid transparent; }
.live-mine .live-bubble { border-radius: 14px 14px 4px 14px; background: var(--accent-soft); border-color: rgba(47, 110, 165, .25); }
.live-gone .live-bubble { background: transparent; border: 1px dashed var(--line-strong, var(--line)); color: var(--muted); font-style: italic; }
.live-author { font-size: 12px; font-weight: 700; color: var(--accent-strong); margin-bottom: 2px; }
.live-body-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.45; }
.live-quoted { display: block; width: 100%; text-align: left; margin: 0 0 5px; padding: 4px 8px; border-radius: 8px; border: 0; border-left: 3px solid var(--accent-strong); background: rgba(19, 34, 56, .06); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-bubble-foot { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 11px; color: var(--muted); }
.live-more-actions { margin-left: auto; padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; }
.live-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.live-flash .live-bubble { animation: live-flash 1.4s ease-out; }
@keyframes live-flash { from { box-shadow: 0 0 0 3px rgba(244, 214, 143, .9); } to { box-shadow: 0 0 0 3px rgba(244, 214, 143, 0); } }
@media (prefers-reduced-motion: reduce) { .live-flash .live-bubble { animation: none; outline: 2px solid var(--highlight); } }

.live-new-below { position: absolute; left: 50%; bottom: 142px; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; border: 0; background: var(--accent-strong); color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 6px 18px rgba(19, 34, 56, .25); }
.live-error { margin: 0; padding: 6px 14px; font-size: 12px; color: var(--danger); }
.live-error[hidden] { display: none; }

.live-composer { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.live-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.live-quote-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; padding: 4px 4px 4px 10px; border-left: 3px solid var(--accent-strong); border-radius: 6px; background: var(--bg-soft, #eef3f9); font-size: 12px; color: var(--muted); }
.live-quote-bar[hidden] { display: none; }
.live-quote-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-textarea { width: 100%; resize: none; padding: 9px 11px; border-radius: 12px; border: 1px solid var(--line-strong, var(--line)); background: var(--card); color: var(--text); font: inherit; font-size: 14.5px; line-height: 1.4; }
.live-input { max-height: 140px; }
.live-send { flex: none; padding: 9px 14px; border-radius: 12px; border: 0; background: var(--accent-strong); color: #fff; font-weight: 700; cursor: pointer; }

/* New discussion */
.live-compose-view { padding-bottom: 12px; overflow-y: auto; }
.live-compose-quote { margin: 12px; padding: 10px 14px; border-radius: 12px; border-right: 4px solid var(--accent-strong); background: var(--accent-soft); font-family: "Frank Ruhl Libre", "Times New Roman", serif; font-size: 20px; line-height: 1.5; }
.live-compose-view .live-textarea { width: calc(100% - 24px); margin: 0 12px; }
.live-note { margin: 8px 14px; font-size: 12px; line-height: 1.45; color: var(--muted); }
.live-compose-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 12px; }

/* Phone: a bottom sheet instead of a drawer */
@media (max-width: 800px) {
  .live-toggle { right: 12px; bottom: 12px; }
  .live-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: min(78vh, 640px);
    border-left: 0; border-top: 1px solid var(--line-strong, var(--line)); border-radius: 18px 18px 0 0;
    box-shadow: 0 -16px 40px rgba(19, 34, 56, .2);
  }
  .live-head { padding-top: 10px; }
  .live-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--line-strong, var(--line)); }
  .live-new-below { bottom: 128px; }
}
/* Above a phone's bottom tab bar. */
@media (max-width: 760px) {
  .live-toggle { bottom: calc(78px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: no-preference) {
  .live-panel:not([hidden]) { animation: live-in .18s ease-out; }
  @keyframes live-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
  @media (max-width: 800px) { @keyframes live-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } } }
}

/* ---- Phase 2: search, filters, what is new, markers on the printed daf ------------------- */
.live-toggle-new { padding: 1px 8px; border-radius: 999px; background: #c2410c; color: #fff; font-size: 12px; font-weight: 700; }
.live-toggle-new[hidden] { display: none; }

.live-search-row { padding: 8px 12px 0; }
.live-search { width: 100%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong, var(--line)); background: var(--card); color: var(--text); font: inherit; font-size: 14px; }
.live-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.live-filter { padding: 4px 12px; }
.live-chip-on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.live-chip-on:hover { background: var(--accent-strong); }
.live-options { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 8px 14px 4px; font-size: 12px; color: var(--muted); }
.live-option { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.live-option[hidden] { display: none; }
.live-option input { accent-color: var(--accent-strong); }
.live-banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 12px 0; padding: 6px 10px; border-radius: 10px; background: var(--accent-soft); font-size: 12px; }
.live-banner[hidden] { display: none; }
.live-badge-here { background: rgba(244, 214, 143, .55); color: #5c4310; }

/* Markers: a small bubble under the first words of a discussion, on the printed page */
.live-markers-overlay { position: absolute; inset: 0; pointer-events: none; }
.live-marker {
  position: absolute; width: 18px; height: 18px; padding: 0; transform: translate(50%, 2px);
  border-radius: 9px 9px 9px 2px; border: 2px solid #fff; background: #c2410c; color: #fff;
  box-shadow: 0 1px 4px rgba(19, 34, 56, .35); cursor: pointer; pointer-events: auto; opacity: .55;
  display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; line-height: 1;
}
.live-marker:hover, .live-marker:focus-visible { opacity: 1; transform: translate(50%, 2px) scale(1.15); }
.live-marker-count { pointer-events: none; }
body.live-open .live-marker { opacity: .8; }
