
/* Public profile and chat styles */
.location-share-panel {
  border: 1px solid #bfd7d2;
  background: #f3fbf9;
  display: grid;
  gap: 14px;
}

.location-share-panel h2 {
  margin-bottom: 6px;
}

.location-share-button {
  width: fit-content;
  min-height: 44px;
}

.location-share-button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* --- AI Chatbot Styles --- */
.chat-container {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: auto;
  margin-top: 40px;
  margin-bottom: 40px;
  direction: inherit;
  text-align: start;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-title h2 {
  font-size: 1.1rem;
  margin: 0;
  color: #1e293b;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e2e8f0;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.chat-status {
  font-size: 0.8rem;
  color: #16a34a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-status::before {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
}

/* Public service availability is separate from the private credit gauge. */
.public-medical-chat .chat-status[data-public-ai-state="limited"] { color: #b45309; }
.public-medical-chat .chat-status[data-public-ai-state="unavailable"] { color: #b91c1c; }
.public-medical-chat .chat-status[data-public-ai-state]::before { background: currentColor; }

.chat-messages {
  flex: 0 0 auto;
  height: clamp(420px, 58vh, 680px);
  min-height: 320px;
  max-height: 78vh;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  resize: vertical;
  scrollbar-gutter: stable;
}

.message {
  display: flex;
  max-width: 85%;
}

.ai-message {
  align-self: flex-end;
}

.user-message {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: start;
  unicode-bidi: plaintext;
  overflow-wrap: anywhere;
}

.ai-message .message-content {
  background: #f1f5f9;
  color: #334155;
  border-start-start-radius: 4px;
}

.user-message .message-content {
  background: #0f172a;
  color: #ffffff;
  border-start-end-radius: 4px;
}

.message-content.is-formatted {
  display: block;
}

.message-content.is-formatted p {
  margin: 0 0 10px;
}

.message-content.is-formatted p:last-child,
.message-content.is-formatted ul:last-child,
.message-content.is-formatted ol:last-child {
  margin-bottom: 0;
}

.message-content.is-formatted h3,
.message-content.is-formatted h4,
.message-content.is-formatted h5,
.message-content.is-formatted h6 {
  margin: 12px 0 6px;
  color: #0f172a;
  line-height: 1.35;
}

.message-content.is-formatted h3:first-child,
.message-content.is-formatted h4:first-child,
.message-content.is-formatted h5:first-child,
.message-content.is-formatted h6:first-child {
  margin-top: 0;
}

.message-content.is-formatted ul,
.message-content.is-formatted ol {
  margin: 0 0 10px;
  padding-inline-start: 22px;
}

.message-content.is-formatted li {
  margin-bottom: 4px;
}

.message-content.is-formatted hr {
  border: 0;
  border-top: 1px solid #cbd5e1;
  margin: 12px 0;
}

.ai-table-wrap {
  max-width: 100%;
  margin: 10px 0;
  overflow-x: auto;
}

.ai-table {
  width: 100%;
  min-width: 360px;
  border-collapse: collapse;
  background: #ffffff;
  font-size: 0.9rem;
}

.ai-table th,
.ai-table td {
  padding: 8px 10px;
  border: 1px solid #d7dee8;
  text-align: start;
  vertical-align: top;
}

.ai-table th {
  background: #eef8f5;
  color: #0f172a;
  font-weight: 700;
}

.chat-disclaimer {
  text-align: center;
  font-size: 0.75rem;
  color: #64748b;
  padding: 8px 20px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.chat-input-area {
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.chat-form {
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  text-align: start;
  direction: inherit;
  unicode-bidi: plaintext;
}

.chat-input::placeholder {
  text-align: start;
}

.chat-input:focus {
  border-color: #0f172a;
}

.chat-send-btn {
  padding: 10px 20px;
  background: #0f172a;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.chat-summary-btn {
  flex: 0 0 auto;
  max-width: 260px;
  padding: 10px 14px;
  background-color: #10b981 !important;
  color: #ffffff !important;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  text-align: center;
  animation: heartPulse 2.5s infinite cubic-bezier(0.4, 0, 0.2, 1);
  transition: background-color 0.3s;
}

.chat-summary-btn:hover {
  background-color: #059669 !important;
  animation: none;
}

@keyframes heartPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  15% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
  30% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
  45% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.chat-header-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.chat-export-menu {
  position: relative;
}

.chat-export-menu summary {
  list-style: none;
  padding: 10px 12px;
  background: #ffffff;
  color: #334155;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}

.chat-export-menu summary::-webkit-details-marker {
  display: none;
}

.chat-export-menu summary::after {
  content: '▾';
  margin-inline-start: 8px;
  font-size: 0.75rem;
}

.chat-export-options {
  position: absolute;
  z-index: 10;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  min-width: 150px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
}

.chat-export-options button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  color: #334155;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-align: start;
}

.chat-export-options button:hover,
.chat-export-options button:focus {
  background: #f1f5f9;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 12px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

@media (max-width: 640px) {
  .chat-header {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-summary-btn {
    max-width: none;
    width: 100%;
  }

  .chat-header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-export-menu summary {
    text-align: center;
  }

  .chat-export-options {
    position: static;
    margin-top: 6px;
  }

  .chat-messages {
    height: min(58vh, 520px);
    min-height: 320px;
    max-height: none;
    resize: none;
  }

  .message {
    max-width: 100%;
  }

  .ai-table {
    min-width: 300px;
  }
}

/* Stable public actions remain usable with touch and keyboard. */
.public-medical-chat .chat-summary-btn { animation: none; }
.public-medical-chat > button { min-height: 44px; padding: .6rem; border: 1px solid #cbd5e1; border-radius: .5rem; background: #fff; font: inherit; cursor: pointer; }

/* Public chat stays compact; availability controls remain functionally disabled. */
.public-medical-chat { margin-block: 24px; }
.public-medical-chat [hidden] { display: none !important; }
.public-medical-chat .chat-messages { height: auto; min-height: 6rem; max-height: min(36vh, 22rem); resize: none; padding: 16px; }
.public-medical-chat .chat-input { min-width: 0; width: 100%; }
.public-medical-chat .chat-avatar { flex-shrink: 0; }
.public-medical-chat .chat-header-actions { flex-direction: row; flex-wrap: wrap; min-width: 0; }
.public-medical-chat .chat-summary-btn { width: auto; max-width: min(100%, 280px); min-width: 0; flex-shrink: 1; white-space: normal; overflow-wrap: anywhere; }
.public-chat-availability { padding: 12px 16px; border-bottom: 1px solid #e2e8f0; }
.public-chat-availability p { margin: 0 0 8px; font-size: .875rem; overflow-wrap: anywhere; }
.public-chat-tools { display: flex; flex-wrap: wrap; align-items: start; gap: 8px; }
.public-chat-tools > button, .public-chat-tools .chat-export-menu > summary {
  min-height: 44px; padding: 8px 12px; border: 1px solid #94a3b8; border-radius: 8px;
  background: #fff; color: #334155; font: inherit; font-size: .875rem; cursor: pointer;
}
.public-chat-tools .chat-export-options { position: static; margin-top: 6px; }
.public-chat-details { margin-top: 8px; font-size: .875rem; }
.public-chat-details > summary { padding-block: 8px; cursor: pointer; color: #334155; }
.public-chat-details p, #chat-reset-help { margin-top: 8px; }
.public-medical-chat button:disabled, .public-medical-chat button:disabled:hover,
.public-medical-chat .chat-input:disabled {
  background: #f1f5f9 !important; color: #475569 !important; border: 1px solid #94a3b8;
  opacity: 1; cursor: not-allowed; animation: none; box-shadow: none; -webkit-text-fill-color: #475569;
}
.public-medical-chat .chat-input:disabled::placeholder { color: #475569; opacity: 1; }
.public-medical-chat :is(button, input, summary, a):focus-visible, .public-emergency-links a:focus-visible {
  outline: 3px solid #0f766e; outline-offset: 3px;
}
.public-emergency-links { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-block: 8px 16px; }
.public-emergency-links a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: underline; }
#saved-emergency-information, #emergency-contacts { scroll-margin-top: 16px; }
@media (max-width: 640px) {
  .public-medical-chat .chat-header, .public-medical-chat .chat-input-area { padding: 12px; }
  .public-medical-chat .chat-messages { padding: 12px; max-height: 32vh; }
  .public-medical-chat .chat-send-btn { padding-inline: 12px; }
}
.emergency-languages { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin:16px 0 24px; }
.emergency-languages form { margin:0; }
.emergency-languages .language-switch-button { width:100%; min-height:58px; padding:14px 20px; border:2px solid #12665c; border-radius:12px; background:#fff; color:#125b53; font:700 19px/1.4 system-ui,sans-serif; }
.emergency-languages .language-switch-button[aria-pressed=true] { background:#12665c; color:#fff; }
.emergency-languages .language-switch-button:focus-visible { outline:3px solid #236db0; outline-offset:4px; }

/* Shared owner allowance: informational, separate from chat availability. */
.public-ai-daily-banner {
  margin-block: 1rem;
  padding: 1rem 1.125rem;
  border: 1px solid #fdba74;
  border-inline-start: 5px solid #c2410c;
  border-radius: .75rem;
  background: #fff7ed;
  color: #7c2d12;
  text-align: start;
  overflow-wrap: anywhere;
}
.public-ai-daily-banner p { margin-block: .5rem 0; line-height: 1.6; }

/* Voluntary location sharing: an explicit, accessible action above the assistant. */
.location-share-panel .location-share-button { background:#b91c1c; border:2px solid #991b1b; color:#fff; min-height:48px; font-weight:700; white-space:normal; overflow-wrap:anywhere; }
.location-share-panel .location-share-button:hover { background:#991b1b; }
.location-share-panel .location-share-button:disabled { background:#f1f5f9; color:#475569; border-color:#94a3b8; cursor:not-allowed; }
.location-share-panel .location-share-button:focus-visible { outline:3px solid #0f172a; outline-offset:4px; }
