/* ==========================================================================
   Design System — Automação de Planilhas
   ========================================================================== */

:root,
[data-theme="light"] {
  --font-sans: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --bg-primary: #f4f6fb;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sidebar: #0f1117;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
  --bg-sidebar-active: rgba(99, 102, 241, 0.18);
  --bg-subtle: #eef1f8;
  --bg-code: #f1f5f9;
  --bg-input: #ffffff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #ffffff;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-2: #8b5cf6;
  --gradient-accent: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  --gradient-sidebar: linear-gradient(180deg, #0f1117 0%, #151929 100%);

  --border: #e2e8f0;
  --border-subtle: #f1f5f9;
  --table-hover: rgba(99, 102, 241, 0.04);
  --link-color: #6366f1;

  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
  --shadow-accent: 0 8px 24px rgba(99, 102, 241, 0.28);

  --sidebar-width: 260px;
  --topbar-height: 72px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-primary: #090b12;
  --bg-card: #12151f;
  --bg-elevated: #181c28;
  --bg-sidebar: #060810;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
  --bg-sidebar-active: rgba(129, 140, 248, 0.15);
  --bg-subtle: #1a1f2e;
  --bg-code: #0d1018;
  --bg-input: #1a1f2e;

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.15);
  --accent-2: #a78bfa;
  --gradient-accent: linear-gradient(135deg, #6366f1 0%, #818cf8 50%, #a78bfa 100%);
  --gradient-sidebar: linear-gradient(180deg, #060810 0%, #0c101a 100%);

  --border: #252b3b;
  --border-subtle: #1a1f2e;
  --table-hover: rgba(129, 140, 248, 0.06);
  --link-color: #a5b4fc;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --shadow-accent: 0 8px 24px rgba(99, 102, 241, 0.2);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  line-height: 1.6;
  font-size: 0.9375rem;
}

/* --- Layout Shell --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--gradient-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.875rem;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem 1.5rem;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-accent);
  flex-shrink: 0;
}

.brand-logo svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.7rem;
  color: var(--text-sidebar);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav-section-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(148, 163, 184, 0.7);
  padding: 0.75rem 0.75rem 0.5rem;
  margin-top: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  overflow-y: auto;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--text-sidebar);
  text-decoration: none;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.sidebar-nav .nav-link svg {
  width: 18px;
  height: 18px;
  opacity: 0.75;
  flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-link:hover svg { opacity: 1; }

.sidebar-nav .nav-link.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  border-color: rgba(99, 102, 241, 0.25);
}

.sidebar-nav .nav-link.active svg {
  opacity: 1;
  color: var(--accent);
}

.sidebar-footer {
  padding: 0.75rem 0.5rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: auto;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem;
  margin-bottom: 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta {
  font-size: 0.7rem;
  color: var(--text-sidebar);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-badge {
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.2);
  color: #c7d2fe;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: inline-block;
  margin-bottom: 0.375rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: var(--text-sidebar);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
}

.btn-sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  min-height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.page-heading { min-width: 0; }

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0;
}

.layout-rename-btn {
  line-height: 1;
  vertical-align: middle;
  text-decoration: none !important;
  opacity: 0.65;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.layout-rename-btn:hover,
.layout-rename-btn:focus-visible {
  opacity: 1;
  color: var(--text-primary) !important;
}

.layout-rename-form {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.layout-rename-input {
  min-width: 14rem;
  max-width: 22rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon svg { width: 18px; height: 18px; }

[x-cloak] { display: none !important; }

.btn-primary i[data-lucide],
.btn-primary svg {
  width: 16px;
  height: 16px;
}

.sidebar-toggle {
  display: none;
}

.content-area {
  padding: 1.75rem 2rem 2.5rem;
  flex: 1;
}

.messages-container {
  padding: 1rem 2rem 0;
  position: relative;
  z-index: 20;
}

.messages-container .alert {
  margin-bottom: 0.75rem;
}

.messages-container .alert.flash-message {
  max-height: var(--flash-max-height, 12rem);
  overflow: hidden;
  transition:
    opacity 0.45s ease,
    transform 0.45s ease,
    max-height 0.45s ease,
    margin 0.45s ease,
    padding 0.45s ease,
    border-width 0.45s ease;
}

.messages-container .alert.flash-message.is-dismissing {
  opacity: 0;
  transform: translateY(-0.5rem);
  max-height: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0;
  pointer-events: none;
}

.messages-container .alert-danger,
.messages-container .alert-error {
  background: rgba(239, 68, 68, 0.14);
  border-color: #ef4444;
  border-left: 4px solid #dc2626;
  color: #991b1b;
  font-weight: 500;
}

/* --- Page Sections --- */
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-toolbar-text {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-sm); }

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 1rem 1.25rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-header svg,
.card-header i[data-lucide] {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex-shrink: 0;
}

.card-body { padding: 1.25rem; }

.card-title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.data-card .card-header {
  background: var(--bg-subtle);
}

.step-card {
  position: relative;
  overflow: visible;
}

.step-card::before {
  content: attr(data-step);
  position: absolute;
  top: -10px;
  left: 1.25rem;
  background: var(--gradient-accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: var(--shadow-accent);
}

.merge-only-section,
.utility-tools-section {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.utility-tools-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.merge-only-card {
  border: 1px dashed var(--border);
  background: var(--bg-card);
  width: 100%;
  max-width: 100%;
}

.merge-output-options {
  grid-template-columns: 1fr;
}

@media (min-width: 576px) {
  .merge-output-options {
    grid-template-columns: 1fr;
  }
}

.staged-file-list {
  padding-left: 1.1rem;
}

.output-mode-options {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 576px) {
  .output-mode-options {
    grid-template-columns: 1fr 1fr;
  }
}

.output-mode-option {
  margin: 0;
  cursor: pointer;
}

.output-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.output-mode-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  background: var(--bg-subtle);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.output-mode-option input:checked + .output-mode-card {
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 1px var(--accent, #2563eb);
  background: var(--bg);
}

.output-mode-option input:focus-visible + .output-mode-card {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

/* --- Processing progress overlay --- */
body.processing-overlay-open {
  overflow: hidden;
}

.processing-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.processing-overlay[hidden] {
  display: none !important;
}

.processing-overlay-card {
  width: min(420px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
}

.processing-overlay-spinner {
  width: 2.25rem;
  height: 2.25rem;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent, #2563eb);
  border-radius: 50%;
  animation: processing-spin 0.8s linear infinite;
}

@keyframes processing-spin {
  to { transform: rotate(360deg); }
}

.processing-overlay-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
  color: var(--text-primary);
}

.processing-overlay-message {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 1.25rem;
}

.processing-overlay-progress {
  height: 0.65rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.processing-overlay-progress .progress-bar {
  background: var(--gradient-accent, var(--accent, #2563eb));
  transition: width 0.25s ease;
}

.processing-overlay-pct {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.job-progress-bar {
  height: 0.65rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.job-progress-bar .progress-bar {
  background: var(--gradient-accent, var(--accent, #2563eb));
  transition: width 0.4s ease;
}

/* --- Stat Cards --- */
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: transform var(--transition), box-shadow var(--transition);
  height: 100%;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .card-body {
  padding: 1.25rem 1.375rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-icon.indigo { background: var(--accent-soft); color: var(--accent); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-icon.blue { background: var(--info-soft); color: var(--info); }

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.875rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-primary);
}

.stat-card.accent {
  background: var(--gradient-accent);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-accent);
}

.stat-card.accent:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.35);
}

.stat-card.accent .stat-label { color: rgba(255, 255, 255, 0.8); }
.stat-card.accent .stat-value { color: #fff; }
.stat-card.accent .stat-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* --- Buttons --- */
.btn {
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  transition: all var(--transition);
  letter-spacing: -0.01em;
}

.btn-sm {
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
  border-radius: 7px;
}

.btn-primary {
  background: var(--gradient-accent);
  border: none;
  color: #fff;
  box-shadow: var(--shadow-accent);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--gradient-accent);
  filter: brightness(1.08);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(99, 102, 241, 0.35);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
}

.btn-outline-primary {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline-primary:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: var(--accent);
}

.btn-outline-secondary {
  color: var(--text-secondary);
  border-color: var(--border);
  background: transparent;
}

.btn-outline-secondary:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-outline-danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-outline-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

/* --- Tables --- */
.table {
  color: var(--text-primary);
  margin-bottom: 0;
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-primary);
  --bs-table-border-color: var(--border);
  --bs-table-hover-bg: var(--table-hover);
}

.table thead th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.25rem;
  background: var(--bg-subtle);
  white-space: nowrap;
}

.table tbody td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table-hover > tbody > tr {
  transition: background var(--transition);
}

.table-hover > tbody > tr:hover > * {
  background-color: var(--table-hover);
}

.table .cell-primary {
  font-weight: 600;
  color: var(--text-primary);
}

.table .cell-secondary {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* --- Forms --- */
.form-label {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.form-control,
.form-select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus,
.form-select:focus {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-control::placeholder { color: var(--text-muted); opacity: 0.7; }

.form-text { color: var(--text-muted); font-size: 0.8125rem; }

.form-select-sm { font-size: 0.8125rem; }

/* --- Badges --- */
.badge {
  font-weight: 600;
  font-size: 0.7rem;
  padding: 0.35em 0.65em;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}

.badge.status-success,
.text-bg-success { background: var(--success) !important; }
.badge.status-failed { background: var(--danger); }
.badge.status-running { background: var(--warning); }
.badge.status-pending { background: var(--text-muted); }

.badge.badge-archived {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge.badge-live {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

/* --- Code --- */
code {
  color: #be185d;
  background: var(--bg-code);
  padding: 0.15em 0.45em;
  border-radius: 6px;
  font-size: 0.8125em;
  font-family: var(--font-mono);
  border: 1px solid var(--border-subtle);
}

pre.code-block,
.bg-subtle {
  background: var(--bg-code);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.font-monospace {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* --- Lists --- */
.list-group-item {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
  padding: 1rem 1.25rem;
}

/* --- Alerts --- */
.alert {
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.875rem;
  padding: 0.875rem 1.125rem;
}

.alert-success {
  background: var(--success-soft);
  border-color: rgba(16, 185, 129, 0.25);
  color: #047857;
}

.alert-warning {
  background: var(--warning-soft);
  border-color: rgba(245, 158, 11, 0.25);
  color: #b45309;
}

.alert-danger {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.25);
  color: #b91c1c;
}

.alert-error {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.25);
  color: #b91c1c;
}

.alert-info {
  background: var(--info-soft);
  border-color: rgba(59, 130, 246, 0.25);
  color: #1d4ed8;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-state-icon svg { width: 28px; height: 28px; }

/* --- Login --- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: "";
  position: absolute;
  top: -20%;
  right: -10%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.login-page::after {
  content: "";
  position: absolute;
  bottom: -20%;
  left: -10%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.12) 0%, transparent 70%);
  pointer-events: none;
}

.login-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}

.login-brand .brand-logo { width: 48px; height: 48px; }
.login-brand .brand-logo svg { width: 26px; height: 26px; }

.login-card h1 {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0.375rem 0 0;
}

.login-form { margin-top: 1.75rem; }

.login-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* --- Action Group --- */
.action-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  justify-content: flex-end;
}

/* --- Definition Lists --- */
dl.row dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

dl.row dd {
  font-size: 0.875rem;
  color: var(--text-primary);
}

/* --- Utilities --- */
.text-muted { color: var(--text-muted) !important; }
.text-secondary-custom { color: var(--text-secondary); }

a:not(.btn):not(.nav-link):not(.btn-sidebar-logout) {
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

a:not(.btn):not(.nav-link):not(.btn-sidebar-logout):hover {
  color: var(--accent-hover);
}

/* --- Dark Theme Overrides --- */
[data-theme="dark"] .topbar {
  background: rgba(18, 21, 31, 0.85);
}

[data-theme="dark"] .table thead th {
  background: var(--bg-subtle);
}

[data-theme="dark"] code {
  color: #f9a8d4;
  background: var(--bg-code);
  border-color: var(--border);
}

[data-theme="dark"] .alert-success { color: #6ee7b7; }
[data-theme="dark"] .alert-warning { color: #fcd34d; }
[data-theme="dark"] .alert-danger { color: #fca5a5; }
[data-theme="dark"] .alert-error { color: #fca5a5; }
[data-theme="dark"] .messages-container .alert-danger,
[data-theme="dark"] .messages-container .alert-error {
  background: rgba(239, 68, 68, 0.2);
  border-color: #f87171;
  border-left-color: #ef4444;
  color: #fecaca;
}
[data-theme="dark"] .alert-info { color: #93c5fd; }

[data-theme="dark"] .text-warning { color: #fcd34d !important; }
[data-theme="dark"] .text-danger { color: #fca5a5 !important; }

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

[data-theme="dark"] .spinner-border { color: var(--accent); }

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background: var(--bg-input);
  border-color: var(--border);
}

[data-theme="dark"] .form-control[readonly] {
  background: var(--bg-code);
  color: var(--text-muted);
}

[data-theme="dark"] .text-bg-light {
  background-color: var(--bg-subtle) !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .text-dark {
  color: var(--text-primary) !important;
}

[data-theme="dark"] .btn-light {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: var(--border);
}

[data-theme="dark"] details summary { color: var(--text-muted); }

/* --- Responsive --- */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    backdrop-filter: blur(4px);
  }

  .sidebar-overlay.visible { display: block; }

  .main-content { margin-left: 0; }

  .sidebar-toggle { display: inline-flex; }

  .content-area { padding: 1.25rem 1rem 2rem; }
  .topbar { padding: 1rem 1rem; }
  .messages-container { padding: 1rem 1rem 0; }
}

@media (max-width: 575.98px) {
  .page-title { font-size: 1.125rem; }
  .stat-value { font-size: 1.5rem; }
  .table thead th,
  .table tbody td { padding: 0.75rem 1rem; }
}

/* --- Chatbot (Assistente de Pipeline) --- */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 560px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.chat-bot-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-accent);
}

.chat-bot-avatar svg { width: 22px; height: 22px; }

.chat-header-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.chat-header-text strong {
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.chat-header-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-status-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.2);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 280px;
  background: var(--bg-primary);
}

.chat-bubble {
  max-width: 92%;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.55;
}

.chat-bubble-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
  opacity: 0.75;
  color: var(--text-primary);
}

.chat-bubble-bot {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble-user {
  align-self: flex-end;
  background: var(--gradient-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble-user .chat-bubble-label { color: rgba(255, 255, 255, 0.75); }
.chat-bubble-user code { background: rgba(255, 255, 255, 0.15); color: #fff; border: none; }
.chat-bubble-user .text-muted { color: rgba(255, 255, 255, 0.8) !important; }

.chat-bubble-error {
  border-color: rgba(239, 68, 68, 0.35);
  background: var(--danger-soft);
}

.chat-bubble-warn {
  border-color: rgba(245, 158, 11, 0.35);
  background: var(--warning-soft);
}

.chat-bubble-history {
  opacity: 0.85;
  max-width: 85%;
}

.chat-prompt-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-prompt-collapsed {
  font-size: 0.8125rem;
}

.chat-bubble-actions {
  display: flex;
  gap: 0.375rem;
  margin-top: 0.625rem;
}

.chat-bubble-history .btn-outline-secondary,
.chat-bubble-history .btn-outline-primary {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
}

.chat-composer {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1rem 1.25rem;
}

.chat-input-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  resize: vertical;
  min-height: 88px;
  outline: none;
}

.chat-input::placeholder { color: var(--text-muted); }

.chat-composer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.chat-send-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.chat-send-btn svg { width: 16px; height: 16px; }

/* --- Preview section --- */
.preview-section {
  margin-top: 4rem;
  padding-top: 2.5rem;
  border-top: 2px solid var(--border);
  scroll-margin-top: 5rem;
}

.preview-section-header {
  margin-bottom: 1.25rem;
}

.preview-section-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.preview-section-title svg { width: 22px; height: 22px; color: var(--accent); }

.preview-section-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.preview-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.preview-loading {
  display: none;
  align-items: center;
}

.preview-loading.htmx-request {
  display: flex;
}

.preview-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.preview-stat {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 1rem;
  min-width: 110px;
}

.preview-stat-warn {
  background: var(--warning-soft);
  border-color: rgba(245, 158, 11, 0.25);
}

.preview-stat-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.preview-stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.preview-col-tag {
  margin: 0.125rem 0.25rem 0.125rem 0;
  font-size: 0.75rem;
}

.preview-col-new {
  background: var(--success-soft) !important;
  color: var(--success) !important;
  border-color: rgba(16, 185, 129, 0.25) !important;
}

.preview-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 520px;
  overflow: auto;
}

.preview-diff-table {
  min-width: max-content;
}

.preview-diff-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  font-size: 0.7rem;
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-diff-table .preview-row-num {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--bg-subtle);
  white-space: nowrap;
}

.preview-diff-table tbody td.preview-row-num {
  background: var(--bg-card, var(--bg-subtle));
  z-index: 1;
}

.preview-diff-table thead th.preview-row-num {
  z-index: 4;
}

.preview-col-changed {
  color: var(--accent, #4f46e5);
}

.preview-row-new {
  box-shadow: inset 3px 0 0 var(--success, #10b981);
}

.preview-cell-changed {
  background: var(--accent-soft) !important;
}

.preview-after {
  font-weight: 600;
  color: var(--text-primary);
}

.preview-before {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

[data-theme="dark"] .chat-messages {
  background: var(--bg-code);
}

[data-theme="dark"] .preview-cell-changed {
  background: rgba(129, 140, 248, 0.12) !important;
}

/* --- Pipeline passo a passo --- */
.pipeline-panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.pipeline-view-toggle .btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
}

.pipeline-steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.pipeline-step-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  background: var(--bg-subtle);
}

.pipeline-step-disabled {
  opacity: 0.55;
}

.pipeline-step-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.pipeline-step-order {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
}

.pipeline-step-title {
  font-size: 0.875rem;
  color: var(--text-primary);
}

.pipeline-step-summary {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.pipeline-step-details {
  margin-top: 0.5rem;
  padding-left: 1.125rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.pipeline-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.pipeline-empty svg {
  width: 2rem;
  height: 2rem;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.pipeline-script-view {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pipeline-script-toolbar {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pipeline-script-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  min-height: 22rem;
  max-height: 36rem;
  resize: vertical;
  background: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border);
  white-space: pre;
  tab-size: 4;
}

.pipeline-script-pre {
  margin: 0;
  max-height: 28rem;
  overflow: auto;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre;
}

.pipeline-script-pre code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  padding: 0;
}

/* --- Formulários centralizados (criar layout, etc.) --- */
.page-form-center {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  padding: 0.25rem 0 2rem;
}

.page-form-card {
  width: 100%;
  max-width: 40rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.page-form-card .card-header {
  padding: 1.25rem 1.5rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}

.page-form-card .card-header h2 {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--text-primary);
}

.page-form-card .card-header p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.page-form-card .card-body {
  padding: 1.5rem 1.75rem 1.75rem;
}

.page-form-back {
  max-width: 40rem;
  margin: 0 auto 1rem;
}

@media (min-width: 992px) {
  .page-form-center {
    align-items: center;
    min-height: calc(100vh - 11rem);
    padding-bottom: 3rem;
  }
}

@media (max-width: 575.98px) {
  .page-form-card .card-body {
    padding: 1.25rem 1.25rem 1.5rem;
  }
}

/* Blocos incrementais de pipeline */
.step-block-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
}
.step-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.step-block-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.step-block-prompt {
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}
.step-block-steps {
  max-height: 280px;
  overflow-y: auto;
  padding-left: 0;
}
.step-block-steps .pipeline-step-item {
  font-size: 0.9em;
}

/* Drag & drop — partes e steps */
.step-block-drag-handle,
.step-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.step-block-drag-handle:hover,
.step-drag-handle:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.step-block-drag-handle:active,
.step-drag-handle:active {
  cursor: grabbing;
  transform: scale(1.08);
}
.step-block-drag-handle svg,
.step-drag-handle svg {
  width: 1rem;
  height: 1rem;
}
.step-block-card.sortable-ghost {
  opacity: 0.35;
  transform: scale(0.98);
  border-style: dashed;
  background: var(--accent-soft);
}
.step-block-card.sortable-chosen {
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  border-color: var(--accent);
  z-index: 5;
}
.step-block-card.sortable-drag {
  opacity: 1;
  transform: scale(1.02) rotate(0.4deg);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}
.pipeline-step-item.sortable-ghost {
  opacity: 0.4;
  background: var(--accent-soft);
  border-style: dashed;
}
.pipeline-step-item.sortable-chosen {
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  border-color: var(--accent);
  z-index: 4;
}
.pipeline-step-item.sortable-drag {
  opacity: 1;
  transform: scale(1.02);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}
#step-blocks-sortable.sortable-busy,
[data-steps-sortable].sortable-busy {
  pointer-events: none;
}
#step-blocks-sortable.sortable-busy::after {
  content: "Atualizando ordem…";
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem 0 0.25rem;
}
[data-theme="dark"] .step-block-card.sortable-chosen,
[data-theme="dark"] .step-block-card.sortable-drag,
[data-theme="dark"] .pipeline-step-item.sortable-chosen,
[data-theme="dark"] .pipeline-step-item.sortable-drag {
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}
