/* ==========================================================================
   Central de Processos e Roteiros
   Design System & Aplicação (v2.0.0)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variáveis e Design Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Identidade & Tons Principais */
  --brand: #f9d406;
  --brand-hover: #eab308;
  --brand-deep: #ca8a04;
  --brand-tint: #fffbeb;
  --brand-tint-strong: #fef3c7;
  --brand-ink: #171300;

  /* Superfícies & Fundo */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-subtle: #f1f5f9;

  /* Tipografia & Cores de Texto */
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --muted-light: #94a3b8;

  /* Estados & Semântica */
  --success: #16a34a;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-ink: #065f46;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-ink: #92400e;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-ink: #991b1b;

  --info: #0284c7;
  --info-bg: #f0f9ff;
  --info-border: #bae6fd;
  --info-ink: #0369a1;

  /* Setores */
  --compras: #8b5cf6;
  --compras-bg: #f5f3ff;
  --comercial: #f59e0b;
  --comercial-bg: #fffbeb;
  --financeiro: #10b981;
  --financeiro-bg: #ecfdf5;
  --logistica: #3b82f6;
  --logistica-bg: #eff6ff;

  /* Sombras & Profundidade */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, 0.1), 0 4px 10px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 24px 60px rgba(15, 23, 42, 0.18), 0 8px 20px rgba(15, 23, 42, 0.06);

  /* Dimensões */
  --topbar-height: 64px;
  --sidebar-width: 240px;
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 9999px;

  /* Transições */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Modo Escuro */
.dark {
  --bg: #090e17;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --surface-3: #334155;
  --border: #1e293b;
  --border-strong: #334155;
  --border-subtle: #131c2e;

  --ink: #f8fafc;
  --ink-secondary: #cbd5e1;
  --muted: #94a3b8;
  --muted-light: #64748b;

  --brand-tint: #231d04;
  --brand-tint-strong: #3d350c;

  --success-bg: #064e3b;
  --success-border: #047857;
  --success-ink: #a7f3d0;

  --warning-bg: #451a03;
  --warning-border: #78350f;
  --warning-ink: #fde68a;

  --danger-bg: #450a0a;
  --danger-border: #7f1d1d;
  --danger-ink: #fecaca;

  --info-bg: #082f49;
  --info-border: #075985;
  --info-ink: #bae6fd;

  --compras-bg: #2e1065;
  --comercial-bg: #451a03;
  --financeiro-bg: #064e3b;
  --logistica-bg: #1e3a8a;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 24px 64px rgba(0, 0, 0, 0.7);
}

/* --------------------------------------------------------------------------
   2. Reset e Tipografia Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  line-height: 1;
  display: inline-block;
  user-select: none;
}

/* Acessibilidade: Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 20px;
  background: var(--brand);
  color: var(--brand-ink);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  z-index: 1000;
  transition: top var(--transition-fast);
}
.skip-link:focus {
  top: 16px;
  outline: 3px solid var(--ink);
}

/* Foco acessível */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   3. Barra Superior (Topbar)
   -------------------------------------------------------------------------- */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-xs);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.topbar-inner {
  height: 100%;
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  border-radius: var(--radius-md);
  padding: 4px 6px;
  transition: opacity var(--transition-fast);
}
.brand:hover {
  opacity: 0.9;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(234, 179, 8, 0.25);
  font-variation-settings: 'FILL' 1;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0.06em;
}
.brand-line strong {
  font-weight: 800;
}
.brand-line em {
  font-style: normal;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: var(--brand);
  color: var(--brand-ink);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.brand-copy small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.portal-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 7px 13px;
  border-radius: var(--radius-md);
  background: var(--brand-tint);
  color: var(--brand-deep);
  border: 1px solid var(--border-strong);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.portal-back-btn:hover {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: var(--brand-hover);
  transform: translateY(-1px);
}
.portal-back-btn .material-symbols-outlined {
  font-size: 16px;
}
html.dark .portal-back-btn {
  background: rgba(249, 212, 6, 0.12);
  color: #f9d406;
  border-color: rgba(249, 212, 6, 0.3);
}
html.dark .portal-back-btn:hover {
  background: #f9d406;
  color: #000;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.icon-button:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.icon-button:active {
  transform: scale(0.95);
}
.icon-button.danger {
  color: var(--danger);
}
.icon-button.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.top-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
  box-shadow: var(--shadow-xs);
  letter-spacing: -0.02em;
}

.user-copy {
  display: flex;
  flex-direction: column;
}
.user-copy strong {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}
.user-copy small {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* --------------------------------------------------------------------------
   4. Estrutura Principal (Sidebar + Workspace)
   -------------------------------------------------------------------------- */
.app-shell {
  min-height: calc(100vh - var(--topbar-height));
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

.sidebar {
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-xs);
}

.sidebar-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted-light);
  padding: 6px 12px 6px;
  user-select: none;
}
.sectors-label {
  margin-top: 16px;
}

.nav-item {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
  position: relative;
}
.nav-item .material-symbols-outlined {
  font-size: 20px;
  color: var(--muted);
  transition: color var(--transition-fast);
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav-item:hover .material-symbols-outlined {
  color: var(--ink);
}

.nav-item.active {
  background: var(--brand-tint-strong);
  color: var(--ink);
  font-weight: 800;
}
.dark .nav-item.active {
  background: var(--brand-tint-strong);
  color: #fef08a;
}
.nav-item.active .material-symbols-outlined {
  color: var(--brand-deep);
}
.dark .nav-item.active .material-symbols-outlined {
  color: #facc15;
}

.nav-count {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
  color: var(--muted);
}
.nav-item.active .nav-count {
  color: var(--ink);
}

#approvalBadge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--warning);
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
}

.sector-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent);
}
.sector-dot { background: var(--dot, var(--muted)); color: var(--dot, var(--muted)); }
.sidebar-empty { font-size: 12px; color: var(--muted); padding: 4px 12px 8px; margin: 0; }
.logout-form { display: contents; }

.sidebar-foot {
  margin-top: auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.sidebar-foot .material-symbols-outlined {
  font-size: 22px;
  color: var(--brand-deep);
}
.dark .sidebar-foot .material-symbols-outlined {
  color: var(--brand);
}
.sidebar-foot strong {
  display: block;
  font-size: 11px;
  color: var(--ink);
  font-weight: 700;
}
.sidebar-foot small {
  display: block;
  font-size: 9px;
  margin-top: 1px;
  line-height: 1.3;
}

.workspace {
  min-width: 0;
  padding: 34px clamp(24px, 4vw, 56px) 64px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   5. Cabeçalhos de Página e Botões Globais
   -------------------------------------------------------------------------- */
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.page-heading.compact {
  align-items: flex-start;
  margin-bottom: 20px;
}

.heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--brand-deep);
  display: flex;
  align-items: center;
  gap: 8px;
}
.dark .eyebrow {
  color: #facc15;
}

.page-heading h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1.15;
}
.page-heading p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 720px;
}

/* Botões do Design System */
.primary-button, .secondary-button, .tool-button {
  min-height: 40px;
  border-radius: var(--radius-md);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.primary-button {
  background: linear-gradient(135deg, #facc15 0%, var(--brand) 100%);
  color: var(--brand-ink);
  border: 1px solid #eab308;
  box-shadow: 0 3px 10px rgba(234, 179, 8, 0.25);
}
.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(234, 179, 8, 0.35);
  filter: brightness(1.02);
}
.primary-button:active {
  transform: translateY(0);
}
.primary-button.danger {
  background: var(--danger);
  border-color: var(--danger-hover);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(220, 38, 38, 0.3);
}
.primary-button.danger:hover {
  background: var(--danger-hover);
  box-shadow: 0 5px 14px rgba(220, 38, 38, 0.4);
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink-secondary);
  box-shadow: var(--shadow-xs);
}
.secondary-button:hover {
  border-color: var(--muted-light);
  background: var(--surface-2);
  color: var(--ink);
}
.secondary-button.danger {
  color: var(--danger);
  border-color: var(--danger-border);
}
.secondary-button.danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.link-button {
  background: none;
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.link-button:hover {
  color: var(--ink);
  background: var(--surface-2);
}
.link-button .material-symbols-outlined {
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   6. Faixa de Estatísticas (Stats Strip)
   -------------------------------------------------------------------------- */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
  text-decoration: none;
}
a.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 22px;
  background: var(--surface-2);
  color: var(--muted);
  flex-shrink: 0;
}
.stat-card.tone-brand .stat-icon {
  background: var(--brand-tint-strong);
  color: var(--brand-deep);
}
.dark .stat-card.tone-brand .stat-icon {
  color: #facc15;
}
.stat-card.tone-success .stat-icon {
  background: var(--success-bg);
  color: var(--success);
}
.stat-card.tone-warning .stat-icon {
  background: var(--warning-bg);
  color: var(--warning);
}

.stat-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stat-copy strong {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--ink);
}
.stat-copy span {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-secondary);
  margin-top: 2px;
}
.stat-copy small {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-go {
  margin-left: auto;
  color: var(--muted-light);
  font-size: 18px;
  transition: transform var(--transition-fast), color var(--transition-fast);
}
a.stat-card:hover .stat-go {
  color: var(--ink);
  transform: translateX(3px);
}

/* --------------------------------------------------------------------------
   7. Barra de Ferramentas e Filtros da Biblioteca
   -------------------------------------------------------------------------- */
.library-tools {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.searchbar {
  height: 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: text;
}
.searchbar:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249, 212, 6, 0.22);
}
.searchbar > .material-symbols-outlined {
  color: var(--muted-light);
  font-size: 22px;
}
.searchbar input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  height: 100%;
  padding: 0 12px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.searchbar input::placeholder {
  color: var(--muted-light);
}

.search-clear {
  color: var(--muted);
  padding: 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: color var(--transition-fast);
}
.search-clear:hover {
  color: var(--ink);
}
.search-clear .material-symbols-outlined {
  font-size: 18px;
}

.searchbar kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  padding: 3px 6px;
  margin-left: 6px;
  user-select: none;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--surface-2);
}
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-xs);
}
.dark .chip.active {
  background: #f8fafc;
  border-color: #f8fafc;
  color: #0f172a;
}
.chip-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   8. Grid de Roteiros e Cards
   -------------------------------------------------------------------------- */
.route-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}

.route-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 220px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
  position: relative;
  outline: none;
  animation: card-appear 0.25s ease backwards;
  animation-delay: calc(var(--i, 0) * 0.03s);
}
@keyframes card-appear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.route-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.route-card:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249, 212, 6, 0.35);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sector-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.05em;
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: uppercase;
}
.status-tag .material-symbols-outlined {
  font-size: 13px;
}
.status-tag.published {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-ink);
}
.status-tag.draft {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-ink);
}
.status-tag.warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-ink);
}

.route-card h3 {
  margin: 16px 0 8px;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.route-card > p {
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}
.card-metrics span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card-metrics .material-symbols-outlined {
  font-size: 14px;
}
.card-metrics .metric-warning {
  color: var(--warning);
}

.card-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.card-open {
  color: var(--brand-deep);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  transition: transform var(--transition-fast);
}
.dark .card-open {
  color: #facc15;
}
.route-card:hover .card-open {
  transform: translateX(3px);
}
.card-open .material-symbols-outlined {
  font-size: 16px;
}

/* Marcação de busca */
mark {
  background: #fde68a;
  color: #171300;
  padding: 0 2px;
  border-radius: 2px;
}
.dark mark {
  background: #ca8a04;
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   9. Estados Vazios e Skeletons
   -------------------------------------------------------------------------- */
.empty-state {
  padding: 72px 24px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.empty-icon {
  font-size: 48px;
  color: var(--muted-light);
  margin-bottom: 12px;
}
.empty-state h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
}
.empty-state p {
  margin: 0 0 16px;
  font-size: 12px;
  max-width: 440px;
}

/* Skeletons */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-color: var(--border) !important;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
   10. Área de Governança & Propostas
   -------------------------------------------------------------------------- */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  margin-bottom: 20px;
}
.segmented button {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}
.segmented button:hover {
  color: var(--ink);
}
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}
.segmented .material-symbols-outlined {
  font-size: 16px;
}

.proposal-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.proposal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  box-shadow: var(--shadow-xs);
}
.proposal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}
.proposal-main h3 {
  margin: 8px 0 6px;
  font-size: 16px;
  font-weight: 800;
}
.proposal-reason {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.proposal-review {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.proposal-review.approved {
  background: var(--success-bg);
  color: var(--success-ink);
}
.proposal-review.rejected {
  background: var(--danger-bg);
  color: var(--danger-ink);
}

.proposal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   11. Documento RO (Roteiro Operacional)
   -------------------------------------------------------------------------- */
.sector-workspace-nav {
  min-height: 54px;
  margin: -4px 0 22px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: var(--shadow-xs);
}

.sector-view-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sector-view-tab {
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  transition: all var(--transition-fast);
}
.sector-view-tab:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.sector-view-tab.active {
  background: var(--brand-tint-strong);
  color: var(--brand-ink);
}
.dark .sector-view-tab.active {
  color: #fde68a;
}
.sector-nav-hint {
  font-size: 11px;
  color: var(--muted);
  padding-right: 12px;
}

.ro-panel {
  max-width: 1100px;
  margin: 0 auto;
}
.ro-loading {
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.ro-loading .material-symbols-outlined {
  color: var(--brand-deep);
  animation: ro-spin 1s linear infinite;
}
@keyframes ro-spin {
  to { transform: rotate(360deg); }
}

.ro-document {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.ro-cover {
  position: relative;
  padding: 38px 44px 34px;
  border-top: 6px solid var(--brand);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
}
.ro-brand-line > div { display: grid; gap: 2px; }
.ro-brand-line small { font-size: 11px; letter-spacing: .08em; color: var(--muted); }
.ro-brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}
.ro-code {
  position: absolute;
  right: 44px;
  top: 38px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
}
.ro-cover h2 {
  margin: 0;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: -0.04em;
}
.ro-cover > p:not(.eyebrow) {
  max-width: 740px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.ro-metadata {
  display: flex;
  gap: 0;
  margin: 28px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.ro-metadata > div {
  min-width: 140px;
  padding-right: 24px;
  margin-right: 24px;
  border-right: 1px solid var(--border);
}
.ro-metadata > div:last-child {
  border-right: 0;
}
.ro-metadata dt {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  color: var(--muted-light);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.ro-metadata dd {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 800;
}

.ro-toc {
  margin: 28px 44px;
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.ro-toc h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: var(--muted);
}
.ro-toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
.ro-toc button {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  transition: background var(--transition-fast);
}
.ro-toc button:hover {
  background: var(--surface);
}
.ro-toc button span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--brand-deep);
}
.ro-toc button small {
  margin-left: auto;
  font-size: 9px;
  color: var(--muted);
}

.ro-purpose {
  margin: 28px 44px;
  padding: 18px 22px;
  border-left: 4px solid var(--brand);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--surface-2);
}
.ro-purpose h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 800;
}
.ro-purpose p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.ro-process {
  margin: 0 44px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.ro-process-header {
  padding: 18px 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}
.ro-process-header > div:first-child > span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  color: var(--brand-deep);
  letter-spacing: 0.1em;
}
.ro-process-header h3 {
  margin: 4px 0;
  font-size: 17px;
  font-weight: 800;
}
.ro-process-header p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}
.ro-process-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ro-responsible-group {
  padding: 22px;
}
.ro-responsible-group + .ro-responsible-group {
  border-top: 1px solid var(--border);
}
.ro-responsible-group > h4 {
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ro-responsible-group > h4 .material-symbols-outlined {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--brand-tint-strong);
  color: var(--brand-deep);
  display: grid;
  place-items: center;
  font-size: 16px;
}
.ro-responsible-group > h4 small {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--muted);
}

.ro-activity-list {
  display: flex;
  flex-direction: column;
}
.ro-activity {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 14px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.ro-activity:first-child {
  border-top: 0;
  padding-top: 0;
}
.ro-activity:last-child {
  padding-bottom: 0;
}

.ro-activity-number {
  width: 34px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  color: var(--brand-deep);
}
.ro-activity-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.ro-activity h5 {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
}
.ro-type {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.ro-type.type-start { color: var(--success); border-color: var(--success-border); }
.ro-type.type-gateway { color: var(--compras); border-color: #ddd6fe; }
.ro-type.type-end { color: var(--danger); border-color: var(--danger-border); }

.ro-activity-body > p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}
.ro-sequence {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  margin-top: 10px;
  font-size: 10px;
}
.ro-sequence > span:first-child {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  color: var(--muted-light);
  letter-spacing: 0.1em;
  padding-top: 2px;
}
.ro-next-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ro-next-list li::before {
  content: '→';
  margin-right: 5px;
  color: var(--brand-deep);
  font-weight: 900;
}
.ro-next-list em {
  font-style: normal;
  color: var(--muted);
}
.ro-end-note {
  color: var(--muted-light);
  font-style: italic;
}

.ro-image {
  max-width: 600px;
  margin: 12px 0 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.ro-image img {
  display: block;
  max-width: 100%;
  max-height: 340px;
  margin: 0 auto;
  border-radius: var(--radius-sm);
}
.ro-image figcaption {
  margin-top: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 9px;
}
.ro-footer {
  min-height: 56px;
  padding: 0 44px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   12. Editor Visual do Fluxograma
   -------------------------------------------------------------------------- */
.modal-layer, .drawer-layer, .dialog-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.editor-panel {
  position: absolute;
  inset: 16px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scale-up 0.22s var(--transition-normal);
}
@keyframes scale-up {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

.editor-header {
  height: 64px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dirty-dot {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  color: var(--warning);
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.dirty-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
}

.readonly-banner {
  padding: 10px 22px;
  background: var(--brand-tint-strong);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
}
.readonly-banner .banner-icon {
  font-size: 20px;
  color: var(--brand-deep);
}
.readonly-banner .banner-copy p {
  margin: 2px 0 0;
  color: var(--muted);
}
.diff-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.diff-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
}
.diff-chip.added { background: var(--success-bg); border-color: var(--success-border); color: var(--success-ink); }
.diff-chip.changed { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-ink); }
.diff-chip.removed { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-ink); }

.editor-meta {
  padding: 12px 22px;
  display: grid;
  grid-template-columns: 2fr 1fr 3fr;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.editor-meta label {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.editor-meta label > span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.editor-meta input, .editor-meta select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.editor-meta input:focus, .editor-meta select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249, 212, 6, 0.22);
}

.flow-toolbar {
  height: 50px;
  flex-shrink: 0;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
}
.tool-group.selection-tools {
  border-right: none;
  padding-left: 6px;
}

.tool-button {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}
.tool-button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--ink);
}
.tool-button.active {
  background: var(--brand-tint-strong);
  border-color: var(--brand);
  color: var(--brand-ink);
}
.tool-button.danger {
  color: var(--danger);
}
.tool-button.danger:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}
.tool-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tool-button.icon-only {
  width: 32px;
  padding: 0;
  justify-content: center;
}
.tool-button .material-symbols-outlined {
  font-size: 18px;
}

.toolbar-tip {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 12px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.zoom-label {
  padding: 0 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
}
.zoom-controls .tool-button {
  border: none;
  background: transparent;
  height: 26px;
  width: 26px;
}
.zoom-controls .tool-button:hover {
  background: var(--surface);
}

/* --------------------------------------------------------------------------
   13. Viewport, Canvas & Linhas SVG do Fluxograma
   -------------------------------------------------------------------------- */
.flow-viewport {
  position: relative;
  flex: 1;
  min-height: 340px;
  overflow: auto;
  background-color: var(--bg);
  background-image: radial-gradient(var(--border-strong) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: default;
}
.flow-viewport.panning {
  cursor: grab;
  cursor: -webkit-grab;
}
.flow-viewport.panning:active {
  cursor: grabbing;
  cursor: -webkit-grabbing;
}
.flow-viewport.is-connecting {
  cursor: crosshair;
}

.flow-stage {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}
.flow-scene {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#flowLanes, #flowLines, #flowCanvas {
  position: absolute;
  left: 0;
  top: 0;
}
#flowLanes {
  z-index: 1;
  pointer-events: none;
}
#flowLines {
  z-index: 2;
  overflow: visible;
}
#flowCanvas {
  z-index: 3;
}

/* Raias (Swimlanes) */
.flow-lane {
  position: absolute;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.45);
  pointer-events: auto;
  box-sizing: border-box;
}
.dark .flow-lane {
  background: rgba(15, 23, 42, 0.45);
}
.flow-lane.lane-0 { border-color: #cbd5e1; }
.flow-lane.lane-1 { border-color: #cbd5e1; background: rgba(248, 250, 252, 0.6); }
.flow-lane.lane-2 { border-color: #fde68a; background: rgba(254, 243, 199, 0.3); }
.flow-lane.lane-3 { border-color: #bfdbfe; background: rgba(239, 246, 255, 0.3); }

.flow-lane-label {
  height: 44px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(241, 245, 249, 0.85);
  backdrop-filter: blur(2px);
  border-top-left-radius: calc(var(--radius-lg) - 2px);
  border-top-right-radius: calc(var(--radius-lg) - 2px);
}
.dark .flow-lane-label {
  background: rgba(30, 41, 59, 0.85);
}
.lane-label-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.lane-label-inner .material-symbols-outlined {
  font-size: 18px;
  color: var(--brand-deep);
}
.lane-name {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink);
}
.lane-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--muted);
  margin-left: 4px;
}
.lane-action {
  padding: 4px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  display: grid;
  place-items: center;
}
.lane-action:hover {
  background: var(--surface);
  color: var(--ink);
}
.lane-action.danger {
  margin-left: auto;
}
.lane-action.danger:hover {
  color: var(--danger);
  background: var(--danger-bg);
}
.lane-action .material-symbols-outlined {
  font-size: 15px;
}

/* Conexões (Linhas SVG) */
.flow-edge {
  cursor: pointer;
}
.flow-edge-hit {
  stroke: transparent;
  stroke-width: 18;
  fill: none;
}
.flow-line {
  stroke: var(--muted-light);
  stroke-width: 2.2;
  fill: none;
  marker-end: url(#arrow);
  transition: stroke var(--transition-fast), stroke-width var(--transition-fast);
}
.flow-edge:hover .flow-line {
  stroke: var(--ink-secondary);
  stroke-width: 3;
}
.flow-edge.selected .flow-line {
  stroke: var(--brand-deep);
  stroke-width: 3.2;
  marker-end: url(#arrow-active);
}
.dark .flow-edge.selected .flow-line {
  stroke: #facc15;
}
.flow-line.preview {
  stroke: var(--brand);
  stroke-dasharray: 6 4;
  stroke-width: 2.5;
  pointer-events: none;
}

.arrow-head {
  fill: var(--muted-light);
}
.arrow-head.active {
  fill: var(--brand-deep);
}
.dark .arrow-head.active {
  fill: #facc15;
}

.flow-label rect {
  fill: var(--surface);
  stroke: var(--border-strong);
  stroke-width: 1;
}
.flow-label text {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 800;
  fill: var(--ink-secondary);
}
.flow-edge.selected .flow-label rect {
  border-color: var(--brand-deep);
  fill: var(--brand-tint-strong);
}

/* --------------------------------------------------------------------------
   14. Etapas do Fluxo (Flow Nodes)
   -------------------------------------------------------------------------- */
.flow-node {
  position: absolute;
  min-width: 180px;
  min-height: 110px;
  max-width: 520px;
  max-height: 520px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-md);
  padding: 10px 12px 34px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  user-select: none;
  cursor: grab;
  box-sizing: border-box;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.flow-node:hover {
  border-color: var(--muted-light);
  box-shadow: var(--shadow-md);
}
.flow-node.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-xl);
  opacity: 0.95;
  z-index: 10;
}
.flow-node.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249, 212, 6, 0.4), var(--shadow-md);
  z-index: 9;
}
.flow-node.connect-source {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}
.flow-node.connect-target {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.4);
}
.flow-node.drop-target {
  border-color: var(--brand);
  background: var(--brand-tint);
}
.flow-node.is-orphan {
  border-style: dashed;
}

/* Tipos de Etapa */
.flow-node.node-start { border-left-color: var(--success); }
.flow-node.node-end { border-left-color: var(--danger); }
.flow-node.node-gateway {
  border-left-color: var(--compras);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(245, 243, 255, 0.5) 100%);
}
.dark .flow-node.node-gateway {
  background: linear-gradient(135deg, var(--surface) 0%, rgba(46, 16, 101, 0.3) 100%);
}

.node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}
.node-step {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  color: var(--brand-deep);
  letter-spacing: 0.08em;
}
.dark .node-step {
  color: #facc15;
}

.diff-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
}
.diff-badge.added { background: var(--success-bg); color: var(--success); }
.diff-badge.changed { background: var(--warning-bg); color: var(--warning); }

.orphan-flag {
  font-size: 14px;
  color: var(--warning);
}

.node-type {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
}
.node-type select {
  border: none;
  background: transparent;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
  cursor: pointer;
  outline: none;
}
.node-type select:hover {
  color: var(--ink);
}
.node-type.is-static {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
}
.node-type .material-symbols-outlined {
  font-size: 14px;
}

.flow-node .node-title {
  width: 100%;
  min-height: 34px;
  height: 34px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  resize: none;
  overflow: hidden;
  padding: 0;
}
.flow-node .node-description {
  width: 100%;
  min-height: 32px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  padding: 0;
  margin-top: 4px;
}

.node-image-wrap {
  position: relative;
  flex: 1;
  min-height: 60px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.node-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-chip {
  position: absolute;
  top: 4px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.75);
  color: #ffffff;
  display: grid;
  place-items: center;
  transition: background var(--transition-fast);
}
.image-chip:hover {
  background: rgba(15, 23, 42, 0.95);
}
.image-chip .material-symbols-outlined {
  font-size: 14px;
}
.image-open { right: 28px; }
.image-remove { right: 4px; }

.node-actions {
  position: absolute;
  left: 8px;
  right: 18px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.node-action {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}
.node-action:hover {
  border-color: var(--brand);
  background: var(--brand-tint-strong);
  color: var(--brand-ink);
}
.node-action.danger {
  margin-left: auto;
}
.node-action.danger:hover {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}
.node-action .material-symbols-outlined {
  font-size: 15px;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--muted-light) 50%, var(--muted-light) 65%, transparent 65%, transparent 80%, var(--muted-light) 80%);
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}
.flow-node:hover .resize-handle {
  opacity: 1;
}

/* Portas de Conexão */
.node-port {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--muted-light);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}
.flow-node:hover .node-port, .flow-viewport.is-connecting .node-port {
  opacity: 1;
}
/* Bolinha: arrastar conecta a outra etapa; clicar cria uma etapa nova ligada naquele lado.
   "scale" (e não transform) para não perder o translate que centraliza a bolinha na borda. */
.node-port {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: opacity var(--transition-fast), scale var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}
.node-port::after {
  content: '+';
  font: 900 9px/1 'Inter', system-ui, sans-serif;
  color: var(--brand-ink);
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}
.node-port:hover {
  border-color: var(--brand);
  background: var(--brand);
  scale: 1.75;
}
.node-port:hover::after {
  opacity: 1;
}
.port-t { top: -6px; left: 50%; transform: translateX(-50%); }
.port-r { right: -6px; top: 50%; transform: translateY(-50%); }
.port-b { bottom: -6px; left: 50%; transform: translateX(-50%); }
.port-l { left: -6px; top: 50%; transform: translateY(-50%); }

/* Rodapé do Editor */
.editor-footer {
  min-height: 60px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
}
.footer-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}
.flow-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-secondary);
}
.stat-warning {
  color: var(--warning);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   15. Gaveta de Histórico e Linha do Tempo
   -------------------------------------------------------------------------- */
.history-drawer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  padding: 0 24px;
  overflow-y: auto;
  animation: slide-in 0.25s var(--transition-normal);
}
@keyframes slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.history-drawer header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.history-drawer h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.history-content {
  padding: 20px 0;
}
.history-section-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted-light);
  font-weight: 800;
  margin: 18px 0 10px;
}

.timeline-item {
  position: relative;
  margin-left: 8px;
  padding: 0 0 20px 22px;
  border-left: 1px solid var(--border);
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--surface);
}
.timeline-item.version.current::before {
  background: var(--success);
}
.timeline-item.activity::before {
  background: var(--muted-light);
}

.timeline-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.timeline-head strong {
  font-size: 13px;
  font-weight: 800;
}
.timeline-item p {
  margin: 4px 0 2px;
  font-size: 11px;
  color: var(--ink-secondary);
}
.timeline-item small {
  font-size: 10px;
  color: var(--muted);
}
.timeline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.timeline-skeleton {
  height: 54px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: 12px;
}

/* --------------------------------------------------------------------------
   16. Modal de Diálogo e Confirmação
   -------------------------------------------------------------------------- */
.dialog-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, 92vw);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 28px;
  animation: dialog-pop 0.22s var(--transition-bounce);
}
@keyframes dialog-pop {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.dialog-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--brand-deep);
  display: grid;
  place-items: center;
  font-size: 24px;
  margin-bottom: 16px;
}
[data-tone="danger"] .dialog-icon {
  background: var(--danger-bg);
  color: var(--danger);
}
[data-tone="warning"] .dialog-icon {
  background: var(--warning-bg);
  color: var(--warning);
}

.dialog-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
}
.dialog-card p {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.dialog-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.dialog-label {
  font-size: 11px;
  font-weight: 700;
}
.dialog-field input, .dialog-field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  outline: none;
  background: var(--surface);
  font-size: 12px;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.dialog-field input:focus, .dialog-field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249, 212, 6, 0.22);
}
.dialog-hint {
  font-size: 9px;
  color: var(--muted);
  text-align: right;
}
.dialog-error {
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 12px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* --------------------------------------------------------------------------
   17. Notificações Flutuantes (Toast Stack)
   -------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--ink);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 420px;
}
.toast.leaving {
  opacity: 0;
  transform: translateY(8px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.error {
  background: var(--danger);
}
.toast.info {
  background: #0284c7;
}
.toast.warning {
  background: #d97706;
}
.toast .material-symbols-outlined {
  font-size: 20px;
}
.toast-text {
  flex: 1;
}
.toast-action {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 800;
  margin-left: 8px;
  transition: background var(--transition-fast);
}
.toast-action:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* --------------------------------------------------------------------------
   18. Responsividade & Impressão
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .editor-meta {
    grid-template-columns: 1fr 1fr;
  }
  .editor-meta label.wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }
  .sidebar-title, .sidebar-foot {
    display: none;
  }
  .nav-item {
    width: auto;
    flex-shrink: 0;
  }
  .workspace {
    padding: 20px 16px 40px;
  }
  .editor-panel {
    inset: 8px;
  }
  .toolbar-tip, .user-copy {
    display: none;
  }
}

@media (max-width: 640px) {
  .page-heading {
    flex-direction: column;
    align-items: flex-start;
  }
  .heading-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .route-grid {
    grid-template-columns: 1fr;
  }
  .editor-meta {
    grid-template-columns: 1fr;
  }
  .flow-toolbar {
    overflow-x: auto;
  }
  .editor-footer .footer-info {
    display: none;
  }
  .proposal-card {
    grid-template-columns: 1fr;
  }
  .proposal-actions {
    justify-content: flex-end;
  }
  .ro-cover {
    padding: 24px 20px;
  }
  .ro-metadata {
    flex-direction: column;
    gap: 12px;
  }
  .ro-purpose, .ro-process, .ro-toc {
    margin-left: 12px;
    margin-right: 12px;
  }
}

/* Folha de Estilos de Impressão (A4 Profissional para RO) */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .topbar, .sidebar, .page-heading, .stats-strip, .sector-workspace-nav,
  #flowsPanel, .no-print, .toast-stack, .dialog-layer, .drawer-layer,
  .modal-layer, .skip-link {
    display: none !important;
  }
  .app-shell {
    display: block !important;
  }
  .workspace {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .view {
    display: block !important;
  }
  .ro-panel, .ro-document {
    display: block !important;
    max-width: none !important;
    border: none !important;
    box-shadow: none !important;
  }
  .ro-loading {
    display: none !important;
  }
  .ro-cover {
    padding: 15mm 15mm 10mm !important;
    border-top: 4mm solid #eab308 !important;
    page-break-after: avoid;
  }
  .ro-purpose {
    margin: 8mm 15mm !important;
    page-break-after: avoid;
  }
  .ro-process {
    margin: 0 15mm 10mm !important;
    border: 1px solid #cbd5e1 !important;
    page-break-inside: avoid;
  }
  .ro-process-header {
    background: #f8fafc !important;
  }
  .ro-responsible-group {
    padding: 6mm !important;
  }
  .ro-activity {
    page-break-inside: avoid;
  }
  .ro-image img {
    max-height: 80mm !important;
  }
  .ro-footer {
    padding: 5mm 15mm !important;
  }
}

/* Fase 2: roteiros arquivados */
.status-tag.archived { background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--muted); }
button.chip { font: inherit; cursor: pointer; }
.chip-archived { margin-left: auto; }
.chip-archived .material-symbols-outlined { font-size: 16px; }
.route-card.is-archived { opacity: .78; border-style: dashed; }

/* Fase 3: módulos fora do plano */
button.nav-item.module-locked { width: 100%; border: 0; background: none; font-family: inherit; font-size: 12px; font-weight: 700; text-align: left; cursor: pointer; color: var(--muted); }
.module-locked .module-tag { margin-left: auto; font-style: normal; font-size: 10px; font-weight: 800; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; background: var(--brand-tint-strong); color: var(--brand-deep); }
.module-locked[data-module-soon] .module-tag { background: var(--surface-2); color: var(--muted); }
.module-locked > span:not(.material-symbols-outlined) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-locked .module-tag { white-space: nowrap; flex: none; }
.sidebar { overflow-y: auto; }
.sidebar > * { flex-shrink: 0; }
.env-badge { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px; font-size: 9px; font-weight: 800; letter-spacing: .06em; font-style: normal; vertical-align: middle; background: #7c3aed; color: #fff; }
.env-badge.env-local { background: var(--surface-3); color: var(--muted); }
