/* --- Chat Screen --- */

#chat-screen {
  position: relative;
}

#chat-screen > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#session-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.model-select {
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.model-select:focus {
  outline: none;
  border-color: var(--primary);
}

.session-cost {
  padding: 0.3rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

/* --- Messages --- */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.9rem;
  word-wrap: break-word;
}

.message.user {
  white-space: pre-wrap;
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* Typing indicator bubble */
.typing-bubble {
  padding: 0.85rem 1.1rem !important;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingPulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* --- Markdown in assistant messages --- */

.message.assistant .content h1,
.message.assistant .content h2,
.message.assistant .content h3 {
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}
.message.assistant .content h1 { font-size: 1.1rem; }
.message.assistant .content h2 { font-size: 1rem; }
.message.assistant .content h3 { font-size: 0.95rem; }

.message.assistant .content p {
  margin-bottom: 0.5rem;
}
.message.assistant .content p:last-child {
  margin-bottom: 0;
}

.message.assistant .content ul,
.message.assistant .content ol {
  margin: 0.25rem 0 0.5rem 1.25rem;
}

.message.assistant .content li {
  margin-bottom: 0.15rem;
}

.message.assistant .content code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 0.85em;
}

.message.assistant .content pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message.assistant .content pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

.message.assistant .content strong {
  color: #fff;
}

.message.assistant .content a {
  color: var(--primary);
}

.message.assistant .content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: var(--text-muted);
}

.message.assistant .content table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  width: 100%;
}

.message.assistant .content th,
.message.assistant .content td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  text-align: left;
}

.message.assistant .content th {
  background: rgba(255, 255, 255, 0.05);
}

.message .tool-call {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  font-family: "SF Mono", Monaco, monospace;
  max-height: 200px;
  overflow-y: auto;
}

/* --- Working Indicator --- */

#working-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* --- Input Area --- */

#input-area {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}

#input-area.drag-over {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-top-color: var(--accent);
}

.upload-zone {
  flex-shrink: 0;
}

.upload-label {
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.4rem;
  display: block;
}

#upload-preview {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.upload-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-hover);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

#upload-preview .remove {
  cursor: pointer;
  color: var(--danger);
  font-size: 0.7rem;
}

#message-input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 150px;
}

#message-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* --- Files Panel --- */

#files-panel {
  position: absolute;
  bottom: 70px;
  right: 1rem;
  width: 320px;
  max-height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  z-index: 10;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 {
  font-size: 0.9rem;
}

#files-list {
  padding: 0.5rem;
  max-height: 340px;
  overflow-y: auto;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.file-item:hover {
  background: var(--surface-hover);
}

.file-item .name {
  font-size: 0.85rem;
  word-break: break-all;
}
.file-item .size {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 0.5rem;
}

/* --- Extension UI --- */

#extension-ui {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#extension-ui .dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
}

#extension-ui .dialog h3 {
  margin-bottom: 0.75rem;
}

#extension-ui .dialog p {
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#extension-ui .dialog .options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#extension-ui .dialog .options .btn {
  text-align: left;
}

#extension-ui .dialog input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

#extension-ui .dialog .dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* --- Subagent pill --- */

.subagent-pill {
  align-self: stretch;
  max-width: 100%;
  margin: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 0.85rem;
  overflow: hidden;
}

.subagent-pill.running {
  border-left-color: #d0a040;
}

.subagent-pill.done {
  border-left-color: #4ac46a;
}

.subagent-pill.error {
  border-left-color: var(--danger);
}

.subagent-pill-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  user-select: none;
}

.subagent-pill-header:hover {
  background: var(--surface-hover);
}

.subagent-pill-icon {
  flex: none;
}

.subagent-pill-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.subagent-pill-status {
  flex: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: lowercase;
}

.subagent-pill-result {
  padding: 0.5rem 0.75rem 0.75rem 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 400px;
  overflow-y: auto;
}

.subagent-pill-result.hidden {
  display: none;
}

.subagent-pill-result p:first-child {
  margin-top: 0;
}

.subagent-pill-result p:last-child {
  margin-bottom: 0;
}

/* Session recall pill */
.session-recall-pill {
  align-self: stretch;
  max-width: 100%;
  margin: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #d0a040;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
}

.session-recall-pill.done {
  border-left-color: #4ac46a;
}

/* Compaction pill */
.compaction-pill {
  align-self: stretch;
  max-width: 100%;
  margin: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #d0a040;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  transition: border-left-color 0.3s ease;
}

.compaction-pill.done {
  border-left-color: #4ac46a;
}

/* Library pill */
.library-pill {
  align-self: stretch;
  max-width: 100%;
  margin: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #d0a040;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  transition: border-left-color 0.3s ease, color 0.3s ease;
}

.library-pill.done {
  border-left-color: #4ac46a;
  color: var(--text-muted);
}

.library-pill.error {
  border-left-color: var(--danger);
}

.library-pill-icon {
  flex: none;
  font-size: 1rem;
}

.library-pill-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Mobile --- */

@media (max-width: 640px) {
  .message {
    max-width: 95%;
  }

  #files-panel {
    left: 1rem;
    width: auto;
  }
}
