/* ══════════════════════════════════════════════════════════════
   EliChat — Modern chat component styles.
   Uses CSS custom properties from blog-base.css.
   No layout opinions — fills its container.
   ══════════════════════════════════════════════════════════════ */

.eli-chat {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', sans-serif;
}

/* ── Messages area ── */
.eli-chat__messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 0.5rem;
  margin-bottom: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.eli-chat__messages::-webkit-scrollbar { width: 4px; }
.eli-chat__messages::-webkit-scrollbar-track { background: transparent; }
.eli-chat__messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

/* ── Message bubbles ── */
.eli-chat__msg {
  max-width: 88%;
  padding: 0.65rem 0.9rem;
  font-size: 0.82rem;
  line-height: 1.6;
  color: rgba(220, 224, 232, 0.9);
  border-radius: 12px;
  animation: eli-chat-fade-up 0.25s ease-out forwards;
}

.eli-chat__msg--eli {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: none;
  padding: 0.5rem 0;
  border-radius: 0;
  max-width: 100%;
}

.eli-chat__msg--user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.07);
  border: none;
  max-width: 75%;
}

.eli-chat__msg--system {
  align-self: center;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 0.72rem;
  color: rgba(160, 165, 180, 0.6);
  text-align: center;
  padding: 0.3rem 0.6rem;
  background: none;
  border: none;
}

/* ── Markdown elements inside Eli messages ── */
.eli-chat__msg--eli p {
  margin: 0 0 0.6em;
}
.eli-chat__msg--eli p:last-child {
  margin-bottom: 0;
}
.eli-chat__msg--eli strong {
  color: rgba(240, 242, 248, 0.95);
  font-weight: 600;
}
.eli-chat__msg--eli em {
  font-style: italic;
  color: rgba(200, 205, 218, 0.85);
}
.eli-chat__msg--eli code {
  font-family: 'SF Mono', 'Fira Code', 'IBM Plex Mono', monospace;
  font-size: 0.8em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: rgba(230, 235, 245, 0.9);
}
.eli-chat__msg--eli pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.75em 1em;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.6em 0;
  line-height: 1.5;
}
.eli-chat__msg--eli pre code {
  background: none;
  padding: 0;
  font-size: 0.78em;
  color: rgba(230, 235, 245, 0.9);
}
.eli-chat__msg--eli ul,
.eli-chat__msg--eli ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}
.eli-chat__msg--eli ul { list-style: disc; }
.eli-chat__msg--eli ol { list-style: decimal; }
.eli-chat__msg--eli li {
  margin: 0.25em 0;
}
.eli-chat__msg--eli blockquote {
  border-left: 2px solid rgba(255, 255, 255, 0.15);
  margin: 0.5em 0;
  padding: 0.2em 0.8em;
  color: rgba(180, 185, 200, 0.75);
}
.eli-chat__msg--eli a {
  color: rgba(180, 200, 255, 0.85);
  text-decoration: none;
}
.eli-chat__msg--eli a:hover {
  text-decoration: underline;
}

/* ── Tables ── */
.eli-chat__msg--eli table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.78em;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
}
.eli-chat__msg--eli thead {
  background: rgba(255, 255, 255, 0.06);
}
.eli-chat__msg--eli th {
  font-weight: 600;
  color: rgba(240, 242, 248, 0.9);
  text-align: left;
  padding: 0.5em 0.75em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.eli-chat__msg--eli td {
  padding: 0.45em 0.75em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: top;
}
.eli-chat__msg--eli tr:last-child td {
  border-bottom: none;
}
.eli-chat__msg--eli tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* ── Headings ── */
.eli-chat__msg--eli h1,
.eli-chat__msg--eli h2,
.eli-chat__msg--eli h3,
.eli-chat__msg--eli h4 {
  color: rgba(240, 242, 248, 0.95);
  font-weight: 600;
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}
.eli-chat__msg--eli h1 { font-size: 1.1em; }
.eli-chat__msg--eli h2 { font-size: 1em; }
.eli-chat__msg--eli h3 { font-size: 0.95em; }
.eli-chat__msg--eli h4 { font-size: 0.9em; color: rgba(220, 224, 232, 0.85); }
.eli-chat__msg--eli h1:first-child,
.eli-chat__msg--eli h2:first-child,
.eli-chat__msg--eli h3:first-child {
  margin-top: 0;
}

/* ── Horizontal rules ── */
.eli-chat__msg--eli hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 0.8em 0;
}

/* ── Images ── */
.eli-chat__msg--eli img {
  max-width: 100%;
  border-radius: 6px;
  margin: 0.5em 0;
}

/* ── Loading dots ── */
.eli-chat__loading {
  display: flex;
  gap: 5px;
  padding: 0.5rem 0;
}
.eli-chat__loading span {
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  animation: eli-chat-dot-pulse 1.2s infinite;
}
.eli-chat__loading span:nth-child(2) { animation-delay: 0.15s; }
.eli-chat__loading span:nth-child(3) { animation-delay: 0.3s; }

@keyframes eli-chat-dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Status indicator ── */
.eli-chat__status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: rgba(160, 165, 180, 0.6);
  padding: 0.4rem 0;
  animation: eli-chat-fade-up 0.2s ease-out forwards;
}
.eli-chat__status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(180, 200, 255, 0.5);
  animation: eli-chat-status-pulse 1.5s ease-in-out infinite;
}
@keyframes eli-chat-status-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ── Input row ── */
.eli-chat__input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.eli-chat__input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 0.84rem;
  color: rgba(230, 235, 245, 0.95);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  resize: none;
  overflow-y: hidden;
  min-height: 2.4rem;
  max-height: 6.5rem;
  line-height: 1.5;
  field-sizing: content;
}
.eli-chat__input:focus {
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.03);
}
.eli-chat__input::placeholder {
  color: rgba(160, 165, 180, 0.5);
}
.eli-chat__input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.eli-chat__send {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 0.9rem;
  color: rgba(230, 235, 245, 0.7);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 2.4rem;
  height: 2.4rem;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.eli-chat__send:hover {
  border-color: rgba(255, 255, 255, 0.25);
  color: rgba(240, 242, 248, 0.95);
  background: rgba(255, 255, 255, 0.05);
}
.eli-chat__send:disabled {
  cursor: not-allowed;
  opacity: 0.25;
}

@keyframes eli-chat-fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .eli-chat__msg {
    font-size: 0.84rem;
    line-height: 1.55;
    max-width: 95%;
  }
  .eli-chat__msg--user {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
  }
  .eli-chat__msg--eli {
    max-width: 100%;
  }
  /* code blocks — horizontal scroll, no overflow */
  .eli-chat__msg--eli pre {
    padding: 0.6em 0.75em;
    font-size: 0.74rem;
    -webkit-overflow-scrolling: touch;
  }
  .eli-chat__msg--eli pre code {
    font-size: 0.74rem;
  }
  /* tables — horizontal scroll wrapper */
  .eli-chat__msg--eli table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.72rem;
  }
  /* input — prevent iOS zoom, thumb-friendly */
  .eli-chat__input {
    font-size: 16px; /* prevent iOS zoom — must be exactly 16px */
    padding: 0.55rem 0.75rem;
    min-height: 2.4rem;
  }
  .eli-chat__send {
    width: 2.6rem;
    height: 2.6rem;
    min-width: 2.6rem;
  }
  /* inline code — slightly larger tap area */
  .eli-chat__msg--eli code {
    font-size: 0.78em;
    padding: 0.2em 0.4em;
  }
}
