:root {
  --bg: #f7f8fa;
  --fg: #1f2937;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --border: #e5e7eb;
  --user-bg: #dbeafe;
  --assistant-bg: #ffffff;
  --sidebar-bg: #1f2937;
  --sidebar-fg: #f9fafb;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif; color: var(--fg); background: var(--bg); }
.view { height: 100vh; }
.hidden { display: none !important; }

/* Login */
#login-view { display: flex; align-items: center; justify-content: center; }
.login-card { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); width: 360px; }
.login-card h1 { margin: 0 0 8px; font-size: 1.4rem; }
.subtitle { color: #6b7280; margin: 0 0 24px; font-size: 0.85rem; }
.login-card label { display: block; margin-bottom: 16px; font-size: 0.9rem; }
.login-card input { display: block; width: 100%; padding: 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem; }
.login-card button { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; }
.login-card button:hover { background: var(--primary-dark); }
.error { color: #dc2626; font-size: 0.85rem; min-height: 1.2em; margin: 12px 0 0; }
.hint { font-size: 0.8rem; color: #9ca3af; margin-top: 16px; text-align: center; }
.hint code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }

/* Chat layout */
#chat-view { display: grid; grid-template-columns: 260px 1fr; }
#sidebar { background: var(--sidebar-bg); color: var(--sidebar-fg); display: flex; flex-direction: column; }
.sidebar-head { padding: 16px; border-bottom: 1px solid #374151; }
#new-chat { width: 100%; padding: 10px; background: transparent; color: white; border: 1px solid #4b5563; border-radius: 6px; cursor: pointer; }
#new-chat:hover { background: #374151; }
#session-list { list-style: none; padding: 8px; margin: 0; flex: 1; overflow-y: auto; }
#session-list li { padding: 10px 12px; margin: 2px 0; border-radius: 6px; cursor: pointer; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#session-list li:hover { background: #374151; }
#session-list li.active { background: #2563eb; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid #374151; display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; }
.sidebar-foot button { background: transparent; color: #9ca3af; border: none; cursor: pointer; font-size: 0.85rem; }
.sidebar-foot button:hover { color: white; }

/* Messages */
#chat { display: flex; flex-direction: column; height: 100vh; }
#messages { flex: 1; overflow-y: auto; padding: 24px; }
.msg { max-width: 800px; margin: 0 auto 16px; padding: 14px 18px; border-radius: 10px; line-height: 1.6; }
.msg.user { background: var(--user-bg); margin-left: auto; max-width: 600px; }
.msg.assistant { background: var(--assistant-bg); border: 1px solid var(--border); }
.msg-role { font-size: 0.75rem; color: #6b7280; margin-bottom: 4px; font-weight: 600; }
.msg pre { background: #f3f4f6; padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }
.msg code { background: #f3f4f6; padding: 2px 4px; border-radius: 3px; font-size: 0.85em; }
.msg table { border-collapse: collapse; margin: 8px 0; font-size: 0.9rem; }
.msg th, .msg td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg th { background: #f9fafb; }

/* Input */
#chat-form { display: flex; padding: 16px 24px; gap: 12px; border-top: 1px solid var(--border); background: white; }
#input { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 8px; resize: none; font-family: inherit; font-size: 0.95rem; }
#send { padding: 12px 24px; background: var(--primary); color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 0.95rem; }
#send:hover { background: var(--primary-dark); }
#send:disabled { background: #9ca3af; cursor: not-allowed; }

/* Typing dot animation */
.dot-anim { display: inline-flex; gap: 6px; align-items: center; }
.dot-anim > span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #6b7280; opacity: 0.4;
  animation: dot-bounce 1.2s infinite ease-in-out both;
}
.dot-anim > span:nth-child(1) { animation-delay: -0.32s; }
.dot-anim > span:nth-child(2) { animation-delay: -0.16s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* Persistent typing pill (sits below latest bubble while agent runs) */
.typing-pill {
  display: inline-flex; align-items: center; gap: 10px;
  background: #eef2f7; color: #4b5563;
  padding: 7px 14px; border-radius: 999px;
  font-size: 0.8rem;
  max-width: 800px; margin: 0 auto 16px;
  width: fit-content;
}
.typing-label { font-style: italic; }

/* Inline tool entries (call + result) — compact colored rows in chat log */
.tool-entry {
  max-width: 800px; margin: 4px auto;
  border-left: 3px solid #9ca3af;
  background: #f3f4f6; color: #374151;
  border-radius: 4px; font-size: 0.8rem;
  overflow: hidden;
}
.tool-entry.skill { border-left-color: #1d4ed8; background: #eff6ff; }
.tool-entry.done  { border-left-color: #10b981; }
.tool-entry.error { border-left-color: #dc2626; background: #fef2f2; }
.tool-entry.pending .tool-status { animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

.tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; cursor: pointer;
}
.tool-head:hover { background: rgba(0,0,0,0.03); }
.tool-icon { font-size: 0.95rem; line-height: 1; }
.tool-name { font-weight: 600; color: #1f2937; flex-shrink: 0; }
.tool-entry.skill .tool-name { color: #1d4ed8; }
.tool-detail {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem;
  color: #6b7280;
}
.tool-status { flex-shrink: 0; font-size: 0.85rem; color: #6b7280; }

.tool-output {
  padding: 0 12px 8px;
  border-top: 1px solid rgba(0,0,0,0.06);
  max-height: 280px; overflow: auto;
}
.tool-output pre {
  margin: 8px 0 0; padding: 8px 10px;
  background: #1f2937; color: #f9fafb;
  border-radius: 4px; font-size: 0.75rem;
  white-space: pre-wrap; word-break: break-word;
}
