/* ============================================================
   Becker — Chatbot público (styles.css)
   Diseño Editorial Premium — minimalista, brand cyan #00AEEF
   IDs y clases compatibles con chat.js
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Inter+Tight:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --b-bg:        #fafaf9;
  --b-surface:   #ffffff;
  --b-ink:       #0c0c0e;
  --b-ink-2:     #3a3a40;
  --b-ink-3:     #7a7a83;
  --b-ink-4:     #b8b6b1;
  --b-line:      #e8e6e1;
  --b-line-soft: #f0eeea;
  --b-accent:    #00aeef;
  --b-accent-ink:#007aa8;
  --b-success:   #1f8a5b;

  --primary:     #0c0c0e;    /* chat.js compat */
  --accent:      #00aeef;    /* chat.js compat */

  --b-font:    'Inter', ui-sans-serif, system-ui, sans-serif;
  --b-display: 'Inter Tight', 'Inter', sans-serif;
  --b-mono:    'JetBrains Mono', ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--b-font);
  color: var(--b-ink);
  background: var(--b-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }

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

/* ---------- shell ---------- */
.app {
  min-height: 100vh;
  display: flex; flex-direction: column;
  background: var(--b-bg);
}

/* ---------- top bar ---------- */
.app-topbar {
  height: 72px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--b-line);
  background: var(--b-bg);
  position: sticky; top: 0; z-index: 5;
}

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

.brand-logo {
  height: 44px; width: auto; max-width: 180px;
  object-fit: contain;
}
.brand-logo[hidden] { display: none; }

.brand-monogram {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--b-ink);
  color: var(--b-bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--b-display);
  font-weight: 700; font-size: 18px;
  letter-spacing: -0.04em;
  flex-shrink: 0;
}
/* hide monogram when real logo is showing */
.brand-logo:not([hidden]) + .brand-monogram { display: none; }

.brand-text {
  display: flex; flex-direction: column; line-height: 1.2;
  min-width: 0;
}
.brand-name {
  font-family: var(--b-display);
  font-size: 16px; font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-name[hidden] { display: none; }
.brand-meta {
  font-family: var(--b-mono);
  font-size: 10.5px; color: var(--b-ink-3);
  letter-spacing: 0.06em; text-transform: uppercase;
}

.topbar-divider {
  width: 1px; height: 24px; background: var(--b-line); margin: 0 6px;
}

.status {
  font-size: 12.5px; color: var(--b-ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.livedot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--b-success);
  box-shadow: 0 0 0 3px rgba(31,138,91,0.16);
  display: inline-block;
}

.topbar-actions {
  display: flex; align-items: center; gap: 10px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px;
  font-weight: 600; font-size: 14px;
  border-radius: 6px; border: 1px solid transparent;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--b-ink); color: #fafaf9;
}
.btn-primary:hover { background: #1f1f23; }
.btn-ghost {
  background: transparent; color: var(--b-ink);
  border-color: var(--b-line);
}
.btn-ghost:hover { background: var(--b-line-soft); }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }

.whatsapp { background: var(--b-ink); color: #fafaf9; height: 36px; padding: 0 14px; }
.whatsapp:hover { background: #1f1f23; }
.whatsapp svg { flex-shrink: 0; }

/* ---------- body 2-col ---------- */
.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

/* ---------- left rail ---------- */
.app-rail {
  border-right: 1px solid var(--b-line);
  padding: 28px 24px;
  overflow-y: auto;
  background: var(--b-bg);
  display: flex; flex-direction: column;
}

.eyebrow {
  font-family: var(--b-font);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--b-ink-3);
  margin: 0 0 14px;
}

.quick-list {
  list-style: none; margin: 0 0 28px; padding: 0;
  display: grid; gap: 2px;
}
.quick-list button {
  width: 100%;
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px;
  padding: 10px 8px;
  background: transparent;
  border: 0; text-align: left;
  color: var(--b-ink);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease;
}
.quick-list button:hover { background: var(--b-line-soft); }
.quick-list .num {
  font-family: var(--b-mono);
  font-size: 10.5px; color: var(--b-ink-3);
}
.quick-list button > :nth-child(2) {
  font-size: 13.5px; font-weight: 500;
}
.quick-list .arrow {
  color: var(--b-ink-3); font-size: 14px;
}

.notice {
  margin-top: auto;
  padding: 12px 14px;
  border-left: 2px solid var(--b-accent);
  font-size: 11.5px; line-height: 1.55;
  color: var(--b-ink-2);
  background: transparent;
}

.sync { margin-top: 14px; align-self: flex-start; }
.sync[hidden] { display: none; }

/* ---------- conversation column ---------- */
.app-conversation {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--b-bg);
}

/* messages container */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 56px 16px;
  display: flex; flex-direction: column; gap: 0;
}

/* generated by chat.js: .message .bot / .user */
.message {
  max-width: 680px;
  width: 100%;
  margin: 0 auto 22px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* bot — editorial card style */
.message.bot {
  align-self: stretch;
  position: relative;
  padding: 0 0 0 52px;
  color: var(--b-ink);
}
.message.bot::before {
  content: "B";
  position: absolute;
  left: 0; top: -2px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--b-ink);
  color: var(--b-bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--b-display);
  font-weight: 700; font-size: 16px;
  letter-spacing: -0.04em;
}

/* user — ink bubble right-aligned */
.message.user {
  align-self: flex-end;
  max-width: 78%;
  margin-left: auto;
  background: var(--b-ink);
  color: #fafaf9;
  padding: 11px 16px;
  border-radius: 12px 4px 12px 12px;
  font-size: 14.5px;
}

/* suggestions row */
.message-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px;
}
.message-actions button {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px; font-weight: 500;
  color: var(--b-ink-2);
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  white-space: nowrap;
}
.message-actions button:hover {
  background: var(--b-line-soft);
  border-color: var(--b-ink-3);
  color: var(--b-ink);
}
.message-actions button.quick-action-primary {
  background: var(--b-ink); color: #fafaf9; border-color: var(--b-ink);
}
.message-actions button.quick-action-primary:hover {
  background: #1f1f23;
}

/* stale suggestions — mensajes anteriores */
.message-actions.suggestions-stale button {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* stale vehicle cards — mensajes anteriores */
.vehicle-card.stale {
  cursor: default;
  pointer-events: none;
}
.vehicle-card.stale .vehicle-card-link {
  pointer-events: auto;
  cursor: pointer;
}

/* typing indicator */
.message.typing-indicator {
  display: inline-flex; align-items: center; gap: 5px;
  width: auto; padding-left: 52px;
  min-height: 38px;
}
.message.typing-indicator span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--b-ink-4);
  animation: b-bounce 1.2s infinite ease-in-out;
}
.message.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.message.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes b-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- composer ---------- */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--b-line);
  padding: 18px 56px 22px;
  background: var(--b-bg);
}
.composer-field {
  max-width: 680px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: 12px;
  padding: 6px 6px 6px 16px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.composer-field:focus-within {
  border-color: var(--b-ink);
  box-shadow: 0 0 0 4px rgba(12,12,14,0.06);
}
.composer-field input {
  flex: 1; min-width: 0;
  height: 40px;
  background: transparent; border: 0; outline: none;
  font-size: 14px;
}
.composer-field button {
  height: 36px; width: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--b-ink); color: #fafaf9;
  border: 0; border-radius: 8px;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}
.composer-field button:hover { background: #1f1f23; transform: translateY(-1px); }
.composer-field button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.composer-foot {
  max-width: 680px; margin: 10px auto 0;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--b-ink-3);
}
.composer-foot .mono { font-family: var(--b-mono); }
.composer-foot kbd {
  border: 1px solid var(--b-line);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--b-mono);
  font-size: 10px;
}

/* ---------- error fallback (chat.js writes .home-shell) ---------- */
.home-shell {
  width: min(640px, calc(100vw - 32px));
  margin: 80px auto;
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: 12px;
  padding: 32px;
  font-size: 14.5px;
}

/* ---------- quick chips (above composer) ---------- */
.quick-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 6px;
  scrollbar-width: none;
}
.quick-chips::-webkit-scrollbar { display: none; }
.quick-chips[hidden] { display: none; }
.quick-chips.chips-hidden { display: none; }

.quick-chip {
  flex-shrink: 0;
  height: 30px;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--b-ink-2);
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.quick-chip:hover {
  background: var(--b-line-soft);
  border-color: var(--b-ink-3);
  color: var(--b-ink);
}

/* ============================================================
   RESPONSIVE — Mobile-first
   Primary breakpoint 768px. iPhone SE min 375px.
   ============================================================ */

/* --- 768px: ocultar rail, layout vertical, tap targets 44px --- */
@media (max-width: 768px) {
  /* Shell: full-screen, sin scroll exterior */
  .app {
    height: 100vh;
    height: 100dvh;  /* progressive: anula la línea anterior en browsers modernos */
    overflow: hidden;
  }

  /* Body: columna única */
  .app-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* El aside izquierdo desaparece por completo */
  .app-rail { display: none; }

  /* La columna de conversación rellena el espacio */
  .app-conversation { flex: 1; min-height: 0; }

  /* Header */
  .app-topbar { padding: 0 16px; height: 60px; }
  .topbar-divider, .status { display: none; }

  /* Mensajes */
  .messages { padding: 16px 16px 8px; }
  .message { font-size: 15px; }
  .message.bot { padding-left: 44px; }
  .message.bot::before { width: 32px; height: 32px; font-size: 14px; top: 0; }
  .message.user { max-width: 85%; font-size: 15px; }

  /* Suggestions: más espacio entre botones */
  .message-actions { gap: 6px; flex-wrap: wrap; }
  .message-actions button { height: 36px; padding: 0 14px; font-size: 13px; }

  /* Composer: sticky en el fondo, por encima del teclado virtual */
  .composer {
    padding: 8px 12px 12px;
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--b-bg);
    border-top: 1px solid var(--b-line);
  }

  /* CRÍTICO: 16px exacto previene el auto-zoom de iOS al enfocar */
  .composer-field input { font-size: 16px; height: 44px; }

  /* Botón enviar: mínimo 44×44px (Apple HIG) */
  .composer-field button { height: 44px; width: 44px; border-radius: 10px; }

  /* Quick chips: mínimo 44px alto, 14px fuente */
  .quick-chip { height: 44px; font-size: 14px; padding: 0 16px; }

  /* Vehicle cards: 1 columna en móvil */
  .vehicle-card-grid { grid-template-columns: 1fr; }
  .vehicle-card-price { font-size: 18px; }
  .vehicle-card-link,
  .vehicle-card-contact { min-height: 44px; display: flex; align-items: center; }

  /* Ocultar pie de compositor (innecesario en móvil) */
  .composer-foot { display: none; }
}

/* Progressive enhancement: usa 100dvh cuando el browser lo soporta */
@supports (height: 100dvh) {
  @media (max-width: 768px) {
    .app { height: 100dvh; }
  }
}

/* --- 480px: teléfonos pequeños --- */
@media (max-width: 480px) {
  .brand-meta { display: none; }
  .brand-logo { height: 34px; }
  .brand-monogram { width: 36px; height: 36px; font-size: 15px; }
  .message.user { max-width: 90%; }
}

/* --- 380px: iPhone SE (375px) y Samsung S21 (360px) --- */
@media (max-width: 380px) {
  /* Solo mostrar monograma + botón WhatsApp en el header */
  .brand-name { font-size: 13px; }
  .brand-meta { display: none; }
  .wa-text { display: none; }
  .whatsapp { padding: 0 10px; gap: 0; }
}

/* ---------- dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --b-bg:        #0f0f13;
    --b-surface:   #1a1a20;
    --b-ink:       #e8e4de;
    --b-ink-2:     #aeaab4;
    --b-ink-3:     #68686f;
    --b-ink-4:     #38383f;
    --b-line:      #27272e;
    --b-line-soft: #1e1e25;
    --b-accent:    #00aeef;
    --b-accent-ink:#4ecdf8;
    --b-success:   #34d399;
    --primary:     #e8e4de;
    --accent:      #00aeef;
  }

  .message.user {
    background: #1c3855;
    color: #c5e3f5;
  }

  .btn-primary,
  .whatsapp {
    background: #1e1e26;
    border-color: var(--b-line);
    color: var(--b-ink);
  }
  .btn-primary:hover { background: var(--b-line); }
  .whatsapp:hover    { background: var(--b-line); }

  .composer-field button {
    background: var(--b-accent);
    color: #fff;
  }
  .composer-field button:hover { background: #009bd6; transform: translateY(-1px); }

  .message-actions button {
    background: var(--b-surface);
    border-color: var(--b-line);
    color: var(--b-ink-2);
  }
  .message-actions button:hover {
    background: var(--b-line);
    border-color: var(--b-ink-4);
    color: var(--b-ink);
  }
  .message-actions button.quick-action-primary {
    background: var(--b-accent);
    color: #fff;
    border-color: var(--b-accent);
  }
  .message-actions button.quick-action-primary:hover { background: #009bd6; }

  .vehicle-card {
    background: var(--b-surface);
    border-color: var(--b-line);
  }
  .vehicle-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.4); }

  .quick-chip {
    background: var(--b-surface);
    border-color: var(--b-line);
    color: var(--b-ink-2);
  }
  .quick-chip:hover {
    background: var(--b-line);
    border-color: var(--b-ink-4);
    color: var(--b-ink);
  }

  .composer-field {
    background: var(--b-surface);
    border-color: var(--b-line);
  }
  .composer-field:focus-within {
    border-color: var(--b-ink-4);
    box-shadow: 0 0 0 4px rgba(232,228,222,0.06);
  }
}

/* ---------- vehicle cards ---------- */
.vehicle-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 14px 0 4px;
}

.vehicle-card {
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: box-shadow 160ms ease, transform 160ms ease;
  outline-offset: 2px;
  text-align: left;
  user-select: none;
}

.vehicle-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.09);
  transform: translateY(-2px);
}

.vehicle-card:focus-visible {
  outline: 2px solid var(--accent);
}

.vehicle-card-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--b-line-soft);
  flex-shrink: 0;
}

.vehicle-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 220ms ease;
}

.vehicle-card:hover .vehicle-card-img img {
  transform: scale(1.04);
}

.vehicle-card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.vehicle-card-title {
  font-family: var(--b-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--b-ink);
  line-height: 1.3;
}

.vehicle-card-price {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--b-accent-ink);
}

.vehicle-card-km {
  font-size: 11.5px;
  color: var(--b-ink-3);
}

.vehicle-card-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: #fff;
  background: #c0392b;
  border-radius: 999px;
  align-self: flex-start;
}

.vehicle-card-actions {
  display: flex;
  gap: 6px;
  padding: 6px 10px 10px;
  flex-wrap: wrap;
}

.vehicle-card-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--b-accent-ink);
  text-decoration: none;
  border: 1px solid var(--b-line);
  border-radius: 6px;
  transition: background 120ms;
  white-space: nowrap;
}
.vehicle-card-link:hover { background: var(--b-line-soft); text-decoration: none; }

.vehicle-card-contact {
  flex: 1;
  min-height: 36px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--b-ink-2);
  background: transparent;
  border: 1px solid var(--b-line);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms;
  white-space: nowrap;
}
.vehicle-card-contact:hover { background: var(--b-line-soft); }

/* Nota: el breakpoint de 1 columna se define en el bloque @media (max-width: 768px) */

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--b-line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--b-ink-4); }
