/* Council Web — Discord-style chat theme */

:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-input: #383a40;
  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #949ba4;
  --accent: #f04747;
  --accent-hover: #d33c3c;
  --border: #1f2023;
}

* { box-sizing: border-box; }

body {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* Chat container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }

/* Message row */
.message-row {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  animation: msgSlideIn 0.25s ease-out;
}

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row:hover {
  background: var(--bg-secondary);
}

/* Avatar */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
}

/* Message body */
.message-body {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.message-author {
  font-weight: 600;
  font-size: 15px;
}

.message-round {
  font-size: 12px;
  color: var(--text-muted);
}

.message-content {
  font-size: 15px;
  line-height: 1.4;
  color: var(--text-secondary);
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* ── Markdown rendered content ── */
.message-content p {
  margin: 0 0 0.6em;
}
.message-content p:last-child {
  margin-bottom: 0;
}
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 0.8em;
  margin-bottom: 0.4em;
  color: var(--text-primary);
}
.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.25em; }
.message-content h3 { font-size: 1.1em; }
.message-content ul,
.message-content ol {
  margin: 0.3em 0;
  padding-left: 1.5em;
}
.message-content li {
  margin-bottom: 0.2em;
}
.message-content blockquote {
  margin: 0.4em 0;
  padding: 0.2em 0.8em;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}
.message-content code {
  font-family: 'gg mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: #f0a;
}
.message-content pre {
  margin: 0.5em 0;
  padding: 0.8em 1em;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre;
}
.message-content pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  color: var(--text-secondary);
}
.message-content a {
  color: #5865f2;
  text-decoration: none;
}
.message-content a:hover {
  text-decoration: underline;
}
.message-content strong {
  font-weight: 700;
  color: var(--text-primary);
}
.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5em 0;
  font-size: 0.92em;
}
.message-content th,
.message-content td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.message-content th {
  background: var(--bg-secondary);
  font-weight: 600;
}

/* Synthesis markdown */
#synthesis-content p {
  margin: 0 0 0.6em;
}
#synthesis-content h1,
#synthesis-content h2,
#synthesis-content h3 {
  color: var(--text-primary);
  margin-top: 1em;
  margin-bottom: 0.4em;
}
#synthesis-content ul,
#synthesis-content ol {
  padding-left: 1.5em;
  margin: 0.3em 0;
}
#synthesis-content li {
  margin-bottom: 0.2em;
}
#synthesis-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.8em;
  color: var(--text-muted);
  font-style: italic;
}
#synthesis-content code {
  font-family: 'gg mono', 'Fira Code', Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: #f0a;
}
#synthesis-content pre {
  margin: 0.5em 0;
  padding: 0.8em 1em;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre;
}
#synthesis-content pre code {
  background: none;
  padding: 0;
}
#synthesis-content a {
  color: #5865f2;
}
#synthesis-content strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* Status / system messages */
.message-row.system {
  padding: 4px 16px;
}

.system-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.system-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 3px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Stop button */
.stop-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stop-btn:hover { background: var(--accent-hover); }
.stop-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Progress bar — Discord style */
.progress-track {
  background: var(--bg-secondary);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
  background: linear-gradient(90deg, #5865f2, #f04747);
}

/* Entity colors */
.entity-rei .message-author { color: #a78bfa; }
.entity-louco .message-author { color: #fbbf24; }
.entity-ferreiro .message-author { color: #34d399; }
.entity-garimpeiro .message-author { color: #60a5fa; }
.entity-alquimista .message-author { color: #f472b6; }
.entity-cartografo .message-author { color: #38bdf8; }
.entity-generic .message-author { color: var(--text-muted); }

.entity-rei .avatar { background: #7c3aed; }
.entity-louco .avatar { background: #d97706; }
.entity-ferreiro .avatar { background: #059669; }
.entity-garimpeiro .avatar { background: #2563eb; }
.entity-alquimista .avatar { background: #db2777; }
.entity-cartografo .avatar { background: #0284c7; }
.entity-generic .avatar { background: #4b5563; }
