/* === Maple audit chat — full-viewport conversation ========================
   Renders the audit page as a chat with Maple. Branded paper/rust palette,
   centered 720px column, sticky input row at the bottom. Coexists with
   book-audit.css (which provides body shell, nav, brand, buttons, eyebrow,
   body::before noise, and shared CSS variables). */

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.ac-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.ac-topbar {
  width: 100%;
  padding: 0 32px;
  flex-shrink: 0;
}

.ac-topbar .nav {
  margin-bottom: 0;
}

.ac-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 32px;
  width: 100%;
  box-sizing: border-box;
}

.ac-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  min-height: 0;
}

/* === Messages =============================================================*/

.ac-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 28px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ac-messages::-webkit-scrollbar {
  width: 6px;
}
.ac-messages::-webkit-scrollbar-thumb {
  background: rgba(42, 31, 23, 0.18);
  border-radius: 3px;
}

.ac-speaker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
  animation: acMsgIn 0.22s ease-out both;
}
.ac-speaker-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--rust);
  color: var(--paper);
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.ac-speaker-name {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.ac-speaker-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.ac-speaker-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7a8a6c;
  box-shadow: 0 0 0 3px rgba(122, 138, 108, 0.18);
}

.ac-msg-bot {
  align-self: flex-start;
  max-width: 100%;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: acMsgIn 0.24s ease-out both;
}

.ac-msg-bot a {
  color: var(--rust);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ac-msg-bot.ac-msg-error {
  color: var(--err);
}

.ac-msg-user {
  align-self: flex-end;
  max-width: 70%;
  background: var(--rust);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: acMsgIn 0.24s ease-out both;
}

.ac-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0;
}
.ac-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-mute);
  animation: acTyping 1.2s infinite ease-in-out;
}
.ac-typing span:nth-child(2) { animation-delay: 0.15s; }
.ac-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes acMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes acTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* === Input area ===========================================================*/

.ac-input-area {
  flex-shrink: 0;
  padding: 14px 0 24px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.ac-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.ac-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  padding: 11px 14px;
  border-radius: 12px;
  max-height: 120px;
  min-height: 44px;
  overflow-y: auto;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.ac-input::placeholder { color: var(--ink-mute); }
.ac-input:focus {
  outline: none;
  border-color: var(--rust);
  background: var(--paper);
  box-shadow: 0 0 0 3px rgba(168, 77, 46, 0.18);
}
.ac-input:disabled { opacity: 0.6; cursor: not-allowed; }

.ac-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  background: var(--rust);
  color: var(--paper);
  border-radius: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ac-send:hover:not(:disabled) {
  background: var(--rust-deep);
  transform: translateY(-1px);
}
.ac-send:disabled {
  background: var(--paper-2);
  color: var(--ink-mute);
  cursor: not-allowed;
}
.ac-send svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* === Chips ================================================================*/

.ac-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ac-chip {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.ac-chip:hover {
  border-color: var(--rust);
  background: var(--paper);
  transform: translateY(-1px);
}
.ac-chip:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 2px;
}
.ac-chip:active {
  transform: translateY(0);
  background: var(--rust);
  color: var(--paper);
  border-color: var(--rust-deep);
}
.ac-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.ac-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--rust);
  color: var(--paper);
  border: 1px solid var(--rust-deep);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease;
}
.ac-cta:hover { background: var(--rust-deep); }
.ac-cta svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* === Honeypot =============================================================*/

.ac-honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* === Responsive ===========================================================*/

@media (max-width: 600px) {
  /* Clear the status bar / notch up top and the home indicator at the bottom,
     and inset the sides so nothing is clipped by rounded screen corners. */
  .ac-topbar {
    padding-top: env(safe-area-inset-top);
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .ac-topbar .nav { padding: 14px 0 6px; }
  .ac-shell {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .ac-messages { padding: 16px 0 10px; gap: 12px; }
  .ac-input-area { padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
  .ac-msg-bot { font-size: 15.5px; }
  .ac-msg-user { font-size: 14.5px; max-width: 82%; }
}

@media (prefers-reduced-motion: reduce) {
  .ac-msg-bot,
  .ac-msg-user,
  .ac-speaker,
  .ac-typing span,
  .ac-send,
  .ac-chip,
  .ac-cta {
    animation: none !important;
    transition: none !important;
  }
}
