/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #111B21;
}

/* ── Pantalla de error / carga ───────────────────────── */
.screen-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}
.error-card {
  background: #202C33;
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  border: 1px solid #2A3942;
}
.error-card .icon { font-size: 48px; margin-bottom: 16px; }
.error-card h2 { color: #E9EDEF; font-size: 18px; margin-bottom: 8px; }
.error-card p  { color: #8696A0; font-size: 14px; line-height: 1.5; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid #2A3942;
  border-top-color: #25D366;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Contenedor principal ─────────────────────────────── */
.chat-wrapper {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #0B141A;
  margin: 0 auto;
}

/* En tablet/desktop: ventana flotante */
@media (min-width: 768px) {
  .chat-wrapper {
    max-width: 860px;
    height: 90dvh;
    max-height: 860px;
    margin: auto;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
    flex-direction: row;
  }
}

/* ── Columna chat ────────────────────────────────────── */
.chat-column {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────── */
.chat-header {
  background: #202C33;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid #2A3942;
}
.header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366, #128C7E);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.header-info { flex: 1; min-width: 0; }
.header-name {
  color: #E9EDEF;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.escalated { background: #FFA500; }
.status-dot.handled   { background: #25D366; }
.status-dot.active    { background: #53BDEB; }
.status-dot.closed    { background: #8696A0; }
.header-status span {
  color: #8696A0;
  font-size: 12px;
}
.header-phone {
  color: #8696A0;
  font-size: 11px;
  margin-top: 1px;
}
.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #8696A0;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background 0.15s;
}
.btn-icon:hover { background: #2A3942; color: #E9EDEF; }

/* ── Banner de estado ────────────────────────────────── */
.status-banner {
  background: #2A2A1A;
  border-bottom: 1px solid #3D3A1A;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.status-banner span {
  color: #FFA500;
  font-size: 12px;
  font-weight: 500;
}
.btn-take {
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-take:hover { background: #1DA851; }

/* ── Área de mensajes ────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-color: #0B141A;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 10c-1 0-1.5.8-1.5 1.5S29 13 30 13s1.5-.8 1.5-1.5S31 10 30 10zm-10 0c-1 0-1.5.8-1.5 1.5S19 13 20 13s1.5-.8 1.5-1.5S21 10 20 10zm20 0c-1 0-1.5.8-1.5 1.5S39 13 40 13s1.5-.8 1.5-1.5S41 10 40 10z' fill='rgba(255,255,255,0.03)'/%3E%3C/svg%3E");
  scroll-behavior: smooth;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #2A3942; border-radius: 2px; }

/* ── Date divider ────────────────────────────────────── */
.date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}
.date-divider span {
  background: #182229;
  color: #8696A0;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid #2A3942;
}

/* ── Burbujas ────────────────────────────────────────── */
.msg-row {
  display: flex;
  margin-bottom: 2px;
}
.msg-row.from-customer { justify-content: flex-start; }
.msg-row.from-ai       { justify-content: flex-start; }
.msg-row.from-operator { justify-content: flex-end; }
.msg-row.system        { justify-content: center; }

.bubble {
  max-width: 72%;
  padding: 8px 10px 6px;
  border-radius: 8px;
  position: relative;
  line-height: 1.45;
}

/* Cola izquierda */
.msg-row.from-customer .bubble::before,
.msg-row.from-ai .bubble::before {
  content: '';
  position: absolute;
  left: -8px; top: 0;
  border: 8px solid transparent;
  border-right-color: inherit;
  border-top-color: inherit;
  border-left: 0;
  border-bottom: 0;
}
/* Cola derecha */
.msg-row.from-operator .bubble::after {
  content: '';
  position: absolute;
  right: -8px; top: 0;
  border: 8px solid transparent;
  border-left-color: inherit;
  border-top-color: inherit;
  border-right: 0;
  border-bottom: 0;
}

/* Cliente */
.msg-row.from-customer .bubble {
  background: #202C33;
  border-color: #202C33;
  color: #E9EDEF;
}
/* IA / Bot */
.msg-row.from-ai .bubble {
  background: #1A2930;
  border-color: #1A2930;
  color: #D1D7DB;
}
/* Operador humano */
.msg-row.from-operator .bubble {
  background: #005C4B;
  border-color: #005C4B;
  color: #E9EDEF;
}
/* Sistema (pill centrado) */
.msg-row.system .bubble {
  background: #182229;
  border: 1px solid #2A3942;
  color: #8696A0;
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 20px;
  max-width: 80%;
  text-align: center;
}
.msg-row.system .bubble::before,
.msg-row.system .bubble::after { display: none; }

.bubble-text { font-size: 14px; word-break: break-word; white-space: pre-wrap; }
.message-proof-link {
  display: inline-flex;
  width: auto;
  margin-top: 8px;
  color: #53bdeb;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}
.message-proof-link:hover { text-decoration: underline; }
.media-retention-note {
  margin-top: 8px;
  color: #8696a0;
  font-size: 12px;
}

/* Badge de rol */
.bubble-role {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 3px;
}
.msg-row.from-ai     .bubble-role { color: #25D366; }
.msg-row.from-operator .bubble-role { color: #A8D5C2; }

.bubble-time {
  font-size: 10px;
  color: #8696A0;
  text-align: right;
  margin-top: 3px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}
.msg-row.from-operator .bubble-time { color: #A8D5C2; }

/* ── Input bloqueado (sin control) ──────────────────── */
.locked-overlay {
  background: #1A2128;
  border-top: 1px solid #2A3942;
  padding: 12px 16px;
  text-align: center;
  flex-shrink: 0;
}
.locked-overlay p {
  color: #8696A0;
  font-size: 12px;
  margin-bottom: 8px;
}
.btn-take-full {
  width: 100%;
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-take-full:hover { background: #1DA851; }

/* ── Input area ──────────────────────────────────────── */
.input-area {
  background: #202C33;
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  border-top: 1px solid #2A3942;
}
.input-box {
  flex: 1;
  background: #2A3942;
  border: none;
  border-radius: 22px;
  padding: 10px 16px;
  color: #E9EDEF;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
}
.input-box::placeholder { color: #8696A0; }
.input-box:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-send {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: #25D366;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-send:hover { background: #1DA851; }
.btn-send:disabled { background: #3A4A42; cursor: not-allowed; }

/* ── Indicador "escribiendo..." ──────────────────────── */
.typing-indicator {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 4px;
}
.typing-bubble {
  background: #202C33;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #8696A0;
  animation: blink 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Panel de info (solo tablet/desktop) ─────────────── */
@media (max-width: 767px) {
  .chat-wrapper { overflow-y: auto; }
  .chat-column { flex: none; height: 75dvh; min-height: 480px; }
  .info-panel {
    display: flex; flex-direction: column; flex: none; padding: 16px; gap: 12px;
    background: #1A2128; border-top: 1px solid #2A3942;
  }
}
@media (min-width: 768px) {
.info-panel {
    width: 280px;
    flex-shrink: 0;
    background: #1A2128;
    border-left: 1px solid #2A3942;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
    overflow-y: auto;
  }
}

.conversation-side-actions { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.conversation-side-actions select { width: 100%; }

.info-title {
  color: #25D366;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid #2A3942;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: #8696A0; font-size: 12px; }
.info-value { color: #E9EDEF; font-size: 12px; text-align: right; max-width: 55%; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge.escalated { background: #3D2E00; color: #FFA500; }
.badge.handled   { background: #003D2E; color: #25D366; }
.badge.active    { background: #1A2D3E; color: #53BDEB; }
.badge.closed    { background: #2A3942; color: #8696A0; }

.btn-action {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}
.btn-action:hover { opacity: 0.85; }
.btn-action.danger     { background: #FF3B30; color: #fff; }
.btn-action.secondary  { background: #2A3942; color: #E9EDEF; }
.btn-action:disabled   { opacity: 0.4; cursor: not-allowed; }

.order-summary-line, .order-edit-heading, .order-edit-controls, .order-edit-total {
  display: flex; justify-content: space-between; gap: 8px; color: #E9EDEF; font-size: 12px;
}
.order-line-note { color: #8696A0; font-size: 11px; padding: 0 0 6px 12px; }
.order-editor { border: 1px solid #2A3942; border-radius: 10px; padding: 10px; }
.order-edit-line { padding: 8px 0; border-bottom: 1px solid #2A3942; }
.order-edit-heading button { color: #F87171; background: transparent; border: 0; cursor: pointer; font-size: 18px; }
.order-edit-controls { align-items: center; margin: 6px 0; }
.order-edit-controls input { width: 64px; padding: 6px; color: #E9EDEF; background: #202C33; border: 1px solid #2A3942; border-radius: 6px; }
.order-note-input { width: 100%; padding: 7px; color: #E9EDEF; background: #202C33; border: 1px solid #2A3942; border-radius: 6px; }
.order-add-product { margin-top: 10px; }
.order-add-product .input-box { width: 100%; }
.order-edit-total { padding-top: 10px; font-weight: 700; color: #25D366; }
.order-editor > .btn-action:not(.secondary) { background: #25D366; color: #071b10; }
