/* The reading assistant (templates/_chat.html): a quiet button, a small
   printed-card panel. Uses the colour tokens of style.css, so it follows
   the light and the dark theme. */

.chat-toggle {
  position: fixed; z-index: 55; right: 1rem; bottom: 1rem;
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1rem;
  font: 500 .72rem/1 var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--paper); background: var(--ink);
  border: 1px solid var(--ink); border-radius: 2rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
  cursor: pointer;
}
.chat-toggle:hover, .chat-toggle:focus-visible { background: var(--accent); border-color: var(--accent); }
.chat-toggle[hidden] { display: none; }

.chat {
  position: fixed; z-index: 56; right: 1rem; bottom: 1rem;
  display: flex; flex-direction: column;
  width: min(24rem, calc(100vw - 2rem));
  height: min(34rem, calc(100vh - 2rem)); height: min(34rem, calc(100dvh - 2rem));
  background: var(--paper-raised); color: var(--ink);
  border: 1px solid var(--rule-strong); border-top: 2px solid var(--accent);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
}
.chat[hidden] { display: none; }

.chat__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem .9rem .6rem; border-bottom: 1px solid var(--rule);
}
.chat__title { margin: 0; font: 600 1.25rem/1.1 var(--display); }
.chat__close {
  width: 2rem; height: 2rem; font-size: 1.4rem; line-height: 1;
  color: var(--ink-soft); background: none; border: 0; cursor: pointer;
}
.chat__close:hover { color: var(--accent); }

.chat__log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: .9rem; display: flex; flex-direction: column; gap: .7rem;
}
.chat__msg {
  margin: 0; max-width: 92%; padding: .55rem .75rem;
  font: .95rem/1.5 var(--body); overflow-wrap: anywhere;
}
.chat__msg p { margin: 0 0 .5em; }
.chat__msg p:last-child, .chat__msg ul:last-child { margin-bottom: 0; }
.chat__msg ul { margin: 0 0 .5em; padding-left: 1.1rem; }
.chat__msg a { color: var(--accent); }
.chat__msg--bot { align-self: flex-start; background: var(--paper); border-left: 2px solid var(--gilt); }
.chat__msg--you { align-self: flex-end; background: var(--accent-wash); border: 1px solid var(--rule); }
.chat__msg--error { align-self: flex-start; color: var(--accent); font-style: italic; }
.chat__msg--wait { align-self: flex-start; color: var(--muted); font: .75rem/1.4 var(--mono); letter-spacing: .06em; }

.chat__rate { display: flex; gap: .3rem; margin-top: .4rem; font: .7rem/1.4 var(--mono); color: var(--muted); }
.chat__rate button {
  padding: .1rem .4rem; font-size: .85rem; line-height: 1.2; cursor: pointer;
  background: none; border: 1px solid var(--rule); border-radius: 1rem;
}
.chat__rate button:hover { border-color: var(--accent); }

.chat__form { display: flex; gap: .5rem; padding: .7rem .9rem 0; border-top: 1px solid var(--rule); }
.chat__form textarea {
  flex: 1; resize: none; padding: .5rem .6rem;
  font: .95rem/1.4 var(--body); color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule-strong);
}
.chat__form textarea:focus { outline: none; border-color: var(--accent); }
.chat__form .button { cursor: pointer; align-self: stretch; padding: 0 1rem; }
.chat__form .button:disabled { opacity: .5; cursor: wait; }

.chat__fine { margin: 0; padding: .5rem .9rem .7rem; font: .68rem/1.45 var(--mono); color: var(--muted); }
.chat__fine a { color: inherit; }

@media print { .chat, .chat-toggle { display: none !important; } }
