/**
 *  /assets/css/hi_allove_widget.css  —  Hi Allove guest widget
 *  -----------------------------------------------------------------------
 *  Self-contained · scoped under #hi-allove-root to avoid host page conflicts.
 *  Mobile-first · responsive · burgundy brand (#7A1F2B) accents.
 */

#hi-allove-root {
  --ha-brand: #7A1F2B;
  --ha-brand-dark: #5A1620;
  --ha-brand-light: #FCE8EA;
  --ha-bg: #ffffff;
  --ha-text: #1a1a1a;
  --ha-muted: #6b6b6b;
  --ha-border: #e5e5e5;
  --ha-bubble-bot: #f4f4f5;
  --ha-bubble-staff: #fff4e6;
  --ha-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial,
               "Sukhumvit Set", "IBM Plex Sans Thai", "Noto Sans Thai", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ha-text);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  #hi-allove-root {
    --ha-bg: #1f1f23;
    --ha-text: #f4f4f5;
    --ha-muted: #a1a1aa;
    --ha-border: #353539;
    --ha-bubble-bot: #2a2a2f;
    --ha-bubble-staff: #3a2a1f;
  }
}

/* ─── Launcher (floating button) ─────────────────────────────────────── */
#hi-allove-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999990;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 12px 12px;
  background: var(--ha-brand);
  color: #fff;
  border: 0;
  border-radius: 28px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--ha-shadow);
  transition: transform 0.15s ease, background 0.15s ease;
}
#hi-allove-launcher:hover { background: var(--ha-brand-dark); transform: translateY(-1px); }
#hi-allove-launcher:active { transform: translateY(0); }
#hi-allove-launcher .ha-avatar {
  width: 32px; height: 32px;
  background: #fff;
  color: var(--ha-brand);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
}

/* ─── Panel (chat window) ───────────────────────────────────────────── */
#hi-allove-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999991;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 540px;
  max-height: calc(100vh - 40px);
  background: var(--ha-bg);
  border: 1px solid var(--ha-border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--ha-shadow);
}
@media (max-width: 480px) {
  #hi-allove-panel {
    right: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 90vh; max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }
  #hi-allove-launcher { right: 14px; bottom: 14px; }
}

/* ─── Header ────────────────────────────────────────────────────────── */
#hi-allove-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ha-brand);
  color: #fff;
  flex-shrink: 0;
}
#hi-allove-header .ha-avatar-circle {
  width: 44px; height: 44px;
  background: #fff;
  color: var(--ha-brand);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
  overflow: hidden;
  flex-shrink: 0;
}
#hi-allove-header .ha-avatar-circle.ha-avatar-brand {
  background: var(--ha-brand);
  padding: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.35);
}
#hi-allove-header .ha-avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

/* Launcher button image (replaces the "A" letter span) */
#hi-allove-launcher .ha-launcher-logo {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.3);
}
.ha-header-text { flex: 1; min-width: 0; }
#hi-allove-title  { font-weight: 600; font-size: 15px; line-height: 1.2; }
.ha-subtitle      { font-size: 12px; opacity: 0.9; margin-top: 2px; }
#hi-allove-close {
  background: transparent; color: #fff;
  border: 0; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.85;
}
#hi-allove-close:hover { opacity: 1; background: rgba(255,255,255,0.1); }

/* ─── Thread (messages) ─────────────────────────────────────────────── */
#hi-allove-thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 12px;
  background: var(--ha-bg);
  scrollbar-width: thin;
}
#hi-allove-thread::-webkit-scrollbar { width: 6px; }
#hi-allove-thread::-webkit-scrollbar-thumb { background: var(--ha-border); border-radius: 3px; }

.ha-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: flex-end;
}
.ha-row-user { justify-content: flex-end; }
.ha-row-system { justify-content: center; }

.ha-avatar-circle.ha-avatar-mini {
  width: 26px; height: 26px;
  background: var(--ha-brand);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.ha-avatar-staff { background: #BA7517 !important; }

.ha-staff-col { display: flex; flex-direction: column; max-width: 75%; }
.ha-staff-name {
  font-size: 11px; color: var(--ha-muted);
  margin: 0 4px 4px; font-weight: 500;
}

.ha-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  max-width: 75%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.ha-bubble-user {
  background: var(--ha-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ha-bubble-bot {
  background: var(--ha-bubble-bot);
  color: var(--ha-text);
  border-top-left-radius: 4px;
}
.ha-bubble-staff {
  background: var(--ha-bubble-staff);
  color: var(--ha-text);
  border-top-left-radius: 4px;
}
.ha-bubble-system {
  background: transparent;
  color: var(--ha-muted);
  font-size: 11px;
  font-style: italic;
  padding: 4px 12px;
  text-align: center;
}

.ha-image {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
}

/* ─── Quick replies ─────────────────────────────────────────────────── */
.ha-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px 34px;
}
.ha-qr-btn {
  background: transparent;
  color: var(--ha-brand);
  border: 1px solid var(--ha-brand);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.ha-qr-btn:hover {
  background: var(--ha-brand);
  color: #fff;
}

/* ─── Typing indicator ──────────────────────────────────────────────── */
.ha-typing {
  background: var(--ha-bubble-bot);
  padding: 10px 14px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  display: inline-flex;
  gap: 4px;
}
.ha-typing span {
  width: 6px; height: 6px;
  background: var(--ha-muted);
  border-radius: 50%;
  animation: ha-bounce 1.2s infinite;
}
.ha-typing span:nth-child(2) { animation-delay: 0.2s; }
.ha-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ha-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── Composer ──────────────────────────────────────────────────────── */
#hi-allove-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ha-border);
  background: var(--ha-bg);
  flex-shrink: 0;
}
#hi-allove-input {
  flex: 1;
  border: 1px solid var(--ha-border);
  background: var(--ha-bg);
  color: var(--ha-text);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
#hi-allove-input:focus { border-color: var(--ha-brand); }
#hi-allove-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ha-brand);
  color: #fff;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#hi-allove-send:hover { background: var(--ha-brand-dark); }

/* ─── Sticker button + picker · 2026-05-12 ────────────────────────────
 *  Adds an inline picker above the composer with tabs of OFFICIAL packs
 *  and a grid of sticker thumbnails.  Mobile keeps the same width as
 *  the panel (no overflow). */
#hi-allove-sticker-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  color: var(--ha-brand);
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.08s;
}
#hi-allove-sticker-btn:hover  { background: rgba(122,31,43,0.08); }
#hi-allove-sticker-btn:active { transform: scale(0.92); }
#hi-allove-sticker-btn[aria-expanded="true"] {
  background: rgba(122,31,43,0.12);
}

#hi-allove-stk-picker {
  background: var(--ha-bg);
  border-top: 1px solid var(--ha-border);
  display: flex;
  flex-direction: column;
  height: 260px;
  flex-shrink: 0;
  animation: ha-stk-slide 0.18s ease-out;
}
@keyframes ha-stk-slide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
#hi-allove-stk-picker[hidden] { display: none; }

#hi-allove-stk-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--ha-border);
  background: #faf6f3;
  flex-shrink: 0;
}
.ha-stk-tab {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--ha-muted);
  transition: background 0.15s;
}
.ha-stk-tab:hover { background: rgba(122,31,43,0.08); }
.ha-stk-tab[aria-selected="true"] {
  background: rgba(122,31,43,0.15);
}
.ha-stk-tab img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

#hi-allove-stk-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  scrollbar-width: thin;
  color: var(--ha-muted);
  font-size: 13px;
  align-content: start;
}
/* When grid is showing a single status message (loading/empty), span all cols */
#hi-allove-stk-grid:not(:has(.ha-stk-item)) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.ha-stk-item {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 0;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.08s;
}
.ha-stk-item:hover  { background: rgba(122,31,43,0.06); transform: scale(1.04); }
.ha-stk-item:active { transform: scale(0.95); }
.ha-stk-item img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
}

/* Sticker bubble — transparent · no padding · no background tint */
.ha-bubble-sticker {
  background: transparent !important;
  padding: 2px !important;
  box-shadow: none !important;
}
.ha-sticker-img {
  max-width: 140px;
  max-height: 140px;
  display: block;
}

/* Mobile · taller picker fits keyboard-up layouts */
@media (max-width: 480px) {
  #hi-allove-stk-picker { height: 220px; }
  #hi-allove-stk-grid   { grid-template-columns: repeat(3, 1fr); }
  .ha-sticker-img       { max-width: 120px; max-height: 120px; }
}

/* ─── Footer ────────────────────────────────────────────────────────── */
#hi-allove-footer {
  text-align: center;
  padding: 6px 8px;
  font-size: 10px;
  color: var(--ha-muted);
  background: var(--ha-bg);
  border-top: 1px solid var(--ha-border);
  flex-shrink: 0;
}

/* === HELP_BOT_AVATAR_V1 · show ALLOVE logo on bot message avatar (2026-05-20) === */
.ha-row-bot .ha-avatar-circle.ha-avatar-mini {
  font-size: 0;
  background-color: var(--ha-brand);
  background-image: url('/assets/logo/hiallove_logo_red_avatar_192.png?v=20260512c');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
