/* ===== Workspace Header ===== */
.workspace-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-soft);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  flex-shrink: 0;
  z-index: var(--z-panel);
}
.wh-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wh-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.model-pill {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.icon-button-sm {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: var(--transition-fast);
  flex-shrink: 0;
}
.icon-button-sm:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== Welcome Screen ===== */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-7) var(--space-4) var(--space-6);
  max-width: 640px;
  margin: 0 auto;
}
.welcome-logo {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-5);
  opacity: 0.9;
}
.welcome-screen h3 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  text-align: center;
}
.welcome-screen > p {
  font-size: var(--text-base);
  color: var(--text-muted);
  text-align: center;
  line-height: var(--leading-relaxed);
  max-width: 480px;
  margin-bottom: var(--space-6);
}

/* Quick action cards */
.quick-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 560px;
  margin-bottom: var(--space-7);
}
.quick-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: left;
  min-height: 90px;
}
.quick-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.quick-card:active {
  transform: translateY(0);
}
.quick-card:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.qc-icon {
  font-size: 20px;
  line-height: 1;
}
.qc-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}
.qc-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: var(--leading-normal);
}

/* Recent sections */
.welcome-recent {
  width: 100%;
  max-width: 560px;
}
.welcome-recent-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Chat Messages ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-4) 0;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.chat-inner {
  max-width: var(--max-content-w);
  margin: 0 auto;
  padding: 0 var(--space-5);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Message */
.msg {
  margin-bottom: var(--space-4);
  animation: msgIn var(--duration-normal) var(--ease-standard);
  display: flex;
  flex-direction: column;
}
.msg.user {
  align-items: flex-end;
}
.msg.assistant {
  align-items: flex-start;
}

/* Message header */
.msg-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  padding: 0 var(--space-1);
}
.msg-avatar {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-avatar svg {
  width: 100%;
  height: 100%;
}
.msg-role {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
}
.msg-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.7;
}

/* Message body */
.msg-body {
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  word-break: break-word;
  color: var(--text-primary);
  max-width: 100%;
}

/* User message */
.msg.user .msg-body {
  background: var(--accent-soft);
  border: 1px solid rgba(113, 101, 235, 0.15);
  border-radius: var(--radius-lg) var(--radius-xs) var(--radius-lg) var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  max-width: 74%;
}
.msg.user .msg-header {
  flex-direction: row-reverse;
}

/* Assistant message */
.msg.assistant .msg-body {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xs) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  max-width: 100%;
}

/* Message actions */
.msg-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
  opacity: 0;
  transition: opacity var(--duration-fast);
  padding: 0 var(--space-1);
}
.msg:hover .msg-actions {
  opacity: 1;
}
.msg-action-btn {
  padding: 3px 10px;
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: var(--transition-fast);
}
.msg-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* Markdown in messages */
.msg-body p { margin-bottom: var(--space-2); }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body pre {
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  overflow-x: auto;
  margin: var(--space-2) 0;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  position: relative;
  max-width: 100%;
}
.msg-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.msg-body :not(pre) > code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: var(--radius-xs);
}
.msg-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: var(--space-2) 0;
  cursor: pointer;
}
.msg-body ul, .msg-body ol {
  padding-left: var(--space-5);
  margin: var(--space-2) 0;
}
.msg-body a {
  color: var(--text-link);
  text-decoration: none;
}
.msg-body a:hover { text-decoration: underline; }
.msg-body table {
  border-collapse: collapse;
  margin: var(--space-2) 0;
  width: 100%;
  font-size: var(--text-sm);
}
.msg-body th, .msg-body td {
  border: 1px solid var(--border-soft);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}
.msg-body th {
  background: var(--bg-inset);
  font-weight: var(--weight-semibold);
}
.msg-body blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--space-2) var(--space-3);
  margin: var(--space-2) 0;
  background: var(--bg-inset);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

/* Code copy button */
.code-copy-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-soft);
  background: var(--bg-panel-solid);
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transition: opacity var(--duration-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}
pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}

/* Typing dots */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: var(--space-2) 0;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

/* ===== Agent Execution Status ===== */
.agent-status-card {
  margin: var(--space-2) 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  animation: msgIn var(--duration-normal) var(--ease-standard);
}
.agent-status-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.agent-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.agent-status-dot.running {
  background: var(--success);
  animation: pulse 1.5s infinite;
}
.agent-status-dot.waiting {
  background: var(--warning);
}
.agent-status-dot.done {
  background: var(--info);
}
.agent-status-dot.failed {
  background: var(--danger);
}
.agent-status-label {
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.agent-status-detail {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding-left: calc(8px + var(--space-2));
}
.agent-status-expand {
  margin-top: var(--space-2);
  padding-left: calc(8px + var(--space-2));
}
.agent-status-expand summary {
  font-size: var(--text-xs);
  color: var(--text-link);
  cursor: pointer;
}
.agent-status-expand summary:hover {
  text-decoration: underline;
}
.agent-status-actions {
  margin-top: var(--space-2);
  display: flex;
  gap: var(--space-2);
}

/* Tool cards */
.tool-card-wrap {
  margin: var(--space-2) 0;
}
.confirm-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  animation: msgIn var(--duration-normal) var(--ease-standard);
}
.confirm-card-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}
.confirm-card-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-3);
}
.confirm-card-params {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.confirm-card-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.confirm-card-actions button {
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: var(--transition-fast);
  min-height: 32px;
}

/* Gen loading */
.gen-loading {
  text-align: center;
  padding: var(--space-5);
}
.gen-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--space-3);
}
.gen-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.gen-progress {
  margin-top: var(--space-2);
  height: 2px;
  background: var(--border-soft);
  border-radius: 2px;
  overflow: hidden;
}
.gen-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  animation: progress 2s ease-in-out infinite;
}
.img-result {
  max-width: 100%;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.video-player {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* Tool status pulse */
.tool-status-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s infinite;
}

/* Search result in messages */
.search-result {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  margin: var(--space-2) 0;
  transition: var(--transition-fast);
  font-size: var(--text-sm);
}
.search-result:hover {
  border-color: var(--accent-soft);
}

/* ===== Scroll-to-bottom button ===== */
.scroll-bottom-btn {
  position: absolute;
  bottom: var(--space-4);
  right: var(--space-4);
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-soft);
  background: var(--bg-panel-solid);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-panel);
}
.scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: auto;
}
.scroll-bottom-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== Composer (input area) ===== */
.composer-root {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4) calc(var(--space-3) + var(--safe-b));
  background: var(--bg-panel);
  border-top: 1px solid var(--border-soft);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.mode-bar {
  display: flex;
  gap: var(--space-1);
  max-width: var(--max-content-w);
  margin: 0 auto var(--space-2);
  justify-content: center;
}
.mode-btn {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: var(--transition-fast);
  font-weight: var(--weight-medium);
}
.mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(113, 101, 235, 0.2);
}
.mode-btn:hover {
  border-color: var(--accent);
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  max-width: var(--max-content-w);
  margin: 0 auto;
}
.attach-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-soft);
  background: var(--bg-panel-solid);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  flex-shrink: 0;
}
.attach-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
textarea {
  flex: 1;
  min-height: 38px;
  max-height: 200px;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  resize: none;
  outline: none;
  line-height: var(--leading-relaxed);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  overflow-y: auto;
}
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-ring);
}
textarea::placeholder {
  color: var(--text-muted);
}
.send-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  flex-shrink: 0;
}
.send-btn:hover {
  background: var(--accent-hover);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.send-btn.sending {
  background: var(--danger);
  animation: pulse 1.5s infinite;
}
.input-hint {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  max-width: var(--max-content-w);
  margin-left: auto;
  margin-right: auto;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .quick-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .msg.user .msg-body {
    max-width: 88%;
  }
  .chat-inner {
    padding: 0 var(--space-3);
  }
  .welcome-screen {
    padding: var(--space-5) var(--space-3) var(--space-4);
  }
  .welcome-screen h3 {
    font-size: var(--text-xl);
  }
  .workspace-header {
    padding: 0 var(--space-3);
  }
}
@media (hover: none) {
  .msg-actions { opacity: 1; }
}