:root {
  --bg: #1a1612; --card: #211d18; --input: #2a251f; --line: rgba(201,169,97,.25); --line-strong: rgba(201,169,97,.55);
  --text: #f5ede0; --soft: rgba(245,237,224,.72); --muted: rgba(245,237,224,.45);
  --gold1: #E8C988; --gold2: #C9A961; --gold3: #9C7E3F; --ok: #6fcf97; --warn: #f2c94c; --bad: #eb5757;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--gold1); }
[hidden] { display: none !important; }
#app { height: 100%; }

/* ---- generic controls */
.btn { background: linear-gradient(135deg, var(--gold1), var(--gold2) 50%, var(--gold3)); color: var(--bg); border: 0; border-radius: 6px; padding: 10px 16px; font-weight: 600; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--gold1); border: 1px solid var(--line-strong); font-weight: 500; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid rgba(235,87,87,.5); font-weight: 500; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.field { display: block; margin: 0 0 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; background: var(--input); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--line-strong); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.muted { color: var(--muted); }

/* ---- login */
.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.login h1 { margin: 0 0 4px; font-size: 22px; font-family: Georgia, serif; color: var(--gold1); }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

/* ---- layout */
.shell { height: 100%; display: flex; }
.pane-list { width: 100%; display: flex; flex-direction: column; min-height: 0; }
.pane-chat { display: none; flex: 1; min-width: 0; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); }
.shell.in-chat .pane-list { display: none; }
.shell.in-chat .pane-chat { display: flex; }
@media (min-width: 900px) {
  .pane-list { width: 360px; flex: none; }
  .pane-chat { display: flex; }
  .shell.in-chat .pane-list { display: flex; }
  .back { display: none; }
}

.top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 14px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.top h1 { margin: 0; font-size: 18px; font-family: Georgia, serif; color: var(--gold1); flex: 1; }
.pill { border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 10px; font-size: 12px; background: transparent; color: var(--soft); }
.pill.on { color: var(--ok); border-color: rgba(111,207,151,.6); }
.iconbtn { background: transparent; border: 1px solid var(--line); border-radius: 6px; width: 36px; height: 36px; color: var(--soft); }

.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--card); }
.tabs button { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: transparent; border: 0; padding: 10px 0; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--gold1); border-bottom-color: var(--gold2); }

.list { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-b); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.row { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row.sel { background: rgba(201,169,97,.08); }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--input); border: 1px solid var(--line-strong); display: flex; align-items: center; justify-content: center; color: var(--gold1); font-weight: 600; }
.row .mid { flex: 1; min-width: 0; }
.row .l1 { display: flex; gap: 6px; align-items: baseline; }
.row .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .tm { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.row .pv { color: var(--soft); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); flex: none; }
.chip.waiting { color: var(--warn); border-color: rgba(242,201,76,.5); }
.chip.active { color: var(--ok); border-color: rgba(111,207,151,.5); }
.chip.offline { color: var(--bad); border-color: rgba(235,87,87,.5); }
.badge { background: var(--gold2); color: var(--bg); border-radius: 999px; min-width: 20px; padding: 0 6px; font-size: 12px; font-weight: 700; text-align: center; align-self: center; }

/* ---- chat pane */
.chat-head { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-empty { flex: 1; display: none; align-items: center; justify-content: center; color: var(--muted); }
@media (min-width: 900px) { .chat-empty { display: flex; } .pane-chat.has-chat .chat-empty { display: none; } }
.chat-body { flex: 1; min-height: 0; display: none; flex-direction: column; }
.pane-chat.has-chat .chat-body { display: flex; }
.pane-chat.has-chat .chat-head { display: flex; }
.pane-chat:not(.has-chat) .chat-head { display: none; }

.details { border-bottom: 1px solid var(--line); background: var(--card); max-height: 45%; overflow-y: auto; padding: 10px 14px; font-size: 13px; }
.details dl { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; margin: 0 0 8px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.details h4 { margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold2); }
.tr { border-left: 2px solid var(--line); padding-left: 8px; margin: 3px 0; color: var(--soft); }
.tr b { color: var(--muted); font-weight: 600; }
.notice { background: rgba(235,87,87,.09); border: 1px solid rgba(235,87,87,.35); border-radius: 6px; padding: 8px 10px; margin: 8px 0; font-size: 12.5px; color: var(--soft); }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.m { max-width: 82%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.m.customer { align-self: flex-start; background: #3a3e45; color: #f1f1f1; border: 1px solid #4a4f57; border-bottom-left-radius: 3px; }
.m.agent { align-self: flex-end; background: #1f8a4c; color: #fff; border: 1px solid #2aa05d; border-bottom-right-radius: 3px; }
.m.agent small { color: rgba(255,255,255,.78); }
.m.ai { align-self: flex-start; background: rgba(201,169,97,.14); color: var(--text, #f1ece1); border: 1px dashed var(--line-strong); border-bottom-left-radius: 3px; }
.m.customer.past { opacity: .78; }
.m.ai small { color: var(--gold2); }
.m.system.divider { border-top: 1px solid var(--line); padding-top: 6px; width: 100%; max-width: 100%; text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }
.m.system { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; max-width: 92%; }
.m small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.typing { color: var(--muted); font-size: 12px; padding: 0 14px 4px; height: 18px; }

.composer { border-top: 1px solid var(--line); background: var(--card); padding: 8px 10px calc(8px + var(--safe-b)); position: relative; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; background: var(--input); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; max-height: 120px; }
.composer textarea:focus { outline: none; border-color: var(--line-strong); }
.canned { position: absolute; left: 10px; right: 10px; bottom: 100%; background: var(--card); border: 1px solid var(--line-strong); border-radius: 8px; max-height: 220px; overflow-y: auto; z-index: 5; }
.canned button { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; }
.canned button b { color: var(--gold1); }
.canned button span { color: var(--soft); font-size: 13px; display: block; }
.closed-bar { padding: 12px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); background: var(--card); }

/* ---- sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } }
.sheet { width: 100%; max-width: 520px; max-height: 90%; overflow-y: auto; background: var(--card); border: 1px solid var(--line-strong); border-radius: 14px 14px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); }
@media (min-width: 700px) { .sheet { border-radius: 14px; } }
.sheet h2 { margin: 0 0 12px; font-size: 18px; font-family: Georgia, serif; color: var(--gold1); }
.sheet h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold2); }
.line { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.line .g { flex: 1; min-width: 0; }
.line .g small { color: var(--muted); display: block; }
.site-row { flex-wrap: wrap; }
.site-edit { width: 100%; padding: 10px 0 4px; }
.usage-table { width: 100%; border-collapse: collapse; margin: 6px 0 16px; font-size: 13px; }
.usage-table th, .usage-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.usage-table th { color: var(--muted); font-weight: 500; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--safe-b)); background: var(--gold2); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; z-index: 30; max-width: 90%; }

.gap { margin-left: 8px; }

/* =====================================================================
   v0.0.5 — business hours, visitors, CSAT, tags
   ===================================================================== */

.pill.hours { color: var(--warn); border-color: rgba(242,201,76,.5); }

.visitor-row { cursor: default; }

.chip.csat-up, .chip.csat-down { border: 0; padding: 0 2px; font-size: 12px; }

.tags-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--card); }
.chip.tag { background: rgba(201,169,97,.12); border-color: var(--line-strong); color: var(--gold1); display: inline-flex; align-items: center; gap: 2px; }
.tag-x { background: transparent; border: 0; color: inherit; padding: 0 0 0 2px; font-size: 13px; line-height: 1; cursor: pointer; }
.chip.tag-add { background: transparent; color: var(--muted); border-style: dashed; cursor: pointer; }
.chip.tag-add:hover { color: var(--gold1); }

.bh-grid { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 12px; }
.bh-row { display: flex; align-items: center; gap: 8px; }
.bh-row label { display: flex; align-items: center; gap: 4px; width: 64px; flex: none; font-size: 13px; }
.bh-row input[type="text"] { width: 72px; padding: 5px 8px; }

/* =====================================================================
   v0.0.7 — role selects (agent/supervisor/admin), matched to the theme
   ===================================================================== */
select {
	background: var(--input);
	color: var(--text);
	border: 1px solid var(--line);
	border-radius: 6px;
	padding: 6px 8px;
	font: inherit;
}

/* =====================================================================
   v0.0.8 (hub) — suggested replies above the composer
   ===================================================================== */
.suggest-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
.suggest-chip {
	max-width: 260px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* =====================================================================
   Multi-site admin — site filter tabs + per-agent site allocation
   ===================================================================== */
.site-tabs { font-size: 12px; }
.site-tabs button { padding: 6px 0; }
.site-checks { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 0 12px; }
.site-check { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.site-check input { margin: 0; }

.m.system a { color: var(--gold2); text-decoration: underline; }

.m.system .offer-btn { margin-left: 8px; padding: 2px 10px; font-size: 12px; }
.details .offer-btn { margin-left: 6px; padding: 1px 8px; font-size: 11px; }

.plus-btn { font-size: 20px; line-height: 1; padding: 6px 12px; }
.plus-menu { position: absolute; left: 10px; bottom: calc(100% + 4px); z-index: 15; width: min(360px, calc(100% - 20px)); max-height: 60vh; overflow-y: auto; background: var(--card); border: 1px solid var(--line-strong); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.plus-menu .plus-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: inherit; padding: 9px 10px; border-radius: 6px; cursor: pointer; font: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plus-menu .plus-item:hover, .plus-menu .plus-item:focus { background: rgba(201,169,97,.14); outline: none; }
.plus-menu .plus-h { padding: 8px 10px 3px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold2); }
.m.system.divider { border-radius: 0; }

/* =====================================================================
   Stage 3 — presence dots, visitors board, 375px layout
   ===================================================================== */

/* dot: an overlay on the avatar; its meaning is always also written as text beside it */
.avatar { position: relative; }
.av-t { line-height: 1; }
.dot { position: absolute; right: -2px; bottom: -2px; width: 13px; height: 13px; border-radius: 50%; background: var(--muted); border: 2px solid var(--bg); }
.dot.active { background: var(--ok); }
.dot.away { background: var(--warn); }
.dot.left { background: #8a8378; }
/* dim a chat only when its customer has left AND it is an active chat nobody is waiting on; never the preview text */
.row.dim .av-t, .row.dim .nm, .row.dim .tm, .row.dim .chip { opacity: .55; }
.row.dim .avatar { border-color: var(--line); }

/* header: name, then site/status, then presence on its own line; actions wrap under the name on phones */
.chat-head .who small.pstate::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--muted); }
.chat-head .who small.pstate.active { color: var(--ok); }
.chat-head .who small.pstate.active::before { background: var(--ok); }
.chat-head .who small.pstate.away { color: var(--warn); }
.chat-head .who small.pstate.away::before { background: var(--warn); }
.chat-head .who small.pstate.left { color: var(--soft); }
.chat-head .who small.pstate.left::before { background: #8a8378; }
.chat-head .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* banner between the suggestions and the composer (outside .composer so renderComposer never clears it) */
.pbar { flex: none; padding: 7px 14px; font-size: 12.5px; line-height: 1.4; color: var(--soft); background: rgba(201,169,97,.1); border-top: 1px solid var(--line); overflow-wrap: anywhere; }

/* board */
.sec-h { padding: 8px 14px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold2); background: var(--card); border-bottom: 1px solid var(--line); }
.visitor-row { cursor: pointer; }
.visitor-row:focus-visible { outline: 2px solid var(--gold2); outline-offset: -2px; }
.visitor-row .av-t { font-size: 18px; }
.row .l1 { min-width: 0; }
.row .chips { flex-wrap: wrap; row-gap: 4px; }
.row .trail { margin-top: 6px; font-size: 12.5px; }
.trail-h { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.trail .tr { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* visitor log */
.vis-toggle { display: flex; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.vis-toggle button { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 3px 12px; font-size: 12.5px; cursor: pointer; }
.vis-toggle button.on { color: var(--gold1); border-color: var(--gold2); }
.vh-bar { padding: 8px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.vh-bar input { width: 100%; }
.vh-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.vh-chips .chip { cursor: pointer; background: transparent; }
.vh-chips .chip.on { color: var(--gold1); border-color: var(--gold2); }
.chip.warm { color: var(--gold1); border-color: var(--line-strong); }
.chip.hot { color: var(--ok); border-color: var(--ok); }
.vh-more { margin: 10px 14px; }
.vh-detail { margin-top: 8px; font-size: 12.5px; cursor: default; }
.vh-facts div { display: flex; gap: 8px; }
.vh-facts .k { color: var(--muted); min-width: 74px; }
.vh-detail .trail-h { margin-top: 8px; }
.vh-detail .ev { display: flex; gap: 8px; align-items: baseline; }
.vh-detail .ev .at { color: var(--muted); min-width: 52px; font-size: 11.5px; }
.vh-detail .ev .dw { color: var(--muted); margin-left: auto; font-size: 11.5px; }
.vh-detail .ev.search, .vh-detail .ev.cart { color: var(--gold1); }
.vh-detail .ev a { color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vh-detail .btn { margin-top: 8px; }

@media (max-width: 599px) {
  .chat-head { flex-wrap: wrap; }
  .chat-head .actions { flex: 1 1 100%; order: 3; }
  .tabs button { font-size: 13.5px; padding: 10px 2px; }
  .details dd { overflow-wrap: anywhere; }
}

.chip.ai-live { background: rgba(201,169,97,.2); color: var(--gold1); }
.chip.ai-done { opacity: .75; }
.jumpbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; justify-content: space-between; }
.jumpbar span { color: var(--muted); font-size: 13px; }
/* shopping-intent alerts */
.intent-cards { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.intent-card { position: relative; background: var(--card); border: 1px solid var(--line-strong); border-left: 4px solid var(--gold2); border-radius: 8px; padding: 10px 30px 10px 12px; font-size: 13px; cursor: pointer; box-shadow: 0 10px 30px -10px rgba(0,0,0,.6); }
.intent-card.hot { border-left-color: var(--ok); }
.intent-card b { display: block; color: var(--gold1); margin-bottom: 2px; }
.intent-card.hot b { color: var(--ok); }
.intent-card .x { position: absolute; top: 4px; right: 6px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.row.hot { box-shadow: inset 3px 0 0 var(--ok); }
/* say hi */
.say-hi { margin: 4px 0 6px; }
.hi-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.hi-opt { text-align: left; background: transparent; border: 1px solid var(--line); color: var(--text, inherit); border-radius: 8px; padding: 8px 10px; font-size: 13px; cursor: pointer; }
.hi-opt.on { border-color: var(--gold2); color: var(--gold1); }
.sheet textarea { width: 100%; }
.row-btns { display: flex; gap: 8px; margin-top: 8px; }
