/* =====================================================================
   Internal chat + attach-picker styles — extracted from styles.css.
   Linked after styles.css, so it inherits every :root custom property.
   ===================================================================== */
/* ==================== Internal chat ==================== */
.chat-fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 45;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.34), 0 2px 6px rgba(0,0,0,.2);
  transition: transform .15s ease, background .15s ease;
}
.chat-fab:hover { background: var(--brand-2); }
.chat-fab:active { transform: scale(.94); }
.chat-fab.hidden { display: none; }
.chat-fab-badge {
  position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; border: 2px solid var(--bg);
  font-size: 12px; font-weight: 800; display: grid; place-items: center;
}
.chat-fab-badge.hidden { display: none; }

.chat-panel {
  position: fixed; z-index: 46; display: flex; flex-direction: column; overflow: hidden;
  overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
  inset: 62px 8px calc(84px + env(safe-area-inset-bottom)) 8px; /* mobile: fill */
}
.chat-panel.hidden { display: none; }
/* While the chat panel is open, lock the page behind it so scrolling the
   conversation never bleeds through to the page underneath (scroll chaining). */
body.chat-open { overflow: hidden; overscroll-behavior: none; }
@media (min-width: 560px) {
  .chat-panel { inset: auto 18px calc(84px + env(safe-area-inset-bottom)) auto; width: 374px; height: min(576px, 74vh); }
}
.chat-head {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 0 10px;
  min-height: 58px; background: var(--brand); color: #fff;
}
.chat-head > * { align-self: center; }
.chat-head .chat-title { font-weight: 800; font-size: 15px; line-height: 1.1; }
.chat-head .chat-sub { font-size: 11.5px; opacity: .9; margin-top: 2px; }
.chat-head-main { flex: 1; min-width: 0; }
.chat-head-main .chat-title, .chat-head-main .chat-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Solid white badges with brand-coloured icons so they stand out on the orange
   header (the translucent version blended in). Flex-centred so the glyph sits
   dead-centre. */
.chat-back, .chat-close {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer; padding: 0;
  background: #fff; color: var(--brand); font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .14);
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.chat-back svg, .chat-close svg { display: block; }
.chat-back:hover, .chat-close:hover { background: #fdeede; box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.chat-back:active, .chat-close:active { transform: scale(.94); }
.chat-back.hidden { display: none; }
.chat-head-actions { display: flex; gap: 6px; }
.chat-head-actions a {
  width: 34px; height: 34px; border-radius: 50%; background: #fff; color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 15px; text-decoration: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .22);
}
.chat-head-actions a.wa { color: #25d366; }
.chat-head-actions a:hover { background: #fdeede; }

.chat-listview, .chat-threadview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-listview.hidden, .chat-threadview.hidden { display: none; }
.chat-contacts { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 6px; }
.chat-contact {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 11px; cursor: pointer;
}
.chat-contact:hover { background: var(--card-2); }
.chat-avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #fff; background: var(--brand);
}
.chat-avatar.team { background: #2d7d5a; }
.chat-ci { flex: 1; min-width: 0; }
.chat-ci .nm { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.chat-ci .nm .role { font-size: 10.5px; font-weight: 700; color: var(--muted); background: var(--card-2); padding: 1px 6px; border-radius: 999px; }
.chat-ci .pv { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.chat-cr { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.chat-cr .tm { font-size: 10.5px; color: var(--muted); }
.chat-unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.chat-phones { display: flex; gap: 6px; }
.chat-phones a { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; text-decoration: none; border: 1px solid var(--line); }
.chat-phones a.call { color: var(--brand); }
.chat-phones a.wa { color: #25d366; }
.chat-phones a:hover { background: var(--card-2); }
.chat-section-lbl { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }

.chat-messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.35; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .who { font-size: 11px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.msg .tm { font-size: 10px; opacity: .7; margin-top: 3px; text-align: right; }
.msg.them { align-self: flex-start; background: var(--card-2); color: var(--text); border-bottom-left-radius: 5px; }
/* Sender bubbles: soft mint (a green tint of the card) instead of loud orange —
   calmer, readable in both themes, and clearly distinct from received bubbles. */
.msg.mine {
  align-self: flex-end;
  background: color-mix(in srgb, var(--ok) 24%, var(--card));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--ok) 36%, var(--line));
  border-bottom-right-radius: 5px;
}
.msg.mine .tm { color: var(--muted); }
.chat-daysep { align-self: center; font-size: 11px; color: var(--muted); background: var(--card-2); padding: 3px 10px; border-radius: 999px; margin: 4px 0; }
.chat-empty { margin: auto; color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }

.chat-inputrow { flex: none; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-input { flex: 1; min-width: 0; padding: 11px 14px; border: 1px solid var(--line); border-radius: 22px; background: var(--bg-2); color: var(--text); font-size: 14px; }
.chat-input:focus { outline: none; border-color: var(--brand); }
.chat-send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--brand); color: #fff; font-size: 17px; cursor: pointer; display: grid; place-items: center; }
.chat-send:hover { background: var(--brand-2); }
.chat-send:active { transform: scale(.94); }

/* ---- Chat: node-photo attachments ---- */
.chat-attach-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; padding: 0; cursor: pointer;
  background: color-mix(in srgb, var(--brand) 14%, var(--card));
  color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 42%, var(--line));
  display: flex; align-items: center; justify-content: center;
}
.chat-attach-btn svg { display: block; }
.chat-attach-btn:hover { background: color-mix(in srgb, var(--brand) 22%, var(--card)); }
.chat-attach-btn:active { transform: scale(.94); }
.chat-attach-strip { flex: none; display: flex; gap: 8px; padding: 8px 10px 0; overflow-x: auto; }
.chat-attach-strip.hidden { display: none; }
.chat-att-thumb { position: relative; flex: none; width: 56px; height: 56px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line); }
.chat-att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-att-thumb .rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid var(--card); font-size: 11px; display: grid; place-items: center; cursor: pointer; }
.chat-att-thumb .nd { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 9px; text-align: center; padding: 1px; }

.chat-picker { position: absolute; inset: 0; z-index: 3; background: var(--card); display: flex; flex-direction: column; }
.chat-picker.hidden { display: none; }
.chat-picker-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 56px; background: var(--brand); color: #fff; }
.chat-picker-title { font-weight: 800; font-size: 15px; }
.chat-picker-controls { flex: none; padding: 10px 12px 6px; }
.chat-picker-controls select { width: 100%; padding: 11px 38px 11px 12px; border: 1px solid var(--line); border-radius: 10px; background-color: var(--bg-2); color: var(--text); font-size: 14px; }
.chat-picker-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-content: start; }
.chat-pick { position: relative; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--bg-2); }
.chat-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-pick .meta { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 9.5px; padding: 2px 4px; }
.chat-pick.sel { border-color: var(--brand); }
.chat-pick.sel::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.chat-picker-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }

/* Referenced photo(s) inside a message bubble — quote-style block */
.msg-attach { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.msg-att {
  display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; cursor: pointer;
  background: rgba(0,0,0,.10); border-left: 3px solid var(--ok);
}
.msg.them .msg-att { background: var(--bg-2); border-left-color: var(--brand); }
.msg.mine .msg-att { background: color-mix(in srgb, var(--ok) 12%, var(--card)); border-left-color: var(--ok); }
.msg-att img { width: 46px; height: 46px; border-radius: 7px; object-fit: cover; flex: none; }
.msg-att .ai { min-width: 0; }
.msg-att .ai .an { font-weight: 800; font-size: 12.5px; }
.msg-att .ai .at { font-size: 11px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat: take a new photo from camera */
/* Soft-tinted button so it separates from the solid-orange picker header
   instead of merging into it. */
.chat-cam-btn {
  width: 100%; padding: 12px; border-radius: 10px; cursor: pointer;
  background: color-mix(in srgb, var(--brand) 15%, var(--card));
  color: var(--brand); border: 1.5px solid var(--brand);
  font-size: 14px; font-weight: 800;
}
.chat-cam-btn:hover { background: color-mix(in srgb, var(--brand) 24%, var(--card)); }
.chat-cam-btn:active { transform: scale(.99); }
.chat-or { text-align: center; font-size: 11.5px; color: var(--muted); margin: 12px 0 8px; }
/* subtle divider under the picker header so it reads as its own bar */
.chat-picker-head { box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
