/* AI assistant (R1) styles — loaded after app.css. */
:root { --ai: #c98a00; --ai-soft: #fff6e0; --ai-border: #e9c66a; --ai-text: #7a5400; }
@media (prefers-color-scheme: dark) {
  :root { --ai: #e3b341; --ai-soft: #2a2412; --ai-border: #5c4a1c; --ai-text: #e3b341; }
}

/* Outbound AI bubble + "AI" tag */
.bubble.ai { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ai) 45%, transparent); }
.ai-tag { display: inline-flex; align-items: center; gap: 3px; font-weight: 700;
  color: var(--ai-text); background: var(--ai-soft); border: 1px solid var(--ai-border);
  border-radius: 6px; padding: 0 4px; margin-right: 5px; font-size: 10px; vertical-align: middle; }
.ai-tag svg { width: 12px; height: 12px; }

/* AI "is typing…" bubble shown while the agent generates a reply */
.ai-typing-row { animation: ai-typing-in .2s ease both; }
@keyframes ai-typing-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.bubble.ai-typing { display: inline-flex; align-items: center; gap: 8px; }
.ai-typing-label { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; color: var(--ai-text); }
.ai-typing-label svg { width: 12px; height: 12px; }
.typing-dots { display: inline-flex; align-items: center; gap: 3px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--ai); opacity: .4; animation: typing-bounce 1.3s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Bubble row stacks the (top) debug block above the bubble */
.bubble-row { flex-direction: column; }
.bubble-row.out { align-items: flex-end; }
.bubble-row.in { align-items: flex-start; }

/* Yellow collapsible AI debug trail (agents only) */
.ai-debug { max-width: min(78%, 540px); margin: 0 0 3px; font-size: 11.5px;
  background: var(--ai-soft); border: 1px solid var(--ai-border); border-radius: 10px; color: var(--ai-text); }
.ai-debug > summary { cursor: pointer; padding: 5px 9px; list-style: none; display: flex; align-items: center; gap: 5px;
  font-weight: 600; user-select: none; }
.ai-debug > summary::-webkit-details-marker { display: none; }
.ai-debug[open] > summary { border-bottom: 1px solid var(--ai-border); }
.ai-dbg-body { padding: 7px 9px; display: flex; flex-direction: column; gap: 7px; }
.ai-dbg-sec .ai-dbg-h { font-weight: 700; margin-bottom: 2px; }
.ai-dbg-body pre { margin: 0; white-space: pre-wrap; word-break: break-word;
  background: color-mix(in srgb, var(--ai) 8%, transparent); padding: 5px 6px; border-radius: 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; color: var(--text); }
.ai-dbg-meta { opacity: .75; font-size: 10.5px; }

/* Inbox: needs-help chip, lead chips & dots, help pill */
.seg-help[aria-pressed="true"] { color: var(--ai); }
.help-count { background: var(--ai); color: #04141f; border-radius: 9px; padding: 0 5px; font-size: 10px; font-weight: 700; margin-left: 4px; }
.lead-chip[aria-pressed="true"].lead-hot { background: rgba(229,72,77,.16); color: #ff8a90; border-color: rgba(229,72,77,.4); }
.lead-chip[aria-pressed="true"].lead-warm { background: var(--ai-soft); color: var(--ai-text); border-color: var(--ai-border); }
.lead-chip[aria-pressed="true"].lead-cold { background: rgba(8,168,249,.16); color: var(--accent); border-color: var(--accent-ring); }
.conv.needs-help { box-shadow: inset 3px 0 0 var(--ai); }
.lead-tag { flex: 0 0 auto; display: inline-flex; align-items: center; font-size: 9.5px; font-weight: 800;
  letter-spacing: .04em; line-height: 1; padding: 3px 6px; border-radius: 5px; border: 1px solid transparent; }
.lead-tag.lead-hot { background: rgba(229,72,77,.16); color: #ff8a90; border-color: rgba(229,72,77,.4); }
.lead-tag.lead-warm { background: var(--ai-soft); color: var(--ai-text); border-color: var(--ai-border); }
.lead-tag.lead-cold { background: rgba(8,168,249,.16); color: var(--accent); border-color: var(--accent-ring); }
.help-pill { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700;
  color: var(--ai-text); background: var(--ai-soft); border: 1px solid var(--ai-border); border-radius: 6px; padding: 0 5px; }

/* Contact panel AI section */
.ai-section .ai-lead { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.lead-pill { font-size: 10.5px; font-weight: 800; border-radius: 6px; padding: 1px 6px; color: #fff; }
.lead-pill.lead-hot { background: #e5484d; }
.lead-pill.lead-warm { background: var(--ai); }
.lead-pill.lead-cold { background: #3b82f6; }
.ai-lead-intent { font-size: 13px; color: var(--text); }
.ai-lead-reason { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.ai-status { font-weight: 600; }
.ai-status-needs_human { color: var(--ai-text); }
.ai-status-auto { color: var(--brand); }
.ai-summary { margin: 8px 0; background: var(--ai-soft); border: 1px solid var(--ai-border); border-radius: 10px; padding: 8px 10px; }
.ai-summary-h { display: flex; align-items: center; gap: 5px; font-weight: 700; font-size: 12px; color: var(--ai-text); margin-bottom: 4px; }
.ai-summary-b { font-size: 12.5px; color: var(--text); white-space: pre-wrap; }
.ai-flag { display: flex; align-items: center; gap: 5px; color: #b42318; font-size: 12px; font-weight: 600; margin: 6px 0; }
.ai-controls { display: flex; gap: 8px; margin-top: 8px; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }

/* AI modal */
/* AI modal title: align the sparkle icon with the text */
.modal-head h3 { display: inline-flex; align-items: center; gap: 8px; }
.modal-head h3 svg { flex: 0 0 auto; }
.modal-tabs { display: flex; gap: 4px; padding: 0 22px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab-btn { background: none; border: none; padding: 13px 14px; font: inherit; color: var(--text-soft); cursor: pointer; border-bottom: 2px solid transparent; transition: color var(--speed) var(--ease); }
.tab-btn:hover { color: var(--text); }
.tab-btn[aria-pressed="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.ai-section-block { margin-bottom: 22px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.ai-section-block:last-of-type { border-bottom: none; }
.ai-section-block h4 { margin: 0 0 12px; font-size: 12px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; }
.ai-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; }
.ai-row-t { font-weight: 600; }
.ai-row-h { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.ai-field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.ai-field-l { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.modal-foot { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 0 4px; border-top: 1px solid var(--border); margin-top: 12px; background: var(--surface); }
.field-ok { color: var(--brand); font-size: 12px; display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.input-time { width: auto; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; }
.switch-input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 999px; transition: .15s; }
.switch-slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch-input:checked + .switch-slider { background: var(--brand); border-color: var(--brand); }
.switch-input:checked + .switch-slider::before { transform: translateX(18px); }

/* Channels & accounts */
.ai-channels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .ai-channels { grid-template-columns: 1fr; } }
.ai-channel { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.ai-acct-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }
.ai-acct-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.bh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 10px; }
@media (max-width: 640px) { .bh-grid { grid-template-columns: 1fr; } }
.bh-day { display: flex; align-items: center; gap: 8px; }
.bh-label { width: 38px; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--text-faint); }
.input-time { padding: 7px 9px; }

/* AI test */
.ai-test-row { display: flex; gap: 8px; }
.ai-test-row .input { flex: 1; }
.ai-test-out { margin-top: 10px; background: var(--surface-3); border-radius: 10px; padding: 10px; }
.ai-test-reply { white-space: pre-wrap; }
.ai-test-tools, .ai-test-meta { font-size: 12px; color: var(--text-soft); margin-top: 6px; }

/* Knowledge base */
.kb-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.kb-row { display: flex; gap: 10px; justify-content: space-between; padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
.kb-title { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.kb-type { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 1px 5px; border-radius: 5px; background: var(--brand-soft); color: var(--brand-strong); }
.kb-body { font-size: 12.5px; color: var(--text-soft); margin-top: 4px; }
.kb-file { font-size: 12px; color: var(--text-soft); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.kb-actions { display: flex; align-items: center; gap: 6px; }
.kb-form { display: flex; flex-direction: column; gap: 12px; }
.kb-drop { display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px; text-align: left;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--bg-deep);
  color: var(--text-soft); transition: all var(--speed) var(--ease); }
.kb-drop:hover, .kb-drop.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.kb-drop.done { border-style: solid; border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.kb-drop.done .kb-drop-ico { color: var(--success); }
.kb-drop.uploading { opacity: .7; }
.kb-drop-ico { display: inline-flex; width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  align-items: center; justify-content: center; background: var(--surface-3); color: var(--accent); }
.kb-drop-ico svg { width: 18px; height: 18px; }
.kb-drop-text { font-size: 13.5px; }
.kb-row { background: var(--surface-2); }
.kb-row:hover { border-color: var(--border-strong); }
.kb-type { background: var(--accent-soft); color: var(--accent); }
