/* ============================================
   Estilos del Chat IA para Clientes - Rediseño
   Layout: Sidebar (chat) + Main (menú + tracking)
   ============================================ */

/* ─── Layout Principal ──────────────────── */

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #f0f2f5;
}

.app-header {
  background: var(--secondary);
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  z-index: 100;
  flex-shrink: 0;
}

.app-header .back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  text-decoration: none;
}

.app-header .back-btn:hover {
  background: rgba(255,255,255,0.1);
}

.header-restaurant {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.header-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.header-restaurant h1 {
  font-size: 1.1rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-meta {
  font-size: 0.8rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-meta .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  animation: pulse 2s infinite;
}

.meta-sep {
  opacity: 0.4;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.header-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  font-size: 1.2rem;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.header-btn:hover {
  background: rgba(255,255,255,0.2);
}

.cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ─── Body: Sidebar + Main ─────────────── */

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar: Chat IA ─────────────────── */

.chat-sidebar {
  width: 360px;
  min-width: 300px;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s, min-width 0.3s;
  overflow: hidden;
  flex-shrink: 0;
}

.chat-sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
}

/* Mensajes del chat */
.chat-sidebar .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-sidebar .message {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  animation: messageIn 0.3s ease;
  word-wrap: break-word;
}

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

.chat-sidebar .message.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-sidebar .message.bot {
  align-self: flex-start;
  background: #f0f2f5;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-sidebar .message.bot .menu-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.chat-sidebar .message.bot .menu-item:last-child {
  border-bottom: none;
}

.chat-sidebar .message.bot .menu-item .item-name {
  font-weight: 600;
}

.chat-sidebar .message.bot .menu-item .item-price {
  color: var(--primary);
  font-weight: 600;
}

.chat-sidebar .message.bot .menu-item .item-desc {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* Input del chat */
.chat-sidebar .chat-input-container {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-sidebar .chat-input-container textarea {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 0.88rem;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  transition: border-color 0.3s;
  font-family: inherit;
  outline: none;
}

.chat-sidebar .chat-input-container textarea:focus {
  border-color: var(--primary);
}

.chat-sidebar .send-btn {
  background: var(--primary);
  border: none;
  color: white;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-sidebar .send-btn:hover {
  background: var(--primary-dark);
}

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

.chat-sidebar .send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Barra WhatsApp ────────────────────── */

.chat-whatsapp-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.whatsapp-bar-text {
  font-size: 0.78rem;
  color: var(--text-light);
  line-height: 1.3;
}

.whatsapp-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #25D366;
  color: white;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}

.whatsapp-btn:hover {
  background: #1ebe5d;
  transform: scale(1.03);
}

.whatsapp-btn:active {
  transform: scale(0.97);
}

.whatsapp-icon {
  font-size: 1rem;
}

/* Typing indicator */
.chat-sidebar .typing-indicator {
  align-self: flex-start;
  background: #f0f2f5;
  padding: 10px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
}

.chat-sidebar .typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typing 1.4s infinite;
}

.chat-sidebar .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.chat-sidebar .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ─── Main Content ─────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── Sección Menú ─────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--text);
}

.menu-filter select {
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.88rem;
  background: white;
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.menu-filter select:focus {
  border-color: var(--primary);
}

/* Grid de productos */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.menu-grid .product-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  border: 2px solid transparent;
}

.menu-grid .product-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}

.menu-grid .product-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.menu-grid .product-card.agotado {
  opacity: 0.55;
  cursor: not-allowed;
}

.product-card .product-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: #f0f0f0;
  display: block;
}

.product-card .product-img-placeholder {
  width: 100%;
  height: 160px;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: #ccc;
}

.product-card .product-body {
  padding: 14px;
}

.product-card .product-categoria {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.product-card .product-nombre {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.product-card .product-desc {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card .product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.product-card .product-precio {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.product-card .product-add-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-card .product-add-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

.product-card .product-qty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.product-card .product-qty button {
  background: var(--bg-hover);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.product-card .product-qty button:hover {
  background: var(--border);
}

.product-card .product-qty span {
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  font-size: 0.95rem;
}

/* Carrito flotante */
.cart-floating {
  position: sticky;
  bottom: 0;
  background: white;
  border-radius: 14px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  border: 1px solid var(--border);
}

.cart-floating-info {
  font-size: 0.9rem;
  color: var(--text);
}

.cart-floating-info strong {
  color: var(--primary);
}

.cart-floating-actions {
  display: flex;
  gap: 8px;
}

/* ─── Sección Tracking ──────────────────── */

.section-tracking {
  animation: fadeIn 0.4s ease;
}

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

.tracking-card {
  background: white;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  padding: 24px;
}

.tracking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.tracking-pedido-id {
  font-size: 1.1rem;
  color: var(--text);
}

.tracking-pedido-id strong {
  color: var(--primary);
}

.tracking-tiempo {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* Barra de progreso */
.tracking-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  padding: 0 20px;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}

.progress-step .step-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.3s;
  border: 3px solid #e0e0e0;
}

.progress-step.active .step-icon {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.2);
}

.progress-step.completed .step-icon {
  background: var(--success);
  border-color: var(--success);
}

.progress-step .step-label {
  font-size: 0.78rem;
  color: var(--text-light);
  font-weight: 500;
  white-space: nowrap;
}

.progress-step.active .step-label {
  color: var(--primary);
  font-weight: 600;
}

.progress-step.completed .step-label {
  color: var(--success);
}

.progress-connector {
  width: 60px;
  height: 3px;
  background: #e0e0e0;
  margin: 0 4px;
  margin-bottom: 24px;
  border-radius: 2px;
  transition: background 0.5s;
}

.progress-connector.completed {
  background: var(--success);
}

.tracking-detail {
  text-align: center;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 10px;
  margin-bottom: 16px;
}

.tracking-detail p {
  margin: 0;
  color: var(--text-light);
  font-size: 0.9rem;
}

.tracking-items {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.tracking-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.88rem;
  color: var(--text);
}

.tracking-item .tracking-item-total {
  font-weight: 600;
  color: var(--text);
}

/* ─── Modal ────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 28px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-content h3 {
  margin: 0 0 20px;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-resumen {
  margin-bottom: 20px;
}

.resumen-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.resumen-total {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

/* ─── Responsive ───────────────────────── */

@media (max-width: 768px) {
  .app-body {
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-sidebar.collapsed {
    max-height: 0;
  }

  .main-content {
    padding: 16px;
  }

  .menu-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .tracking-progress {
    padding: 0 10px;
  }

  .progress-connector {
    width: 30px;
  }

  .header-restaurant h1 {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .menu-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .product-card .product-img {
    height: 120px;
  }

  .product-card .product-body {
    padding: 10px;
  }

  .product-card .product-nombre {
    font-size: 0.88rem;
  }

  .tracking-progress {
    padding: 0 5px;
  }

  .progress-connector {
    width: 20px;
  }

  .progress-step .step-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
}
