/* Rules studio components — load after combined_static/css/pipeline.css */

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(24px, 4vw, 48px) clamp(20px, 4vw, 32px) 64px;
}

/* Header */
.brand {
  margin-bottom: 1.5rem;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(19, 99, 223, 0.25);
  margin-bottom: 1rem;
}

.brand h1 {
  margin: 0 0 6px;
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

.brand p {
  margin: 0;
  max-width: 48ch;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: clamp(20px, 3vw, 28px) clamp(20px, 3vw, 32px) 32px;
  margin-bottom: 1.25rem;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Upload grid */
.upload-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .upload-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
  }
}

.drop-zone {
  position: relative;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1.5rem 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-subtle);
}

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

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone.has-file {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 0.75rem;
  border-radius: 10px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.drop-icon svg {
  width: 22px;
  height: 22px;
}

.drop-label {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.drop-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.file-name {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  word-break: break-all;
  min-height: 1.2em;
}

/* Optional row */
.optional-block {
  margin-top: 0.5rem;
}

.drop-zone.compact {
  padding: 1.15rem 1rem;
}

/* Advanced */
details.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  overflow: hidden;
}

details.advanced summary {
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

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

details.advanced summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform 0.2s;
}

details.advanced[open] summary::after {
  transform: rotate(-135deg);
  margin-top: 4px;
}

.advanced-body {
  padding: 0 1.1rem 1.1rem;
  display: grid;
  gap: 0.85rem;
}

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field textarea {
  min-height: 72px;
  resize: vertical;
}

.rules-toggle-row {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.rules-toggle-row input {
  margin-top: 0.2rem;
}

.rules-toggle-row strong,
.rules-toggle-row small {
  display: block;
}

.rules-toggle-row small {
  margin-top: 0.25rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.rules-config-saved {
  align-self: center;
  color: var(--success, #1f8a4c);
  font-weight: 600;
}

.rule-tree-stage {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
}

.rule-tree-stage[hidden] {
  display: none;
}

.rule-tree-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.rule-tree-canvas,
.rule-tree-detail-panel {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.rule-tree-canvas {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
}

.rule-tree-detail-panel {
  overflow: auto;
  padding: 18px;
}

.rule-tree-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rule-tree-toolbar label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.rule-tree-viewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.rule-tree-empty {
  padding: 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: var(--surface-subtle);
}

.rule-tree-root,
.rule-tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rule-tree-root {
  display: grid;
  gap: 8px;
}

.rule-tree-children {
  position: relative;
  margin-left: 22px;
  padding-left: 26px;
  display: grid;
  gap: 8px;
  grid-column: 2;
}

.rule-tree-children::before {
  content: "";
  position: absolute;
  top: -8px;
  bottom: 18px;
  left: 8px;
  width: 2px;
  background: var(--border-strong);
  border-radius: 999px;
}

.rule-tree-node-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: start;
}

.rule-tree-children > .rule-tree-node-wrap::before {
  content: "";
  position: absolute;
  top: 22px;
  left: -18px;
  width: 18px;
  height: 2px;
  background: var(--border-strong);
  border-radius: 999px;
}

.rule-tree-toggle {
  width: 28px;
  height: 28px;
  margin-top: 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    background 0.15s ease;
  z-index: 1;
}

.rule-tree-toggle:hover:not(:disabled) {
  border-color: rgba(19, 99, 223, 0.55);
  color: var(--accent);
  background: var(--accent-soft);
}

.rule-tree-toggle:disabled {
  opacity: 0;
  cursor: default;
}

.rule-tree-node-wrap.is-collapsed > .rule-tree-toggle {
  transform: rotate(-90deg);
}

.rule-tree-node-edit {
  width: 32px;
  height: 32px;
  margin-top: 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.rule-tree-node-edit:hover {
  border-color: rgba(19, 99, 223, 0.55);
  color: var(--accent);
  background: var(--accent-soft);
}

.rule-tree-node {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-width: 0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.rule-tree-node:hover,
.rule-tree-node.is-selected {
  border-color: rgba(19, 99, 223, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.rule-tree-node-title {
  font-weight: 650;
  line-height: 1.35;
  min-width: 0;
}

.rule-tree-node-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.rule-tree-node-fields-label {
  margin-top: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rule-tree-node-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.rule-tree-node-fields.is-empty {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

.rule-tree-node-field {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 3px 7px;
  border: 1px solid rgba(19, 99, 223, 0.18);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.25;
}

.tree-node-flags,
.tree-node-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.tree-node-edit-panel {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.tree-node-edit-panel[hidden] {
  display: none;
}

.tree-node-action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tree-node-flags label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Actions */
.actions {
  margin-top: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.15s,
    box-shadow 0.2s,
    background 0.2s;
}

.btn-primary {
  color: #fff;
  background: var(--accent);
  box-shadow: none;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: none;
  box-shadow: none;
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn .spinner {
  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid rgba(4, 18, 15, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.btn.loading .spinner {
  display: block;
}

.btn.loading .btn-text-default {
  display: none;
}

.btn.loading .btn-text-loading {
  display: inline !important;
}

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

.btn-text-loading {
  display: none !important;
}

/* Full-screen busy state while /api/process runs */
.process-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.process-overlay[hidden] {
  display: none !important;
}

.process-overlay-inner {
  text-align: center;
  padding: 2rem;
}

.process-overlay-spinner {
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 auto 1.1rem;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.process-overlay-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.process-overlay-stages {
  margin: 1.25rem auto 0;
  padding: 0;
  list-style: none;
  text-align: left;
  max-width: 22rem;
}

.process-overlay-stages li {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.35rem 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  opacity: 0.55;
}

.process-overlay-stages li.is-active {
  opacity: 1;
  color: var(--text);
  font-weight: 600;
}

.process-overlay-stages li.is-done {
  opacity: 0.85;
  color: var(--text-muted);
}

.process-overlay-stages .stage-dot {
  flex: 0 0 auto;
  width: 0.55rem;
  height: 0.55rem;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.process-overlay-stages li.is-active .stage-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.process-overlay-stages li.is-done .stage-dot {
  background: var(--success, #1f8a4c);
}

.rule-tree-gen-progress {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.rule-tree-gen-progress[hidden] {
  display: none !important;
}

.rule-tree-gen-progress-spinner {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(15, 23, 42, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.rule-tree-gen-progress-body {
  min-width: 0;
  flex: 1 1 auto;
}

.rule-tree-gen-progress-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.rule-tree-gen-progress-stages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.rule-tree-gen-progress-stage {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
}

.rule-tree-gen-progress-stage.is-active {
  color: var(--accent);
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.08);
}

.rule-tree-gen-progress-stage.is-done {
  color: var(--success, #1f8a4c);
  border-color: rgba(31, 138, 76, 0.25);
  background: rgba(31, 138, 76, 0.08);
}

body.is-processing {
  overflow: hidden;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 0.9rem 1.25rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition:
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.25s;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Top navigation */
.top-nav { display: none; }

.top-nav a {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  transition:
    color 0.15s,
    background 0.15s;
}

.top-nav a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.top-nav a[aria-current="page"] {
  color: var(--accent);
}

/* Editable rule list */
.rule-list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.btn-secondary {
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: rgba(19, 99, 223, 0.35);
  transform: translateY(-1px);
}

.btn-danger-outline {
  color: var(--danger);
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.35);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

.btn-danger-outline:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.12);
}

.btn-icon {
  padding: 0.45rem 0.55rem;
  min-width: auto;
  font-size: 0.85rem;
  line-height: 1;
}

.rule-rows {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.rule-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.65rem;
  align-items: flex-start;
  padding: 0.85rem 0.95rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--surface-subtle, #f8fafc);
  transition: border-color 0.15s;
}

.rule-row:hover {
  border-color: var(--border-strong, #cbd5e1);
}

.rule-row .rule-row-index {
  flex: 0 0 1.75rem;
  text-align: right;
  margin-top: 0.55rem;
}

.rule-row .rule-row-actions {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 0.35rem;
}

.rule-row textarea {
  flex: 1 1 220px;
  min-width: min(100%, 200px);
  min-height: 3.25rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
}

.rule-row textarea:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.rule-row .rule-row-main {
  flex: 1 1 280px;
  min-width: min(100%, 200px);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rule-row .rule-row-main textarea,
.rule-row .rule-row-main .rule-row-textarea {
  flex: 0 0 auto;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  overflow-y: hidden;
  field-sizing: content;
  box-sizing: border-box;
}

.rule-row .rule-row-main textarea:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.rule-source-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-source-toggle {
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s,
    background 0.15s;
}

.btn-source-toggle:hover {
  color: var(--accent);
  border-color: rgba(19, 99, 223, 0.35);
  background: var(--accent-soft);
}

.rule-source-panel {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  background: var(--surface-subtle);
  border-left: 2px solid rgba(19, 99, 223, 0.3);
  white-space: pre-wrap;
  word-break: break-word;
}

.rule-source-panel[hidden] {
  display: none !important;
}

.rule-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.rule-row-index {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 1.75rem;
  text-align: right;
  padding-top: 0.5rem;
}

.toast.toast-success {
  border-color: rgba(19, 99, 223, 0.45);
  color: #166534;
}

/* Previous runs */
.wrap.wrap-runs {
  max-width: 1000px;
}

.runs-shell {
  display: grid;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  min-height: min(70vh, 620px);
}

@media (min-width: 880px) {
  .runs-shell {
    grid-template-columns: 258px 1fr;
  }
}

@media (max-width: 879px) {
  .runs-shell {
    grid-template-rows: auto 1fr;
  }
}

.runs-sidebar {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

@media (min-width: 880px) {
  .runs-sidebar {
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
}

.runs-sidebar-label {
  padding: 1.1rem 1rem 0.45rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.runs-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.55rem 1rem;
  min-height: 100px;
  max-height: min(36vh, 260px);
}

@media (min-width: 880px) {
  .runs-sidebar-scroll {
    max-height: none;
  }
}

.run-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.run-list-item {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.run-list-item:hover {
  background: var(--accent-soft);
}

.run-list-item.is-active {
  background: var(--accent-soft);
  border-color: rgba(19, 99, 223, 0.25);
}

.run-list-item .run-item-title {
  font-weight: 600;
  font-size: 0.84rem;
  line-height: 1.35;
  word-break: break-word;
  margin-bottom: 0.2rem;
}

.run-list-item .run-item-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.35;
  opacity: 0.9;
}

.run-item-field-aliases {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.run-item-field-aliases:hover {
  text-decoration: underline;
}

.runs-empty {
  padding: 1rem 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.runs-main {
  min-width: 0;
}

.runs-main-inner {
  min-height: min(52vh, 480px);
  padding: 1.2rem 1.2rem 1.65rem;
}

@media (min-width: 880px) {
  .runs-main-inner {
    padding: 1.45rem 1.65rem 1.85rem;
  }
}

.runs-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 260px;
  padding: 1.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: var(--surface-subtle);
}

.runs-placeholder-icon {
  font-size: 1.35rem;
  color: var(--accent);
  opacity: 0.3;
  margin-bottom: 0.65rem;
  font-weight: 300;
}

.runs-placeholder-title {
  margin: 0 0 0.3rem;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
}

.runs-placeholder-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 15rem;
  line-height: 1.45;
}

.runs-editor-top {
  margin-bottom: 1.15rem;
}

.runs-editor-title {
  margin: 0 0 0.45rem;
  font-size: clamp(1.05rem, 2.4vw, 1.22rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.28;
  word-break: break-word;
}

.runs-editor-sub.meta-line {
  margin: 0 0 0.9rem;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.45;
  word-break: break-word;
}

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

.runs-toolbar-secondary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
}

.runs-toolbar-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
}

.runs-link {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

a.runs-link:hover,
button.runs-link:hover {
  border-bottom-color: rgba(19, 99, 223, 0.45);
}

.runs-link-danger {
  color: #fca5a5;
}

.runs-link-danger:hover {
  border-bottom-color: rgba(252, 165, 165, 0.45);
}

.runs-rules-block {
  margin-top: 0.15rem;
}

.runs-rules-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  gap: 0.65rem;
}

.runs-rules-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.runs-pill-btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.38rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s,
    background 0.15s;
}

.runs-pill-btn:hover {
  color: var(--accent);
  border-color: rgba(19, 99, 223, 0.32);
  background: var(--accent-soft);
}

.run-rule-rows {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.run-rule-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  padding: 0.8rem 0.95rem;
  transition: border-color 0.2s;
}

.run-rule-card:hover {
  border-color: var(--border);
}

.run-rule-card-top {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
}

.run-rule-num {
  flex: 0 0 1.45rem;
  width: 1.45rem;
  height: 1.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(19, 99, 223, 0.18);
  margin-top: 0.18rem;
}

.run-rule-card-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.run-rule-textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.45;
  resize: none;
  overflow-y: hidden;
  box-sizing: border-box;
}

.run-rule-textarea:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.42);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.run-rule-source-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.run-rule-source-toggle {
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
}

.run-rule-source-toggle:hover,
.run-rule-source-toggle.is-open {
  color: var(--accent);
}

.run-rule-source-panel {
  width: 100%;
  font-size: 0.71rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: var(--surface-subtle);
  border-left: 2px solid rgba(19, 99, 223, 0.26);
  word-break: break-word;
}

.run-rule-source-panel[hidden] {
  display: none !important;
}

.run-rule-remove {
  align-self: flex-end;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.35rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.12s,
    background 0.12s;
}

.run-rule-remove:hover {
  color: var(--danger);
  background: rgba(255, 80, 80, 0.08);
}

@media (max-width: 520px) {
  .run-rule-card-top {
    flex-wrap: wrap;
  }
}

/* Rule mapping editor mode */
.mapping-page .wrap.wrap-runs {
  max-width: 1440px;
}

.mapping-editor-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 980px) {
  .mapping-editor-grid {
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  }
}

.mapping-editor-col {
  min-width: 0;
}

.mapping-editor-canvas-col {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
}

.map-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.map-select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.55rem 0.65rem;
}

.map-select:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.45);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.map-current {
  margin-top: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 10px;
  padding: 0.55rem;
  min-height: 5.5rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.map-rule-full {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 10px;
  padding: 0.6rem;
  min-height: 4.5rem;
  font-size: 0.78rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.map-source-wrap {
  margin-top: 0.5rem;
}

.map-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: rgba(19, 99, 223, 0.08);
  border: 1px solid rgba(19, 99, 223, 0.2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
}

.map-chip.map-chip-focused {
  border-color: rgba(248, 113, 113, 0.75);
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.18);
}

.map-chip button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
}

.map-chip button:hover {
  color: #fca5a5;
}

.mapping-canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.mapping-canvas-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-subtle);
  padding: 0.35rem;
  overflow: auto;
  min-height: 74vh;
}

#page-image {
  display: block;
  max-width: none;
  border-radius: 8px;
}

#bbox-overlay {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  pointer-events: none;
}

.bbox {
  position: absolute;
  border-radius: 6px;
  border: 2px solid rgba(148, 163, 184, 0.45);
  background: rgba(148, 163, 184, 0.08);
  pointer-events: auto;
  cursor: pointer;
  text-align: left;
  padding: 0;
  overflow: hidden;
}

.bbox:hover {
  border-color: rgba(19, 99, 223, 0.65);
  background: rgba(19, 99, 223, 0.2);
}

.bbox-mapped {
  border-color: rgba(19, 99, 223, 0.9);
  background: rgba(19, 99, 223, 0.28);
}

.bbox-focused {
  border-color: rgba(248, 113, 113, 0.98) !important;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.3);
}

.bbox-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 0.58rem;
  line-height: 1.2;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.95);
  padding: 0.1rem 0.2rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Light pipeline alignment */
.shell-wide {
  max-width: 1000px;
}

.shell-mapping {
  max-width: 1440px;
}

.brand-badge {
  display: none;
}

details.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  overflow: hidden;
}

details.advanced summary {
  color: var(--text-muted);
}

.field input[type="text"],
.field textarea,
.map-select,
.rule-row textarea,
.run-rule-textarea {
  background: var(--surface);
}

#templating-run-links a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

#templating-run-links a:hover {
  text-decoration: underline;
}

.drop-icon {
  background: var(--accent-soft);
  color: var(--accent);
}

.runs-link {
  color: var(--accent);
}

.runs-link-danger {
  color: var(--danger);
}

.mapping-canvas-wrap {
  background: var(--surface-subtle);
}

.map-chip {
  background: var(--accent-soft);
  border-color: rgba(19, 99, 223, 0.25);
}

.linked-run-status {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.linked-run-status a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.linked-run-status a:hover {
  text-decoration: underline;
}

.drop-zone.is-linked-supplied {
  opacity: 0.65;
  pointer-events: none;
  border-style: solid;
  border-color: var(--border);
  background: var(--surface-subtle);
}

/* Tabs (Generate | Previous runs) */
.tabs-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0 8px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.tablist button {
  appearance: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 14px 18px;
  margin: 0;
  cursor: pointer;
  position: relative;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.tablist button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}

.tablist button[aria-selected="true"] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 0 var(--surface);
}

.tablist button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

.tab-panel {
  padding: clamp(20px, 3vw, 28px);
}

.tab-panel[hidden] {
  display: none !important;
}

.panel-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--text);
}

.panel-lead {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 52ch;
}

.card-flat {
  border: none;
  box-shadow: none;
  padding: 0;
}

.studio-run-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.studio-run-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.studio-run-open {
  flex: 1;
  min-width: 200px;
  text-decoration: none;
  color: inherit;
}

.studio-run-open:hover .studio-run-title {
  color: var(--accent);
}

.studio-run-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.studio-run-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.studio-run-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
}

.studio-run-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.studio-run-link:hover {
  text-decoration: underline;
}

.studio-run-dot {
  color: var(--text-muted);
}

.studio-run-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.studio-run-delete {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #b91c1c;
  cursor: pointer;
}

.studio-run-delete:hover {
  text-decoration: underline;
}

.studio-run-delete:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.run-list-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.run-list-row .run-list-item {
  flex: 1;
  min-width: 0;
}

.run-list-delete {
  flex-shrink: 0;
  align-self: center;
  margin-right: 4px;
  appearance: none;
  border: none;
  background: transparent;
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: #b91c1c;
  cursor: pointer;
  border-radius: 6px;
}

.run-list-delete:hover {
  background: #fef2f2;
}

.run-list-delete:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

.rule-row-mappings {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border, #e2e8f0);
}

.rule-row-mappings-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rule-row-mapping-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 1.25rem;
}

.rule-row-mapping-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.22rem 0.45rem 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(19, 99, 223, 0.22);
  background: var(--accent-soft);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}

.rule-row-mapping-chip-label {
  line-height: 1.2;
}

.rule-row-mapping-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.rule-row-mapping-chip-remove:hover {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.08);
}

.rule-row-mapping-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.rule-row-mapping-select {
  flex: 1 1 180px;
  min-width: min(100%, 160px);
  max-width: 100%;
  padding: 0.42rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
}

.rule-row-mapping-select:focus {
  outline: none;
  border-color: rgba(19, 99, 223, 0.45);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.rule-row-mapping-add-btn {
  font-size: 0.75rem;
  padding: 0.42rem 0.75rem;
}
