/* Demo chatbot · Ferretería El Tornillo — estilos */
:root {
  --azul: #2563eb;
  --azul-oscuro: #1d4ed8;
  --azul-suave: #eff6ff;
  --verde: #22c55e;
  --verde-oscuro: #16a34a;
  --tinta: #0f172a;
  --gris: #64748b;
  --gris-claro: #94a3b8;
  --linea: #e2e8f0;
  --fondo: #f3f6fb;
  --blanco: #ffffff;
  --ambar: #f59e0b;
  --rojo: #ef4444;
  --radio: 16px;
  --sombra: 0 12px 32px rgba(15, 23, 42, 0.07);
  --sombra-suave: 0 2px 8px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(37, 99, 235, 0.10), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(34, 197, 94, 0.10), transparent 55%),
    var(--fondo);
  color: var(--tinta);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* App de alto completo: encabezado fijo arriba y chat/panel con scroll propio. */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1400px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 18px 24px 22px;
}

/* ------------------------------------------------------------- encabezado */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-icon {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #2563eb 60%, #1d4ed8);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
}

.brand-text { min-width: 0; }

.brand-text h1 {
  font-size: clamp(1.02rem, 1.9vw, 1.3rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.brand-text h1 .sep { color: var(--gris-claro); font-weight: 500; }
.brand-text h1 .soft { color: #475569; font-weight: 600; }

.brand-text p {
  font-size: 12.5px;
  color: var(--gris);
}

/* ------------------------------------------------------------------ tabs */
.tabs { display: none; }

.tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border: 1px solid var(--linea);
  border-radius: 12px;
  background: var(--blanco);
  color: #475569;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab-extra { margin-left: -3px; }

.tab.is-active {
  background: var(--azul);
  border-color: var(--azul);
  color: #fff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

.badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--verde);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
}

.tab.is-active .badge { background: #fff; color: var(--azul-oscuro); }

/* ---------------------------------------------------------------- layout */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(340px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 20px;
}

/* ------------------------------------------------------------------ chat */
.chat-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--blanco);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  overflow: hidden;
}

.chat-head,
.suggestions,
.composer { flex: 0 0 auto; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--linea);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}

.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  color: var(--azul-oscuro);
  font-size: 18px;
}

.chat-head-text { min-width: 0; flex: 1; }

.chat-head-text h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chat-head-text p {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gris);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--verde);
}

.icon-btn {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--linea);
  border-radius: 10px;
  background: var(--blanco);
  color: var(--gris);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover { color: var(--azul); border-color: #bfdbfe; background: var(--azul-suave); }

.chat-log {
  flex: 1 1 auto;
  scrollbar-width: thin;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(600px 200px at 100% 0%, rgba(37, 99, 235, 0.035), transparent 70%),
    #f8fafc;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 90%;
  min-width: 0;
}

.msg-user { align-self: flex-end; align-items: flex-end; }

.bubble {
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  background: var(--blanco);
  border: 1px solid var(--linea);
  box-shadow: var(--sombra-suave);
  font-size: 13.8px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-user .bubble {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: transparent;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 5px;
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.22);
}

.msg-meta {
  margin-top: 4px;
  padding: 0 4px;
  font-size: 10.5px;
  color: var(--gris-claro);
}

.productos {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.producto {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: 12px;
  background: var(--blanco);
}

.producto-info { min-width: 0; flex: 1 1 150px; }

.producto-info h4 {
  font-size: 12.8px;
  font-weight: 600;
  line-height: 1.35;
}

.producto-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--gris);
}

.producto-compra {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.precio {
  font-size: 13px;
  font-weight: 700;
  color: var(--tinta);
  white-space: nowrap;
}

.stock {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.stock-ok { background: #dcfce7; color: #15803d; }
.stock-bajo { background: #fef3c7; color: #b45309; }
.stock-cero { background: #fee2e2; color: #b91c1c; }

.btn-agregar {
  padding: 7px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--azul);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-agregar:hover { background: var(--azul-oscuro); }
.btn-agregar:active { transform: translateY(1px); }
.btn-agregar:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }

/* indicador escribiendo */
.msg-bot .typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 13px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  background: var(--blanco);
  border: 1px solid var(--linea);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: saltito 1.1s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes saltito {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* sugerencias y composer */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--linea);
  background: var(--blanco);
}

.suggestions:empty { display: none; }

.chip {
  padding: 7px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: var(--azul-suave);
  color: var(--azul-oscuro);
  font: inherit;
  font-size: 12.2px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chip:hover { background: #dbeafe; border-color: #93c5fd; }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--linea);
  background: var(--blanco);
}

.composer input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  color: var(--tinta);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.composer input::placeholder { color: #94a3b8; }

.composer input:focus {
  border-color: var(--azul);
  background: var(--blanco);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.send-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, var(--azul));
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
  transition: background 0.15s ease, transform 0.1s ease;
}

.send-btn:hover { background: linear-gradient(135deg, #2563eb, var(--azul-oscuro)); }
.send-btn:active { transform: translateY(1px); }
.send-btn:disabled { opacity: 0.6; cursor: wait; box-shadow: none; }

/* ----------------------------------------------------------------- panel */
.panel-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 18px;
  background: var(--blanco);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.panel-head p { margin-top: 2px; font-size: 12px; color: var(--gris); }

.panel-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  color: #15803d;
  font-size: 11px;
  font-weight: 600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 12px;
  border: 1px solid #eef2f7;
  border-radius: 12px;
  background: #f8fafc;
  min-width: 0;
}

.metric-value {
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-green { color: var(--verde-oscuro); }
.metric-label { font-size: 11px; color: var(--gris); line-height: 1.3; }

.panel-section { margin-bottom: 18px; }
.panel-section:last-child { margin-bottom: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.section-head h3 { font-size: 13px; font-weight: 700; }

.pill {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e0ecff;
  color: var(--azul-oscuro);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.hint { font-size: 10.5px; color: var(--gris-claro); }

.orders { display: flex; flex-direction: column; gap: 9px; }

.empty {
  padding: 14px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  color: var(--gris);
  font-size: 12px;
  text-align: center;
}

.pedido {
  padding: 11px 12px;
  border: 1px solid var(--linea);
  border-left: 3px solid var(--verde);
  border-radius: 12px;
  background: #fff;
}

.pedido.is-new { animation: aparecer 0.5s ease; }

@keyframes aparecer {
  0% { transform: translateY(-10px) scale(0.98); background: #f0fdf4; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22); }
  100% { transform: translateY(0) scale(1); background: #ffffff; box-shadow: none; }
}

.pedido-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.pedido-id { font-size: 13px; font-weight: 800; color: var(--azul-oscuro); }
.pedido-nombre { font-size: 12.5px; color: #334155; font-weight: 600; overflow-wrap: anywhere; }

.pedido-tipo {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--gris);
}

.pedido-items {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  font-size: 11.8px;
  color: #475569;
}

.pedido-items li { padding: 1px 0; }

.pedido-total {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed var(--linea);
  font-size: 12.5px;
}

.pedido-total strong { font-size: 13px; color: var(--tinta); }

.stock-list {
  display: flex;
  flex-direction: column;
  padding-right: 2px;
}

.stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px dashed #eef2f7;
  font-size: 12.2px;
}

.stock-row:last-child { border-bottom: 0; }

.stock-row-nombre {
  min-width: 0;
  color: #334155;
  overflow-wrap: anywhere;
}

.stock-row .stock { flex: 0 0 auto; }

.stock-vacio { color: var(--gris); font-size: 12px; }

/* ------------------------------------------------------- CTA y crédito */
.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex: 0 0 auto;
  padding: 11px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(22, 163, 74, 0.25);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.cta i { font-size: 18px; }
.cta:hover { transform: translateY(-1px); box-shadow: 0 12px 26px rgba(22, 163, 74, 0.3); }
.cta:active { transform: translateY(0); }
.cta:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.icon-btn:focus-visible,
.btn-agregar:focus-visible,
.send-btn:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.45); outline-offset: 2px; }

.credit {
  margin-top: auto;
  padding-top: 16px;
  font-size: 11.5px;
  color: var(--gris-claro);
  text-align: center;
}

.credit a { color: var(--gris); font-weight: 600; text-decoration: none; }
.credit a:hover { color: var(--azul); }

/* --------------------------------------------------------------- móvil */
@media (max-width: 899px) {
  .app {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .topbar { gap: 10px; margin-bottom: 12px; }
  .brand { gap: 11px; }
  .brand-icon { width: 42px; height: 42px; flex-basis: 42px; border-radius: 12px; font-size: 17px; }
  .brand-text h1 { font-size: 1rem; }
  .brand-text h1 .sep { display: none; }
  .brand-text h1 .soft { display: block; font-size: 0.86rem; }
  .brand-text p { display: none; }

  .cta { width: 44px; height: 44px; padding: 0; }
  .cta-text { display: none; }

  .tabs {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
    margin-bottom: 12px;
    padding: 4px;
    border: 1px solid var(--linea);
    border-radius: 14px;
    background: var(--blanco);
  }

  .tab { border: 0; border-radius: 10px; padding: 9px 8px; }
  .tab.is-active { box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25); }

  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }

  .chat-card,
  .panel-card { display: none; }

  .app[data-view="chat"] .chat-card { display: flex; }
  .app[data-view="panel"] .panel-card { display: flex; }

  .chat-head { padding: 11px 14px; }
  .avatar { width: 38px; height: 38px; flex-basis: 38px; font-size: 16px; }
  .chat-log { padding: 14px 12px; gap: 10px; }
  .bubble { font-size: 14px; }
  .msg { max-width: 92%; }

  /* Sugerencias en una fila deslizable: no le roban alto al chat. */
  .suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 9px 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .suggestions::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; white-space: nowrap; }

  .composer { padding: 10px 12px 12px; }
  .composer input { font-size: 16px; } /* evita el zoom automático en iOS */

  .panel-card { padding: 15px; }
}

@media (max-width: 520px) {
  .tab-extra { display: none; }
}

@media (max-width: 420px) {
  .head-extra { display: none; }
  .producto { padding: 9px 10px; }
  .producto-compra { width: 100%; justify-content: space-between; }
  .metric-value { font-size: 1.08rem; }
}

/* Pantallas bajas (celular apaisado, notebooks chicas): todo más compacto. */
@media (max-height: 520px) {
  .app { padding-top: 8px; padding-bottom: 8px; }
  .topbar { margin-bottom: 8px; }
  .brand-icon { width: 36px; height: 36px; flex-basis: 36px; font-size: 15px; }
  .brand-text p { display: none; }
  .tabs { margin-bottom: 8px; }
  .brand-text h1 .soft { display: none; }
  .tab { padding: 6px 8px; }
  .chat-head { padding: 6px 12px; }
  .chat-head .avatar { display: none; }
  .icon-btn { width: 32px; height: 32px; flex-basis: 32px; }
  .chat-log { padding: 10px 12px; }
  .suggestions { flex-wrap: nowrap; overflow-x: auto; padding: 6px 12px; scrollbar-width: none; }
  .chip { flex: 0 0 auto; white-space: nowrap; }
  .composer { padding: 8px 12px; }
}

/* Si la ventana es demasiado baja para una app fija, se deja scrollear la página. */
@media (min-width: 900px) and (max-height: 600px) {
  .app { height: auto; min-height: 100dvh; }
  .layout { grid-template-rows: auto; }
  .chat-card { height: 520px; }
  .panel-card { max-height: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
