/* D1 Sales Floor -- modern chat (v617)
 *
 * Logan, Oct 16: "Anyway to make the chat section super modern" -> the
 * polished version shipped in v617 (dark header, messages on cards, dark
 * sold card). Then, v618: "it's too much with the dark backgrounds let's go
 * more the slack route". So now it reads like Slack: one white page, a
 * light header with a thin line under it, messages flat on the page (name
 * and time on one line, square-ish avatars), sold posts on a light gold
 * card, and a plain composer bar at the bottom. Kept from v617: the coloured
 * channel tiles, last message under each chat, and the press-and-hold card.
 *
 * Phone only (below 900px) except where noted; the desktop sidebar keeps
 * its look. Everything is scoped to #view-chat, loaded after styles-v2.css,
 * and works in light and dark (html[data-theme="dark"]). */

:root {
  --cm-ink: #0c1a2b;
  --cm-ink-2: #15263b;
  --cm-accent: #0aa6ad;
  --cm-accent-ink: #087a80;
  --cm-accent-soft: #e0f7f8;
  --cm-ground: #ffffff;
  --cm-soft: #f3f5f8;
  --cm-card: #ffffff;
  --cm-line: #e6ebf1;
  --cm-text: #0f172a;
  --cm-muted: #64748b;
  --cm-shadow: 0 6px 20px rgba(15, 23, 42, .07);
  --cm-shadow-lg: 0 12px 32px rgba(15, 23, 42, .16);
}
html[data-theme="dark"] {
  --cm-ink: #0a1422;
  --cm-ink-2: #13233a;
  --cm-accent-soft: rgba(10, 166, 173, .18);
  --cm-ground: #0d1520;
  --cm-soft: #182536;
  --cm-card: #162232;
  --cm-line: #223247;
  --cm-text: #e7edf5;
  --cm-muted: #94a3b8;
  --cm-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --cm-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

@media (max-width: 899px) {
  #view-chat { background: var(--cm-ground) !important; }

  /* ---------- the channel list ---------- */
  #view-chat:not(.room) .chan-row {
    background: transparent !important;
    border: 0 !important;
    padding: 0 14px 12px !important;
    gap: 12px !important;
  }
  #view-chat:not(.room) .chan-row::after { display: none !important; }
  #view-chat:not(.room) #chanStrip {
    background: transparent !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 4px 0 8px !important;
    margin-top: 0 !important;
  }
  #view-chat:not(.room) #chanStrip .chan-sec {
    padding: 12px 16px 4px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    letter-spacing: .6px !important;
    text-transform: uppercase;
    color: var(--cm-muted) !important;
    background: transparent !important;
  }
  #view-chat:not(.room) #chanStrip .chip {
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    grid-template-areas: "ic name when" "ic prev prev";
    column-gap: 12px; row-gap: 1px;
    align-items: center;
    width: 100% !important;
    min-height: 62px;
    padding: 9px 16px !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--cm-text) !important;
    text-align: left;
  }
  #view-chat:not(.room) #chanStrip .chip.active { background: transparent !important; }
  #view-chat:not(.room) #chanStrip .chip:active { background: var(--cm-soft) !important; }
  #view-chat:not(.room) #chanStrip .chip-hash {
    grid-area: ic;
    width: 42px; height: 42px;
    border-radius: 10px;
    display: flex !important; align-items: center; justify-content: center;
    font-style: normal; font-weight: 800; font-size: 18px;
    background: #00b3bb; color: #fff;
    background-size: cover; background-position: center;
  }
  /* no photo yet: D1 teal and purple, taking turns down the list (v619) */
  #view-chat:not(.room) #chanStrip .chip[data-chan]:nth-of-type(2n) .chip-hash { background-color: #8958fe; color: #fff; }
  /* a channel photo (channel-photos.js) fills the tile */
  #view-chat:not(.room) #chanStrip .chip-hash.has-photo {
    color: transparent !important; background-color: var(--cm-soft);
    background-size: cover !important; background-position: center !important;
  }
  /* the header photo and the camera only belong inside a channel */
  #view-chat:not(.room) .chan-pic, #view-chat:not(.room) .chan-photo-btn { display: none !important; }
  #view-chat:not(.room) #chanStrip .chip .avatar {
    grid-area: ic;
    width: 42px !important; height: 42px !important;
    border-radius: 21px !important;
    font-size: 14px !important;
  }
  #view-chat:not(.room) #chanStrip .chip-name {
    grid-area: name;
    font-size: 15px !important; font-weight: 600 !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #view-chat:not(.room) #chanStrip .chip-when {
    grid-area: when;
    font-style: normal; font-size: 12px !important; font-weight: 600;
    color: var(--cm-muted) !important;
  }
  #view-chat:not(.room) #chanStrip .chip-prev {
    grid-area: prev;
    font-style: normal; font-size: 13px; color: var(--cm-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
  }
  /* unread: bold name, teal time, dark preview */
  #view-chat:not(.room) #chanStrip .chip:has(.dot) .chip-name,
  #view-chat:not(.room) #chanStrip .chip.unread .chip-name { font-weight: 800 !important; }
  #view-chat:not(.room) #chanStrip .chip:has(.dot) .chip-when,
  #view-chat:not(.room) #chanStrip .chip.unread .chip-when { color: var(--cm-accent-ink) !important; }
  #view-chat:not(.room) #chanStrip .chip:has(.dot) .chip-prev,
  #view-chat:not(.room) #chanStrip .chip.unread .chip-prev { color: var(--cm-text); }
  #view-chat:not(.room) #chanStrip .chip .dot {
    grid-area: prev; justify-self: end;
    position: static !important;
    min-width: 22px; height: 22px; padding: 0 7px; box-sizing: border-box;
    border-radius: 11px !important;
    background: var(--cm-accent) !important; color: #fff !important;
    font-size: 12px !important; font-weight: 700;
    display: inline-flex !important; align-items: center; justify-content: center;
  }
  /* Activity: a pill above the list */
  #view-chat:not(.room) #chanStrip #jobMsgOpen {
    display: flex !important; align-items: center; justify-content: center;
    min-height: 44px !important;
    margin: 6px 12px 4px !important; width: calc(100% - 24px) !important;
    border-radius: 14px !important;
    background: var(--cm-accent-soft) !important;
    color: var(--cm-accent-ink) !important;
    font-weight: 700 !important; font-size: 14px !important;
  }
  /* search: a soft field at the foot of the list */
  #view-chat:not(.room) .chan-row #searchOpen {
    background: var(--cm-soft) !important;
    border: 1px solid var(--cm-line) !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    min-height: 48px !important;
    color: var(--cm-muted) !important;
  }

  /* ---------- inside a channel ---------- */
  /* one header: the app bar steps aside while a room is open */
  body:has(#view-chat.room:not(.hidden)) .topbar { display: none !important; }
  #view-chat.room .chan-row {
    background: var(--cm-card) !important;
    color: var(--cm-text) !important;
    border: 0 !important;
    border-bottom: 1px solid var(--cm-line) !important;
    border-radius: 0 !important;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 10px 10px !important;
    box-shadow: none !important;
    position: relative; z-index: 2;
  }
  #view-chat.room .chan-row::after { display: none !important; }
  #view-chat.room .chan-back,
  #view-chat.room .chan-row #searchOpen {
    color: var(--cm-text) !important;
    background: var(--cm-soft) !important;
    border: 0 !important;
    border-radius: 12px !important;
    width: 40px !important; height: 40px !important; min-height: 40px !important;
  }
  /* the channel's photo (or tile) next to its name, and the admin camera */
  #view-chat.room .chan-pic {
    display: flex; align-items: center; justify-content: center; flex: none;
    width: 34px; height: 34px; border-radius: 9px;
    font-style: normal; font-weight: 800; font-size: 15px;
    background-size: cover; background-position: center;
  }
  #view-chat.room .chan-pic[hidden] { display: none; }
  #view-chat.room .chan-pic.has-photo { color: transparent !important; background-size: cover !important; }
  #view-chat.room .chan-photo-btn {
    display: flex; align-items: center; justify-content: center; flex: none;
    color: var(--cm-text); background: var(--cm-soft); border: 0;
    border-radius: 12px; width: 40px; height: 40px; margin-left: auto;
  }
  #view-chat.room .chan-photo-btn[hidden] { display: none; }
  #view-chat.room .chan-cur {
    color: var(--cm-text) !important;
    font-size: 17px !important; font-weight: 700 !important;
  }
  #view-chat.room .pin-strip {
    margin: 12px 12px 0 !important;
    border-radius: 16px !important;
    background: #fff7e6 !important;
    border: 1px solid #fde4b0 !important;
    color: #78350f !important;
  }
  html[data-theme="dark"] #view-chat.room .pin-strip { background: #2a2210 !important; border-color: #4a3b12 !important; color: #fcd34d !important; }

  #view-chat .msgs {
    background: var(--cm-ground) !important;
    padding: 8px 14px 96px !important;
  }
  #view-chat .day-sep span, #view-chat .day-sep {
    color: var(--cm-muted) !important;
  }

  /* every message reads left, flat on the page, name and time on one line */
  #view-chat .msg, #view-chat .msg.mine {
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 10px !important;
    margin: 0 0 12px !important;
  }
  #view-chat .msg.grouped { margin-top: -8px !important; }
  #view-chat .msg .avatar.tiny {
    width: 36px !important; height: 36px !important;
    border-radius: 9px !important;
    font-size: 13px !important;
  }
  #view-chat .msg-body, #view-chat .msg.mine .msg-body {
    flex: 1 1 auto !important; min-width: 0;
    max-width: none !important;
    align-items: stretch !important;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    padding: 0 !important;
  }
  #view-chat .msg-head, #view-chat .msg.mine .msg-head {
    display: flex !important; flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: baseline !important; gap: 8px !important;
    margin: 0 0 2px !important; padding: 0 !important;
  }
  #view-chat .msg-head b { font-size: 15px !important; font-weight: 800 !important; color: var(--cm-text) !important; }
  #view-chat .msg-head span { font-size: 12px !important; color: var(--cm-muted) !important; }
  #view-chat .bubble, #view-chat .msg.mine .bubble, #view-chat .msg.mine .bubble.has-photo {
    background: transparent !important;
    background-image: none !important;
    color: var(--cm-text) !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    font-size: 15px !important; line-height: 1.5 !important;
  }
  #view-chat .msg.mine .bubble a { color: var(--cm-accent-ink) !important; }
  #view-chat .msg-photo {
    border-radius: 14px !important;
    margin-top: 6px !important;
    max-width: 100% !important;
  }
  #view-chat .msg.calls-me .msg-body { background: var(--cm-accent-soft); border-radius: 8px; box-shadow: inset 3px 0 0 var(--cm-accent); padding: 6px 10px !important; }
  #view-chat .bubble .mention, #view-chat .bubble .at {
    background: var(--cm-accent-soft) !important;
    color: var(--cm-accent-ink) !important;
    border-radius: 6px; padding: 0 4px; font-weight: 700;
  }
  #view-chat .rx { padding-left: 46px !important; gap: 6px !important; }
  #view-chat .rx button, #view-chat .rx .rx-pill {
    height: 28px !important; padding: 0 10px !important;
    border-radius: 14px !important;
    background: var(--cm-soft) !important;
    border: 1px solid var(--cm-line) !important;
    box-shadow: none;
    font-weight: 700 !important;
  }
  #view-chat .rx button.mine, #view-chat .rx .rx-pill.mine {
    background: var(--cm-accent-soft) !important;
    border-color: var(--cm-accent) !important;
    color: var(--cm-accent-ink) !important;
  }

  /* sold posts: a light gold card */
  #view-chat .win {
    display: grid !important;
    grid-template-columns: 44px 1fr;
    grid-template-areas: "b line" "b time";
    column-gap: 12px; row-gap: 2px; align-items: center;
    background: #fffbeb !important;
    color: var(--cm-text) !important;
    border: 1px solid #fde68a !important;
    border-radius: 14px !important;
    box-shadow: none !important;
    padding: 12px !important;
    margin: 4px 0 10px !important;
  }
  #view-chat .win-burst {
    grid-area: b;
    width: 44px; height: 44px; border-radius: 10px;
    background: #fde68a;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
  }
  #view-chat .win-line { grid-area: line; font-size: 15px !important; line-height: 1.4; color: var(--cm-text) !important; }
  #view-chat .win-line b { color: #b45309 !important; }
  #view-chat .win-time { grid-area: time; font-size: 12px !important; color: var(--cm-muted) !important; }
  html[data-theme="dark"] #view-chat .win { background: #2a2210 !important; border-color: #4a3b12 !important; }
  html[data-theme="dark"] #view-chat .win-burst { background: #4a3b12; }
  html[data-theme="dark"] #view-chat .win-line b { color: #fbbf24 !important; }

  /* the composer: a plain bar along the bottom */
  #view-chat .composer {
    background: var(--cm-card) !important;
    border: 0 !important;
    border-top: 1px solid var(--cm-line) !important;
    box-shadow: none !important;
    padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
  }
  #view-chat .composer .comp-field {
    background: var(--cm-soft) !important;
    border: 1px solid var(--cm-line) !important;
    border-radius: 14px !important;
    box-shadow: none !important;
    min-height: 48px;
    padding: 4px 4px 4px 6px !important;
  }
  #view-chat .composer .attach {
    width: 40px !important; height: 40px !important;
    border-radius: 10px !important;
  }
  #view-chat .composer #chatAttach { background: transparent !important; color: var(--cm-text) !important; }
  #view-chat .composer .send {
    width: 44px !important; height: 44px !important; min-width: 44px;
    border-radius: 12px !important;
    background: var(--cm-accent) !important;
    background-image: none !important;
    box-shadow: none !important;
  }
  #view-chat .reply-bar, #view-chat .rec-bar, #view-chat .pending-photo, #view-chat .mention-bar {
    margin: 0 12px 8px !important;
    border-radius: 12px !important;
    background: var(--cm-soft) !important;
    box-shadow: none !important;
    border: 1px solid var(--cm-line) !important;
  }
}

/* phone list: fixes on top of the rules above */
@media (max-width: 899px) {
  #view-chat:not(.room) #chanStrip .chip-hash { opacity: 1 !important; }
  #view-chat:not(.room) #chanStrip .chip-when { display: block !important; }
  #view-chat:not(.room) #chanStrip .chip .chip-ava {
    grid-area: ic;
    width: 42px !important; height: 42px !important;
    border-radius: 21px !important; overflow: hidden;
    margin: 0 !important;
  }
  #view-chat:not(.room) #chanStrip .chip .chip-ava img { width: 100%; height: 100%; object-fit: cover; }
  #view-chat:not(.room) #chanStrip .chip .chip-badge {
    grid-area: prev; justify-self: end;
    position: static !important;
    min-width: 22px; height: 22px; padding: 0 7px; box-sizing: border-box;
    border-radius: 11px !important;
    background: var(--cm-accent) !important; color: #fff !important;
    font-style: normal; font-size: 12px !important; font-weight: 700;
    display: inline-flex !important; align-items: center; justify-content: center;
  }
  #view-chat:not(.room) #chanStrip .chip:has(.chip-badge) .chip-name { font-weight: 800 !important; color: var(--cm-text) !important; }
  #view-chat:not(.room) #chanStrip .chip:has(.chip-badge) .chip-when { color: var(--cm-accent-ink) !important; }
  #view-chat:not(.room) #chanStrip .chip:has(.chip-badge) .chip-prev { color: var(--cm-text); font-weight: 500; }
  #view-chat:not(.room) #chanStrip .chip:has(.chip-badge) .chip-prev { padding-right: 34px; }
  #view-chat:not(.room) #chanStrip #chanNew {
    display: flex !important; align-items: center; justify-content: center;
    min-height: 44px !important;
    margin: 8px 12px 2px !important; width: calc(100% - 24px) !important;
    border-radius: 14px !important;
    background: var(--cm-soft) !important;
    color: var(--cm-text) !important;
    font-weight: 600 !important; font-size: 14px !important;
  }
}
@media (max-width: 899px) {
  #view-chat:not(.room) #chanStrip .chip-prev { font-weight: 400 !important; }
  #view-chat .bubble, #view-chat .msg.mine .bubble { border: 0 !important; outline: 0 !important; }
  #view-chat .bubble .mention, #view-chat .msg.mine .bubble .mention {
    background: var(--cm-accent-soft) !important;
    color: var(--cm-accent-ink) !important;
    border-radius: 6px !important; padding: 0 4px !important; font-weight: 700 !important;
  }
  html[data-theme="dark"] #view-chat .bubble .mention,
  html[data-theme="dark"] #view-chat .msg.mine .bubble .mention { color: #5eead4 !important; }
  #view-chat .win { margin: 2px 0 8px !important; }
  #view-chat .win + .rx { padding-left: 8px !important; margin-bottom: 10px; }
}
@media (min-width: 900px) {
  #chanStrip .chip-prev, #chanStrip .chip-when-added { display: none !important; }
  #view-chat .chan-pic { display: none !important; }
  #view-chat .chan-photo-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: 0; border-radius: 10px;
    background: var(--cm-soft); color: var(--cm-text); cursor: pointer;
  }
  #view-chat .chan-photo-btn[hidden] { display: none; }
  #chanStrip .chip-hash.has-photo {
    color: transparent !important; background-size: cover; background-position: center;
    border-radius: 6px;
  }
}

/* admin channel-photo sheet: earlier photos to go back to (v619, schema-v507) */
#chanPhotoSheet .sheet-head { position: static; margin: -20px -18px 14px; }
#chanPhotoSheet [hidden] { display: none !important; }
#chanPhotoSheet .cp-hist-title { font-size: 13px; font-weight: 600; color: var(--cm-muted); margin: 2px 0 8px; }
#chanPhotoSheet .cp-hist { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 0 14px; }
#chanPhotoSheet .cp-h { position: relative; }
#chanPhotoSheet .cp-hist .cp-pick {
  display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; border: 0; border-radius: 12px;
  background: var(--cm-soft) center / cover no-repeat; cursor: pointer;
}
#chanPhotoSheet .cp-hist .cp-pick.current { outline: 3px solid #00b3bb; outline-offset: 2px; cursor: default; }
#chanPhotoSheet .cp-h:has(.current)::after {
  content: "Current"; position: absolute; left: 4px; right: 4px; bottom: 4px; pointer-events: none;
  font: 700 10px Poppins, system-ui, sans-serif; color: #fff; text-align: center;
  background: rgba(0, 0, 0, .55); border-radius: 6px; padding: 2px 0;
}
#chanPhotoSheet .cp-hist button:disabled { opacity: .5; }
/* delete an old photo: a small x in the corner, "Delete?" once armed */
#chanPhotoSheet .cp-del {
  position: absolute; top: -6px; right: -6px; min-width: 24px; height: 24px; padding: 0 6px;
  border: 2px solid #fff; border-radius: 12px; background: #334155; color: #fff;
  font: 700 14px/1 Poppins, system-ui, sans-serif; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
#chanPhotoSheet .cp-del.armed { background: #dc2626; font-size: 11px; right: -4px; }

/* the press-and-hold card: lifted, rounded, on every screen size */
#msgSheet .sheet {
  border-radius: 22px !important;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .3) !important;
}
#msgSheet .rx-shelf button {
  width: 46px !important; height: 46px !important;
  border-radius: 23px !important;
  background: var(--cm-soft) !important;
}


/* v641 -- Logan, on a reply he sent: "This looks like shit". Two leftovers from
   the bubble days: your own messages were still pushed to the right, and a
   reply quote inside them kept the white text it wore on a teal bubble -- white
   on white, so it showed as a blank block with the message shoved beside it.
   Every message now reads left, and your quotes look like everyone else's. */
.msg.mine .msg-body{text-align:left}
.msg.mine .reply-quote{
  border-left-color:var(--teal);
  background:color-mix(in srgb,var(--teal) 9%,transparent);
  color:inherit;
}
.msg.mine .reply-quote b{color:var(--teal)}
.msg.mine .reply-quote span{color:var(--txt-2)}
