/**
 * "ASK" — The Asiatic Society chatbot widget.
 *
 * Self-contained, site-wide floating chat assistant. All rules are scoped
 * under .ask-root so they cannot leak into (or be broken by) theme CSS.
 */

.ask-root {
  --ask-primary: #771d1d;
  --ask-primary-dark: #5e1414;
  --ask-cream: #fbf2e9;
  --ask-surface: #ffffff;
  --ask-border: #efe2d4;
  --ask-ink: #2f2a26;
  --ask-muted: #9b9189;
  --ask-amber: #b07d16;
  --ask-radius: 16px;

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99999;
  font-family: 'Noto Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ask-ink);
}

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

.ask-root button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  color: inherit;
}

.ask-root a {
  text-decoration: none;
}

/* ===========================================================
   Floating action button
   =========================================================== */
.ask-fab {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  color: var(--ask-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ask-primary);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(119, 29, 29, 0.4);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ask-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 28px rgba(119, 29, 29, 0.5);
}

.ask-fab:focus-visible {
  outline: 3px solid var(--ask-primary);
  outline-offset: 3px;
}

.ask-fab-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Small "online" dot on the FAB. */
.ask-fab::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2.5px solid #fff;
  z-index: 1;
}

.ask-root.is-open .ask-fab {
  display: none;
}

/* ===========================================================
   Chat panel
   =========================================================== */
.ask-panel {
  display: none;
  flex-direction: column;
  width: min(560px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 48px));
  background: var(--ask-cream);
  border-radius: var(--ask-radius);
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.ask-root.is-open .ask-panel {
  display: flex;
  animation: ask-pop 0.22s ease-out;
}

@keyframes ask-pop {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ----- Header ----- */
.ask-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ask-primary);
  color: #fff;
  flex-shrink: 0;
}

.ask-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  color: var(--ask-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ask-avatar .ask-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ask-header-text {
  flex: 1;
  min-width: 0;
}

.ask-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.ask-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.9;
}

.ask-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2ecc71;
}

.ask-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.ask-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.ask-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* ----- Message list ----- */
.ask-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ask-body::-webkit-scrollbar {
  width: 6px;
}

.ask-body::-webkit-scrollbar-thumb {
  background: #dac9b6;
  border-radius: 3px;
}

/* ----- A single message row ----- */
.ask-msg {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  animation: ask-fade 0.25s ease-out;
}

@keyframes ask-fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ask-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ask-msg-row--top {
  align-items: flex-start;
}

.ask-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  color: var(--ask-primary);
  border: 1px solid var(--ask-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ask-msg-avatar .ask-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ask-bubble {
  max-width: 80%;
  padding: 11px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* When the bubble contains a markdown table, let it grow to fit and
   give the inner table room to scroll horizontally. */
.ask-msg--bot .ask-bubble:has(.ask-table-wrap) {
  max-width: 100%;
  width: 100%;
  white-space: normal;
  padding-left: 8px;
  padding-right: 8px;
}

.ask-bubble .ask-bubble-text {
  white-space: pre-wrap;
}

.ask-bubble .ask-bubble-text + .ask-table-wrap,
.ask-bubble .ask-table-wrap + .ask-bubble-text,
.ask-bubble .ask-table-wrap + .ask-table-wrap {
  margin-top: 10px;
}

.ask-bubble .ask-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  max-height: 360px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--ask-border);
  background: #fff;
  /* Subtle right-edge fade hints there's more to scroll. */
  background-image: linear-gradient(to right, transparent calc(100% - 24px), rgba(0, 0, 0, 0.04));
  background-attachment: local;
  -webkit-overflow-scrolling: touch;
}

.ask-bubble .ask-table {
  /* Each column gets at least a comfortable reading width so the table
     overflows horizontally instead of crushing every cell to one char.
     Approx (min-width-per-col × col-count). table-layout:auto means we
     don't need to pre-compute exactly; columns expand to content. */
  min-width: 480px;
  width: max-content;
  max-width: none;
  border-collapse: collapse;
  font-size: 12.5px;
  line-height: 1.45;
}

.ask-bubble .ask-table th,
.ask-bubble .ask-table td {
  padding: 7px 10px;
  min-width: 110px;
  border-bottom: 1px solid var(--ask-border);
  border-right: 1px solid var(--ask-border);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
}

.ask-bubble .ask-table th:last-child,
.ask-bubble .ask-table td:last-child {
  border-right: none;
}

.ask-bubble .ask-table tbody tr:last-child td {
  border-bottom: none;
}

.ask-bubble .ask-table thead th {
  background: #f3eee9;
  color: var(--ask-ink);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.ask-bubble .ask-table tbody tr:nth-child(even) td {
  background: #fbf8f5;
}

/* Custom scrollbar so the table-wrap scrollers feel light. */
.ask-bubble .ask-table-wrap::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}
.ask-bubble .ask-table-wrap::-webkit-scrollbar-thumb {
  background: rgba(119, 29, 29, 0.25);
  border-radius: 4px;
}
.ask-bubble .ask-table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(119, 29, 29, 0.45);
}

/* Bot bubble */
.ask-msg--bot .ask-bubble {
  background: var(--ask-surface);
  border: 1px solid var(--ask-border);
  border-bottom-left-radius: 4px;
  color: var(--ask-ink);
}

/* User bubble */
.ask-msg--user .ask-msg-row {
  flex-direction: row-reverse;
}

.ask-msg--user .ask-bubble {
  background: var(--ask-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ask-time {
  font-size: 10.5px;
  color: var(--ask-muted);
  margin-top: 5px;
  padding: 0 6px;
}

.ask-msg--bot .ask-time {
  margin-left: 38px;
}

.ask-msg--user .ask-time {
  text-align: right;
}

/* ----- Typing indicator ----- */
.ask-typing {
  display: flex;
  gap: 4px;
  padding: 14px;
}

.ask-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9b9a5;
  animation: ask-bounce 1.2s infinite ease-in-out;
}

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

@keyframes ask-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ----- Source card ----- */
.ask-source {
  margin-top: 10px;
  margin-left: 38px;
  background: #fff;
  border: 1px solid #e7c9c9;
  border-radius: 12px;
  padding: 12px 14px;
}

.ask-source-head {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ask-primary);
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 6px;
}

.ask-source-head svg {
  width: 15px;
  height: 15px;
}

.ask-source-title {
  color: var(--ask-primary);
  font-weight: 700;
  font-size: 13.5px;
}

.ask-source-excerpt {
  color: #9a5b3f;
  font-style: italic;
  font-size: 12.5px;
  margin-top: 3px;
}

.ask-source-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ask-primary);
  font-weight: 600;
  font-size: 12.5px;
  margin-top: 8px;
}

.ask-source-link:hover {
  text-decoration: underline;
}

.ask-source-link svg {
  width: 13px;
  height: 13px;
}

/* ----- Feedback row ----- */
.ask-feedback {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  margin-left: 38px;
}

.ask-fb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border: 1px solid var(--ask-border);
  border-radius: 20px;
  background: #fff;
  font-size: 12.5px;
  color: #6b6259;
  transition: all 0.15s ease;
}

.ask-fb-btn:hover {
  border-color: var(--ask-primary);
  color: var(--ask-primary);
}

.ask-fb-btn.is-selected {
  background: var(--ask-primary);
  border-color: var(--ask-primary);
  color: #fff;
}

.ask-fb-done {
  margin-left: 38px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ask-muted);
}

/* ===========================================================
   "Unable to find an answer" card
   =========================================================== */
.ask-noanswer {
  flex: 1;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--ask-border);
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 14px;
}

.ask-na-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ask-amber);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
}

.ask-na-text {
  color: var(--ask-ink);
  font-size: 13px;
}

.ask-na-flag {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #f6e7ec;
  color: var(--ask-primary);
  font-size: 12.5px;
  padding: 9px 11px;
  border-radius: 9px;
  margin-top: 12px;
}

.ask-na-suggest {
  background: #faf6ef;
  border-radius: 10px;
  padding: 11px 12px;
  margin-top: 12px;
}

.ask-na-suggest-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 7px;
}

.ask-na-suggest ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ask-na-suggest li {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12.5px;
  color: #6b6259;
  padding: 4px 0;
}

.ask-na-suggest li::before {
  content: '✓';
  color: #c79a3e;
  font-weight: 800;
  flex-shrink: 0;
}

.ask-na-contact {
  border-top: 1px solid var(--ask-border);
  margin-top: 12px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ask-na-contact a {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ask-primary);
  font-weight: 600;
  font-size: 12.5px;
}

.ask-na-contact a:hover {
  text-decoration: underline;
}

.ask-retry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: calc(100% - 38px);
  margin-left: 38px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--ask-border);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--ask-ink);
  transition: all 0.15s ease;
}

.ask-retry:hover {
  border-color: var(--ask-primary);
  color: var(--ask-primary);
}

.ask-retry svg {
  width: 15px;
  height: 15px;
}

/* ===========================================================
   Input + footer
   =========================================================== */
.ask-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 6px;
  flex-shrink: 0;
}

.ask-input input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 16px;
  border: 1px solid #d9b8b8;
  border-radius: 24px;
  background: #fff;
  font-size: 13.5px;
  color: var(--ask-ink);
  outline: none;
}

.ask-input input:focus {
  border-color: var(--ask-primary);
}

.ask-input input::placeholder {
  color: #b5a89c;
}

.ask-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--ask-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.ask-send:hover {
  background: var(--ask-primary-dark);
}

.ask-send:disabled {
  background: #c9b3b3;
  cursor: not-allowed;
}

.ask-send:focus-visible {
  outline: 2px solid var(--ask-primary);
  outline-offset: 2px;
}

.ask-send svg {
  width: 19px;
  height: 19px;
}

.ask-footer {
  text-align: center;
  font-size: 10.5px;
  color: var(--ask-muted);
  padding: 4px 10px 10px;
  flex-shrink: 0;
}

/* ===========================================================
   Mobile — near full-screen
   =========================================================== */
@media (max-width: 480px) {
  .ask-root {
    right: 16px;
    bottom: 16px;
  }

  .ask-root.is-open {
    right: 0;
    bottom: 0;
  }

  .ask-panel {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .ask-root.is-open .ask-panel,
  .ask-msg {
    animation: none;
  }

  .ask-fab,
  .ask-typing span {
    transition: none;
    animation: none;
  }
}
