/* ── Widget container ─────────────────────────────────────────── */
#sf-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Floating toggle button ───────────────────────────────────── */
#sf-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #50b3c8;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(80,179,200,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  color: white;
  font-size: 22px;
}
#sf-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 22px rgba(80,179,200,0.6);
}

/* ── Chat panel ───────────────────────────────────────────────── */
#sf-panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 390px;
  height: 580px;
  background: #f5f7fa;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sf-slide-in 0.22s cubic-bezier(0.16,1,0.3,1);
}
#sf-panel[hidden] { display: none; }

@keyframes sf-slide-in {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes sf-slide-out {
  from { opacity: 1; transform: translateY(0)    scale(1); }
  to   { opacity: 0; transform: translateY(18px) scale(0.97); }
}
#sf-panel.sf-closing {
  animation: sf-slide-out 0.18s ease forwards;
  pointer-events: none;
}

/* ── Header ───────────────────────────────────────────────────── */
#sf-header {
  background: #50b3c8;
  color: white;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.sf-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.sf-logo-wrap {
  background: white;
  border-radius: 6px;
  padding: 3px 7px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.sf-logo-wrap img { height: 24px; width: auto; display: block; }
#sf-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sf-status {
  font-size: 11px;
  opacity: 0.75;
  background: rgba(255,255,255,0.15);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  flex-shrink: 0;
}
#sf-status.connected { opacity: 1; background: rgba(255,255,255,0.25); }

#sf-clear, #sf-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.15s;
}
#sf-clear:hover, #sf-close:hover { background: rgba(255,255,255,0.28); }

/* ── Messages area ────────────────────────────────────────────── */
#sf-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#sf-messages::-webkit-scrollbar { width: 4px; }
#sf-messages::-webkit-scrollbar-track { background: transparent; }
#sf-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Message bubbles ──────────────────────────────────────────── */
.sf-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.sf-msg-user {
  align-self: flex-end;
  background: #e8f5f8;
  color: #1f2937;
  border: 1px solid #c5e8ef;
  border-bottom-right-radius: 4px;
}
.sf-msg-agent {
  align-self: flex-start;
  background: white;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.sf-msg-error {
  align-self: flex-start;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-bottom-left-radius: 4px;
  font-size: 13px;
}

/* Montos resaltados en verde lima */
.sf-amount {
  background: #f5f8d0;
  color: #5a6600;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 3px;
}

/* Markdown dentro de mensajes del agente */
.sf-msg-agent p  { margin: 0 0 8px; }
.sf-msg-agent p:last-child { margin-bottom: 0; }
.sf-msg-agent ul, .sf-msg-agent ol { margin: 4px 0 8px 18px; padding: 0; }
.sf-msg-agent li { margin-bottom: 2px; }
.sf-msg-agent strong { font-weight: 600; }
.sf-msg-agent h3 { font-size: 13px; margin: 10px 0 4px; color: #374151; }
.sf-msg-agent code {
  background: #f3f4f6; border-radius: 3px;
  padding: 1px 4px; font-size: 12px;
}

/* Tablas */
.sf-msg-agent table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  margin: 6px 0;
}
.sf-msg-agent th {
  background: #e8f5f8;
  padding: 5px 8px;
  text-align: left;
  font-weight: 600;
  color: #1f2937;
}
.sf-msg-agent td {
  padding: 4px 8px;
  border-bottom: 1px solid #e5e7eb;
}
.sf-msg-agent tr:last-child td { border-bottom: none; }
.sf-msg-agent tr:nth-child(even) td { background: #f9fafb; }

/* ── Thinking / tool status ───────────────────────────────────── */
.sf-thinking-wrap {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  max-width: 88%;
}
.sf-thinking-label {
  font-size: 13px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.sf-thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}
.sf-thinking-dots span {
  width: 6px;
  height: 6px;
  background: #50b3c8;
  border-radius: 50%;
  animation: sf-bounce 1.2s ease-in-out infinite;
}
.sf-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.sf-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sf-bounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.4; }
  40%           { transform: scale(1);    opacity: 1; }
}

/* ── Confirmation card ────────────────────────────────────────── */
.sf-msg-confirm {
  align-self: stretch;
  max-width: 100%;
  background: white;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #50b3c8;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.sf-msg-confirm[data-type="update"]  { border-left-color: #bfd020; }
.sf-msg-confirm[data-type="convert"] { border-left-color: #8b5cf6; }
.sf-msg-confirm[data-type="handoff"] { border-left-color: #f59e0b; }
.sf-msg-confirm[data-type="create"]  { border-left-color: #50b3c8; }

.sf-confirm-title {
  font-weight: 700;
  font-size: 13px;
  color: #1f2937;
  margin-bottom: 8px;
}
.sf-confirm-params {
  font-size: 12px;
  color: #374151;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 110px;
  overflow-y: auto;
}
.sf-param b { color: #6b7280; font-weight: 600; }
.sf-confirm-actions { display: flex; gap: 8px; }

.sf-btn-yes, .sf-btn-no {
  padding: 6px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.sf-btn-yes { background: #bfd020; color: #1f2937; }
.sf-btn-no  { background: #e5e7eb; color: #374151; }
.sf-btn-yes:hover { opacity: 0.88; transform: translateY(-1px); }
.sf-btn-no:hover  { opacity: 0.8;  transform: translateY(-1px); }

.sf-confirmed { color: #15803d; font-size: 13px; font-weight: 600; }
.sf-cancelled { color: #991b1b; font-size: 13px; font-weight: 600; }

/* ── Input area ───────────────────────────────────────────────── */
#sf-input-area {
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: white;
}
#sf-input {
  flex: 1;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  background: #f9fafb;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
}
#sf-input:focus  { border-color: #50b3c8; background: white; }
#sf-input:disabled { background: #f3f4f6; color: #9ca3af; }

#sf-send {
  background: #50b3c8;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s;
  flex-shrink: 0;
  font-family: inherit;
}
#sf-send:hover:not(:disabled) { opacity: 0.88; }
#sf-send:disabled { background: #9ca3af; cursor: default; }

/* ── Footer ───────────────────────────────────────────────────── */
#sf-footer {
  text-align: center;
  font-size: 10px;
  color: #9ca3af;
  padding: 5px 0 7px;
  flex-shrink: 0;
  background: white;
  letter-spacing: 0.03em;
}

/* ── Restore divider ─────────────────────────────────────────── */
.sf-divider {
  text-align: center;
  font-size: 10px;
  color: #94a3b8;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sf-divider::before, .sf-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

/* ── Sources ──────────────────────────────────────────────────── */
.sf-sources {
  font-size: 11px;
  color: #9ca3af;
  padding: 0 2px 2px 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
}
.sf-sources::before {
  content: '⊞';
  font-size: 10px;
  opacity: 0.7;
}

/* ── Suggestion pills ─────────────────────────────────────────── */
.sf-suggestions {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 4px;
  max-width: 100%;
}
.sf-suggestion-pill {
  background: #f0fafe;
  border: 1px solid #b8e9f3;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  color: #1f5566;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: inherit;
  text-align: left;
  line-height: 1.4;
}
.sf-suggestion-pill:hover {
  background: #d0f0f7;
  border-color: #50b3c8;
  transform: translateY(-1px);
}

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #sf-widget { bottom: 16px; right: 16px; }
  #sf-panel {
    width: calc(100vw - 32px);
    height: calc(90vh - 80px);
    right: 0;
    bottom: 68px;
  }
}
