:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --ink: #2c2c2c;
  --muted: #796f66;
  --line: #eadfd2;
  --orange: #d97706;
  --teal: #0f766e;
  --danger: #dc2626;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; font-weight: 800; }
button:disabled { cursor: not-allowed; opacity: .55; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
.eyebrow { color: var(--teal); font-weight: 900; text-transform: uppercase; letter-spacing: .05em; font-size: 12px; }

.auth-card {
  width: min(420px, calc(100vw - 32px));
  margin: 10vh auto;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(44,44,44,.11);
}
.field, .stack { display: grid; gap: 8px; margin: 14px 0; }
label { font-weight: 800; font-size: 13px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
.primary, .secondary, .danger, .tiny {
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 14px;
}
.primary { background: var(--orange); color: #fff; }
.secondary { background: #fff; color: var(--teal); border: 1px solid rgba(15,118,110,.42); }
.danger { background: #fff1f1; color: var(--danger); border: 1px solid rgba(220,38,38,.28); }
.tiny { min-height: 32px; padding: 6px 10px; background: var(--teal); color: #fff; border-radius: 999px; }

.shell {
  display: grid;
  grid-template-columns: 320px minmax(460px, 1fr) 320px;
  height: 100vh;
}
.shell.tools-collapsed { grid-template-columns: 320px minmax(460px, 1fr) 58px; }
.sidebar, .tools {
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,.65);
  overflow: auto;
}
.tools { border-left: 1px solid var(--line); border-right: 0; padding: 16px; }
.tools-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.tools-collapse { width: 38px; min-width: 38px; height: 38px; border-radius: 12px; background: #fff; color: var(--teal); border: 1px solid var(--line); font-size: 24px; line-height: 1; }
.shell.tools-collapsed .tools { padding: 10px; overflow: hidden; }
.shell.tools-collapsed .tools-header { justify-content: center; }
.shell.tools-collapsed #tools-content, .shell.tools-collapsed #settings-button { display: none !important; }
.shell.tools-collapsed .tools-collapse { transform: rotate(180deg); }
.brand { display: flex; gap: 12px; align-items: center; padding: 20px; border-bottom: 1px solid var(--line); }
.brand > div:last-child { min-width: 0; }
.brand strong, .brand span { overflow-wrap: anywhere; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center; color: #fff; background: var(--orange); font-weight: 900;
}
.status-card, .panel {
  margin: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.panel { margin: 0 0 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.pill { background: #fff1e5; color: var(--orange); padding: 5px 10px; border-radius: 999px; font-weight: 900; font-size: 12px; }
.presence-pill.online { background: #e5f7ef; color: var(--teal); }
.presence-pill.offline { background: #f3f1ef; color: var(--muted); }
.presence-panel h3, .presence-panel p { margin: 0; }
.presence-panel button { width: 100%; margin-top: 12px; }
.filters { display: flex; gap: 8px; padding: 0 16px 12px; }
.filters { flex-wrap: wrap; }
.filters button {
  background: #fff; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 8px 10px; font-size: 12px;
}
.filters button.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.search { width: calc(100% - 32px); margin: 0 16px 12px; }
.chat-list { padding: 0 12px 16px; display: grid; gap: 8px; }
.chat-item {
  text-align: left;
  padding: 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
}
.chat-item.active { border-color: var(--orange); background: #fff3df; }
.chat-item { min-width: 0; overflow: hidden; }
.chat-item strong, .chat-item span { display: block; white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.chat-item .chat-item-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.chat-item-title .visitor-name { display: flex; align-items: center; min-width: 0; gap: 8px; margin-top: 0; }
.chat-item-title strong { min-width: 0; }
.channel-icon { flex: 0 0 22px; width: 22px; height: 22px; display: grid !important; place-items: center; border-radius: 7px; margin-top: 0 !important; }
.channel-icon.website { color: #087f8c; background: #e5f8f7; }
.channel-icon.whatsapp { color: #148a52; background: #e5f7ed; }
.channel-icon.telegram { color: #168dcc; background: #e4f5fd; }
.channel-icon.facebook { color: #0866ff; background: #e8f0ff; }
.channel-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.channel-icon.whatsapp svg path:first-of-type { fill: currentColor; stroke: none; }
.channel-icon.whatsapp svg path:last-of-type { stroke: #fff; stroke-width: 1.15; }
.channel-icon.telegram svg path { fill: currentColor; stroke: none; }
.channel-icon.facebook svg path:first-of-type { fill: currentColor; stroke: none; }
.channel-icon.facebook svg path:last-of-type { fill: #fff; stroke: none; }
.chat-item .escalation-mark { flex: 0 0 22px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; background: var(--danger); color: #fff; font-size: 13px; font-weight: 900; overflow-wrap: normal; }
.chat-item span { color: var(--muted); font-size: 12px; margin-top: 4px; }

.conversation {
  display: grid;
  grid-template-areas: "header" "notice" "messages" "brief" "composer";
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.conversation-header {
  grid-area: header;
  padding: 18px 22px;
  background: rgba(255,248,240,.9);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}
.conversation-header h2 { margin: 0; }
.conversation-header p { margin: 4px 0 0; }
.conversation-header > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.header-actions, .composer-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.messages { grid-area: messages; padding: 22px; overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.message {
  max-width: min(720px, 84%);
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.message.in { align-self: flex-start; }
.message.out { align-self: flex-end; background: #e7f4f2; border-color: rgba(15,118,110,.2); }
.message.agent { align-self: flex-end; background: #fff1e5; border-color: rgba(217,119,6,.24); }
.message small { display: block; color: var(--muted); margin-top: 8px; }
.message-body { margin-top: 7px; }
.message-media-link { display: block; }
.message-media { display: block; width: min(360px, 100%); max-height: 420px; object-fit: contain; border-radius: 12px; background: rgba(0,0,0,.04); }
.message-media.sticker { width: min(180px, 100%); max-height: 180px; background: transparent; }
.attachment-button{cursor:pointer}.message-file{display:inline-flex;gap:7px;color:var(--teal);font-weight:700;text-decoration:none}.message-body strong{font-weight:750}
.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.message-reactions span { padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 16px; line-height: 1.2; }
.conversation-separator { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 800; margin: 10px 0; }
.previous-session{border:1px solid var(--line);border-radius:12px;background:var(--bg)}.previous-session>summary{padding:11px 14px;cursor:pointer;color:var(--muted);font-size:12px;font-weight:800}.previous-session-messages,.current-session{display:flex;flex-direction:column;gap:12px}.previous-session-messages{padding:12px;border-top:1px solid var(--line)}.messages{overflow-anchor:none}
.conversation-separator::before, .conversation-separator::after { content: ''; height: 1px; background: var(--line); flex: 1; }
.conversation-separator span { text-align: center; }
.issue-brief { grid-area: brief; margin: 0 16px 10px; padding: 12px 14px; border: 1px solid #f0b84b; border-radius: 14px; background: #fffaf0; max-height: 150px; overflow: auto; }
.issue-brief > div { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.issue-brief span { color: var(--orange); font-size: 12px; font-weight: 800; overflow-wrap: anywhere; }
.issue-brief p { margin: 7px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { grid-area: composer; border-top: 1px solid var(--line); padding: 16px; background: rgba(255,255,255,.75); }
.composer textarea { min-height: 80px; }
.composer-actions { justify-content: flex-end; margin-top: 10px; }
.suggestion {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(15,118,110,.22);
  background: #e7f4f2;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.suggestion-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 8px; }
.suggestion-head span { color: var(--muted); font-size: 12px; }
.suggestion-body { white-space: pre-wrap; }
.suggestion-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.button-spinner { display: none; width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }
#ask-rag.loading .button-spinner { display: inline-block; animation: spin .7s linear infinite; }
#ask-rag.loading { cursor: wait; }
@keyframes spin { to { transform: rotate(360deg); } }
.feedback-modal { width: min(560px, calc(100vw - 28px)); }
.feedback-modal fieldset { border: 0; padding: 0; margin: 20px 0; }
.feedback-modal legend { font-weight: 800; margin-bottom: 12px; }
.score-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.score-options label { cursor: pointer; }
.score-options input { position: absolute; opacity: 0; pointer-events: none; }
.score-options span { min-height: 58px; display: grid; place-items: center; align-content: center; border: 1px solid var(--line); border-radius: 12px; font-weight: 900; background: #fff; }
.score-options small { display: block; color: var(--muted); font-size: 9px; font-weight: 600; }
.score-options input:checked + span { border-color: var(--teal); background: #e7f4f2; color: var(--teal); box-shadow: 0 0 0 2px rgba(15,118,110,.12); }
.score-options input:focus-visible + span { outline: 3px solid rgba(15,118,110,.25); }
#feedback-note { min-height: 84px; margin-top: 7px; }
@media (prefers-reduced-motion: reduce) { .button-spinner { animation-duration: 1.5s; } }
.escalation-notice { grid-area: notice; margin: 10px 16px 0; padding: 10px 12px; border: 1px solid #f0b84b; background: #fff5d9; border-radius: 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; }
.escalation-notice strong, .escalation-notice span { display: block; overflow-wrap: anywhere; }
.escalation-notice span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.notice-close, .panel-collapse { background: transparent; color: var(--muted); padding: 6px; }
.notice-close { font-size: 20px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading h3 { margin: 0; }
.panel-collapse { font-size: 12px; color: var(--teal); }
.connection-panel.collapsed { padding-bottom: 16px; }
.qr-box {
  min-height: 160px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
  padding: 12px;
}
.qr-box img { max-width: 100%; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: #fff8f0; border-radius: 14px; padding: 10px; }
.stat strong { display: block; font-size: 20px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--muted); }
.check input { width: auto; }
.modal { min-width: min(460px, 90vw); }
dialog { border: 0; border-radius: 22px; padding: 22px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,.2); max-height: 90vh; overflow: auto; }
.provider-card { border: 1px solid var(--line); border-radius: 16px; padding: 2px 14px; margin: 12px 0; }
.modal hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.key-meta { color: var(--teal); font-weight: 800; }
.learning-list { display: grid; gap: 10px; }
.learning-item, .learning-compose { border: 1px solid var(--line); border-radius: 14px; padding: 11px; background: #fff; }
.learning-compose { margin: 12px 0; border-color: rgba(15,118,110,.35); }
.learning-item summary, .learning-compose summary { cursor: pointer; font-weight: 850; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.learning-item[open] summary, .learning-compose[open] summary { margin-bottom: 12px; }
.learning-item label, .learning-compose label { display: grid; gap: 5px; margin: 9px 0; font-size: 11px; color: var(--muted); }
.learning-item textarea, .learning-compose textarea { min-height: 78px; padding: 9px 10px; border-radius: 10px; font-size: 12px; line-height: 1.45; }
.learning-filter { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--muted); }
.learning-filter select { padding: 8px 10px; border-radius: 10px; }
.learning-actions { margin-top: 10px; flex-wrap: wrap; }
.learning-note { min-height: 18px; margin: 8px 0 0; color: var(--teal); font-size: 12px; font-weight: 700; }
.test-chat-modal { width: min(980px, 92vw); }
.test-chat-modal h2, .test-chat-modal p { margin: 0 0 6px; }
.test-chat-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; margin-top: 14px; }
.test-history { border-right: 1px solid var(--line); padding-right: 14px; min-height: 520px; }
.test-thread-list { display: grid; gap: 7px; margin-top: 12px; max-height: 500px; overflow: auto; }
.test-thread-row { display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 3px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.test-thread-row.active { border-color: var(--teal); background: #effbf8; }
.test-thread { border: 0; background: transparent; text-align: left; padding: 9px; min-width: 0; cursor: pointer; }
.test-thread strong, .test-thread small { display: block; overflow-wrap: anywhere; word-break: break-word; }
.test-thread small { color: var(--muted); margin-top: 3px; }
.test-thread-delete { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; }
.test-thread-delete:hover { color: #a72b2b; background: #fff0f0; }
.test-chat-main { min-width: 0; }
.test-messages { height: min(440px, 50vh); overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; }
.test-help { font-size: 12px; }
.test-progress { color: var(--teal); font-weight: 800; }
.activity-log { max-height: 180px; overflow: auto; display: grid; gap: 6px; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.insights-open{width:100%;margin-top:12px}.insights-modal{width:min(1050px,calc(100vw - 32px));max-height:88vh;overflow:auto}.insights-modal h2{margin:3px 0}.insights-toolbar{display:flex;align-items:center;justify-content:space-between;gap:16px;margin:20px 0}.insights-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}.insight-list,.page-ranking{display:grid;gap:10px}.insight-card,.page-rank{border:1px solid var(--line);border-radius:14px;padding:14px;background:#fff}.insight-card header,.page-rank{display:flex;justify-content:space-between;gap:12px}.insight-card p{margin:8px 0 0;font-size:13px;line-height:1.45}.insight-card b{color:var(--teal)}.insight-count{white-space:nowrap;color:var(--muted);font-size:12px}.page-rank a{color:var(--teal);font-weight:750;text-decoration:none}.insights-toolbar .primary{width:auto}.insights-toolbar .primary.loading .button-spinner{display:inline-block;animation:spin .7s linear infinite}@media(max-width:760px){.insights-grid{grid-template-columns:1fr}}
.insights-toolbar>div{display:flex;gap:9px}.download-insights{display:inline-flex;align-items:center;text-decoration:none}.insight-table{border:1px solid var(--line);border-radius:14px;overflow:hidden;margin-bottom:24px}.insight-table-head,.insight-row summary{display:grid;grid-template-columns:58px minmax(220px,2fr) 90px minmax(160px,1fr) 28px;gap:12px;align-items:center}.insight-table-head{padding:10px 14px;background:var(--bg);color:var(--muted);font-size:11px;font-weight:800;text-transform:uppercase;letter-spacing:.04em}.insight-row{border-top:1px solid var(--line);background:#fff}.insight-row:first-of-type{border-top:0}.insight-row summary{padding:14px;cursor:pointer;list-style:none}.insight-row summary::-webkit-details-marker{display:none}.rank-number{width:30px;height:30px;border-radius:8px;background:#fff3df;color:#a45800;display:grid;place-items:center;font-weight:900}.asked-by-summary{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--muted);font-size:12px}.expand-mark{font-size:18px;transition:transform .15s}.insight-row[open] .expand-mark{transform:rotate(180deg)}.insight-detail{border-top:1px solid var(--line);padding:16px 72px;background:#fffcf8}.insight-detail dl{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin:0}.insight-detail dl div{padding:12px;border:1px solid var(--line);border-radius:10px;background:#fff}.insight-detail dt{color:var(--teal);font-size:11px;font-weight:850;text-transform:uppercase}.insight-detail dd{margin:5px 0 0;font-size:13px;line-height:1.45}.insight-evidence{margin-top:14px}.insight-evidence>p{font-size:13px}.insight-evidence blockquote{margin:8px 0;padding:10px 12px;border-left:3px solid var(--teal);background:#fff}.insight-evidence blockquote span,.insight-evidence blockquote small{display:block}.insight-evidence blockquote small{color:var(--muted);margin-top:5px}@media(max-width:760px){.insight-table-head{display:none}.insight-row summary{grid-template-columns:42px 1fr 55px 24px}.asked-by-summary{grid-column:2/4}.insight-detail{padding:14px}.insight-detail dl{grid-template-columns:1fr}.insights-toolbar{align-items:flex-start}.insights-toolbar>div{flex-direction:column}}
.activity-log div { padding-bottom: 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .shell { grid-template-columns: 1fr; height: auto; }
  .shell.tools-collapsed { grid-template-columns: 1fr; }
  .sidebar, .tools { border: 0; }
  .conversation { min-height: 70vh; }
  .messages { max-height: 60vh; }
  .test-chat-layout { grid-template-columns: 1fr; }
  .test-history { min-height: 0; border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; }
  .test-thread-list { max-height: 150px; }
}
