/* Only things Tailwind CDN can't handle */

/* ─── Global refinements ─────────────────────── */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

* { transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1); }

/* ─── Auth overlay ───────────────────────────── */
.auth-card { animation: auth-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1); }
.auth-glow {
  position: absolute; top: -60px; left: 50%; transform: translateX(-50%);
  width: 200px; height: 120px;
  background: radial-gradient(ellipse, hsl(var(--c-primary) / 0.15), transparent 70%);
  pointer-events: none;
}
@keyframes auth-enter {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Heartbeat pulse ────────────────────────── */
/* The dot only animates when the server pushes a heartbeat; each beat
   restarts the animation via a class swap in app.js. If the heartbeat
   stops, the dot stops — so a stale dot means the server is not alive. */
.status-pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: hsl(142 71% 45%);
  flex-shrink: 0;
  transition: background 0.2s;
}
.status-pulse.beat {
  animation: heartbeat 1.5s ease-out;
}
@keyframes heartbeat {
  0%   { opacity: 1;    transform: scale(1.25); box-shadow: 0 0 8px hsl(142 71% 45% / 0.6); }
  30%  { opacity: 0.9;  transform: scale(1); }
  100% { opacity: 0.45; transform: scale(1); box-shadow: 0 0 0 hsl(142 71% 45% / 0); }
}
/* Stalled state: dot turns amber/red and stops beating. */
#status-bar.stalled .status-pulse {
  background: hsl(0 70% 55%);
  animation: none;
  opacity: 1;
}
#status-bar.stalled #status-text {
  color: hsl(0 70% 70%);
}

/* ─── Connection dot ──────────────────────────── */
.dot-online {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; display: inline-block;
  background: hsl(142 71% 45%);
  box-shadow: 0 0 8px hsl(142 71% 45% / 0.35);
}
.dot-offline {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; display: inline-block;
  background: hsl(var(--c-muted-fg));
}

/* ─── Messages ────────────────────────────────── */
#messages {
  display: flex; flex-direction: column;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.msg {
  max-width: 72%;
  word-wrap: break-word; overflow-wrap: break-word;
  animation: msg-in 0.2s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: hsl(var(--c-msg-user));
  color: hsl(var(--c-fg));
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  font-size: 13.5px; line-height: 1.65;
}

.msg.agent {
  align-self: flex-start;
  background: hsl(var(--c-msg-agent));
  border: 1px solid hsl(var(--c-border));
  padding: 12px 16px;
  border-radius: 16px 16px 16px 4px;
  font-size: 13.5px; line-height: 1.65;
}

.msg.system {
  align-self: center;
  background: hsl(var(--c-msg-system));
  color: hsl(var(--c-muted-fg));
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px; letter-spacing: 0.01em;
}

/* ─── Markdown ────────────────────────────────── */
.msg pre {
  background: hsl(var(--c-code-bg));
  border: 1px solid hsl(var(--c-border));
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg code {
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 12.5px;
}
.msg p code {
  background: hsl(var(--c-code-inline));
  padding: 2px 6px; border-radius: 4px;
  font-size: 12px; color: hsl(var(--c-primary));
}
.msg p { margin: 4px 0; }
.msg ul, .msg ol { padding-left: 20px; margin: 4px 0; }
.msg a { color: hsl(var(--c-primary)); text-decoration: none; }
.msg a:hover { text-decoration: underline; }
.msg blockquote { border-left: 2px solid hsl(var(--c-primary)); padding-left: 12px; color: hsl(var(--c-muted-fg)); margin: 8px 0; }
.msg table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.msg th, .msg td { border: 1px solid hsl(var(--c-border)); padding: 6px 10px; }
.msg th { background: hsl(var(--c-muted)); }

/* ─── Tool groups ─────────────────────────────── */
.tool-group {
  align-self: flex-start;
  width: 100%; max-width: 560px;
  background: hsl(var(--c-tool-bg));
  border: 1px solid hsl(var(--c-tool-border));
  border-radius: 10px;
  font-size: 13px;
  animation: msg-in 0.2s ease-out;
}

.tool-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  cursor: pointer; user-select: none;
  transition: background 0.1s;
  border-radius: 10px;
}
.tool-group-header:hover { background: hsl(var(--c-accent)); }

.tool-group-label {
  color: hsl(var(--c-muted-fg));
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 12px; flex: 1;
}

.tool-group .tool-chevron {
  color: hsl(var(--c-muted-fg));
  font-size: 10px;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.tool-group:not(.collapsed) .tool-chevron { transform: rotate(90deg); }

.tool-group-body {
  border-top: 1px solid hsl(var(--c-tool-border));
  padding: 4px 0;
}
.tool-group.collapsed .tool-group-body { display: none; }

.tool-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 20px;
}

.tool-item .tool-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: hsl(var(--c-muted-fg));
  flex-shrink: 0; transition: background 0.2s;
}
.tool-item.active .tool-dot {
  background: hsl(142 71% 45%);
  animation: pulse 1.4s ease-in-out infinite;
}
.tool-item.done .tool-dot {
  background: hsl(var(--c-muted-fg));
  animation: none;
}

.tool-item .tool-label {
  color: hsl(var(--c-muted-fg));
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 11.5px; flex: 1; min-width: 0;
}
.tool-item .tool-label code {
  background: hsl(var(--c-code-inline));
  padding: 1px 5px; border-radius: 3px;
  font-size: 11px;
}

/* ─── File download ───────────────────────────── */
.file-download {
  display: inline-flex; align-items: center; gap: 6px;
  background: hsl(var(--c-muted));
  border: 1px solid hsl(var(--c-border));
  border-radius: 8px; padding: 8px 12px; margin-top: 8px;
  color: hsl(var(--c-primary));
  text-decoration: none; font-size: 12.5px;
  transition: border-color 0.15s;
}
.file-download:hover { border-color: hsl(var(--c-primary)); }

/* ─── Project list items ──────────────────────── */
.project-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 7px;
  cursor: pointer; font-size: 13px;
  color: hsl(var(--c-muted-fg));
  transition: all 0.12s ease;
}
.project-item:hover { background: hsl(var(--c-accent)); color: hsl(var(--c-fg)); }
.project-item.active { background: hsl(var(--c-primary) / 0.12); color: hsl(var(--c-primary)); }

.project-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: hsl(var(--c-muted-fg)); flex-shrink: 0;
}
.project-item.active .project-dot {
  background: hsl(142 71% 45%);
  box-shadow: 0 0 6px hsl(142 71% 45% / 0.3);
}

/* ─── Sidebar ─────────────────────────────────── */
.sidebar-default { transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
.sidebar-action { position: relative; }
.sidebar-action::before {
  content: ''; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0; border-radius: 2px;
  background: hsl(var(--c-primary)); opacity: 0; transition: all 0.15s;
}
.sidebar-action:hover::before { width: 3px; height: 14px; opacity: 1; }

details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }

@media (max-width: 768px) {
  .sidebar-default {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); z-index: 50;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .sidebar-default.open { transform: translateX(0); }
  #sidebar-toggle { display: block !important; }
  #sidebar-close { display: block !important; }
  .msg { max-width: 92%; }
}

/* Input wrapper */
.input-wrapper {
  box-shadow: 0 -2px 12px hsl(var(--c-bg) / 0.5);
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--c-border)); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--c-muted-fg)); }

#status-bar.hidden { display: none !important; }

/* ─── Chat list ───────────────────────────────── */
.chat-item { position: relative; }
.chat-item > button:first-child {
  color: hsl(var(--c-muted-fg));
  background: transparent;
  border: 1px solid transparent;
}
.chat-item > button:first-child:hover {
  background: hsl(var(--c-accent));
  color: hsl(var(--c-fg));
}
.chat-item.active > button:first-child {
  background: hsl(var(--c-accent));
  color: hsl(var(--c-fg));
  border-color: hsl(var(--c-border));
}
.chat-delete { font-size: 16px; line-height: 1; }

/* ─── Todo checklist ──────────────────────────── */
.todo-box {
  background: hsl(var(--c-card));
  border: 1px solid hsl(var(--c-tool-border));
  border-radius: 10px;
  padding: 10px 14px 12px;
  margin: 4px 0;
}
.todo-box.live {
  border-color: hsl(var(--c-primary) / 0.45);
  box-shadow: 0 0 24px hsl(var(--c-primary) / 0.08);
}
.todo-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.todo-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: hsl(var(--c-muted-fg)); font-weight: 600;
}
.todo-count {
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 11px; color: hsl(var(--c-muted-fg));
}
.todo-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.todo-item {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px;
  color: hsl(var(--c-fg) / 0.85);
  padding: 2px 0;
}
.todo-glyph {
  display: inline-block; width: 14px; flex-shrink: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px; line-height: 1.4;
  text-align: center;
  color: hsl(var(--c-muted-fg));
}
.todo-item.pending .todo-glyph { color: hsl(var(--c-muted-fg)); }
.todo-item.active .todo-glyph {
  color: hsl(var(--c-primary));
  animation: todo-pulse 1.4s ease-in-out infinite;
}
.todo-item.done .todo-glyph { color: hsl(142 71% 45%); }
.todo-item.done .todo-text {
  color: hsl(var(--c-muted-fg));
  text-decoration: line-through;
  text-decoration-color: hsl(var(--c-muted-fg) / 0.5);
}
.todo-item.active .todo-text {
  color: hsl(var(--c-fg));
  font-weight: 500;
}
@keyframes todo-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
::selection { background: hsl(var(--c-primary) / 0.25); }

/* ─── Light mode highlight.js override ────────── */
.light .hljs { background: hsl(var(--c-code-bg)) !important; }
