/* iMessage, as closely as a web app gets.

   Two layouts from one document: a fixed sidebar + conversation on the Mac,
   and a push-navigation stack on the phone, exactly as Messages behaves on
   macOS and iOS. The breakpoint is 820px — below it a sidebar would leave the
   transcript too narrow to read. */
:root{
  --blue:#0b84ff; --blue-press:#0a6fd8;
  --bg:#fff; --sidebar:#f7f7f7; --sidebar-sel:#dcdcdd;
  --ink:#000; --mut:#8a8a8e; --line:#e0e0e2;
  --in-bg:#e9e9eb; --in-ink:#000;
  --hair:0.5px solid var(--line);
  --sb-w:320px;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#1e1e1e; --sidebar:#232323; --sidebar-sel:#3a3a3c;
    --ink:#fff; --mut:#98989d; --line:#38383a;
    --in-bg:#3b3b3d; --in-ink:#fff;
  }
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{
  margin:0;background:var(--bg);color:var(--ink);overflow:hidden;
  font:15px/1.35 -apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,sans-serif;
  -webkit-font-smoothing:antialiased;
}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}

/* ---------- shell ---------- */
#shell{display:flex;height:100dvh;overflow:hidden}
#sidebar{
  width:var(--sb-w);flex:0 0 var(--sb-w);background:var(--sidebar);
  border-right:var(--hair);display:flex;flex-direction:column;overflow:hidden;
}
#pane{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0}

/* ---------- sidebar ---------- */
.sb-top{
  padding:calc(env(safe-area-inset-top) + 10px) 12px 8px;display:flex;align-items:center;gap:8px;
}
.sb-top h1{font-size:22px;font-weight:700;margin:0;flex:1;letter-spacing:-.02em}
.search{
  margin:0 12px 8px;background:rgba(120,120,128,.12);border-radius:9px;
  display:flex;align-items:center;gap:6px;padding:6px 8px;color:var(--mut);
}
.search input{
  border:0;background:transparent;outline:none;color:var(--ink);font:inherit;width:100%;
}
#list{overflow-y:auto;flex:1;-webkit-overflow-scrolling:touch}
.conv{
  display:flex;gap:10px;padding:9px 12px;cursor:pointer;position:relative;align-items:flex-start;
}
.conv.sel{background:var(--sidebar-sel);border-radius:9px;margin:0 6px;padding:9px 8px}
.conv + .conv::before{
  content:"";position:absolute;left:56px;right:12px;top:0;border-top:var(--hair);
}
.conv.sel::before,.conv.sel + .conv::before{border-top:0}
.avatar{
  width:40px;height:40px;border-radius:50%;flex:0 0 40px;display:grid;place-items:center;
  background:linear-gradient(180deg,#b6b6bb,#8e8e93);color:#fff;font-weight:600;font-size:15px;
}
.avatar.live{background:linear-gradient(180deg,#43d669,#25a848)}
.avatar.flag{background:linear-gradient(180deg,#ff6961,#d7372c)}
.conv-main{min-width:0;flex:1}
.conv-row{display:flex;align-items:baseline;gap:6px}
.conv-name{font-weight:600;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1}
.conv-time{font-size:12px;color:var(--mut);flex:0 0 auto}
.conv-sub{
  font-size:13px;color:var(--mut);margin-top:1px;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.unread{width:9px;height:9px;border-radius:50%;background:var(--blue);flex:0 0 auto;align-self:center}
.taken{font-size:11px;color:var(--blue);font-weight:600}

/* ---------- conversation ---------- */
.pane-top{
  display:flex;align-items:center;gap:8px;padding:calc(env(safe-area-inset-top) + 8px) 14px 8px;
  border-bottom:var(--hair);background:color-mix(in srgb,var(--bg) 82%,transparent);
  backdrop-filter:saturate(180%) blur(20px);-webkit-backdrop-filter:saturate(180%) blur(20px);
  position:sticky;top:0;z-index:3;min-height:52px;
}
.pane-title{flex:1;min-width:0}
.pane-title b{display:block;font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pane-title span{display:block;font-size:12px;color:var(--mut);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.back{display:none;font-size:26px;line-height:1;color:var(--blue);padding:0 4px 3px}
.takeover{
  font-size:13px;font-weight:600;color:#fff;background:var(--blue);
  border-radius:999px;padding:6px 12px;white-space:nowrap;
}
.takeover.on{background:transparent;color:var(--blue);border:1px solid var(--blue)}
#thread{flex:1;overflow-y:auto;padding:12px 14px 4px;-webkit-overflow-scrolling:touch}
.day{text-align:center;color:var(--mut);font-size:11px;font-weight:600;margin:14px 0 8px}

/* Bubbles. Tail via a masked pseudo-element, the way Messages draws them. */
.b{max-width:min(64ch,72%);margin:2px 0;padding:7px 12px;border-radius:18px;position:relative;
   white-space:pre-wrap;word-wrap:break-word;line-height:1.3;clear:both}
.b.them{background:var(--in-bg);color:var(--in-ink);float:left;border-bottom-left-radius:5px}
.b.me{background:var(--blue);color:#fff;float:right;border-bottom-right-radius:5px}
.b.bot{background:var(--in-bg);color:var(--in-ink);float:right;border-bottom-right-radius:5px;opacity:.92}
.b.sys{float:none;margin:10px auto;background:transparent;color:var(--mut);font-size:12px;text-align:center;max-width:80%}
.grp{overflow:hidden}
.stamp{clear:both;text-align:center;color:var(--mut);font-size:11px;margin:8px 0 2px}
.who{font-size:11px;color:var(--mut);margin:0 4px 2px;clear:both}
.who.me{text-align:right}

/* composer */
.composer{
  border-top:var(--hair);padding:8px 12px calc(env(safe-area-inset-bottom) + 8px);
  display:flex;gap:8px;align-items:flex-end;background:var(--bg);
}
.composer textarea{
  flex:1;resize:none;border:1px solid var(--line);border-radius:18px;padding:7px 12px;
  font:inherit;background:var(--bg);color:var(--ink);max-height:120px;min-height:34px;outline:none;
}
.composer textarea:focus{border-color:#c7c7cc}
.send{
  width:30px;height:30px;border-radius:50%;background:var(--blue);color:#fff;
  display:grid;place-items:center;font-size:16px;flex:0 0 30px;margin-bottom:2px;
}
.send:disabled{background:#c7c7cc}
.empty{margin:auto;color:var(--mut);text-align:center;padding:40px}

/* ---------- phone: push navigation, like Messages on iOS ---------- */
@media (max-width:820px){
  :root{--sb-w:100%}
  #shell.show-thread #sidebar{display:none}
  #shell:not(.show-thread) #pane{display:none}
  #sidebar{border-right:0}
  .back{display:block}
  .conv.sel{background:transparent;margin:0;padding:9px 12px}
  .b{max-width:78%}
}

/* ---------- composer actions + picker ---------- */
.tools{display:flex;gap:2px;align-items:center;margin-bottom:2px}
.tool{
  width:30px;height:30px;border-radius:50%;display:grid;place-items:center;
  color:var(--mut);font-size:17px;flex:0 0 30px;
}
.tool:hover{background:rgba(120,120,128,.14);color:var(--blue)}
.tool:disabled{opacity:.4}
.tool.on{background:var(--blue);color:#fff}

.sheet-back{position:fixed;inset:0;background:rgba(0,0,0,.28);z-index:20;display:flex;align-items:flex-end;justify-content:center}
@media (min-width:821px){.sheet-back{align-items:center}}
.sheet{
  background:var(--bg);width:min(560px,100%);max-height:min(70dvh,560px);
  border-radius:14px 14px 0 0;display:flex;flex-direction:column;overflow:hidden;
  box-shadow:0 18px 60px rgba(0,0,0,.3);
}
@media (min-width:821px){.sheet{border-radius:14px}}
.sheet-top{padding:12px 14px 8px;border-bottom:var(--hair);display:flex;align-items:center;gap:10px}
.sheet-top b{flex:1;font-size:15px}
.sheet-top .cancel{color:var(--blue);font-size:15px}
.sheet input.find{
  margin:10px 14px;background:rgba(120,120,128,.12);border:0;border-radius:9px;
  padding:9px 11px;font:inherit;color:var(--ink);outline:none;
}
.results{overflow-y:auto;padding:0 6px 10px}
.res{display:flex;align-items:center;gap:10px;padding:9px 8px;border-radius:9px;cursor:pointer}
.res:hover{background:rgba(120,120,128,.14)}
.res img{width:34px;height:34px;border-radius:6px;object-fit:contain;background:#fff;flex:0 0 34px}
.res .ph{width:34px;height:34px;border-radius:6px;display:grid;place-items:center;background:rgba(120,120,128,.16);font-size:15px;flex:0 0 34px}
.res-main{min-width:0;flex:1}
.res-main b{display:block;font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.res-main span{display:block;font-size:12px;color:var(--mut);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.b a{color:inherit;text-decoration:underline;text-underline-offset:2px}
.b.them a,.b.bot a{color:var(--blue)}

/* ---------- installed-app window chrome ----------

   macOS "Add to Dock" web apps lay a draggable title-bar strip across the top
   of the page. Anything inside roughly the first 30px receives window drags
   instead of clicks — which is why the bell and the gear did nothing in the
   Dock app while everything further down worked normally. Clear the strip, and
   mark the controls no-drag so they stay clickable either way.

   Scoped to wide standalone windows: on the phone the app is narrower than the
   breakpoint, and there the OS status bar is already handled by
   safe-area-inset, so it must not gain a second gap.

   Confirmed in the Dock app: the "Messages" heading rendered underneath the
   close/minimise/zoom buttons, so the page really does start at y=0 behind the
   chrome. 40px clears a standard macOS title bar with room to spare. */
@media (display-mode: standalone) and (min-width: 821px){
  .sb-top{padding-top:calc(env(safe-area-inset-top) + 40px)}
  .pane-top{padding-top:calc(env(safe-area-inset-top) + 40px)}
}
.sb-top button,.pane-top button{-webkit-app-region:no-drag}

/* ---------- settings sheet ---------- */
/* 30px square minimum: these were 23x25, which is below the comfortable target
   size on any pointer and unforgiving of a near miss. */
#gearBtn{
  font-size:17px;line-height:1;border-radius:7px;color:var(--mut);
  width:30px;height:30px;display:grid;place-items:center;flex:0 0 30px;
}
#gearBtn:hover{background:rgba(120,120,128,.14);color:var(--blue)}
.set{padding:4px 14px 16px}
.set-sec{
  font-size:12px;font-weight:600;color:var(--mut);text-transform:uppercase;
  letter-spacing:.04em;margin:16px 0 7px;
}
.set-sec:first-child{margin-top:8px}
.set-row{display:flex;gap:8px;align-items:center}
.fld{
  flex:1;min-width:0;background:rgba(120,120,128,.12);border:0;border-radius:9px;
  padding:9px 11px;font:inherit;color:var(--ink);outline:none;
}
.fld:focus{box-shadow:0 0 0 2px var(--blue) inset}
.mini{
  font-size:13px;font-weight:600;color:#fff;background:var(--blue);
  border-radius:999px;padding:7px 13px;white-space:nowrap;flex:0 0 auto;
}
.mini:disabled{background:#c7c7cc}
.mini.danger{background:transparent;color:#d7372c;padding:7px 4px}
.set-note{font-size:12px;color:var(--mut);margin-top:6px;line-height:1.4}
.set-msg{font-size:13px;margin-top:8px;min-height:1em}
.set-msg.good{color:#25a848}
.set-msg.bad{color:#d7372c}
.code{
  flex:1;font:600 20px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.12em;
  background:rgba(120,120,128,.12);border-radius:9px;padding:11px;text-align:center;
}
.code[data-left]::after{
  content:" " attr(data-left);font-size:12px;letter-spacing:0;color:var(--mut);font-weight:400;
}
.dev{display:flex;align-items:center;gap:10px;padding:9px 0;border-top:var(--hair)}
.dev:first-child{border-top:0}
.dev.pending .res-main b{color:var(--mut);font-weight:500}

/* ---------- visitor context ----------
   One glanceable line under the header — where they are, how they found us,
   how long they have been reading — that opens into the detail. Collapsed by
   default: on a phone this sits between the header and the transcript, and a
   permanent six-row panel would push the conversation off the screen. */
.vis{border-bottom:var(--hair);background:var(--sidebar);flex:0 0 auto}
.vis-line{
  display:flex;align-items:center;gap:8px;width:100%;
  padding:7px 14px;font-size:12px;color:var(--mut);text-align:left;
}
.vis-line span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.vis-caret{transition:transform .15s ease;flex:0 0 auto}
.vis.open .vis-caret{transform:rotate(90deg)}
.vis-detail{padding:2px 14px 10px;max-height:45vh;overflow-y:auto;overscroll-behavior:contain}
.vis-row{display:flex;gap:10px;align-items:baseline;padding:3px 0;font-size:12px}
.vis-row span{flex:0 0 92px;color:var(--mut)}
.vis-row b{flex:1;min-width:0;font-weight:500;word-break:break-word}
.vis-sub{margin:8px 0 4px;font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--mut)}
.vis-page{display:flex;gap:8px;font-size:12px;padding:2px 0}
.vis-page span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.vis-page i{flex:0 0 auto;color:var(--mut);font-style:normal;font-size:11px;
  max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-meta{font-size:11px;color:var(--mut);margin-top:1px;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* What they are typing but have not sent. Deliberately looks unfinished —
   dashed, muted, never a bubble — because it is not a message yet and an agent
   must not answer a sentence the customer is still changing. */
.typing-peek{
  clear:both;display:flex;align-items:center;gap:8px;margin:6px 0 10px;padding:6px 10px;
  border:1px dashed var(--line);border-radius:14px;color:var(--mut);font-size:13px;
  max-width:75%;
}
.typing-peek .peek{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-style:italic}
.typing-peek .dots{display:inline-flex;gap:3px;flex:0 0 auto}
.typing-peek .dots i{width:5px;height:5px;border-radius:50%;background:currentColor;
  animation:peekdot 1.2s infinite ease-in-out}
.typing-peek .dots i:nth-child(2){animation-delay:.15s}
.typing-peek .dots i:nth-child(3){animation-delay:.3s}
@keyframes peekdot{0%,60%,100%{opacity:.25}30%{opacity:.9}}
@media (prefers-reduced-motion: reduce){ .typing-peek .dots i{animation:none} }

/* ---------- traffic view ----------
   The same sidebar + pane shell as the conversations, so the phone gets the
   push-navigation stack and the desktop gets the split, without a second
   layout to keep in step. */
.seg{display:flex;gap:2px;margin:0 10px 8px;padding:2px;border-radius:8px;background:var(--sidebar-sel)}
.seg button{
  flex:1;padding:5px 8px;border-radius:6px;font-size:13px;font-weight:500;
  color:var(--mut);display:flex;align-items:center;justify-content:center;gap:5px;
}
.seg button.on{background:var(--bg);color:var(--ink);box-shadow:0 1px 2px rgba(0,0,0,.12)}
.seg-count{
  font-size:11px;font-weight:600;line-height:1;padding:2px 5px;border-radius:999px;
  background:var(--blue);color:#fff;
}
.seg-count:empty{display:none}
.stats{display:flex;padding:8px 10px 10px;gap:6px}
.stat{
  flex:1;display:flex;flex-direction:column;align-items:center;gap:1px;
  padding:7px 4px;border-radius:9px;background:var(--sidebar-sel);
}
.stat b{font-size:17px;font-weight:600;line-height:1.1}
.stat span{font-size:10px;color:var(--mut);text-transform:uppercase;letter-spacing:.03em}
.vrow .avatar{font-size:17px}
.vpane{flex:1;overflow-y:auto;padding:14px 16px 24px;-webkit-overflow-scrolling:touch}
.vpane .vis-row span{flex:0 0 104px}
.dot{display:inline-block;width:7px;height:7px;border-radius:50%;margin-right:6px;vertical-align:middle}
.dot.live{background:#34c759}
.dot.idle{background:#ffcc00}

/* ---------- swipe to delete ----------
   The iOS list gesture: the row is the moving surface, the action sits behind
   it and is only ever revealed by the row sliding off it. */
.swipe{position:relative;overflow:hidden}
.swipe-actions{
  position:absolute;inset:0 0 0 auto;width:184px;     /* = SWIPE_W in index.html */
  display:flex;align-items:stretch;
  opacity:0;transition:opacity .08s linear;           /* lit only while sliding */
}
.swipe.sliding .swipe-actions{opacity:1}
.swipe-del{
  flex:1;background:#ff3b30;color:#fff;font-size:15px;font-weight:500;
  display:flex;align-items:center;justify-content:center;
}
.swipe-del:active{background:#d7372c}
.swipe > .conv{
  position:relative;background:var(--sidebar);
  will-change:transform;touch-action:pan-y;          /* let the list scroll vertically */
}
/* .conv.sel paints its own background and insets itself; keep the sliding
   surface opaque either way or the red shows through the whole row. */
.swipe > .conv.sel{background:var(--sidebar-sel);margin:0}

/* End chat sits next to Take over — quieter than it, because closing a
   conversation is the last thing you do, not the first. */
.endchat{
  flex:0 0 auto;padding:5px 10px;margin-right:6px;border-radius:999px;
  border:1px solid var(--line);color:var(--mut);font-size:13px;
}
.endchat:active{background:var(--sidebar-sel)}
.endchat[hidden]{display:none}
.taken.ended{color:var(--mut)}

/* The APK link is an <a>, not a <button>, so it needs the same shape as .mini
   without inheriting a button's default text colour. */
a.mini{display:inline-flex;align-items:center;justify-content:center;text-decoration:none}

/* The confirm sheets (delete, end chat) put their text straight into .sheet,
   which has no horizontal padding of its own — the settings sheet gets its
   inset from .set on the inner div. So the copy ran to both edges. */
.sheet > .set-note,
.sheet > .set-row,
.sheet > label.set-row{padding-left:14px;padding-right:14px}
.sheet > .set-row{padding-bottom:12px}
.sheet > .set-note{padding-top:10px}

/* Two actions behind the row now, so the drawer is wider. Archive is the quiet
   one: this is the action you take dozens of times a day, delete is the one you
   take rarely and mean. */
.swipe-arch{
  flex:1;background:#8e8e93;color:#fff;font-size:15px;font-weight:500;
  display:flex;align-items:center;justify-content:center;
}
.swipe-arch:active{background:#7a7a7f}

/* A photograph in the transcript, so a reviewer sees what the family saw. */
.msg-photo{display:block;text-decoration:none;color:inherit;padding:6px 6px 8px;max-width:230px}
.msg-photo img{display:block;width:100%;height:auto;border-radius:12px;background:var(--in-bg)}
.msg-photo span{display:block;margin-top:6px;font-size:11px;opacity:.75;line-height:1.3}

/* Where the customer is, under the last message. Quiet by default — it is
   context, not an event — and only coloured when they have gone. */
.presence{
  clear:both;text-align:center;font-size:11px;color:var(--mut);
  margin:10px 0 4px;padding:0 12px;line-height:1.4;
}
.presence--left{color:#c8891f}
.presence--ended,.presence--closed{color:#c0392b}
