/* Sales: WhatsApp chats and GAKA's suggestions on the order form.
   Owned by public/js/chats.js and loaded after /styles.css. Class names here belong to this module;
   a look shared by several modules goes in /styles.css (npm run check-styles enforces this). */

/* ---------- chats ---------- */
/* The chat screen fills the window below the top bar (--topbar-h, measured by shell.js) and above the phone menu */
/* Chat colours, as in WhatsApp: soft green for our messages, white or grey for the customer's, a warm background.
   No bright blue, so long reading is easy on the eyes, by day and at night. */
.chats { --chat-bg: #efeae2; --chat-dots: rgb(0 0 0 / .05); --bubble-in: #ffffff; --bubble-out: #d9fdd3; --bubble-ink: #111b21;
  --bubble-meta: #667781; --tick-read: #53bdeb;
  /* The whole chat screen in WhatsApp green instead of GAKA blue: buttons, chips, unread counts, links */
  --accent: #008069; --accent-ink: #ffffff; --accent-soft: #d9fdd3; --link: #027eb5; }
@media (prefers-color-scheme: dark) {
  .chats { --chat-bg: #0b141a; --chat-dots: rgb(255 255 255 / .035); --bubble-in: #202c33; --bubble-out: #005c4b; --bubble-ink: #e9edef;
    --bubble-meta: #8696a0; --tick-read: #53bdeb;
    --accent: #00a884; --accent-ink: #111b21; --accent-soft: #103529; --link: #53bdeb; }
}
.chats { display: grid; height: calc(100dvh - var(--topbar-h) - var(--nav-h) - env(safe-area-inset-bottom, 0px)); }
/* A chat never grows wider than the screen (the CEO, 8 November 2026): a wide photo, a long link or a long file name once
   stretched the whole chat, cutting off bubbles, the header and Send reply. The column is the screen's width, and what is
   inside shrinks or wraps to it. */
.chats { grid-template-columns: minmax(0, 1fr); }
.chats > *, .thread, .messages, .thread-head, .composer { min-width: 0; }
.msg { overflow-wrap: anywhere; }
.msg img { max-width: 100%; height: auto; object-fit: contain; }
.msg .doc { min-width: 0; overflow-wrap: anywhere; }
.conv-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--surface); }
/* The search, tabs and filters stay inside the chat list at any width: the filters wrap onto a second line when the list
   is narrow and spread out as it is dragged wider; the tabs scroll sideways inside the list if they ever need to */
.pane-head { padding: .75rem .75rem 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; border-bottom: 1px solid var(--border); min-width: 0; }
.pane-head > * { min-width: 0; }
.filter-chips { display: flex; flex-wrap: wrap; gap: .4rem; padding-bottom: .55rem; }
.filter-chips:empty { display: none; }
.filter-chip { font: inherit; font-size: .8rem; padding: .2rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.filter-chip:hover { border-color: var(--accent); }
.filter-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: .7rem; padding: .7rem .85rem; color: inherit; border-bottom: 1px solid var(--border); align-items: center; }
.conv-item:hover { background: var(--surface-2); text-decoration: none; }
.conv-item.active { background: var(--accent-soft); }
.conv-main { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.conv-row { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.conv-row time { font-size: .75rem; color: var(--muted); flex: none; }
.conv-row > strong, .conv-row > .preview { min-width: 0; }
.has-unread .conv-row strong { font-weight: 800; }
.has-unread .conv-row time { color: var(--accent); font-weight: 600; }
.preview { color: var(--muted); font-size: .9rem; }
.has-unread .preview { color: var(--text); font-weight: 600; }
.unread { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .72rem; font-weight: 700; padding: 0 .45rem; min-width: 1.3rem; text-align: center; flex: none; }
.conv-meta { font-size: .75rem; color: var(--muted); }

/* Avatar colours, one per customer (tint() in chats.js) */
.avatar.av-0 { background: #dbe7fb; color: #1f3f8f; }
.avatar.av-1 { background: #d9f2e6; color: #1f6b47; }
.avatar.av-2 { background: #fbe3d6; color: #9a3f12; }
.avatar.av-3 { background: #ece0fa; color: #5b2a92; }
.avatar.av-4 { background: #fdf0c8; color: #7a5800; }
.avatar.av-5 { background: #f9dde3; color: #9b1f3e; }
.avatar.av-6 { background: #d6f1f4; color: #11636e; }
.avatar.av-7 { background: #e6e9f0; color: #3d475e; }
@media (prefers-color-scheme: dark) {
  .avatar.av-0 { background: #22366a; color: #c4d6ff; }
  .avatar.av-1 { background: #1d4a37; color: #b4ecd0; }
  .avatar.av-2 { background: #5a2f19; color: #ffd2b8; }
  .avatar.av-3 { background: #3d2a5e; color: #e1ccff; }
  .avatar.av-4 { background: #4d3d0f; color: #ffe39a; }
  .avatar.av-5 { background: #5a2131; color: #ffc7d4; }
  .avatar.av-6 { background: #134a52; color: #b2eef5; }
  .avatar.av-7 { background: #2c3550; color: #d3d9e8; }
}

.thread { display: none; flex-direction: column; min-height: 0; background: var(--bg); }
.chats.has-thread .conv-pane { display: none; }
.chats.has-thread .thread { display: flex; }
/* The chat header in two rows (GAKA 1.70.2): the customer (picture, name, number, reply timer) on the first, never squeezed;
   the buttons on the second, scrolling sideways when they do not fit. Before, the buttons took the whole line and the name
   and number shrank to nothing under the timer. */
.thread-head { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .55rem; padding: .5rem .75rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.thread-title { flex: 1 1 12rem; min-width: 0; display: grid; }
.thread-title .muted { font-size: .8rem; }
.thread-actions { display: flex; gap: .35rem; align-items: center; flex: 1 0 100%; order: 10; overflow-x: auto; scrollbar-width: thin; padding-bottom: .1rem; }
.thread-actions > * { flex: none; }
.window-pill { flex: none; font-size: .72rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.window-pill::before { content: '●'; margin-right: .3rem; font-size: .6rem; vertical-align: .1em; }
.window-pill.open { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.window-pill.closed { background: color-mix(in srgb, #d97706 16%, transparent); color: #b45309; }
@media (prefers-color-scheme: dark) { .window-pill.closed { color: #fbbf24; } }

/* More actions (phones): a small menu under the ⋯ button */
.thread-more { position: relative; }
.thread-more > summary { list-style: none; cursor: pointer; width: 2.1rem; height: 2.1rem; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 700; }
.thread-more > summary::-webkit-details-marker { display: none; }
/* Fixed to the screen (placed by public/js/chats.js), so the sideways-scrolling row of actions cannot cut it off (GAKA 1.82.11) */
.thread-more .menu { position: fixed; right: 8px; top: 120px; z-index: 60; min-width: 13rem; max-width: calc(100vw - 16px); overflow-y: auto; display: grid; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .14); }
.thread-more .menu button { font: inherit; text-align: left; padding: .7rem .8rem; min-height: 44px; border: 0; border-radius: 6px; background: none; color: var(--text); cursor: pointer; }
.thread-more .menu button:hover { background: var(--surface-2); }
.thread-actions .full-only { display: none; }
@media (max-width: 599px) {
  .thread-head { flex-wrap: wrap; }
  .thread-head .avatar { display: none; }
  .window-pill { order: 3; }
  /* The customer's name keeps room; the reply timer goes to the next line when it must */
  .thread-title { min-width: 7.5rem; }
}
@media (min-width: 600px) {
  .thread-actions .full-only { display: inline-flex; }
  .thread-more { display: none; }
}

.order-strip { display: flex; gap: .4rem; overflow-x: auto; padding: .45rem .75rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.order-chip { font-size: .8rem; white-space: nowrap; border: 1px solid var(--border); border-radius: 999px; padding: .2rem .3rem .2rem .7rem; color: var(--text); }
.order-chip:hover { text-decoration: none; border-color: var(--accent); }

/* The thread: a faint dotted wallpaper, a heading for each day, bubbles grouped while one side keeps writing */
.messages { flex: 1; overflow-y: auto; padding: 1rem .75rem; display: flex; flex-direction: column; gap: .35rem;
  background-color: var(--chat-bg); background-image: radial-gradient(var(--chat-dots) 1px, transparent 1.4px); background-size: 20px 20px; }
.day-sep { align-self: center; margin: .6rem 0 .3rem; }
.day-sep span { display: inline-block; font-size: .72rem; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .15rem .7rem; }
.msg { max-width: min(78%, 560px); padding: .45rem .7rem .3rem; border-radius: 10px 10px 10px 3px; background: var(--bubble-in); color: var(--bubble-ink);
  border: 0; align-self: flex-start; overflow-wrap: anywhere; box-shadow: 0 1px .5px rgb(11 20 26 / .13); }
.msg.out { align-self: flex-end; border-radius: 10px 10px 3px 10px; background: var(--bubble-out); }
.msg.cont { margin-top: -.2rem; }
.msg.in.cont { border-top-left-radius: 6px; }
.msg.out.cont { border-top-right-radius: 6px; }
.msg-body { white-space: pre-wrap; }
/* Reply to one message: a button beside the bubble (on a computer when the mouse is over it), the quote inside the reply */
.msg { position: relative; }
.msg-reply { position: absolute; top: .15rem; display: grid; place-items: center; width: 1.8rem; height: 1.8rem; padding: 0; border: 0; border-radius: 50%;
  background: var(--surface); color: var(--muted); cursor: pointer; box-shadow: 0 1px 2px rgb(0 0 0 / .2); }
.msg-reply svg { width: 1rem; height: 1rem; }
.msg.in .msg-reply { left: calc(100% + .3rem); }
.msg.out .msg-reply { right: calc(100% + .3rem); }
@media (hover: hover) {
  .msg-reply { opacity: 0; }
  .msg:hover .msg-reply, .msg-reply:focus-visible { opacity: 1; }
}
.msg-quote { display: flex; flex-direction: column; width: 100%; min-width: 0; margin-bottom: .25rem; padding: .3rem .5rem; border: 0; border-left: 3px solid var(--accent);
  border-radius: 6px; background: rgb(0 0 0 / .07); color: inherit; font: inherit; font-size: .82rem; text-align: left; cursor: pointer; }
.quote-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.msg-quote strong { color: var(--accent); }
.msg.msg-found { outline: 2px solid var(--accent); outline-offset: 2px; }
.reply-bar { display: flex; align-items: center; gap: .6rem; padding: .45rem .75rem; background: var(--surface); border-top: 1px solid var(--border); }
.reply-bar[hidden] { display: none; }
.reply-bar-text { display: flex; flex-direction: column; flex: 1; min-width: 0; padding-left: .5rem; border-left: 3px solid var(--accent); font-size: .85rem; }
.reply-bar-text strong { color: var(--accent); }
.tpl-tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .8; margin-bottom: .1rem; }
.msg.out a { color: inherit; text-decoration: underline; }
.msg img { display: block; border-radius: 8px; max-height: 320px; margin-bottom: .25rem; }
.msg audio, .msg video { max-width: 100%; display: block; margin-bottom: .25rem; }
.msg .doc { display: flex; align-items: center; gap: .35rem; margin-bottom: .25rem; font-weight: 600; padding: .45rem .6rem; border-radius: 8px;
  background: color-mix(in srgb, currentColor 8%, transparent); color: inherit; text-decoration: none; }
.msg .doc small { font-weight: 400; opacity: .75; margin-left: auto; padding-left: .5rem; }
.doc-name { overflow-wrap: anywhere; }
.msg .media-failed { color: var(--danger); font-weight: 600; }
.msg-meta { font-size: .7rem; color: var(--bubble-meta); text-align: right; margin-top: .1rem; }
.tick { margin-left: .3rem; letter-spacing: -.12em; }
.msg.out .tick.s-read { color: var(--tick-read); }
.msg.failed { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--text); border: 1px solid var(--danger); }
.msg.failed .msg-meta { color: var(--muted); }
.msg.failed .tick { color: var(--danger); font-weight: 800; }
.msg .retry { display: block; margin: .3rem 0 .1rem auto; font: inherit; font-size: .75rem; font-weight: 600; color: var(--danger); background: none; border: 0; padding: 0; text-align: right; }
.msg button.retry { cursor: pointer; text-decoration: underline; }
.msg button.retry:disabled { opacity: .5; cursor: default; }

.composer { display: flex; gap: .5rem; padding: .6rem .75rem; background: var(--surface); border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: .55rem .9rem; }
.composer .send { border-radius: 50%; width: 42px; height: 42px; padding: 0; flex: none; font-size: 1.05rem; }
.composer.closed { align-items: center; justify-content: space-between; gap: .5rem .75rem; font-size: .85rem; flex-wrap: wrap; }
.composer.busy { opacity: .65; pointer-events: none; }

/* The reply bar: the message box on top, the tools and Send reply below, in one rounded card */
.composer.reply-box { position: relative; display: grid; gap: .3rem; margin: .5rem .75rem .75rem; padding: .5rem .55rem .45rem; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / .05); }
.reply-box:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer.reply-box textarea { border: 0; border-radius: 6px; padding: .3rem .4rem; resize: none; max-height: 160px; background: transparent; box-shadow: none; outline: none; }
.reply-box textarea:focus { outline: none; }
.reply-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.reply-tools { display: flex; align-items: center; gap: .1rem; }
.reply-tools .tool, .tool-menu > summary { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 0; background: none;
  color: var(--muted); cursor: pointer; font-size: 1.1rem; list-style: none; }
.tool-menu > summary::-webkit-details-marker { display: none; }
.reply-tools .tool:hover, .tool-menu > summary:hover, .tool-menu[open] > summary { background: var(--surface-2); color: var(--text); }
.tool-menu { position: relative; }
.tool-menu .menu { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 30; min-width: 15rem; display: grid; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .16); }
.tool-menu .menu button { font: inherit; text-align: left; padding: .55rem .7rem; border: 0; border-radius: 8px; background: none; color: var(--text); cursor: pointer;
  display: flex; align-items: center; gap: .45rem; }
.tool-menu .menu button:hover { background: var(--surface-2); }
.emoji-menu .menu { min-width: 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 2.2rem); gap: .1rem; }
.tool-menu .emoji-grid button { font-size: 1.25rem; padding: .25rem; justify-content: center; }
.composer.reply-box .send { border-radius: 10px; width: auto; height: 40px; padding: 0 1rem; display: flex; align-items: center; gap: .45rem; font-weight: 600; font-size: .95rem; }
@media (max-width: 480px) { .send-label { display: none; } .composer.reply-box .send { width: 44px; padding: 0; justify-content: center; } }
/* Narrow phones: the box is one column the width of the screen, the tools wrap onto a second line if they must, and each
   tool's menu opens from the box's left edge, inside the screen */
.composer.reply-box { grid-template-columns: minmax(0, 1fr); }
.reply-bar { min-width: 0; }
.reply-tools { flex-wrap: wrap; min-width: 0; }
.reply-box .tool-menu { position: static; }
.reply-box .tool-menu .menu { left: .4rem; right: auto; bottom: calc(100% + 6px); max-width: calc(100% - .8rem); }
/* The emoji grid takes as many columns as the menu has room for */
.reply-box .emoji-menu .menu { width: min(19.5rem, calc(100% - .8rem)); }
.reply-box .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(2.2rem, 1fr)); }

/* /shortcut: matching saved replies above the reply bar */
.reply-suggest { position: absolute; left: .4rem; right: .4rem; bottom: calc(100% + 6px); z-index: 30; display: grid; padding: .3rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .16); }
.reply-suggest[hidden] { display: none; }
.reply-suggest button { font: inherit; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .6rem; align-items: center; text-align: left; padding: .45rem .6rem;
  border: 0; border-radius: 8px; background: none; color: var(--text); cursor: pointer; }
.reply-suggest button.active, .reply-suggest button:hover { background: var(--accent-soft); }
.reply-suggest span { color: var(--muted); font-size: .85rem; }

/* Saved replies (⚡) */
.saved-list { display: grid; gap: .4rem; max-height: 60vh; overflow-y: auto; }
.saved-row { display: flex; gap: .5rem; align-items: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: .5rem .6rem; }
.saved-use { flex: 1; min-width: 0; display: grid; gap: .15rem; text-align: left; font: inherit; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; }
.saved-use span { white-space: pre-wrap; color: var(--muted); font-size: .88rem; }
.saved-use .badge { margin-left: .4rem; }
.saved-actions { display: flex; gap: .3rem; flex: none; }

/* 🛍 Product catalogue: a grid of cards with the picture, name, manufacturer and starting price; picked cards are outlined */
.catalog-filters input, .catalog-filters .qsearch { flex: 1; min-width: 12rem; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; max-height: 58vh; overflow-y: auto; padding: .15rem; }
.catalog-card { display: grid; align-content: start; gap: .2rem; text-align: left; font: inherit; color: var(--text); background: var(--surface); padding: .45rem;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.catalog-card:hover { border-color: var(--accent); }
.catalog-card.chosen { border: 2px solid var(--accent); padding: calc(.45rem - 1px); background: var(--accent-soft); }
.catalog-card img, .catalog-noimg { width: 100%; height: 96px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.catalog-noimg { display: grid; place-items: center; font-size: 2rem; color: var(--muted); }
.catalog-card strong { font-size: .9rem; line-height: 1.25; }
.catalog-card small { font-size: .75rem; }
.catalog-price { font-size: .8rem; font-weight: 600; color: var(--accent); }
.catalog-actions { align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.catalog-picture[hidden] { display: none; }

/* The chosen file, waiting for Send */
.attach-preview { display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; background: var(--surface); border-top: 1px solid var(--border); }
.attach-preview[hidden] { display: none; }
.attach-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.attach-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font-size: 1.4rem; flex: none; }
.attach-name { flex: 1; min-width: 0; display: grid; }

/* Send template: the template's text and its values */
.tpl-fields { display: grid; gap: .6rem; }
.tpl-preview { white-space: pre-wrap; font-size: .9rem; padding: .6rem .75rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }

/* The customer beside the chat: wide screens only */
.cust-panel { display: none; }
.cust-panel h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.1rem 0 .45rem; }
.panel-card { display: grid; justify-items: start; gap: .35rem; }
.panel-card .avatar { margin-bottom: .2rem; }
.panel-line { display: flex; align-items: flex-start; gap: .2rem; color: var(--text); font-size: .88rem; overflow-wrap: anywhere; }
.panel-notes { margin: .2rem 0 0; font-size: .85rem; color: var(--muted); white-space: pre-wrap; }
.panel-actions { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .4rem; }
.panel-list { display: grid; gap: .3rem; }
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem .55rem; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .82rem; background: var(--surface); }
.panel-row:hover { text-decoration: none; border-color: var(--accent); }
.panel-right { flex: none; display: flex; align-items: center; gap: .3rem; }

@media (min-width: 900px) {
  .chats { height: calc(100dvh - var(--topbar-h)); grid-template-columns: var(--conv-w, 340px) minmax(0, 1fr); }
  .conv-pane { border-right: 1px solid var(--border); }
  .chats .conv-pane, .chats.has-thread .conv-pane { display: flex; }
  .chats .thread { display: flex; }
}
@media (min-width: 1280px) {
  .chats.has-thread { grid-template-columns: var(--conv-w, 320px) minmax(0, 1fr) 300px; }
  .chats.has-thread .cust-panel { display: block; overflow-y: auto; padding: 1rem; background: var(--surface); border-left: 1px solid var(--border); }
  .chats.has-thread .order-strip, .thread-actions .no-panel { display: none; }
}

/* ---------- GAKA suggests (order form) ---------- */
.suggest-box { width: 100%; display: grid; gap: .45rem; padding: .7rem .8rem; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.suggest-head { display: flex; align-items: center; font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); }
.suggest-chip { justify-self: start; padding: .35rem .75rem; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; cursor: pointer; text-align: left; }
.suggest-chip:hover { border-color: var(--accent); }
.suggest-price { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; font-size: .9rem; }
.suggest-price small { margin-left: .35rem; }

/* Twilio and Claude in chats: the SMS tag in the list, Claude's notes and buttons under messages, Call through GAKA */
.chan-tag { display: inline-block; font-size: .65rem; font-weight: 700; letter-spacing: .04em; padding: 0 .35rem; margin-right: .3rem; border-radius: 4px;
  border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.ai-note { margin-top: .3rem; padding: .35rem .5rem; border-radius: 8px; font-size: .8rem; line-height: 1.35; white-space: pre-wrap;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.msg.out .ai-note { background: color-mix(in srgb, var(--bubble-ink) 7%, transparent); color: var(--bubble-ink); border-color: color-mix(in srgb, var(--bubble-ink) 18%, transparent); }
.ai-read { display: inline-flex; align-items: center; gap: .25rem; margin-top: .3rem; font: inherit; font-size: .75rem; font-weight: 600; color: var(--accent);
  background: none; border: 1px solid var(--border); border-radius: 999px; padding: .1rem .6rem; cursor: pointer; }
.ai-read:disabled { opacity: .6; cursor: default; }
.ai-summary { white-space: pre-wrap; line-height: 1.5; margin: 0; }
.panel-call { align-self: flex-start; display: inline-flex; align-items: center; gap: .3rem; }

/* Unread / Mine on: the tabs step back, since the chips look across every chat */
.tabs.stepped-back button { opacity: .45; }
/* The list's tabs scroll sideways only, without a scroll bar (no ▲▼ arrows beside them) */
.pane-head .tabs { overflow-y: hidden; scrollbar-width: none; }
.pane-head .tabs::-webkit-scrollbar { display: none; }
.team-chip { margin-left: auto; }
.late-row td { background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* ---------- WhatsApp Business: labels, pinned and archived chats ---------- */
.label-select { appearance: none; width: auto; flex: none; field-sizing: content; max-width: 11rem; min-height: 0; padding-right: .75rem; }
.label-select.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
/* The tags and the label windows themselves are shared with Customers: public/styles.css */
.thread-title .label-tags { margin-top: .15rem; }
.conv-item { position: relative; }
.conv-item.pinned { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.pin-mark { display: inline-grid; color: var(--muted); }
.pin-mark svg { width: 14px; height: 14px; }
/* The ⌄ on a chat: shown on hover on computers, always on phones */
.conv-menu-btn { border: 0; background: none; color: var(--muted); font-size: 1rem; line-height: 1; padding: 0 .15rem; cursor: pointer; opacity: 0; transition: opacity .12s; }
.conv-item:hover .conv-menu-btn, .conv-menu-btn:focus-visible { opacity: 1; }
@media (pointer: coarse) { .conv-menu-btn { opacity: .7; } }
.chat-menu { position: fixed; z-index: 120; width: 220px; display: grid; padding: .3rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.chat-menu button { display: flex; align-items: center; gap: .55rem; padding: .55rem .7rem; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.chat-menu button:hover, .chat-menu button:focus-visible { background: var(--surface-2); outline: none; }

/* Hover on the green buttons stays green (the shared hover is GAKA blue) */
.chats .btn.primary:hover { background: color-mix(in srgb, var(--accent) 86%, #000); border-color: color-mix(in srgb, var(--accent) 86%, #000); color: var(--accent-ink); }

/* A shared new enquiry in the list: every sales person sees it until one of them replies */
.new-tag { display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .02em; padding: 0 .4rem; margin-right: .35rem; border-radius: 4px;
  background: var(--accent); color: var(--accent-ink); }

/* Several photos chosen at once: thumbnails in a row above the reply bar, each with × */
.attach-strip { flex: 1; min-width: 0; display: flex; gap: .45rem; overflow-x: auto; padding: .1rem 0; }
.attach-tile { position: relative; flex: none; }
.attach-tile .icon-btn { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; min-width: 0; padding: 0; border-radius: 50%;
  background: var(--text); color: var(--bg); font-size: .8rem; line-height: 1; display: grid; place-items: center; }
.attach-count { flex: none; }

/* Computers: the chat list's right edge can be dragged to make the list wider (phones show one pane at a time) */
.conv-resize { display: none; }
@media (min-width: 900px) {
  .conv-pane { position: relative; }
  .conv-resize { display: block; position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 5; touch-action: none; }
  .conv-resize::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background .15s; }
  .conv-resize:hover::after, .conv-resize:focus-visible::after, .chats.resizing .conv-resize::after { background: var(--accent); }
  .chats.resizing { cursor: col-resize; user-select: none; }
}

/* Waiting filter: how long the customer has waited, in red */
.wait-tag { color: var(--danger); font-weight: 600; }

/* Team window: give a non-sales person's customers to the sales team */
.hand-btn { margin-left: .5rem; }

/* The company a customer buys for: "Procurement Director at Urban Forge" */
.works-for a { color: inherit; font-weight: 600; }
/* Who a quotation is for: long names wrap inside the button */
.choice-btn { white-space: normal; text-align: left; justify-content: flex-start; line-height: 1.35; }

/* Template form: the heading, footer and buttons of the message as the customer will see it */
.tpl-head { display: block; margin-bottom: .25rem; }
.tpl-foot { font-size: .8rem; margin-top: .35rem; }
.tpl-buttons { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.tpl-btn { font-size: .8rem; padding: .2rem .6rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--link); }

/* Follow-ups planned in the open chat, above the reply box */
.follow-strip { display: grid; gap: .3rem; padding: .4rem .75rem; background: var(--surface); border-top: 1px solid var(--border); }
.follow-item { display: flex; align-items: center; gap: .5rem; font-size: .82rem; min-width: 0; }
.follow-item > svg { width: 16px; height: 16px; flex: none; color: var(--accent); }
.follow-item > .ellipsis { flex: 1; }

/* Recording a voice note: takes the reply box's place */
.rec-bar { display: flex; align-items: center; gap: .6rem; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: rec-pulse 1.2s ease-in-out infinite; flex: none; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-note { flex: 1; font-size: .85rem; }
@keyframes rec-pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }

/* Follow up many customers */
.bulk-filters { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: end; }
.bulk-list { max-height: 50vh; overflow: auto; }
.bulk-actions { align-items: center; gap: .75rem; }
.batch-row { cursor: pointer; }

/* The customer's number in a chat opens the call menu */
.call-link { padding-left: 0; font-weight: 500; }
.call-menu .btn { justify-content: center; }

/* ---------- Message actions (public/js/chats/message-menu.js) ---------- */
/* The small arrow that opens a message's menu (right click and a long press open it too) */
.msg-more { position: absolute; top: .15rem; right: .25rem; width: 1.5rem; height: 1.3rem; padding: 0; border: 0; border-radius: 6px; font-size: .9rem; line-height: 1;
  color: var(--bubble-meta, var(--muted)); background: color-mix(in srgb, var(--bubble-in) 85%, transparent); cursor: pointer; opacity: 0; }
.msg.out .msg-more { background: color-mix(in srgb, var(--bubble-out) 85%, transparent); }
.msg:hover .msg-more, .msg-more:focus-visible { opacity: 1; }
@media (hover: none) { .msg-more { display: none; } }
.msg { -webkit-touch-callout: none; }
/* Deleted in GAKA: a quiet note for staff; management see the message with a mark */
.msg-deleted .msg-body { font-style: italic; opacity: .7; }
.msg-deleted-full { outline: 1px dashed var(--danger); outline-offset: -1px; }
.msg-flag { font-size: .78rem; margin-bottom: .25rem; padding: .25rem .45rem; border-radius: 6px; background: color-mix(in srgb, var(--danger) 10%, transparent); }
.msg-translation { font-size: .85rem; margin-top: .3rem; padding-top: .3rem; border-top: 1px solid color-mix(in srgb, var(--bubble-ink) 15%, transparent); }
.msg-reactions { display: flex; gap: .2rem; margin-top: .2rem; }
.msg-reaction { font-size: .95rem; padding: 0 .3rem; border-radius: 999px; background: color-mix(in srgb, var(--bubble-ink) 8%, transparent); }
.msg-mark { font-size: .7rem; }
/* The menu */
.msg-menu { display: grid; gap: .6rem; }
.msg-menu-preview { font-size: .9rem; padding: .5rem .7rem; border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; }
.msg-react-row { display: flex; flex-wrap: wrap; gap: .25rem; }
.msg-react { font-size: 1.45rem; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; }
.msg-react.on { outline: 2px solid var(--accent); }
.msg-menu-list { display: grid; }
.msg-menu-item { text-align: left; font: inherit; padding: .7rem .6rem; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); cursor: pointer; }
.msg-menu-item:hover { background: var(--surface-2); }
.msg-menu-item.danger { color: var(--danger); border-bottom: 0; }
/* Forward and starred lists */
.fwd-list { display: grid; max-height: 50vh; overflow-y: auto; }
.fwd-item { display: grid; text-align: left; font: inherit; padding: .55rem .5rem; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); cursor: pointer; overflow-wrap: anywhere; }
.fwd-item:hover { background: var(--surface-2); }
/* Pinned messages, above the chat */
.pin-bar { background: var(--surface); border-bottom: 1px solid var(--border); }
.pin-bar[hidden] { display: none; }
.pin-bar-item { display: flex; align-items: center; gap: .5rem; width: 100%; min-width: 0; padding: .45rem .75rem; border: 0; background: none; color: var(--text); font: inherit; font-size: .88rem; text-align: left; cursor: pointer; }
/* Phones: a long press opens the message menu (Copy is there), so it must not start selecting text */
@media (hover: none) { .msg { -webkit-user-select: none; user-select: none; } }

/* ---------- Chat calculator (public/js/chats/calculator.js): a floating panel over the chat ---------- */
.calc-panel { position: fixed; right: 1.25rem; bottom: 9.5rem; z-index: 60; width: 19.5rem; max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px); overflow: auto; display: grid; background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28), 0 2px 6px rgba(0, 0, 0, .12); animation: calc-in .16s ease-out; }
@keyframes calc-in { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .calc-panel { animation: none; } }
.calc-panel.dragging { user-select: none; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.calc-head { display: flex; align-items: center; gap: .4rem; padding: .5rem .5rem .35rem .75rem; cursor: grab; touch-action: none; }
.calc-panel.dragging .calc-head { cursor: grabbing; }
.calc-grip { color: var(--accent); display: grid; place-items: center; }
.calc-tabs { display: flex; gap: .15rem; padding: .15rem; background: var(--surface-2); border-radius: 999px; margin-right: auto; }
.calc-tabs button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600; padding: .3rem .75rem;
  border-radius: 999px; cursor: pointer; }
.calc-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.calc-close { border: 0; background: none; color: var(--muted); font-size: 1.35rem; line-height: 1; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; }
.calc-close:hover { background: var(--surface-2); color: var(--text); }
.calc-body { padding: 0 .75rem .75rem; }
.calc-view, .calc-bricks { display: grid; gap: .6rem; }

.calc-screen { text-align: right; padding: .7rem .8rem .6rem; border-radius: 14px; overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 14%, var(--surface-2)), var(--surface-2)); }
.calc-expr { color: var(--muted); font-size: .9rem; min-height: 1.3em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.calc-result { font-size: 2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; color: var(--text); }
.calc-result.preview { color: var(--accent); }

.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.calc-key { height: 46px; border: 0; border-radius: 12px; font: inherit; font-size: 1.15rem; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--surface-2); transition: transform .06s, filter .12s; font-variant-numeric: tabular-nums; }
.calc-key:hover { filter: brightness(1.08); }
.calc-key:active { transform: scale(.94); }
.calc-key.fn { color: var(--muted); font-size: 1rem; }
.calc-key.op { background: var(--accent-soft); color: var(--accent); font-size: 1.3rem; }
.calc-key.eq { background: var(--accent); color: var(--accent-ink, #fff); font-size: 1.35rem; }

.calc-tape { display: grid; gap: .1rem; max-height: 7.5rem; overflow: auto; border-top: 1px solid var(--border); padding-top: .4rem; }
.calc-tape button { display: flex; justify-content: space-between; gap: .5rem; border: 0; background: none; color: var(--text); font: inherit;
  font-size: .82rem; padding: .25rem .35rem; border-radius: 8px; cursor: pointer; text-align: left; font-variant-numeric: tabular-nums; }
.calc-tape button:hover { background: var(--surface-2); }
.calc-put { width: 100%; justify-content: center; }
.calc-put.done { background: var(--ok); border-color: var(--ok); }

.calc-field { display: grid; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 600; }
.calc-field input, .calc-field select { font-size: .95rem; padding: .45rem .6rem; border-radius: 10px; }
.calc-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.calc-chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: -.25rem; }
.calc-chips button { border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .75rem;
  padding: .2rem .6rem; border-radius: 999px; cursor: pointer; }
.calc-chips button.active, .calc-chips button:hover { border-color: var(--accent); color: var(--accent); }
.calc-warn { font-size: .78rem; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: .35rem .55rem; border-radius: 8px; }
.calc-sum { display: grid; gap: .3rem; padding: .65rem .75rem; border-radius: 12px; background: var(--surface-2); font-variant-numeric: tabular-nums; font-size: .88rem; }
.calc-sum > div { display: flex; justify-content: space-between; gap: .5rem; }
.calc-sum .calc-total { border-top: 1px solid var(--border); padding-top: .35rem; margin-top: .1rem; font-weight: 600; }
.calc-total strong { font-size: 1.35rem; color: var(--accent); }
.calc-sum .calc-each { font-size: .76rem; justify-content: flex-end; }
.calc-row { display: flex; gap: .5rem; align-items: center; }
.calc-row .calc-put { flex: 1; }

/* Phones: across the top of the chat, clear of the keyboard and the reply box */
@media (max-width: 640px) {
  .calc-panel { left: 8px; right: 8px; width: auto; top: calc(var(--topbar-h, 56px) + 8px); bottom: auto; max-height: calc(100dvh - var(--topbar-h, 56px) - 140px); }
  .calc-key { height: 42px; }
  .calc-result { font-size: 1.7rem; }
}

/* Phones inside a conversation: the bottom menu is hidden (styles.css), so the chat runs to the bottom of the screen,
   with the reply box clear of the iPhone's home bar */
@media (max-width: 899px) {
  body.in-chat .chats { height: calc(100dvh - var(--topbar-h)); }
  body.in-chat .composer.reply-box { margin-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px)); }
  /* Keyboard up: it covers the home bar, so that room goes and the box sits right on the keyboard (chats.js) */
  body.in-chat.keyboard-open .composer.reply-box { margin-bottom: .35rem; }
}
/* The calculator sits outside the chat layout (on the page), so it takes the chat's WhatsApp green itself */
.calc-panel { --accent: #008069; --accent-ink: #ffffff; --accent-soft: #d9fdd3; }
@media (prefers-color-scheme: dark) { .calc-panel { --accent: #00a884; --accent-ink: #111b21; --accent-soft: #103529; } }
/* Small phones: the reply tools stay on one line with the calculator added */
@media (max-width: 480px) {
  .reply-tools .tool, .tool-menu > summary { width: 30px; }
  .reply-tools { gap: 0; flex-wrap: nowrap; }
}
@media (max-width: 380px) { .reply-tools .tool, .tool-menu > summary { width: 27px; } .composer.reply-box .send { width: 40px; } }
/* The smallest phones: two lines rather than cut tools */
@media (max-width: 340px) { .reply-tools { flex-wrap: wrap; } }
/* The calculator's pin: on, a tap outside does not close it (public/js/chats/calculator.js) */
.calc-pin { border: 0; background: none; color: var(--muted); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.calc-pin:hover { background: var(--surface-2); color: var(--text); }
.calc-pin.active { background: var(--accent-soft); color: var(--accent); }
.calc-pin.active svg { transform: rotate(-30deg); }
.calc-tape .calc-tape-clear { justify-content: flex-end; color: var(--muted); font-size: .75rem; padding-top: .2rem; }
.calc-tape .calc-tape-clear:hover { color: var(--danger); background: none; }

/* ---------- Search inside a chat (public/js/chats.js openSearch): a bar under the chat's top bar ---------- */
.chat-search { display: flex; align-items: center; gap: .25rem; padding: .4rem .6rem; background: var(--surface); border-bottom: 1px solid var(--border);
  animation: chat-search-in .14s ease-out; }
.chat-search[hidden] { display: none; }
@keyframes chat-search-in { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .chat-search { animation: none; } }
.chat-search-icon { color: var(--muted); display: grid; place-items: center; padding: 0 .2rem; }
.chat-search input[type="search"], .chat-search .qsearch { flex: 1; min-width: 0; border: 0; background: var(--surface-2); border-radius: 999px; padding: .45rem .85rem; font-size: .95rem; }
.chat-search input[type="search"]:focus, .chat-search .qsearch:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chat-search-count { font-size: .8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 4.2rem; text-align: center; }
.chat-search .icon-btn { font-size: 1.1rem; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 50%; color: var(--muted); flex: none; }
.chat-search .icon-btn:hover:not(:disabled) { color: var(--text); }
.chat-search .icon-btn:disabled { opacity: .35; cursor: default; }
.chat-search-close { font-size: 1.4rem; }
/* The day box is hidden behind its 📅 button, which opens the phone's or computer's date picker */
.chat-search-daybox { position: relative; display: grid; }
.chat-search .chat-search-daybox .chat-search-day { position: absolute; inset: 0; opacity: 0; pointer-events: none; width: 100%; height: 100%; min-width: 0; padding: 0; border: 0; margin: 0; }
.chat-search-btn { font-size: 1.1rem; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 50%; color: var(--muted); flex: none; }
.chat-search-btn:hover { color: var(--text); }
/* The words found, and the match now shown */
mark.chat-hit { background: color-mix(in srgb, #ffd54a 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
mark.chat-hit.now { background: #ffb300; color: #111b21; }
.msg.search-now { outline: 2px solid color-mix(in srgb, #ffb300 70%, transparent); outline-offset: 2px; }
@media (max-width: 480px) {
  .chat-search { gap: .1rem; padding: .35rem .4rem; }
  .chat-search-icon { display: none; }
  .chat-search-count { min-width: 3.4rem; font-size: .75rem; }
  .chat-search .icon-btn { width: 32px; height: 32px; }
}

/* ---------- promises (GAKA 1.61.0): a date the customer gave to buy ---------- */
/* In the chat list: amber within 2 days, red when overdue */
.promise-tag { color: var(--muted); font-weight: 600; margin-right: .45rem; }
.promise-tag.soon { color: var(--copper); }
.promise-tag.late { color: var(--danger); }
/* Under the chat's header: the open promise with its buttons, or the suggestion from the customer's last message */
.promise-strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem .8rem; padding: .5rem .75rem;
  background: color-mix(in srgb, var(--copper) 9%, var(--surface)); border-bottom: 1px solid var(--border); font-size: .92rem; }
.promise-strip.soon { background: color-mix(in srgb, var(--copper) 18%, var(--surface)); }
.promise-strip.late { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.promise-strip.promise-suggest { background: color-mix(in srgb, var(--accent, #3b82f6) 10%, var(--surface)); }
.promise-strip .actions { display: flex; flex-wrap: wrap; gap: .35rem; }

/* Above the chat list (GAKA 1.69.0): who in the team is online now, and Claude's master switch for management */
.chats-teambar { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .55rem; min-width: 0; }
.chats-online { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .55rem; min-width: 0; }
.chats-online-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600; }
/* Claude in one chat: on, or paused by the sales person */
.claude-pause.locked { opacity: .7; }
.claude-pause.paused { border-color: color-mix(in srgb, var(--warn, #d97706) 60%, var(--border)); color: var(--warn, #d97706); }
