/* ========================================
   Layout Primitives
   ======================================== */

.public-home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
}

.card {
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.stack {
  display: grid;
  gap: var(--space-4);
}

.split {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
}

.list {
  display: grid;
  gap: var(--space-2);
}

.list-item {
  display: grid;
  gap: var(--space-2);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  padding: var(--space-4);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast);
}

.list-item:hover {
  border-color: var(--color-border-focus);
  background: var(--color-surface-hover);
}

.list-item.active {
  border-color: var(--color-accent);
  box-shadow: inset 2px 0 0 var(--color-accent);
}

/* Header pills (form selector in header) */
.header-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--border-radius-pill);
  border: var(--border-thin);
  background: var(--color-surface);
  font-size: var(--text-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.header-pill:hover {
  border-color: var(--color-border-focus);
  background: var(--color-surface-hover);
}

.header-pill.active {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.header-pill .pill-title {
  font-weight: var(--weight-medium);
}

/* Column toggle buttons */
.toggle-col {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--border-radius-pill);
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.toggle-col:hover {
  color: var(--color-text);
}

.toggle-col[data-col="chat"] {
  color: var(--col-chat-accent);
  border-color: color-mix(in srgb, var(--col-chat-accent) 30%, transparent);
}

.toggle-col[data-col="builder"] {
  color: var(--col-builder-accent);
  border-color: color-mix(in srgb, var(--col-builder-accent) 30%, transparent);
}

.toggle-col[data-col="preview"] {
  color: var(--col-preview-accent);
  border-color: color-mix(in srgb, var(--col-preview-accent) 30%, transparent);
}

.toggle-col.focused {
  color: #ffffff;
}

.toggle-col[data-col="chat"].focused {
  background: var(--col-chat-accent);
  border-color: var(--col-chat-accent);
}

.toggle-col[data-col="chat"].focused:hover {
  background: #2563eb;
}

.toggle-col[data-col="builder"].focused {
  background: var(--col-builder-accent);
  border-color: var(--col-builder-accent);
}

.toggle-col[data-col="builder"].focused:hover {
  background: #d97706;
}

.toggle-col[data-col="preview"].focused {
  background: var(--col-preview-accent);
  border-color: var(--col-preview-accent);
}

.toggle-col[data-col="preview"].focused:hover {
  background: #15803d;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* ========================================
   Badges
   ======================================== */

.badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-pill);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.published {
  color: var(--color-positive);
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.badge.draft {
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.badge.archived {
  color: var(--color-text-muted);
  background: var(--color-info-bg);
}

.badge.official {
  color: var(--color-positive);
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

/* ========================================
   Buttons
   ======================================== */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: fit-content;
  min-height: 36px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: 999px;
  background: var(--color-accent);
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    opacity var(--transition-fast),
    transform var(--transition-fast);
  user-select: none;
}

.button:hover {
  background: var(--color-accent-hover);
}

.button:active {
  transform: scale(0.98);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.button.secondary {
  background: transparent;
  color: var(--color-text);
  border: var(--border-thin);
}

.button.secondary:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-border-focus);
}

.button.danger {
  background: transparent;
  color: var(--color-negative);
  border: 1px solid var(--color-negative-border);
}

.button.danger:hover {
  background: var(--color-negative-bg);
}

.button.sm {
  min-height: 28px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.button svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

/* Loading spinner inside button */
.button .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}

.button.secondary .spinner {
  border-color: rgba(17, 17, 17, 0.15);
  border-top-color: var(--color-text);
}

/* ========================================
   Inputs
   ======================================== */

.input,
.textarea,
.select {
  width: 100%;
  min-height: 38px;
  border: var(--border-thin);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-text);
  padding: 0 var(--space-4);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--color-text-muted);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-muted);
}

.textarea {
  min-height: 100px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: var(--space-8);
}

.code-input {
  width: 100%;
  min-height: 200px;
  border: var(--border-thin);
  border-radius: 20px;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  resize: vertical;
  background: var(--color-info-bg);
  transition: border-color var(--transition-fast);
}

.code-input:focus {
  border-color: var(--color-border-focus);
  outline: none;
}

.field {
  display: grid;
  gap: var(--space-2);
}

.field label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

/* Inline field error state */
.field-has-error .input,
.field-has-error .textarea,
.field-has-error .select {
  border-color: var(--color-negative);
}

.field-has-error .input:focus,
.field-has-error .textarea:focus,
.field-has-error .select:focus {
  box-shadow: 0 0 0 2px var(--color-negative-bg);
}

.field-error-message {
  color: var(--color-negative);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* ========================================
   Error & Empty States
   ======================================== */

.error-box {
  border: 1px solid var(--color-negative-border);
  border-radius: var(--border-radius-sm);
  background: var(--color-negative-bg);
  color: var(--color-negative);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
}

.empty-state {
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  padding: var(--space-6);
  text-align: center;
  font-size: var(--text-sm);
}

/* ========================================
   Eyebrow & Text Utils
   ======================================== */

.eyebrow {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  color: var(--color-text-secondary);
}

.section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

/* ========================================
   Field Editor
   ======================================== */

.field-editor-list {
  display: grid;
  gap: var(--space-3);
}

.field-editor-item {
  display: grid;
  gap: 0;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  transition: border-color var(--transition-fast);
  overflow: hidden;
}

.field-editor-item:hover {
  border-color: var(--color-text-muted);
}

.inline-proposal {
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: flex-start;
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-2);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--border-radius-sm);
  background: rgba(245, 158, 11, 0.08);
}

.inline-proposal-main {
  min-width: 0;
}

.inline-proposal-actions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* Row 1: Label, Type, Actions */
.field-editor-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(110px, 160px) auto;
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-3);
}

/* Config toggle button */
.field-config-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-1) var(--space-3);
  border: 0;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-info-bg);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-align: left;
}

.field-config-toggle:hover {
  background: var(--color-surface-hover);
  color: var(--color-text-secondary);
}

.field-config-toggle .config-chevron {
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.field-config-toggle.open .config-chevron {
  transform: rotate(90deg);
}

.field-config-toggle .config-hint {
  margin-left: auto;
  opacity: 0.7;
  font-weight: var(--weight-normal);
}

/* Config panel */
.field-config-panel {
  display: none;
  padding: var(--space-3);
  border-top: 1px solid var(--color-border-light);
  background: var(--color-info-bg);
  animation: fadeIn 0.15s ease;
}

.field-config-panel.open {
  display: block;
}

.field-config-panel .field {
  margin-bottom: var(--space-3);
}

.field-config-panel .field:last-child {
  margin-bottom: 0;
}

.field-config-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: var(--space-3);
}

/* Options editor */
.option-editor-list {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.option-editor-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
}

.option-editor-row .input {
  min-height: 30px;
  font-size: var(--text-xs);
  padding: 0 var(--space-3);
  border-radius: var(--border-radius-pill);
}

.option-editor-row .button {
  min-height: 24px;
  min-width: 24px;
  padding: 0;
  font-size: var(--text-xs);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.option-editor-empty {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  padding: var(--space-2);
  text-align: center;
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-sm);
}

.option-add-btn {
  font-size: var(--text-xs);
}

/* Config small inputs */
.field-config-panel .input-sm {
  min-height: 30px;
  font-size: var(--text-xs);
  padding: 0 var(--space-3);
  border-radius: var(--border-radius-pill);
}

.field-config-panel .textarea-sm {
  min-height: 60px;
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  border-radius: 10px;
  resize: vertical;
}

.field-config-panel label {
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ========================================
   AI Chat
   ======================================== */

.chat-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  height: 100%;
  min-height: 0;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  padding: var(--space-2) 0;
}

.chat-message {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
  border-radius: 20px;
  max-width: 85%;
  animation: fadeInUp var(--transition-slow) ease;
}

.chat-message.user {
  background: var(--color-accent);
  color: #ffffff;
  margin-left: auto;
  border-bottom-right-radius: 6px;
}

.chat-message.assistant {
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--border-thin);
  margin-right: auto;
  border-bottom-left-radius: 6px;
}

.chat-message .chat-role {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.6;
  margin-bottom: var(--space-1);
}

.chat-message.user .chat-role {
  color: rgba(255, 255, 255, 0.7);
}

/* AI thinking indicator */
.chat-thinking {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  max-width: 85%;
  animation: fadeInUp var(--transition-slow) ease;
}

.chat-thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.chat-thinking span:nth-child(2) {
  animation-delay: 0.2s;
}
.chat-thinking span:nth-child(3) {
  animation-delay: 0.4s;
}

.chat-input-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  padding-top: var(--space-2);
  border-top: var(--border-thin);
}

.chat-input-row .textarea {
  min-height: 38px;
  max-height: 120px;
}

/* Chat toolbar */
.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

/* ========================================
   Diff View
   ======================================== */

.diff-list {
  display: grid;
  gap: var(--space-2);
}

.diff-item {
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-3);
  animation: fadeInUp var(--transition-slow) ease;
}

.diff-item.add_field {
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.diff-item.update_field,
.diff-item.update_form {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.diff-item.remove_field {
  background: var(--color-negative-bg);
  border-color: var(--color-negative-border);
}

.diff-item.reorder_fields {
  background: var(--color-info-bg);
  border-color: var(--color-info-border);
}

.diff-item.add_section {
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.diff-item.update_section,
.diff-item.update_submission_page {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.diff-item.remove_section {
  background: var(--color-negative-bg);
  border-color: var(--color-negative-border);
}

.diff-item pre {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-x: auto;
  padding: var(--space-2);
  background: rgba(255, 255, 255, 0.5);
  border-radius: var(--border-radius-sm);
}

/* ========================================
   Form Preview
   ======================================== */

.form-preview {
  flex: 1;
  min-height: 0;
  padding: var(--space-4);
  position: relative;
  height: 100%;
  overflow-y: auto;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
  background: var(--color-surface);
  flex-shrink: 0;
}

.preview-live-url {
  display: grid;
  min-width: 0;
  gap: var(--space-1);
}

.preview-live-url .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Device toggle (form preview) */
.device-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--color-bg);
  border-radius: var(--border-radius-pill);
  padding: 2px;
  border: var(--border-thin);
}

.device-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-pill);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1;
}

.device-toggle button:hover {
  color: var(--color-text);
}

.device-toggle button.active {
  background: var(--color-surface);
  color: var(--col-preview-accent);
  box-shadow: var(--shadow-sm);
}

.device-toggle button svg {
  flex-shrink: 0;
}

/* Form preview frame (device width constraint) */
.form-preview-frame {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}

.form-preview-frame .form-preview {
  width: 100%;
  transition: max-width 0.3s ease;
}

.form-preview-frame.device-desktop .form-preview {
  max-width: var(--preview-width-desktop);
}

.form-preview-frame.device-tablet .form-preview {
  max-width: var(--preview-width-tablet);
}

.form-preview-frame.device-mobile .form-preview {
  max-width: var(--preview-width-mobile);
}

/* ========================================
   Modern Form Renderer (rf-*)
   ======================================== */

.rendered-form.rf-modern {
  display: grid;
  gap: 0;
}

/* Hero image */
.rf-hero {
  width: 100%;
  max-height: 200px;
  overflow: hidden;
  border-radius: 12px;
  margin-bottom: var(--space-5);
}

.rf-hero-img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

/* Form header */
.rf-form-header {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 2px solid var(--color-border-light);
}

.rf-form-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.rf-form-desc {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.6;
}

/* Sections */
.rf-section {
  margin-bottom: var(--space-6);
}

.rf-section-header {
  margin-bottom: var(--space-5);
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-accent);
}

.rf-section-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.rf-section-desc {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

.rf-section-fields {
  display: grid;
  gap: var(--space-5);
}

.rf-section-empty {
  text-align: center;
  padding: var(--space-4);
}

/* Section divider (old section field type) */
.rendered-section-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.section-divider-line {
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.section-divider-text {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Markdown block */
.rendered-markdown {
  padding: var(--space-4);
  background: var(--color-info-bg);
  border-radius: var(--border-radius-lg);
  border-left: 3px solid var(--color-border);
}

.markdown-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.markdown-body {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-top: var(--space-1);
}

/* ---- Field base ---- */
.rendered-field,
.choice-field,
.structured-field {
  display: grid;
  gap: var(--space-2);
}

.field-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.field-label-sm {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}

.field-required {
  color: var(--color-negative);
}

.form-help {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}

/* ---- Modern inputs ---- */
.rf-input,
.rf-textarea,
.rf-select {
  width: 100%;
  min-height: 44px;
  border: 1.5px solid var(--color-border);
  border-radius: 25px;
  background: var(--color-surface);
  color: var(--color-text);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}

.rf-input:hover,
.rf-textarea:hover,
.rf-select:hover {
  border-color: var(--color-text-muted);
}

.rf-input:focus,
.rf-textarea:focus,
.rf-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle), 0 1px 3px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.rf-input::placeholder,
.rf-textarea::placeholder {
  color: var(--color-text-muted);
}

.rf-textarea {
  min-height: 100px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
  border-radius: 14px;
}

.rf-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: var(--space-8);
  cursor: pointer;
}

/* Number input with prefix/suffix */
.input-affix-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.input-affix-wrap:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.input-prefix,
.input-suffix {
  padding: 0 var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--color-info-bg);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.input-affix-wrap .rf-input {
  border: 0;
  border-radius: 0;
  min-height: 42px;
}

.input-affix-wrap .rf-input:focus {
  box-shadow: none;
  transform: none;
}

/* ---- Choice fields (radio/checkbox) ---- */
.choice-options {
  display: grid;
  gap: var(--space-2);
}

.choice-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--color-border-light);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--color-surface);
}

.choice-option:hover {
  border-color: var(--color-text-muted);
  background: var(--color-surface-hover);
}

.choice-option:has(input:checked) {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.choice-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.choice-indicator {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  transition: all 0.15s ease;
}

/* Checkbox indicator = square */
.choice-option:has(input[type="checkbox"]) .choice-indicator {
  border-radius: 5px;
}

.choice-option:has(input:checked) .choice-indicator {
  border-color: var(--color-accent);
  background: var(--color-accent);
}

.choice-option:has(input:checked) .choice-indicator::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Radio: inner dot */
.choice-option:has(input[type="radio"]:checked) .choice-indicator::after {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

/* Checkbox: checkmark */
.choice-option:has(input[type="checkbox"]:checked) .choice-indicator::after {
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}

.choice-text {
  font-size: var(--text-sm);
  color: var(--color-text);
}

/* ---- Toggle switch ---- */
.toggle-switch-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  padding: var(--space-3) 0;
}

.toggle-switch-wrap {
  position: relative;
  flex-shrink: 0;
}

.toggle-switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch-track {
  display: block;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--color-border);
  position: relative;
  transition: background 0.2s ease;
}

.toggle-switch-input:checked + .toggle-switch-track {
  background: var(--color-positive);
}

.toggle-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.toggle-switch-input:checked + .toggle-switch-track .toggle-switch-thumb {
  transform: translateX(20px);
}

.toggle-switch-label {
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.4;
}

/* ---- Star rating ---- */
.rating-field {
  gap: var(--space-2);
}

.star-rating {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 2px;
}

.star-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.star-label {
  cursor: pointer;
  color: var(--color-border);
  transition: color 0.1s ease, transform 0.1s ease;
}

.star-label:hover,
.star-label:hover ~ .star-label {
  color: #facc15;
  transform: scale(1.1);
}

.star-input:checked ~ .star-label {
  color: #facc15;
}

.star-label svg {
  display: block;
}

/* ---- Slider ---- */
.slider-field {
  gap: var(--space-2);
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.slider-bound {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  min-width: 2ch;
  text-align: center;
}

.slider-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  text-align: center;
}

.rf-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--color-border-light);
  outline: none;
  transition: background 0.2s;
}

.rf-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rf-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.rf-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 0;
}

/* ---- File upload zone ---- */
.upload-zone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: 14px;
  padding: var(--space-8) var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--color-surface);
}

.upload-zone:hover,
.upload-zone:focus-within {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.upload-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
}

.upload-zone-content svg {
  color: var(--color-text-muted);
}

.upload-zone-text {
  font-size: var(--text-sm);
}

.upload-zone-link {
  color: var(--color-accent);
  font-weight: var(--weight-medium);
  text-decoration: underline;
}

.upload-zone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---- Structured fields (address, name, date_range, location) ---- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.field-grid-item {
  display: grid;
}

/* ---- Complex field placeholder ---- */
.complex-field {
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* ---- Error state ---- */
.field-has-error .rf-input,
.field-has-error .rf-textarea,
.field-has-error .rf-select {
  border-color: var(--color-negative);
}

.field-has-error .rf-input:focus,
.field-has-error .rf-textarea:focus,
.field-has-error .rf-select:focus {
  box-shadow: 0 0 0 3px var(--color-negative-bg);
}

/* ========================================
   Slides Mode
   ======================================== */

.rf-slides-body {
  display: grid;
  gap: 0;
}

.rf-slides-container {
  display: flex;
  flex-direction: column;
}

.rf-slide {
  display: none;
  flex-direction: column;
}

.rf-slide-active {
  display: flex;
  animation: rfSlideIn 0.3s ease forwards;
}

@keyframes rfSlideIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Progress */
.rf-progress {
  margin-bottom: var(--space-5);
  display: grid;
  gap: var(--space-3);
}

.rf-progress-bar {
  height: 4px;
  background: var(--color-border-light);
  border-radius: 2px;
  overflow: hidden;
}

.rf-progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.rf-dots {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
}

.rf-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 0;
  background: var(--color-border);
  padding: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.rf-dot-active {
  background: var(--color-accent);
  transform: scale(1.3);
}

/* Navigation */
.rf-slides-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: var(--border-thin);
}

.rf-slide-counter {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.rf-nav-row {
  display: flex;
  gap: var(--space-2);
}

.rf-nav-btn {
  min-height: 36px;
  font-size: var(--text-sm);
}

/* ========================================
   Success Page
   ======================================== */

.rf-success-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-10) var(--space-6);
  animation: fadeInUp 0.4s ease;
  gap: var(--space-4);
}

.rf-success-icon {
  width: 56px;
  height: 56px;
  color: var(--color-positive);
  animation: rfSuccessPop 0.5s ease;
}

.rf-success-icon svg {
  width: 100%;
  height: 100%;
}

@keyframes rfSuccessPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.rf-success-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.rf-success-message {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
}

/* ========================================
   Preview Submit Button
   ======================================== */

.rf-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--color-accent);
  color: #fff;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: var(--space-4);
}

.rf-submit-btn:hover {
  background: var(--color-accent-hover);
}

.rf-submit-btn:active {
  transform: scale(0.98);
}

/* Legacy compat */
.choice-option-legacy,
.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  cursor: pointer;
}

/* ========================================
   Section Editor in Builder
   ======================================== */

#sections-editor {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.title-field-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  border: 1.5px solid var(--color-border-light);
  border-radius: 12px;
  background: var(--color-surface);
}
.title-field-picker label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
}
.title-field-picker .title-field-hint {
  font-size: var(--text-xs);
  margin: 0;
}

.section-editor-group {
  border: 1.5px solid var(--color-border-light);
  border-radius: 12px;
  background: var(--color-surface);
  overflow: hidden;
}

.section-editor-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-info-bg);
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  user-select: none;
}

.section-editor-header:hover {
  background: var(--color-surface-hover);
}

.section-editor-title-input {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  outline: none;
  padding: var(--space-1) var(--space-2);
  border-radius: 4px;
  transition: background 0.15s;
}

.section-editor-title-input:focus {
  background: var(--color-surface);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.section-editor-body {
  padding: var(--space-4);
}

.section-editor-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.section-editor-badge {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Display mode toggle */
.display-mode-toggle {
  display: inline-flex;
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  overflow: hidden;
}

.display-mode-option {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.display-mode-option.active {
  background: var(--color-accent);
  color: #fff;
}

/* Submission page editor */
.submission-page-editor {
  border: 1.5px solid var(--color-border-light);
  border-radius: 12px;
  padding: var(--space-4);
  background: var(--color-positive-bg);
  display: grid;
  gap: var(--space-3);
}

.submission-page-editor .field label {
  font-size: var(--text-xs);
}

/* ========================================
   Auth
   ======================================== */

/* Full-viewport auth page */
#auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: var(--space-6);
}

.auth-page-inner {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
}

.auth-brand__logo {
  width: 80px;
  height: 80px;
  position: relative;
  flex-shrink: 0;
}
.auth-brand__logo::before,
.auth-brand__logo > span {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.auth-brand__logo::before {
  width: 100%;
  height: 100%;
  background: #2C3E55;
}
.auth-brand__logo > span:nth-child(1) {
  width: 90%;
  height: 90%;
  background: #355070;
  transform: translate(calc(-50% + 2.5px), calc(-50% + 2.5px));
}
.auth-brand__logo > span:nth-child(2) {
  width: 80%;
  height: 80%;
  background: #406890;
  transform: translate(calc(-50% + 5px), calc(-50% + 5px));
}
.auth-brand__logo > span:nth-child(3) {
  width: 68%;
  height: 68%;
  background: #5080AC;
  transform: translate(calc(-50% + 7.5px), calc(-50% + 7.5px));
}
.auth-brand__logo > span:nth-child(4) {
  width: 56%;
  height: 56%;
  background: #6A95BE;
  transform: translate(calc(-50% + 10px), calc(-50% + 10px));
}
.auth-brand__logo > span:nth-child(5) {
  width: 44%;
  height: 44%;
  background: #84AAD0;
  transform: translate(calc(-50% + 12.5px), calc(-50% + 12.5px));
}
.auth-brand__logo > span:nth-child(6) {
  width: 34%;
  height: 34%;
  background: #9DBDDF;
  transform: translate(calc(-50% + 15px), calc(-50% + 15px));
}
.auth-brand__logo > span:nth-child(7) {
  width: 24%;
  height: 24%;
  background: #B5D0EC;
  transform: translate(calc(-50% + 17.5px), calc(-50% + 17.5px));
}

.auth-brand__name {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
}

.auth-brand__slogan {
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--color-text-muted, var(--color-text));
  opacity: 0.7;
}

.auth-card {
  width: 100%;
}

.auth-card h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

.auth-toggle {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.auth-toggle a {
  color: var(--color-accent);
  font-weight: var(--weight-medium);
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border, #e0e0e0);
}

/* ========================================
   Placeholder Panels (upcoming pages)
   ======================================== */

.placeholder-panel {
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  background: var(--color-surface);
  padding: var(--space-8);
  animation: fadeIn var(--transition-slow) ease;
}

/* Placeholder stat cards grid */
.placeholder-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}

.placeholder-stat-card {
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-5);
  display: grid;
  gap: var(--space-2);
  text-align: center;
}

.placeholder-stat-card .stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-text-muted);
  letter-spacing: -0.03em;
}

.placeholder-stat-card .stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Placeholder table skeleton */
.placeholder-table {
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
}

.placeholder-table-header {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--color-border-light);
  padding: var(--space-3) var(--space-4);
}

.placeholder-table-header span {
  height: 12px;
  background: var(--color-border);
  border-radius: 2px;
  animation: pulse 1.5s ease-in-out infinite;
}

.placeholder-table-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-light);
}

.placeholder-table-row span {
  height: 10px;
  background: var(--color-border-light);
  border-radius: 2px;
}

/* Placeholder chart skeleton */
.placeholder-chart {
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-6);
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  height: 200px;
}

.placeholder-chart-bar {
  flex: 1;
  background: var(--color-border-light);
  border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Dashboard analytics charts (stacked + single-color bars). */
.stacked-chart {
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4) var(--space-3);
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 180px;
  background: var(--color-surface);
}

.chart-bar {
  flex: 1;
  min-width: 2px;
  height: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  border-radius: 2px;
  overflow: hidden;
  transition: opacity var(--transition-fast, 0.12s) ease;
}

.chart-bar:hover {
  opacity: 0.7;
}

.chart-bar-seg {
  display: block;
  width: 100%;
}

.chart-legend {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.activity-type {
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

/* Settings skeleton */
.placeholder-settings-group {
  display: grid;
  gap: var(--space-4);
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-5);
}

.placeholder-settings-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--space-4);
  align-items: center;
}

.placeholder-settings-row .skel-label {
  height: 12px;
  width: 80%;
  background: var(--color-border);
  border-radius: 2px;
}

.placeholder-settings-row .skel-input {
  height: 36px;
  background: var(--color-border-light);
  border-radius: var(--border-radius-sm);
}

.settings-url-preview {
  display: block;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-info-bg);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 280px;
  max-width: 420px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: toastIn var(--transition-slow) ease;
  transition: opacity var(--transition-base), transform var(--transition-base);
}

.toast.toast-exit {
  opacity: 0;
  transform: translateX(12px);
}

.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.toast.success {
  border-left: 3px solid var(--color-positive);
}

.toast.success .toast-icon {
  color: var(--color-positive);
}

.toast.error {
  border-left: 3px solid var(--color-negative);
}

.toast.error .toast-icon {
  color: var(--color-negative);
}

.toast.info {
  border-left: 3px solid var(--color-text-muted);
}

.toast-message {
  flex: 1;
}

.toast-dismiss {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.toast-dismiss:hover {
  color: var(--color-text);
}

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

/* ========================================
   Modal
   ======================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn var(--transition-fast) ease;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(100%, 440px);
  padding: var(--space-6);
  display: grid;
  gap: var(--space-4);
  animation: modalIn var(--transition-slow) ease;
}

.modal h3 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

.modal p {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.modal .button-row {
  justify-content: flex-end;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ========================================
   Schedule editor
   ======================================== */

.schedule-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle, rgba(0, 0, 0, 0.02));
}

.schedule-editor .sched-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
}

.schedule-editor .sched-days {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.schedule-editor .sched-day {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  user-select: none;
}

.schedule-editor .sched-day:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft, rgba(99, 102, 241, 0.1));
}

.schedule-editor .sched-summary {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
}

/* ========================================
   Record detail viewer
   ======================================== */

.record-view {
  margin: 0;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.record-view-row {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.record-view-row:last-child {
  border-bottom: none;
}

.record-view-row dt {
  margin: 0;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.record-view-row dd {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.record-view-meta {
  margin: var(--space-3) 0 0;
  font-size: var(--text-sm);
}

/* ========================================
   Loading Spinner
   ======================================== */

.spinner-inline {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
  display: inline-block;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-border-light) 25%,
    var(--color-bg) 50%,
    var(--color-border-light) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--border-radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ========================================
   Details / Collapsible
   ======================================== */

details.collapsible {
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
}

details.collapsible summary {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: color var(--transition-fast);
}

details.collapsible summary:hover {
  color: var(--color-text);
}

details.collapsible summary::marker,
details.collapsible summary::-webkit-details-marker {
  display: none;
}

details.collapsible summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

details.collapsible[open] summary::before {
  transform: rotate(90deg);
}

details.collapsible .collapsible-content {
  padding: 0 var(--space-4) var(--space-4);
}

/* ========================================
   Proposed Changes Overlay
   ======================================== */

.changes-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  animation: fadeIn var(--transition-fast) ease;
  overflow: hidden;
}

.changes-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-thin);
  flex-shrink: 0;
}

.changes-overlay-header h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.changes-overlay-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
  display: grid;
  gap: var(--space-3);
  align-content: start;
  scrollbar-width: thin;
}

.changes-overlay-footer {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: var(--border-thin);
  flex-shrink: 0;
}

.change-item {
  border: var(--border-thin);
  border-radius: 12px;
  padding: var(--space-3) var(--space-4);
  display: grid;
  gap: var(--space-2);
  animation: fadeInUp var(--transition-slow) ease;
}

.change-item.add_field {
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.change-item.update_field,
.change-item.update_form {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.change-item.remove_field {
  background: var(--color-negative-bg);
  border-color: var(--color-negative-border);
}

.change-item.reorder_fields {
  background: var(--color-info-bg);
  border-color: var(--color-info-border);
}

.change-item.stale {
  opacity: 0.6;
  border-style: dashed;
}

.change-item.accepted {
  opacity: 0.5;
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.change-item.rejected {
  opacity: 0.4;
  text-decoration: line-through;
}

.change-item pre {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-x: auto;
  padding: var(--space-2);
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
}

.change-detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-xs);
  line-height: 1.5;
}

.change-prop {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
}

.change-label {
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  flex-shrink: 0;
}

.change-detail code {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
}

.change-item .change-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.change-item .stale-warning {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-warning);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* Show proposed changes button on assistant messages */
.btn-show-changes {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: var(--border-thin);
  border-radius: 999px;
  background: var(--color-accent-subtle);
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-show-changes:hover {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
}

.btn-show-changes .changes-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-1);
  border-radius: 999px;
  background: var(--color-accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: var(--weight-bold);
}

.btn-show-changes:hover .changes-count {
  background: #ffffff;
  color: var(--color-accent);
}

/* Changes status indicators on message */
.changes-status {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.changes-status .accepted-count {
  color: var(--color-positive);
}

.changes-status .rejected-count {
  color: var(--color-negative);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }

  .field-editor-item,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .placeholder-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .placeholder-settings-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .placeholder-stats {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   Tables Page (Records)
   ======================================== */

.tables-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6);
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Form cards grid */
.data-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.data-form-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  font: inherit;
  color: var(--color-text);
}

.data-form-card:hover {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.data-form-card.skeleton-card {
  pointer-events: none;
}

/* Pipeline card canvas snapshot thumbnail. */
.pipeline-grid-card {
  gap: var(--space-2);
  padding-top: var(--space-3);
}

.pipeline-card-thumb {
  background: var(--color-surface-hover, var(--color-bg));
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-1);
}

.pipeline-thumb-svg {
  display: block;
  width: 100%;
  height: 90px;
}

.data-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.data-card-title {
  font-weight: 600;
  font-size: var(--text-base);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-card-desc {
  font-size: var(--text-sm);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.data-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.data-card-submeta {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  gap: var(--space-1);
}

.record-count {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-sm);
}

/* Records table header */
.records-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.records-back-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.records-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
}

.records-count {
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* Records table */
.records-table-wrapper {
  overflow-x: auto;
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  background: var(--color-surface);
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.records-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  border-bottom: var(--border-thin);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.records-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records-table tbody tr:last-child td {
  border-bottom: none;
}

.records-table tbody tr:hover {
  background: var(--color-surface-hover);
}

.records-date {
  white-space: nowrap;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* Pagination */
.records-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Loading skeleton cards */
.skeleton-card .skel-line {
  height: 14px;
  border-radius: var(--border-radius-sm);
}

.skeleton-card .skel-line.short {
  width: 30%;
}
.skeleton-card .skel-line.medium {
  width: 60%;
}
.skeleton-card .skel-line.long {
  width: 80%;
}

.records-table-loading {
  padding: var(--space-4);
}

@media (max-width: 640px) {
  .data-cards-grid {
    grid-template-columns: 1fr;
  }
  .records-header {
    flex-wrap: wrap;
  }
}

/* ========================================
   Table Card Grid (tables landing page)
   ======================================== */

.table-cards-page {
  padding: var(--space-6);
  /* max-width: 1200px; */
  margin: 0 auto;
  width: 100%;
}

.table-cards-page .data-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.table-card-stat {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-sm);
}

/* ========================================
   Airtable-style Table Grid
   ======================================== */

.table-grid-container {
  overflow-x: auto;
  border: var(--border-thin);
  background: var(--color-surface);
  min-height: 300px;
}

.table-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  table-layout: fixed;
}

.table-grid th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  border-bottom: var(--border-thin);
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
  min-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-grid th:last-child {
  border-right: none;
}

.table-grid th.system-field-col,
.table-grid td.system-field-col {
  background: color-mix(in srgb, var(--color-surface-hover) 55%, transparent);
}

.table-grid th .field-type-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface);
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: var(--space-1);
  text-transform: lowercase;
  letter-spacing: normal;
}

.table-grid td {
  padding: 0;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  position: relative;
  vertical-align: top;
  overflow: hidden;
}

.table-grid td:last-child {
  border-right: none;
}

.table-grid tbody tr:last-child td {
  border-bottom: none;
}

.table-grid tbody tr:hover {
  background: var(--color-surface-hover);
}

/* Cell content display */
.table-grid-cell {
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  display: flex;
  align-items: center;
  cursor: text;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-grid-cell--empty {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: var(--text-xs);
}

.table-grid-cell--readonly {
  cursor: default;
  color: var(--color-text-muted);
}

/* Cell editing */
.table-grid-cell--editing {
  padding: 0;
}

.table-grid-cell--editing input,
.table-grid-cell--editing select,
.table-grid-cell--editing textarea {
  width: 100%;
  border: none;
  outline: none;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  background: var(--color-accent-light, rgba(59, 130, 246, 0.05));
  min-height: 36px;
  box-sizing: border-box;
}

.table-grid-cell--editing textarea {
  resize: vertical;
  min-height: 60px;
}

.table-grid-cell--editing input:focus,
.table-grid-cell--editing select:focus,
.table-grid-cell--editing textarea:focus {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

/* Checkbox cell */
.table-grid-cell input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Row actions column */
.table-grid th.row-actions-col,
.table-grid td.row-actions-col {
  width: 64px;
  min-width: 64px;
  max-width: 64px;
  text-align: center;
  border-right: 1px solid var(--color-border);
}

.table-grid th.row-select-col,
.table-grid td.row-select-col {
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  text-align: center;
  vertical-align: middle;
}

.table-grid td.row-select-col {
  padding: var(--space-2) 0;
}

.table-grid th.row-select-col input,
.table-grid td.row-select-col input {
  cursor: pointer;
}

/* Column resize handle */
.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 2;
  user-select: none;
  -webkit-user-select: none;
}

.col-resize-handle:hover,
.col-resize-handle--active {
  background: var(--color-accent, #3b82f6);
  opacity: 0.5;
}

.table-grid--resizing {
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
}

.table-grid-row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-muted);
  opacity: 0.65;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
}

.table-grid tbody tr:hover .table-grid-row-action {
  opacity: 1;
}

.table-grid-row-action:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.table-grid-row-action--danger:hover {
  background: var(--color-danger-bg, #fef2f2);
  color: var(--color-danger, #ef4444);
}

.table-grid-bulkbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: var(--border-thin);
  border-bottom: none;
  background: var(--color-surface-hover);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Add row button */
.table-grid-add-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: var(--border-thin);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  transition: background 0.1s;
}

.table-grid-add-row:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

/* Empty state */
.table-grid-empty {
  padding: var(--space-8);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Sandbox notice */
.table-grid-notice {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  border-bottom: var(--border-thin);
  text-align: center;
  font-style: italic;
}

/* ========================================
   Schema Diff Styles (table grid)
   ======================================== */

.table-grid th.field-added {
  background: rgba(34, 197, 94, 0.08);
  border-bottom-color: rgba(34, 197, 94, 0.3);
  box-shadow: inset 0 -2px 0 rgba(34, 197, 94, 0.4);
}

.table-grid td.field-added {
  background: rgba(34, 197, 94, 0.04);
}

.table-grid th.field-dropped {
  background: rgba(239, 68, 68, 0.06);
  color: var(--color-text-muted);
  text-decoration: line-through;
  opacity: 0.6;
}

.table-grid td.field-dropped {
  background: rgba(239, 68, 68, 0.03);
  opacity: 0.5;
}

/* ========================================
   Official Table View
   ======================================== */

.table-view-page {
  padding: var(--space-4) var(--space-6);
  max-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.table-view-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.table-view-header h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
}

.table-view-header .header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.table-view-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* ========================================
   Destructive Changes Modal
   ======================================== */

.changes-modal-section {
  margin-bottom: var(--space-4);
}

.changes-modal-section h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0 0 var(--space-2) 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.changes-modal-section h4 .change-count {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--border-radius-pill);
}

.changes-modal-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-sm);
  margin-bottom: 2px;
}

.changes-modal-field--added {
  background: rgba(34, 197, 94, 0.08);
  color: #16a34a;
}

.changes-modal-field--added .change-count {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}

.changes-modal-field--modified {
  background: rgba(245, 158, 11, 0.08);
  color: #d97706;
}

.changes-modal-field--modified .change-count {
  background: rgba(245, 158, 11, 0.15);
  color: #d97706;
}

.changes-modal-field--dropped {
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
}

.changes-modal-field--dropped .change-count {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
}

.changes-modal-warning {
  font-size: var(--text-xs);
  color: #dc2626;
  margin-top: var(--space-1);
  padding-left: var(--space-5);
}

.changes-modal-forms {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding-left: var(--space-5);
  margin-top: 2px;
}

/* ========================================
   Form Stale Field Indicators
   ======================================== */

.form-stale-banner {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--border-radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: #dc2626;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-field-stale {
  opacity: 0.6;
  text-decoration: line-through;
}

.form-field-stale .stale-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  color: #dc2626;
  background: rgba(239, 68, 68, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
  text-decoration: none;
  margin-left: var(--space-1);
}

/* ========================================
   Form Builder: Display Mode Toggle
   ======================================== */

.display-mode-toggle {
  display: inline-flex;
  gap: 0;
  background: var(--color-bg);
  border-radius: var(--border-radius-pill);
  padding: 2px;
  border: var(--border-thin);
}

.display-mode-toggle button {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border: none;
  border-radius: var(--border-radius-pill);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.display-mode-toggle button:hover {
  color: var(--color-text-secondary);
}

.display-mode-toggle button.active {
  background: var(--color-surface);
  color: var(--col-builder-accent);
  box-shadow: var(--shadow-sm);
  font-weight: var(--weight-semibold);
}

/* ========================================
   Form Builder: Section Containers
   ======================================== */

.form-sections-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.form-section-container {
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  background: var(--color-surface);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-section-container.drop-target {
  border-color: var(--col-builder-accent);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15);
}

.form-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border-bottom: var(--border-thin);
  min-height: 36px;
}

.form-section-header .section-drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 2px;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.form-section-header .section-drag-handle:hover {
  opacity: 1;
}

.form-section-header .section-title-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-sm);
  outline: none;
  min-width: 0;
}

.form-section-header .section-title-input:focus {
  background: var(--color-surface);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.form-section-header .section-delete-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}

.form-section-header:hover .section-delete-btn {
  opacity: 1;
}

.form-section-header .section-delete-btn:hover {
  color: var(--color-negative);
}

.form-section-dropzone {
  min-height: 40px;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.15s ease;
}

.form-section-dropzone.drag-over {
  background: var(--col-builder-accent-bg);
}

.form-section-dropzone-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-style: italic;
  opacity: 0.6;
}

/* ========================================
   Form Builder: Draggable Field Items
   ======================================== */

.form-field-draggable {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-sm);
  cursor: grab;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    opacity var(--transition-fast),
    transform var(--transition-fast);
  user-select: none;
}

.form-field-draggable:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
}

.form-field-draggable.dragging {
  opacity: 0.4;
  transform: scale(0.98);
}

.form-field-draggable .field-drag-handle {
  color: var(--color-text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.4;
  transition: opacity var(--transition-fast);
}

.form-field-draggable:hover .field-drag-handle {
  opacity: 0.8;
}

.form-field-draggable .field-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-field-draggable .field-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-field-draggable .field-type-badge {
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 1px 6px;
  border-radius: var(--border-radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.form-field-draggable .field-required-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--col-builder-accent);
  flex-shrink: 0;
}

.form-field-draggable .field-remove-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}

.form-field-draggable:hover .field-remove-btn {
  opacity: 1;
}

.form-field-draggable .field-remove-btn:hover {
  color: var(--color-negative);
}

/* Drop indicator line */
.form-field-drop-indicator {
  height: 2px;
  background: var(--col-builder-accent);
  border-radius: 1px;
  margin: -1px 0;
  pointer-events: none;
  animation: fadeIn 0.1s ease;
}

/* ========================================
   Form Builder: Available Fields Pool
   ======================================== */

.form-fields-pool {
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-3);
  background: var(--color-bg);
}

.form-fields-pool.drag-over {
  border-color: var(--color-negative);
  background: rgba(239, 68, 68, 0.03);
}

.form-fields-pool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.form-fields-pool-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.form-pool-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px dashed var(--color-border-light);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.form-pool-field:hover {
  background: var(--color-surface-hover);
  border-color: var(--col-builder-accent);
  border-style: solid;
}

.form-pool-field .field-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-pool-field .field-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

.form-pool-field .field-type-badge {
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 1px 6px;
  border-radius: var(--border-radius-sm);
  white-space: nowrap;
}

.form-pool-field .field-add-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--col-builder-accent);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  font-weight: bold;
  font-size: var(--text-lg);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.form-pool-field:hover .field-add-btn {
  opacity: 1;
}

/* Section being dragged */
.form-section-container.section-dragging {
  opacity: 0.4;
  transform: scale(0.98);
}

.form-section-drop-indicator {
  height: 3px;
  background: var(--col-builder-accent);
  border-radius: 2px;
  margin: -2px 0;
  pointer-events: none;
  animation: fadeIn 0.1s ease;
}

/* ========================================
   Table Editor Header (draft/official edit)
   ======================================== */

.table-editor-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0;
}

.table-editor-header .back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-sm);
  transition: background 0.1s, color 0.1s;
}

.table-editor-header .back-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

@media (max-width: 640px) {
  .table-view-page {
    padding: var(--space-3);
  }
}

/* ========================================
   Creation Mode Selector
   ======================================== */

.creation-mode-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 60%;
  padding: var(--space-8) var(--space-4);
}

.creation-mode-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 440px;
}

.creation-mode-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: 14px;
  cursor: pointer;
  transition:
    border-color var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-base);
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}

.creation-mode-card:hover {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.creation-mode-card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.creation-mode-card-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--color-accent-subtle);
}

.creation-mode-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.creation-mode-card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.creation-mode-card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.creation-mode-card-arrow {
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform var(--transition-base);
}

.creation-mode-card:hover .creation-mode-card-arrow {
  transform: translateX(2px);
}

/* ========================================
   CSV Upload Zone
   ======================================== */

.csv-upload-zone-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60%;
  padding: var(--space-6) var(--space-4);
  gap: var(--space-4);
}

.csv-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  border: 2px dashed var(--color-border);
  border-radius: 16px;
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color var(--transition-base), background var(--transition-base);
  width: 100%;
  max-width: 440px;
}

.csv-upload-zone:hover,
.csv-upload-zone.drag-over {
  border-color: var(--col-builder-accent);
  background: var(--col-builder-accent-bg);
}

.csv-analysing {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6);
}

/* ========================================
   Preview Highlight
   ======================================== */

@keyframes previewPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.3);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15);
  }
}

.toggle-col.preview-highlight {
  background: var(--col-preview-accent-bg);
  border-color: var(--col-preview-accent);
  color: var(--col-preview-accent);
  animation: previewPulse 2s ease-in-out infinite;
  font-weight: var(--weight-semibold);
}

/* ========================================
   Pipelines & Boards
   ======================================== */

.badge.active {
  color: var(--color-positive);
  background: var(--color-positive-bg);
  border-color: var(--color-positive-border);
}

.badge.paused {
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.badge.error {
  color: var(--color-danger, #b91c1c);
  background: var(--color-danger-bg, #fee2e2);
}

.data-cards-page {
  padding: var(--space-4);
}

.pipeline-detail {
  padding: var(--space-4);
  max-width: 920px;
}

.pipeline-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.pipeline-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
}

.pipeline-section-head h3 {
  margin: var(--space-1) 0 0 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.pipeline-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.pipeline-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md, 10px);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast, 0.15s), background var(--transition-fast, 0.15s);
  flex-wrap: wrap;
}

button.pipeline-row:hover {
  border-color: var(--color-text-muted);
  background: var(--color-info-bg, #f8fafc);
}

.pipeline-row-title {
  font-weight: var(--weight-medium);
  flex: 1;
  min-width: 120px;
}

.pipeline-row-meta {
  font-size: var(--text-xs);
}

.pipeline-row-arrow {
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.source-row {
  cursor: default;
}

.source-row-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

.source-row-url {
  flex-basis: 100%;
  font-size: var(--text-xs);
  font-family: var(--font-mono, monospace);
}

/* Add-source modal */

.modal.modal-lg {
  max-width: 560px;
  width: 92vw;
}

.source-type-cards {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.source-type-card {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md, 10px);
  cursor: pointer;
  font-size: var(--text-sm);
}

.source-type-card:has(input:checked) {
  border-color: var(--color-text);
  background: var(--color-info-bg, #f8fafc);
  font-weight: var(--weight-medium);
}

.source-field-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 220px;
  overflow: auto;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md, 10px);
}

.source-field-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  cursor: pointer;
}

/* Pipeline creation wizard */

.wizard-body {
  padding: var(--space-5) var(--space-4);
  max-width: 760px;
}

.wizard-steps {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.wizard-step {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-pill);
  white-space: nowrap;
}

.wizard-step.active {
  color: var(--color-text);
  background: var(--color-info-bg, #f1f5f9);
  font-weight: var(--weight-semibold);
}

.wizard-step.done {
  color: var(--color-positive);
}

.field-hint {
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

/* Web source wizard */

.wizard-steps {
  margin-bottom: var(--space-4);
}

.wizard-step {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.wizard-step .wizard-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--border-radius-pill);
  border: 1px solid currentColor;
  font-size: 0.65rem;
  line-height: 1;
}

.wizard-step.done .wizard-step-num {
  background: var(--color-positive);
  border-color: var(--color-positive);
  color: var(--color-surface, #fff);
}

.wizard-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.wizard-page-intro {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.wizard-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* Flat source editor (single-pane edit of an existing source). */
.source-editor-section {
  display: none;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.is-inline .source-editor-section {
  display: block;
}

/* In the flat editor every wizard page is visible at once; space them out. */
.is-inline .wizard-page {
  margin-bottom: var(--space-5);
}

.is-inline .wizard-page-intro {
  margin-top: calc(-1 * var(--space-1));
}

.source-editor-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3);
  margin-top: var(--space-3);
  background: var(--color-surface-2, #f8fafc);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.source-editor-meta-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
}

.source-editor-meta-actions {
  display: flex;
  gap: var(--space-2);
}

.wizard-footer .wizard-spacer {
  flex: 1;
}

.creation-mode-card.selected {
  border-color: var(--color-text);
  box-shadow: var(--shadow-sm);
  background: var(--color-info-bg, #f8fafc);
}

.creation-mode-card .cm-example {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-style: italic;
}

.creation-mode-card .cm-produces {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.wizard-summary {
  border: var(--border-thin);
  border-radius: var(--border-radius-md, 10px);
  background: var(--color-info-bg, #f8fafc);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.wizard-summary ul {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-4);
}

.wizard-summary li {
  margin-bottom: var(--space-1);
}

/* ========================================
   Board Workspace (3-zone)
   ======================================== */

#app.board-mode {
  padding: 0;
  overflow: hidden;
}

.board-workspace {
  position: relative;
  display: grid;
  /* Chat / Board / Viewer. Viewer collapsed → 40 / 60. */
  grid-template-columns: 40% 60% 0;
  height: calc(100vh - var(--header-height));
  min-height: 0;
  transition: grid-template-columns var(--transition-base);
}

.board-workspace.viewer-open {
  /* All three open → 30 / 40 / 30. */
  grid-template-columns: 30% 40% 30%;
}

.board-workspace.chat-collapsed {
  grid-template-columns: 0 100% 0;
}

.board-workspace.chat-collapsed.viewer-open {
  grid-template-columns: 0 60% 40%;
}

/* Expanded view-card viewer — give the data table real width. */
.board-workspace.viewer-open.viewer-wide {
  grid-template-columns: 0 35% 65%;
}

.board-workspace.chat-collapsed.viewer-open.viewer-wide {
  grid-template-columns: 0 25% 75%;
}

/* Full-width overlay — viewer covers the entire workspace (board + chat). */
.board-viewer.viewer-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  max-width: none;
  z-index: 40;
  border-left: none;
  box-shadow: var(--shadow-lg, 0 8px 40px rgba(0, 0, 0, 0.18));
}

/* --- Left: chat --- */
.board-chat {
  display: flex;
  flex-direction: column;
  border-right: var(--border-thin);
  background: var(--color-surface);
  min-height: 0;
}

.board-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
}

.board-chat-head-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.board-chat-head-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.board-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Message rows + bubbles */
.board-chat-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  max-width: 100%;
}

.board-chat-row.user {
  flex-direction: row-reverse;
}

.board-chat-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  font-weight: var(--weight-bold);
}

.board-chat-avatar.assistant {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

.board-chat-avatar.user {
  background: var(--color-surface-hover);
  color: var(--color-text-secondary);
  border: var(--border-thin);
}

.board-chat-bubble-wrap {
  min-width: 0;
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.board-chat-row.user .board-chat-bubble-wrap {
  align-items: flex-end;
}

.board-chat-bubble {
  position: relative;
  font-size: var(--text-sm);
  line-height: 1.5;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-lg);
  background: var(--color-surface-hover);
  border: var(--border-thin);
  word-break: break-word;
}

.board-chat-bubble.rendered-markdown {
  white-space: normal;
}

/* Unified message author name (multi-user chats). */
.board-chat-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  padding: 0 var(--space-1);
}

.board-chat-avatar .avatar-img {
  width: 100%;
  height: 100%;
}

/* Author header for the pipeline assistant message bubbles. */
.chat-author {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.chat-author-name {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

/* Settings: avatar editor row (profile + assistant). */
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.board-chat-bubble.user {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  padding-left: 38px;
  /* border-bottom-right-radius: var(--border-radius-sm); */
}

.board-chat-bubble.assistant {
  padding-right: 38px;
  /* border-bottom-left-radius: var(--border-radius-sm); */
}

.board-chat-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: var(--border-thin);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  opacity: 0;
  cursor: pointer;
  transition:
    opacity var(--transition-fast),
    color var(--transition-fast),
    background var(--transition-fast);
}

.board-chat-bubble:hover .board-chat-copy,
.board-chat-copy:focus-visible,
.board-chat-copy.is-copied {
  opacity: 1;
}

.board-chat-copy:hover,
.board-chat-copy.is-copied {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.board-chat-bubble.user .board-chat-copy {
  left: 6px;
  right: auto;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}

/* Onboarding / empty */
.board-chat-onboarding {
  margin: auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
}

.board-chat-onboarding-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.board-chat-onboarding-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.board-chat-onboarding-sub {
  font-size: var(--text-sm);
  max-width: 36ch;
}

.board-chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-2);
}

.board-chat-suggestion {
  font-size: var(--text-sm);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.board-chat-suggestion:hover {
  border-color: var(--color-accent);
  color: var(--color-text);
}

/* Streaming stepper */
.board-chat-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

.board-chat-stepper {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-2);
}

.board-cycle-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.board-cycle-group.is-nested .board-cycle-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: var(--space-3);
  border-left: 1px solid var(--color-border);
  margin-left: 7px;
}

.board-cycle-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.board-step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
}

.board-step-mark {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  color: #fff;
}

.board-step.done .board-step-mark {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.board-step.active .board-step-mark {
  border-color: var(--color-accent);
}

.board-step-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: psa-pulse 0.9s ease-in-out infinite;
}

.board-step-label {
  color: var(--color-text-muted);
}

.board-step.done .board-step-label,
.board-step.active .board-step-label {
  color: var(--color-text-secondary);
}

.board-chat-stream-text {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  line-height: 1.5;
}

@keyframes psa-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.board-chat-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: psa-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes psa-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Showcase pills inside assistant replies */
.board-chat-pills {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
/* When the bubble has body text, separate the pills with a hairline. */
.board-chat-bubble-body:not(:empty) + .board-chat-pills {
  padding-top: var(--space-2);
  border-top: var(--border-thin);
}

.board-chat-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  background: var(--color-bg);
  max-width: 100%;
}

.board-chat-pill-icon {
  display: none;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

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

.board-chat-pill-btn {
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

.board-chat-pill-btn:hover,
.board-chat-pill-btn.primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

/* Composer (picker + input) */
.board-composer {
  border-top: var(--border-thin);
  background: var(--color-surface);
}

/* ---- Composer (inline pills + slash commands) ---- */
.composer-box {
  position: relative;
  margin: var(--space-3);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  background: var(--color-bg);
  transition: border-color var(--transition-fast);
}

.composer-box:focus-within {
  border-color: var(--color-border-focus);
}

.composer-box.is-disabled {
  opacity: 0.7;
}

.composer-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) 0;
}

.composer-pills:empty {
  display: none;
}

.composer-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 2px var(--space-1) 2px var(--space-2);
  border-radius: var(--border-radius-pill);
  border: var(--border-thin);
  max-width: 180px;
}

.composer-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-pill--table {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
  color: var(--color-accent);
}

.composer-pill--card {
  background: color-mix(in srgb, #a855f7 14%, transparent);
  border-color: color-mix(in srgb, #a855f7 38%, transparent);
  color: #9333ea;
}

.composer-pill--node {
  background: color-mix(in srgb, var(--col-builder-accent, #4caf8e) 14%, transparent);
  border-color: color-mix(in srgb, var(--col-builder-accent, #4caf8e) 38%, transparent);
  color: var(--col-builder-accent, #4caf8e);
}

/* Inline card/node pills sit within the contenteditable text flow. */
.board-chat-input .composer-pill--card,
.board-chat-input .composer-pill--node {
  vertical-align: baseline;
  margin: 0 1px;
  user-select: none;
  cursor: default;
  max-width: 220px;
}

.composer-pill-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  opacity: 0.65;
  padding: 0;
}

.composer-pill-x:hover {
  opacity: 1;
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-2);
}

.composer-input-row .board-chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: var(--space-1) var(--space-2);
  font: inherit;
  color: var(--color-text);
  line-height: 1.5;
  min-height: 1.5em;
  max-height: 160px;
  overflow-y: auto;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer-input-row .board-chat-input:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
  pointer-events: none;
}

.composer-hint {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.composer-hint kbd {
  font-family: var(--font-mono, monospace);
  font-size: 0.85em;
  background: var(--color-surface-hover);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  padding: 0 4px;
}

.composer-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

/* Command popover */
.cmd-popover {
  position: absolute;
  left: var(--space-2);
  right: var(--space-2);
  bottom: calc(100% + 4px);
  max-height: 240px;
  overflow-y: auto;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.12));
  z-index: 40;
  padding: var(--space-1);
}

.cmd-popover-head {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
}

.cmd-empty {
  padding: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: none;
  background: transparent;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text);
  text-align: left;
}

.cmd-item.active {
  background: var(--color-surface-hover);
}

.cmd-item.selected {
  color: var(--color-accent);
}

.cmd-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmd-item-tag {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
  border-radius: var(--border-radius-pill);
  padding: 0 var(--space-2);
}

/* Pipeline section header inside the table picker */
.cmd-section-head {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-2) var(--space-1);
  margin-top: var(--space-1);
  border-top: var(--border-thin);
}
.cmd-section-head:first-of-type {
  border-top: none;
  margin-top: 0;
}

/* A table staged (Tab) for adding as a pill on Enter */
.cmd-item.staged {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
}
.cmd-item-staged {
  color: var(--color-accent);
  display: inline-flex;
  align-items: center;
}

/* ---- Card edit proposals (chat) ---- */
.board-proposals {
  margin-top: var(--space-2);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
}

.board-proposals-head {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  background: var(--color-surface-hover);
}

.board-proposals-count {
  margin-left: auto;
  color: var(--color-accent);
}

.board-proposal {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-top: var(--border-thin);
  background: var(--color-surface);
  cursor: pointer;
  text-align: left;
}

.board-proposal:hover {
  background: var(--color-surface-hover);
}

.board-proposal-icon {
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.board-proposal-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.board-proposal-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-proposal-summary {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-proposal-status {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
}

.board-proposal.is-accepted .board-proposal-status {
  color: var(--color-success, #16a34a);
}
.board-proposal.is-rejected .board-proposal-status {
  color: var(--color-text-muted);
}
.board-proposal.is-accepted, .board-proposal.is-rejected {
  opacity: 0.7;
}

/* ---- Proposal diff (viewer) ---- */
.board-proposal-summary-full {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.board-proposal-stale {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: #b45309;
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  border-radius: var(--border-radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.board-proposal-applied {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--border-radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.board-proposal-applied.is-accepted {
  color: var(--color-success, #16a34a);
  background: color-mix(in srgb, #16a34a 12%, transparent);
}
.board-proposal-applied.is-rejected {
  color: var(--color-text-muted);
  background: var(--color-surface-hover);
}

.board-proposal-preview {
  font-size: var(--text-sm);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-3);
  background: var(--color-surface);
}

.board-view-preview {
  font-size: var(--text-sm);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-3);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.board-view-preview-row {
  color: var(--color-text-secondary);
}
.board-view-preview-row.muted {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.board-view-preview-filters {
  margin: 0;
  padding-left: var(--space-4);
}
.board-view-preview-filters li {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}
.board-view-preview-filters li.muted {
  color: var(--color-text-muted);
}

.card-diff {
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  overflow: hidden;
}

.card-diff-line {
  display: flex;
  gap: var(--space-2);
  padding: 1px var(--space-2);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-diff-gutter {
  flex-shrink: 0;
  width: 1ch;
  color: var(--color-text-muted);
  user-select: none;
}

.card-diff-text {
  flex: 1;
}
.card-diff-add {
  background: color-mix(in srgb, #16a34a 14%, transparent);
}
.card-diff-del {
  background: color-mix(in srgb, #dc2626 14%, transparent);
}

.card-diff-sheets {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
}

.card-diff-sheet-col {
  flex: 1;
  min-width: 0;
}

.card-diff-sheet-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.card-diff-sheet {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-xs);
}

.card-diff-sheet td {
  border: var(--border-thin);
  padding: 2px var(--space-1);
}

.card-diff-cell-add {
  background: color-mix(in srgb, #16a34a 18%, transparent);
}
.card-diff-cell-del {
  background: color-mix(in srgb, #dc2626 18%, transparent);
}

.board-proposal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.board-chat-input {
  padding: var(--space-3);
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.board-chat-textarea {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.4;
  padding: var(--space-2) var(--space-3);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  background: var(--color-bg);
  color: var(--color-text);
  max-height: 160px;
  overflow-y: auto;
}

.board-chat-textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
}

.board-chat-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.board-chat-send:disabled {
  opacity: 0.6;
  cursor: default;
}

.board-chat-send .board-chat-spinner {
  border-color: rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
}

/* Collapsed-chat expand handle */
.board-chat-expand {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-4);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: var(--border-thin);
  background: var(--color-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.board-filter-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.board-filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.board-filter-row [data-filter-field] {
  flex: 1 1 38%;
  min-width: 0;
}

.board-filter-row [data-filter-op] {
  flex: 1 1 28%;
  min-width: 0;
}

.board-filter-row [data-filter-value] {
  flex: 1 1 28%;
  min-width: 0;
}

.board-filter-row .board-filter-novalue {
  flex: 1 1 28%;
  min-width: 0;
  display: flex;
  align-items: center;
  font-size: var(--text-xs);
  font-style: italic;
}

.board-filter-combinator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.board-filter-comb-btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  cursor: pointer;
}

.board-filter-comb-btn.active {
  background: var(--color-accent, var(--color-primary, #4f46e5));
  border-color: var(--color-accent, var(--color-primary, #4f46e5));
  color: #fff;
}

/* Live results preview (view editor + proposal preview) */
.board-view-results {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: var(--color-surface);
  margin-bottom: var(--space-2);
}

.board-view-results .board-card-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

/* Results-first viewer: the table fills the panel instead of a capped box. */
.board-view-results--full {
  flex: 1;
  min-height: 0;
  max-height: none;
  margin-bottom: 0;
}

/* Collapsible "Filters & columns" panel in the view viewer. */
.board-view-settings {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

.board-view-settings > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.board-view-settings > summary::-webkit-details-marker {
  display: none;
}

.board-view-settings-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.board-view-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  min-width: 0;
}

.board-view-chip {
  font-size: var(--text-xs);
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill, 999px);
  background: var(--color-accent-subtle, var(--color-bg));
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.board-view-chip.is-meta {
  background: transparent;
  color: var(--color-text-muted);
}

.board-view-settings-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
}

/* New view builder modal: stacked controls + preview, scrollable body. */
.view-builder .view-builder-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: 60vh;
  overflow-y: auto;
  margin-top: var(--space-3);
}

.view-builder .board-view-results {
  max-height: 240px;
}

.board-viewer-title-static {
  flex: 1;
  font-weight: 600;
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Center: canvas (fixed sectioned grid) --- */
.board-canvas {
  overflow: auto;
  padding: var(--space-4);
  background: var(--color-bg);
  min-height: 0;
}

.board-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.board-grid.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}

.board-empty {
  text-align: center;
  color: var(--color-text-muted);
}

/* Sections (duration grouping) */
.board-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.board-section-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-1);
  background: transparent;
  border: none;
  border-bottom: var(--border-thin);
  cursor: pointer;
  text-align: left;
  color: var(--color-text);
}

.board-section-chevron {
  display: inline-flex;
  color: var(--color-text-muted);
  transition: transform var(--transition-base);
}

.board-section.collapsed .board-section-chevron {
  transform: rotate(-90deg);
}

.board-section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-section-count {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  background: var(--color-surface-hover);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  padding: 1px var(--space-2);
  min-width: 22px;
  text-align: center;
}

/* Uniform card grid */
.board-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
  align-items: start;
}

/* The `hidden` attribute must win over `display: grid` for section collapse. */
.board-cards-grid[hidden] {
  display: none;
}

.board-card {
  display: flex;
  flex-direction: column;
  height: 240px;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.board-card:hover {
  box-shadow: var(--shadow-md);
}

.board-card.is-dragging {
  opacity: 0.4;
}

.board-card.drop-before {
  box-shadow: -3px 0 0 0 var(--color-accent);
}

.board-card.drop-after {
  box-shadow: 3px 0 0 0 var(--color-accent);
}

.board-card--hidden {
  opacity: 0.55;
  border-style: dashed;
}

.board-card-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-thin);
  background: var(--color-surface-hover);
}

.board-card-grip {
  display: inline-flex;
  color: var(--color-text-muted);
  cursor: grab;
  flex-shrink: 0;
}

.board-card-grip:active {
  cursor: grabbing;
}

.board-card-type-icon {
  display: inline-flex;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.board-card-title {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.board-card-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
}

.board-card-btn:hover {
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.board-card-body {
  flex: 1;
  overflow: auto;
  padding: var(--space-3);
  font-size: var(--text-sm);
}

/* ---- Chart cards (view/sheet chart section) ---- */
.board-chart-wrap {
  position: relative;
  width: 100%;
  min-height: 160px;
  height: 220px;
}

.board-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.board-chart-preview {
  margin-top: var(--space-3);
  height: 200px;
}

.board-chart-toggle {
  display: inline-flex;
  gap: 1px;
  margin-bottom: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
}

.board-chart-toggle button {
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: none;
  cursor: pointer;
}

.board-chart-toggle button.active {
  color: var(--color-text-on-accent, #fff);
  background: var(--color-accent);
}

.board-chart-settings {
  display: none;
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
}

.board-chart-settings > summary {
  cursor: pointer;
  list-style: none;
}

.board-chart-settings > summary::-webkit-details-marker {
  display: none;
}

/* Assistant-authored card purpose/description. */
.board-card-provenance {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: var(--space-2) var(--space-3) 0;
  padding: 2px var(--space-2);
  max-width: calc(100% - var(--space-3) * 2);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  background: var(--color-accent-subtle);
}

.board-card-provenance svg {
  flex: 0 0 auto;
}

.board-card-provenance span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-viewer-head + .board-card-provenance {
  margin: var(--space-2) var(--space-4) 0;
}

.board-card-desc {
  margin: 0;
  padding: var(--space-2) var(--space-3) 0;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.board-proposal-desc {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.board-viewer-desc {
  margin: 0 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.board-card-placeholder {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.board-card-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

/* Header: grouping toggle */
.board-group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--color-surface-hover);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
}

.board-group-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: 0 var(--space-1) 0 var(--space-2);
}

.board-group-opt {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 3px var(--space-2);
  border: none;
  background: transparent;
  border-radius: var(--border-radius-pill);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.board-group-opt.active {
  background: var(--color-border);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.button.icon-only {
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.button.is-public {
  color: var(--color-accent);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
}

/* Share / settings modal rows */
.board-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  cursor: pointer;
}

.board-toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.board-copy-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.board-copy-row .input {
  flex: 1;
  min-width: 0;
}

.board-copy-row .button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* Public board badges in the grid */
.board-grid-card {
  cursor: pointer;
}

.board-public-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  border-radius: var(--border-radius-pill);
  padding: 1px var(--space-2);
  margin-left: auto;
}

.board-card-copy-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  background: transparent;
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  padding: 1px var(--space-2);
  cursor: pointer;
  margin-left: auto;
}

.board-card-copy-link:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* --- Public read-only board page --- */
.public-board-shell {
  min-height: 100vh;
  background: var(--color-bg);
}

.public-board-loading,
.public-board-empty {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}

.public-board-header {
  border-bottom: var(--border-thin);
  background: var(--color-surface);
}

.public-board-header-inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.public-board-header h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
}

.public-board-desc {
  margin-top: var(--space-2);
  color: var(--color-text-secondary);
  max-width: 70ch;
}

.public-board-body {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.public-board-footer {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-align: center;
}

.board-card--public {
  cursor: default;
}

.board-card--public.is-clickable {
  cursor: pointer;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.board-card--public:hover {
  box-shadow: var(--shadow-sm);
}

.board-card--public.is-clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md, 0 4px 16px rgba(0, 0, 0, 0.1));
}

/* Public read-only card viewer drawer */
.public-card-viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: flex-end;
}

.public-card-viewer[hidden] {
  display: none;
}

body.public-viewer-open {
  overflow: hidden;
}

.public-viewer-panel {
  width: min(560px, 100%);
  height: 100%;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  animation: public-viewer-in 0.18s ease-out;
}

@keyframes public-viewer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.public-viewer-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
}

.public-viewer-type {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
}

.public-viewer-title {
  flex: 1;
  min-width: 0;
  font-weight: var(--weight-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.public-viewer-close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
}

.public-viewer-close:hover {
  color: var(--color-text);
}

.public-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.board-view-table,
.board-sheet-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}

.board-view-table th,
.board-view-table td,
.board-sheet-preview td {
  border: 1px solid var(--color-border-light);
  padding: 2px 6px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.board-view-table th {
  background: var(--color-surface-hover);
  font-weight: var(--weight-semibold);
  position: sticky;
  top: 0;
  z-index: 1;
}

.board-proposal-sheet th {
  border: 1px solid var(--color-border-light);
  padding: 2px 6px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  background: var(--color-surface-hover);
  font-weight: var(--weight-semibold);
}

.board-view-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--color-surface-hover) 45%, transparent);
}

.board-view-table tbody tr:hover {
  background: var(--color-accent-subtle);
}

.board-showcase {
  margin: 0;
}

.board-showcase-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: var(--border-thin);
}

/* Rich record values */
.board-record-img {
  max-width: 100%;
  max-height: 160px;
  border-radius: var(--border-radius-sm);
  display: block;
}

.board-record-link {
  color: var(--color-accent);
  word-break: break-all;
}

.board-tag {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 1px var(--space-2);
  margin: 1px;
  background: var(--color-surface-hover);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
}

/* Viewer header type icon */
.board-viewer-type-icon {
  display: inline-flex;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* Markdown toolbar */
.board-md-toolbar {
  display: flex;
  gap: 2px;
  margin-bottom: var(--space-2);
}

.board-md-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 var(--space-2);
  border: var(--border-thin);
  background: var(--color-surface);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.board-md-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

/* Sheet editor row/col controls */
.board-sheet-del {
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  line-height: 1;
}

.board-sheet-del:hover {
  background: var(--color-danger-bg, #fde8e8);
  color: var(--color-danger, #c0392b);
}

.board-sheet-rowhead,
.board-sheet-colhead,
.board-sheet-corner {
  background: var(--color-surface-hover);
  text-align: center;
  padding: 0;
}

.board-showcase-row {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.board-showcase-row dt {
  flex: 0 0 38%;
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

.board-showcase-row dd {
  flex: 1;
  margin: 0;
  word-break: break-word;
}

/* --- Right: viewer --- */
.board-viewer {
  border-left: var(--border-thin);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.board-viewer[hidden] {
  display: none;
}

.board-viewer-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border-bottom: var(--border-thin);
}

.board-viewer-title {
  flex: 1;
  min-width: 0;
}

.board-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.board-field-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-2);
}

.board-text-editor {
  min-height: 160px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.board-text-preview {
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  padding: var(--space-3);
  background: var(--color-bg);
  min-height: 60px;
}

.board-col-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.board-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.board-sheet-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.board-sheet-tb-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px var(--space-1);
  background: var(--color-border-light);
}

.board-sheet-fmt {
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  font-size: var(--text-sm);
  cursor: pointer;
  line-height: 1;
}

.board-sheet-fmt:hover { background: var(--color-surface-hover, #f3f4f6); }
.board-sheet-fmt.is-on { background: var(--color-border-focus); color: #fff; }
.board-sheet-fmt:disabled { opacity: 0.4; cursor: default; }

.board-sheet-color {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 4px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}

.board-sheet-color input[type="color"] {
  width: 16px;
  height: 16px;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
}

.board-sheet-numfmt {
  height: 26px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-xs);
  background: var(--color-surface);
}

.board-sheet-wrap {
  overflow: auto;
  max-height: 420px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  outline: none;
}

.board-sheet-editor {
  border-collapse: collapse;
  table-layout: fixed;
}

.board-sheet-editor td,
.board-sheet-editor th {
  border: 1px solid var(--color-border-light);
  padding: 0;
}

.board-sheet-corner,
.board-sheet-colhead,
.board-sheet-rowhead {
  position: relative;
  background: var(--color-surface-muted, #f8f9fa);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  user-select: none;
}

.board-sheet-colhead {
  padding: 2px 4px;
  white-space: nowrap;
}

.board-sheet-colhead.is-filtered { background: #fef3c7; }

.board-sheet-colname { cursor: pointer; }
.board-sheet-colname:hover { text-decoration: underline; }

.board-sheet-rowhead {
  width: 34px;
  text-align: center;
}

.board-sheet-colfilter {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 9px;
  padding: 0 2px;
  color: var(--color-text-muted);
}

.board-sheet-editor.has-frozen .board-sheet-frozen td,
.board-sheet-editor.has-frozen .board-sheet-frozen th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-muted, #f8f9fa);
  font-weight: 600;
}

.board-sheet-td {
  position: relative;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  min-width: 80px;
  height: 26px;
  white-space: nowrap;
  overflow: hidden;
  cursor: cell;
}

.board-sheet-td.is-selected { background: rgba(59, 130, 246, 0.12); }
.board-sheet-td.is-active {
  outline: 2px solid var(--color-border-focus);
  outline-offset: -2px;
}

.board-sheet-cell-input {
  width: 100%;
  border: none;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  background: var(--color-surface);
  outline: 2px solid var(--color-border-focus);
  outline-offset: -2px;
}

.board-sheet-fill {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 7px;
  height: 7px;
  background: var(--color-border-focus);
  border: 1px solid #fff;
  cursor: crosshair;
  z-index: 2;
}

.board-sheet-resize-col {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}

.board-sheet-resize-row {
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 6px;
  cursor: row-resize;
  z-index: 2;
}

.board-sheet-del {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 11px;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.1s;
}

.board-sheet-colhead:hover .board-sheet-del,
.board-sheet-rowhead:hover .board-sheet-del { opacity: 1; }

/* --- Formula bar --- */
.board-sheet-fbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.board-sheet-fbar-ref {
  min-width: 48px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface-muted, #f8f9fa);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
}

.board-sheet-fbar-fx {
  height: 26px;
  min-width: 30px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  font-style: italic;
  cursor: pointer;
}

.board-sheet-fbar-fx:hover { background: var(--color-surface-hover, #f3f4f6); }

.board-sheet-fbar-input {
  flex: 1;
  height: 26px;
  padding: 0 var(--space-2);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-sm);
  font-family: var(--font-mono, monospace);
}

.board-sheet-fbar-input:focus {
  outline: 2px solid var(--color-border-focus);
  outline-offset: -1px;
}

/* Referenced cells, highlighted live while editing a formula */
.board-sheet-td.is-ref { transition: box-shadow 0.05s; }

/* --- fx function picker --- */
.board-sheet-fxmenu,
.board-sheet-autocomplete {
  position: fixed;
  z-index: var(--z-modal, 1000);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--space-1);
  max-height: 280px;
  overflow-y: auto;
  min-width: 220px;
}

.board-sheet-fxitem,
.board-sheet-acitem {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--border-radius-sm);
}

.board-sheet-fxitem:hover,
.board-sheet-acitem:hover,
.board-sheet-acitem.is-on { background: var(--color-surface-hover, #eef2ff); }

.board-sheet-fxsig {
  font-family: var(--font-mono, monospace);
  font-size: var(--text-sm);
  font-weight: 600;
}

.board-sheet-fxdesc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.board-sheet-acitem {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.board-sheet-acsig {
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* --- Add-card dropdown --- */
.board-add-menu {
  position: relative;
}

.board-add-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-width: 140px;
  z-index: var(--z-header);
  padding: var(--space-1);
}

.board-add-dropdown[hidden] {
  display: none;
}

.board-add-dropdown button {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  border-radius: var(--border-radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}

.board-add-dropdown button:hover {
  background: var(--color-accent-subtle);
}

/* ========================================
   Pipeline Canvas (interactive node editor)
   ======================================== */

#app.canvas-mode {
  padding: 0;
  overflow: hidden;
}

.pipeline-canvas {
  position: relative;
  height: calc(100vh - var(--header-height));
  background: radial-gradient(circle, var(--color-border-light) 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: var(--color-bg);
  overflow: hidden;
  touch-action: none;
  cursor: default;
}

.pipeline-canvas.space-pan {
  cursor: grab;
}

.pipeline-canvas.is-panning {
  cursor: grabbing;
}

/* Group-select marquee (drawn in world coords inside #canvas-world). */
.canvas-marquee {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  border: 1px solid var(--color-accent, #111);
  background: color-mix(in srgb, var(--color-accent, #111) 10%, transparent);
  border-radius: 2px;
}

.canvas-node.is-selected {
  outline: 2px solid var(--color-accent, #111);
  outline-offset: 2px;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-edges {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none; /* override reset.css `img, svg { max-width: 100% }` (parent is 1px wide) */
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

.canvas-edge {
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  transition: opacity var(--transition-base), stroke-width var(--transition-base);
}

/* Per-stage edge colours (match the source node of each edge). */
.canvas-edge.is-source {
  stroke: #6aa9ff;
}
.canvas-edge.is-table {
  stroke: var(--col-builder-accent);
}
.canvas-edge.is-board {
  stroke: #4caf8e;
}

.canvas-edge.is-active {
  stroke-width: 3.5;
}

.canvas-edge.is-dim {
  opacity: 0.15;
}

/* Proposal connectors: dashed + directional (drawn into #canvas-proposal-edges). */
.canvas-edges.is-proposal {
  z-index: 1;
}
.canvas-edge.is-ghost {
  stroke: var(--col-builder-accent);
  stroke-width: 2.5;
  stroke-dasharray: 7 5;
  opacity: 0.95;
  animation: canvas-edge-flow 0.8s linear infinite;
}
.canvas-edge.is-removing {
  stroke: var(--color-negative) !important;
  stroke-dasharray: 6 4;
  opacity: 0.85;
}
@keyframes canvas-edge-flow {
  to {
    stroke-dashoffset: -12;
  }
}

/* Live "data is flowing" edges (outgoing from a processing node). */
.canvas-edge.is-flowing {
  stroke-dasharray: 6 6;
  stroke-width: 3;
  animation: canvas-edge-flow 0.6s linear infinite;
}

/* A glowing packet that travels along an edge when data is produced. */
.canvas-edge-packet {
  fill: var(--col-builder-accent, #4caf8e);
  filter: drop-shadow(0 0 5px var(--col-builder-accent, #4caf8e));
  opacity: 0.95;
}

/* --- Nodes --- */
.canvas-node {
  position: absolute;
  width: 300px;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: grab;
  z-index: 1;
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.canvas-node:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-focus);
  z-index: 2;
}

.canvas-node.is-dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lg);
  z-index: 5;
  transition: none;
}

/* --- Node header band (type identity) --- */
.canvas-node-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-thin);
}

.canvas-node-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--border-radius-sm);
  flex-shrink: 0;
}

.canvas-node-icon svg {
  width: 14px;
  height: 14px;
}

.canvas-node-type {
  flex: 1;
  min-width: 0;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--weight-bold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-type colour theming for the header band. */
.canvas-node.is-source .canvas-node-header {
  background: rgba(106, 169, 255, 0.12);
}
.canvas-node.is-source .canvas-node-icon {
  background: rgba(106, 169, 255, 0.18);
  color: #2f6fd0;
}
.canvas-node.is-source .canvas-node-type {
  color: #2f6fd0;
}

.canvas-node.is-table .canvas-node-header {
  background: var(--color-accent-subtle);
}
.canvas-node.is-table .canvas-node-icon {
  background: var(--color-accent-subtle);
  color: var(--color-border-focus);
}
.canvas-node.is-table .canvas-node-type {
  color: var(--color-border-focus);
}

.canvas-node.is-analyzer {
  background: var(--col-builder-accent-bg);
  border-color: var(--col-builder-accent);
}
.canvas-node.is-analyzer .canvas-node-header {
  background: var(--col-builder-accent-bg);
}
.canvas-node.is-analyzer .canvas-node-icon {
  background: var(--col-builder-accent);
  color: var(--color-surface);
}
.canvas-node.is-analyzer .canvas-node-type {
  color: var(--col-builder-accent);
}

.canvas-node.is-board .canvas-node-header {
  background: rgba(76, 175, 142, 0.12);
}
.canvas-node.is-board .canvas-node-icon {
  background: rgba(76, 175, 142, 0.18);
  color: #2f8c6c;
}
.canvas-node.is-board .canvas-node-type {
  color: #2f8c6c;
}

.canvas-node-body {
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.canvas-node-badges {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.canvas-node-schedule {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent, #2563eb);
  background: color-mix(in srgb, var(--color-accent, #2563eb) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent, #2563eb) 35%, transparent);
  line-height: 1.2;
}

.canvas-node-schedule svg {
  flex: 0 0 auto;
}

/* --- Node metadata rows --- */
.canvas-node-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.canvas-node-stat strong {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

.canvas-node-submeta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

.canvas-node-menu-btn {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 var(--space-1);
  border-radius: var(--border-radius-sm);
}

.canvas-node-menu-btn:hover {
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.canvas-node-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
  word-break: break-word;
}

.canvas-node-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-xs);
}

.canvas-node-flow {
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
}

.canvas-node-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: var(--leading-snug, 1.4);
}

.canvas-node-warn {
  color: var(--color-negative);
  font-weight: var(--weight-medium);
}

.canvas-node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-3);
}

/* --- Node context menu --- */
.canvas-node-menu {
  position: fixed;
  z-index: var(--z-modal);
  min-width: 160px;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
}

.canvas-node-menu-item {
  text-align: left;
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  color: var(--color-text);
}

.canvas-node-menu-item:hover {
  background: var(--color-accent-subtle);
}

.canvas-node-menu-item.danger {
  color: var(--color-negative);
}

/* --- Pipeline canvas header --- */
.canvas-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.canvas-header-lead {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.canvas-header .back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--border-radius-sm);
  transition: background 0.1s, color 0.1s;
}
.canvas-header .back-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}
.canvas-header-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0;
  min-width: 0;
  max-width: 24ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.canvas-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Add-node toolbar (centered between lead + actions). */
.canvas-toolbar {
  display: flex;
  gap: var(--space-2);
  margin: 0 auto;
  padding: 0;
}

/* Shared sizing for all header controls so the bar reads as one system. */
.canvas-toolbar-btn,
.canvas-header-btn {
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 0 var(--space-3);
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    filter var(--transition-fast);
}

.canvas-header-btn.secondary {
  background: transparent;
}
.canvas-header-btn.secondary:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-border-focus);
}
.canvas-header-btn.danger {
  background: transparent;
  color: var(--color-negative);
  border-color: var(--color-negative-border);
}
.canvas-header-btn.danger:hover {
  background: var(--color-negative-bg);
}
.canvas-toolbar-btn[draggable="true"]:not(:disabled) {
  cursor: grab;
}
.canvas-toolbar-btn[draggable="true"]:active {
  cursor: grabbing;
}
/* Visible drop affordance while dragging a toolbar item over the canvas. */
.pipeline-canvas.is-drop-target {
  outline: 2px dashed var(--color-border-focus);
  outline-offset: -6px;
}

/* Per-type colour coding for the add-node buttons (matches node tier colours). */
.canvas-toolbar-btn {
  border-left-width: 3px;
}
.canvas-toolbar-btn svg {
  flex-shrink: 0;
}

.canvas-toolbar-btn.is-source {
  border-color: rgba(106, 169, 255, 0.5);
  border-left-color: #6aa9ff;
  background: rgba(106, 169, 255, 0.1);
  color: #2f6fd0;
}
.canvas-toolbar-btn.is-source:hover:not(:disabled) {
  background: rgba(106, 169, 255, 0.18);
}

.canvas-toolbar-btn.is-table {
  border-color: var(--color-border-focus);
  border-left-color: var(--color-border-focus);
  background: var(--color-accent-subtle);
  color: var(--color-border-focus);
}
.canvas-toolbar-btn.is-table:hover:not(:disabled) {
  filter: brightness(0.97);
}

.canvas-toolbar-btn.is-analyzer {
  border-color: var(--col-builder-accent);
  border-left-color: var(--col-builder-accent);
  background: var(--col-builder-accent-bg);
  color: var(--col-builder-accent);
}
.canvas-toolbar-btn.is-analyzer:hover:not(:disabled) {
  filter: brightness(0.97);
}

.canvas-toolbar-btn.is-activity {
  border-color: var(--color-border);
  border-left-color: var(--color-border-focus);
  background: var(--color-accent-subtle);
  color: var(--color-text-secondary);
}
.canvas-toolbar-btn.is-activity:hover:not(:disabled) {
  filter: brightness(0.97);
}

.canvas-toolbar-btn:disabled {
  opacity: 0.5;
}

/* --- Zoom controls (segmented group, lives in the pipeline header) --- */
.canvas-controls {
  display: inline-flex;
  align-items: center;
  height: 30px;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
}

.canvas-ctrl {
  height: 100%;
  min-width: 32px;
  padding: 0 var(--space-2);
  border: none;
  border-right: var(--border-thin);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  transition: background var(--transition-fast);
}

.canvas-ctrl:last-child {
  border-right: none;
}

.canvas-ctrl:hover {
  background: var(--color-accent-subtle);
}

.canvas-ctrl-fit {
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.canvas-ctrl-fit svg {
  flex-shrink: 0;
}

/* --- Tier legend --- */
.canvas-tier-labels {
  position: absolute;
  top: 50%;
  left: var(--space-4);
  transform: translateY(-50%);
  z-index: 4;
  display: none;
  flex-direction: column;
  gap: var(--space-6);
  pointer-events: none;
}

.canvas-tier-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  opacity: 0.7;
}

/* --- Guided setup rail --- */
.canvas-setup {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 6;
  width: 280px;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-4);
}

.canvas-setup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.canvas-setup-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}

.canvas-setup-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--color-border-light);
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.canvas-setup-progress span {
  display: block;
  height: 100%;
  background: var(--col-builder-accent, var(--color-border-focus));
  transition: width var(--transition-base);
}

.canvas-setup-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.canvas-setup-step {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}

.canvas-setup-check {
  flex: 0 0 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 50%;
  border: var(--border-thin);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--color-surface);
}

.canvas-setup-step.is-done .canvas-setup-check {
  background: var(--col-builder-accent, var(--color-border-focus));
  border-color: transparent;
}

.canvas-setup-step.is-current .canvas-setup-check {
  border-color: var(--color-border-focus);
}

.canvas-setup-step-btn {
  display: block;
  border: none;
  background: transparent;
  padding: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
}

.canvas-setup-step.is-done .canvas-setup-step-btn {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

.canvas-setup-step-btn:hover {
  text-decoration: underline;
}

.canvas-setup-hint {
  display: block;
  font-size: var(--text-xs);
}

/* --- Table builder slide-over drawer --- */
.canvas-drawer-host:empty {
  display: none;
}

.canvas-drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.25);
  animation: fadeIn var(--transition-fast) ease;
}

.canvas-drawer {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(96%, 760px);
  background: var(--color-bg);
  box-shadow: var(--shadow-lg);
  z-index: 21;
  display: flex;
  flex-direction: column;
  animation: drawerIn var(--transition-base) ease;
}

@keyframes drawerIn {
  from {
    transform: translateX(24px);
    opacity: 0.6;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ========================================
   Floating canvas panels (fade in over canvas)
   ======================================== */

.canvas-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  padding: var(--space-4);
  animation: fadeIn var(--transition-fast) ease;
}

.canvas-panel {
  width: min(100%, 460px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-modal);
  animation: modalIn var(--transition-base) ease;
  overflow: hidden;
}

.canvas-panel.wide {
  width: min(100%, 640px);
}

.canvas-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: var(--border-thin);
}

.canvas-panel-head h3 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.canvas-panel-body {
  padding: var(--space-6);
  overflow-y: auto;
}

.canvas-panel-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: var(--border-thin);
}

.canvas-panel-footer .button:last-child {
  margin-left: auto;
}

.canvas-panel-footer .button:last-child:only-child {
  margin-left: auto;
}

.canvas-panel-prompt {
  font-weight: var(--weight-semibold);
  margin: var(--space-4) 0 var(--space-3);
}

.creation-mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

.creation-mode-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: left;
  padding: var(--space-4);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.creation-mode-card:hover:not(:disabled) {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-sm);
}

.creation-mode-card:disabled {
  opacity: 0.5;
  cursor: default;
}

.creation-mode-card .cm-title {
  font-weight: var(--weight-semibold);
}

.creation-mode-card .cm-desc {
  font-size: var(--text-xs);
}

/* --- Analyzer panel --- */
.field-row {
  display: flex;
  gap: var(--space-3);
}

.field-row .field {
  flex: 1;
}

.an-table-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 160px;
  overflow-y: auto;
  border: var(--border-thin);
  border-radius: var(--border-radius-sm);
  padding: var(--space-2);
}

.an-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.an-board-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.an-board-row #an-board {
  flex: 1 1 auto;
  min-width: 0;
}

.an-board-row #an-new-board {
  flex: 0 0 auto;
  white-space: nowrap;
}

.an-progress {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 160px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.an-progress:empty {
  display: none;
}

.an-progress-line {
  color: var(--color-text-secondary);
}

.an-progress-line.error {
  color: var(--color-negative);
}

/* Analyzer-run feedback: while a run streams, the node widens and a feedback
   column renders inside the SAME border (no separately bordered box). */
.canvas-node.is-running {
  width: 600px;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header feed"
    "body   feed";
  align-items: stretch;
}

/* Processing state: a breathing accent glow so the canvas feels alive. */
.canvas-node.is-running,
.canvas-node.is-processing {
  animation: canvas-node-pulse 1.6s ease-in-out infinite;
  border-color: var(--col-builder-accent, #4caf8e);
}

@keyframes canvas-node-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(76, 175, 142, 0.0), var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.12));
  }
  50% {
    box-shadow:
      0 0 0 4px rgba(76, 175, 142, 0.18),
      var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.12));
  }
}

/* Brief flash when a node receives freshly-produced data. */
.canvas-node.is-receiving {
  animation: canvas-node-receive 1.2s ease-out;
}

@keyframes canvas-node-receive {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 175, 142, 0.55);
    border-color: var(--col-builder-accent, #4caf8e);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(76, 175, 142, 0);
  }
}

.canvas-node.is-running .canvas-node-header {
  grid-area: header;
}

.canvas-node.is-running .canvas-node-body {
  grid-area: body;
}

.canvas-node-run {
  grid-area: feed;
  display: flex;
  flex-direction: column;
  border-left: var(--border-thin);
  min-width: 0;
  max-height: 380px;
  overflow: hidden;
}

.canvas-node-run-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-thin);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--weight-bold);
  color: var(--col-builder-accent);
}

.canvas-node-run-head svg {
  flex-shrink: 0;
}

.canvas-node-run-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3);
}

/* The stepper sits directly under the status line (no extra top gap). */
.canvas-node-run-body .board-chat-stepper {
  margin-top: var(--space-2);
}

/* ========================================
   Pipeline activity / logs panel
   ======================================== */
.activity-content {
  min-height: 120px;
  max-height: min(60vh, 520px);
  overflow-y: auto;
}

.activity-loading,
.activity-empty {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  padding: var(--space-4) var(--space-2);
  text-align: center;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.activity-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.activity-item.is-ok {
  border-left-color: var(--color-positive, #16a34a);
}

.activity-item.is-error {
  border-left-color: var(--color-negative);
}

.activity-item.is-skipped {
  border-left-color: var(--color-warning, #d97706);
}

.activity-icon {
  flex: 0 0 auto;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.activity-body {
  flex: 1;
  min-width: 0;
}

.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.activity-summary {
  font-size: var(--text-sm);
  font-weight: 500;
}

.activity-actor.badge {
  flex: 0 0 auto;
  font-size: var(--text-xs);
}

.activity-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.activity-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  margin-right: var(--space-1);
}

.activity-detail {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
}

.activity-detail div {
  display: flex;
  gap: var(--space-1);
}

.activity-detail dt {
  color: var(--color-text-secondary);
  margin: 0;
}

.activity-detail dd {
  margin: 0;
  font-family: var(--font-mono);
}

.activity-narrative {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--color-border);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.activity-narrative > :first-child {
  margin-top: 0;
}

.activity-narrative > :last-child {
  margin-bottom: 0;
}

/* ========================================
   Dashboard
   ======================================== */
.dashboard-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-7, 2.5rem);
}

.dashboard-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dashboard-section-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.dashboard-section-title {
  font-size: var(--text-base);
  font-weight: 600;
  margin: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

.dashboard-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.dashboard-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.dashboard-card-head h3 {
  margin: 0;
}

.dashboard-balance.is-low {
  border-color: var(--color-negative);
}

.dashboard-balance-value {
  font-size: var(--text-2xl, 1.75rem);
  font-weight: 700;
}

.dashboard-balance-value span {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-secondary);
}

.dashboard-balance #add-funds-btn {
  align-self: flex-start;
  margin-top: var(--space-2);
}

.dashboard-balance-warning {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-negative);
}

.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

.pack-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--color-surface);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition-fast) ease;
}

.pack-card:hover:not(:disabled) {
  border-color: var(--color-accent, #6aa9ff);
}

.pack-card:disabled {
  opacity: 0.5;
  cursor: default;
}

.pack-credits {
  font-weight: 700;
  font-size: var(--text-lg);
}

.pack-price {
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.ar-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

/* ========================================
   AI Model settings + searchable combobox
   ======================================== */

.model-settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.model-settings-title {
  margin: var(--space-1) 0 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.model-settings-sub {
  margin-top: var(--space-2);
  max-width: 60ch;
  font-size: var(--text-sm);
}

.model-catalogue-badge {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: var(--border-radius-pill);
  background: var(--color-accent-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.model-settings-form {
  margin-top: var(--space-5);
  display: grid;
  gap: var(--space-2);
  border: 1px dashed var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-5);
}

.model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 340px);
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: var(--border-thin);
}

.model-row-primary {
  border-top: none;
  padding-top: 0;
}

.model-row-label {
  display: grid;
  gap: 2px;
}

.model-row-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.model-row-help {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.model-advanced {
  border-top: var(--border-thin);
  margin-top: var(--space-1);
}

.model-advanced-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  list-style: none;
  user-select: none;
}

.model-advanced-summary::-webkit-details-marker {
  display: none;
}

.model-advanced-caret {
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.model-advanced[open] .model-advanced-caret {
  transform: rotate(90deg);
}

.model-advanced-hint {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--color-text-muted);
}

.model-advanced-body {
  display: grid;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}

.model-advanced-body .model-row:first-child {
  border-top: none;
}

.model-settings-actions {
  margin-top: var(--space-4);
}

.model-readonly-note {
  margin-top: var(--space-4);
  font-size: var(--text-xs);
}

.model-skeleton {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.model-skeleton .skeleton-line {
  height: 42px;
  border-radius: var(--border-radius-md);
  background: linear-gradient(
    90deg,
    var(--color-surface-2) 25%,
    var(--color-surface-hover) 50%,
    var(--color-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: model-shimmer 1.3s ease-in-out infinite;
}

@keyframes model-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ---- Combobox ---- */

.combobox {
  position: relative;
  width: 100%;
}

.combobox-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.combobox-trigger:hover {
  border-color: var(--color-text-muted);
}

.combobox.is-open .combobox-trigger {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.combobox.is-disabled {
  opacity: 0.6;
}

.combobox.is-disabled .combobox-trigger {
  cursor: not-allowed;
}

.combobox-trigger-text {
  display: grid;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.combobox-trigger-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combobox-trigger-title.is-inherit {
  color: var(--color-text-secondary);
  font-style: italic;
}

.combobox-trigger-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combobox-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.combobox.is-open .combobox-chevron {
  transform: rotate(180deg);
}

.combobox-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  max-height: 340px;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: combobox-pop 0.12s ease-out;
}

.combobox-panel[hidden] {
  display: none;
}

@keyframes combobox-pop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.combobox-search-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-thin);
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.combobox-search {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  padding: var(--space-1) 0;
}

.combobox-search::placeholder {
  color: var(--color-text-muted);
}

.combobox-list {
  list-style: none;
  margin: 0;
  padding: var(--space-1);
  overflow-y: auto;
}

.combobox-option {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title check" "id check" "meta check";
  align-items: center;
  gap: 0 var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
}

.combobox-option.is-highlighted {
  background: var(--color-accent-subtle);
}

.combobox-option.is-selected {
  background: var(--color-accent-subtle);
}

.combobox-option-title {
  grid-area: title;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.combobox-option.is-inherit-option .combobox-option-title {
  font-style: italic;
  color: var(--color-text-secondary);
}

.combobox-option-id {
  grid-area: id;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combobox-option-meta {
  grid-area: meta;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-top: 1px;
}

.combobox-check {
  grid-area: check;
  color: var(--color-accent);
}

.combobox-empty {
  padding: var(--space-4) var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

@media (max-width: 640px) {
  .model-row {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }
}

/* ============================================================
   Pipeline Assistant — floating dock + canvas change proposals
   ============================================================ */

.button.xs {
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  border-radius: var(--border-radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---- Floating dock (collapsed FAB -> expanded panel) ---- */
.pipeline-assistant {
  position: absolute;
  left: var(--space-4);
  bottom: var(--space-4);
  z-index: 8;
}

.pa-fab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--border-radius-pill);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}
.pa-fab:hover {
  background: var(--color-accent-hover);
}
.pipeline-assistant.is-open .pa-fab {
  display: none;
}
.pipeline-assistant.is-open .pa-panel {
  display: flex;
}

/* The expanded panel hovers over the canvas: 20px inset from the sidebar edge,
   header bottom, and viewport bottom; rounded 20px; never touching the chrome. */
.pa-panel {
  position: fixed;
  left: calc(var(--sidebar-width) + 20px);
  bottom: 20px;
  top: calc(var(--header-height) + 20px);
  width: var(--pa-panel-width);
  max-width: calc(100vw - var(--sidebar-width) - 40px);
  display: none;
  flex-direction: column;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
body.sidebar-collapsed .pa-panel,
.sidebar-collapsed .pa-panel {
  left: calc(var(--sidebar-width-collapsed) + 20px);
  max-width: calc(100vw - var(--sidebar-width-collapsed) - 40px);
}

/* ========================================
   Unified canvas dock — uniform hovering node-edit panel.
   Mirrors the .pa-panel look (fixed, inset 20px, rounded, shadowed);
   width is situational: 1/3 right (source/analyzer) or full (table/board).
   ======================================== */
.canvas-dock {
  position: fixed;
  top: calc(var(--header-height) + 20px);
  bottom: 20px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn var(--transition-base) ease;
}
.canvas-dock[hidden] {
  display: none;
}

/* 1/3 width, docked right — no backdrop, canvas + assistant stay live */
.canvas-dock.is-right {
  right: 20px;
  left: auto;
  width: min(420px, 33vw);
  min-width: 320px;
}

/* When the pipeline assistant is expanded it lives on the left edge of the
   canvas region. The dock must always respect its width and never overlap.
   We trim the dock's right edge to leave room for the pa-panel + gaps. */
body.pipeline-assistant-open .canvas-dock.is-right {
  left: calc(var(--sidebar-width) + var(--pa-panel-width) + 40px);
  right: 20px;
  width: auto;
  min-width: 0;
}
body.sidebar-collapsed.pipeline-assistant-open .canvas-dock.is-right,
body.pipeline-assistant-open .sidebar-collapsed .canvas-dock.is-right {
  left: calc(var(--sidebar-width-collapsed) + var(--pa-panel-width) + 40px);
}

/* full width across the canvas region */
.canvas-dock.is-full {
  left: calc(var(--sidebar-width) + 20px);
  right: 20px;
  width: auto;
}
body.sidebar-collapsed .canvas-dock.is-full,
.sidebar-collapsed .canvas-dock.is-full {
  left: calc(var(--sidebar-width-collapsed) + 20px);
}

/* When the assistant is open, the full-width dock shrinks to clear it. */
body.pipeline-assistant-open .canvas-dock.is-full {
  left: calc(var(--sidebar-width) + var(--pa-panel-width) + 40px);
  right: 20px;
}
body.sidebar-collapsed.pipeline-assistant-open .canvas-dock.is-full,
body.pipeline-assistant-open .sidebar-collapsed .canvas-dock.is-full {
  left: calc(var(--sidebar-width-collapsed) + var(--pa-panel-width) + 40px);
}

/* persistent close button (host mode) */
.canvas-dock-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--border-radius-sm);
}
.canvas-dock-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* host head behaves like the app header bar */
.canvas-dock-head {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 48px 0 var(--space-4); /* clear the close button on the right */
  border-bottom: var(--border-thin);
  background: var(--color-surface);
  flex-shrink: 0;
}
.canvas-dock-head:empty {
  display: none;
}
/* The dock's own × handles closing, so the per-view header "Back" buttons
   (table editor / board) are redundant when hosted in the dock. */
.canvas-dock-head .back-btn {
  display: none;
}

/* host body scrolls and hosts full-page renders */
.canvas-dock-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* panel-mode reuses .canvas-panel-head/body/footer */
.canvas-dock .canvas-panel-body {
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.canvas-dock .canvas-panel-head,
.canvas-dock .canvas-panel-footer {
  flex-shrink: 0;
}

/* board workspace hosted inside the dock fits the dock, not the viewport */
.canvas-dock-body.board-mode {
  padding: 0;
  overflow: hidden;
  height: 100%;
}
.canvas-dock-body.board-mode .board-workspace {
  height: 100%;
}

/* The canvas-dock always respects the expanded pipeline assistant: when both
   are open the dock shrinks to leave room for the pa-panel, and the assistant
   stays visible regardless of dock width. */

.pa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
  gap: var(--space-2);
}
.pa-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  flex-shrink: 0;
}
.pa-header-actions {
  display: flex;
  gap: var(--space-1);
}

/* Focus pill: shows which canvas node the assistant is currently scoped to.
   Sits between the title and the action buttons. Click × to drop focus and
   return to the general pipeline thread. */
.pa-focus {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  margin: 0 var(--space-1);
  background: var(--color-accent-subtle);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.pa-focus-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.pa-focus-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}
.pa-focus-x:hover {
  background: var(--color-surface);
  color: var(--color-text);
}
.pa-icon-btn {
  display: inline-flex;
  padding: 4px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
}
.pa-icon-btn:hover {
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.pa-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.pa-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.pa-msg {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.pa-msg.user {
  align-items: flex-end;
}
.pa-bubble {
  position: relative;
  max-width: 90%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-md);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.pa-msg.assistant .pa-bubble {
  padding-right: 34px;
}
.pa-msg.user .pa-bubble {
  padding-left: 34px;
}

/* Per-message copy button (mirrors the board chat copy affordance). */
.pa-copy {
  position: absolute;
  top: 5px;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: var(--border-thin);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  opacity: 0;
  cursor: pointer;
  transition:
    opacity var(--transition-fast),
    color var(--transition-fast),
    background var(--transition-fast);
}
.pa-bubble:hover .pa-copy,
.pa-copy:focus-visible,
.pa-copy.is-copied {
  opacity: 1;
}
.pa-copy:hover,
.pa-copy.is-copied {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}
.pa-msg.user .pa-copy {
  left: 5px;
  right: auto;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}

/* Posted time next to the author name. */
.chat-author-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-left: auto;
  padding-left: var(--space-2);
  white-space: nowrap;
}
.pa-msg.user .pa-bubble {
  background: var(--color-accent);
  color: #fff;
}
.pa-msg.assistant .pa-bubble {
  background: var(--color-info-bg);
  color: var(--color-text);
  border: var(--border-thin);
}
.pa-stage {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.pa-dots {
  display: inline-flex;
  gap: 3px;
}
.pa-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: pa-blink 1.2s infinite ease-in-out both;
}
.pa-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.pa-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes pa-blink {
  0%, 80%, 100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

.pa-proposal-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  background: var(--col-builder-accent-bg);
  color: var(--col-builder-accent);
  border: 1px solid var(--col-builder-accent);
  border-radius: var(--border-radius-pill);
  cursor: pointer;
}

/* Contenteditable composer (with @-node picker) for the pipeline assistant. */
.pa-composer {
  position: relative;
  border-top: var(--border-thin);
}
.pa-composer .composer-input-row {
  align-items: flex-end;
}
.pa-composer .board-chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: var(--space-1) var(--space-2);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 1.5em;
  max-height: 140px;
  overflow-y: auto;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pa-composer .board-chat-input:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
  pointer-events: none;
}
.pa-composer .composer-hint.pa-hint {
  display: flex;
}

.pa-input-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  padding: var(--space-3);
  border-top: var(--border-thin);
}
.pa-input {
  flex: 1;
  resize: none;
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.4;
  max-height: 120px;
}
.pa-input:focus {
  outline: none;
  border-color: var(--color-border-focus);
}
.pa-send {
  display: inline-flex;
  padding: var(--space-2);
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--border-radius-md);
  cursor: pointer;
}
.pa-send:hover {
  background: var(--color-accent-hover);
}

/* ---- Canvas proposal overlay ---- */
.canvas-proposal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 17, 0.06);
  backdrop-filter: saturate(0.92);
  z-index: 3;
  pointer-events: none;
}

.canvas-proposal-bar {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-pill);
  box-shadow: var(--shadow-md);
}
.cpb-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.cpb-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.cpb-close {
  display: inline-flex;
  padding: 4px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
}
.cpb-close:hover {
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

/* Ghost (new) node */
.canvas-ghost-node {
  position: absolute;
  width: 300px;
  z-index: 5;
  background: var(--color-surface);
  border: 2px dashed var(--col-builder-accent);
  border-radius: var(--border-radius-md);
  padding: var(--space-3);
  opacity: 0.95;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  max-height: 340px;
}
.canvas-ghost-node .canvas-node-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  color: var(--col-builder-accent);
  flex-shrink: 0;
}
.canvas-ghost-node .canvas-node-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.canvas-ghost-node .canvas-node-title {
  font-weight: var(--weight-semibold);
}
.canvas-ghost-node .canvas-op-actions {
  flex-shrink: 0;
  margin-top: var(--space-2);
}
.pa-ghost-summary {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* Proposed-node settings preview (shared by ghost nodes + edit cards) */
.pa-settings {
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pa-setting {
  display: grid;
  grid-template-columns: minmax(70px, auto) 1fr;
  gap: var(--space-2);
  font-size: var(--text-xs);
  align-items: baseline;
}
.pa-setting-key {
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
}
.pa-setting-val {
  color: var(--color-text);
  word-break: break-word;
}

.pa-fields {
  margin-top: var(--space-2);
  border-top: var(--border-thin);
  padding-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pa-fields-caption {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: 2px;
}
.pa-field {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: 1px 0;
}
.pa-field-label {
  color: var(--color-text);
}
.pa-field-req {
  color: var(--color-negative);
  margin-left: 2px;
}
.pa-field-type {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  flex-shrink: 0;
}
.pa-prompt-preview {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  background: var(--color-info-bg);
  border-radius: var(--border-radius-sm);
  padding: var(--space-2);
}

/* Edited / removed node decorations */
.canvas-node.is-editing {
  box-shadow: 0 0 0 2px var(--color-warning);
}
.canvas-node.is-editing::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--color-warning-bg);
  opacity: 0.5;
  border-radius: inherit;
  pointer-events: none;
}
.canvas-node.is-removing {
  box-shadow: 0 0 0 2px var(--color-negative);
}
.canvas-node.is-removing::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--color-negative-bg);
  opacity: 0.55;
  border-radius: inherit;
  pointer-events: none;
}

/* Hover edit-card anchored beside an edited/removed node */
.canvas-edit-card {
  position: absolute;
  width: 280px;
  max-height: 360px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
}
.canvas-edit-card.is-remove {
  border-color: var(--color-negative-border);
}
.canvas-edit-card.is-edit {
  border-color: var(--color-warning-border);
}
.cec-head {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
  flex-shrink: 0;
}
.cec-diff {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-2);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
/* Multi-section edit card (fused intake: Structure + Input) */
.cec-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.cec-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cec-section .cec-diff {
  flex: 0 1 auto;
  margin-bottom: 0;
  overflow-y: visible;
}
.cec-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
}
.pa-diff-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 6px;
  align-items: baseline;
  font-size: var(--text-xs);
}
.pa-diff-row.muted {
  color: var(--color-text-muted);
  display: block;
}
.pa-diff-row.is-single {
  grid-template-columns: auto 1fr;
}
.pa-diff-row.is-block {
  grid-template-columns: 1fr;
  gap: 2px;
}
.pa-diff-key {
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
}
.pa-diff-old {
  color: var(--color-negative);
  text-decoration: line-through;
  word-break: break-word;
}
.pa-diff-arrow {
  color: var(--color-text-muted);
}
.pa-diff-new {
  color: var(--color-positive);
  word-break: break-word;
}
.pa-diff-ctx {
  color: var(--color-text);
  word-break: break-word;
}
.pa-diff-row.is-context .pa-diff-ctx {
  color: var(--color-text-secondary);
}

/* Stacked old/new for long free-text values (prompt, description). */
.pa-diff-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.pa-diff-block .pa-diff-old,
.pa-diff-block .pa-diff-new {
  white-space: pre-wrap;
  line-height: 1.4;
}

/* Expanded nested-object group (e.g. source config). */
.pa-diff-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: var(--space-2);
  margin-top: var(--space-1);
  border-top: var(--border-thin);
}
.pa-diff-grouphead {
  font-size: 0.68rem;
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pa-diff-count {
  font-weight: var(--weight-medium);
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text-secondary);
}
.pa-diff-fields {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pa-field-add::before {
  content: "+";
  color: var(--color-positive);
  font-weight: var(--weight-bold);
  margin-right: 4px;
}
.pa-field-del::before {
  content: "−";
  color: var(--color-negative);
  font-weight: var(--weight-bold);
  margin-right: 4px;
}
.pa-field-add .pa-field-label {
  color: var(--color-positive);
}
.pa-field-del .pa-field-label {
  color: var(--color-negative);
  text-decoration: line-through;
}
.pa-field-same .pa-field-label {
  color: var(--color-text-secondary);
}

.canvas-op-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.canvas-ghost-node .canvas-op-actions {
  margin-top: var(--space-2);
}

/* ============================================================
   Intake panel (tabbed Frontend / Backend) + Intelligent I/O
   ============================================================ */
.intake-panel-head {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 56px 0 var(--space-5);
  border-bottom: var(--border-thin);
  background: var(--color-surface);
  flex-shrink: 0;
}
.intake-panel-title {
  font-weight: 600;
  font-size: var(--text-lg);
}
.intake-panel-title-input {
  min-width: 220px;
  max-width: min(560px, 60vw);
  border: 1px solid transparent;
  border-radius: var(--border-radius-sm);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-lg);
  font-weight: 600;
  padding: 5px 8px;
}
.intake-panel-title-input:hover,
.intake-panel-title-input:focus {
  border-color: var(--color-border);
  background: var(--color-bg);
  outline: none;
}
.intake-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--color-bg);
  border-radius: var(--border-radius-md);
}
.intake-tab {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  padding: 6px 16px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-weight: 500;
}
.intake-tab.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.intake-panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.intake-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.75fr) minmax(420px, 1fr) minmax(420px, 1fr);
  gap: var(--space-4);
  padding: var(--space-5);
  min-height: 100%;
}
.intake-workspace:not(:has(.intake-preview-section)) {
  grid-template-columns: minmax(320px, 0.8fr) minmax(520px, 1.2fr);
}
.intake-workspace-section {
  min-width: 0;
  border: var(--border-thin);
  border-radius: 20px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.intake-source-section {
  align-self: start;
}
.intake-builder-section,
.intake-preview-section {
  min-height: min(780px, calc(100vh - 170px));
  display: flex;
  flex-direction: column;
}
.intake-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-thin);
}
.intake-section-head h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
}
#intake-builder-body {
  flex: 1;
  min-height: 0;
  padding: var(--space-4);
}
#intake-preview-body {
  flex: 1;
  min-height: 0;
  padding: var(--space-4);
}
.intake-builder-section .editor-scroll-container,
.intake-builder-section .csv-editor-layout {
  height: min(720px, calc(100vh - 260px));
}
.intake-builder-section .csv-editor-layout {
  grid-template-columns: 1fr;
}
.intake-builder-section .editor-panel--main {
  max-width: none;
  padding-right: 0;
}
.intake-preview-section .editor-panel--preview,
.intake-preview-section .preview-col {
  display: flex;
  min-width: 0;
  height: min(720px, calc(100vh - 260px));
}
.intake-be-head {
  flex-shrink: 0;
}
.intake-be-body {
  flex: 1;
  min-height: 0;
}

/* Frontend pane */
.intake-frontend,
.intake-form-builder,
.intake-web-config {
  padding: var(--space-5);
}

@media (max-width: 980px) {
  .intake-workspace {
    grid-template-columns: 1fr;
  }
}
.intake-frontend-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.intake-frontend-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.seg-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--color-bg);
  border-radius: var(--border-radius-md);
}
.seg-toggle .seg {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  padding: 5px 14px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
}
.seg-toggle .seg.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.intake-live-form {
  max-width: 640px;
}

/* Intelligent I/O widget */
.intelligent-io {
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 640px;
}
.intelligent-io .io-head {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.intelligent-io .io-desc {
  margin: 0;
  font-size: var(--text-sm);
}
.intelligent-io .io-analyze {
  align-self: flex-start;
}
.intelligent-io .io-status {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.rendered-field .io-alts {
  margin-top: var(--space-2);
}

/* Form builder */
.fb-field-list,
.an-table-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 260px;
  overflow: auto;
  border: var(--border-thin);
  border-radius: var(--border-radius-md);
  padding: var(--space-3);
}
.fb-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}
.intake-form-builder-foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.error-text {
  color: var(--color-danger, #d33);
}

/* Board toolbar button mirrors the board node accent */
.canvas-toolbar-btn.is-board .canvas-node-icon,
.canvas-toolbar-btn.is-board svg {
  color: #4caf8e;
}
