/* ── Chat (ORDER GIVEL_CHAT_ORB_V1 / TRI CLAW concierge) ───────────────
   Owned by the chat only. Law: specs/t27os/chat_orb.t27.
   The orb's place and size and the panel's colours are NOT here: the
   component writes them as inline style from the law, so no other
   stylesheet can move the orb or repaint the panel. Do not add .chat-*
   rules to main.css. */
.chat-orb { cursor: pointer; transition: transform .15s; }
.chat-orb:active { transform: scale(.93); }
.chat-orb-dot {
  position: absolute; bottom: 3px; right: 3px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--bg, #fff);
}

.chat-panel {
  position: fixed;
  /* keep the sheet inside the Telegram-drawn app area (see .chat-orb) */
  bottom: calc(100vh - var(--tg-viewport-stable-height, 100vh)); left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: var(--app-max-width, 430px);
  height: 70svh; height: 70dvh; min-height: 320px;
  max-height: calc(100dvh - 16px);
  background: rgba(18,18,20,0.72);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border-top: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,0.04);
  display: flex; flex-direction: column;
  z-index: 300;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: chatIn .35s cubic-bezier(.22,1.22,.42,1);
}
@keyframes chatIn {
  from { transform: translate(-50%, 20%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
}
.chat-head-ava {
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover;
}
.chat-head-name {
  flex: 1;
  font-size: 15px; font-weight: 700;
  color: var(--text, #111);
}
.chat-close {
  background: none; border: none; cursor: pointer;
  color: var(--text2, #888);
  font-size: 18px; line-height: 1;
  padding: 4px 6px;
}

.chat-body {
  flex: 1; overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-msg {
  display: flex; flex-direction: column; align-items: flex-start;
  max-width: 80%;
  min-width: 0;
}
.chat-msg.chat-me { align-self: flex-end; align-items: flex-end; }
.chat-text {
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text, #111);
  border-radius: 14px; padding: 8px 12px;
  font-size: 14px; line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0;
  border: 1px solid rgba(255,255,255,0.06);
}
.chat-me .chat-text {
  background: linear-gradient(135deg, rgba(255,255,255,0.14), rgba(255,255,255,0.06));
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
}
.chat-proto-tag {
  font-size: 10px; color: var(--text3, #aaa);
  margin-top: 2px; padding: 0 2px;
}

.chat-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: var(--bg2, #f4f4f5);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 16px; color: var(--text, #111); /* 16px: iOS does not zoom the page on focus */
  min-width: 0;
  outline: none;
}
.chat-input:focus { border-color: var(--accent, #000); }
.chat-send {
  background: var(--accent, #000); color: #fff;
  border: none; border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.chat-tg-fallback {
  padding: 6px 12px 10px;
  display: flex; justify-content: center;
  flex-shrink: 0;
}
.chat-tg-link {
  background: none; border: none; cursor: pointer;
  color: var(--text2, #888);
  font-size: 13px; text-decoration: underline;
}
.chat-ai-tag {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 980px;
  padding: 1px 6px;
  margin-bottom: 3px;
}

.nav-version {
  text-align: center;
  font-size: 10px;
  color: var(--text2);
  opacity: .6;
  padding: 2px 0 0;
}
.chat-attach {
  flex: none;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 17px;
  color: var(--text);
}
.chat-ingest {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
}
.ingest-line { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.ingest-icon { font-size: 15px; }
.ingest-meta { font-size: 12px; color: var(--text2); margin-top: 6px; overflow-wrap: anywhere; }
.ingest-missing { margin-top: 6px; color: var(--yellow, #e6b800); overflow-wrap: anywhere; }

/* Service bubbles (greeting, AI-down line): muted, centred, never a message of a person. */
.chat-msg.chat-service { align-self: center; align-items: center; max-width: 90%; }
.chat-service .chat-text { background: transparent; border: 1px dashed var(--border); color: var(--text2); font-size: 13px; text-align: center; }
.chat-offline {
  margin: 0 12px; padding: 6px 10px; border-radius: 10px;
  background: rgba(239,68,68,.18); color: #fff; font-size: 12px; text-align: center;
}
.chat-mgr-btn {
  margin-top: 6px; padding: 8px 14px; border-radius: 980px; cursor: pointer;
  background: #fff; color: #000; border: none; font-size: 13px; font-weight: 600;
}
.chat-send:disabled { opacity: .4; cursor: default; }

/* The orb hangs over the bottom-right corner: keep one orb plus a gap of free space under the
   last row of every screen (orb 56 + gap 8, law chat_orb.t27) so it never hides content at the end. */
#main::after { content: ""; display: block; height: 64px; }
