/* AMA Chat Widget — styled for Minimal Mistakes "dirt" skin
   Palette: bg #f3f3f3 | text #343434 | border/warm #e9dcbe | accent #ca7f32 */

/* ── Floating button ───────────────────────────────────────────── */
#ama-float-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background-color: #343434;
  color: #f3f3f3;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
#ama-float-btn:hover {
  background-color: #ca7f32;
  transform: scale(1.05);
}

/* ── Slide-up panel (floating mode) ───────────────────────────── */
#ama-panel {
  position: fixed;
  bottom: 5rem;
  right: 1.5rem;
  z-index: 999;
  width: 360px;
  max-width: calc(100vw - 2rem);
  height: 480px;
  background: #f3f3f3;
  border: 1px solid #e9dcbe;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  font-family: inherit;
  font-size: 0.9rem;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
#ama-panel.ama-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Panel header ──────────────────────────────────────────────── */
#ama-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e9dcbe;
  font-weight: 600;
  font-size: 0.875rem;
  color: #343434;
  flex-shrink: 0;
}
#ama-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #8e8b82;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
#ama-panel-close:hover { color: #343434; }

.ama-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.ama-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #8e8b82;
  font-size: 0.75rem;
  font-family: inherit;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ama-clear-btn:hover { color: #343434; }

/* ── Message list ──────────────────────────────────────────────── */
.ama-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overscroll-behavior: contain;
}

.ama-msg {
  max-width: 88%;
  line-height: 1.55;
  word-break: break-word;
}
.ama-msg-user {
  align-self: flex-end;
  background: #e9dcbe;
  color: #343434;
  border-radius: 14px 14px 2px 14px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}
.ama-msg-assistant {
  align-self: flex-start;
  color: #343434;
  font-size: 0.875rem;
}
.ama-msg-assistant p { margin: 0 0 0.4em; }
.ama-msg-assistant p:last-child { margin-bottom: 0; }
.ama-msg-assistant ul,
.ama-msg-assistant ol { margin: 0 0 0.4em 1.25em; padding: 0; }
.ama-msg-assistant li { margin-bottom: 0.2em; }
.ama-msg-assistant code { background: #e9dcbe; border-radius: 3px; padding: 0.1em 0.3em; font-size: 0.85em; }
.ama-msg-assistant strong { font-weight: 600; }
.ama-msg-assistant h3,
.ama-msg-assistant h4,
.ama-msg-assistant h5 { margin: 0.5em 0 0.2em; font-size: 0.9em; font-weight: 600; }

/* Typing indicator */
.ama-typing {
  align-self: flex-start;
  color: #8e8b82;
  font-size: 0.8rem;
  font-style: italic;
}

/* ── Input row ─────────────────────────────────────────────────── */
.ama-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #e9dcbe;
  flex-shrink: 0;
}
.ama-input {
  flex: 1;
  border: 1px solid #e9dcbe;
  border-radius: 4px;
  padding: 0.45rem 0.65rem;
  background: #fff;
  color: #343434;
  font-size: 0.875rem;
  font-family: inherit;
  resize: none;
  min-height: 36px;
  max-height: 120px;
  line-height: 1.4;
  outline: none;
}
.ama-input:focus { border-color: #ca7f32; }
.ama-send {
  background: #343434;
  color: #f3f3f3;
  border: none;
  border-radius: 4px;
  padding: 0 0.85rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}
.ama-send:hover:not(:disabled) { background: #ca7f32; }
.ama-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Full-page chat (on /ama page) ─────────────────────────────── */
#ama-full-chat {
  border: 1px solid #e9dcbe;
  border-radius: 6px;
  background: #f3f3f3;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 280px);
  min-height: 400px;
  margin-top: 1.5rem;
}
#ama-full-chat .ama-messages { padding: 1.25rem 1.5rem; }
#ama-full-chat .ama-input-row { padding: 0.75rem 1.25rem; padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)); }
#ama-full-chat .ama-input { font-size: 0.95rem; }
#ama-full-chat .ama-send { padding: 0 1.1rem; font-size: 0.95rem; }
#ama-full-chat .ama-msg { max-width: 80%; }
#ama-full-chat .ama-msg-user { font-size: 0.95rem; }
#ama-full-chat .ama-msg-assistant { font-size: 0.95rem; }

/* ── Welcome message ───────────────────────────────────────────── */
.ama-welcome {
  align-self: flex-start;
  color: #8e8b82;
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.25rem 0;
}

/* ── Error state ───────────────────────────────────────────────── */
.ama-msg-error {
  align-self: flex-start;
  color: #b85c38;
  font-size: 0.85rem;
}

/* ── Responsive: hide floating button on /ama page ─────────────── */
.page--ama #ama-float-btn,
.page--ama #ama-panel {
  display: none !important;
}

/* ── Mobile overrides ──────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Floating button: smaller margin from edges */
  #ama-float-btn {
    bottom: 1rem;
    right: 1rem;
  }

  /* Floating panel: full-width, fills available viewport height */
  #ama-panel {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 4.5rem;
    width: auto;
    max-width: none;
    height: calc(100dvh - 120px);
  }

  /* Full-page chat: tighter top offset on small screens */
  #ama-full-chat {
    height: calc(100dvh - 220px);
    min-height: 300px;
    border-left: none;
    border-right: none;
    border-radius: 0;
    margin-top: 1rem;
  }
}
