/* ==========================================================================
   Live Chat — kotak masuk dua panel + tab Pesan Otomatis.
   Memakai token dari admin.css; tidak ada warna baru.
   Satu hal yang ditonjolkan: penanda "Hilang dalam N jam" pada tiap pesan (kuning bila < 1 jam).
   Violet hanya dipakai untuk bubble admin, tombol kirim, lencana belum dibaca, dan pilihan aktif.
   Semua yang lain diam: permukaan datar, garis tipis, tanpa bayangan dekoratif.
   ========================================================================== */

/* ---------- halaman ---------- */
.lcw-actions { justify-content: flex-end; }
.lcw-quick { min-width: 0; }

.card.lcw {
  --lcw-list: 340px;
  display: grid; grid-template-columns: var(--lcw-list) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  height: clamp(520px, calc(100dvh - 232px), 920px); overflow: hidden;
}

/* ---------- daftar percakapan ---------- */
.lcw-list { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line-soft); background: var(--s1); }
.lcw-list__head { flex: none; padding: 14px; border-bottom: 1px solid var(--line-soft); }
.lcw-list__head .search { position: relative; }
.lcw-list__body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.lcw-list__body > .gm-alert { flex-wrap: wrap; margin: 12px 12px 0; }
.lcw-list__state .empty { padding: 40px 20px; }
.lcw-rows { display: grid; }
.lcw-more { display: flex; justify-content: center; padding: 14px; }

.lcw-row {
  position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: start; gap: 12px;
  width: 100%; padding: 12px 14px 12px 16px; text-align: left; border-bottom: 1px solid var(--line-soft);
  transition: background 0.15s;
}
.lcw-row::before { content: ""; position: absolute; inset: 10px auto 10px 0; width: 3px; border-radius: 0 3px 3px 0; background: transparent; transition: background 0.15s; }
.lcw-row:hover { background: var(--wash); }
.lcw-row.is-open { background: var(--s2); }
.lcw-row.is-open::before { background: var(--accent); }
.lcw-row:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-line); }
.lcw-row.is-off .lcw-avatar { opacity: 0.5; }
.lcw-row__body { display: grid; gap: 3px; min-width: 0; }
.lcw-row__line { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.lcw-row__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 14px/1.3 var(--f-display); letter-spacing: -0.005em; color: var(--fg-2); }
.lcw-row.is-unread .lcw-row__name, .lcw-row.is-open .lcw-row__name { color: var(--fg); }
.lcw-row.is-unread .lcw-row__name { font-weight: 700; }
.lcw-row__time { flex: none; font-size: 12px; color: var(--dim); white-space: nowrap; }
.lcw-row.is-unread .lcw-row__time { color: var(--accent-hi); }
.lcw-row__sub { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lcw-row__handle { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }
.lcw-row__sub .pill { flex: none; padding: 1px 8px; font-size: 11.5px; }
.lcw-row__prev { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.lcw-row.is-unread .lcw-row__prev { color: var(--fg-2); }
.lcw-row__prev .i { margin-right: 5px; vertical-align: -2px; }
.lcw-row__you { color: var(--dim); }
.lcw-row__typing { color: var(--accent-hi); }
.lcw-badge { flex: none; display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink); font: 700 11.5px/1 var(--f-body); font-style: normal; }
.lcw-wait { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--warn); }

.avatar.lcw-avatar { width: 40px; height: 40px; font-size: 15px; }
.avatar.lcw-avatar--lg { width: 44px; height: 44px; font-size: 17px; }

/* ---------- loading ---------- */
.lcw-skel { display: grid; }
.lcw-skel__row { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.lcw-skel__av { width: 40px; height: 40px; border-radius: 50%; }
.lcw-skel__ln { display: grid; gap: 9px; }
.lcw-skel__ln .skel { height: 12px; }
.lcw-skel__ln .skel:last-child { width: 68%; }
.lcw-skel--thread { display: flex; flex-direction: column; gap: 12px; padding: 20px 18px; }
.lcw-skel__bub { height: 44px; max-width: 78%; border-radius: 16px; align-self: flex-start; }
.lcw-skel__bub.is-r { align-self: flex-end; }

/* ---------- panel chat ---------- */
.lcw-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--c-page); }
.lcw-blank { flex: 1; align-content: center; }
.lcw-thread__in { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.lcw-head { flex: none; display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); background: var(--s1); }
.lcw-back { display: none; flex: none; margin-left: -6px; }
.lcw-head__body { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.lcw-head__id { display: grid; gap: 1px; min-width: 0; flex: 1; }
.lcw-head__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 15px/1.3 var(--f-display); letter-spacing: -0.01em; }
.lcw-head__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; min-width: 0; font-size: 13px; color: var(--muted); }
.lcw-head__pills { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-left: auto; }

.lcw-stage { position: relative; flex: 1; min-height: 0; display: flex; }
.lcw-scroll { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 16px 18px 12px; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.lcw-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0 auto 14px; font-size: 12.5px; color: var(--dim); text-align: center; }
.lcw-older { align-self: center; margin-bottom: 14px; }
.lcw-log__state .empty { padding: 36px 20px; }
.lcw-log { display: flex; flex-direction: column; margin-top: auto; }

.lcw-day { display: flex; align-items: center; gap: 12px; margin: 16px 0 6px; font-size: 12px; color: var(--dim); }
.lcw-day::before, .lcw-day::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.lcw-day:first-child { margin-top: 4px; }

/* ---------- pesan ---------- */
.lcw-msg { display: grid; gap: 4px; max-width: min(560px, 80%); margin-top: 12px; }
.lcw-msg.is-cont { margin-top: 3px; }
.lcw-day + .lcw-msg { margin-top: 8px; }
.lcw-msg.is-user { align-self: flex-start; justify-items: start; }
.lcw-msg.is-admin { align-self: flex-end; justify-items: end; }

.lcw-bubble { display: grid; gap: 8px; min-width: 0; max-width: 100%; padding: 9px 13px; border: 1px solid var(--line-soft); border-radius: 16px; background: var(--s2); color: var(--fg); }
.lcw-msg.is-user .lcw-bubble { border-bottom-left-radius: 6px; }
.lcw-msg.is-admin .lcw-bubble { border-bottom-right-radius: 6px; background: var(--accent-soft); border-color: var(--accent-line); }
.lcw-msg.is-local .lcw-bubble { opacity: 0.7; }
.lcw-msg.is-fail .lcw-bubble { opacity: 1; background: var(--err-bg); border-color: #523030; }
.lcw-who { font-size: 12px; font-weight: 600; color: var(--accent-hi); }
.lcw-msg.is-cont .lcw-who { display: none; }
.lcw-text { margin: 0; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }

.lcw-img { display: block; max-width: min(320px, 100%); min-width: 96px; min-height: 64px; overflow: hidden; border-radius: 11px; background: var(--s3); }
.lcw-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lcw-img.is-broken { display: grid; justify-items: center; align-content: center; gap: 6px; width: 220px; min-height: 120px; padding: 16px; border: 1px dashed var(--line-strong); background: var(--s1); color: var(--muted); font-size: 13px; text-align: center; }
.lcw-img.is-broken small { color: var(--dim); font-size: 12px; }
.lcw-img.is-broken:hover { border-color: var(--accent-line); color: var(--fg-2); }

/* baris keterangan: jam, status kirim, penanda hilang */
.lcw-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-inline: 4px; font-size: 11.5px; line-height: 1.4; color: var(--dim); }
.lcw-msg.is-admin .lcw-meta { justify-content: flex-end; }
.lcw-time { font-variant-numeric: tabular-nums; }
.lcw-status { display: inline-flex; align-items: center; gap: 4px; }
.lcw-status.is-read { color: var(--accent-hi); }
.lcw-status.is-fail { color: var(--err); }
.lcw-exp { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px 1px 8px; border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--muted); font-weight: 500; white-space: nowrap; }
.lcw-exp::before { content: ""; flex: none; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.lcw-exp.is-soon { border-color: transparent; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.lcw-exp.is-soon::before { opacity: 1; }

.lcw-fail { display: grid; gap: 8px; max-width: 100%; padding: 10px 12px; border-radius: var(--r-md); background: var(--err-bg); color: var(--err); }
.lcw-fail__msg { margin: 0; font-size: 13px; line-height: 1.45; }
.lcw-fail__btns { display: flex; flex-wrap: wrap; gap: 6px; }

.lcw-newpill { position: absolute; z-index: 2; left: 50%; bottom: 12px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 14px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 600; box-shadow: var(--shadow-float); }
.lcw-newpill:hover { background: var(--accent-hi); }

.lcw-typing { flex: none; display: flex; align-items: center; gap: 8px; min-height: 28px; padding: 2px 18px 8px; font-size: 12.5px; color: var(--muted); }
.lcw-dots { display: inline-flex; align-items: center; gap: 3px; }
.lcw-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .lcw-dots i { animation: lcw-dot 1.2s infinite ease-in-out; }
  .lcw-dots i:nth-child(2) { animation-delay: 0.16s; }
  .lcw-dots i:nth-child(3) { animation-delay: 0.32s; }
  .lcw-newpill { animation: lcw-rise 0.2s var(--ease); }
}
@keyframes lcw-dot { 0%, 70%, 100% { opacity: 0.35; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }
@keyframes lcw-rise { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- composer ---------- */
.lcw-compose { flex: none; display: grid; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--line-soft); background: var(--s1); }
.lcw-cerr { margin: 0; padding: 8px 12px; border-radius: var(--r-sm); background: var(--err-bg); color: var(--err); font-size: 13px; font-weight: 500; }
.lcw-attach { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--c-black); }
.lcw-attach__img { flex: none; width: 48px; height: 48px; border-radius: var(--r-sm); object-fit: cover; background: var(--s3); }
.lcw-attach__t { display: grid; flex: 1; min-width: 0; }
.lcw-attach__t b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.lcw-compose__row { display: flex; align-items: flex-end; gap: 8px; }
.lcw-tools { position: relative; flex: none; display: flex; align-items: center; gap: 2px; }
.lcw-compose textarea.lcw-input { flex: 1; min-width: 0; min-height: 40px; max-height: 168px; padding: 9px 12px; resize: none; line-height: 1.5; }
.lcw-counter { flex: none; align-self: center; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.lcw-counter.is-over { color: var(--err); font-weight: 600; }
.lcw-send { flex: none; }
.lcw-hint { margin: 0; font-size: 12px; color: var(--dim); }

.lcw-emoji { position: absolute; z-index: 6; left: 0; bottom: calc(100% + 10px); display: grid; gap: 6px; width: 320px; max-width: calc(100vw - 48px); padding: 8px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--s2); box-shadow: var(--shadow-float); }
.lcw-emoji__tabs { display: flex; gap: 4px; }
.lcw-emoji__tab { min-width: 38px; height: 32px; border-radius: var(--r-sm); font-size: 17px; line-height: 1; color: var(--muted); }
.lcw-emoji__tab:hover { background: var(--s3); }
.lcw-emoji__tab[aria-selected="true"] { background: var(--s3); box-shadow: 0 0 0 1px var(--line-strong); }
.lcw-emoji__grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 2px; max-height: 196px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.lcw-emoji__i { height: 34px; border-radius: var(--r-sm); font-size: 20px; line-height: 1; }
.lcw-emoji__i:hover { background: var(--s3); }

/* ---------- penampil gambar ---------- */
dialog.modal.lcw-viewer-dlg { width: min(960px, calc(100vw - 32px)); }
.lcw-viewer { display: grid; place-items: center; padding: 8px; border-radius: var(--r-md); background: var(--c-black); }
.lcw-viewer__img { display: block; max-width: 100%; max-height: min(72dvh, 760px); object-fit: contain; border-radius: var(--r-sm); }

/* ==========================================================================
   Pesan Otomatis
   ========================================================================== */
.lcw-q { display: grid; gap: 16px; min-width: 0; }
.lcw-q__intro { max-width: 72ch; color: var(--muted); }
.lcw-q > .gm-alert { flex-wrap: wrap; margin: 0; }
.lcw-q__state:not(:empty) { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--s1); }
.lcw-q .skel-rows { padding: 18px; }
.lcw-q .skel-rows > .lcw-q__sk { height: 120px; }

.lcw-q__grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.lcw-slots { display: grid; gap: 12px; min-width: 0; }
.lcw-slot { display: grid; gap: 14px; padding: 16px 18px 18px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--s1); }
.lcw-slot__top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.lcw-slot__pos { font: 700 14px var(--f-display); color: var(--fg-2); }
.lcw-slot__tools { display: flex; align-items: center; gap: 14px; }
.lcw-slot__move { display: inline-flex; gap: 2px; }
.lcw-slot__fields { display: grid; gap: 14px; transition: opacity 0.15s; }
.lcw-slot.is-off .lcw-slot__fields { opacity: 0.55; }
.lcw-slot.is-off:focus-within .lcw-slot__fields, .lcw-slot.is-off .lcw-slot__fields:hover { opacity: 1; }
.lcw-slot textarea { min-height: 76px; }
.lcw-slot .field > .btn { justify-self: start; }
.field small.lcw-count { display: block; margin-top: -2px; text-align: right; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.field small.lcw-count.is-over { color: var(--err); font-weight: 600; }

/* pratinjau: meniru kotak pesan di aplikasi desktop */
.lcw-pv { position: sticky; top: 84px; }
.lcw-pv__body { display: grid; gap: 14px; }
.lcw-pv__app { display: grid; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--c-black); }
.lcw-pv__cap { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.lcw-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lcw-chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--muted); font-size: 12.5px; white-space: nowrap; transition: color 0.15s, border-color 0.15s, background 0.15s; }
.lcw-chip:hover { color: var(--fg); border-color: var(--accent); }
.lcw-chip[aria-pressed="true"] { color: var(--accent-hi); border-color: var(--accent-line); background: var(--accent-soft); }
.lcw-pv__none { font-size: 13px; color: var(--dim); }
.lcw-prevbox { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--s1); }
.lcw-prevbox__text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg); }
.lcw-prevbox__hint { margin: 0; font-size: 13px; color: var(--dim); }
.lcw-pv-sw { font-size: 13px; }

.lcw-savebar { position: sticky; bottom: 16px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--s1); box-shadow: var(--shadow-float); transition: border-color 0.15s; }
.lcw-savebar[data-dirty="true"] { border-color: var(--accent-line); }
.lcw-savebar__msg { font-size: 13px; color: var(--muted); }
.lcw-savebar[data-dirty="true"] .lcw-savebar__msg { color: var(--fg-2); }
.lcw-savebar__btns { display: flex; gap: 8px; margin-left: auto; }

/* ---------- layar sempit ---------- */
@media (max-width: 1100px) {
  .lcw-q__grid { grid-template-columns: minmax(0, 1fr); }
  .lcw-pv { position: static; order: -1; }
}
@media (max-width: 960px) {
  .card.lcw { grid-template-columns: minmax(0, 1fr); height: clamp(480px, calc(100dvh - 200px), 900px); }
  .lcw[data-view="list"] .lcw-thread { display: none; }
  .lcw[data-view="thread"] .lcw-list { display: none; }
  .lcw-list { border-right: 0; }
  .lcw-back { display: inline-grid; }
  .lcw-actions { width: 100%; justify-content: space-between; }
  .lcw-msg { max-width: 88%; }
  .lcw-hint { display: none; }
  .lcw-row { min-height: 72px; }
  /* target sentuh minimal 40px */
  .lcw .icon-btn, .lcw-q .icon-btn { width: 40px; height: 40px; }
  .lcw .btn--sm, .lcw-q .btn--sm { min-height: 40px; }
  .lcw-send { min-height: 40px; }
  .lcw-chip { min-height: 40px; }
  .lcw-emoji__tab { min-height: 40px; }
  .lcw-emoji__i { height: 40px; }
  .lcw-emoji { width: min(320px, calc(100vw - 32px)); }
}
@media (max-width: 560px) {
  .lcw-head { padding-inline: 12px; }
  .lcw-head__body { flex-wrap: wrap; row-gap: 6px; }
  .lcw-head__pills { margin-left: 0; justify-content: flex-start; }
  .lcw-scroll { padding-inline: 12px; }
  .lcw-compose { padding-inline: 12px; }
  .lcw-slot { padding: 14px; }
  .lcw-savebar__btns { width: 100%; }
  .lcw-savebar__btns .btn { flex: 1; min-height: 40px; }
}
