.hidden { display: none !important; }

body {
  height: 100dvh;
  overflow: hidden;
}

#app {
  height: 100dvh;
}

#chat {
  display: flex;
  height: 100dvh;
}

/* Sidebar */
#sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--hf-space-3);
}

#sidebar-header h1 {
  margin: 0;
}

#sidebar-logo {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  color: var(--hf-accent);
  margin: -4px;
}

#sidebar {
  width: 240px;
  background: var(--hf-bg-surface);
  border-right: 1px solid var(--hf-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--hf-transition-slow), opacity var(--hf-transition-slow);
  overflow: hidden;
}

#sidebar.collapsed {
  width: 0;
  opacity: 0;
  border-right: none;
}

#participants {
  list-style: none;
  margin: 0;
  padding: 0 var(--hf-space-2);
  flex: 1;
  overflow-y: auto;
}

#participants li {
  display: flex;
  align-items: center;
  gap: var(--hf-space-2);
  padding: var(--hf-space-1) var(--hf-space-2);
  font-size: var(--hf-size-sm);
  color: var(--hf-text-normal);
  border-radius: var(--hf-radius-sm);
}

#participants li .participant-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--hf-radius-full);
  background: var(--hf-green);
  flex-shrink: 0;
}

#sidebar-toggle {
  margin-top: auto;
  border-top: 1px solid var(--hf-border);
  border-radius: 0;
}

#presence-status.active {
  color: var(--hf-green);
}

/* Chat main area */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--hf-space-2) 0;
}

.message {
  padding: 2px var(--hf-space-4) 2px 72px;
  line-height: var(--hf-leading-normal);
  position: relative;
}

.message:hover {
  background: color-mix(in srgb, var(--hf-color-2) 50%, transparent 50%);
}

.message-first {
  margin-top: var(--hf-space-3);
  padding-top: var(--hf-space-1);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--hf-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--hf-size-sm);
  font-weight: var(--hf-weight-bold);
  color: var(--hf-text-bright);
  position: absolute;
  left: var(--hf-space-4);
  flex-shrink: 0;
}

.bot-avatar {
  background: var(--hf-accent);
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: var(--hf-space-2);
}

.sender-name {
  font-weight: var(--hf-weight-semibold);
  font-size: var(--hf-size-base);
}

.bot-name {
  color: var(--hf-accent);
}

.message-time {
  font-size: var(--hf-size-xs);
  color: var(--hf-text-muted);
}

.message-model {
  font-size: var(--hf-size-xs);
  color: var(--hf-text-muted);
  margin-left: var(--hf-space-2);
  opacity: 0.7;
}

.inline-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--hf-space-1);
  margin-bottom: 2px;
}

.message-body {
  font-size: var(--hf-size-base);
  color: var(--hf-text-normal);
}

.message-body pre {
  background: var(--hf-bg-base);
  padding: var(--hf-space-3);
  border-radius: var(--hf-radius-sm);
  border: 1px solid var(--hf-border);
  overflow-x: auto;
  margin: var(--hf-space-2) 0;
}

.message-body code {
  font-family: var(--hf-font-family-mono);
  font-size: var(--hf-size-sm);
}

/* Name prompt */
#name-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  gap: var(--hf-space-4);
}

#name-input {
  width: 200px;
}

/* Input area */
#input-area {
  padding: var(--hf-space-3) var(--hf-space-4);
  background: var(--hf-bg-surface);
  align-items: center;
}

.channel-label {
  font-size: var(--hf-size-sm);
  color: var(--hf-text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

#input {
  flex: 1;
  resize: none;
  min-height: 0;
  max-height: 200px;
  padding: var(--hf-space-2) var(--hf-space-3);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Idle thoughts and tool calls */
.idle-thought {
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  font-style: italic;
  margin: var(--hf-space-2) var(--hf-space-4);
  padding: var(--hf-space-2) var(--hf-space-3);
  border-left: 2px solid var(--hf-border);
  background: color-mix(in srgb, var(--hf-bg-surface) 50%, transparent 50%);
  border-radius: 0 var(--hf-radius-sm) var(--hf-radius-sm) 0;
}

.idle-thought-name {
  font-weight: 600;
  font-style: normal;
  margin-right: var(--hf-space-2);
}

.idle-thought-name::after {
  content: ' \00b7  idle thought';
  font-weight: 400;
  color: var(--hf-text-muted);
}

.idle-thought-details > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.idle-thought-details > summary::-webkit-details-marker { display: none; }
.idle-thought-details > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: var(--hf-space-2);
  color: var(--hf-text-muted);
  transition: transform 0.15s ease;
}
.idle-thought-details[open] > summary::before {
  transform: rotate(90deg);
}
.idle-thought-details > .idle-thought-body {
  margin-top: var(--hf-space-2);
}

/* Dual-lane assistant output — thought block above the chat body.
   Required by the standing bans: thought must be visible, never hidden,
   never stripped. Rendered with visually-distinct styling so the reader
   can tell it apart from chat content. No `<details>` collapse here —
   ban on hiding text means the content is always rendered expanded. */
.assistant-thought {
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  font-style: italic;
  margin: var(--hf-space-1) 0 var(--hf-space-2) 0;
  padding: var(--hf-space-2) var(--hf-space-3);
  border-left: 2px solid var(--hf-border);
  background: color-mix(in srgb, var(--hf-bg-surface) 50%, transparent 50%);
  border-radius: 0 var(--hf-radius-sm) var(--hf-radius-sm) 0;
}

.assistant-thought-header {
  font-size: var(--hf-size-xs, 0.75em);
  font-style: normal;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--hf-text-muted);
  margin-bottom: var(--hf-space-1);
}

.assistant-thought-body {
  /* Inherit italic from parent; spacing matches idle-thought-body. */
}

.assistant-thought-body > :first-child { margin-top: 0; }
.assistant-thought-body > :last-child { margin-bottom: 0; }

/* DM welcome header */
.dm-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--hf-space-6) var(--hf-space-4) var(--hf-space-2);
}

.dm-welcome-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--hf-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--hf-size-lg);
  color: var(--hf-text-on-accent, #fff);
}

.dm-welcome-name {
  font-size: var(--hf-size-lg);
  font-weight: 700;
  margin-top: var(--hf-space-2);
  color: var(--hf-text);
}

.dm-welcome-desc {
  font-size: var(--hf-size-sm);
  color: var(--hf-text-dim);
  margin-top: var(--hf-space-1);
}

.dm-welcome-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--hf-border);
  margin-top: var(--hf-space-4);
}

#connection-status {
  background: var(--hf-warn, #b8860b);
  color: #fff;
  font-size: var(--hf-size-sm);
  text-align: center;
  padding: var(--hf-space-1) var(--hf-space-2);
}

.system-message {
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  text-align: center;
  margin: var(--hf-space-2) var(--hf-space-4);
  padding: var(--hf-space-1) 0;
}

.tool-details {
  margin: var(--hf-space-1) 0;
  padding-left: var(--hf-space-2);
  border-left: 2px solid var(--hf-border);
}

.tool-summary {
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.tool-summary:hover {
  color: var(--hf-text-normal);
}

.tool-call {
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  font-style: italic;
  margin: 2px 0;
}

/* Running state: animated pulse marker + live elapsed-time display.
   Applied to a tool chip from tool_start until tool_result lands. Critical
   affordance for slow tools (e.g. deep_think) — user can see brad is still
   in flight rather than wondering if he crashed. */
.tool-call.running {
  color: var(--hf-text-normal);
  font-style: normal;
}

.tool-call.running::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 6px 0 2px;
  border-radius: var(--hf-radius-full);
  background: var(--hf-accent, var(--hf-text-dim));
  animation: thinking-pulse 1.4s ease-in-out infinite;
  vertical-align: middle;
}

/* Error state: tool returned is_error=true. Visually distinct from a
   normal completion so failures aren't silently buried in the tool chip
   stack. */
.tool-call.error {
  color: var(--hf-danger, #d04242);
  font-style: normal;
}
.tool-call.error::before {
  content: '⚠';
  display: inline-block;
  margin: 0 6px 0 2px;
  color: var(--hf-danger, #d04242);
  vertical-align: middle;
}
.tool-call.error .tool-label,
.tool-call.error .message-time {
  color: inherit;
}

.tool-elapsed {
  margin-left: 6px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  font-style: normal;
}

/* Thinking indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: var(--hf-space-2);
  color: var(--hf-text-dim);
  font-size: var(--hf-size-sm);
  font-style: italic;
  padding: var(--hf-space-1) 0;
}

.thinking-indicator .thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-indicator .thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: var(--hf-radius-full);
  background: var(--hf-text-dim);
  animation: thinking-pulse 1.4s ease-in-out infinite;
}

.thinking-indicator .thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-indicator .thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

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

.error { color: var(--hf-red); }

/* Agent messages (visiting agents in the room) */
.agent-message .avatar {
  border: 2px solid var(--hf-accent);
}

/* Visiting agent messages — color-coded left border */
.visitor-message {
  border-left: 3px solid var(--hf-accent);
  padding-left: calc(72px - 3px);
}

.visitor-message .avatar {
  border: none;
}

.visitor-tools-summary {
  font-size: var(--hf-size-xs);
  color: var(--hf-text-dim);
  font-style: italic;
  margin-bottom: var(--hf-space-1);
}

/* Mobile / responsive */
@media (max-width: 768px) {
  body, #app, #chat {
    height: 100dvh;
  }

  #name-prompt {
    height: 100dvh;
    padding: var(--hf-space-4);
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    z-index: 10;
    width: 240px;
  }

  #sidebar.collapsed {
    width: 0;
    opacity: 0;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
  }

  .message {
    padding-left: 52px;
    padding-right: var(--hf-space-3);
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: var(--hf-size-xs);
    left: var(--hf-space-3);
  }

  .visitor-message {
    padding-left: calc(52px - 3px);
  }

  .idle-thought,
  .system-message {
    margin-left: var(--hf-space-3);
    margin-right: var(--hf-space-3);
  }

  #input-area {
    padding: var(--hf-space-2) var(--hf-space-3);
  }

  #send-btn {
    padding: var(--hf-space-2) var(--hf-space-3);
  }

  .message-body pre {
    font-size: var(--hf-size-xs);
  }
}

@media (max-width: 400px) {
  .message {
    padding-left: 44px;
  }

  .visitor-message {
    padding-left: calc(44px - 3px);
  }

  .avatar {
    width: 24px;
    height: 24px;
    font-size: 0.5rem;
    left: var(--hf-space-2);
  }

  #input-area {
    gap: var(--hf-space-1);
  }
}

/* Room list */
.room-item {
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  border-radius: var(--hf-radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--hf-size-sm);
  color: var(--hf-text-normal);
}

.room-item:hover,
.participant-item:hover {
  background: color-mix(in srgb, var(--hf-color-2) 50%, transparent 50%);
}

.room-item.active,
.participant-item.active {
  background: color-mix(in srgb, var(--hf-color-3) 50%, transparent 50%);
  font-weight: var(--hf-weight-semibold);
}

/* Unread badge */
.unread-badge {
  background: var(--hf-accent);
  color: var(--hf-text-bright);
  font-size: 0.65rem;
  font-weight: var(--hf-weight-bold);
  padding: 0.1rem 0.4rem;
  border-radius: var(--hf-radius-full);
  min-width: 1.2rem;
  text-align: center;
}

/* Sidebar sections */
.sidebar-section-label {
  padding: var(--hf-space-3) var(--hf-space-3) var(--hf-space-1);
}

#rooms-list {
  list-style: none;
  margin: 0;
  padding: 0 var(--hf-space-2);
}

/* Message hover toolbar */
.message-toolbar {
  position: absolute;
  top: -12px;
  right: var(--hf-space-4);
  display: none;
  gap: 2px;
  background: var(--hf-color-3);
  border: 1px solid var(--hf-color-4);
  border-radius: var(--hf-radius-md);
  padding: 2px;
  z-index: 10;
}

.message:hover .message-toolbar {
  display: flex;
}

.toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--hf-radius-sm);
  font-size: var(--hf-size-sm);
  color: var(--hf-text-muted);
  line-height: 1;
}

.toolbar-btn:hover {
  background: var(--hf-color-4);
  color: var(--hf-text-normal);
}

/* Reply banner above input */
.reply-banner {
  display: flex;
  align-items: center;
  gap: var(--hf-space-2);
  padding: var(--hf-space-1) var(--hf-space-3);
  background: var(--hf-color-2);
  border-left: 3px solid var(--hf-accent);
  font-size: var(--hf-size-sm);
  color: var(--hf-text-muted);
}

.reply-banner.hidden {
  display: none;
}

.reply-banner-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--hf-text-muted);
  font-size: var(--hf-size-sm);
  padding: 2px 4px;
}

.reply-banner-close:hover {
  color: var(--hf-text-normal);
}

/* Reply header on messages */
.reply-header {
  display: flex;
  gap: var(--hf-space-1);
  padding: 2px 0;
  margin-bottom: 2px;
  border-left: 2px solid var(--hf-text-muted);
  padding-left: var(--hf-space-2);
  font-size: var(--hf-size-xs);
  color: var(--hf-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-header-name {
  font-weight: var(--hf-weight-semibold);
}

.reply-header-snippet {
  opacity: 0.7;
}

.reply-header-linked {
  cursor: pointer;
}

/* Highlight effect when scrolling to referenced message */
.message {
  transition: background 0.3s ease;
}

.reply-highlight {
  background: color-mix(in srgb, var(--hf-accent) 15%, transparent) !important;
}

/* Emoji picker */
.emoji-picker {
  position: fixed;
  background: var(--hf-color-2);
  border: 1px solid var(--hf-color-4);
  border-radius: var(--hf-radius-lg);
  padding: var(--hf-space-2);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  max-width: 280px;
}

.emoji-picker-quick {
  display: flex;
  gap: 2px;
  padding-bottom: var(--hf-space-1);
}

.emoji-picker-divider {
  border: none;
  border-top: 1px solid var(--hf-color-4);
  margin: var(--hf-space-1) 0;
}

.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.emoji-pick-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--hf-radius-sm);
  font-size: 18px;
  line-height: 1;
}

.emoji-pick-btn:hover {
  background: var(--hf-color-4);
}

/* Reaction pills */
.reactions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 2px 0 2px 0;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--hf-color-2);
  border: 1px solid var(--hf-color-4);
  border-radius: var(--hf-radius-full);
  padding: 1px 8px;
  cursor: pointer;
  font-size: var(--hf-size-xs);
  color: var(--hf-text-muted);
  line-height: 1.4;
}

.reaction-pill:hover {
  background: var(--hf-color-3);
  border-color: var(--hf-text-muted);
}

.reaction-pill.reaction-mine {
  border-color: var(--hf-accent);
  background: color-mix(in srgb, var(--hf-accent) 10%, var(--hf-color-2));
}

.reaction-emoji {
  font-size: 14px;
}

.reaction-count {
  font-size: var(--hf-size-xs);
  font-weight: var(--hf-weight-semibold);
}

/* Thread viewer overlay (thread-ui.js) */
.thread-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
.thread-panel {
  background: var(--hf-bg, #14141a);
  border: 1px solid var(--hf-border, #333);
  border-radius: 8px;
  width: min(680px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.thread-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hf-border, #333);
  font-size: 13px;
  opacity: 0.9;
}
.thread-panel-body {
  overflow-y: auto;
  padding: 10px 14px;
}
.thread-entry {
  padding: 8px 10px;
  margin-bottom: 8px;
  border-left: 2px solid var(--hf-border, #444);
  border-radius: 4px;
}
.thread-entry-agent {
  border-left-color: var(--hf-accent, #4a9eff);
}
.thread-entry-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 4px;
  opacity: 0.85;
}
.thread-entry-id, .thread-entry-reply, .thread-entry-time {
  font-family: monospace;
  font-size: 11px;
  opacity: 0.6;
}
.thread-entry-text {
  font-size: 13px;
  line-height: 1.45;
}
.thread-empty {
  padding: 20px;
  text-align: center;
  opacity: 0.6;
  font-size: 13px;
}

/* History search overlay (search-ui.js) */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8vh;
  z-index: 910;
}
.search-overlay.hidden { display: none; }
.search-panel {
  background: var(--hf-bg, #14141a);
  border: 1px solid var(--hf-border, #333);
  border-radius: 8px;
  width: min(720px, 92vw);
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.search-panel-header {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--hf-border, #333);
}
.search-input { flex: 1; }
.search-results {
  overflow-y: auto;
  padding: 8px 12px;
}
.search-hit {
  padding: 8px 10px;
  margin-bottom: 8px;
  border-left: 2px solid var(--hf-border, #444);
  border-radius: 4px;
}
.search-hit-agent { border-left-color: var(--hf-accent, #4a9eff); }
.search-hit-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 3px;
  opacity: 0.85;
}
.search-hit-tag {
  font-family: monospace;
  font-size: 10px;
  padding: 0 5px;
  border: 1px solid var(--hf-border, #444);
  border-radius: 8px;
  opacity: 0.7;
}
.search-hit-time { margin-left: auto; font-size: 11px; opacity: 0.55; }
.search-hit-text { font-size: 13px; line-height: 1.4; }
.search-hit-text mark {
  background: var(--hf-accent, #4a9eff);
  color: var(--hf-bg, #111);
  border-radius: 2px;
  padding: 0 1px;
}
.search-hit-actions { display: flex; gap: 6px; margin-top: 5px; }
.search-hint { padding: 14px; opacity: 0.6; font-size: 13px; }

/* Search hit reply link + thread reply affordance */
.search-reply-link {
  font-size: 12px;
  color: var(--hf-accent, #4a9eff);
  text-decoration: none;
}
.search-reply-link:hover { text-decoration: underline; }
.thread-reply-btn { margin-left: 8px; font-size: 11px; }

/* Library panels (Task 10): scripts / webhooks / artifacts sidebar sections.
   #sidebar-scripts/#sidebar-webhooks/#sidebar-artifacts and their .harness-*
   row/list/empty-state classes are already fully styled by harness.css
   (unconditionally loaded regardless of RAZOR_LEGACY_SINGLE_ROOM) — only the
   artifact viewer's content area needs new rules here. */
.artifact-viewer-frame {
  display: block;
  width: 100%;
  height: 60vh;
  border: none;
  border-radius: var(--hf-radius-sm);
}

.artifact-viewer-text {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
}
