/* Live chat (#chat) and its settings (#chatsetup). Classes start cht. Uses the tokens in styles.css :root. */

/* ---------- Top bar: title, Taking chats switch, status pills ---------- */
.chtpage { max-width: 1320px; }
.chtbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.chtbar .pagehead { margin-bottom: 0; min-width: 0; }
.chttake { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 14px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); }
.chttake.on { border-color: var(--blue-btn); background: var(--blue-tint); }
.chttl { display: flex; flex-direction: column; line-height: 1.2; }
.chttl b { font-size: var(--fs-14); color: var(--ink); }
.chttl span { font-size: var(--fs-12); color: var(--muted); }
.chtsw { width: 52px; height: 30px; flex: none; }
.chtsw i { width: 24px; height: 24px; }
.chtsw[aria-checked="true"] i { left: 24px; }
.chtsw:disabled { opacity: 0.6; cursor: progress; }

.chtstat { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 16px; }
.chtpill { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px 0 10px; border-radius: var(--r-pill); background: var(--chip-bg); color: var(--grey-ink); font-size: var(--fs-13); font-weight: 600; }
.chtpill .ic { width: 16px; height: 16px; }
.chtpill a { color: inherit; text-decoration: underline; font-weight: 700; margin-left: 2px; }
.chtpill.good { background: var(--tint-good); color: var(--good); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--good) 25%, transparent); }
.chtpill.amber { background: var(--amber-bg); color: var(--amber); }
.chtpill.red { background: var(--red-bg); color: var(--red); }
.chtpill.blue { background: var(--blue-bg); color: var(--blue); }
.chtpill.off { background: var(--chip-bg); color: var(--muted); }
.chtavs { display: inline-flex; margin-right: 2px; }
.chtavs .av { width: 20px; height: 20px; font-size: 0.625rem; border: 2px solid var(--blue-bg); margin-left: -6px; }
.chtavs .av:first-child { margin-left: 0; }

/* ---------- Two panes ---------- */
.chtwrap { display: grid; grid-template-columns: 320px minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); overflow: hidden; min-height: 460px; }
.chtwrap > .card.skel { margin: 12px; }
.chtlist { border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; background: var(--surface2); min-height: 0; }
.chtpane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* List groups */
.chtgrp + .chtgrp { border-top: 1px solid var(--divider); }
.chtgh { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 14px 6px; font-size: var(--fs-12); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.chtgh .n { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--chip-bg); color: var(--grey-ink); font-size: var(--fs-12); letter-spacing: 0; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
#chtg-wait .n:not(:empty) { background: var(--red-bg); color: var(--red); }
.chtgd { width: 8px; height: 8px; border-radius: 50%; background: #9AA8A1; flex: none; }
.chtgd.red { background: var(--red); } .chtgd.blue { background: var(--blue-btn); } .chtgd.amber { background: var(--amber-bar); }
.chtfold { display: flex; align-items: center; gap: 8px; width: 100%; padding: 0; border: 0; background: none; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; min-height: 28px; }
.chtfold .ic { width: 16px; height: 16px; transition: transform 0.15s; }
.chtfold[aria-expanded="true"] .ic { transform: rotate(180deg); }
.chtnone { margin: 0; padding: 2px 14px 12px; font-size: var(--fs-13); color: var(--muted); }
.chtrows { padding: 0 6px 8px; display: flex; flex-direction: column; gap: 2px; }

.chtrow { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 10px 10px; border-radius: var(--r-ctl); color: var(--ink); text-decoration: none; border: 1px solid transparent; }
.chtrow:hover { background: var(--surface); border-color: var(--divider); }
.chtrow.sel { background: var(--surface); border-color: var(--blue-btn); box-shadow: inset 3px 0 0 var(--blue-btn); }
.chtrow.k-wait { background: var(--tint-red); }
.chtrow.k-wait.sel { background: var(--surface); }
.chtav { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: var(--fs-13); font-weight: 700; background: var(--chip-bg); color: var(--grey-ink); }
.chtav.k-wait { background: var(--red-bg); color: var(--red); }
.chtav.k-mine { background: var(--blue-bg); color: var(--blue); }
.chtav.k-msg { background: var(--amber-bg); color: var(--amber); }
.chtav.lg { width: 44px; height: 44px; font-size: var(--fs-16); }
.chtmain { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.chttop { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.chttop b { font-size: var(--fs-14); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.chtrow.un .chttop b { color: var(--ink); }
.chtago { font-size: var(--fs-12); color: var(--muted); white-space: nowrap; flex: none; }
.chtwait { font-size: var(--fs-12); font-weight: 700; color: var(--red); white-space: nowrap; flex: none; font-variant-numeric: tabular-nums; }
.chtline { font-size: var(--fs-13); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chtrow.un .chtline { color: var(--grey-ink); font-weight: 600; }
.chtmeta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chtpath, .chtflag, .chtlead, .chtleft, .chtwho { display: inline-flex; align-items: center; gap: 4px; min-height: 20px; max-width: 100%; padding: 0 7px; border-radius: 6px; font-size: var(--fs-12); font-weight: 600; background: var(--chip-bg); color: var(--grey-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chtpath { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500; letter-spacing: -0.01em; }
.chtflag { background: var(--red-bg); color: var(--red); }
.chtflag.over { background: var(--amber-bg); color: var(--amber); }
.chtlead { background: var(--tint-good); color: var(--good); }
.chtleft { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.chtwho { padding-left: 2px; background: transparent; box-shadow: inset 0 0 0 1px var(--line); border-radius: var(--r-pill); }
.chtwho .av { width: 18px; height: 18px; font-size: 0.5625rem; }
.chtwho.none { padding-left: 8px; color: var(--muted); font-weight: 500; }
.chtdot { position: absolute; top: 14px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue-btn); box-shadow: 0 0 0 2px var(--surface); }
.chtrow.un .chttop { padding-right: 14px; }

/* ---------- Empty pane ---------- */
.chtempty { align-items: center; justify-content: center; text-align: center; padding: 32px 24px; gap: 8px; }
.chtempty h2 { font-size: var(--fs-20); font-weight: 700; color: var(--ink); margin: 6px 0 0; }
.chtempty p { max-width: 380px; margin: 0; }
.chtbig { width: 88px; height: 88px; border-radius: 50%; background: var(--blue-bg); color: var(--blue); display: grid; place-items: center; }
.chtbig .ic { width: 40px; height: 40px; }
.chtnudge { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px !important; padding: 10px 12px; border-radius: var(--r-ctl); background: var(--amber-bg); color: var(--amber); font-size: var(--fs-13); text-align: left; }
.chtnudge .ic { width: 18px; height: 18px; flex: none; }

/* ---------- Conversation ---------- */
.chthead { padding: 14px 18px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.chtback { display: none; align-items: center; gap: 4px; color: var(--link); font-weight: 600; text-decoration: none; min-height: 36px; align-self: flex-start; font-size: var(--fs-14); }
.chtback .ic { width: 18px; height: 18px; }
.chthid { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chthn { min-width: 0; flex: 1; }
.chthn h2 { margin: 0; font-size: var(--fs-20); font-weight: 700; color: var(--ink); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chthc { display: flex; align-items: center; gap: 4px; margin-top: 2px; min-width: 0; font-size: var(--fs-14); }
.chtcon { display: inline-flex; align-items: center; gap: 6px; color: var(--link); font-weight: 600; text-decoration: none; min-width: 0; }
.chtcon span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chtcon:hover span { text-decoration: underline; }
.chtcon .ic { width: 16px; height: 16px; flex: none; }
.chticon { width: 32px; height: 32px; flex: none; display: inline-grid; place-items: center; border: 0; border-radius: var(--r-tight); background: transparent; color: var(--muted); cursor: pointer; }
.chticon:hover { background: var(--chip-bg); color: var(--ink); }
.chticon .ic { width: 16px; height: 16px; }
.chtstate { flex: none; display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: var(--r-pill); font-size: var(--fs-12); font-weight: 700; background: var(--chip-bg); color: var(--grey-ink); }
.chtstate.red { background: var(--red-bg); color: var(--red); }
.chtstate.blue { background: var(--blue-bg); color: var(--blue); }
.chtstate.amber { background: var(--amber-bg); color: var(--amber); }
.chtfacts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chtfact { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-13); color: var(--muted); }
.chtfact .ic { width: 14px; height: 14px; }
.chtfacts .chtwho { min-height: 24px; font-size: var(--fs-13); }
.chtfacts .chtwho .av { width: 20px; height: 20px; }
.chtacts { display: flex; flex-wrap: wrap; gap: 8px; }
.chtacts .btn { min-height: 36px; padding: 0 14px; }
.chtacts .btn .ic { width: 16px; height: 16px; }
.chtleadbtn { border-color: color-mix(in srgb, var(--good) 35%, var(--line)); color: var(--good); background: var(--tint-good); }
.chtendb { margin-left: auto; color: var(--red); }
.chtendb:hover { background: var(--red-bg); border-color: var(--red-bg); }
.chtconfirm { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-ctl); background: var(--red-bg); color: var(--red); font-size: var(--fs-14); font-weight: 600; }
.chtconfirm span { flex: 1 1 200px; }
.chtendyes { background: var(--red); border-color: var(--red); color: var(--surface); min-height: 36px; }
.chtendyes:hover { background: var(--red); opacity: 0.9; }

/* Lead form */
.chtlf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface2); }
.chtlf h3 { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-15); font-weight: 700; color: var(--ink); }
.chtlf h3 .ic { width: 18px; height: 18px; color: var(--good); }
.chtlf .wide { grid-column: 1 / -1; }
.chtlf .fld input[type="tel"] { width: 100%; min-height: 44px; border: 1px solid var(--input-strong); border-radius: var(--r-ctl); background: var(--surface); padding: 0 12px; color: var(--ink); font: inherit; }
.chtlf .hint { margin: 0; }
.chtlf .formact .ic { width: 16px; height: 16px; }

.chtnote { display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 18px; font-size: var(--fs-13); color: var(--grey-ink); background: var(--surface2); border-bottom: 1px solid var(--divider); }
.chtnote .ic { width: 16px; height: 16px; flex: none; }
.chtnote.amber { background: var(--amber-bg); color: var(--amber); }

/* Messages */
.chtmsgs { flex: 1; min-height: 120px; overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 10px; background: var(--ground); }
.chtmsgs:focus-visible { outline-offset: -2px; }
.chtload { margin: auto; color: var(--muted); font-size: var(--fs-14); }
.chtday { display: flex; align-items: center; gap: 10px; margin: 4px 0; font-size: var(--fs-12); font-weight: 600; color: var(--muted); }
.chtday::before, .chtday::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.chtsys { align-self: center; max-width: 80%; margin: 0; padding: 4px 12px; border-radius: var(--r-pill); background: var(--chip-bg); color: var(--muted); font-size: var(--fs-12); text-align: center; }
.chtsys time { opacity: 0.8; margin-left: 4px; }
.chtb { display: flex; flex-direction: column; gap: 3px; max-width: min(78%, 560px); }
.chtb.vis { align-self: flex-start; }
.chtb.staff { align-self: flex-end; align-items: flex-end; }
.chtbm { font-size: var(--fs-12); font-weight: 600; color: var(--grey-ink); padding: 0 4px; }
.chtbm time { font-weight: 500; color: var(--muted); margin-left: 4px; }
.chtbody { padding: 9px 13px; border-radius: 16px; font-size: var(--fs-15); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.chtb.vis .chtbody { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chtb.staff .chtbody { background: var(--blue-btn); color: var(--on-accent); border-bottom-right-radius: 5px; }

/* Reply box */
.chtcompose { border-top: 1px solid var(--line); padding: 10px 14px 12px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.chtquick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chtquick::-webkit-scrollbar { display: none; }
.chtq { flex: none; min-height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--blue-ink); font: inherit; font-size: var(--fs-13); font-weight: 600; cursor: pointer; white-space: nowrap; }
.chtq:hover { background: var(--blue-tint); border-color: var(--blue-tint); }
.chtin { display: flex; gap: 8px; align-items: flex-end; }
.chtin textarea { flex: 1; min-width: 0; min-height: 48px; max-height: 160px; resize: vertical; padding: 11px 12px; border: 1px solid var(--input-strong); border-radius: var(--r-ctl); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-15); line-height: 1.45; }
.chtsendb { min-height: 48px; flex: none; }
.chtsendb .ic { width: 18px; height: 18px; }
.chtcompose .hint { margin: 0; }
.chtended { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface2); color: var(--grey-ink); font-size: var(--fs-14); }
.chtended .ic { width: 18px; height: 18px; flex: none; color: var(--muted); }

/* ---------- Settings (#chatsetup) ---------- */
.chtset { max-width: 860px; }
.chtset .card + .card { margin-top: 16px; }
.chtonrow { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface2); }
.chtonrow.on { border-color: var(--good); background: var(--tint-good); }
.chtonic { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--chip-bg); color: var(--grey-ink); }
.chtonrow.on .chtonic { background: var(--good); color: var(--surface); }
.chtonic .ic { width: 22px; height: 22px; }
.chtont { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chtont b { font-size: var(--fs-16); color: var(--ink); }
.chtont span { font-size: var(--fs-13); color: var(--muted); }
.chtonrow.on .chtont span { color: var(--good); }
.chtonrow .chtsw { width: 60px; height: 34px; }
.chtonrow .chtsw i { width: 28px; height: 28px; }
.chtonrow .chtsw[aria-checked="true"] { background: var(--good); border-color: var(--good); }
.chtonrow .chtsw[aria-checked="true"] i { left: 28px; }
.chtsetgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.chtsetgrid .wide { grid-column: 1 / -1; }
.chtsecs { display: flex; align-items: center; gap: 8px; }
.chtsecs input { width: 120px !important; }
.chtsecs span { color: var(--muted); font-size: var(--fs-14); }
#chts-orig { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--fs-13); }
.chtsaved { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-13); color: var(--muted); }
.chtsaved .ic { width: 16px; height: 16px; }
.chtsaved.un { color: var(--amber); font-weight: 600; }

.chttiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.chttile { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--r-sm); background: var(--chip-bg); color: var(--grey-ink); }
.chttile .ic { grid-row: 1 / 3; width: 24px; height: 24px; }
.chttile b { font-size: var(--fs-20); line-height: 1.1; }
.chttile span { font-size: var(--fs-12); font-weight: 600; opacity: 0.9; }
.chttile.good { background: var(--tint-good); color: var(--good); }
.chttile.amber { background: var(--amber-bg); color: var(--amber); }
.chttile.red { background: var(--red-bg); color: var(--red); }
.chttile.blue { background: var(--blue-bg); color: var(--blue); }
.chttile.off { color: var(--muted); }
.chtagents { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chtagents li { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: var(--r-pill); font-size: var(--fs-14); font-weight: 600; }

.chtcode { display: flex; align-items: center; gap: 10px; margin: 12px 0 16px; padding: 10px 10px 10px 14px; border-radius: var(--r-ctl); background: #1E2420; color: #E8EEEA; }
.chtcode .btn { color: #16231D; background: #FFFFFF; border-color: #FFFFFF; }
.chtcode .btn:hover { background: #E8EEEA; }
.chtcode code { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--fs-13); overflow-wrap: anywhere; user-select: all; }
.chtcode .btn { flex: none; }
.chtsteps { list-style: none; counter-reset: cht; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.chtsteps li { counter-increment: cht; position: relative; padding-left: 42px; display: flex; flex-direction: column; gap: 2px; min-height: 30px; }
.chtsteps li::before { content: counter(cht); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--blue-bg); color: var(--blue); font-weight: 700; font-size: var(--fs-14); display: grid; place-items: center; }
.chtsteps b { font-size: var(--fs-15); color: var(--ink); }
.chtsteps span { font-size: var(--fs-14); color: var(--muted); line-height: 1.45; }
.chtprevrow { display: flex; align-items: center; gap: 14px; }
.chtprevrow > div { flex: 1; min-width: 0; }
.chtprevrow .sechead { margin-bottom: 2px; }
.chtprevrow .chtonic { background: var(--blue-bg); color: var(--blue); }

/* ---------- Phones: the list, then the conversation as its own screen ---------- */
@media (max-width: 899px) {
  .chtbar { align-items: stretch; }
  .chttake { width: 100%; justify-content: space-between; border-radius: var(--r-sm); }
  .chtstat { margin: 12px 0; gap: 6px; }
  .chtpill { font-size: var(--fs-12); min-height: 28px; }
  .chtwrap { display: block; min-height: 0; }
  .chtlist { border-right: 0; background: var(--surface); }
  .chtpage:not(.has-sel) .chtpane { display: none; }
  .chtpage.has-sel .chtbar, .chtpage.has-sel .chtstat, .chtpage.has-sel .chtlist { display: none; }
  .chtpage.has-sel .chtwrap { display: flex; flex-direction: column; margin: -12px -16px 0; border-radius: 0; border-left: 0; border-right: 0; }
  .chtpage.has-sel .chtpane { flex: 1; min-height: 0; }
  .chtrow { padding: 12px 10px; }
  .chtback { display: inline-flex; }
  .chthead { padding: 6px 14px 12px; }
  .chthn h2 { font-size: var(--fs-16); }
  .chtendb { margin-left: 0; }
  .chtacts .btn { flex: 1 1 auto; }
  .chtlf { grid-template-columns: minmax(0, 1fr); }
  .chtmsgs { padding: 12px; }
  .chtb { max-width: 86%; }
  .chtcompose { padding: 8px 10px 10px; }
  .chtsetgrid { grid-template-columns: minmax(0, 1fr); }
  .chttiles { grid-template-columns: minmax(0, 1fr); }
  .chtcode { flex-direction: column; align-items: stretch; }
  .chtprevrow { flex-wrap: wrap; }
  .chtprevrow .btn { width: 100%; }
  .chtonrow { padding: 12px; gap: 10px; }
  .chtonrow .chtonic { display: none; }
}
