/* ============================================================
   Hatena Base Chat Widget
   ============================================================ */

/* --- Invite Popup --- */
.hb-chat-invite {
  position: fixed;
  bottom: 148px;
  right: 28px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 24px;
  padding: 10px 16px 10px 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.hb-chat-invite.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}
.hb-chat-invite__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8f0fe, #d4e4f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.hb-chat-invite__text {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  font-family: "Zen Kaku Gothic New", sans-serif;
  white-space: nowrap;
}
.hb-chat-invite__close {
  background: none;
  border: none;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.hb-chat-invite__close:hover {
  color: #666;
}
/* Tail triangle pointing down-right */
.hb-chat-invite::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 30px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #fff;
}

@media (max-width: 480px) {
  .hb-chat-invite {
    right: 16px;
    bottom: 80px;
  }
}

/* --- Toggle Button --- */
.hb-chat-toggle {
  position: fixed;
  bottom: 80px;
  right: 28px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: var(--hb-brand, #2A5772);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(42, 87, 114, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.hb-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(42, 87, 114, 0.55);
}
.hb-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: opacity 0.2s;
}
.hb-chat-toggle .icon-close {
  display: none;
}
.hb-chat-toggle.is-open .icon-chat {
  display: none;
}
.hb-chat-toggle.is-open .icon-close {
  display: block;
}

/* --- Widget Panel --- */
.hb-chat-widget {
  position: fixed;
  bottom: 152px;
  right: 28px;
  z-index: 9997;
  width: 420px;
  max-height: 680px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.hb-chat-widget.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* --- Header --- */
.hb-chat-header {
  background: var(--hb-brand, #2A5772);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.hb-chat-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.hb-chat-header__info {
  flex: 1;
}
.hb-chat-header__name {
  font-size: 14px;
  font-weight: 700;
  font-family: "Zen Kaku Gothic New", sans-serif;
  line-height: 1.3;
}
.hb-chat-header__status {
  font-size: 11px;
  opacity: 0.8;
  font-family: "Zen Kaku Gothic New", sans-serif;
}

/* --- Messages Area --- */
.hb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #F7F9FC;
  scroll-behavior: smooth;
}
.hb-chat-messages::-webkit-scrollbar {
  width: 4px;
}
.hb-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.hb-chat-messages::-webkit-scrollbar-thumb {
  background: #C8D8E4;
  border-radius: 2px;
}

/* --- Message Bubble --- */
.hb-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: hbFadeUp 0.2s ease;
}
@keyframes hbFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hb-msg--bot {
  align-self: flex-start;
}
.hb-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.hb-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--hb-brand, #2A5772);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  color: #fff;
}
.hb-msg__bubble {
  max-width: 260px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.6;
  font-family: "Zen Kaku Gothic New", sans-serif;
  color: #333;
  word-break: break-word;
}
.hb-msg--bot .hb-msg__bubble {
  background: #fff;
  border: 1px solid #E2EAF0;
  border-bottom-left-radius: 4px;
}
.hb-msg--user .hb-msg__bubble {
  background: var(--hb-brand, #2A5772);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.hb-msg--typing .hb-msg__bubble {
  padding: 12px 16px;
}
.hb-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 16px;
}
.hb-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9BAFC0;
  animation: hbDot 1.2s infinite ease-in-out;
}
.hb-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.hb-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes hbDot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* --- Selection Buttons --- */
.hb-selections {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
  animation: hbFadeUp 0.2s ease;
}
.hb-sel-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid #C8D8E4;
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 13px;
  font-family: "Zen Kaku Gothic New", sans-serif;
  color: var(--hb-brand, #2A5772);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-weight: 500;
}
.hb-sel-btn:hover {
  background: #EDF3F7;
  border-color: var(--hb-brand, #2A5772);
  transform: translateX(2px);
}
.hb-sel-btn .hb-sel-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* --- Link Cards --- */
.hb-link-cards {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
  animation: hbFadeUp 0.2s ease;
}
.hb-link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1.5px solid #E2EAF0;
  border-radius: 10px;
  padding: 10px 13px;
  text-decoration: none;
  color: #333;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: "Zen Kaku Gothic New", sans-serif;
}
.hb-link-card:hover {
  border-color: var(--hb-brand, #2A5772);
  box-shadow: 0 2px 8px rgba(42, 87, 114, 0.12);
  text-decoration: none;
  color: var(--hb-brand, #2A5772);
}
.hb-link-card__icon {
  font-size: 18px;
  flex-shrink: 0;
}
.hb-link-card__body {
  flex: 1;
  min-width: 0;
}
.hb-link-card__label {
  font-size: 10px;
  color: #9BAFC0;
  font-family: "Jost", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.hb-link-card__title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hb-link-card__desc {
  font-size: 11px;
  color: #8C9DAA;
  line-height: 1.4;
  margin-top: 2px;
}
.hb-link-card__arrow {
  color: #9BAFC0;
  font-size: 14px;
  flex-shrink: 0;
}

/* --- "Back to menu" button --- */
.hb-back-btn {
  background: none;
  border: none;
  color: #9BAFC0;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  font-family: "Zen Kaku Gothic New", sans-serif;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  transition: color 0.15s;
}
.hb-back-btn:hover {
  color: var(--hb-brand, #2A5772);
}

/* --- Input Area --- */
.hb-chat-input-area {
  border-top: 1px solid #E2EAF0;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
  flex-shrink: 0;
}
.hb-chat-input {
  flex: 1;
  border: 1.5px solid #C8D8E4;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: "Zen Kaku Gothic New", sans-serif;
  color: #333;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  transition: border-color 0.15s;
  background: #F7F9FC;
}
.hb-chat-input:focus {
  border-color: var(--hb-brand, #2A5772);
  background: #fff;
}
.hb-chat-input::placeholder {
  color: #B0BFC9;
}
.hb-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--hb-brand, #2A5772);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.hb-chat-send:hover {
  background: color-mix(in srgb, var(--hb-brand, #2A5772), black 15%);
}
.hb-chat-send:active {
  transform: scale(0.93);
}
.hb-chat-send svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}
.hb-chat-send:disabled {
  background: #C8D8E4;
  cursor: not-allowed;
}

/* --- Tablet --- */
@media (max-width: 768px) {
  .hb-chat-widget {
    width: 380px;
    max-height: 620px;
    bottom: 96px;
  }
}

/* --- Mobile --- */
@media (max-width: 480px) {
  .hb-chat-widget {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  }
  .hb-chat-widget.is-open {
    /* Full screen on mobile */
    height: 100dvh;
  }
  .hb-chat-toggle {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
  .hb-chat-toggle.is-open {
    /* Hide toggle when chat is fullscreen on mobile */
    display: none;
  }
  .hb-chat-header {
    padding: 16px 18px;
    /* Safe area for notch phones */
    padding-top: max(16px, env(safe-area-inset-top));
  }
  .hb-chat-header__name {
    font-size: 15px;
  }
  .hb-chat-messages {
    padding: 16px;
  }
  .hb-msg__bubble {
    max-width: 85%;
    font-size: 14px;
  }
  .hb-sel-btn {
    padding: 12px 14px;
    font-size: 14px;
  }
  .hb-chat-input-area {
    padding: 10px 14px;
    /* Safe area for home indicator */
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .hb-chat-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
    padding: 10px 14px;
  }
  .hb-chat-send {
    width: 40px;
    height: 40px;
  }
  .hb-link-card {
    padding: 12px 14px;
  }
  .hb-link-card__title {
    font-size: 13px;
    white-space: normal;
  }
}

/* --- Close button for mobile fullscreen --- */
.hb-chat-header__close {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.hb-chat-header__close:hover {
  color: #fff;
}
@media (max-width: 480px) {
  .hb-chat-header__close {
    display: block;
  }
}
