:root {
  --bg: #f5f5f5;
  --bg-deep: #ffffff;
  --panel: rgba(255, 255, 255, 0.98);
  --text: #1a1a1a;
  --muted: #666666;
  --accent: #000000;
  --accent-dark: #333333;
  --ok: #404040;
  --line: rgba(0, 0, 0, 0.1);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  --widget-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(130deg, var(--bg) 0%, var(--bg-deep) 100%);
}

.shell {
  width: min(800px, calc(100% - 2rem));
  margin: 4rem auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.intro-header {
  padding: 3rem 2.5rem 2.5rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.control-panel {
  padding: 2.5rem;
  background: #fcfcfc;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

h1,
h2 {
  margin: 0.5rem 0 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h1 {
  font-size: 2.2rem;
}

h2 {
  font-size: 1.4rem;
  margin-top: 0;
}

.intro-copy {
  margin: 0;
  color: var(--text);
  line-height: 1.6;
  font-size: 1.05rem;
}

.chips {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip {
  background: #f0f0f0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.stats-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-badge {
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--text);
}

.turn-badge {
  color: var(--muted);
  background: #f5f5f5;
}

.conversation-tools label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.tool-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.conversation-tools input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-family: monospace;
  font-size: 0.95rem;
}

.conversation-tools input:focus {
  outline: none;
  border-color: var(--accent);
}

.conversation-tools button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.conversation-tools button:hover {
  background: #f5f5f5;
}

.conversation-tools button.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.conversation-tools button.btn-primary:hover {
  background: var(--accent-dark);
}

.help-text {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 1rem;
}

.help-text code {
  background: #eee;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

/* WIDGET FLOTANTE */
.chat-widget {
  position: fixed;
  bottom: 90px;
  right: 30px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--widget-shadow);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

.chat-widget.hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  border-radius: 16px 16px 0 0;
}

.widget-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.close-btn:hover {
  background: #f0f0f0;
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: #fafafa;
}

.msg {
  width: fit-content;
  max-width: 85%;
  margin: 0.8rem 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  transform: translateY(4px);
  opacity: 0;
  animation: pop 200ms ease forwards;
  font-size: 0.95rem;
}

.msg--user {
  margin-left: auto;
  background: #000;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.msg--user .msg-meta {
  color: rgba(255, 255, 255, 0.7);
}

.msg--agent {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
  border-bottom-left-radius: 2px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.msg--system {
  background: transparent;
  border: 1px dashed var(--line);
  margin-left: auto;
  margin-right: auto;
  font-size: 0.8rem;
  text-align: center;
  color: var(--muted);
}

.msg-meta {
  margin: 0 0 0.4rem 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.msg-body {
  margin: 0;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-attachment {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.85rem;
}

.msg--agent .msg-attachment {
  border-top-color: var(--line);
}

.msg-image-preview {
  max-width: 100%;
  max-height: 160px;
  border-radius: 6px;
  display: block;
  object-fit: contain;
}

/* TYPING INDICATOR */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.5rem 0.2rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing {
  0%, 80%, 100% { 
    transform: scale(0);
  } 40% { 
    transform: scale(1);
  }
}

.modern-composer {
  padding: 0.8rem;
  background: #fff;
  border-top: 1px solid var(--line);
  border-radius: 0 0 16px 16px;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: #f4f4f4;
  border: 1px solid transparent;
  border-radius: 24px;
  padding: 0.4rem;
  transition: all 0.2s;
}

.composer-inner:focus-within,
.composer-inner.dragover {
  border-color: var(--line);
  background: #fff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.circle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.circle-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #000;
}

.circle-btn.send-btn {
  background: #000;
  color: #fff;
}

.circle-btn.send-btn:hover:not(:disabled) {
  background: #333;
}

.circle-btn.send-btn:disabled {
  background: #e5e5e5;
  color: #a3a3a3;
  cursor: not-allowed;
}

.input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.2rem 0;
  min-width: 0;
}

textarea {
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  max-height: 120px;
  padding: 0.2rem 0;
  color: var(--text);
  overflow-y: auto;
}

textarea:focus {
  outline: none;
}

textarea::placeholder {
  color: #888;
}

.receipt-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #e5e5e5;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  width: fit-content;
  max-width: 100%;
}

.receipt-badge.hidden {
  display: none;
}

.receipt-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receipt-badge button {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  padding: 0;
}

.receipt-badge button:hover {
  color: #000;
}

.status-text {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.4rem;
  min-height: 14px;
}

/* BOTÓN FLOTANTE (FAB) */
.fab-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s;
}

.fab-btn:hover {
  transform: scale(1.08);
  background: var(--accent-dark);
}

.fab-btn:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .shell {
    margin: 1rem auto;
  }
  
  .tool-row {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-widget {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  
  .widget-header {
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 1rem);
  }
  
  .modern-composer {
    padding-bottom: env(safe-area-inset-bottom, 0.8rem);
    border-radius: 0;
  }

  .fab-btn {
    bottom: 20px;
    right: 20px;
  }
}

@keyframes rise {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pop {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}