/* APEX pipeline — shared design system (auto templating + rules) */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #1363df;
  --accent-hover: #0f55bf;
  --accent-soft: #e8f1ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #166534;
  --success-soft: #f0fdf4;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 4px 24px rgba(15, 23, 42, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

.shell-wide {
  max-width: 1000px;
}

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

.masthead {
  margin-bottom: 24px;
}

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

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

.masthead-compact {
  margin-bottom: 20px;
}

.masthead-compact h1 {
  margin: 0;
}

/* Pipeline workflow nav */
.workflow-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 14px clamp(20px, 4vw, 32px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.workflow-nav-brand {
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.workflow-nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
}

.workflow-nav-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.workflow-nav-links a:hover {
  color: var(--accent);
}

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

/* Section nav (rules sub-pages — full-width bar, matches run editor) */
.section-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

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

.section-nav-inner a {
  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;
  text-decoration: none;
}

.section-nav-inner a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}

.section-nav-inner a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.section-nav-inner a[aria-current="page"] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 0 var(--surface);
}

.section-nav-inner a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* Rules pages — shared chrome layout (studio, fixed rules, run editor) */
body.rules-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.rules-app .workflow-nav {
  flex-shrink: 0;
}

body.rules-app .rules-chrome,
body.mapping-app.rules-app .mapping-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.rules-app .rules-chrome > .section-nav,
body.mapping-app.rules-app .mapping-body > .section-nav {
  flex-shrink: 0;
}

body.rules-app .rules-chrome-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

body.rules-app.runs-page .rules-chrome {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.rules-app.runs-page .rules-chrome-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Cards & panels */
.panel-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: clamp(20px, 3vw, 28px) clamp(20px, 3vw, 32px) 32px;
}

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

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

.panel-lead code,
code.inline {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

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

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

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

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

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn-danger-outline {
  color: var(--danger);
  background: transparent;
  border: 1px solid #fecaca;
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
}

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

.btn .spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  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;
}

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

/* Form fields */
.field label,
.field-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.field input[type="text"],
.field textarea,
.field select,
.field-group input,
.field-group select {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

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

.field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Toast & overlay */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  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;
}

.toast.toast-success {
  background: var(--success-soft);
  border-color: #86efac;
  color: var(--success);
}

.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(2px);
}

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

.process-overlay-inner {
  text-align: center;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: min(320px, 90vw);
}

.process-overlay-spinner {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 12px;
  border: 3px solid #dbeafe;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.process-overlay-label {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

body.is-processing {
  overflow: hidden;
}

/* Legacy hooks — hide old dark-theme backgrounds */
.bg-mesh,
.bg-grid {
  display: none !important;
}
