/* MotoAI chat UI — scoped under .motoai-app to avoid host CSS conflicts.
   Design-token system (v43.1): calm indigo/slate palette, premium-assistant
   character. Red is RESERVED for real errors only (--color-error). */

/* ---------- Design tokens ---------- */
:root {
  /* surfaces */
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-surface-soft: #eef1f6;

  /* brand / action (indigo — calm, not aggressive) */
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-soft: #eef0fe;
  --color-on-primary: #ffffff;

  /* text */
  --color-text: #1a2333;
  --color-text-muted: #5c6b81;

  /* lines & shapes */
  --color-border: #dde3ec;
  --color-border-strong: #c3ccd9;

  /* status semantics */
  --color-success: #0d8a5f;
  --color-success-soft: #e3f6ee;
  --color-warning: #9a6700;
  --color-warning-soft: #fdf3e0;
  --color-error: #d2193c; /* the ONLY red: real errors/destructive states */
  --color-error-soft: #fdeaee;

  /* layout scale */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;

  /* elevation & motion */
  --shadow-sm: 0 1px 3px rgba(26, 35, 51, 0.08);
  --shadow-md: 0 6px 24px rgba(26, 35, 51, 0.12);
  --duration-fast: 140ms;
  --duration-slow: 280ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

html[data-motoai-theme="dark"] {
  --color-bg: #10141b;
  --color-surface: #171d26;
  --color-surface-elevated: #1d2430;
  --color-surface-soft: #232b38;

  --color-primary: #7c7cf4;
  --color-primary-hover: #9494f7;
  --color-primary-soft: #262a4d;
  --color-on-primary: #ffffff;

  --color-text: #e7ecf4;
  --color-text-muted: #93a0b5;

  --color-border: #2b3444;
  --color-border-strong: #3d495c;

  --color-success: #2fc48e;
  --color-success-soft: #12291f;
  --color-warning: #e0a94e;
  --color-warning-soft: #2b2413;
  --color-error: #ff6b81;
  --color-error-soft: #331a20;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.5);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

/* v60: the ROOT document is a normal scrolling document by default.
   No global html/body height:100% — no global overflow lock. The chat
   homepage (body.chat-home) locks its own viewport below; content pages
   never inherit any app lock. */
html {
  margin: 0;
  padding: 0;
  height: auto;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  padding: 0;
  height: auto;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: inherit;
}

/* ---------- App shell ---------- */
.motoai-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--color-bg);
  padding:
    calc(env(safe-area-inset-top, 0px) + var(--space-2))
    calc(env(safe-area-inset-right, 0px) + var(--space-3))
    calc(env(safe-area-inset-bottom, 0px) + var(--space-2))
    calc(env(safe-area-inset-left, 0px) + var(--space-3));
  gap: var(--space-2);
}

/* ---------- Header ---------- */
.motoai-header {
  display: flex;
  flex-wrap: wrap;          /* narrow screens: status wraps to its OWN row */
  align-items: center;
  justify-content: space-between;
  column-gap: var(--space-2);
  row-gap: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.motoai-header-text { display: flex; align-items: center; gap: var(--space-3); flex: 1 1 auto; min-width: 0; }
.motoai-header-text > div { min-width: 0; }  /* title/address may shrink, never force overflow */

.motoai-brand-mark {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  font-size: 18px;
}

.motoai-title {
  margin: 0;
  font-size: 1.02rem;      /* ~17px mobile — readable, one line */
  font-weight: 650;
  letter-spacing: 0.2px;
  line-height: 1.2;
  white-space: nowrap;     /* never stacks word-per-line */
  overflow: hidden;
  text-overflow: ellipsis; /* safety net on the very narrowest phones */
}

.motoai-subtitle {
  margin: 2px 0 0;
  font-size: 0.74rem;          /* ~13px mobile */
  color: var(--color-text-muted);
  white-space: normal;         /* full address wraps cleanly on small screens */
  overflow-wrap: break-word;
  display: -webkit-box;        /* cap at 2 lines — never a tall address block */
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
@media (max-width: 359px) {
  .motoai-subtitle { font-size: 0.68rem; } /* compact but complete, never clipped */
  .motoai-menu-label { display: none; }    /* icon-only Menu: identity keeps its width */
  .motoai-menu { padding: 0 12px; min-width: 44px; }
}

.motoai-status {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  white-space: normal;         /* status lines wrap on narrow screens, never clipped */
  min-height: 1em;
}

.motoai-status[data-tone="warning"] { color: var(--color-warning); }
.motoai-status[data-tone="error"] { color: var(--color-error); }
.motoai-status[data-tone="success"] { color: var(--color-success); }

/* v58 mobile header contract: status never steals width from the identity.
   Below 768px it wraps onto its own full-width row (it is hidden when empty). */
@media (max-width: 767px) {
  .motoai-status {
    order: 5;               /* after Auto/Menu in row 1 */
    flex-basis: 100%;       /* forces the second row */
  }
}

/* ---------- Messages ---------- */
.motoai-messages {
  flex: 1 1 auto;
  min-height: 0;               /* critical: lets the area shrink when the iOS keyboard reduces iframe height */
  overflow-y: auto;
  overflow-x: hidden;           /* vertical-only chat scroll; no horizontal leak */
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-1);
  scroll-padding-bottom: var(--space-3);
}

.motoai-msg {
  max-width: 86%;
  padding: 9px 13px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border-radius: var(--radius-md);
}

.motoai-msg-user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-end-end-radius: var(--radius-sm);
}

.motoai-msg-bot {
  align-self: flex-start;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-end-start-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.motoai-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.motoai-msg-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 550;
}

.motoai-msg-actions a:hover { background: var(--color-primary); color: var(--color-on-primary); }

/* thinking indicator */
.motoai-typing { display: flex; gap: 5px; align-items: center; padding: 12px 14px; }
.motoai-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-text-muted);
  animation: motoai-bounce 1.1s infinite ease-in-out;
}
.motoai-typing span:nth-child(2) { animation-delay: 0.15s; }
.motoai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes motoai-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---------- Quick actions (ONE single horizontal row) ---------- */
.motoai-quick {
  display: flex;
  flex-wrap: nowrap;            /* one horizontal row, never a second line */
  gap: var(--space-2);
  padding: var(--space-1) 0 var(--space-1);
  overflow-x: auto;             /* swipe/scroll sideways to reveal later chips */
  overflow-y: hidden;           /* never leaks vertical scroll or layout shift */
  overscroll-behavior-x: contain; /* swipe does not scroll the host page */
  -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
  scrollbar-width: none;        /* hidden scrollbar; chips stay fully visible */
}
.motoai-quick::-webkit-scrollbar { display: none; }

.motoai-chip {
  flex: 0 0 auto;               /* never squashed, never half-clipped */
  display: inline-flex;        /* button and link chips render identically */
  align-items: center;
  min-height: 40px;             /* consistent chip height, comfortable touch target */
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8rem;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;        /* link chips look exactly like button chips */
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.motoai-chip:hover { background: var(--color-primary-soft); border-color: var(--color-primary); color: var(--color-primary); }

/* ---------- Local AI panel ---------- */
.motoai-ai-panel { display: flex; flex-direction: column; gap: var(--space-2); }

.motoai-ai-toggle {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8rem;
  cursor: pointer;
}
.motoai-ai-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }

.motoai-ai-explain {
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 0.78rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}
.motoai-ai-explain ul { margin: var(--space-2) 0; padding-left: 18px; }
.motoai-ai-explain li { margin: 2px 0; }

.motoai-ai-confirm {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: var(--space-2);
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.motoai-ai-confirm:hover { background: var(--color-primary-hover); }

.motoai-ai-cancel {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: var(--space-2);
  margin-left: var(--space-2);
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
}

.motoai-ai-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  flex-wrap: wrap;
}

.motoai-ai-progress {
  flex: 0 0 96px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.motoai-ai-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--color-primary);
  transition: width var(--duration-slow) var(--ease);
}

.motoai-ai-status[data-tone="warning"] #motoai-ai-status-text { color: var(--color-warning); }
.motoai-ai-status[data-tone="error"] #motoai-ai-status-text { color: var(--color-error); }
.motoai-ai-status[data-tone="success"] #motoai-ai-status-text { color: var(--color-success); }

.motoai-ai-off {
  border: none;
  background: none;
  color: var(--color-text-muted);
  text-decoration: underline;
  font-size: 0.75rem;
  cursor: pointer;
  min-height: 36px;
}

/* ---------- Composer ---------- */
.motoai-composer {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  padding-bottom: 2px;
}

.motoai-input {
  flex: 1;
  min-height: 46px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 11px 15px;
  font-size: 16px; /* >=16px: iOS Safari never zooms on focus */
  font-family: inherit;
  resize: none;
}
.motoai-input::placeholder { color: var(--color-text-muted); }
.motoai-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }

.motoai-send {
  flex: 0 0 auto;
  min-height: 46px;
  min-width: 46px;
  padding: 0 18px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}
.motoai-send:hover { background: var(--color-primary-hover); }
.motoai-send:disabled { opacity: 0.55; cursor: default; }

.motoai-send[data-error="true"] { background: var(--color-error); }

/* ---------- Bottom dock (v53): flat bottom navigation — NOT tag-like ---------- */
.motoai-dock {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* one row, 4 equal cells */
  gap: var(--space-1);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) / 2);
  border-top: 1px solid var(--color-border);
}
/* App bottom-nav look: icon above a small label, flat transparent cells.
   Deliberately different from quick chips (no pill, no per-item border/bg). */
.motoai-dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 44px;               /* touch target */
  padding: var(--space-1) 2px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: nowrap;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; /* no sticky grey flash on iOS */
}
.motoai-dock-item .motoai-dock-icon { font-size: 1.1rem; line-height: 1; }
/* Hover ONLY on real pointers — never sticky/persistent on touch devices. */
@media (hover: hover) and (pointer: fine) {
  .motoai-dock-item:hover { color: var(--color-primary); background: transparent; }
}
/* Tap feedback: primary accent while pressed, returns to normal after. */
.motoai-dock-item:active { color: var(--color-primary); }
.motoai-dock-item:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
/* No "selected" state is kept — dock items are actions, not tabs. */
/* Hide the ecosystem dock in embed mode (widget stays minimal). */
body[data-motoai-embed="1"] .motoai-dock { display: none; }
/* Laptop/desktop: centered compact dock inside the chat column (not stretched). */
@media (min-width: 768px) {
  .motoai-dock { max-width: 560px; margin: 0 auto; width: 100%; }
  .motoai-dock-item { font-size: 0.74rem; }
}

/* ---------- Grouped menu (v50): accordion parent/child ---------- */
.motoai-group { padding: 0; }
.motoai-group-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.motoai-group-btn:hover { background: var(--color-primary-soft); color: var(--color-primary); }
.motoai-group-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.motoai-group-btn[aria-expanded="true"] { color: var(--color-primary); }
.motoai-caret { transition: transform var(--duration-fast) var(--ease); }
.motoai-group-btn[aria-expanded="true"] .motoai-caret { transform: rotate(180deg); }
.motoai-group-items {
  list-style: none;
  margin: 0;
  padding: 0 0 var(--space-2) var(--space-4); /* children clearly indented */
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.motoai-group-items[hidden] { display: none; }

/* Hub → children hierarchy inside the Cẩm nang drawer group (v61):
   the parent hub keeps a real crawlable link with a 44px+ touch target,
   children sit indented underneath — no deep accordion nesting. */
.motoai-hub { padding-top: 2px; }
.motoai-hub-link {
  display: flex; align-items: center; min-height: 48px;
  font-weight: 700; font-size: 0.95rem;
}
.motoai-hub-items {
  list-style: none; margin: 0; padding: 0 0 6px 14px;
  border-left: 2px solid var(--color-primary-soft, rgba(79, 70, 229, 0.2));
}
.motoai-hub-items li a { display: flex; align-items: center; min-height: 44px; font-size: 0.9rem; }

/* Drawer theme row (v63): shared by the chat homepage AND content pages —
   one implementation, identical look. Kept in sync by theme.js which
   preserves the "🌗 Chủ đề: " label on .motoai-drawer-theme toggles. */
.motoai-drawer-theme {
  width: 100%;
  justify-content: flex-start;
  min-height: 48px;
  border: none;
  background: none;
  font-weight: 550;
  font-size: 0.95rem;
  text-align: left;
}
/* Chat-only utility separator before the Xóa chat action (chat homepage). */
.motoai-drawer-divider {
  list-style: none;
  border-top: 1px solid var(--color-border);
  margin: 8px 4px;
}

/* ---------- Accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

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

/* ---------- Embed iframe mode ---------- */
body[data-motoai-embed="1"] .motoai-app {
  max-width: none;
  height: 100%;
}

/* --- Context reset button (v44) --- */
.motoai-reset {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}
.motoai-reset:hover { background: var(--color-surface-elevated); color: var(--color-text); }
.motoai-reset:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---------- v47.1: chatbot-first shell + menu drawer ---------- */
/* The chatbot IS the homepage — no hero above it. Supporting SEO copy
   (.motoai-seo) renders AFTER the app, unobtrusive and muted. */
.motoai-shell {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* The chat app fills the viewport exactly, edge-to-edge — "full màn hình như app".
   The SEO copy lives below the 100dvh app, so it is never in the first viewport. */
.motoai-shell .motoai-app { height: 100dvh; min-height: 100dvh; }

/* Unobtrusive SEO copy below the chatbot (hidden in embed mode). */
.motoai-seo { padding: var(--space-3) var(--space-2) 0; }
.motoai-seo-copy {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--color-text-muted);
}
.motoai-seo-copy a { color: var(--color-primary); }

/* Install button (PWA) — hidden until beforeinstallprompt fires. */
.motoai-install {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.motoai-install:hover { filter: brightness(1.08); }
.motoai-install:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.motoai-ios-hint { color: var(--color-text-muted); }
body[data-motoai-embed="1"] .motoai-install { display: none; }

/* v58: homepage theme control (Auto → Sáng → Tối), sits before Menu (right side). */
.motoai-theme {
  flex: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.82rem;
  line-height: 1;
  cursor: pointer;
}
.motoai-theme:hover { border-color: var(--color-primary); color: var(--color-primary); }
.motoai-theme:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }


/* Menu button replaces the old broom icon in the header. */
/* Menu button (v51): icon + "Menu" pill with indigo accent — discoverable. */
.motoai-menu {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;               /* touch target */
  padding: 0 14px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full); /* pill */
  background: var(--color-primary);
  color: var(--color-on-primary);  /* white text on purple in both themes */
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  /* One-time first-load attention cue: 3 subtle glow pulses then stops. */
  animation: motoai-menu-glow 1.6s var(--ease) 3; /* finite, ~3 cycles */
}
.motoai-menu:hover { background: var(--color-primary-hover); }
.motoai-menu:active { background: var(--color-primary-hover); transform: scale(0.97); } /* obvious tap state */
.motoai-menu:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.motoai-menu-label { white-space: nowrap; }
@keyframes motoai-menu-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124, 124, 244, 0); }
  50% { box-shadow: 0 0 0 6px rgba(124, 124, 244, 0.35); }
}
/* Reduced motion: no pulse at all — button stays fully usable. */
@media (prefers-reduced-motion: reduce) {
  .motoai-menu { animation: none; }
}

/* Drawer */
.motoai-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 27, 0.45);
  z-index: 40;
}
.motoai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(84vw, 300px);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  z-index: 41;
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-3)) var(--space-3) calc(env(safe-area-inset-bottom, 0px) + var(--space-4));
  overflow-y: auto;                      /* long menus scroll INSIDE the drawer */
  -webkit-overflow-scrolling: touch;
}
.motoai-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.motoai-drawer-close {
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 0.95rem;
  cursor: pointer;
}
.motoai-drawer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.motoai-drawer-list a,
.motoai-drawer-list button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: 0.92rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.motoai-drawer-list a:hover,
.motoai-drawer-list button:hover { background: var(--color-primary-soft); color: var(--color-primary); }
.motoai-drawer-list a[hidden], .motoai-drawer-list button[hidden] { display: none; }

/* Embed iframe mode: no SEO copy, no menu — the widget stays minimal. */
body[data-motoai-embed="1"] .motoai-shell { max-width: none; padding: 0; }
body[data-motoai-embed="1"] .motoai-seo,
body[data-motoai-embed="1"] .motoai-drawer,
body[data-motoai-embed="1"] .motoai-drawer-backdrop,
body[data-motoai-embed="1"] .motoai-menu { display: none; }
body[data-motoai-embed="1"] .motoai-app { max-width: none; height: 100%; min-height: 0; }
/* ---------- v47.4 / v60: mobile app-lock refinements (iPhone Safari) ----------
   The document never scroll-panes during chat use: CHAT HOMEPAGE ONLY
   (body.chat-home) locks the viewport. Per CSS spec, overflow on body with
   html:visible propagates to the viewport — no html-level lock needed.
   Content pages never load this lock. Embed mode keeps its own flow. */
body.chat-home { overflow: hidden; overscroll-behavior: none; }
body[data-motoai-embed="1"] { overflow: auto; overscroll-behavior: auto; } /* embed unchanged */

/* App pinned edge-to-edge: the header can never drift under Safari chrome. */
.motoai-shell .motoai-app { position: fixed; inset: 0; }
body[data-motoai-embed="1"] .motoai-app { position: static; inset: auto; }

/* ---------- EMBED HEIGHT CHAIN FIX (embed-layout-2) ----------
   The iframe's own 100% height is canonical in embed mode: the host /shop
   panel/iframe already follows visualViewport. Previously .motoai-app used
   height:100% but .motoai-shell had NO definite height, so 100% did not
   resolve reliably on iOS Safari and the app collapsed to content height,
   leaving a large blank area below the composer. Definite chain:
   html -> body -> .motoai-shell -> .motoai-app, all height:100%, min-height:0.
   No independent 100dvh layout is used in embed mode. */
body[data-motoai-embed="1"] {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body[data-motoai-embed="1"] .motoai-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body[data-motoai-embed="1"] .motoai-app {
  position: static;
  inset: auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  max-width: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Stable zones: header / chips / composer never shrink or reflow. */
.motoai-header, .motoai-quick, .motoai-composer { flex: 0 0 auto; }
.motoai-messages { overscroll-behavior-y: contain; } /* chat scroll never chains to body */

/* Pristine state: a lone greeting sits upper-middle instead of hugging the
   top with dead space below. Applies only while it is the only message. */
.motoai-messages > .motoai-msg:only-child {
  margin-top: auto;
  margin-bottom: auto;
  translate: 0 -6vh;
}


/* ---------- v49: responsive device classes (mobile-first) ---------- */
/* Base (<=767px) is the mobile app-lock above: full-screen chat, messages
   86% wide, drawer min(84vw, 300px). Larger classes below do NOT stretch the
   phone UI — they re-center a comfortable chat column and relax density. */

/* Laptop / tablet landscape 768–1199px: centered chat application. */
@media (min-width: 768px) {
  .motoai-shell { max-width: 820px; }
  .motoai-shell .motoai-app { max-width: 820px; }
  body[data-motoai-embed="1"] .motoai-app { max-width: none; } /* embed keeps its own flow */
  .motoai-app {
    padding:
      calc(env(safe-area-inset-top, 0px) + var(--space-3))
      calc(env(safe-area-inset-right, 0px) + var(--space-4))
      calc(env(safe-area-inset-bottom, 0px) + var(--space-3))
      calc(env(safe-area-inset-left, 0px) + var(--space-4));
    gap: var(--space-3);
  }
  .motoai-header { padding: var(--space-3) var(--space-1) var(--space-4); }
  .motoai-msg { max-width: 80%; }               /* readable line length */
  .motoai-input { padding: 12px 16px; }
  .motoai-drawer { width: 320px; }               /* intentional with a mouse */
}

/* Desktop 1200–1599px: premium centered column — never a stretched phone. */
@media (min-width: 1200px) {
  .motoai-shell { max-width: 940px; }
  .motoai-shell .motoai-app { max-width: 940px; }
  .motoai-app {
    padding:
      calc(env(safe-area-inset-top, 0px) + var(--space-4))
      calc(env(safe-area-inset-right, 0px) + var(--space-5))
      calc(env(safe-area-inset-bottom, 0px) + var(--space-4))
      calc(env(safe-area-inset-left, 0px) + var(--space-5));
    gap: var(--space-4);
  }
  .motoai-header { padding: var(--space-4) var(--space-2) var(--space-5); }
  .motoai-msg { max-width: 74%; font-size: 0.95rem; }
  .motoai-input { padding: 13px 18px; }
  .motoai-send { padding: 0 24px; }
  .motoai-drawer { width: 340px; }
}

/* Large desktop >=1600px: capped column with balanced side breathing room. */
@media (min-width: 1600px) {
  .motoai-shell { max-width: 1000px; }
  .motoai-shell .motoai-app { max-width: 1000px; }
  .motoai-msg { max-width: 72%; }
  .motoai-drawer { width: 360px; }
}
