/* Constellation Writer — Intercom Dark Components */

/* === Buttons (Intercom: sharp 4px, scale hover) === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1.43;
  letter-spacing: 0.01em;
}
.btn:hover {
  background: var(--hover-bg);
  border-color: var(--hover-border);
  transform: scale(1.03);
}
.btn:active {
  transform: scale(0.97);
}
.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: var(--color-on-accent, #fff);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-blue-hover);
  border-color: var(--accent-blue-hover);
  transform: scale(1.05);
}
.btn-success {
  background: rgba(11, 223, 80, 0.12);
  border-color: var(--accent-green);
  color: var(--accent-green);
}
.btn-danger {
  background: rgba(196, 28, 28, 0.12);
  border-color: var(--accent-red);
  color: var(--accent-red);
}
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  padding: 4px 6px;
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--transition-fast);
}
.btn-icon:hover { color: var(--text-primary); }
.btn-icon:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 10px;
  line-height: 1.4;
}
.badge-empty { background: rgba(61,68,85,0.3); color: var(--node-empty); }
.badge-draft { background: rgba(91,156,246,0.15); color: var(--node-draft); }
.badge-review { background: rgba(168,85,247,0.15); color: var(--node-review); }
.badge-final { background: rgba(63,185,80,0.15); color: var(--node-final); }

/* === Status Dot === */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.empty { background: var(--node-empty); }
.status-dot.draft { background: var(--node-draft); }
.status-dot.review { background: var(--node-review); }
.status-dot.final { background: var(--node-final); }

/* === Tabs === */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  gap: 0;
}
.tab {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.tab:hover { color: var(--text-secondary); }
.tab:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}
.tab.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* === Toast === */
.toast-container {
  position: fixed;
  bottom: 40px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s ease;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-blue); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Form === */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast);
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent-blue);
}
.form-textarea {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-sans);
}
.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a6070'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* === Diff View === */
.diff-line {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-add {
  background: var(--diff-add);
  color: var(--accent-green);
}
.diff-remove {
  background: var(--diff-remove);
  color: var(--accent-red);
  text-decoration: line-through;
}

/* === Context Menu === */
.context-menu {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: 900;
  padding: 4px 0;
}
.context-menu-item {
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.context-menu-item:hover {
  background: var(--hover-bg);
}
.context-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* === Cards (Welcome screen — Intercom editorial) === */
.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition-normal);
}
.project-card:hover {
  border-color: var(--accent-blue);
  background: var(--bg-elevated);
  transform: scale(1.02);
}
.project-card .card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin-bottom: 6px;
}
.project-card .card-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}
.project-card .card-preview {
  height: 100px;
  margin-top: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-graph);
  overflow: hidden;
}

/* === Type Cards (New Project — Intercom sharp geometry) === */
.type-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}
.type-card:hover {
  border-color: var(--accent-blue);
  transform: scale(1.04);
}
.type-card.selected {
  border-color: var(--accent-blue);
  background: rgba(255, 86, 0, 0.08);
}
.type-card .type-icon {
  font-size: 28px;
  margin-bottom: 8px;
}
.type-card .type-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin-bottom: 4px;
}
.type-card .type-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* === Progress Bar === */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar .fill,
.progress-bar .progress-fill {
  height: 100%;
  background: var(--accent-blue);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* === Toolbar (Editor) === */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.toolbar-btn {
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 28px;
  text-align: center;
}
.toolbar-btn:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}
.toolbar-btn.active {
  color: var(--accent-blue);
  background: rgba(91, 156, 246, 0.15);
}
.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Jiva selector chips ── */
.jiva-chips {
  display: flex; gap: 4px; padding: 6px 10px;
  overflow-x: visible; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  scrollbar-width: none;
}
.jiva-chips::-webkit-scrollbar { display: none; }
.jiva-chip {
  padding: 3px 10px; border-radius: 12px; font-size: 11px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); cursor: pointer; white-space: nowrap;
  transition: all 0.15s;
}
.jiva-chip.active {
  background: var(--accent-blue); color: #fff; border-color: var(--accent-blue);
}
.jiva-chip:hover:not(.active) { border-color: var(--accent-blue); color: var(--accent-blue); }

/* ── Thinking indicator ── */
.ai-thinking {
  padding: 6px 0; font-size: 12px; color: var(--text-hint);
}
.ai-thinking.hidden { display: none; }
@keyframes thinking-pulse { 0%,80%,100% { opacity: 0.3; } 40% { opacity: 1; } }
.thinking-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent-blue);
  animation: thinking-pulse 1.4s infinite;
  margin-right: 4px;
}

/* ── Chat bubble layout ── */
.ai-msg {
  display: flex;
  flex-direction: row;
  gap: 8px;
  max-width: 92%;
  animation: msg-in 0.2s ease;
  margin-bottom: 4px;
}
.ai-msg.msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.ai-msg.msg-assistant,
.ai-msg.msg-error {
  align-self: flex-start;
}
.ai-msg.msg-system {
  align-self: center;
  max-width: 100%;
}

/* Avatar */
.ai-msg .msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 10px;
  color: #fff;
  margin-top: 16px;
}

/* Body (sender + bubble) */
.ai-msg .msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.ai-msg .msg-sender {
  font-size: 11px; font-weight: 600;
  margin-bottom: 2px; padding: 0 2px;
}
.ai-msg.msg-user .msg-sender {
  text-align: right;
}
.ai-msg .msg-time {
  font-weight: 400;
  font-size: 10px;
  color: var(--text-hint);
  margin-left: 4px;
}
.ai-msg .msg-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.ai-msg.msg-user .msg-bubble {
  background: var(--accent-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.msg-assistant .msg-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.ai-msg.msg-error .msg-bubble {
  background: rgba(239,83,80,0.08);
  border: 1px solid rgba(239,83,80,0.2);
  color: var(--accent-red);
}
.ai-msg.msg-system .msg-bubble {
  background: rgba(0, 117, 222, 0.06);
  border: 1px solid rgba(0, 117, 222, 0.12);
  color: var(--text-secondary);
  font-size: 12px;
  border-radius: 8px;
  padding: 6px 12px;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Markdown inside bubbles (marked.js output) ── */
.ai-msg .msg-bubble p {
  margin: 0 0 6px 0;
}
.ai-msg .msg-bubble p:last-child {
  margin-bottom: 0;
}
.ai-msg .msg-bubble strong { font-weight: 700; }
.ai-msg .msg-bubble em { font-style: italic; }
.ai-msg .msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px; border-radius: 3px;
  font-size: 12px; font-family: var(--font-mono, monospace);
}
.ai-msg .msg-bubble pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 12px;
  line-height: 1.5;
}
.ai-msg .msg-bubble pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  white-space: pre;
}
.ai-msg .msg-bubble h1,
.ai-msg .msg-bubble h2,
.ai-msg .msg-bubble h3 {
  margin: 8px 0 4px 0;
  font-weight: 700;
  line-height: 1.3;
}
.ai-msg .msg-bubble h1 { font-size: 16px; }
.ai-msg .msg-bubble h2 { font-size: 14px; }
.ai-msg .msg-bubble h3 { font-size: 13px; }
.ai-msg .msg-bubble ul,
.ai-msg .msg-bubble ol {
  margin: 4px 0;
  padding-left: 20px;
}
.ai-msg .msg-bubble li {
  margin: 2px 0;
}
.ai-msg .msg-bubble blockquote {
  border-left: 3px solid var(--accent-blue);
  margin: 6px 0;
  padding: 4px 12px;
  color: var(--text-secondary);
  font-style: italic;
}
.ai-msg .msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.ai-msg .msg-bubble th {
  background: var(--bg-elevated);
  padding: 6px 10px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}
.ai-msg .msg-bubble td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
}
.ai-msg .msg-bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}
.ai-msg .msg-bubble a {
  color: var(--accent-blue);
  text-decoration: none;
}
.ai-msg .msg-bubble a:hover {
  text-decoration: underline;
}
/* User bubble: override colors for dark-on-light */
.ai-msg.msg-user .msg-bubble code {
  background: rgba(255,255,255,0.2);
}
.ai-msg.msg-user .msg-bubble a {
  color: #fff;
  text-decoration: underline;
}

/* ── Thinking indicator bubble ── */
.ai-thinking-wrap {
  align-self: flex-start;
  max-width: 70%;
}
.ai-thinking-wrap .msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-hint);
}

/* ── Workflow collapsible ── */
.workflow-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; cursor: pointer; user-select: none;
  font-size: 11px; color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.5px; font-weight: 600;
}
.workflow-toggle:hover { color: var(--text-secondary); }
.wf-arrow {
  transition: transform 0.2s; font-size: 10px;
}
.wf-arrow.collapsed { transform: rotate(-90deg); }
.workflow-body {
  overflow: hidden;
  transition: max-height 0.3s ease;
  max-height: 500px;
}
.workflow-body.collapsed {
  max-height: 0 !important;
  padding: 0;
  margin: 0;
}

/* ── Workflow progress indicator ── */
.wf-progress {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; font-size: 11px;
  color: var(--text-secondary);
}
.wf-progress-bar {
  flex: 1; height: 4px; border-radius: 2px;
  background: var(--border-light, rgba(0,0,0,0.06));
  overflow: hidden;
}
.wf-progress-fill {
  height: 100%; border-radius: 2px;
  background: var(--accent-blue);
  transition: width 0.5s ease;
}
.wf-step-status {
  font-size: 10px; color: var(--text-hint);
  white-space: nowrap;
}

/* ── User Badge ── */
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all 0.2s;
  position: absolute;
  top: 1.5rem;
  right: 2rem;
}
.user-badge:hover {
  background: var(--hover-bg);
  border-color: var(--hover-border);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #58a6ff 0%, #bc8cff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
}
.user-name {
  font-size: 0.85rem;
  color: var(--text-primary, #e6edf3);
  white-space: nowrap;
}
.user-logout {
  font-size: 0.75rem;
  color: var(--text-muted, #8b949e);
  opacity: 0;
  transition: opacity 0.2s;
  margin-left: 0.2rem;
}
.user-badge:hover .user-logout {
  opacity: 1;
}
/* Smaller variant for workspace topbar */
.user-badge-sm {
  position: static;
  padding: 0.25rem 0.6rem;
  gap: 0.4rem;
}
.user-badge-sm .user-avatar {
  width: 22px;
  height: 22px;
  font-size: 0.75rem;
}
.user-badge-sm .user-name {
  font-size: 0.8rem;
}


/* ===== Floating AI Chat Widget ===== */
.ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ai-fab:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-lg);
}
.ai-fab:active {
  transform: scale(0.95);
}

.ai-float-modal {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 400px;
  min-width: 300px;
  min-height: 300px;
  max-height: calc(100vh - 120px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: float-in 0.2s ease;
  resize: both;
  overflow: auto;
}
@keyframes float-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-float-modal.hidden {
  display: none;
}
.ai-float-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}
.ai-float-header:active { cursor: grabbing; }
.ai-float-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}
.ai-float-modal .workflow-controls {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-light);
}
.ai-float-modal .jiva-chips {
  flex-shrink: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
}
.jiva-more-toggle {
  background: transparent !important;
  border-color: var(--border) !important;
  color: var(--text-tertiary) !important;
  font-size: 11px !important;
}
.jiva-more {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  padding-top: 6px;
}
.jiva-more.hidden { display: none; }
.ai-float-modal .ai-draft-area {
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
}
.ai-float-modal .ai-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 150px;
  max-height: 400px;
  padding: 10px 12px;
}
.ai-float-modal .ai-input-row {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}
.ai-float-modal .ai-input-field {
  flex: 1;
  min-height: 36px;
  max-height: 100px;
  resize: none;
}

/* Mobile: full-width modal */
@media (max-width: 640px) {
  .ai-float-modal {
    right: 8px;
    left: 8px;
    bottom: 80px;
    width: auto;
    max-height: calc(100vh - 100px);
  }
  .ai-fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}
