/* Floating chat — isolated from page Tailwind */
#niam-chat-root {
  --niam-chat-primary: #0f766e;
  --niam-chat-primary-hover: #0d9488;
  --niam-chat-surface: #ffffff;
  --niam-chat-border: #e2e8f0;
  --niam-chat-text: #1e293b;
  --niam-chat-muted: #64748b;
  --niam-chat-user-bg: #ecfdf5;
  --niam-chat-bot-bg: #f1f5f9;
  font-family: "Alexandria", system-ui, sans-serif;
  direction: rtl;
  text-align: right;
}

#niam-chat-root *,
#niam-chat-root *::before,
#niam-chat-root *::after {
  box-sizing: border-box;
}

.niam-chat-toggle {
  position: fixed;
  z-index: 9998;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: max(1rem, env(safe-area-inset-left));
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  border: none;
  background: var(--niam-chat-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px -5px rgb(15 118 110 / 0.35);
  transition: transform 0.2s ease, background 0.2s ease;
}

.niam-chat-toggle:hover {
  background: var(--niam-chat-primary-hover);
  transform: scale(1.05);
}

.niam-chat-toggle:focus-visible {
  outline: 2px solid var(--niam-chat-primary);
  outline-offset: 3px;
}

.niam-chat-panel {
  position: fixed;
  z-index: 9999;
  bottom: max(5.5rem, calc(env(safe-area-inset-bottom) + 4.5rem));
  left: max(1rem, env(safe-area-inset-left));
  width: min(22rem, calc(100vw - 2rem));
  height: min(28rem, calc(100vh - 8rem));
  background: var(--niam-chat-surface);
  border: 1px solid var(--niam-chat-border);
  border-radius: 1.25rem;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#niam-chat-root.niam-chat-open .niam-chat-panel {
  display: flex;
}

.niam-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
  color: #fff;
}

.niam-chat-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.niam-chat-header p {
  margin: 0.15rem 0 0;
  font-size: 0.7rem;
  opacity: 0.92;
  line-height: 1.35;
}

.niam-chat-header-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.niam-chat-header-actions button {
  background: rgb(255 255 255 / 0.2);
  border: none;
  color: #fff;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.niam-chat-header-actions button:hover {
  background: rgb(255 255 255 / 0.3);
}

.niam-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #fafafa;
}

.niam-chat-msg {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.niam-chat-msg-user {
  align-self: flex-end;
  background: var(--niam-chat-user-bg);
  color: var(--niam-chat-text);
  border: 1px solid #a7f3d0;
}

.niam-chat-msg-bot {
  align-self: flex-start;
  background: var(--niam-chat-bot-bg);
  color: var(--niam-chat-text);
  border: 1px solid var(--niam-chat-border);
}

.niam-chat-msg-error {
  align-self: stretch;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-size: 0.75rem;
}

.niam-chat-footer {
  padding: 0.65rem;
  border-top: 1px solid var(--niam-chat-border);
  background: var(--niam-chat-surface);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.niam-chat-footer textarea {
  flex: 1;
  min-height: 2.5rem;
  max-height: 6rem;
  resize: none;
  border: 1px solid var(--niam-chat-border);
  border-radius: 0.75rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--niam-chat-text);
  direction: rtl;
}

.niam-chat-footer textarea:focus {
  outline: none;
  border-color: var(--niam-chat-primary);
  box-shadow: 0 0 0 2px rgb(15 118 110 / 0.15);
}

.niam-chat-send {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  border: none;
  background: var(--niam-chat-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.niam-chat-send:hover:not(:disabled) {
  background: var(--niam-chat-primary-hover);
}

.niam-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.niam-chat-typing {
  font-size: 0.7rem;
  color: var(--niam-chat-muted);
  padding: 0 0.25rem 0.25rem;
  min-height: 1rem;
}

.niam-chat-credit {
  flex-shrink: 0;
  font-size: 0.65rem;
  color: var(--niam-chat-muted);
  text-align: center;
  padding: 0.4rem 0.75rem;
  line-height: 1.45;
  border-top: 1px solid var(--niam-chat-border);
  background: #f8fafc;
}

@media (max-width: 480px) {
  .niam-chat-panel {
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
  }
}
