:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --border: #e4e7eb;
    --border-strong: #cbd2d9;
    --text: #1f2933;
    --text-soft: #52606d;
    --muted: #7b8794;
    --accent: #2257d6;
    --accent-soft: #e6edff;
    --danger: #c92a2a;
    --danger-soft: #ffe3e3;
    --success: #1f8a4c;
    --shadow: 0 4px 14px rgba(31, 41, 51, 0.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; }

button { font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; padding: 8px 14px; transition: filter .15s ease; }
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text-soft); border-color: var(--border-strong); }
button.ghost:hover { background: var(--surface-2); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.subtle { background: var(--surface); color: var(--text); border-color: var(--border); }
button.subtle:hover { background: var(--surface-2); }

input, textarea, select { font: inherit; color: var(--text); border: 1px solid var(--border-strong); border-radius: 6px; padding: 8px 10px; background: var(--surface); width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 10px; }
label input, label textarea, label select { margin-top: 4px; }

.error { color: var(--danger); background: var(--danger-soft); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.hint { color: var(--text-soft); font-size: 12px; min-height: 16px; margin-top: 6px; }
.muted { color: var(--muted); }

/* ===== Visitor ===== */
.visitor-body { background: linear-gradient(180deg, #eef1f6 0%, #f5f6f8 100%); }
.visitor-shell { max-width: 460px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; background: var(--surface); box-shadow: var(--shadow); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.visitor-header { padding: 14px 18px; background: var(--accent); color: #fff; flex-shrink: 0; }
.visitor-header .title { font-weight: 600; font-size: 16px; }
.visitor-header .subtitle { font-size: 12px; opacity: .85; margin-top: 2px; }
.visitor-main { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.contact-form { padding: 20px; }
.contact-form h2 { margin: 0 0 4px; font-size: 16px; }
.contact-form p { margin: 0 0 14px; font-size: 13px; }
.phone-row { display: grid; grid-template-columns: 110px 1fr; gap: 6px; margin-top: 4px; }
.phone-row select, .phone-row input { margin-top: 0; }
.chat-area { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px; }
.messages { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; font-size: 14px; word-wrap: break-word; white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.you { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.you .meta { color: rgba(255,255,255,0.8); }
.msg.team { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
/* Typing indicator — shared by visitor.js, agent.js, qa.js, and widget.js
   for the "Support/Visitor is typing…" pill. Three bouncing dots + label. */
.typing-pill { display: inline-flex; align-items: center; gap: 5px; padding: 8px 12px; margin: 6px 8px; max-width: 78%; background: var(--surface-2, #f1f5f9); border: 1px solid var(--border, #e5e7eb); border-radius: 14px; font-size: 12px; color: var(--text-soft, #475569); align-self: flex-start; }
.typing-pill .typing-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.4; animation: typing-bounce 1.2s infinite ease-in-out; }
.typing-pill .typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-pill .typing-dot:nth-child(3) { animation-delay: 0.30s; }
.typing-pill .typing-label { margin-left: 4px; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%           { transform: translateY(-3px); opacity: 1; }
}
.msg.sys-msg { align-self: center; background: #ecfeff; color: #155e75; border: 1px solid #a5f3fc; padding: 4px 10px; border-radius: 999px; font-size: 12px; max-width: none; }
.connect-banner { padding: 10px 14px; background: var(--surface-2); border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--border); }
.connect-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); margin-bottom: 6px; }
.connect-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: connect-pulse 1.2s ease-in-out infinite; }
.connect-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; position: relative; }
.connect-bar::after { content: ''; position: absolute; left: -40%; top: 0; bottom: 0; width: 40%; background: var(--accent); border-radius: 2px; animation: connect-slide 1.6s ease-in-out infinite; }
@keyframes connect-pulse { 0%, 100% { opacity: 0.4; transform: scale(0.9); } 50% { opacity: 1; transform: scale(1.1); } }
@keyframes connect-slide { 0% { left: -40%; } 100% { left: 100%; } }

.install-popup { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); z-index: 200; pointer-events: none; }
.install-popup-card { pointer-events: auto; max-width: 420px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18); padding: 12px; display: grid; grid-template-columns: 40px 1fr; grid-template-areas: "icon text" "actions actions"; gap: 10px; align-items: center; animation: install-slide-up .25s ease-out; }
.install-popup-icon { grid-area: icon; width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--accent); }
.install-popup-icon img { width: 100%; height: 100%; object-fit: cover; }
.install-popup-icon svg { width: 22px; height: 22px; }
.install-popup-text { grid-area: text; min-width: 0; }
.install-popup-title { font-size: 14px; font-weight: 600; color: var(--text); }
.install-popup-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.install-popup-actions { grid-area: actions; display: flex; gap: 8px; justify-content: flex-end; }
.install-close { background: transparent; color: var(--text-soft); border: 1px solid var(--border); padding: 8px 14px; min-height: 36px; }
.install-add { background: var(--accent); color: #fff; border: 0; padding: 8px 16px; min-height: 36px; font-weight: 600; }
@keyframes install-slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.composer textarea { resize: none; min-height: 38px; max-height: 120px; }
.composer button { flex-shrink: 0; }

/* ===== Staff shared ===== */
.staff-body { background: var(--bg); }
.login-card { max-width: 360px; margin: 80px auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 16px; font-size: 18px; }
.staff-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.brand { padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.tabs { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.tabs button { background: transparent; color: var(--text); border: 1px solid transparent; text-align: left; padding: 8px 10px; border-radius: 6px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tabs button:hover:not(.active) { background: var(--surface-2); }
/* Presence + break toggle live directly under the nav tabs. Top border
   visually separates them from the buttons. */
.presence-group { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.presence { font-size: 13px; color: var(--success); padding: 4px 0; font-weight: 500; }
.agent-on-break .presence { color: #b45309; }

/* Bigger, more tactile break toggle (was 32x18 / 14x14). */
.break-toggle { display: flex; align-items: center; gap: 10px; padding: 8px 0; margin: 0; cursor: pointer; font-size: 14px; color: var(--text-soft); user-select: none; }
.break-toggle input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.break-toggle .break-track { position: relative; width: 46px; height: 26px; background: var(--border); border-radius: 999px; transition: background .15s ease; flex-shrink: 0; }
.break-toggle .break-thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: left .15s ease; }
.break-toggle input:checked ~ .break-track { background: #f59e0b; }
.break-toggle input:checked ~ .break-track .break-thumb { left: 23px; }
.break-toggle input:focus-visible ~ .break-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.break-toggle input:disabled ~ .break-track { opacity: 0.6; cursor: wait; }
.break-toggle input:checked ~ .break-label { color: #b45309; font-weight: 600; }
.tag.break { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.workspace { padding: 16px 20px; min-width: 0; }

/* Mobile topbar + nav drawer (hidden on desktop) */
.mobile-topbar { display: none; }
.nav-backdrop { display: none; }
.nav-toggle { display: none; }
.pane { display: none; }
.pane.active { display: block; }
.pane-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.counts { font-size: 12px; color: var(--text-soft); }
.counts .dot { margin: 0 6px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }

/* ===== Agent inbox ===== */
.inbox-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100dvh - 110px); min-height: 480px; }
.chat-list { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow-y: auto; padding: 8px; }
.list-heading { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 8px 6px; }
.chat-row { padding: 10px 10px 10px 12px; border-radius: 6px; border: 1px solid transparent; border-left: 3px solid transparent; cursor: pointer; margin-bottom: 4px; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.active { background: var(--accent-soft); border-color: var(--accent-soft); border-left-color: var(--accent); }
.chat-row.unread { background: #ecfdf5; border-left-color: var(--success); }
.chat-row.unread:hover { background: #d1fae5; }
.chat-row.unread.active { background: var(--accent-soft); border-left-color: var(--accent); }
.chat-row .top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-row .name { font-weight: 500; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row.unread .name { font-weight: 700; }
.chat-row .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.chat-row.unread .time { color: var(--success); font-weight: 600; }
.chat-row .preview-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 3px; }
.chat-row .preview { font-size: 12px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.chat-row.unread .preview { color: var(--text); font-weight: 600; }
.chat-row .badge-new { background: var(--success); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; min-width: 18px; text-align: center; flex-shrink: 0; line-height: 1.4; }
.chat-row .badge-assigned { background: var(--danger); color: #fff; font-size: 9px; font-weight: 700; padding: 2px 7px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; }
.chat-row .meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-row .status-tag { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0 6px; }
/* Status-specific colours so the agent can scan the bucket at a glance.
   "online" = live conversation (green), "offline" = visitor stepped away (amber),
   "closed" = explicitly ended (grey, default). */
.chat-row .status-tag.status-open    { background: #ecfdf5; border-color: #6ee7b7; color: #047857; }
.chat-row .status-tag.status-offline { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }
.chat-row .status-tag.status-closed  { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.chat-row .status-tag.status-queued  { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

.presence-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-right: 2px; flex-shrink: 0; }
.presence-online { background: var(--success); box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18); }
.presence-offline { background: var(--muted); }

.chat-detail { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
.chat-detail .empty { padding: 40px; color: var(--muted); text-align: center; }
.detail-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.detail-header-left { flex: 1; min-width: 0; }
.detail-visitor { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; align-items: center; }
/* Hand-off ("Assign to another agent") control in the chat detail header. */
.assign-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); }
.assign-label { white-space: nowrap; }
.assign-select { height: 30px; min-height: 30px; padding: 0 24px 0 8px; font-size: 12px; min-width: 130px; max-width: 200px; }
.detail-back { display: none; background: transparent; color: var(--text); border: 1px solid var(--border-strong); width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; border-radius: 8px; align-items: center; justify-content: center; flex-shrink: 0; }
.detail-back:hover { background: var(--surface-2); filter: none; }
.detail-messages { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; min-height: 0; -webkit-overflow-scrolling: touch; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.bubble-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.bubble.from-user { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.bubble.from-staff { align-self: flex-end; background: var(--accent); color: #fff; }
.bubble.from-staff .bubble-meta { color: rgba(255,255,255,0.8); }
.bubble.from-admin { align-self: flex-end; background: #5b3aa6; color: #fff; }
.bubble.from-admin .bubble-meta { color: rgba(255,255,255,0.8); }
/* Clickable URLs inside chat bubbles. URLs are linkified by linkifyInto()
   in agent.js / admin.js / visitor.js with rel="noopener noreferrer nofollow". */
.bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.bubble.from-user a { color: var(--accent); }

/* All Leads — lead status + follow-up + final remark cells.
   Compact, single-row input + inline save so 5 extra columns fit. */
.lead-status-select { font-size: 12px; height: 28px; min-height: 28px; padding: 2px 6px; min-width: 110px; max-width: 130px; }

.fu-cell { display: flex; flex-direction: column; gap: 3px; min-width: 180px; max-width: 200px; }
.fu-cell .fu-row { display: flex; gap: 4px; align-items: stretch; }
.fu-cell .fu-input {
    flex: 1;
    height: 28px;
    min-height: 28px;
    max-height: 28px;
    font-size: 12px;
    padding: 4px 6px;
    resize: none;
    line-height: 18px;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
}
.fu-cell .fu-save { font-size: 11px; padding: 0 10px; min-height: 28px; height: 28px; flex-shrink: 0; }
.fu-cell .fu-edit { font-size: 11px; padding: 2px 6px; min-height: 22px; align-self: flex-start; }
.fu-cell .fu-text {
    font-size: 12px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
}
.fu-cell .fu-ts { font-size: 10px; color: var(--text-soft); white-space: nowrap; }
.fu-cell .fu-hint { font-size: 10px; color: var(--text-soft); }

/* The global `.data-table--compact td` rule applies `max-width: 220px` +
   ellipsis truncation — fine for plain-text cells but it clips our widget
   cells (status select, follow-up inputs, final remark). Opt those out so
   the inputs render fully and only the text columns keep ellipsis. */
.data-table--compact td.al-agent-cell,
.data-table--compact td.al-status-cell,
.data-table--compact td.al-fu1-cell,
.data-table--compact td.al-fu2-cell,
.data-table--compact td.al-fu3-cell,
.data-table--compact td.al-final-cell,
.data-table--compact td.acrm-status-cell,
.data-table--compact td.acrm-fu1-cell,
.data-table--compact td.acrm-fu2-cell,
.data-table--compact td.acrm-fu3-cell,
.data-table--compact td.acrm-final-cell {
    max-width: none;
    overflow: visible;
    white-space: normal;
    vertical-align: top;
}

/* Per-column min-widths so the All Leads table scrolls horizontally
   smoothly instead of crushing important columns like Name and Email. */
.data-table--compact td.al-status-cell,
.data-table--compact td.acrm-status-cell { min-width: 130px; }
.data-table--compact td.al-fu1-cell,
.data-table--compact td.al-fu2-cell,
.data-table--compact td.al-fu3-cell,
.data-table--compact td.al-final-cell,
.data-table--compact td.acrm-fu1-cell,
.data-table--compact td.acrm-fu2-cell,
.data-table--compact td.acrm-fu3-cell,
.data-table--compact td.acrm-final-cell { min-width: 190px; }

/* All Leads table: 11 columns are wider than any normal viewport, so make
   horizontal scroll the explicit design. Per-column min-widths keep the
   layout stable instead of letting each column shrink unpredictably. */
.all-leads-table { min-width: 1700px; }
.all-leads-table th, .all-leads-table td { vertical-align: top; }
.all-leads-table th:nth-child(1), .all-leads-table td:nth-child(1) { min-width: 130px; }  /* Date */
.all-leads-table th:nth-child(2), .all-leads-table td:nth-child(2) { min-width: 140px; max-width: 180px; }  /* Name */
.all-leads-table th:nth-child(3), .all-leads-table td:nth-child(3) { min-width: 120px; max-width: 150px; }  /* Number */
.all-leads-table th:nth-child(4), .all-leads-table td:nth-child(4) { min-width: 180px; max-width: 240px; }  /* Email */
.all-leads-table th:nth-child(5), .all-leads-table td:nth-child(5) { min-width: 110px; }  /* Source */
.all-leads-table th:nth-child(6), .all-leads-table td:nth-child(6) { min-width: 140px; }  /* Agent */

/* Sticky Name column when horizontally scrolling. Keeps the most
   identifying piece of info on-screen while the user scans follow-ups. */
.all-leads-table th:nth-child(2),
.all-leads-table td:nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
}
.all-leads-table thead th:nth-child(2) {
    z-index: 3;
    background: var(--surface-2);
}

/* =====================================================================
   AI Integration tab — purpose-built layout so the form reads as
   clearly grouped sections rather than a flat checkbox + grid soup.
   ===================================================================== */
.ai-card { max-width: 880px; }
.ai-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.ai-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-soft);
    white-space: nowrap;
    flex-shrink: 0;
}
.ai-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-soft); }
.ai-status-badge[data-state="active"] { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.ai-status-badge[data-state="active"] .ai-status-dot { background: #10b981; }
.ai-status-badge[data-state="unconfigured"] { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.ai-status-badge[data-state="unconfigured"] .ai-status-dot { background: #f59e0b; }

.ai-enable-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.ai-section { margin: 0 0 18px; }
.ai-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border);
}

.ai-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}
.ai-field { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.ai-field-label { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.ai-field-hint { font-size: 11px; color: var(--text-soft); margin-top: 2px; }

.ai-apikey-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.ai-apikey-input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, Menlo, monospace; }
.ai-apikey-show {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
}
.ai-apikey-show:hover { background: var(--accent-soft); color: var(--accent); }

.ai-routing-row {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.ai-routing-row input[type="range"] {
    flex: 1 1 240px;
    min-width: 0;
    accent-color: var(--accent);
}
.ai-routing-readout {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-soft);
    line-height: 1.4;
    min-width: 140px;
}
.ai-routing-readout strong { color: var(--accent); font-size: 14px; }

.ai-action-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.ai-primary { background: var(--accent); color: #fff; border: 0; padding: 8px 18px; font-weight: 600; }
.ai-primary:hover { filter: brightness(0.92); }
.ai-action-status { font-size: 12px; color: var(--text-soft); }
.ai-action-status.ok { color: #047857; }
.ai-action-status.err { color: #b91c1c; }

.ai-help { max-width: 880px; }

/* Tiny "AI" badge that goes next to the agent name in the Agents tab so
   admins can spot the virtual AI agent at a glance. */
.tag.ai-tag {
    background: #ecfdf5;
    color: #047857;
    border-color: #a7f3d0;
    font-size: 10px;
    padding: 0 6px;
    font-weight: 700;
    letter-spacing: 0.4px;
}
.agent-row-ai { background: #fafafa; }
.ai-help code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: ui-monospace, Consolas, Menlo, monospace;
    font-size: 11px;
}

/* CRM-table pagination footer (Prev | "N-N of N" | Next). */
.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 10px 4px 4px;
    font-size: 12px;
    color: var(--text-soft);
    flex-wrap: wrap;
}
.pagination button { font-size: 12px; padding: 4px 12px; min-height: 28px; }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Top horizontal scrollbar — a thin, JS-managed mirror of the bottom
   scrollbar that sits above the table. Auto-attached by attachTopScrollbar()
   in admin.js / agent.js. */
.data-table-top-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    height: 14px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    margin-bottom: -1px;
    background: var(--surface-2);
}
.data-table-top-scroll-spacer { height: 1px; }
/* When the top scrollbar is present, remove the bottom wrapper's top-rounded
   corners so the two elements visually merge into one container. */
.data-table-top-scroll + .data-table-wrap {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.detail-composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); flex-shrink: 0; }
.detail-composer textarea { resize: none; min-height: 38px; max-height: 140px; }
.detail-composer button { flex-shrink: 0; }

/* ===== Admin specifics ===== */
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.metric-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.metric-value { display: block; font-size: 22px; font-weight: 600; margin-top: 6px; }
.date-filters { display: flex; gap: 10px; margin-bottom: 12px; align-items: end; }
.date-filters label { margin: 0; }
.filter-toggle { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-toggle button { background: var(--surface); color: var(--text); border-color: var(--border); padding: 6px 10px; font-size: 13px; flex: 0 1 auto; }
.filter-toggle button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

/* Agent inbox controls: filter dropdown + free-text search on a single row. */
.list-controls { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.list-filter-select {
    flex: 0 0 auto;
    width: auto;
    min-width: 110px;
    height: 36px;
    padding: 0 28px 0 10px;
    font-size: 13px;
    background-color: var(--surface);
}
.list-search {
    flex: 1 1 auto;
    height: 36px;
    padding: 6px 12px;
    font-size: 13px;
    min-width: 0;
}

/* Star (Important) button on each chat row. Outline-only when unstarred,
   filled gold when starred. Sits between the name and the time. */
.chat-row .star-btn {
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0 6px 0 4px;
    width: 26px;
    height: 26px;
    min-height: 26px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-soft);
    cursor: pointer;
    border-radius: 4px;
}
.chat-row .star-btn:hover { background: var(--surface-2); color: #f59e0b; filter: none; }
.chat-row .star-btn.starred { color: #f59e0b; }
.chat-row .star-btn.starred svg { fill: #f59e0b; stroke: #f59e0b; }
.chat-row .star-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.subtab-toggle { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.subtab-toggle button { background: var(--surface); color: var(--text); border-color: var(--border); padding: 6px 10px; font-size: 13px; flex: 0 1 auto; }
.subtab-toggle button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

.report-toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.report-toolbar label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-soft); margin: 0; }
.report-toolbar input[type="date"], .report-toolbar input[type="search"], .report-toolbar select { padding: 6px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); min-width: 0; }
.report-toolbar input[type="search"] { width: 100%; }
.report-toolbar select { min-width: 140px; }
.report-toolbar button { padding: 6px 12px; font-size: 13px; }
.report-toolbar button.secondary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.report-toolbar button.ghost { background: var(--surface); color: var(--text-soft); border-color: var(--border); }

.admin-chat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.admin-chat-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; cursor: pointer; }
.admin-chat-card:hover { border-color: var(--border-strong); }
.admin-chat-card .name { font-weight: 600; }
.admin-chat-card .sub { font-size: 12px; color: var(--text-soft); margin-top: 4px; word-break: break-word; }
.admin-chat-card .tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; font-size: 11px; }
.admin-chat-card .tag { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; }
.admin-chat-card .tag.open { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.admin-chat-card .tag.queued { background: #fff4d6; border-color: #fff4d6; color: #8a5500; }
.admin-chat-card .tag.closed { background: #e8eaee; border-color: #e8eaee; color: var(--text-soft); }

.add-agent { display: grid; grid-template-columns: 1fr 1fr 1fr 120px auto; gap: 10px; align-items: end; }
.add-agent label { margin: 0; }
.agents-list { display: flex; flex-direction: column; gap: 10px; }
.agent-row { display: grid; grid-template-columns: minmax(170px, 1.1fr) auto auto 1fr minmax(320px, 1.7fr) auto; gap: 10px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.agent-row .agent-name { font-weight: 600; }
.agent-row .agent-email { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.agent-row .row-block label { margin: 0; font-size: 11px; }
.agent-row .row-block input { padding: 4px 8px; font-size: 13px; }
.agent-row .agent-delete-btn { display: inline-block; margin-top: 6px; padding: 3px 10px; font-size: 11px; font-weight: 500; line-height: 1.4; border-radius: 5px; width: auto; }
.agent-online { color: var(--success); font-size: 12px; }
.agent-offline { color: var(--muted); font-size: 12px; }
.agent-online-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.agent-online-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 13px; }
.dot-state { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-state.on { background: var(--success); }
.dot-state.off { background: var(--muted); }

.data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; word-break: break-word; }
.data-table th { background: var(--surface-2); font-weight: 600; color: var(--text-soft); position: sticky; top: 0; z-index: 1; }
.data-table a { color: var(--accent); }

.data-table--compact th, .data-table--compact td { padding: 6px 8px; white-space: nowrap; word-break: normal; }
.data-table--compact td { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.data-table--clickable tbody tr { cursor: pointer; }
.data-table--clickable tbody tr:hover { background: var(--accent-soft); }

.lead-source { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.lead-source-web { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
.lead-source-upload { background: #ede9fe; color: #6d28d9; border: 1px solid #c4b5fd; }

.perm-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text); user-select: none; margin: 0; }
.perm-toggle input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.perm-toggle .perm-track { position: relative; width: 36px; height: 20px; background: var(--border); border-radius: 999px; transition: background .15s ease; flex-shrink: 0; }
.perm-toggle .perm-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,0.2); transition: left .15s ease; }
.perm-toggle input:checked ~ .perm-track { background: var(--accent); }
.perm-toggle input:checked ~ .perm-track .perm-thumb { left: 18px; }
.perm-toggle input:focus-visible ~ .perm-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.qr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qr-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); margin: 0; }
.qr-grid textarea { font-family: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; resize: vertical; min-height: 56px; }
@media (max-width: 600px) { .qr-grid { grid-template-columns: 1fr; } }

.qr-wrap { position: relative; flex-shrink: 0; align-self: end; }
.qr-toggle { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); border-radius: 8px; width: 38px; height: 38px; min-height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.qr-toggle:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.qr-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.agent-attach-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface-2); }
.agent-attach-preview img { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); }
.agent-attach-preview-status { flex: 1; font-size: 12px; color: var(--text-soft); }
.agent-attach-preview button { background: transparent; border: none; color: var(--text-soft); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.agent-attach-preview button:hover { background: var(--surface); color: var(--text); }
.qr-popup { position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 260px; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(15,23,42,0.18); padding: 4px; z-index: 50; display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.qr-popup-item { background: transparent; border: 0; text-align: left; padding: 8px 10px; font-size: 13px; color: var(--text); cursor: pointer; border-radius: 6px; white-space: normal; word-break: break-word; line-height: 1.35; }
.qr-popup-item:hover { background: var(--accent-soft); color: var(--accent); }
.qr-popup-empty { padding: 10px; font-size: 12px; color: var(--text-soft); }

.attach-btn { background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border); border-radius: 8px; width: 38px; height: 38px; min-height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; align-self: end; }
.attach-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.attach-btn:disabled { opacity: 0.5; cursor: wait; }

.attach-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface-2); flex-shrink: 0; }
.attach-preview img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); }
.attach-preview-meta { flex: 1; font-size: 12px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-preview button { background: transparent; border: none; color: var(--text-soft); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.attach-preview button:hover { background: var(--surface); color: var(--text); }

.msg-attachment { display: block; margin-top: 4px; }
.msg-attachment img { display: block; max-width: 260px; max-height: 260px; border-radius: 10px; object-fit: cover; cursor: zoom-in; box-shadow: 0 2px 6px rgba(15,23,42,0.12); }
.bubble .msg-attachment img { max-width: 280px; max-height: 280px; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; justify-content: center; align-items: center; padding: 20px; z-index: 100; }
.modal-card { background: var(--surface); border-radius: 8px; width: 100%; max-width: 620px; max-height: 90dvh; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(15,23,42,0.25); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 600; }
.modal-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.modal .close { background: transparent; color: var(--muted); border: none; font-size: 22px; padding: 0 6px; cursor: pointer; }
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-messages { display: flex; flex-direction: column; gap: 8px; }
.modal-footer { padding: 10px 14px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; }
.modal-footer textarea { resize: none; min-height: 38px; max-height: 120px; }

/* ===== Toasts ===== */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: #fff; border-radius: 8px; padding: 10px 14px; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,0.25); max-width: 320px; border-left: 3px solid transparent; animation: toast-in 0.2s ease-out; }
.toast.toast-assign { background: #18181b; border-left-color: var(--danger); }
.toast.toast-assign::before { content: "🆕 "; }
.toast.toast-msg { background: #18181b; border-left-color: var(--success); }
.toast.toast-msg::before { content: "💬 "; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Token view ===== */
.token-shell { max-width: 760px; margin: 30px auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.token-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.token-header .title { font-weight: 600; font-size: 15px; }
.token-messages { display: flex; flex-direction: column; gap: 8px; padding: 16px 20px; }

/* ===== Mobile + tablet ===== */
@media (max-width: 900px) {
    .visitor-shell {
        max-width: 100%;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .staff-shell { grid-template-columns: 1fr; min-height: 100dvh; }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 82%;
        max-width: 320px;
        z-index: 80;
        transform: translateX(-100%);
        transition: transform .25s ease;
        border-right: 1px solid var(--border);
        border-bottom: none;
        padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px 16px;
        box-shadow: 4px 0 18px rgba(15,23,42,0.14);
        gap: 4px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    body.nav-open .sidebar { transform: translateX(0); }

    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,0.45);
        z-index: 75;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    body.nav-open .nav-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    body.nav-open { overflow: hidden; }

    /* Mobile topbar — replaces the sidebar header visually */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 40;
    }
    .mobile-topbar .topbar-title {
        flex: 1;
        font-weight: 600;
        font-size: 15px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px; height: 40px;
        padding: 0;
        border: 1px solid var(--border-strong);
        background: transparent;
        color: var(--text);
        border-radius: 8px;
        flex-shrink: 0;
    }
    .nav-toggle:hover { background: var(--surface-2); filter: none; }
    .nav-toggle svg { width: 20px; height: 20px; }

    .tabs {
        flex-direction: column;
        gap: 4px;
        overflow: visible;
    }
    .tabs button {
        padding: 12px 14px;
        font-size: 14px;
        text-align: left;
        min-height: 44px;
    }
    .presence { padding: 8px 4px; }
    .sidebar > button.ghost {
        margin-top: auto;
        padding: 10px 14px;
        min-height: 44px;
    }

    .workspace { padding: 12px; }

    /* Single-pane agent inbox on mobile */
    .inbox-grid {
        grid-template-columns: 1fr;
        gap: 0;
        height: auto;
        min-height: 0;
    }
    .chat-list {
        max-height: none;
        height: calc(100dvh - 150px);
        border-radius: 8px;
    }
    /* Chat detail is hidden by default on mobile — appears full-screen only after a chat is opened */
    .chat-detail { display: none; }
    body.detail-open .chat-list,
    body.detail-open .pane-toolbar,
    body.detail-open .mobile-topbar { display: none; }
    body.detail-open .chat-detail {
        display: flex;
        position: fixed;
        inset: 0;
        height: 100dvh;
        z-index: 70;
        border-radius: 0;
        border: none;
    }
    body.detail-open .workspace { padding: 0; }
    .detail-back { display: inline-flex; }

    .detail-header {
        padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
        gap: 8px;
    }
    .detail-composer {
        padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
        gap: 8px;
    }
    .detail-composer textarea { font-size: 16px; min-height: 42px; }
    .detail-composer button { min-height: 42px; padding: 0 18px; }

    .filter-toggle,
    .subtab-toggle {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: -2px -2px 12px;
        padding: 2px;
    }
    .filter-toggle::-webkit-scrollbar,
    .subtab-toggle::-webkit-scrollbar { display: none; }
    .filter-toggle button,
    .subtab-toggle button { white-space: nowrap; min-height: 38px; }

    .add-agent { grid-template-columns: 1fr 1fr; }
    .agents-list { gap: 8px; }
    .agent-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px;
    }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .admin-chat-list { grid-template-columns: 1fr; }

    .modal { padding: 0; align-items: stretch; }
    .modal-card {
        max-height: 100dvh;
        height: 100dvh;
        max-width: 100%;
        border-radius: 0;
    }
    .modal-header { padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 12px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
    .modal-body { padding: 12px 14px; }
    .modal-footer {
        padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
        grid-template-columns: 1fr auto;
        grid-template-areas: "assign assignbtn" "text send";
        gap: 8px;
    }
    .modal-footer #modal-assign { grid-area: assign; }
    .modal-footer #modal-assign-btn { grid-area: assignbtn; }
    .modal-footer #modal-text { grid-area: text; }
    .modal-footer #modal-send { grid-area: send; }
    .modal-footer textarea { font-size: 16px; min-height: 44px; }
    .modal-footer button { min-height: 44px; }

    .data-table-wrap {
        background: linear-gradient(90deg, var(--surface) 0%, transparent 6%, transparent 94%, var(--surface) 100%);
    }
    .data-table { min-width: 600px; font-size: 12px; }

    .toasts { left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
    .toast { max-width: none; }

    .bubble { max-width: 82%; }
}

@media (max-width: 520px) {
    body { font-size: 14px; }
    .login-card { margin: 24px 12px; padding: 18px; }
    .card { padding: 12px; border-radius: 10px; }
    .add-agent { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .metric { padding: 10px; }
    .metric-value { font-size: 18px; }
    .date-filters { flex-direction: column; align-items: stretch; gap: 8px; }
    .bubble { max-width: 85%; padding: 10px 12px; }
    .visitor-header { padding: 12px 14px; }
    .visitor-header .title { font-size: 15px; }
    .contact-form { padding: 14px; }
    .composer { padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px); }
    .composer textarea { min-height: 42px; font-size: 16px; }
    .composer button { min-height: 42px; }
    .data-table th, .data-table td { padding: 6px 8px; }
    .modal .close { font-size: 28px; padding: 4px 10px; min-height: 44px; min-width: 44px; }
    button { padding: 10px 14px; min-height: 40px; }
    input, textarea, select { padding: 10px 12px; font-size: 16px; }
    .detail-visitor { font-size: 15px; }
    .detail-sub { font-size: 11px; }
    .pane-toolbar { margin-bottom: 8px; }
    .counts { font-size: 11px; }
    /* Hand-off control hidden on phones — agent picks hand-off from desktop. */
    .detail-actions .assign-wrap { display: none; }
}
