/**
 * PHR Wellness — Chatbot styles
 * Brand: navy #0D2240, teal #0D8FA0, Nunito Sans
 */

.phr-chat {
  --phr-navy: #0D2240;
  --phr-teal: #0D8FA0;
  --phr-teal-dark: #0A7382;
  --phr-surface: #FFFFFF;
  --phr-bg: #F4F7F9;
  --phr-border: #DCE4EA;
  --phr-text: #1C2B3A;
  --phr-muted: #5C6E7E;

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: 'Nunito Sans', system-ui, -apple-system, sans-serif;
}

/* ---------- Toggle button ---------- */

.phr-chat__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--phr-teal);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(13, 34, 64, .28);
  transition: background .2s ease, transform .2s ease;
}

.phr-chat__toggle:hover { background: var(--phr-teal-dark); }
.phr-chat__toggle:active { transform: scale(.97); }
.phr-chat__toggle:focus-visible {
  outline: 3px solid var(--phr-navy);
  outline-offset: 2px;
}

.phr-chat.is-open .phr-chat__toggle {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Panel ----------
   Closed state is enforced by BOTH visibility and pointer-events so a single
   overridden property cannot leave the panel interactive. */

.phr-chat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: var(--phr-surface);
  border: 1px solid var(--phr-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(13, 34, 64, .25);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(.98);
  transition: opacity .22s ease, transform .22s ease, visibility 0s linear .22s;
}

.phr-chat.is-open .phr-chat__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition: opacity .22s ease, transform .22s ease, visibility 0s;
}

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

.phr-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--phr-navy);
  color: #fff;
  flex-shrink: 0;
}

.phr-chat__title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .01em;
}

.phr-chat__subtitle {
  font-size: 12.5px;
  opacity: .78;
  margin-top: 2px;
}

.phr-chat__close {
  background: transparent;
  border: 0;
  color: #fff;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  opacity: .8;
  display: flex;
}

.phr-chat__close:hover { opacity: 1; background: rgba(255,255,255,.12); }
.phr-chat__close:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- Log ---------- */

.phr-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px;
  background: var(--phr-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.phr-chat__row { display: flex; }
.phr-chat__row--user { justify-content: flex-end; }
.phr-chat__row--bot { justify-content: flex-start; }

.phr-chat__bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--phr-text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.phr-chat__bubble--bot {
  background: var(--phr-surface);
  border: 1px solid var(--phr-border);
  border-bottom-left-radius: 4px;
}

.phr-chat__bubble--user {
  background: var(--phr-teal);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.phr-chat__typing .phr-chat__bubble {
  display: inline-flex;
  gap: 4px;
  padding: 14px;
}

.phr-chat__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--phr-muted);
  opacity: .45;
  animation: phrBlink 1.2s infinite;
}

.phr-chat__typing span:nth-child(2) { animation-delay: .18s; }
.phr-chat__typing span:nth-child(3) { animation-delay: .36s; }

@keyframes phrBlink {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: .9; transform: translateY(-3px); }
}

/* ---------- Quick-reply options ---------- */

.phr-chat__options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  background: var(--phr-bg);
  border-top: 1px solid var(--phr-border);
  max-height: 170px;
  overflow-y: auto;
  flex-shrink: 0;
}

.phr-chat__options[hidden] { display: none; }

.phr-chat__option {
  padding: 8px 14px;
  border: 1.5px solid var(--phr-teal);
  border-radius: 999px;
  background: #fff;
  color: var(--phr-teal-dark);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.phr-chat__option:hover { background: var(--phr-teal); color: #fff; }
.phr-chat__option:focus-visible {
  outline: 2px solid var(--phr-navy);
  outline-offset: 2px;
}

/* ---------- Input ---------- */

.phr-chat__form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--phr-border);
  background: #fff;
  flex-shrink: 0;
}

.phr-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--phr-border);
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  color: var(--phr-text);
  background: var(--phr-bg);
}

.phr-chat__input:focus {
  outline: none;
  border-color: var(--phr-teal);
  background: #fff;
}

.phr-chat__send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--phr-teal);
  color: #fff;
  cursor: pointer;
}

.phr-chat__send:hover { background: var(--phr-teal-dark); }
.phr-chat__send:focus-visible {
  outline: 2px solid var(--phr-navy);
  outline-offset: 2px;
}

/* ---------- Footer ---------- */

.phr-chat__footer {
  padding: 8px 14px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--phr-muted);
  text-align: center;
  background: #fff;
  border-top: 1px solid var(--phr-border);
  flex-shrink: 0;
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .phr-chat { right: 14px; bottom: 14px; }

  .phr-chat__panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
  }

  .phr-chat__toggle { padding: 13px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .phr-chat__panel,
  .phr-chat__toggle { transition: none; }
  .phr-chat__typing span { animation: none; }
}
