/* =========================================================
   Fast IELTS Studies — support chat widget
   Shared by the landing page and every member page.
   ========================================================= */

.fis-chat {
  font-family: var(--font-body);
  color: var(--ink);
}

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

.fis-chat-panel[hidden],
.fis-chat-suggest[hidden] {
  display: none !important;
}

/* ---------- Launcher ---------- */

.fis-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 116;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 20px 0 12px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-dark) 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow:
    0 20px 44px -20px rgba(53, 39, 184, 0.72),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  transition: transform 0.22s ease, box-shadow 0.22s ease, opacity 0.22s ease, visibility 0.22s ease;
}

.fis-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow:
    0 26px 52px -20px rgba(53, 39, 184, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}

.fis-chat-launcher:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

.fis-chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  flex: none;
}

.fis-chat-launcher-icon svg {
  width: 21px;
  height: 21px;
}

.fis-chat-launcher-label {
  padding-right: 6px;
}

.fis-chat-launcher-dot {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 8px;
  height: 8px;
  border: 2px solid var(--indigo);
  border-radius: 50%;
  background: var(--amber);
  box-sizing: content-box;
}

.fis-chat.is-open .fis-chat-launcher {
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  pointer-events: none;
}

/* ---------- Panel ---------- */

.fis-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 117;
  display: flex;
  flex-direction: column;
  width: min(398px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 48px));
  height: min(640px, calc(100dvh - 48px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  border: 1px solid rgba(74, 61, 224, 0.16);
  border-radius: 24px;
  background: var(--paper-2);
  box-shadow:
    0 36px 90px -30px rgba(23, 19, 41, 0.55),
    0 2px 8px rgba(23, 19, 41, 0.06);
  animation: fis-chat-panel-in 0.26s cubic-bezier(0.22, 0.9, 0.32, 1);
}

@keyframes fis-chat-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* ---------- Header ---------- */

.fis-chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 13px 14px 16px;
  background:
    radial-gradient(circle at 12% -20%, rgba(243, 172, 60, 0.24), transparent 12rem),
    linear-gradient(135deg, #251b67 0%, var(--indigo) 58%, #5a4bf1 100%);
  color: #fff;
  flex: none;
}

.fis-chat-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  flex: none;
}

.fis-chat-avatar svg {
  width: 21px;
  height: 21px;
  color: var(--amber);
}

.fis-chat-id {
  min-width: 0;
}

.fis-chat-id strong {
  display: block;
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.fis-chat-id span {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 10.5px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.66);
}

.fis-chat-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(243, 172, 60, 0.16);
  flex: none;
}

.fis-chat-head-actions {
  display: flex;
  gap: 3px;
  margin-left: auto;
  flex: none;
}

.fis-chat-icon-btn {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.64);
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.fis-chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.fis-chat-icon-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.fis-chat-icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- Conversation ---------- */

.fis-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 16px 14px 10px;
  background:
    radial-gradient(circle at 100% 0%, rgba(243, 172, 60, 0.08), transparent 15rem),
    var(--paper-2);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.fis-chat-log::-webkit-scrollbar {
  width: 5px;
}

.fis-chat-log::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line);
}

.fis-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: fis-chat-msg-in 0.22s ease both;
}

.fis-msg--static {
  animation: none;
}

@keyframes fis-chat-msg-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.fis-msg-avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-bottom: 2px;
  border-radius: 9px;
  background: var(--indigo-soft);
  color: var(--indigo);
  flex: none;
}

.fis-msg-avatar svg {
  width: 14px;
  height: 14px;
}

.fis-msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  max-width: calc(100% - 34px);
}

.fis-msg-bubble {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 5px;
  background: #fff;
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.62;
  white-space: pre-line;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 22px -22px rgba(23, 19, 41, 0.45);
}

.fis-msg--user {
  justify-content: flex-end;
}

.fis-msg--user .fis-msg-body {
  align-items: flex-end;
  max-width: 86%;
}

.fis-msg--user .fis-msg-bubble {
  border: 0;
  border-radius: 16px 16px 5px 16px;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-dark) 100%);
  color: #fff;
  box-shadow: 0 14px 26px -20px rgba(74, 61, 224, 0.8);
}

.fis-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fis-msg-action {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 11px;
  border: 1px solid rgba(74, 61, 224, 0.22);
  border-radius: 999px;
  background: #fff;
  color: var(--indigo);
  font-family: var(--font-display);
  font-size: 10.8px;
  font-weight: 700;
  line-height: 1.2;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.fis-msg-action:hover {
  border-color: rgba(74, 61, 224, 0.4);
  background: var(--indigo-soft);
}

.fis-msg-action:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

/* ---------- Typing indicator ---------- */

.fis-msg--typing {
  animation: none;
}

.fis-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 39px;
  padding: 13px 14px;
}

.fis-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted-2);
  animation: fis-chat-typing 1s ease-in-out infinite;
}

.fis-typing span:nth-child(2) {
  animation-delay: 0.14s;
}

.fis-typing span:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes fis-chat-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Suggestion chips ---------- */

.fis-chat-suggest {
  display: flex;
  gap: 6px;
  flex: none;
  padding: 0 14px 10px;
  overflow-x: auto;
  background: var(--paper-2);
  scrollbar-width: none;
}

.fis-chat-suggest::-webkit-scrollbar {
  display: none;
}

.fis-chat-chip {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 10.8px;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.fis-chat-chip:hover {
  border-color: rgba(74, 61, 224, 0.35);
  background: var(--indigo-soft);
  color: var(--indigo);
}

.fis-chat-chip:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

/* ---------- Composer ---------- */

.fis-chat-compose {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.fis-chat-compose input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.fis-chat-compose input::placeholder {
  color: var(--muted-2);
}

.fis-chat-compose input:focus {
  border-color: rgba(74, 61, 224, 0.5);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(74, 61, 224, 0.1);
}

.fis-chat-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--indigo);
  color: #fff;
  cursor: pointer;
  flex: none;
  transition: opacity 0.18s ease, transform 0.18s ease, background-color 0.18s ease;
}

.fis-chat-send:hover:not(:disabled) {
  background: var(--indigo-dark);
  transform: translateY(-1px);
}

.fis-chat-send:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

.fis-chat-send:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.fis-chat-send svg {
  width: 18px;
  height: 18px;
}

.fis-chat-foot {
  flex: none;
  margin: 0;
  padding: 0 14px 10px;
  background: #fff;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.5;
  text-align: center;
}

.fis-chat-foot a {
  color: var(--indigo);
  font-weight: 650;
}

.fis-chat-foot a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  body.app-body .fis-chat-launcher {
    bottom: calc(74px + env(safe-area-inset-bottom));
  }

  body.app-body .fis-chat-panel {
    bottom: calc(72px + env(safe-area-inset-bottom));
    height: calc(100vh - 86px - env(safe-area-inset-bottom));
    height: calc(100dvh - 86px - env(safe-area-inset-bottom));
  }
}

@media (max-width: 760px) {
  .fis-chat-launcher {
    right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    height: 54px;
    padding: 0 12px 0 10px;
    gap: 8px;
  }

  .fis-chat-launcher-icon {
    width: 34px;
    height: 34px;
  }

  .fis-chat-launcher-label {
    display: none;
  }

  .fis-chat-launcher-dot {
    top: 8px;
    right: 8px;
  }

  .fis-chat-panel {
    right: 12px;
    left: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    height: calc(100vh - 24px - env(safe-area-inset-bottom));
    height: calc(100dvh - 24px - env(safe-area-inset-bottom));
    max-height: none;
    border-radius: 20px;
  }

  .fis-chat-head {
    padding: 12px 10px 12px 14px;
  }

  .fis-chat-log {
    padding: 14px 12px 8px;
  }

  .fis-chat-suggest {
    padding: 0 12px 9px;
  }

  .fis-chat-compose {
    padding: 9px 10px;
  }

  .fis-chat-foot {
    padding-bottom: 8px;
  }
}

@media (max-width: 380px) {
  .fis-chat-id span {
    font-size: 9.8px;
  }

  .fis-msg-bubble {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fis-chat-panel,
  .fis-msg,
  .fis-typing span,
  .fis-chat-launcher,
  .fis-chat-send {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  .fis-chat {
    display: none !important;
  }
}
