/* ── Chat widget ───────────────────────────────────────────────── */

.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 55%, var(--bg));
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 800;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  transition: opacity 0.15s, transform 0.15s;
}

.chat-bubble:hover {
  opacity: 0.85;
  transform: scale(1.06);
}

.chat-bubble svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

/* ── Panel base ────────────────────────────────────────────────── */

.chat-panel {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 340px;
  max-height: 480px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  z-index: 800;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease, width 0.2s ease;
}

.chat-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ── Panel with draft sidebar ──────────────────────────────────── */

.chat-panel.has-draft {
  width: min(580px, calc(100vw - 48px));
  display: grid;
  grid-template-columns: 1fr 210px;
  grid-template-rows: auto 1fr auto;
}

.chat-panel.has-draft .chat-header   { grid-column: 1 / -1; grid-row: 1; }
.chat-panel.has-draft .chat-messages { grid-column: 1;       grid-row: 2; }
.chat-panel.has-draft .chat-footer   { grid-column: 1;       grid-row: 3; }
.chat-panel.has-draft .chat-send-msg { grid-column: 1;       grid-row: 3; }

/* ── Header ────────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.chat-header-title {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}

.chat-close:hover { color: var(--ink); }

/* ── Messages ──────────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.chat-msg {
  max-width: 86%;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg-bot   { background: color-mix(in srgb, var(--line) 40%, transparent); color: var(--ink); align-self: flex-start; }
.chat-msg-user  { background: var(--ink); color: var(--bg); align-self: flex-end; }
.chat-msg-error { color: var(--accent); font-size: 13px; font-family: var(--mono); align-self: flex-start; }

/* ── Typing indicator ──────────────────────────────────────────── */

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-bounce 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-5px); }
}

/* ── Footer / input ────────────────────────────────────────────── */

.chat-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 8px 10px;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
}

.chat-input:focus { border-color: var(--ink); }

.chat-send {
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--bg);
  background: var(--ink);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.chat-send:hover:not(:disabled) { opacity: 0.75; }
.chat-send:disabled              { opacity: 0.35; cursor: default; }

/* ── Fallback send bar (no draft) ──────────────────────────────── */

.chat-send-msg {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.chat-send-telegram {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.chat-send-telegram:hover { color: var(--ink); border-color: var(--ink); }

/* ── Draft sidebar ─────────────────────────────────────────────── */

.chat-draft {
  grid-column: 2;
  grid-row: 2 / 4;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px 10px 10px;
  gap: 8px;
  min-height: 0;
}

.chat-draft-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

.chat-draft-text {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  min-height: 0;
  transition: border-color 0.15s;
}

.chat-draft-text:focus { border-color: var(--ink); }

.chat-draft-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.chat-draft-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  transition: color 0.15s;
}

.chat-draft-count.is-over { color: var(--accent); }

.chat-draft-send {
  width: 100%;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--bg);
  background: color-mix(in srgb, var(--ink) 80%, var(--bg));
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.chat-draft-send:hover:not(:disabled) { opacity: 0.78; }
.chat-draft-send:disabled             { opacity: 0.4; cursor: default; }

/* ── Mobile ────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .chat-panel.has-draft {
    width: auto;
    max-height: none;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
  }

  .chat-panel.has-draft .chat-messages { grid-row: 2; }
  .chat-panel.has-draft .chat-footer   { grid-row: 3; }

  .chat-draft {
    grid-column: 1;
    grid-row: 4;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 220px;
  }
}

@media (max-width: 480px) {
  .chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 76px;
  }

  .chat-bubble {
    right: 16px;
    bottom: 16px;
  }
}
