/* WA Platform — UI styles. */

:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --panel: #f7f8fa;
    --border: #e5e7eb;
    --text: #1c1c1e;
    --muted: #6b7280;
    --accent: #25d366;
    --accent-dark: #128c7e;
    --inbound: #ffffff;
    --outbound: #d9fdd3;
    --danger: #dc2626;
    --warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

input, textarea, button, select {
    font-family: inherit;
    font-size: inherit;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────── */

.topbar {
    display: grid;
    grid-template-columns: 200px 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; font-size: 16px; }

.topnav { display: flex; gap: 4px; }
.topnav button {
    border: none;
    background: transparent;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--muted);
    font-weight: 500;
}
.topnav button:hover { background: var(--panel); color: var(--text); }
.topnav button.active { background: var(--panel); color: var(--text); }

.user-menu { display: flex; align-items: center; gap: 12px; }
.user-menu button {
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

/* Force the HTML `hidden` attribute to always win, regardless of other rules.
   Without this, ID-level selectors like `#view-settings { display: block }`
   beat `.view[hidden] { display: none }` on specificity. */
[hidden] { display: none !important; }

.view {
    flex: 1;
    overflow: hidden;
    display: flex;
}

/* ── Inbox ───────────────────────────────────────────── */

#view-inbox {
    display: grid;
    grid-template-columns: 320px 1fr;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
}
.sidebar-header h2 { margin: 0; font-size: 14px; }
.sidebar-header button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    color: var(--muted);
}

.conversation-list { flex: 1; }
.conversation-list .empty { padding: 16px; text-align: center; }

.conversation-row {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.conversation-row:hover { background: var(--panel); }
.conversation-row.active { background: #e7f3ff; }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.conversation-row .meta {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.conversation-row .name {
    font-weight: 500;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.conversation-row .preview {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.conversation-row .right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}
.conversation-row .time { font-size: 11px; color: var(--muted); }
.conversation-row .badge {
    background: var(--accent);
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    min-width: 18px;
    text-align: center;
}

/* ── Thread ──────────────────────────────────────────── */

.thread-pane {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}

#thread-empty {
    margin: auto;
    max-width: 420px;
    text-align: center;
    padding: 24px;
}

#thread-active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.thread-name { font-weight: 600; }

.thread-actions { display: flex; align-items: center; gap: 12px; }
.window-status { font-size: 12px; color: var(--muted); }
.window-status.open::before { content: '●'; color: var(--accent); margin-right: 4px; }
.window-status.closed::before { content: '●'; color: var(--warning); margin-right: 4px; }
.thread-actions button {
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background-image:
        linear-gradient(rgba(255,255,255,0.5), rgba(255,255,255,0.5)),
        radial-gradient(circle at top left, #d4ecdf 0, transparent 60%);
}

.bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    background: var(--inbound);
    word-wrap: break-word;
    position: relative;
}
.bubble.outbound {
    align-self: flex-end;
    background: var(--outbound);
}
.bubble .meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}
.bubble .text { white-space: pre-wrap; }
.bubble.failed { border: 1px solid var(--danger); }
.bubble.failed .meta { color: var(--danger); }
.bubble-error {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--danger);
    opacity: 0.95;
}

.bubble img,
.bubble video { max-width: 100%; border-radius: 6px; display: block; }
/* Audio bubbles need a flat min-width to render proper controls. The
   bubble lives in a flex container with shrink-to-fit sizing — without
   an explicit width on the audio element, the bubble collapses around
   the (zero-intrinsic-width) <audio> and the browser falls back to a
   tiny pill UI with only a 3-dots overflow menu.

   The earlier attempt used min-width: min(280px, 100%) which was
   self-defeating: min() returns the smaller value, so when the bubble
   was narrow, the audio's min-width tracked the bubble width and the
   pair stayed collapsed. Solution: a flat 280px min-width, which forces
   the bubble to grow around it. 280px fits a play button + scrubber +
   timer + volume across Chrome/Safari/Firefox. max-width: 100% keeps it
   from overflowing on very narrow viewports (mobile). */
.bubble audio {
    display: block;
    min-width: 280px;
    max-width: 100%;
    width: 320px;
}
.bubble .file-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.04);
    border-radius: 6px;
}

.status-tick { font-size: 11px; }
.status-pending { color: var(--muted); }
.status-sent { color: var(--muted); }
.status-delivered { color: var(--muted); }
.status-read { color: #4fc3f7; }
.status-failed { color: var(--danger); }

/* ── Reactions & edited indicator ────────────────────── */

/* Tiny "edited" tag inline with the timestamp — italicized and muted
   to stay out of the way. WhatsApp shows this prefixed to the time;
   we put it after instead because our meta line already left-aligns
   the time. */
.bubble-edited {
    font-style: italic;
    opacity: 0.75;
}

/* Reaction-chip strip beneath the bubble, matching WhatsApp's UX.
   Negative top margin pulls the strip up a bit so it visually
   anchors to the bubble's bottom edge, with a subtle drop shadow
   to lift it off the chat background. */
.bubble-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: -6px;
    margin-bottom: 2px;
    padding-left: 4px;
}
.bubble.outbound .bubble-reactions {
    justify-content: flex-end;
    padding-left: 0;
    padding-right: 4px;
}
.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 13px;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.reaction-count {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

/* ── Composer ────────────────────────────────────────── */

.composer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    position: relative;
}

.window-warning {
    background: #fef3c7;
    border: 1px solid var(--warning);
    color: #92400e;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.window-warning button {
    border: 1px solid var(--warning);
    background: white;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    color: #92400e;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    font-size: 18px;
    cursor: pointer;
    color: var(--muted);
}
.icon-btn:hover { color: var(--accent); }
.icon-btn.recording { color: var(--danger); animation: pulse 1.4s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#composer-text {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 8px 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}
#composer-text:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

button.primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 18px;
    cursor: pointer;
    font-weight: 500;
}
button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.recording-state {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    background: #fef2f2;
    border-radius: 8px;
}
.rec-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: pulse 1.2s infinite;
}
#rec-time { font-variant-numeric: tabular-nums; font-weight: 500; }
.recording-state button {
    border: 1px solid var(--border);
    background: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-left: auto;
}
/* Higher specificity than `.recording-state button` so the primary
   "Stop & send" button stays green instead of inheriting white. */
.recording-state button.primary {
    background: var(--accent);
    color: white;
    border: none;
}
.recording-state button.primary:hover {
    background: var(--accent-dark);
}

/* ── Link previews ───────────────────────────────────── */

.link-preview {
    margin-bottom: 6px;
}
.lp-card {
    display: block;
    border-left: 3px solid var(--accent);
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    max-width: 320px;
    transition: background 0.12s;
}
.lp-card:hover {
    background: rgba(0, 0, 0, 0.07);
}
.bubble.outbound .lp-card {
    background: rgba(0, 0, 0, 0.06);
}
.bubble.outbound .lp-card:hover {
    background: rgba(0, 0, 0, 0.09);
}
.lp-card img {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    display: block;
    background: var(--border);
}
.lp-text {
    padding: 8px 10px;
}
.lp-site {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}
.lp-title {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    margin-bottom: 4px;
    color: var(--text);
}
.lp-desc {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Composer live link preview ──────────────────────── */

.composer-preview {
    position: relative;
    margin-bottom: 8px;
    padding: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 340px;
}
.composer-preview .cp-loading {
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    padding: 8px;
}
.composer-preview .cp-cleaned {
    font-size: 11px;
    color: var(--accent-dark);
    margin-bottom: 6px;
    padding: 6px 8px;
    background: rgba(37, 211, 102, 0.1);
    border-radius: 4px;
    line-height: 1.35;
}
.composer-preview .cp-dismiss {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    color: var(--muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    z-index: 1;
}
.composer-preview .cp-dismiss:hover {
    background: rgba(0, 0, 0, 0.18);
    color: var(--text);
}
.composer-preview .lp-card {
    max-width: none;
}

/* ── Quick reply popup ───────────────────────────────── */

.quick-reply-popup {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 240px;
    overflow-y: auto;
}
.quick-reply-popup .qr-row {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.quick-reply-popup .qr-row:hover,
.quick-reply-popup .qr-row.active { background: var(--panel); }
.quick-reply-popup .qr-shortcut { font-weight: 600; color: var(--accent-dark); }
.quick-reply-popup .qr-body { color: var(--muted); font-size: 12px; }

/* ── Settings + Admin panels ─────────────────────────── */

#view-settings, #view-admin {
    display: block;
    overflow-y: auto;
    padding: 24px;
}

.panel {
    max-width: 800px;
    margin: 0 auto;
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.panel h2 { margin-top: 0; }

.panel-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.panel-section:first-of-type { border-top: 0; padding-top: 0; }
.panel-section h3 { margin: 0 0 8px; font-size: 15px; }

.row { display: flex; gap: 8px; align-items: center; }
.row select, .row input { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.row button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    cursor: pointer;
}

.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.inline-form button {
    padding: 8px 14px;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    cursor: pointer;
}

.stacked-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.stacked-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.stacked-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }

/* Notification preferences — left-aligned checkbox + label rows.
   Distinct from .stacked-form which forces flex-direction:column on labels
   (intended for "label above input" patterns like the password form). */
.notif-prefs { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.notif-prefs label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}
.notif-prefs input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
}
.stacked-form button {
    align-self: flex-start;
    padding: 8px 16px;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    cursor: pointer;
}

.checkbox { flex-direction: row !important; align-items: center; gap: 8px; }

.qr-list, .tpl-list, #admin-waba-list, #admin-user-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.qr-item, .tpl-item, .waba-item, .user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--panel);
    border-radius: 6px;
}
.qr-item code, .tpl-item code { color: var(--accent-dark); }
.tpl-item .badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--border);
}
.tpl-item .badge.APPROVED { background: #d1fae5; color: #065f46; }
.tpl-item .badge.PENDING { background: #fef3c7; color: #92400e; }
.tpl-item .badge.REJECTED { background: #fee2e2; color: #991b1b; }

/* Delete button on each template row — small, muted by default,
   redshifts on hover so the destructive intent is obvious. */
.tpl-item .tpl-del {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    width: 26px;
    height: 26px;
    line-height: 1;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}
.tpl-item .tpl-del:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}
.tpl-item .tpl-del:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Export link inside the remove-WABA dialog. */
.btn-export {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--accent-dark);
    text-decoration: none;
    font-size: 14px;
}
.btn-export:hover { background: var(--panel-2, rgba(0,0,0,0.04)); border-color: var(--accent); }

/* Edit button on each template row — neutral, accent on hover. */
.tpl-item .tpl-edit {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    height: 26px;
    line-height: 1;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    padding: 0 10px;
}
.tpl-item .tpl-edit:hover {
    background: var(--panel-2, rgba(0,0,0,0.04));
    border-color: var(--accent);
    color: var(--accent-dark);
}

/* ── Login ───────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    width: 360px;
    padding: 32px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.login-card input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}
.login-card input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
.login-card button {
    margin-top: 8px;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; margin: 0; }

/* ── Toast ───────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1f2937;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    max-width: 360px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--accent); }

/* === bubble image size cap === */
/* Cap image bubbles. Without this, a tall product photo from a CDN
   renders at full natural resolution and disrupts scroll on send. */
.bubble img {
    max-width: min(100%, 340px);
    max-height: 380px;
    width: auto;
    height: auto;
    border-radius: 6px;
    display: block;
    cursor: zoom-in;
}

/* === markdown + word-break polish === */
/* WhatsApp-style markdown rendered inside text bubbles. */
.bubble strong { font-weight: 600; }
.bubble em     { font-style: italic; }
.bubble del    { text-decoration: line-through; opacity: 0.85; }
.bubble code, .bubble pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 0.92em;
}
.bubble pre {
    display: block;
    padding: 8px 10px;
    margin: 4px 0;
    white-space: pre-wrap;
    overflow-x: auto;
}

/* Long unbreakable strings — percent-encoded URLs without dashes or
   spaces — were wrapping one character per line on narrow viewports.
   Force the browser to break anywhere when no whitespace candidate. */
.bubble .text,
.lp-card .lp-title,
.lp-card .lp-desc,
.composer-preview .lp-title,
.composer-preview .lp-desc {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* === cta button styling === */

/* Composer-preview send-mode toggle */
.cp-controls { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cp-mode { display: inline-flex; gap: 4px; padding: 3px; background: rgba(0,0,0,0.04); border-radius: 8px; align-self: flex-start; }
.cp-mode-opt { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 0.85em; transition: background 120ms ease; }
.cp-mode-opt input { display: none; }
.cp-mode-opt.is-active { background: var(--accent, #25d366); color: white; }
.cp-button-text { padding: 6px 10px; border: 1px solid var(--border, #ddd); border-radius: 6px; font-size: 0.9em; max-width: 240px; }
.cp-button-text:focus { outline: 2px solid var(--accent, #25d366); outline-offset: -1px; }
.cp-hint { font-size: 0.8em; opacity: 0.7; }

/* CTA-button bubble — image + caption + tappable link styled as button */
.bubble-cta { display: flex; flex-direction: column; gap: 6px; }
.bubble-cta img { max-width: 340px; max-height: 380px; border-radius: 6px; align-self: stretch; }
.bubble-cta-btn {
    display: block;
    text-align: center;
    padding: 10px 14px;
    margin-top: 6px;
    background: rgba(255,255,255,0.5);
    border-top: 1px solid rgba(0,0,0,0.08);
    border-radius: 0 0 6px 6px;
    color: #007bff;
    font-weight: 500;
    text-decoration: none;
    transition: background 120ms ease;
}
.bubble-cta-btn:hover { background: rgba(255,255,255,0.8); text-decoration: underline; }
.bubble-cta-btn::before { content: "🔗 "; opacity: 0.7; }

/* === cta button presets dropdown === */
.cp-button-preset {
    padding: 6px 10px;
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    font-size: 0.9em;
    max-width: 240px;
    background: white;
}
.cp-button-preset:focus { outline: 2px solid var(--accent, #25d366); outline-offset: -1px; }


/* ─── Reply + Local Delete (item #3) ─────────────────────────────── */

/* Inbound bubbles need explicit definition. The default .bubble rule sets
 * background: var(--inbound) (#fff), but on our pale thread background
 * (#f0f2f5) the white-on-near-white blends visually. WhatsApp Web gets
 * away with white bubbles because their thread has a busy doodle pattern;
 * we don't, so we add a subtle border to define the bubble's edges. */
.bubble.inbound {
    background: var(--inbound);
    border: 1px solid var(--border);
}

/* Bubble menu trigger — chevron at top-right corner of every bubble.
 * Faint by default, opaque on hover. Gives every message a single
 * affordance for actions instead of a row of icons. */
.bubble { padding-right: 36px; } /* room for the chevron */
.bubble-menu-trigger {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.04);
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.12s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}
.bubble:hover .bubble-menu-trigger { opacity: 0.7; }
.bubble-menu-trigger:hover,
.bubble-menu-trigger:focus { opacity: 1 !important; background: rgba(0, 0, 0, 0.12); outline: none; }
.bubble.outbound .bubble-menu-trigger { background: rgba(0, 0, 0, 0.05); }

/* Floating dropdown menu — single global element repositioned per click.
 * Dark theme to match WhatsApp's iOS/Android menu. */
.bubble-menu {
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    background: #2a2f32;
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.18);
    padding: 6px 0;
    font-size: 14px;
    user-select: none;
}
.bubble-menu[hidden] { display: none; }
.bubble-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: 0;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.2;
}
.bubble-menu-item:hover { background: rgba(255, 255, 255, 0.08); }
.bubble-menu-item.danger { color: #ff6b6b; }
.bubble-menu-icon {
    flex: 0 0 18px;
    text-align: center;
    font-size: 14px;
    opacity: 0.95;
}
.bubble-menu-sep {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

/* Quote block rendered above a bubble that's a reply — shows the
 * original message inline like WhatsApp does. Click scrolls to the
 * original. */
.bubble-quote {
    display: flex;
    gap: 8px;
    padding: 6px 8px;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    transition: background 0.12s ease;
}
.bubble.outbound .bubble-quote { background: rgba(0, 0, 0, 0.06); }
.bubble-quote:hover { background: rgba(0, 0, 0, 0.1); }
.bubble-quote-bar {
    flex: 0 0 3px;
    background: var(--accent);
    border-radius: 2px;
    align-self: stretch;
}
.bubble-quote-content { flex: 1; min-width: 0; }
.bubble-quote-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bubble-quote-body {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bubble-quote-missing {
    font-style: italic;
    color: var(--muted);
    padding: 4px 8px;
}

/* Deleted-for-me placeholder — replaces the bubble body when the
 * operator soft-deleted the message. Recipient still has their copy. */
.bubble-deleted {
    background: rgba(0, 0, 0, 0.04) !important;
    border: 1px dashed rgba(0, 0, 0, 0.18);
    box-shadow: none !important;
    color: var(--muted);
}
.bubble.outbound.bubble-deleted { background: rgba(217, 253, 211, 0.45) !important; }
.bubble-deleted-content {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-style: italic;
}
.bubble-deleted-icon { opacity: 0.7; }

/* Reply-staging strip — appears above the composer when a reply is
 * queued. Cancel with the × or Escape. After send it auto-clears. */
.reply-staging {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.reply-staging[hidden] { display: none; }
.reply-staging-bar {
    flex: 0 0 4px;
    height: 32px;
    border-radius: 2px;
    background: var(--accent);
}
.reply-staging-content { flex: 1; min-width: 0; }
.reply-staging-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-staging-body {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.reply-staging-close {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
}
.reply-staging-close:hover { background: rgba(0, 0, 0, 0.06); color: var(--text); }

/* Flash highlight when scrolling to a quoted original via quote-click */
.bubble.flash {
    animation: bubbleFlash 1.4s ease-out;
}
@keyframes bubbleFlash {
    0%   { box-shadow: 0 0 0 4px rgba(37, 211, 102, 0); }
    25%  { box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.45); }
    100% { box-shadow: 0 0 0 4px rgba(37, 211, 102, 0); }
}


/* ─── Super admin: impersonation banner ─────────────────────────── */
.impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--warning);
    color: #1f2937;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid #d97706;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
}
.impersonation-banner .imp-icon {
    font-size: 16px;
}
.impersonation-banner strong {
    background: rgba(255, 255, 255, 0.6);
    padding: 1px 8px;
    border-radius: 4px;
}
.impersonation-banner button {
    margin-left: auto;
}
/* When impersonating, give the topbar a subtle warning tint so it's
   immediately clear from any view that this is not the home tenant. */
body.is-impersonating .topbar {
    background: linear-gradient(to right, rgba(245, 158, 11, 0.06), transparent);
}

/* ─── Super admin: Tenants page ──────────────────────────────────── */
#view-tenants .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}
#view-tenants .panel-header h2 { margin: 0 0 4px; }
#view-tenants .panel-header p { margin: 0; }

.tenants-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.tenants-table th,
.tenants-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.tenants-table thead th {
    background: var(--panel);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.tenants-table tbody tr:last-child td { border-bottom: 0; }
.tenants-table tbody tr:hover { background: rgba(0, 0, 0, 0.015); }
.tenants-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.tenants-table th.num { text-align: right; }
.tenants-table .tenant-name {
    font-weight: 500;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Inline badges in the tenant name cell */
.badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-home {
    background: rgba(37, 211, 102, 0.12);
    color: var(--accent-dark);
}
.badge-acting {
    background: rgba(245, 158, 11, 0.18);
    color: #92400e;
}
.badge-suspended {
    background: rgba(220, 38, 38, 0.12);
    color: #991b1b;
}

/* ─── Super admin: Create tenant dialog ──────────────────────────── */
.dialog {
    border: 0;
    border-radius: 12px;
    padding: 24px;
    max-width: 460px;
    width: calc(100vw - 40px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    background: var(--surface);
    color: var(--text);
}
.dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}
.dialog h3 { margin: 0 0 4px; }
.dialog > p.muted { margin: 0 0 16px; font-size: 13px; }

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.temp-password-panel {
    margin-top: 20px;
    padding: 16px;
    background: rgba(37, 211, 102, 0.08);
    border: 1px solid rgba(37, 211, 102, 0.3);
    border-radius: 8px;
}
.temp-password-panel h4 { margin: 0 0 8px; font-size: 14px; }
.temp-password-panel p { margin: 0 0 10px; font-size: 13px; }
.temp-password-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.temp-password-value {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: 'Menlo', 'Monaco', monospace;
    font-size: 13px;
    user-select: all;
    word-break: break-all;
}

/* Secondary button — used in the dialog and copy buttons */
button.secondary {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
button.secondary:hover { background: var(--border); }
button.secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* ─── Corner signature mark ─────────────────────────────────────── */
/* Tiny WebNetCom logo + version, fixed at the bottom-right. Watermark
   feel — low opacity, brightens slightly on hover, never blocks clicks. */
.app-signature {
    position: fixed;
    bottom: 6px;
    left: 10px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0.32;
    pointer-events: none;
    user-select: none;
    font-size: 10px;
    line-height: 1;
    color: var(--muted);
    transition: opacity 0.18s ease;
}
.app-signature:hover {
    /* Hover doesn't actually fire because pointer-events:none, but the
       :hover on body/topbar can be combined later if we want to brighten
       the mark when the user is reading. For now the static state is fine. */
    opacity: 0.55;
}
.app-signature img {
    width: 14px;
    height: 14px;
    object-fit: contain;
    /* If the file isn't there yet the broken-image icon would scream;
       this keeps the area clean even pre-upload. */
    background: transparent;
}
.app-signature span {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}


/* ─── Draft marker on conversation rows ─────────────────────────── */
/* WhatsApp uses a red-orange italic "Draft:" prefix to flag conversations
   that have unsent text. We match that visual idiom. The whole row also
   gets a subtle highlight so it's scannable at a glance. */
.draft-marker {
    color: #e74c3c;
    font-style: italic;
    font-weight: 600;
    margin-right: 4px;
}
.conversation-row.has-draft .preview {
    color: var(--text);  /* preview text reads more present, less muted */
}
.conversation-row.has-draft {
    /* Tiny left accent bar — non-intrusive but signals "you have unfinished
       work here" even on rows where the draft text is short. */
    box-shadow: inset 3px 0 0 0 #e74c3c;
}


/* ─── Save-as-shortcut popover (📌 from composer) ───────────────── */
/* The pin button sits in the composer row with the same icon-btn
   styling. Visible only when the textarea has content. */
#save-shortcut-btn {
    /* Inherits .icon-btn styles. No special tuning needed. */
}

/* The popover floats above the composer. Anchored relative to the
   composer footer (which has position: relative for this purpose).
   Width is fluid up to a max so it doesn't dwarf narrow viewports. */
.save-shortcut-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    z-index: 80;
    width: 320px;
    max-width: calc(100vw - 24px);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.save-shortcut-popover .popover-title {
    font-weight: 600;
    font-size: 14px;
}
.save-shortcut-popover .popover-body-preview {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.save-shortcut-popover input[type="text"] {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Menlo', 'Monaco', monospace;
}
.save-shortcut-popover input[type="text"]:focus {
    border-color: var(--accent);
    outline: none;
}
.save-shortcut-popover .checkbox {
    font-size: 13px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.save-shortcut-popover .popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}
.save-shortcut-popover .popover-actions button {
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
}
.save-shortcut-popover .popover-actions button.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.save-shortcut-popover .popover-actions button.primary:hover {
    background: var(--accent-dark);
}
.save-shortcut-popover .popover-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Composer footer needs position: relative so the absolute popover
   anchors to its top edge. The footer.composer is already styled
   elsewhere, so this is a single-property additive rule. */
.thread-pane > #thread-active footer.composer { position: relative; }


/* ─── Template picker dialog ────────────────────────────────────── */
/* Wider variant of the standard .dialog — templates need room for body
   previews. Two views inside: list + variable form. */
.dialog.dialog-wide {
    max-width: 580px;
    width: calc(100vw - 40px);
}
.dialog-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: -4px -4px 12px;
}
.dialog-header h3 { margin: 0; flex: 1; }
.dialog-back, .dialog-close {
    background: transparent;
    border: 0;
    font-size: 18px;
    cursor: pointer;
    color: var(--muted);
    padding: 4px 10px;
    border-radius: 6px;
    line-height: 1;
}
.dialog-back:hover, .dialog-close:hover {
    background: var(--panel);
    color: var(--text);
}
.dialog-close {
    font-size: 22px;
    line-height: 0.8;
}

#template-picker-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 12px;
    box-sizing: border-box;
}
#template-picker-search:focus {
    border-color: var(--accent);
    outline: none;
}

.template-picker-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.template-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: border-color 0.12s, background 0.12s;
}
.template-row:hover {
    border-color: var(--accent);
    background: rgba(37, 211, 102, 0.04);
}
.template-row-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.template-name {
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.template-preview {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Category badges — different colors so APPROVED templates of different
   categories are visually distinguishable in a long list. */
.badge-marketing { background: rgba(245, 158, 11, 0.18); color: #92400e; }
.badge-utility   { background: rgba(59, 130, 246, 0.15); color: #1e40af; }
.badge-authentication { background: rgba(168, 85, 247, 0.15); color: #6b21a8; }

/* ─── Template variable form view ────────────────────────────── */
.template-picker-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.template-form-head {
    padding: 10px 12px;
    background: var(--panel);
    border-radius: 8px;
}
.template-form-head .template-name {
    font-size: 15px;
}
.template-form-section h4 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.template-vars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.template-var-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.template-var-name {
    font-family: 'Menlo', 'Monaco', monospace;
    color: var(--accent-dark);
    width: 56px;
    flex-shrink: 0;
}
.template-var-input {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}
.template-var-input:focus {
    border-color: var(--accent);
    outline: none;
}
.template-preview-box {
    padding: 10px 12px;
    background: var(--outbound);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 40px;
}


/* ─── Sidebar header action buttons (refresh + new conversation) ── */
.sidebar-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}
.sidebar-header-actions .icon-btn {
    padding: 4px 8px;
    font-size: 14px;
}


/* ── Compliance / data deletion ──────────────────────────────────── */

.danger-btn {
    background: var(--danger);
    color: #fff;
    border: 1px solid var(--danger);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}
.danger-btn:hover:not(:disabled) {
    background: #b91c1c;
    border-color: #b91c1c;
}
.danger-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.danger-btn.armed {
    background: #f59e0b;
    border-color: #f59e0b;
    animation: pulse-armed 1s ease-in-out infinite;
}
@keyframes pulse-armed {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}


/* ─── Labels ────────────────────────────────────────────────────────── */

.label-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    color: white;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.labels-filter {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    margin: 8px 0 0;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    font-size: 13px;
}
.labels-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 12px 0;
}

.labels-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.labels-row:last-child {
    border-bottom: none;
}

.labels-row-actions {
    display: flex;
    gap: 6px;
}

.labels-row-actions button {
    padding: 4px 10px;
    font-size: 12px;
}

.labels-form {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}

.labels-form .row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
}

.labels-form input[name="name"] {
    flex: 1;
    min-width: 0;
}

.palette-picker {
    display: grid;
    grid-template-columns: repeat(10, 28px);
    gap: 6px;
}

.palette-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s, border-color 0.1s;
}

.palette-swatch:hover {
    transform: scale(1.12);
}

.palette-swatch.selected {
    border-color: var(--text);
    transform: scale(1.12);
}

#labels-add-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}


/* ─── Labels: inbox integration ─────────────────────────────────────── */

/* Compact chip used on conversation rows + as overflow indicator */
.label-chip.compact {
    padding: 1px 7px;
    font-size: 10px;
    border-radius: 8px;
    max-width: 80px;
}

.label-chip.compact.overflow {
    background: var(--muted) !important;
    color: white;
    font-weight: 600;
}

/* Strip below the contact name in conversation rows */
.labels-strip {
    display: flex;
    flex-wrap: nowrap;
    gap: 3px;
    margin: 2px 0;
    overflow: hidden;
}

/* Thread header — restructured to use .thread-info container */
.thread-header .thread-info {
    flex: 1;
    min-width: 0;
}

.thread-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.thread-labels:empty {
    display: none;
}

#thread-labels-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

#thread-labels-btn:hover {
    background: var(--bg);
}

/* Picker popover anchored to the thread-labels button */
.label-picker {
    z-index: 1000;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    padding: 8px;
    min-width: 240px;
    max-width: 320px;
    max-height: 60vh;
    overflow-y: auto;
}

.label-picker-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 8px 8px;
}

.label-picker-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.label-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
}

.label-picker-row:hover {
    background: var(--bg);
}

.label-picker-row input[type="checkbox"] {
    margin: 0;
}


/* ─── Labels filter view (Phase K phase 2b) ─────────────────────────── */

/* Active filter chip strip — sits between sidebar header and conversation list */
.label-filter-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.label-filter-chip .label-chip {
    flex: 0 1 auto;
    max-width: none;
}

#label-filter-clear {
    margin-left: auto;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--muted);
    padding: 2px 6px;
    border-radius: 4px;
}

#label-filter-clear:hover {
    background: var(--border);
    color: var(--text);
}

/* Labels view (replaces conversation list when 🏷 toggle is on) */
.labels-view {
    overflow-y: auto;
    flex: 1;
}

.labels-view-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

.labels-view-row:hover {
    background: var(--bg);
}

.labels-view-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    filter: saturate(1.1);
}

.labels-view-meta {
    flex: 1;
    min-width: 0;
}

.labels-view-name {
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.labels-view-count {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

/* Make the labels-toggle button visually distinct when labels mode is active */
#labels-toggle-btn.active {
    background: var(--accent);
    color: white;
}

/* ─── Archive polish + Display name edit (polish push) ──────────────── */

/* Archived pseudo-row at the top of the conversation list */
.archived-row {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.archived-row:hover { background: var(--bg); }

.archived-row-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.archived-row-icon {
    font-size: 18px;
    width: 36px;
    text-align: center;
    flex-shrink: 0;
}

.archived-row-label {
    flex: 1;
    font-weight: 500;
    color: var(--text);
}

.archived-row-count {
    font-size: 12px;
    color: var(--muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

/* Archive button — visual hint when viewing an archived conversation */
#archive-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
#archive-btn:hover { background: var(--bg); }
#archive-btn.archived {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Sidebar title — clickable when in a mode (← prefix indicates back) */
#sidebar-title.clickable {
    cursor: pointer;
    user-select: none;
}
#sidebar-title.clickable:hover {
    color: var(--accent-dark);
}

/* Thread header — name + edit pencil row */
.thread-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.thread-name {
    cursor: text;
    border-radius: 4px;
    padding: 1px 4px;
    margin-left: -4px;
}
.thread-name:hover {
    background: var(--bg);
}

.icon-btn-tiny {
    background: transparent;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.4;
    transition: opacity 0.1s;
}
.thread-name-row:hover .icon-btn-tiny {
    opacity: 1;
}

.thread-name-input {
    font-size: inherit;
    font-weight: inherit;
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    background: white;
    color: var(--text);
    min-width: 200px;
    outline: none;
}


/* ─── CRM integration (Phase L) ─────────────────────────────────────── */

#crm-section .crm-connected {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 10px;
}
#crm-section .crm-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.12);
    color: rgb(22, 101, 52);
    font-size: 13px;
    font-weight: 600;
    align-self: flex-start;
}
#crm-section .crm-badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(34, 197, 94);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}
#crm-section .crm-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    margin: 0;
    font-size: 13px;
}
#crm-section .crm-details dt {
    color: var(--muted);
    font-weight: 500;
}
#crm-section .crm-details dd {
    margin: 0;
    color: var(--fg);
    word-break: break-word;
}
#crm-section .crm-actions {
    margin-top: 4px;
}
#crm-section .crm-form {
    margin-top: 10px;
}
#crm-section .crm-mode-toggle {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#crm-section .crm-mode-toggle legend {
    padding: 0 6px;
    font-size: 13px;
    color: var(--muted);
}
#crm-section .crm-mode-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
}
#crm-section .crm-mode-option:hover {
    background: var(--bg-subtle, rgba(0,0,0,0.03));
}
#crm-section .crm-mode-option input[type="radio"] {
    margin-top: 3px;
    flex-shrink: 0;
}
#crm-section .crm-mode-option > span {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
#crm-section .crm-mode-option input[disabled] + span {
    opacity: 0.6;
}
#crm-section .crm-byo-fields {
    border-left: 3px solid var(--border);
    padding: 4px 0 4px 14px;
    margin-left: 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#crm-section .crm-byo-fields code {
    background: var(--bg-subtle, rgba(0,0,0,0.04));
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    word-break: break-all;
}
#crm-section button.danger {
    background: rgb(220, 38, 38);
    color: white;
    border-color: rgb(220, 38, 38);
}

/* ─── CRM-managed label badge (Phase L Session 3) ─────────────────── */
.labels-row.crm-managed { opacity: 0.92; }
.crm-managed-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: rgb(67, 56, 202);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid rgba(99, 102, 241, 0.25);
    cursor: help;
}

/* ─── Phase L Session 4: Inbox CRM card ────────────────────────────── */
.thread-crm-card {
    background: #f8fafc;
    border-bottom: 1px solid var(--border, #e5e7eb);
    padding: 8px 16px;
    font-size: 13px;
}
.crm-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.crm-card-provider {
    font-weight: 600;
    font-size: 10px;
    letter-spacing: 0.5px;
    color: #4f46e5;
    padding: 1px 6px;
    background: #eef2ff;
    border-radius: 3px;
}
.crm-card-org {
    font-size: 11px;
}
.crm-card-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.crm-card-link, .crm-card-suggestion {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    flex-wrap: wrap;
}
.crm-card-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.crm-card-badge-leads    { background: #dbeafe; color: #1e40af; }
.crm-card-badge-contacts { background: #d1fae5; color: #065f46; }
.crm-card-badge-deals    { background: #fef3c7; color: #92400e; }
.crm-card-name {
    font-weight: 500;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crm-card-sub {
    flex: 0 0 100%;
    margin-left: 0;
    margin-top: 2px;
}
.crm-card-open {
    color: #4f46e5;
    text-decoration: none;
    font-weight: 500;
    font-size: 12px;
    padding: 2px 6px;
    border: 1px solid #c7d2fe;
    border-radius: 3px;
    background: #eef2ff;
}
.crm-card-open:hover { background: #e0e7ff; }
.crm-card-unlink {
    background: none;
    border: 1px solid var(--border, #e5e7eb);
    color: #6b7280;
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 3px;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}
.crm-card-unlink:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.crm-card-link-btn, .crm-card-create-lead {
    background: #4f46e5;
    color: white;
    border: 0;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}
.crm-card-link-btn:hover, .crm-card-create-lead:hover { background: #4338ca; }
.crm-card-link-btn:disabled, .crm-card-create-lead:disabled { background: #9ca3af; cursor: not-allowed; }

/* Phase L deepening (rich card) — per-entity Link/relink button colors
   (Talie May 25 2026): Deal = green, Contact = blue, Lead = amber.
   NOTE: the entity *badges* use a different pre-existing color scheme. */
.crm-card-link-btn.crm-link-btn-deals    { background: #16a34a; }
.crm-card-link-btn.crm-link-btn-deals:hover    { background: #15803d; }
.crm-card-link-btn.crm-link-btn-contacts { background: #2563eb; }
.crm-card-link-btn.crm-link-btn-contacts:hover { background: #1d4ed8; }
.crm-card-link-btn.crm-link-btn-leads    { background: #ea580c; }
.crm-card-link-btn.crm-link-btn-leads:hover    { background: #c2410c; }

/* Phase L deepening (rich card) — contact-detail rows under a linked record */
.crm-card-details {
    flex: 0 0 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed var(--border, #e5e7eb);
}
.crm-card-detail {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #374151;
    min-width: 0;
}
.crm-card-detail-k { flex: 0 0 auto; font-size: 11px; opacity: 0.7; width: 14px; text-align: center; }
.crm-card-detail-v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.crm-card-detail-v { color: #2563eb; text-decoration: none; }
a.crm-card-detail-v:hover { text-decoration: underline; }
.crm-card-copy {
    flex: 0 0 auto;
    margin-left: auto;
    background: none;
    border: 0;
    padding: 0 2px;
    cursor: pointer;
    color: #9ca3af;
    font-size: 12px;
    line-height: 1;
}
.crm-card-copy:hover { color: #4f46e5; }
.crm-card-copy--done { color: #16a34a; }

/* Phase L deepening (rich card) — stale (deleted) + converted-Lead states */
.crm-card-link--stale { background: #fff7ed; border-color: #fed7aa; }
.crm-card-name--stale { text-decoration: line-through; color: #9ca3af; }
.crm-card-stale-note { flex: 0 0 100%; margin-top: 3px; font-size: 11px; color: #b45309; }
.crm-card-link--converted { background: #f5f3ff; border-color: #ddd6fe; }
.crm-card-converted-note { flex: 0 0 100%; margin-top: 3px; font-size: 11px; color: #6d28d9; }
.crm-card-relink-row { flex: 0 0 100%; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.crm-card-relink-btn {
    background: #4f46e5;
    color: white;
    border: 0;
    padding: 3px 9px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
}
.crm-card-relink-btn:hover { filter: brightness(0.92); }
.crm-card-relink-btn.crm-link-btn-deals    { background: #16a34a; }
.crm-card-relink-btn.crm-link-btn-contacts { background: #2563eb; }

/* Phase L deepening (rich card) — Notes (Comments) + task-time editors */
.crm-card-extras {
    flex: 0 0 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--border, #e5e7eb);
}
.crm-card-field { display: flex; flex-direction: column; gap: 4px; }
.crm-card-field-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #6b7280;
}
.crm-card-field-row { display: flex; align-items: center; gap: 6px; }
.crm-card-note-input {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    min-height: 48px;
    font: inherit;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    color: #111827;
}
.crm-card-task-input {
    flex: 1 1 auto;
    min-width: 0;
    font: inherit;
    font-size: 12px;
    padding: 4px 6px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    color: #111827;
}
.crm-card-field-save {
    align-self: flex-start;
    background: #4f46e5;
    color: white;
    border: 0;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
}
.crm-card-field-save:hover { background: #4338ca; }
.crm-card-field-save:disabled { background: #9ca3af; cursor: not-allowed; }
.crm-card-field-hint { margin-top: 2px; }

/* Syncing overlay — keep the card visible (dimmed) with a corner spinner
   during a save/link/unlink refetch instead of blanking the panel. */
.crm-card--syncing { position: relative; pointer-events: none; }
.crm-card--syncing > * { opacity: 0.45; transition: opacity 0.12s; }
.crm-card--syncing::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    border-top-color: #4f46e5;
    animation: crm-card-spin 0.7s linear infinite;
}
@keyframes crm-card-spin { to { transform: rotate(360deg); } }

/* "Link another record" expander beneath linked records */
.crm-card-link-another { margin-top: 8px; width: 100%; }
.crm-card-link-another-toggle {
    background: none;
    border: 0;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.crm-card-link-another-toggle:hover { text-decoration: underline; }
.crm-card-la-caret { font-size: 10px; }
.crm-card-link-another-body { margin-top: 6px; }
.crm-card-la-note { margin-bottom: 6px; }

/* ─── Phase N-2: keyword automation rules ────────────────────────── */
.kw-rule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.kw-rule-item--off { opacity: 0.5; }
.kw-rule-main { flex: 1; min-width: 0; }
.kw-rule-default {
    font-size: 10px;
    font-weight: 600;
    background: #f3e8ff;
    color: #6b21a8;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 6px;
}
.kw-rule-editor {
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.kw-rule-editor input,
.kw-rule-editor textarea {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
}
.kw-rule-keywords code {
    background: #eef2ff;
    border-radius: 3px;
    padding: 1px 5px;
    margin-right: 4px;
    font-size: 12px;
}

/* ─── Phase N-1: Broadcasts ──────────────────────────────────────── */
.bc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.bc-status {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-left: 6px;
}
.bc-status-scheduled { background: #f3e8ff; color: #6b21a8; }
.bc-status-queued    { background: #e0e7ff; color: #3730a3; }
.bc-status-running   { background: #dbeafe; color: #1d4ed8; }
.bc-status-paused    { background: #fef3c7; color: #92400e; }
.bc-status-completed { background: #d1fae5; color: #065f46; }
.bc-status-aborted   { background: #e5e7eb; color: #4b5563; }
.bc-preview {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    white-space: pre-wrap;
    max-width: 480px;
}
.bc-confirm-dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    margin: 8px 0;
    font-size: 13px;
}
.bc-confirm-dl dt { font-weight: 600; color: #4b5563; }
.bc-confirm-dl dd { margin: 0; }
.bc-warn {
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
}
.bc-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}
.bc-bar-fill {
    height: 100%;
    background: #4f46e5;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.bc-counts { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; margin-bottom: 8px; }
.bc-count strong { font-size: 14px; }
.bc-recipients { max-height: 380px; overflow-y: auto; margin-top: 10px; border: 1px solid var(--border, #e5e7eb); border-radius: 6px; }
.bc-recipients-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.bc-recipients-table th, .bc-recipients-table td {
    padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border, #e5e7eb);
}
.bc-recipients-table th {
    background: #f8fafc; position: sticky; top: 0; font-weight: 600; color: #4b5563;
    text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px;
}
.bc-rstatus { font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 3px; text-transform: uppercase; }
.bc-rstatus-pending        { background: #e5e7eb; color: #4b5563; }
.bc-rstatus-sent           { background: #e0e7ff; color: #3730a3; }
.bc-rstatus-delivered      { background: #dbeafe; color: #1d4ed8; }
.bc-rstatus-read           { background: #d1fae5; color: #065f46; }
.bc-rstatus-failed         { background: #fee2e2; color: #991b1b; }
.bc-rstatus-skipped_optout    { background: #fef3c7; color: #92400e; }
.bc-rstatus-skipped_frequency { background: #fef3c7; color: #92400e; }
#bc-detail-actions { gap: 8px; margin: 6px 0; }
#bc-detail-actions .danger { color: #991b1b; border-color: #fecaca; }

/* Context-aware Create — inline Deal form */
.crm-card-create-deal {
    margin-top: 6px;
    padding: 5px 10px;
    border: 1px dashed #4f46e5;
    border-radius: 4px;
    background: none;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
}
.crm-card-create-deal:hover { background: #eef2ff; }
.crm-card-deal-form {
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.crm-card-deal-row label { display: flex; flex-direction: column; gap: 2px; }
.crm-card-deal-name,
.crm-card-deal-date,
.crm-card-deal-stage,
.crm-card-deal-pipeline {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
}
.crm-card-deal-contacts { display: flex; flex-direction: column; gap: 3px; }
.crm-card-deal-contact-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
}
.crm-card-deal-actions { display: flex; gap: 6px; }
.crm-card-deal-submit {
    padding: 4px 12px;
    border: 0;
    border-radius: 4px;
    background: #4f46e5;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}
.crm-card-deal-submit:hover:not(:disabled) { background: #4338ca; }
.crm-card-deal-submit:disabled { opacity: 0.6; cursor: default; }
.crm-card-deal-cancel {
    padding: 4px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    background: #fff;
    color: #4b5563;
    font-size: 12px;
    cursor: pointer;
}
.crm-card-deal-cancel:hover { background: #f3f4f6; }

/* Unified onboarding chooser */
.waba-connect { margin: 10px 0; }
#waba-connect-btn {
    padding: 9px 16px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
#waba-connect-btn:hover { background: #f3f4f6; }
.waba-chooser {
    margin: 10px 0;
    padding: 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.waba-chooser-opt { display: flex; flex-direction: column; gap: 4px; }
.link-btn { background: none; border: 0; color: #6b7280; cursor: pointer; font-size: 13px; align-self: flex-start; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* M-3b: Embedded Signup launcher */
.waba-es { margin: 8px 0 12px; padding: 10px 12px; border: 1px solid var(--border, #e5e7eb); border-radius: 8px; background: #f8fafc; }
.es-btn {
    background: #1877f2;
    border: 0;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    padding: 9px 16px;
}
.es-btn:hover:not(:disabled) { background: #166fe5; }
.es-btn:disabled { opacity: 0.6; cursor: default; }
#es-result { margin-top: 8px; }

/* M-3: WABA BSP badge + onboarding selector */
.waba-bsp-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.waba-bsp-meta    { background: #dbeafe; color: #1d4ed8; }
.waba-bsp-gupshup { background: #e5e7eb; color: #4b5563; }
.waba-bsp-choice {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
}
.waba-bsp-choice legend { font-size: 13px; font-weight: 500; padding: 0 4px; }
.waba-bsp-choice .radio { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 2px 0; }

/* 6.7: template creator buttons builder */
.tpl-btn-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}
.tpl-btn-row select { flex: 0 0 130px; }
.tpl-btn-row .tpl-btn-text { flex: 0 0 140px; }
.tpl-btn-row .tpl-btn-value { flex: 1; min-width: 0; }
.tpl-btn-remove {
    background: none;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 8px;
}
.stacked-form-group { margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.stacked-form-group > span { font-size: 13px; font-weight: 500; }

/* Deepening (e): contact section at the top of the side panel */
.thread-contact-section {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    font-size: 13px;
}
.thread-contact-section:empty { display: none; }
.contact-sec-name { font-weight: 600; }
.contact-sec-labels {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.thread-side-panel--collapsed .thread-contact-section { display: none; }

/* Rich card: collapsible record + header actions + inline editor */
.crm-card-link-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.crm-card-link-header .crm-card-name { flex: 1; min-width: 0; }
.crm-card-collapse {
    background: none;
    border: 0;
    cursor: pointer;
    font-size: 11px;
    color: #6b7280;
    padding: 0 2px;
}
.crm-card-link--collapsed { padding-bottom: 4px; }

/* Rich card (g+h): note history + activity timeline */
.crm-card-section-toggle {
    background: none;
    border: 0;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    text-align: left;
}
.crm-card-section-toggle:hover { text-decoration: underline; }
.crm-card-sec-caret { font-size: 10px; }
.crm-card-section-body {
    margin: 2px 0 6px;
    padding: 6px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: #f8fafc;
    max-height: 240px;
    overflow-y: auto;
    font-size: 12px;
}
.crm-note { padding: 4px 0; border-bottom: 1px solid var(--border, #e5e7eb); }
.crm-note-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.crm-note-actions button {
    background: none;
    border: 0;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    opacity: 0.6;
}
.crm-note-actions button:hover { opacity: 1; }
.crm-note-editor { display: flex; flex-direction: column; gap: 4px; margin: 4px 0; }
.crm-note-edit-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
}
.crm-note-edit-save {
    padding: 2px 10px;
    border: 0;
    border-radius: 4px;
    background: #4f46e5;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
}
.crm-note-edit-cancel {
    padding: 2px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
}
.crm-note:last-of-type { border-bottom: 0; }
.crm-note-content { white-space: pre-wrap; word-break: break-word; }
.crm-note-add { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.crm-note-add-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
}
.crm-note-add-btn {
    align-self: flex-start;
    padding: 3px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
}
.crm-note-add-btn:hover:not(:disabled) { background: #eef2f7; }
.crm-timeline-entry { padding: 4px 0; border-bottom: 1px solid var(--border, #e5e7eb); }
.crm-timeline-entry:last-child { border-bottom: 0; }

/* Phase L deepening (b) — free-text "Search Zoho" */
.crm-card-search { margin-top: 4px; }
.crm-card-search-toggle {
    background: none;
    border: 0;
    color: #4f46e5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.crm-card-search-toggle:hover { text-decoration: underline; }
.crm-card-search-caret { font-size: 10px; }
.crm-card-search-body { margin-top: 6px; }
.crm-card-search-row {
    display: flex;
    gap: 6px;
}
.crm-card-search-input {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 12px;
}
.crm-card-search-btn {
    padding: 4px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    background: #f8fafc;
    color: #374151;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.crm-card-search-btn:hover:not(:disabled) { background: #eef2f7; }
.crm-card-search-btn:disabled { opacity: 0.6; cursor: default; }
.crm-card-search-results { margin-top: 8px; }
.crm-card-search-results .crm-card-suggestions-list {
    max-height: 220px;
    overflow-y: auto;
}

/* Phase L deepening (a) — stage chip + picker */
.crm-card-stage {
    flex: 0 0 100%;
    margin-top: 2px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: #f9fafb;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    text-align: left;
}
.crm-card-stage:hover { background: #f3f4f6; border-color: #d1d5db; }
.crm-card-stage-empty { color: #6b7280; font-style: italic; }
.crm-stage-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: inline-block;
}
.crm-stage-text { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-stage-picker {
    position: fixed;
    z-index: 1000;
    background: white;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    min-width: 180px;
    max-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
}
.crm-stage-picker-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #6b7280;
    padding: 4px 6px 6px;
}
.crm-stage-picker-list { display: flex; flex-direction: column; gap: 2px; }
.crm-stage-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: 0;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 13px;
    color: #111827;
    cursor: pointer;
    text-align: left;
}
.crm-stage-option:hover { background: #f3f4f6; }
.crm-stage-option.is-current { background: #eef2ff; font-weight: 600; }
.crm-stage-option-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-stage-check { color: #4f46e5; font-weight: 700; }
.crm-card-suggestions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.crm-card-heading {
    margin-bottom: 2px;
}
.crm-card-create-lead {
    align-self: flex-start;
    margin-top: 4px;
    background: transparent;
    color: #4f46e5;
    border: 1px dashed #c7d2fe;
}
.crm-card-create-lead:hover {
    background: #eef2ff;
}
.crm-card-empty {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}

/* ─── Phase L Session 4 follow-up: Sync Activity panel ─────────────── */
.sync-activity-controls {
    margin: 8px 0;
    gap: 8px;
}
#sync-activity-filter {
    padding: 4px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    font-size: 13px;
}
.sync-activity-scroll {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
}
.sync-activity-note {
    margin: 8px 0 0;
}
.sync-activity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.sync-activity-table th,
.sync-activity-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border, #e5e7eb);
    vertical-align: top;
}
.sync-activity-table th {
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 1;
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}
.sync-status {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.sync-status-success  { background: #d1fae5; color: #065f46; }
.sync-status-failed   { background: #fee2e2; color: #991b1b; }
.sync-status-conflict { background: #fef3c7; color: #92400e; }
.sync-status-skipped  { background: #e5e7eb; color: #4b5563; }
.sync-error {
    color: #991b1b;
    cursor: help;
    border-bottom: 1px dotted #991b1b;
}
/* Phase L deepening (d): per-row metadata expander */
.sync-meta-toggle {
    font-family: monospace;
    font-size: 11px;
    padding: 1px 6px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    background: #f8fafc;
    color: #4b5563;
    cursor: pointer;
}
.sync-meta-toggle:hover { background: #eef2f7; }
.sync-meta-toggle.open  { background: #e0e7ff; border-color: #c7d2fe; color: #3730a3; }
.sync-meta-row td {
    background: #f8fafc;
    padding: 0 8px 8px;
}
.sync-meta-pre {
    margin: 0;
    padding: 8px;
    max-height: 200px;
    overflow: auto;
    font-size: 11px;
    line-height: 1.5;
    background: #fff;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Phase L Session 5 follow-up: side panel layout ─────────────────
 * The CRM card moves from a horizontal strip under the conversation
 * header to a right-rail aside (~300px). thread-active becomes flex:
 * .thread-main fills the left column with header/messages/composer,
 * the aside takes a fixed width on the right.
 *
 * Aside is hidden when no CRM is connected so non-CRM tenants see no
 * empty rail. Future follow-ups will add Contact + notes + activity
 * sections that make the aside always-visible.
 */
#thread-active {
    display: flex;
    flex-direction: row;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}
.thread-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.thread-side-panel {
    width: 300px;
    flex-shrink: 0;
    border-left: 1px solid var(--border, #e5e7eb);
    background: #fafbfc;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: width 0.15s ease;
}
/* Deepening (f): collapsed rail — thin strip, card hidden, « to reopen */
.thread-side-panel-header {
    display: flex;
    justify-content: flex-start;
    padding: 4px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
#side-panel-collapse {
    background: none;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #6b7280;
    padding: 1px 7px;
}
#side-panel-collapse:hover { background: #eef2f7; }
.thread-side-panel--collapsed { width: 30px; overflow: hidden; }
.thread-side-panel--collapsed .thread-crm-card { display: none; }
.thread-side-panel--collapsed .thread-side-panel-header {
    border-bottom: 0;
    justify-content: center;
    padding: 4px 2px;
}

/* The CRM card was a strip; now it's a side-panel section. Override the
 * Session 4 styles that gave it a bottom border + horizontal strip look. */
.thread-side-panel .thread-crm-card {
    background: transparent;
    border-bottom: 1px solid var(--border, #e5e7eb);
    padding: 12px;
    font-size: 13px;
}
.thread-side-panel .crm-card-header {
    margin-bottom: 10px;
}
.thread-side-panel .crm-card-link,
.thread-side-panel .crm-card-suggestion {
    background: white;
}

/* The scrollable inner list — sits between heading and the Create button,
 * which stays pinned below the scroll. */
.crm-card-suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 2px;
    margin-bottom: 6px;
}
.crm-card-suggestions-list::-webkit-scrollbar {
    width: 6px;
}
.crm-card-suggestions-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}
.crm-card-suggestions-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}
