/* Respect the hidden attribute even when a rule sets a display value
   (chat window, auth fields, login form all toggle via .hidden). */
[hidden] {
  display: none !important;
}

/* Brand logo sits inside the deck wordmark, next to the name. */
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.wordmark img {
  display: block;
  width: 1.7rem;
  height: 1.7rem;
}

/* Custom browser UI: no default scrollbar, selection, or control chrome. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: content-box;
}
::selection {
  background: var(--fill);
  color: var(--ink);
}

/* Help / directory cards. */
.help-list {
  list-style: none;
  margin: 1.2rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.9rem;
}
.contact {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.25rem;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1rem 1.15rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.contact:hover,
.contact:focus-within {
  border-color: var(--link);
  box-shadow: var(--float);
}
.contact-body {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
}
.contact .service {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--sans);
  font-weight: 700;
}
.contact .service .icon {
  color: var(--link);
}
.contact-desc {
  margin: 0;
  text-align: left;
  color: var(--muted);
  font-size: 0.92rem;
}
.call {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-ctl);
  background: var(--active);
  border: 1px solid var(--border);
  color: var(--link);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.call::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-card);
}
.contact:hover .call,
.call:hover,
.call:focus-visible {
  background: var(--link);
  color: var(--ink);
  border-color: var(--link);
  text-decoration: none;
}
.contact-multi .call::after {
  display: none;
}
.contact-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
@media (max-width: 540px) {
  .contact {
    align-items: flex-start;
  }
  .contact-actions {
    width: 100%;
  }
  .contact-actions .call {
    flex: 1;
    justify-content: center;
  }
}

/* Callout for notes. */
.callout {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius-card);
  padding: 0.95rem 1.1rem;
  margin: 1.3rem 0;
}
.callout .icon {
  flex: none;
  margin-top: 0.15rem;
  color: var(--warn);
}
.callout strong {
  display: block;
}
.callout p {
  margin: 0.3rem 0 0;
  text-align: left;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Form fields (account + responder). */
.field {
  display: grid;
  gap: 0.35rem;
  margin: 1.1rem 0;
}
.field span {
  font-weight: 700;
  font-size: 0.95rem;
}
.field input,
.chat-form textarea {
  font: inherit;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
.chat-form {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.6rem;
}
.chat-form textarea {
  resize: vertical;
  appearance: none;
}
.chat-form .btn {
  justify-self: start;
}

/* Directory actions. */
.dir-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1.1rem 0;
}

/* ---- Chat window (Cerita) ---- */
#chat-box {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: min(80vh, 46rem);
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--float);
  overflow: hidden;
}

/* Header: who (left) + actions (right). */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}
.chat-who {
  color: var(--muted);
  font-size: 0.9rem;
}
.chat-tools {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--warn);
  border-color: var(--border);
  background: var(--panel);
}

/* Segmented mode control. */
.seg {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: fit-content;
  max-width: 100%;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.seg-btn:hover {
  color: var(--text);
}
.seg-btn[aria-pressed="true"] {
  background: var(--active);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Compact crisis banner. */
.chat-crisis {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.45;
}
.chat-crisis > .icon {
  flex: none;
  margin-top: 0.1rem;
  color: var(--warn);
}
.crisis-body {
  min-width: 0;
}
.crisis-body strong {
  display: block;
  font-weight: 700;
}
.crisis-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.crisis-call {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--warn);
  color: var(--warn);
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
}
.crisis-call:hover,
.crisis-call:focus-visible {
  background: var(--warn);
  color: var(--bg);
}
.crisis-more {
  align-self: center;
  font-size: 0.82rem;
}
.crisis-close {
  flex: none;
  margin-left: auto;
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  background: transparent;
  color: var(--warn);
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 999px;
  cursor: pointer;
}
.crisis-close:hover {
  background: var(--warn);
  color: var(--bg);
}

/* Thread. */
#chat-box .chat-thread {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0.15rem 0.25rem 0.15rem 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 0.55rem;
}
.chat-empty {
  place-self: center;
  max-width: 26rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Bubbles. */
.msg {
  max-width: 78%;
  padding: 0.6rem 0.85rem;
  font-size: 0.98rem;
  line-height: 1.55;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-user {
  justify-self: end;
  background: var(--fill);
  color: var(--ink);
  border-radius: 18px 18px 6px 18px;
}
.msg-ai,
.msg-responder {
  justify-self: start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 6px;
}
.msg-typing {
  justify-self: start;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 0.7rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 6px;
}
.msg-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typedots 1.2s infinite;
}
.msg-typing .dot:nth-child(2) {
  animation-delay: 0.15s;
}
.msg-typing .dot:nth-child(3) {
  animation-delay: 0.3s;
}
@media (prefers-reduced-motion: reduce) {
  .msg-typing .dot {
    animation: none;
    opacity: 0.6;
  }
}

/* Composer: rounded bar, auto-grow textarea, icon send button. */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.45rem 0.45rem 0.45rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  transition: border-color 0.2s ease;
}
.chat-composer:focus-within {
  border-color: var(--link);
}
.chat-composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 8rem;
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}
.chat-composer textarea:focus {
  outline: none;
}
.chat-composer textarea::placeholder {
  color: var(--muted);
}
.composer-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}
.composer-send:hover {
  background: var(--link);
}
.composer-send .icon {
  width: 1.25rem;
  height: 1.25rem;
}
.composer-send[disabled] {
  opacity: 0.6;
  cursor: default;
}
.composer-send.sending .icon {
  display: none;
}
.composer-send.sending::after {
  content: "";
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
}
.chat-error {
  margin: 0;
  color: var(--warn);
  font-size: 0.88rem;
}

/* Intro modal: sets reply-time expectations after login. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: rgba(26, 23, 40, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.modal-card {
  width: min(30rem, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--float);
  padding: 1.5rem 1.5rem 1.3rem;
}
.modal-card h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
}
.modal-card > p {
  margin: 0 0 0.9rem;
  color: var(--muted);
}
.modal-list {
  display: grid;
  gap: 0.7rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}
.modal-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.95rem;
  text-align: left;
  font-size: 0.96rem;
  line-height: 1.55;
}
.modal-list strong {
  color: var(--text);
}
.modal-card .btn {
  width: 100%;
  justify-content: center;
}
@media (prefers-reduced-motion: no-preference) {
  .modal-card {
    animation: modalin 0.18s ease-out;
  }
}
@keyframes modalin {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Floating donate button (bottom-right), gentle by design. */
.fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink);
  box-shadow: var(--float);
  transition: background-color 0.2s ease, transform 0.2s ease;
}
.fab:hover,
.fab:focus-visible {
  background: var(--link);
  color: var(--bg);
}
.fab .icon {
  width: 1.4rem;
  height: 1.4rem;
}
@media (prefers-reduced-motion: no-preference) {
  .fab:hover,
  .fab:focus-visible {
    transform: translateY(-2px);
  }
}
/* Keep it clear of the chat / responder composer when that is open. */
body:has(#chat-box:not([hidden])) .fab,
body:has(#rq-view:not([hidden])) .fab {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes typedots {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}
