/* Public chat page styles. Dark navy header, light conversation surface, blue accent --
   consistent with NathFiles but deliberately calmer than the operator dashboard, since a
   first-time visitor should not feel they have landed in a project-management tool. */

:root {
  --navy: #0a1128;
  --navy-2: #111827;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #3b82f6;
  --accent-deep: #1d4ed8;
  --surface: #ffffff;
  --mine: #2563eb;
  --theirs: #f1f5f9;
  --ok: #10b981;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #eef2ff 100%);
  overflow: hidden;
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
}

/* ---- left panel ---- */
.chat-aside {
  padding: 28px 26px;
  background: linear-gradient(165deg, var(--navy) 0%, var(--navy-2) 60%, #1e1b4b 100%);
  color: #e2e8f0;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #1e1b4b;
  color: #f59e0b;
  font-weight: 800;
}

.brand-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.chat-aside h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  line-height: 1.2;
  color: #fff;
}

.lede {
  margin: 0 0 26px;
  color: #94a3b8;
  font-size: 0.92rem;
  line-height: 1.55;
}

.facts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 18px;
}

.facts li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.facts strong {
  display: block;
  color: #f8fafc;
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.facts small {
  color: #94a3b8;
  font-size: 0.79rem;
  line-height: 1.45;
}

.dot {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  margin-top: 4px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 4px rgba(100, 116, 139, 0.18);
}

.dot.on {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18);
  animation: pulse 2.4s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18); }
  50% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0.06); }
}

.glyph {
  flex: 0 0 auto;
  width: 15px;
  text-align: center;
  margin-top: 2px;
}

/* ---- conversation ---- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #1e1b4b;
  color: #f59e0b;
  font-weight: 800;
  flex: 0 0 auto;
}

.avatar.big { width: 52px; height: 52px; font-size: 1.2rem; }

.chat-head-text { min-width: 0; }
.chat-head-text strong { display: block; font-size: 0.95rem; }
.chat-head-text small { color: var(--muted); font-size: 0.78rem; }

.conn-pill {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.conn-pill[data-state="open"] { color: #047857; background: #ecfdf5; border-color: #a7f3d0; }
.conn-pill[data-state="closed"] { color: #b45309; background: #fffbeb; border-color: #fde68a; }

.chat-login-btn {
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.chat-login-btn:hover {
  background: #dbeafe;
  border-color: var(--accent);
  color: var(--accent);
}
.chat-login-btn:active {
  background: #bfdbfe;
}
.chat-login-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg { display: flex; flex-direction: column; max-width: 74%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  /* Messages can contain long unbroken strings (a token, a URL). Break them rather than
     letting one word push the layout sideways. */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.theirs .bubble {
  background: var(--theirs);
  color: var(--ink);
  border-bottom-left-radius: 5px;
}

.msg.pending .bubble { opacity: 0.7; }

.meta {
  margin-top: 4px;
  padding: 0 6px;
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

.tick { color: var(--muted); }
.tick.read { color: #2563eb; }

.typing-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 22px 8px;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 0 0 auto;
}

/* REQUIRED. Setting `display: flex` above beats the user-agent's `[hidden] { display: none }`,
   so without this the indicator stays on screen permanently -- showing "NathFiles is typing"
   to a visitor when nobody is typing. */
.typing-row[hidden] { display: none; }

.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

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

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.composer textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 160px;
  padding: 12px 15px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

.composer button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-deep);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.composer button:hover { background: #1e40af; }
.composer button:active { transform: scale(0.94); }

.composer-hint {
  margin: 0;
  padding: 0 22px 12px;
  font-size: 0.78rem;
  color: #b45309;
  min-height: 0;
  flex: 0 0 auto;
}

/* ---- name gate ---- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 17, 40, 0.55);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.gate[hidden] { display: none; }

.gate-card {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.35);
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: left;
}

.gate-card h2 { margin: 6px 0 0; font-size: 1.2rem; }
.gate-card > p { margin: 0 0 4px; color: var(--muted); font-size: 0.88rem; }
.gate-card label { width: 100%; font-size: 0.8rem; font-weight: 600; color: #334155; }
.gate-card label em { font-weight: 400; color: var(--muted); font-style: normal; }

.gate-card input,
.gate-card textarea {
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  resize: vertical;
}

.gate-card input:focus,
.gate-card textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

.gate-send {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--accent-deep);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.gate-send:disabled { opacity: 0.6; cursor: wait; }

/* ---- responsive: the chat owns the whole viewport ---- */
@media (max-width: 860px) {
  .chat-shell { grid-template-columns: minmax(0, 1fr); box-shadow: none; }
  .chat-aside { display: none; }
  .msg { max-width: 86%; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .dot.on { animation: none; }
  .typing-dots i { animation: none; }
  .messages { scroll-behavior: auto; }
}

@media (prefers-color-scheme: dark) {
  body { background: #0b0f19; }
  .chat-shell { background: #151c2c; box-shadow: none; }
  .chat-main { background: #151c2c; }
  .chat-head { border-color: #222d44; }
  .chat-head-text strong { color: #f8fafc; }
  .theirs .bubble { background: #1e2637; color: #e2e8f0; }
  .composer { border-color: #222d44; }
  .composer textarea,
  .gate-card input,
  .gate-card textarea { background: #0b0f19; border-color: #222d44; color: #f8fafc; }
  .gate-card { background: #151c2c; }
  .gate-card h2 { color: #f8fafc; }
  .gate-card label { color: #cbd5e1; }
  .meta, .chat-head-text small { color: #94a3b8; }
  .chat-login-btn { background: #1e3a5f; border-color: #1e40af; color: #93c5fd; }
  .chat-login-btn:hover { background: #1e40af; border-color: #3b82f6; color: #fff; }
  .chat-login-btn:active { background: #1e3a5f; }
}