/* Cadastros — mobile-first, flex layout
   Preferir tokens de tokens.css (fs/space/control/radius).
 */

/* --- Shell flex: 100% da janela (via #main-view), zero scroll de página ---
   NUNCA forçar display no seletor #view-cadastros sozinho: ID + !important
   vence .hidden e o kanban vaza em todas as telas. */
#view-cadastros:not(.hidden) {
  padding: 0 !important;
  flex: 1 1 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

#view-cadastros.hidden {
  display: none !important;
}

.cadastros-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas, var(--surface));
}

.cadastros-body {
  background: var(--surface);
  flex: 1 1 0 !important;
  min-height: 0 !important;
  max-height: 100%;
  overflow: hidden !important;
}

/* Toolbar — flex: 0 0 auto */
.cadastros-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}

.cadastros-toolbar-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 220px;
  min-width: 0;
  max-width: 420px;
}

.cadastros-toolbar-search .cadastros-search {
  flex: 1;
  min-width: 0;
}

.cadastros-filter-wrap {
  position: relative;
  flex: 0 0 auto;
}

.cadastros-filter-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  width: min(280px, 86vw);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl, var(--radius));
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.cadastros-filter-pop.hidden { display: none !important; }

.cadastros-filter-pop-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

@media (min-width: 768px) {
  .cadastros-toolbar {
    padding: var(--space-3) var(--space-5);
    gap: var(--space-3);
  }
}

/* Filtros — chips alinhados a ui-chip */
.cadastros-filters {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft, var(--surface-2));
  overflow-x: auto;
  flex: 0 0 auto;
  scrollbar-width: thin;
}

@media (min-width: 768px) {
  .cadastros-filters {
    padding: var(--space-2) var(--space-5);
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

.cadastros-filter-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

.cadastros-filter-label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium, 500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft, var(--muted));
  min-width: auto;
  padding-right: 0.15rem;
}

.cadastros-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.cadastros-chip.active,
.cadastros-chip.is-active {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  color: var(--accent);
  background: var(--accent-soft);
}

/* Segmentos — ui-seg */
.cadastros-segments {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.cadastros-seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 var(--fs-sm)/1 var(--font);
  min-height: calc(var(--control-h-sm) - 2px);
  padding: 0 var(--space-3);
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.cadastros-seg-btn.active,
.cadastros-seg-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.cadastros-search {
  flex: 1;
  min-width: 140px;
  max-width: 300px;
}

@media (min-width: 768px) {
  .cadastros-search {
    max-width: 360px;
  }
}

/* Corpo: lista/kanban rolam internamente; body NÃO cria 2º scroll horizontal */
.cadastros-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Barra de selecao */
.cadastros-selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--accent);
}

/* Lista wrap — único scroll vertical da lista */
.cadastros-list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: var(--space-3) var(--space-3) var(--space-5);
}

@media (min-width: 768px) {
  .cadastros-list-wrap {
    padding: var(--space-4) var(--space-5) var(--space-6);
  }
}

/* --- Tabela: colunas com min-width --- */
.cadastros-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
}

@media (min-width: 768px) {
  .cadastros-table {
    font-size: var(--fs-md);
  }
}

.cadastros-table th,
.cadastros-table td {
  text-align: left;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

@media (min-width: 768px) {
  .cadastros-table th,
  .cadastros-table td {
    padding: 0.4rem 0.55rem;
  }
}

.cadastros-table th {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
}

.cadastros-table tr:hover td {
  background: var(--surface-2);
}

/* Colunas com min-width */
.cadastros-check-col {
  width: 2rem;
  text-align: center;
}
.cadastros-nome-col { min-width: 120px; }
.cadastros-tel-col { min-width: 100px; }
.cadastros-cpf-col { min-width: 85px; }
.cadastros-orig-col { min-width: 75px; }
.cadastros-coluna-col { min-width: 105px; }
.cadastros-interacao-col { min-width: 110px; }
.cadastros-acoes-col { min-width: 70px; white-space: nowrap; }

@media (min-width: 768px) {
  .cadastros-nome-col { min-width: 140px; }
  .cadastros-tel-col { min-width: 110px; }
  .cadastros-cpf-col { min-width: 100px; }
  .cadastros-orig-col { min-width: 90px; }
  .cadastros-coluna-col { min-width: 120px; }
  .cadastros-interacao-col { min-width: 130px; }
  .cadastros-acoes-col { min-width: 120px; }
}

/* Tags */
.cadastros-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2xs);
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  margin-right: 0.2rem;
}

.cadastros-tag-sm {
  font-size: 0.6rem;
  padding: 0.05rem 0.3rem;
}

.cadastros-row-tags {
  margin-top: 0.15rem;
}

.cadastros-row-mobile-meta {
  display: none;
}

@media (max-width: 767px) {
  .cadastros-list-wrap {
    overflow-x: hidden;
    overflow-y: auto;
    padding-inline: var(--space-2);
  }

  .cadastros-table {
    table-layout: fixed;
  }

  .cadastros-table th,
  .cadastros-table td {
    white-space: normal;
  }

  .cadastros-tel-col,
  .cadastros-cpf-col,
  .cadastros-orig-col,
  .cadastros-coluna-col,
  .cadastros-interacao-col {
    display: none;
  }

  .cadastros-check-col {
    width: 2rem;
  }

  .cadastros-nome-col {
    min-width: 0;
    width: calc(100% - 6.5rem);
  }

  .cadastros-table thead th.cadastros-tel-col,
  .cadastros-table thead th.cadastros-cpf-col,
  .cadastros-table thead th.cadastros-orig-col,
  .cadastros-table thead th.cadastros-coluna-col,
  .cadastros-table thead th.cadastros-interacao-col {
    display: none;
  }

  .cadastros-nome-col > strong {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cadastros-acoes-col {
    min-width: 0;
    width: 4.5rem;
  }

  .cadastros-row-mobile-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0.5rem;
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: var(--fs-2xs);
  }
}

.cadastros-tag-editable {
  background: var(--accent-soft);
  color: var(--accent);
}

.cadastros-tag-remove {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.1rem;
}

.cadastros-tags-edit {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cadastros-tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.cadastros-tag-input {
  font-size: 0.8125rem;
}

.cadastros-tags-field label span {
  display: block;
  margin-bottom: 0.25rem;
}

/* Origem badge */
.cadastros-origem-badge {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border-radius: var(--radius-sm);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: capitalize;
  background: var(--surface-2);
  color: var(--muted);
}

.cadastros-origem-badge.whatsapp {
  background: #dcf8e8;
  color: #166534;
}

.cadastros-origem-badge.telefone,
.cadastros-origem-badge.presencial {
  background: #e8eef8;
  color: #1e3a5f;
}

/* Dots */
.cadastros-col-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: middle;
}

/* Acoes group */
.cadastros-actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  align-items: center;
}

/* Paginacao — flex: 0 0 auto */
.cadastros-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.8125rem;
  color: var(--muted);
  flex: 0 0 auto;
}

@media (min-width: 768px) {
  .cadastros-pagination {
    padding: 0.75rem 1rem;
  }
}

/* Skeleton: base em components.css (.skeleton shimmer); só tamanhos locais */
.skeleton-cell {
  height: 14px;
  width: 80%;
}

.skeleton-check {
  height: 14px;
  width: 14px;
  margin: 0 auto;
}

/* --- Kanban: preenche o body; só .kanban-col-body rola na vertical --- */
.cadastros-kanban-host {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  height: 100%;
}

.cadastros-kanban-host.hidden {
  display: none !important;
}

.kanban-board {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1 1 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  min-height: 0;
  min-width: 0;
  padding: var(--space-3);
  overflow: hidden;
  box-sizing: border-box;
}

.kanban-board-rows {
  flex-direction: column;
}

@media (min-width: 768px) {
  .kanban-board {
    padding: var(--space-3) var(--space-4);
  }
}

.kanban-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1 1 50%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.kanban-group-label {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0.3rem;
  flex-shrink: 0;
}

.kanban-group-cols {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.kanban-col {
  width: 320px;
  min-width: 300px;
  max-width: 360px;
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

@media (min-width: 768px) {
  .kanban-col {
    width: 340px;
    min-width: 320px;
  }
}

html.dark .kanban-col {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.kanban-col-head {
  min-height: 34px;
  padding: 0.32rem 0.38rem;
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  background: color-mix(in srgb, var(--kanban-col-color, var(--surface-2)) 38%, var(--surface));
  border-bottom: 2px solid color-mix(in srgb, var(--kanban-col-color, var(--line)) 75%, transparent);
}

html.dark .kanban-col-head {
  background: color-mix(in srgb, var(--kanban-col-color, var(--surface-2)) 50%, var(--surface));
}

.kanban-col-title {
  font-weight: 600;
  font-size: 0.74rem;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kanban-col-count {
  font-size: 0.62rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--surface) 55%, var(--kanban-col-color, var(--line)));
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  color: var(--muted);
}

.kanban-col-admin {
  display: flex;
  gap: 0.1rem;
  flex-shrink: 0;
}

.kanban-col-admin .btn-icon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
}

.kanban-col-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 0.55rem;
  padding: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Só a coluna rola verticalmente — board/groups não criam segundo scroll */
.kanban-board,
.kanban-group,
.kanban-group-cols {
  overscroll-behavior: contain;
}

.kanban-col-body.drag-over {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.kanban-add-col {
  width: 168px;
  min-height: 42px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  /* No Windows, todos os estágios ficam numa única faixa. Cada quadro
     mantém uma coluna de cards para leitura rápida e sem empilhamento lateral. */
  .kanban-board-rows {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: var(--space-2);
  }
  .kanban-board-rows > .kanban-group,
  .kanban-board-rows .kanban-group-cols {
    display: contents;
  }
  .kanban-board-rows .kanban-group-label {
    display: none;
  }
  .kanban-board-rows .kanban-col {
    width: auto;
    min-width: 0;
    max-width: none;
  }
  .kanban-board-rows .kanban-add-col {
    width: auto;
    min-width: 0;
  }

  .kanban-add-col {
    width: 176px;
    min-height: 42px;
  }
}

.kanban-add-col:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 5.25rem;
  padding: 0.55rem 0.6rem;
  margin-bottom: 0;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.15s, transform 0.15s;
}

.kanban-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.kanban-card.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

/* Nome + botão chat na mesma linha (economiza altura no quadro). */
.kanban-card-head {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
  margin-bottom: 0.08rem;
}

.kanban-card-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: 0.74rem;
  line-height: 1.25;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kanban-card-phone {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.25;
}

.kanban-card-summary {
  display: flex;
  align-items: flex-start;
  gap: 0.28rem;
  min-width: 0;
  margin-top: 0.14rem;
  font-size: 0.68rem;
  line-height: 1.25;
}

.kanban-card-summary-text {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.kanban-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin: 0.12rem 0 0;
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  margin-top: 0.16rem;
  font-size: 0.65rem;
  color: var(--muted);
}

.kanban-card .cad-ficha-chat {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  color: var(--brand);
  border: 1px solid color-mix(in srgb, var(--brand) 28%, var(--line));
  border-radius: var(--radius-sm, 6px);
  background: var(--surface-2);
}

.kanban-card .cad-ficha-chat .ico {
  width: 13px;
  height: 13px;
}

.kanban-card .cad-ficha-chat:hover {
  color: var(--surface);
  border-color: var(--brand);
  background: var(--brand);
}

/* --- Ficha flutuante (modal centrado) --- */
.cadastros-ficha {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 2rem));
  max-height: min(88vh, 720px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl, 12px);
  box-shadow: var(--shadow);
  z-index: 220;
  display: flex;
  flex-direction: column;
  transform: translate(-50%, -46%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.cadastros-ficha.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.cadastros-ficha-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.cadastros-ficha-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.cadastros-ficha-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

@media (max-width: 479px) {
  .cadastros-ficha {
    width: 100%;
    max-height: 88vh;
    top: auto;
    bottom: 0;
    left: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
  }
  .cadastros-ficha.open {
    transform: translateY(0);
  }
}

/* Overlay full-viewport para ficha flutuante */
.cadastros-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 24, 0.45);
  z-index: 210;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.cadastros-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Import preview */
.cadastros-import-preview {
  max-height: 200px;
  overflow: auto;
  margin-top: 0.65rem;
}

.cadastros-import-table {
  font-size: 0.72rem;
}

/* Dark mode ajustes */
html.dark .cadastros-seg-btn.active {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Responsivo */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }

  .cadastros-toolbar {
    padding: 0.5rem 0.6rem;
    align-items: stretch;
    flex-wrap: wrap;
  }

  .cadastros-segments {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .cadastros-seg-btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .cadastros-kanban-host {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .kanban-board {
    display: block;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .kanban-group {
    display: block;
    min-height: 0;
    overflow: visible;
    margin-bottom: var(--space-4);
  }

  .kanban-group-label {
    margin-bottom: var(--space-2);
  }

  .kanban-group-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    height: auto;
    overflow: visible;
    gap: 0.55rem;
  }

  .kanban-col {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    max-height: none;
  }
  .kanban-col-body {
    grid-template-columns: minmax(0, 1fr);
    flex: 0 1 auto;
    height: auto;
    min-height: 2.5rem;
    max-height: 18rem;
    overscroll-behavior: contain;
  }
  .kanban-col-body:has(.kanban-card) {
    min-height: 12rem;
  }
  .kanban-card { touch-action: manipulation; }
}

/* Kanban mobile — colunas mais estreitas */
@media (max-width: 479px) {
  .kanban-col {
    width: 100%;
    min-width: 0;
  }
  .kanban-board {
    padding: 0.5rem;
  }
  .kanban-add-col {
    width: 100%;
  }
}

.cadastros-orcamentos-filters {
  margin-bottom: var(--space-3);
}
.cadastros-orcamentos-filters .ui-search-wrap {
  flex: 1 1 16rem;
}
.cadastros-orcamentos-filters select {
  flex: 0 0 10rem;
}
.cadastros-orcamentos-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: var(--space-3);
}
.budget-manager-card {
  min-width: 0;
}
.budget-manager-card .guide-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}
.budget-manager-card .guide-card-head > div {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.45rem;
  min-width: 0;
}
.budget-manager-card .guide-card-head strong {
  overflow-wrap: anywhere;
}
.budget-manager-card .guide-number {
  color: var(--muted);
  font-size: var(--fs-xs);
}
.budget-manager-card .guide-status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.16rem 0.48rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
}
.budget-manager-card .guide-card-summary {
  display: grid;
  gap: var(--space-2);
}
.budget-manager-card .guide-card-summary > span {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.budget-manager-card .guide-card-summary small {
  color: var(--muted);
}
.budget-manager-card .guide-card-summary {
  grid-template-columns: minmax(7rem, auto) minmax(0, 1fr);
}
.budget-manager-card .guide-card-summary strong {
  overflow-wrap: anywhere;
}
.budget-manager-card .guide-card-actions {
  padding-top: var(--space-2);
  border-top: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
}
.budget-manager-card .guide-card-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  min-width: 0;
}
.modal-budget-manager {
  width: min(72rem, calc(100vw - 2rem));
  height: min(52rem, calc(100vh - 2rem));
}
.modal-budget-manager .modal-body,
.cadastros-budget-editor {
  min-height: 0;
  height: 100%;
  overflow: auto;
}
@media (max-width: 600px) {
  .cadastros-orcamentos-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }
  .cadastros-orcamentos-filters select {
    width: 100%;
  }
  .cadastros-orcamentos-list {
    grid-template-columns: minmax(0, 1fr);
  }
  .budget-manager-card .guide-card-summary {
    grid-template-columns: minmax(0, 1fr);
  }
  .modal-budget-manager {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }
}

/* Swatches Kanban (sem hex livre) */
.kanban-swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.kanban-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--swatch);
  cursor: pointer;
  padding: 0;
}
.kanban-swatch.is-selected,
.kanban-swatch:focus-visible {
  border-color: var(--ink);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Estágio no atendimento — feedback discreto (sem linha de status) */
.crm-stage-panel {
  margin: var(--space-4) 0;
}

.budget-stage-card {
  margin-top: var(--space-3);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl, 12px);
  background: var(--surface-soft);
}

.budget-stage-card .crm-stage-panel {
  margin: 0;
}

.crm-stage-flow {
  --stage-rail: color-mix(in srgb, var(--line) 78%, var(--surface));
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl, 12px);
  background: linear-gradient(145deg, color-mix(in srgb, var(--surface-soft) 86%, var(--surface)), var(--surface));
  box-shadow: var(--shadow-sm);
}

.crm-stage-header,
.crm-stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.crm-stage-title-area { min-width: 0; }
.crm-stage-title-area h3 {
  margin: 0;
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold, 600);
}
.crm-stage-title-area p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: var(--fs-2xs);
}
.crm-stage-current-label {
  display: none !important;
}
.crm-stage-title-area h3 {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.crm-stage-title-area .crm-stage-feedback {
  font-size: var(--fs-sm);
  color: var(--ok);
}
.crm-stage-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 20px;
  padding: 0 var(--space-2);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--line));
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.58rem;
  font-weight: var(--fw-semibold, 600);
  letter-spacing: 0.05em;
}

.crm-stage-switcher {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-4);
  padding: var(--space-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-2) 65%, transparent);
}
.crm-stage-switch {
  flex: 1 1 0;
  min-width: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-stage-switch.is-active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.crm-stage-area {
  position: relative;
  /* Nó + legenda abaixo, sem deixar a legenda dentro do botão circular. */
  min-height: 0;
  margin: var(--space-4) 0 0;
  padding: 0;
}
.crm-stage-rail {
  position: absolute;
  z-index: 0;
  top: 19px;
  right: 19px;
  left: 19px;
  height: 3px;
  transform: translateY(-50%);
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--stage-rail);
}
.crm-stage-rail-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  /* Cor viva da etapa (ou brand) — sem virar preto/cinza */
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--stage-color, var(--brand)) 78%, #fff),
    var(--stage-color, var(--brand))
  );
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.crm-stage-stepper {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}
.crm-stage-item {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1 1 0;
  min-width: 38px;
  flex-direction: column;
  align-items: center;
}
.crm-stage-step {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft, var(--muted));
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.crm-stage-step:hover:not(:disabled) {
  transform: scale(1.05);
  border-color: color-mix(in srgb, var(--stage-color, var(--brand)) 70%, var(--line));
  color: var(--stage-color, var(--brand));
  background: color-mix(in srgb, var(--stage-color, var(--brand)) 10%, var(--surface));
}
.crm-stage-step:focus-visible {
  outline: 2px solid var(--stage-color, var(--brand));
  outline-offset: 2px;
}
/* Completo: cor cheia da coluna (vida + contraste no ícone branco) */
.crm-stage-step.is-complete {
  border-color: var(--stage-color, var(--brand));
  background: var(--stage-color, var(--brand));
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--stage-color, var(--brand)) 35%, transparent);
}
/* Atual: anel + glow da cor da etapa */
.crm-stage-step.is-current {
  transform: scale(1.12);
  border-color: var(--stage-color, var(--brand));
  background: color-mix(in srgb, var(--stage-color, var(--brand)) 16%, var(--surface));
  color: var(--stage-color, var(--brand));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--stage-color, var(--brand)) 28%, transparent),
    0 0 16px color-mix(in srgb, var(--stage-color, var(--brand)) 32%, transparent);
}
html.dark .crm-stage-step.is-complete {
  color: #fff;
  background: color-mix(in srgb, var(--stage-color, var(--brand)) 88%, #0f1419);
  border-color: color-mix(in srgb, var(--stage-color, var(--brand)) 92%, #fff);
}
html.dark .crm-stage-step.is-current {
  color: color-mix(in srgb, var(--stage-color, var(--brand)) 80%, #fff);
  background: color-mix(in srgb, var(--stage-color, var(--brand)) 22%, var(--surface));
}
html.dark .crm-stage-rail-fill {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--stage-color, var(--brand)) 70%, #1a1f24),
    var(--stage-color, var(--brand))
  );
}
.crm-stage-step:disabled { cursor: wait; opacity: 0.72; }
.crm-stage-step .ico { display: block; }
.crm-stage-caption {
  display: block;
  max-width: 4.6rem;
  margin-top: var(--space-2);
  font-size: 0.58rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--muted);
  text-align: center;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.crm-stage-item.is-current .crm-stage-caption {
  color: var(--stage-color, var(--accent));
}
.crm-stage-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 4;
  max-width: 12rem;
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-2xs);
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.crm-stage-step:hover .crm-stage-tooltip,
.crm-stage-step:focus-visible .crm-stage-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.crm-stage-footer {
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}
.crm-stage-current {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.2rem var(--space-2);
  min-width: 0;
}
.crm-stage-current small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium, 500);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.crm-stage-current strong {
  min-width: 0;
  overflow: hidden;
  color: var(--stage-color, var(--brand));
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crm-stage-feedback {
  min-width: 1rem;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold, 600);
}
.crm-stage-flow.is-saving .crm-stage-feedback { color: var(--brand); }
.crm-stage-flow.is-saved .crm-stage-feedback { color: var(--ok); }
.crm-stage-flow.is-error .crm-stage-feedback { color: var(--danger); }
.crm-stage-actions { display: flex; gap: var(--space-1); flex: 0 0 auto; }
.crm-stage-action { border: 1px solid var(--line); background: var(--surface-2); }
.crm-stage-action:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); }
.crm-stage-loading,
.crm-stage-empty {
  padding: var(--space-5) var(--space-3);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: var(--fs-sm);
  text-align: center;
}

@media (max-width: 420px) {
  .crm-stage-flow { padding: var(--space-3); }
  .crm-stage-step { width: 32px; height: 32px; }
  .crm-stage-rail { top: 16px; right: 16px; left: 16px; }
  .crm-stage-step .ico { width: 14px; height: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .crm-stage-step,
  .crm-stage-rail-fill,
  .crm-stage-tooltip { transition: none; }
}


/* Emissão de guia — painel HubMed + resumo (design system) */
.emit-hubmed-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  margin-bottom: var(--space-2);
}
.emit-hubmed-panel.is-ready {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}
.emit-hubmed-panel.is-disabled { opacity: 0.78; }
.emit-hubmed-switch-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.emit-hubmed-switch-copy {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  min-width: 0;
}
.emit-hubmed-switch-copy strong {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold, 600);
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.emit-hubmed-panel .ui-switch {
  flex-shrink: 0;
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
  margin: 0;
}
.emit-hubmed-panel .ui-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.emit-hubmed-panel .ui-switch__ui {
  display: block;
  position: absolute;
  inset: 0;
  margin: 0;
  border-radius: var(--radius-pill);
  background: var(--line);
  text-transform: none;
  font-size: 0;
  letter-spacing: 0;
  transition: background 0.15s;
  cursor: pointer;
}
.emit-hubmed-panel .ui-switch__ui::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}
.emit-hubmed-panel .ui-switch input:checked + .ui-switch__ui { background: var(--accent); }
.emit-hubmed-panel .ui-switch input:checked + .ui-switch__ui::after { transform: translateX(18px); }
.emit-hubmed-panel .ui-switch input:disabled + .ui-switch__ui {
  cursor: not-allowed;
  opacity: 0.7;
}
.emit-hubmed-ready {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.emit-hubmed-ready-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.emit-hubmed-ready-left .tag-semaforo {
  width: 0.85rem;
  height: 0.85rem;
  min-width: 0.85rem;
  border-radius: 999px;
  padding: 0;
}
.emit-hubmed-ready-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.emit-hubmed-ready-copy strong {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold, 600);
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.emit-hubmed-ready-copy span {
  color: var(--muted);
  font-size: var(--fs-2xs);
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  display: block;
}
.emit-hubmed-ready .btn[aria-busy="true"] { opacity: 0.75; pointer-events: none; }
.emit-guide-summary {
  margin: 0 0 var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
  font-size: var(--fs-sm);
}
.emit-guide-summary p { margin: 0.2rem 0; }
.emit-guide-totals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  margin: 0.35rem 0;
}
.emit-guide-totals span {
  display: inline;
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: var(--fw-regular, 400);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}
.emit-guide-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
@media (max-width: 520px) {
  .emit-guide-fields-row { grid-template-columns: 1fr; }
}
