/* ============================================================================
   chat.css — Phase R6a — Chat pane (yellow color identity).

   Yellow is the warm noon between orange Contacts and green Call. Chats
   are conversation — light, fast, friendly. Liquid-glass thread cards
   with a faint spherical-harmonic ripple on the active row, and bubble
   gradients that subtly differ by role (yours brighter, theirs cooler).

   All selectors live under .page-chat.chat-stage[data-color="yellow"] with
   .ch-* prefixes so they never collide with the legacy .dm-* / .rcd-*
   classes still in app.css. The legacy .dm-msg-file-* preview chrome
   continues to apply inside .ch-thread-log because we re-render file
   messages with the same .dm-msg-file class names.

   Layout:
     • Phone (≤ 720px): one card at a time (list OR thread).
     • Tablet+ (≥ 880px container): list rail (320px) + thread (1fr).
   ========================================================================= */

.page-chat.chat-stage {
    --ch-color-0: #ffe06b;       /* primary yellow */
    --ch-color-1: #f5c518;       /* deeper amber */
    --ch-color-2: #fff4b5;       /* highlight */
    --ch-color-3: rgba(245, 197, 24, 0.16);
    --ch-color-4: rgba(245, 197, 24, 0.32);
    --ch-glass:   rgba(28, 24, 10, 0.58);
    --ch-glass-2: rgba(40, 32, 12, 0.72);
    --ch-border:  rgba(255, 224, 107, 0.22);
    --ch-border-strong: rgba(255, 224, 107, 0.42);
    --ch-fg:      #fff7e0;
    --ch-fg-2:    #d8c89d;
    --ch-fg-3:    #998a55;
    --ch-shadow:  0 18px 42px rgba(245, 197, 24, 0.16);

    display: grid;
    gap: 14px;
    padding: 18px clamp(14px, 4vw, 28px);
    container-type: inline-size;
    color: var(--ch-fg);
    min-height: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    background:
        radial-gradient(ellipse at 80% -10%, var(--ch-color-3), transparent 55%),
        radial-gradient(ellipse at -10% 110%, rgba(245, 197, 24, 0.10), transparent 55%);
}

@container (min-width: 880px) {
    .page-chat.chat-stage {
        grid-template-columns: 320px 1fr;
        grid-template-rows: auto 1fr;
    }
    .page-chat.chat-stage .ch-topbar { grid-column: 1 / -1; }
}

/* ── Topbar ─────────────────────────────────────────────────────── */

.chat-stage .ch-topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    border: 1px solid var(--ch-border);
    border-radius: 18px;
    background: var(--ch-glass);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    box-shadow: var(--ch-shadow);
}
.chat-stage .ch-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.chat-stage .ch-sub   { margin: 4px 0 0; font-size: 12.5px; color: var(--ch-fg-2); line-height: 1.45; }
.chat-stage .ch-topbar-right {
    display: flex; align-items: center; gap: 10px;
}
.chat-stage .ch-avatar-host { width: 56px; height: 56px; flex: 0 0 56px; position: relative; }
.chat-stage .ch-stats { font-size: 11.5px; color: var(--ch-fg-2); white-space: nowrap; }

/* ── Threads list (left column on desktop) ──────────────────────── */

.chat-stage .ch-list-card {
    display: flex; flex-direction: column; gap: 8px;
    padding: 14px;
    border: 1px solid var(--ch-border);
    border-radius: 18px;
    background: var(--ch-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
}
.chat-stage .ch-list-actions {
    display: flex; gap: 6px; flex-wrap: wrap;
    margin-bottom: 6px;
}
.chat-stage .ch-add-btn {
    appearance: none;
    border: 1px solid var(--ch-border-strong);
    background: linear-gradient(180deg, var(--ch-color-0), var(--ch-color-1));
    color: #2a1f04;
    border-radius: 999px;
    padding: 6px 12px;
    font: inherit; font-weight: 600; font-size: 12.5px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(245, 197, 24, 0.32);
    transition: transform .12s ease, box-shadow .15s ease;
}
.chat-stage .ch-add-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(245,197,24,.4); }
.chat-stage .ch-add-btn:active { transform: translateY(0); }
.chat-stage .ch-add-btn:disabled { opacity: .55; cursor: not-allowed; }

.chat-stage .ch-list {
    display: flex; flex-direction: column; gap: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    max-height: clamp(280px, 60vh, 720px);
}
.chat-stage .ch-list-row {
    appearance: none;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: var(--ch-fg);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
    padding: 10px 12px;
    border: 1px solid var(--ch-border);
    border-radius: 14px;
    background: var(--ch-glass-2);
    transition: transform .12s ease, border-color .15s ease, background .15s ease;
    position: relative;
}
.chat-stage .ch-list-row:hover  { transform: translateY(-1px); border-color: var(--ch-border-strong); }
.chat-stage .ch-list-row:active { transform: translateY(0); }
.chat-stage .ch-list-row.is-active {
    border-color: var(--ch-color-1);
    background: linear-gradient(180deg, var(--ch-color-3), var(--ch-glass-2));
}
.chat-stage .ch-list-row.has-unread { border-color: var(--ch-color-1); }
.chat-stage .ch-list-row-name {
    font-weight: 600; font-size: 14px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; gap: 6px; align-items: center;
}
.chat-stage .ch-list-row-kind {
    font-size: 10.5px; padding: 1px 7px;
    border-radius: 999px;
    background: var(--ch-color-3);
    color: var(--ch-color-0);
    font-weight: 500;
}
.chat-stage .ch-list-row-when {
    font-size: 10.5px; color: var(--ch-fg-3); white-space: nowrap;
}
.chat-stage .ch-list-row-preview {
    font-size: 12.5px; color: var(--ch-fg-2);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    grid-column: 1 / -1;
}
.chat-stage .ch-list-row-badge {
    position: absolute;
    top: 8px; right: 10px;
    background: var(--ch-color-1);
    color: #2a1f04;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 10.5px; font-weight: 700;
    min-width: 18px; text-align: center;
}

.chat-stage .ch-list-empty {
    text-align: center;
    padding: 20px 12px;
    color: var(--ch-fg-2);
    font-size: 13px;
    border: 1px dashed var(--ch-border);
    border-radius: 14px;
    background: var(--ch-glass-2);
}

/* ── Thread card (right column on desktop) ──────────────────────── */

.chat-stage .ch-thread-card {
    display: flex; flex-direction: column;
    border: 1px solid var(--ch-border);
    border-radius: 18px;
    background: var(--ch-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    overflow: hidden;
    min-height: 360px;
    box-shadow: var(--ch-shadow);
}
.chat-stage .ch-thread-head {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--ch-border);
    background: rgba(40, 32, 12, 0.45);
}
.chat-stage .ch-back {
    appearance: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid var(--ch-border);
    background: rgba(0,0,0,.3);
    color: var(--ch-fg);
    cursor: pointer;
    display: grid; place-items: center;
    font-size: 16px;
    transition: background .15s ease;
}
.chat-stage .ch-back:hover { background: var(--ch-color-3); }
.chat-stage .ch-thread-peer {
    font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 14.5px;
}
.chat-stage .ch-typing-pill {
    font-size: 10.5px;
    background: var(--ch-color-3);
    color: var(--ch-color-0);
    padding: 1px 8px;
    border-radius: 999px;
    font-weight: 500;
    margin-left: 6px;
    animation: ch-typing-pulse 1.4s ease-in-out infinite;
}
@keyframes ch-typing-pulse {
    0%, 100% { opacity: .55; }
    50%      { opacity: 1; }
}
.chat-stage .ch-thread-status { font-size: 11px; color: var(--ch-fg-3); }
.chat-stage .ch-manage-btn {
    appearance: none;
    border: 1px solid var(--ch-border);
    background: rgba(0,0,0,.3);
    color: var(--ch-fg);
    width: 36px; height: 36px;
    border-radius: 50%;
    font-size: 16px; cursor: pointer;
    display: grid; place-items: center;
}
.chat-stage .ch-manage-btn:hover { background: var(--ch-color-3); }

.chat-stage .ch-thread-log {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px;
    display: flex; flex-direction: column; gap: 8px;
}

/* ── Bubbles ────────────────────────────────────────────────────── */

.chat-stage .ch-msg {
    max-width: min(80%, 560px);
    padding: 9px 13px;
    border-radius: 16px;
    border: 1px solid transparent;
    font-size: 14px; line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    transition: transform .1s ease;
}
.chat-stage .ch-msg.me {
    align-self: flex-end;
    background: linear-gradient(180deg, rgba(255, 224, 107, 0.18), rgba(245, 197, 24, 0.12));
    border-color: rgba(245, 197, 24, 0.38);
    color: var(--ch-fg);
    border-top-right-radius: 6px;
}
.chat-stage .ch-msg.them {
    align-self: flex-start;
    background: rgba(40, 32, 12, 0.55);
    border-color: rgba(255, 224, 107, 0.18);
    color: var(--ch-fg);
    border-top-left-radius: 6px;
}
.chat-stage .ch-msg.deleted,
.chat-stage .ch-msg.err {
    font-style: italic; opacity: .6;
}
.chat-stage .ch-msg.pending {
    opacity: .75;
    border-style: dashed;
}
.chat-stage .ch-msg.pending::after {
    content: ' · queued';
    color: var(--ch-color-0);
    font-size: 10.5px;
}
.chat-stage .ch-msg-text { white-space: pre-wrap; }
.chat-stage .ch-msg-toggle {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(245, 197, 24, 0.35);
  background: rgba(245, 197, 24, 0.10);
  color: var(--fg-0, #fff7e0);
  font-size: 11.5px;
  cursor: pointer;
}
.chat-stage .ch-msg-toggle:hover { background: rgba(245, 197, 24, 0.18); }

/* Phase 13 — reactions */
.chat-stage .ch-msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.chat-stage .ch-reaction-pill {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg-0, #fff7e0);
  font-size: 12px;
  cursor: pointer;
  line-height: 1.3;
}
.chat-stage .ch-reaction-pill:hover { background: rgba(255, 255, 255, 0.10); }
.chat-stage .ch-reaction-pill.is-mine {
  background: rgba(245, 197, 24, 0.20);
  border-color: rgba(245, 197, 24, 0.50);
}
.ch-reaction-picker {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px;
}
.ch-reaction-picker-row {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(20, 16, 8, 0.92);
  border: 1px solid rgba(245, 197, 24, 0.45);
  border-radius: 999px;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.55);
}
.ch-reaction-picker-btn {
  background: transparent;
  border: 0;
  padding: 6px 8px;
  font-size: 22px;
  cursor: pointer;
  border-radius: 50%;
  transition: transform 120ms ease;
}
.ch-reaction-picker-btn:hover { transform: scale(1.25); }

/* Phase 14 — location card */
.chat-stage .ch-msg-location {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(245, 197, 24, 0.30);
  text-decoration: none;
  color: inherit;
  margin-top: 4px;
  cursor: pointer;
  max-width: 320px;
}
.chat-stage .ch-msg-location:hover { background: rgba(255, 255, 255, 0.10); }
.chat-stage .ch-loc-icon { font-size: 26px; flex-shrink: 0; }
.chat-stage .ch-loc-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-stage .ch-loc-label  { font-size: 13.5px; font-weight: 600; color: var(--fg-0, #fff7e0); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-stage .ch-loc-coords { font-size: 12px;   color: rgba(255, 247, 224, 0.85); font-family: ui-monospace, monospace; }
.chat-stage .ch-loc-acc    { font-size: 11px;   color: rgba(255, 247, 224, 0.55); }

/* Phase 14 — attachments modal */
.y-attv-sheet {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.y-attv-panel {
  width: 100%;
  max-width: 880px;
  max-height: 85vh;
  background: rgba(20, 16, 8, 0.94);
  border: 1px solid rgba(245, 197, 24, 0.40);
  border-radius: 18px;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.y-attv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.y-attv-title { font-size: 14px; color: var(--fg-0, #fff7e0); font-weight: 600; }
.y-attv-close { background: transparent; border: 0; color: #fff; font-size: 18px; cursor: pointer; }
.y-attv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  min-height: 0;
}
.y-attv-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 10px;
  color: rgba(255, 247, 224, 0.55);
  font-size: 13px;
}
.y-attv-tile {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: inherit;
  text-align: left;
  font: inherit;
  overflow: hidden;
}
.y-attv-tile:hover { background: rgba(255, 255, 255, 0.10); }
.y-attv-tile .attv-img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  display: block;
}
.y-attv-tile .attv-placeholder {
  width: 100%;
  height: 110px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}
.y-attv-tile .attv-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 4px 4px;
  min-width: 0;
}
.y-attv-tile .attv-fname {
  font-size: 12px;
  color: var(--fg-0, #fff7e0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.y-attv-tile .attv-fsize {
  font-size: 10.5px;
  color: rgba(255, 247, 224, 0.55);
}
.chat-stage .ch-msg-meta {
    font-size: 10.5px;
    margin-top: 4px;
    opacity: 0.7;
}
.chat-stage .ch-msg-sender {
    display: block;
    font-size: 11px;
    color: var(--ch-color-0);
    font-weight: 600;
    margin-bottom: 2px;
}

/* ── Compose ────────────────────────────────────────────────────── */

.chat-stage .ch-compose {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--ch-border);
    background: rgba(40, 32, 12, 0.45);
    align-items: end;
}
.chat-stage .ch-attach-label {
    appearance: none;
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--ch-border);
    background: rgba(0,0,0,.3);
    color: var(--ch-fg);
    cursor: pointer;
    display: grid; place-items: center;
    font-size: 18px;
    transition: background .15s ease;
}
.chat-stage .ch-attach-label:hover { background: var(--ch-color-3); }
.chat-stage .ch-attach-label.busy { opacity: .55; pointer-events: none; }
.chat-stage .ch-input {
    appearance: none;
    background: rgba(0,0,0,.36);
    border: 1px solid var(--ch-border);
    color: var(--ch-fg);
    border-radius: 14px;
    padding: 9px 12px;
    font: inherit; font-size: 14px;
    line-height: 1.4;
    resize: none;
    min-height: 40px;
    max-height: 140px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    box-sizing: border-box;
    width: 100%;
}
.chat-stage .ch-input:focus {
    border-color: var(--ch-color-1);
    box-shadow: 0 0 0 3px var(--ch-color-3);
}
.chat-stage .ch-send {
    appearance: none;
    border: 1px solid var(--ch-border-strong);
    background: linear-gradient(180deg, var(--ch-color-0), var(--ch-color-1));
    color: #2a1f04;
    border-radius: 999px;
    padding: 9px 18px;
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(245, 197, 24, 0.32);
    transition: transform .12s ease, box-shadow .15s ease;
}
.chat-stage .ch-send:hover  { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(245, 197, 24, 0.4); }
.chat-stage .ch-send:active { transform: translateY(0); }
.chat-stage .ch-send:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

/* Mobile ⇒ thread takes the whole screen when a thread is active. */
.page-chat.chat-stage .ch-list-card[data-mobile-hidden="true"] { display: none; }
.page-chat.chat-stage .ch-thread-card[hidden]                  { display: none; }

@media (prefers-reduced-motion: reduce) {
    .chat-stage .ch-list-row,
    .chat-stage .ch-add-btn,
    .chat-stage .ch-send,
    .chat-stage .ch-typing-pill { transition: none; animation: none; }
}
