/* aiaxis chat UI — palette and layout intentionally close to claude.ai */

:root {
  --bg: #fdfcf8;
  --surface: #ffffff;
  --user-bubble: #f0ece4;
  --text: #2c2924;
  --text-muted: #8c8479;
  --accent: #d97757;
  --accent-hover: #c5664a;
  --border: #e7e3da;
  --radius: 14px;
  --code-bg: #f6f3ec;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue",
               system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.chat-shell {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ─── header ─────────────────────────────────────────────── */

.chat-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}

.chat-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.user-info {
  font-weight: 500;
  color: var(--text);
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--user-bubble);
  font-size: 12px;
}

.memory-counter {
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.memory-counter.warning {
  color: var(--accent);
  border-color: var(--accent);
}

.reset-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  font-family: inherit;
  transition: all 0.15s;
}
.reset-btn:hover {
  background: var(--surface);
  color: var(--text);
}

/* ─── messages ───────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
  margin: auto;
  max-width: 500px;
}
.empty-state .hint {
  display: inline-block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.7;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.message.user {
  align-self: flex-end;
  align-items: flex-end;
}
.message.assistant {
  align-self: flex-start;
  width: 100%;
}

.bubble {
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--user-bubble);
  padding: 10px 14px;
}

.message.assistant .bubble {
  background: transparent;
}

/* markdown rendering inside assistant messages */
.message.assistant .bubble p { margin: 0 0 10px; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }
.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin: 6px 0; padding-left: 22px;
}
.message.assistant .bubble li { margin: 3px 0; }
.message.assistant .bubble strong { font-weight: 600; }
.message.assistant .bubble code {
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", "Menlo", Consolas, monospace;
  font-size: 13px;
}
.message.assistant .bubble pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
}
.message.assistant .bubble pre code {
  background: transparent;
  padding: 0;
}
.message.assistant .bubble a { color: var(--accent); }
.message.assistant .bubble table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
}
.message.assistant .bubble th,
.message.assistant .bubble td {
  border: 1px solid var(--border);
  padding: 4px 10px;
}

/* ─── thinking dots ──────────────────────────────────────── */

.thinking {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 8px 0;
}
.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: think 1.4s infinite ease-in-out both;
}
.thinking-dot:nth-child(2) { animation-delay: 0.16s; }
.thinking-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes think {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40%           { opacity: 1;    transform: scale(1); }
}

/* ─── input bar ──────────────────────────────────────────── */

.chat-input-bar {
  padding: 14px 24px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg);
}

.chat-input-bar textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  outline: none;
  max-height: 200px;
  line-height: 1.45;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-bar textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.12);
}

#send-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--accent-hover); }
#send-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

/* ─── api-key modal ──────────────────────────────────────── */

.api-key-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.api-key-modal.hidden { display: none; }
.modal-content {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  max-width: 420px;
  width: 90%;
  position: relative;
}
.modal-content h2 { margin: 0 0 12px; font-size: 18px; }
.modal-content p { margin: 0 0 12px; font-size: 14px; }
.modal-content input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
  font-family: inherit;
  outline: none;
}
.modal-content input:focus { border-color: var(--accent); }
.modal-content button#api-key-save {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.modal-content button#api-key-save:hover { background: var(--accent-hover); }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  margin-left: 8px;
  font-family: inherit;
  text-decoration: underline;
}
.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 0 !important;
}

/* ─── responsive ─────────────────────────────────────────── */

@media (max-width: 640px) {
  .chat-header { padding: 12px 16px; }
  .chat-messages { padding: 18px 16px; }
  .chat-input-bar { padding: 12px 16px 18px; }
  .memory-counter { font-size: 11px; }
}
