/* „Чат с Реа" (src/Service/ReaChat/CLAUDE.md). Theme tokens only, so dark mode follows app.css.
   Stacking: above .nav-bottom (30), below the drawer backdrop (40) and drawer (50) — an open
   menu must cover the chat, not the other way round. */
.rea-chat {
  --rea-chat-bottom: 1.25rem;
  position: fixed;
  right: 1.25rem;
  bottom: var(--rea-chat-bottom);
  z-index: 35;
  font-family: var(--font);
}
/* Below 960px the bottom nav owns the last ~4.5rem of the screen. */
@media (max-width: 959px) {
  .rea-chat { --rea-chat-bottom: 5.4rem; right: 0.75rem; }
}
body.drawer-open .rea-chat { visibility: hidden; }

.rea-chat__launcher {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 1.05rem; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--btn-primary-bg); color: var(--btn-primary-ink);
  font: inherit; font-weight: 700; box-shadow: var(--shadow);
}
.rea-chat__launcher-dot {
  width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
.rea-chat--open .rea-chat__launcher { display: none; }

.rea-chat__panel {
  width: min(400px, calc(100vw - 1.5rem));
  height: min(620px, calc(100vh - var(--rea-chat-bottom) - 1.5rem));
  height: min(620px, calc(100dvh - var(--rea-chat-bottom) - 1.5rem)); /* the visible height, not behind a mobile toolbar */
  display: flex; flex-direction: column;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.rea-chat__panel[hidden] { display: none; }

.rea-chat--expanded {
  inset: 1rem; right: 1rem; bottom: 1rem;
}
.rea-chat--expanded .rea-chat__panel { width: 100%; height: 100%; }
@media (max-width: 959px) {
  .rea-chat--open:not(.rea-chat--expanded) .rea-chat__panel {
    height: min(620px, calc(100vh - var(--rea-chat-bottom) - 1rem));
    height: min(620px, calc(100dvh - var(--rea-chat-bottom) - 1rem));
  }
  .rea-chat--expanded { inset: 0.5rem; z-index: 45; }
}

.rea-chat__head {
  display: flex; align-items: center; gap: 0.25rem;
  padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line);
  background: var(--tile-bg);
}
.rea-chat__title { flex: 1; font-weight: 800; padding-left: 0.25rem; }
.rea-chat__subtitle { color: var(--muted); font-weight: 500; font-size: 0.82rem; margin-left: 0.25rem; }
.rea-chat__icon-btn {
  min-width: 2.25rem; height: 2.25rem; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--ink); font-size: 1rem; line-height: 1;
}
.rea-chat__icon-btn:hover { background: var(--brand-soft); }
.rea-chat__icon-btn[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); }
.rea-chat__icon-btn:disabled { opacity: 0.45; cursor: default; }

.rea-chat__body { flex: 1; display: flex; min-height: 0; }
.rea-chat__threads {
  width: 100%; overflow-y: auto; padding: 0.6rem; border-right: 1px solid var(--line); background: var(--card);
}
.rea-chat__threads[hidden] { display: none; }
.rea-chat__threads:not([hidden]) + .rea-chat__conversation { display: none; }
.rea-chat--expanded .rea-chat__threads { width: 260px; flex-shrink: 0; }
.rea-chat--expanded .rea-chat__threads:not([hidden]) + .rea-chat__conversation { display: flex; }
.rea-chat__threads-head { margin: 0 0 0.4rem; font-size: 0.78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.rea-chat__thread {
  display: block; width: 100%; text-align: left; padding: 0.55rem 0.6rem; margin-bottom: 0.2rem;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink); font: inherit; font-size: 0.9rem; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rea-chat__thread:hover, .rea-chat__thread.is-active { background: var(--brand-soft); }

.rea-chat__conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.rea-chat__messages { flex: 1; overflow-y: auto; padding: 0.85rem; display: flex; flex-direction: column; gap: 0.6rem; }
.rea-chat__empty { margin: auto 0; text-align: left; }
.rea-chat__empty-title { font-weight: 800; margin: 0 0 0.3rem; }
.rea-chat__empty .muted { margin: 0 0 0.8rem; line-height: 1.45; font-size: 0.92rem; }
.rea-chat__suggestions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.rea-chat__suggestion {
  border: 1px solid var(--line); border-radius: 999px; padding: 0.4rem 0.75rem; cursor: pointer;
  background: var(--tile-bg); color: var(--ink); font: inherit; font-size: 0.85rem;
}
.rea-chat__suggestion:hover { border-color: var(--brand); }

.rea-chat__msg { max-width: 88%; display: flex; flex-direction: column; gap: 0.2rem; }
.rea-chat__msg--user { align-self: flex-end; align-items: flex-end; }
.rea-chat__msg--rea { align-self: flex-start; }
.rea-chat__msg-body {
  padding: 0.6rem 0.8rem; border-radius: 14px; line-height: 1.45; font-size: 0.94rem; overflow-wrap: anywhere;
}
.rea-chat__msg--user .rea-chat__msg-body { background: var(--btn-primary-bg); color: var(--btn-primary-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.rea-chat__msg--rea .rea-chat__msg-body { background: var(--tile-bg); border-bottom-left-radius: 4px; }
.rea-chat__msg-body a { color: var(--brand); }
.rea-chat__msg-body code { font-size: 0.86em; background: var(--brand-soft); padding: 0 0.25em; border-radius: 4px; }
.rea-chat__msg-meta { font-size: 0.72rem; color: var(--muted); }
.rea-chat__msg--typing { padding: 0.6rem 0.8rem; border-radius: 14px; background: var(--tile-bg); color: var(--muted); font-style: italic; }

.rea-chat__notice {
  margin: 0 0.85rem 0.5rem; padding: 0.55rem 0.7rem; border-radius: 12px;
  background: var(--wip-bg); color: var(--wip-ink); font-size: 0.88rem; line-height: 1.4;
}
.rea-chat__notice[hidden] { display: none; }
.rea-chat__notice .linklike { margin-left: 0.35rem; font-weight: 700; color: inherit; text-decoration: underline; }

.rea-chat__composer { display: flex; align-items: flex-end; gap: 0.4rem; padding: 0.6rem 0.7rem 0.3rem; border-top: 1px solid var(--line); }
.rea-chat__input {
  flex: 1; resize: none; min-height: 2.6rem; max-height: 10rem; padding: 0.6rem 0.75rem;
  border: 1px solid var(--input-border); border-radius: 12px; background: var(--input-bg); color: var(--ink);
  font: inherit; font-size: 0.95rem; line-height: 1.35;
}
.rea-chat__send {
  width: 2.6rem; height: 2.6rem; flex-shrink: 0; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--btn-primary-bg); color: var(--btn-primary-ink); font-size: 1rem;
}
.rea-chat__send:disabled, .rea-chat__input:disabled { opacity: 0.5; cursor: default; }
.rea-chat__disclaimer { margin: 0; padding: 0 0.85rem 0.55rem; font-size: 0.72rem; }

@media print { .rea-chat { display: none !important; } }
@media (max-width: 480px) { .rea-chat__subtitle { display: none; } }
/* Under 16px iOS Safari zooms the page when the field takes focus. */
@media (max-width: 959px) { .rea-chat__input { font-size: 16px; } }
