/* ==============================================================================
   NIDIX CHAT GATEWAY - ULTRA-LIGHTWEIGHT CSS DESIGN SYSTEM
   Modern, Mobile-First, OLED-optimized Dark Mode (< 15KB, No External Dependencies)
   ============================================================================== */

:root {
  --primary: #0066ff;
  --primary-hover: #0052cc;
  --primary-gradient: linear-gradient(135deg, #0066ff 0%, #0047b3 100%);
  --user-bubble-gradient: linear-gradient(135deg, #0066ff 0%, #1e40af 100%);
  
  --bg-main: #0a0f1d;
  --bg-surface: #111827;
  --bg-card: #1f293d;
  --bg-card-hover: #26354f;
  --bg-input: #151e30;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(0, 102, 255, 0.5);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-link: #38bdf8;

  --status-online: #10b981;
  --status-queued: #f59e0b;
  --status-closed: #6b7280;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(0, 102, 255, 0.35);

  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --header-height: 64px;
  --banner-height: 38px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Chat App Container */
.chat-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-main);
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}

@media (max-width: 600px) {
  .chat-app {
    border: none;
  }
}

/* Top App Header */
.chat-header {
  height: var(--header-height);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0);
  z-index: 10;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-container {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.avatar-icon {
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  letter-spacing: -0.5px;
}

.status-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 13px;
  height: 13px;
  border-radius: var(--radius-full);
  background-color: var(--status-online);
  border: 2.5px solid var(--bg-surface);
}

.status-badge.pulse::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  background: inherit;
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

.header-info {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.verified-icon {
  width: 16px;
  height: 16px;
  fill: var(--primary);
}

.header-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Client Context Banner */
.context-banner {
  background: linear-gradient(90deg, #131c31 0%, #17233d 100%);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.context-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-tag {
  background: rgba(0, 102, 255, 0.2);
  color: #60a5fa;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.75rem;
}

/* Chat Messages Flow */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

/* Message Bubbles */
.message-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.25s ease-out forwards;
}

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

.message-row.client {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.bot,
.message-row.agent {
  align-self: flex-start;
  align-items: flex-start;
}

.sender-label {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  margin-left: 8px;
  color: var(--text-muted);
}

.message-row.agent .sender-label {
  color: #60a5fa;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-line;
  position: relative;
  box-shadow: var(--shadow-sm);
}

/* Client bubble: blue gradient, rounded corners */
.message-row.client .message-bubble {
  background: var(--user-bubble-gradient);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* Bot bubble: dark card with subtle blue hint */
.message-row.bot .message-bubble {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

/* Agent bubble: slate card */
.message-row.agent .message-bubble {
  background-color: #1a253a;
  color: var(--text-primary);
  border: 1px solid rgba(0, 102, 255, 0.2);
  border-bottom-left-radius: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  margin-top: 4px;
  color: var(--text-muted);
  padding: 0 4px;
}

.message-row.client .message-meta {
  color: rgba(255, 255, 255, 0.6);
}

/* System Notifications inside chat */
.system-notice {
  align-self: center;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  margin: 6px 0;
  text-align: center;
  max-width: 90%;
  animation: fadeIn 0.3s ease;
}

/* Triage Quick Action Chips / Buttons */
.triage-options-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  width: 100%;
}

.triage-chip {
  background: rgba(0, 102, 255, 0.08);
  border: 1px solid rgba(0, 102, 255, 0.35);
  color: #60a5fa;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.triage-chip:hover {
  background: rgba(0, 102, 255, 0.2);
  border-color: #0066ff;
  color: #93c5fd;
  transform: translateY(-1px);
}

.triage-chip:active {
  transform: scale(0.98);
}

.triage-chip.disabled {
  opacity: 0.5;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border-subtle);
  color: var(--text-muted);
}

.chip-arrow {
  opacity: 0.7;
  font-size: 14px;
}

/* Typing Indicator */
.typing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  margin-top: 2px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #60a5fa;
  border-radius: var(--radius-full);
  animation: typingBounce 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 typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.typing-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Input Area */
.chat-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px 14px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(0, 102, 255, 0.15);
}

.chat-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  padding: 8px 4px;
  max-height: 100px;
  resize: none;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--primary-gradient);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.35);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

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

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.send-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  margin-left: 2px;
}

/* Botón de Adjuntos (Comprobantes / Fotos) */
.attach-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-right: 4px;
  flex-shrink: 0;
}

.attach-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.attach-btn:active {
  transform: scale(0.92);
}

/* Imágenes dentro de burbujas de mensaje */
.message-image-container {
  margin-top: 6px;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 260px;
}

.message-image {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.message-image:hover {
  opacity: 0.92;
  transform: scale(1.02);
}

/* Modal Lightbox para ver comprobante a tamaño completo */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}

.modal-image {
  max-width: 95%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Offline Banner */
.offline-banner {
  background: #ef4444;
  color: white;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  padding: 6px;
  position: absolute;
  top: var(--header-height);
  left: 0;
  right: 0;
  z-index: 20;
  display: none;
}
