/* ==========================================================================
   CHECKPLACE DS — COMPONENTES
   Convenção: .cp-nome  /  .cp-nome__parte  /  .cp-nome--variante  /  estados por atributo
   ([disabled], [aria-busy], [aria-invalid], [aria-pressed], [aria-selected], [aria-current]).
   Estado por atributo = o mesmo atributo que o leitor de tela lê. Nada de classe só visual.
   ========================================================================== */

/* ==========================================================================
   BOTÃO
   Variantes: primary · secondary · ghost · danger · success · link
   Tamanhos : --sm · (padrão por densidade) · --lg · --block · --icon
   Estados  : hover · focus-visible · active · [disabled] · [aria-busy=true] · [data-state=success]
   ========================================================================== */
.cp-btn {
  --_bg: var(--color-surface);       --_bg-hover: var(--color-surface-hover);  --_bg-active: var(--color-border-subtle);
  --_fg: var(--color-text);          --_bd: var(--color-border-strong);        --_spin: var(--color-primary);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--control-h); padding: 0 calc(var(--control-px) + .25rem);
  border: var(--border-width) solid var(--_bd); border-radius: var(--radius-control);
  background: var(--_bg); color: var(--_fg);
  font-family: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 1.2;
  text-decoration: none; white-space: nowrap; user-select: none; cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}
[data-density="comfortable"] .cp-btn { font-size: var(--text-base); }
.cp-btn:hover  { background: var(--_bg-hover); color: var(--_fg); }
.cp-btn:active { background: var(--_bg-active); transform: translateY(.5px); }
.cp-btn:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-control); }

.cp-btn--primary   { --_bg: var(--color-primary); --_bg-hover: var(--color-primary-hover); --_bg-active: var(--color-primary-pressed);
                     --_fg: var(--color-text-on-primary); --_bd: transparent; --_spin: #fff; }
.cp-btn--secondary { /* = padrão */ }
.cp-btn--ghost     { --_bg: transparent; --_bd: transparent; --_fg: var(--color-text-link); --_bg-hover: var(--color-primary-soft); --_bg-active: var(--color-primary-soft-2); }
.cp-btn--ghost.cp-btn--neutral { --_fg: var(--color-text-secondary); --_bg-hover: var(--color-surface-hover); --_bg-active: var(--color-border-subtle); }
.cp-btn--danger    { --_bg: var(--color-danger); --_bg-hover: var(--color-danger-hover); --_bg-active: var(--color-danger-hover);
                     --_fg: #fff; --_bd: transparent; --_spin: #fff; }
.cp-btn--danger-soft { --_bg: var(--color-danger-soft); --_bg-hover: var(--color-danger-border); --_bg-active: var(--color-danger-border);
                     --_fg: var(--color-danger-text); --_bd: transparent; --_spin: var(--color-danger-text); }
.cp-btn--success   { --_bg: var(--color-success); --_bg-hover: var(--color-success-hover); --_bg-active: var(--color-success-hover);
                     --_fg: #fff; --_bd: transparent; --_spin: #fff; }
.cp-btn--link      { --_bg: transparent; --_bd: transparent; --_fg: var(--color-text-link); --_bg-hover: transparent; --_bg-active: transparent;
                     min-height: 24px; padding: 2px 0; text-decoration: underline; text-underline-offset: 3px; font-weight: var(--weight-medium); }
.cp-btn--link:hover { color: var(--color-primary-pressed); }

.cp-btn--sm    { min-height: var(--control-h-sm); padding: 0 var(--control-px); }
.cp-btn--lg    { min-height: var(--control-h-lg); padding: 0 calc(var(--control-px) + .5rem); }
.cp-btn--block { display: flex; width: 100%; }
.cp-btn--icon  { width: var(--icon-btn); min-height: var(--icon-btn); height: var(--icon-btn); padding: 0; }
.cp-btn--icon.cp-btn--sm { width: var(--control-h-sm); min-height: var(--control-h-sm); height: var(--control-h-sm); }

.cp-btn[disabled], .cp-btn[aria-disabled="true"] {
  --_bg: var(--color-surface-sunken); --_fg: var(--color-text-disabled); --_bd: transparent;
  cursor: not-allowed; transform: none; pointer-events: none;
}
.cp-btn--link[disabled] { --_bg: transparent; }

/* Carregando: o botão mantém o tamanho (texto invisível, spinner por cima) e não aceita novo clique */
.cp-btn[aria-busy="true"] { color: transparent; pointer-events: none; cursor: progress; }
.cp-btn[aria-busy="true"] > * { visibility: hidden; }
.cp-btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 1.1em; height: 1.1em;
  border: 2px solid var(--_spin); border-right-color: transparent; border-radius: 50%;
  animation: cp-spin .7s linear infinite;
}
.cp-btn[data-state="success"] { --_bg: var(--color-success); --_bg-hover: var(--color-success); --_fg: #fff; --_bd: transparent; }

/* ==========================================================================
   CAMPOS
   Estrutura: .cp-field > .cp-label + (.cp-input | .cp-select | .cp-textarea | .cp-input-wrap | .cp-input-group) + .cp-hint + .cp-error
   Obrigatório = padrão. Opcional é que recebe marca: <span class="cp-optional">(opcional)</span>
   ========================================================================== */
.cp-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cp-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); line-height: var(--leading-snug); }
.cp-optional { font-weight: var(--weight-regular); color: var(--color-text-tertiary); margin-left: 4px; }
.cp-hint  { font-size: var(--text-sm); color: var(--color-text-tertiary); line-height: var(--leading-snug); }
.cp-error { display: flex; gap: 6px; align-items: flex-start; font-size: var(--text-sm); color: var(--color-danger-text);
            line-height: var(--leading-snug); font-weight: var(--weight-medium); }
.cp-error .cp-icon { width: 16px; height: 16px; margin-top: 1px; }

.cp-input, .cp-select, .cp-textarea {
  width: 100%; min-height: var(--control-h); padding: 0 var(--control-px);
  background: var(--color-surface); color: var(--color-text);
  border: var(--border-width) solid var(--color-border-control); border-radius: var(--radius-control);
  font-family: inherit; font-size: var(--text-input); line-height: 1.3;
  transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
  appearance: none; -webkit-appearance: none;
}
.cp-input::placeholder, .cp-textarea::placeholder { color: var(--color-text-tertiary); opacity: 1; }
.cp-input:hover, .cp-select:hover, .cp-textarea:hover { border-color: var(--color-text-tertiary); }
.cp-input:focus-visible, .cp-select:focus-visible, .cp-textarea:focus-visible,
.cp-input:focus, .cp-select:focus, .cp-textarea:focus {
  outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(17, 102, 254, .28); border-radius: var(--radius-control);
}
.cp-input[aria-invalid="true"], .cp-select[aria-invalid="true"], .cp-textarea[aria-invalid="true"] {
  border-color: var(--color-danger); background: var(--color-surface);
}
.cp-input[aria-invalid="true"]:focus, .cp-select[aria-invalid="true"]:focus, .cp-textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(198, 57, 43, .25);
}
.cp-input[readonly], .cp-textarea[readonly] { background: var(--color-surface-sunken); border-color: var(--color-border); cursor: default; }
.cp-input:disabled, .cp-select:disabled, .cp-textarea:disabled {
  background: var(--color-surface-sunken); border-color: var(--color-border); color: var(--color-text-disabled); cursor: not-allowed;
}
.cp-textarea { padding-block: var(--space-sm); min-height: 96px; resize: vertical; line-height: var(--leading-normal); }

.cp-select {
  padding-right: 2.5rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23626E8B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center;
}

/* Campo com ícone (busca) */
.cp-input-wrap { position: relative; display: block; }
.cp-input-wrap > .cp-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--color-icon-muted); pointer-events: none; }
.cp-input-wrap > .cp-input { padding-left: 2.5rem; }
.cp-input-wrap > .cp-input-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.cp-input[type="search"]::-webkit-search-cancel-button { display: none; }

/* Prefixo / sufixo (R$, %, un.) */
.cp-input-group { display: flex; align-items: stretch; }
.cp-input-group > .cp-input { border-radius: 0; flex: 1 1 auto; min-width: 0; }
.cp-input-group > .cp-addon {
  display: inline-flex; align-items: center; padding: 0 var(--control-px); background: var(--color-surface-sunken);
  border: var(--border-width) solid var(--color-border-control); color: var(--color-text-secondary);
  font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap;
}
.cp-input-group > :first-child { border-top-left-radius: var(--radius-control); border-bottom-left-radius: var(--radius-control); }
.cp-input-group > :last-child  { border-top-right-radius: var(--radius-control); border-bottom-right-radius: var(--radius-control); }
.cp-input-group > .cp-addon:first-child { border-right: 0; }
.cp-input-group > .cp-addon:last-child  { border-left: 0; }

.cp-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: var(--space-xs); }
.cp-fieldset > legend { padding: 0; margin-bottom: var(--space-xs); font-size: var(--text-sm); font-weight: var(--weight-semibold); }

/* ==========================================================================
   CHECKBOX · RADIO · SWITCH
   O <label> inteiro é a área de toque. Sempre com texto ao lado.
   ========================================================================== */
.cp-check, .cp-radio {
  display: flex; align-items: flex-start; gap: 10px; min-height: var(--control-h-sm); padding-block: 4px; cursor: pointer;
  font-size: var(--text-body); line-height: var(--leading-snug);
}
.cp-check > input, .cp-radio > input {
  appearance: none; -webkit-appearance: none; flex: none; width: 20px; height: 20px; margin: 1px 0 0; cursor: pointer;
  background: var(--color-surface); border: 1.5px solid var(--color-border-control);
  transition: background-color var(--duration-fast), border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.cp-check > input { border-radius: var(--radius-xs); }
.cp-radio > input { border-radius: 50%; }
.cp-check > input:hover, .cp-radio > input:hover { border-color: var(--color-primary); }
.cp-check > input:checked, .cp-check > input:indeterminate { background-color: var(--color-primary); border-color: var(--color-primary); }
.cp-check > input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: 14px; background-position: center; background-repeat: no-repeat;
}
.cp-check > input:indeterminate {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
  background-size: 14px; background-position: center; background-repeat: no-repeat;
}
.cp-radio > input:checked { background: var(--color-primary); border-color: var(--color-primary); box-shadow: inset 0 0 0 4px var(--color-surface); }
.cp-check > input:focus-visible, .cp-radio > input:focus-visible { box-shadow: var(--shadow-focus); }
.cp-radio > input:checked:focus-visible { box-shadow: inset 0 0 0 4px var(--color-surface), 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-primary); }
.cp-check > input:disabled, .cp-radio > input:disabled { background-color: var(--color-surface-sunken); border-color: var(--color-border); cursor: not-allowed; }
.cp-check > input:disabled:checked { background-color: var(--color-border-strong); }
.cp-check:has(> input:disabled), .cp-radio:has(> input:disabled) { color: var(--color-text-disabled); cursor: not-allowed; }
.cp-check--bare { min-height: 24px; padding: 2px; }
.cp-check__desc { display: block; font-size: var(--text-sm); color: var(--color-text-tertiary); margin-top: 2px; }

/* Opção em cartão (escolher uma loja, uma rede, um modo) */
.cp-choice {
  display: flex; align-items: flex-start; gap: 10px; padding: var(--space-sm) var(--space-md); cursor: pointer;
  background: var(--color-surface); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg);
  transition: border-color var(--duration-fast), background-color var(--duration-fast);
}
.cp-choice:hover { border-color: var(--color-border-strong); }
.cp-choice:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-soft); }
.cp-choice:has(input:focus-visible) { box-shadow: var(--shadow-focus); }

/* Switch: aplica na hora. Escreva o estado ao lado ("Ligado"/"Desligado") — não dependa só da cor. */
.cp-switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); min-height: var(--control-h); }
.cp-switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 44px; height: 26px; margin: 0; cursor: pointer;
  border-radius: var(--radius-full); background: var(--color-border-control); border: 0;
  transition: background-color var(--duration-base) var(--ease-standard);
}
.cp-switch::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(11, 30, 94, .3); transition: transform var(--duration-base) var(--ease-standard);
}
.cp-switch:checked { background: var(--color-primary); }
.cp-switch:checked::before { transform: translateX(18px); }
.cp-switch:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-full); }
.cp-switch:disabled { background: var(--color-border); cursor: not-allowed; }

/* Contador de quantidade (– 12 +) */
.cp-stepper { display: inline-flex; align-items: center; gap: var(--space-xs); }
.cp-stepper > .cp-input { width: 64px; text-align: center; font-weight: var(--weight-semibold); padding: 0 4px; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.cp-stepper > .cp-input::-webkit-outer-spin-button, .cp-stepper > .cp-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ==========================================================================
   BADGE (status) · CONTADOR · CHIP (filtro)
   Badge informa, não é clicável. Chip é clicável. Sempre tem texto: cor sozinha não basta.
   ========================================================================== */
.cp-badge {
  --_bg: var(--color-surface-sunken); --_fg: var(--color-text-secondary); --_dot: var(--color-icon-muted);
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius-full);
  background: var(--_bg); color: var(--_fg); font-size: var(--text-xs); font-weight: var(--weight-semibold); line-height: 1; white-space: nowrap; flex: none;
}
.cp-badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--_dot); flex: none; }
.cp-badge--info    { --_bg: var(--color-info-soft);    --_fg: var(--color-text-link);       --_dot: var(--color-primary); }
.cp-badge--success { --_bg: var(--color-success-soft); --_fg: var(--color-success);         --_dot: var(--color-success); }
.cp-badge--warning { --_bg: var(--color-warning-soft); --_fg: var(--color-warning-text);    --_dot: var(--color-warning); }
.cp-badge--danger  { --_bg: var(--color-danger-soft);  --_fg: var(--color-danger-text);     --_dot: var(--color-danger); }

.cp-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full);
            background: var(--color-danger); color: #fff; font-size: var(--text-xs); font-weight: var(--weight-bold); line-height: 1; font-variant-numeric: tabular-nums; }
.cp-count--neutral { background: var(--color-surface-sunken); color: var(--color-text-secondary); }

.cp-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--control-h-sm); padding: 0 12px;
  background: var(--color-surface); color: var(--color-text-secondary); border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-full); font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; cursor: pointer; flex: none;
  transition: background-color var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}
.cp-chip:hover { background: var(--color-surface-hover); }
.cp-chip[aria-pressed="true"] { background: var(--color-primary-soft); border-color: var(--color-primary); color: var(--color-text-link); font-weight: var(--weight-semibold); }
.cp-chip[aria-pressed="true"]::before {   /* selecionado = cor + marca de check */
  content: ""; width: 14px; height: 14px; background: currentColor; flex: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
}
.cp-chip:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-full); }
.cp-chip-row { display: flex; gap: var(--space-xs); overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.cp-chip-row::-webkit-scrollbar { display: none; }

/* Filtro ativo e removível ("Cidade: Campinas  ×") */
.cp-tag { display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0 4px 0 10px; border-radius: var(--radius-full);
          background: var(--color-primary-soft); color: var(--color-text-link); font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; }
.cp-tag__x { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border: 0; background: transparent; color: inherit; border-radius: 50%; padding: 0; }
.cp-tag__x:hover { background: var(--color-primary-soft-2); }

/* ==========================================================================
   CARD · INDICADOR
   Borda sutil, sem sombra. Sombra só aparece em card clicável ao passar o mouse.
   Não aninhe card dentro de card.
   ========================================================================== */
.cp-card {
  background: var(--color-surface); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-md); min-width: 0; display: block; color: inherit; text-align: left; font: inherit;
}
.cp-card--flush { padding: 0; overflow: hidden; }
.cp-card--lg    { padding: var(--space-lg); }
.cp-card--flat  { background: var(--color-surface-sunken); border-color: transparent; }
.cp-card--interactive { cursor: pointer; text-decoration: none; width: 100%;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast); }
.cp-card--interactive:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-xs); }
.cp-card--interactive:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-lg); }
.cp-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-md); }
.cp-card__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); line-height: var(--leading-snug); }
.cp-card__desc  { font-size: var(--text-sm); color: var(--color-text-tertiary); margin-top: 2px; }
.cp-card__foot  { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); margin-top: var(--space-md); padding-top: var(--space-md); border-top: var(--border-width) solid var(--color-border-subtle); }
.cp-panel__head { padding: var(--space-md); border-bottom: var(--border-width) solid var(--color-border); }

/* Indicador: valor em destaque + o que é + contexto para interpretar */
.cp-stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cp-stat__label { font-size: var(--text-sm); color: var(--color-text-secondary); font-weight: var(--weight-medium); display: flex; align-items: center; gap: 4px; }
.cp-stat__value { font-family: var(--font-sans); font-size: var(--text-5xl); font-weight: var(--weight-semibold); line-height: 1.05;
                  letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--color-text); }
.cp-stat__unit  { font-size: var(--text-lg); font-weight: var(--weight-medium); color: var(--color-text-tertiary); margin-left: 2px; letter-spacing: 0; }
.cp-stat__context { font-size: var(--text-xs); color: var(--color-text-tertiary); line-height: var(--leading-snug); }
[data-density="comfortable"] .cp-stat__value { font-size: var(--text-4xl); }

.cp-delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-xs); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.cp-delta--up   { color: var(--color-success); }
.cp-delta--down { color: var(--color-danger-text); }
.cp-delta--flat { color: var(--color-text-tertiary); }
.cp-delta .cp-icon { width: 14px; height: 14px; }

/* Faixa de indicadores: um único bloco com divisórias (evita 4 caixinhas competindo) */
.cp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--color-surface);
            border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.cp-stats > .cp-stat { padding: var(--space-md) var(--space-lg) var(--space-md) var(--space-md); border-right: var(--border-width) solid var(--color-border-subtle); border-bottom: var(--border-width) solid var(--color-border-subtle); margin: 0 -1px -1px 0; }
.cp-stats .cp-stat__value { font-size: var(--text-4xl); }

/* ==========================================================================
   ALERTA (permanece na tela) · TOAST (some sozinho)
   Alerta: o que o usuário precisa saber/ler depois. Toast: confirmação rápida de algo que ele acabou de fazer.
   ========================================================================== */
.cp-alert {
  --_bg: var(--color-info-soft); --_bd: var(--color-info-border); --_ic: var(--color-primary);
  display: flex; align-items: flex-start; gap: var(--space-sm); padding: var(--space-sm) var(--space-md);
  background: var(--_bg); border: var(--border-width) solid var(--_bd); border-radius: var(--radius-lg);
  font-size: var(--text-body); line-height: var(--leading-snug); color: var(--color-text);
}
.cp-alert > .cp-icon { color: var(--_ic); margin-top: 1px; }
.cp-alert__body  { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cp-alert__title { font-weight: var(--weight-semibold); }
.cp-alert__text  { color: var(--color-text-secondary); }
.cp-alert__actions { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-top: var(--space-xs); }
.cp-alert--success { --_bg: var(--color-success-soft); --_bd: var(--color-success-border); --_ic: var(--color-success); }
.cp-alert--warning { --_bg: var(--color-warning-soft); --_bd: var(--color-warning-border); --_ic: var(--color-warning-text); }
.cp-alert--danger  { --_bg: var(--color-danger-soft);  --_bd: var(--color-danger-border);  --_ic: var(--color-danger-text); }

.cp-toasts { position: fixed; z-index: var(--z-toast); left: var(--space-md); right: var(--space-md); bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
             display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); pointer-events: none; }
.cp-toasts--above-tabbar { bottom: calc(76px + var(--space-md) + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 640px) { .cp-toasts { left: auto; right: var(--space-lg); bottom: var(--space-lg); align-items: flex-end; } }
.cp-toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--space-sm); width: 100%; max-width: 420px;
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md); background: var(--color-text); color: #fff;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); font-size: var(--text-sm); line-height: var(--leading-snug);
  animation: cp-rise-in var(--duration-base) var(--ease-out);
}
.cp-toast > .cp-icon { margin-top: 1px; }
.cp-toast--success > .cp-icon { color: #6EE7A8; }
.cp-toast--danger  > .cp-icon { color: #FFA59B; }
.cp-toast__body { flex: 1; min-width: 0; padding-block: 2px; }
.cp-toast__title { font-weight: var(--weight-semibold); display: block; }
.cp-toast__text  { color: #C9D3F0; display: block; }
.cp-toast .cp-btn { --_fg: #fff; --_bg-hover: rgba(255,255,255,.14); --_bg-active: rgba(255,255,255,.2); min-height: 32px; }
.cp-toast .cp-btn:focus-visible { box-shadow: 0 0 0 2px var(--color-text), 0 0 0 4px #fff; }

/* ==========================================================================
   ABAS · CONTROLE SEGMENTADO
   Abas trocam o conteúdo da página. Segmentado troca a forma de ver o mesmo conteúdo (lista/mapa, mês/semana).
   ========================================================================== */
.cp-tabs { display: flex; gap: var(--space-lg); border-bottom: var(--border-width) solid var(--color-border); overflow-x: auto; scrollbar-width: none; }
.cp-tabs::-webkit-scrollbar { display: none; }
.cp-tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 10px 2px 12px; margin-bottom: -1px; border: 0; background: transparent;
  border-bottom: 2px solid transparent; color: var(--color-text-tertiary); font-size: var(--text-md); font-weight: var(--weight-semibold); white-space: nowrap; cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast);
}
.cp-tab:hover { color: var(--color-text); }
.cp-tab[aria-selected="true"] { color: var(--color-text); border-bottom-color: var(--color-primary); }
.cp-tab:focus-visible { box-shadow: var(--shadow-focus); border-radius: var(--radius-sm); }
.cp-tabpanel { padding-top: var(--space-md); }

.cp-segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--color-surface-sunken); border-radius: var(--radius-md); }
.cp-segmented > button {
  min-height: calc(var(--control-h-sm) - 2px); padding: 0 12px; border: 0; border-radius: calc(var(--radius-md) - 2px); background: transparent;
  color: var(--color-text-secondary); font-size: var(--text-sm); font-weight: var(--weight-semibold);
}
.cp-segmented > button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); box-shadow: 0 1px 2px rgba(11, 30, 94, .14); }

/* ==========================================================================
   TABELA
   Colunas numéricas à direita com .is-num. Ordenável: <th aria-sort><button class="cp-th-btn">.
   Pequenas telas: .cp-table--stack vira lista de blocos (cada <td data-label="...">)
                   ou .cp-hide-sm esconde colunas secundárias (as primárias ficam).
   ========================================================================== */
.cp-table-wrap { overflow-x: auto; background: var(--color-surface); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg); }
.cp-table-wrap:focus-visible { box-shadow: var(--shadow-focus); }
.cp-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-body); }
.cp-table caption { text-align: left; padding: var(--space-md); font-weight: var(--weight-semibold); }
.cp-table th {
  position: sticky; top: 0; z-index: 1; text-align: left; padding: 10px var(--space-md); background: var(--color-surface);
  color: var(--color-text-tertiary); font-size: var(--text-sm); font-weight: var(--weight-semibold); white-space: nowrap;
  border-bottom: var(--border-width) solid var(--color-border);
}
.cp-table td { padding: var(--row-py) var(--space-md); border-bottom: var(--border-width) solid var(--color-border-subtle); vertical-align: middle; line-height: var(--leading-snug); }
.cp-table tbody tr:last-child td { border-bottom: 0; }
.cp-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.cp-table .is-actions { width: 1%; text-align: right; white-space: nowrap; }
.cp-table--interactive tbody tr { cursor: pointer; }
.cp-table--interactive tbody tr:hover td { background: var(--color-surface-hover); }
.cp-table tbody tr[aria-selected="true"] td { background: var(--color-primary-soft); }
.cp-table td .cp-sub { display: block; font-weight: var(--weight-regular); font-size: var(--text-sm); color: var(--color-text-tertiary); margin-top: 1px; }
.cp-table td .cp-strong { font-weight: var(--weight-semibold); }

.cp-th-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 2px 4px; margin-left: -4px; border-radius: var(--radius-sm); border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.cp-th-btn:hover { color: var(--color-text); }
.cp-th-btn::after { content: ""; width: 12px; height: 12px; opacity: .35; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5M7 9l5-5 5 5'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5M7 9l5-5 5 5'/%3E%3C/svg%3E") center/contain no-repeat; }
th[aria-sort="ascending"]  .cp-th-btn, th[aria-sort="descending"] .cp-th-btn { color: var(--color-text); }
th[aria-sort="ascending"]  .cp-th-btn::after { opacity: 1; -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 15-6-6-6 6'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 15-6-6-6 6'/%3E%3C/svg%3E"); }
th[aria-sort="descending"] .cp-th-btn::after { opacity: 1; -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }

.cp-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); flex-wrap: wrap; padding: var(--space-sm) var(--space-md);
                 border-top: var(--border-width) solid var(--color-border); font-size: var(--text-sm); color: var(--color-text-secondary); }

@media (max-width: 639px) {
  .cp-hide-sm { display: none !important; }
  .cp-table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cp-table--stack, .cp-table--stack tbody, .cp-table--stack tr, .cp-table--stack td { display: block; width: 100%; }
  .cp-table--stack tr { padding: var(--space-sm) var(--space-md); border-bottom: var(--border-width) solid var(--color-border); }
  .cp-table--stack tbody tr:last-child { border-bottom: 0; }
  .cp-table--stack td { display: flex; justify-content: space-between; gap: var(--space-md); padding: 4px 0; border: 0; text-align: right; }
  .cp-table--stack td::before { content: attr(data-label); color: var(--color-text-tertiary); font-size: var(--text-sm); text-align: left; flex: none; }
  .cp-table--stack td.is-title { display: block; text-align: left; padding-bottom: 6px; }
  .cp-table--stack td.is-title::before { display: none; }
  .cp-table--stack td.is-actions { width: 100%; }
}

/* ==========================================================================
   MODAL · DRAWER   (elemento nativo <dialog>: foco preso, Esc fecha, fundo inerte — sem JS extra)
   Modal = tarefa curta que interrompe. Drawer = editar mantendo a página à vista.
   Celular: modal vira "bottom sheet".
   ========================================================================== */
dialog.cp-modal, dialog.cp-drawer {
  --_w: 520px; padding: 0; border: 0; background: var(--color-surface); color: var(--color-text);
  width: calc(100% - 2rem); max-width: var(--_w); max-height: min(88dvh, 760px);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow: hidden; flex-direction: column;
}
dialog.cp-modal[open], dialog.cp-drawer[open] { display: flex; animation: cp-rise-in var(--duration-base) var(--ease-out); }
dialog.cp-modal::backdrop, dialog.cp-drawer::backdrop { background: var(--color-overlay); animation: cp-fade-in var(--duration-base) ease; }
dialog.cp-modal--sm { --_w: 400px; }
dialog.cp-modal--lg { --_w: 720px; }

.cp-dialog__head { display: flex; align-items: flex-start; gap: var(--space-md); padding: var(--space-lg) var(--space-lg) var(--space-xs); }
.cp-dialog__title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
.cp-dialog__desc  { color: var(--color-text-secondary); font-size: var(--text-body); margin-top: 4px; }
.cp-dialog__body  { padding: var(--space-md) var(--space-lg); overflow-y: auto; flex: 1 1 auto; }
.cp-dialog__foot  { display: flex; justify-content: flex-end; gap: var(--space-xs); padding: var(--space-md) var(--space-lg) var(--space-lg); flex-wrap: wrap; }
.cp-dialog__icon  { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--color-danger-soft); color: var(--color-danger-text); }
.cp-dialog__icon--warning { background: var(--color-warning-soft); color: var(--color-warning-text); }
.cp-dialog__icon--info    { background: var(--color-info-soft); color: var(--color-primary); }
.cp-dialog__icon--success { background: var(--color-success-soft); color: var(--color-success); }

dialog.cp-drawer { margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(480px, 100vw); max-width: none; border-radius: 0; --_w: 480px; }
dialog.cp-drawer[open] { animation: cp-drawer-in var(--duration-slow) var(--ease-out); }
@keyframes cp-drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 639px) {
  dialog.cp-modal { margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  dialog.cp-modal[open] { animation: cp-sheet-in var(--duration-slow) var(--ease-out); }
  .cp-dialog__foot { flex-direction: column-reverse; padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px)); }
  .cp-dialog__foot .cp-btn { width: 100%; }
  dialog.cp-drawer { width: 100vw; }
}
@keyframes cp-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==========================================================================
   MENU (dropdown) · TOOLTIP · AJUDA CONTEXTUAL
   ========================================================================== */
.cp-menu { position: relative; display: inline-block; }
.cp-menu__list {
  position: absolute; z-index: var(--z-dropdown); top: calc(100% + 4px); right: 0; min-width: 200px; padding: 4px;
  background: var(--color-surface); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  animation: cp-fade-in var(--duration-fast) ease;
}
.cp-menu__list--left { right: auto; left: 0; }
.cp-menu__item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--control-h-sm); padding: 6px 10px; border: 0; background: transparent; border-radius: var(--radius-md);
                 color: var(--color-text); font-size: var(--text-body); text-align: left; text-decoration: none; cursor: pointer; }
.cp-menu__item:hover, .cp-menu__item:focus-visible { background: var(--color-surface-hover); box-shadow: none; }
.cp-menu__item:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.cp-menu__item--danger { color: var(--color-danger-text); }
.cp-menu__item--danger:hover { background: var(--color-danger-soft); }
.cp-menu__sep { height: 1px; margin: 4px 0; background: var(--color-border-subtle); border: 0; }

.cp-tip { position: relative; display: inline-flex; }
.cp-tip__bubble {
  position: absolute; z-index: var(--z-tooltip); bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); width: max-content; max-width: 260px;
  padding: 6px 10px; background: var(--color-text); color: #fff; border-radius: var(--radius-md); font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: var(--leading-snug);
  text-align: left; white-space: normal; visibility: hidden; opacity: 0; transition: opacity var(--duration-fast), visibility var(--duration-fast);
}
.cp-tip--right .cp-tip__bubble { bottom: auto; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); }
.cp-tip:hover .cp-tip__bubble, .cp-tip:focus-within .cp-tip__bubble { visibility: visible; opacity: 1; }
.cp-tip.is-dismissed .cp-tip__bubble { visibility: hidden !important; opacity: 0 !important; }   /* Esc fecha (WCAG 1.4.13) */

/* "?" ao lado de um termo difícil: explica no momento da dúvida, sem sair da tela */
.cp-help { display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: var(--color-surface-sunken); color: var(--color-text-secondary); cursor: help; }
.cp-help:hover { background: var(--color-primary-soft-2); color: var(--color-text-link); }
.cp-help .cp-icon { width: 14px; height: 14px; }

/* ==========================================================================
   CARREGANDO · VAZIO · ERRO
   Todo estado vazio responde: o que está acontecendo? e o que posso fazer?
   ========================================================================== */
.cp-spinner { display: inline-block; width: 20px; height: 20px; border: 2.5px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: cp-spin .8s linear infinite; }
.cp-spinner--lg { width: 32px; height: 32px; border-width: 3px; }

.cp-skeleton { display: block; height: 12px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-surface-sunken) 30%, var(--color-border-subtle) 50%, var(--color-surface-sunken) 70%); background-size: 200% 100%; animation: cp-shimmer 1.4s linear infinite; }
.cp-skeleton--title  { height: 20px; width: 40%; }
.cp-skeleton--text   { width: 100%; }
.cp-skeleton--short  { width: 55%; }
.cp-skeleton--avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.cp-skeleton--block  { height: 96px; border-radius: var(--radius-lg); }

.cp-progress { height: 8px; background: var(--color-surface-sunken); border-radius: var(--radius-full); overflow: hidden; }
.cp-progress > span { display: block; height: 100%; width: var(--value, 0%); background: var(--color-primary); border-radius: inherit; transition: width var(--duration-slow) var(--ease-standard); }

.cp-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-xs); text-align: center; padding: var(--space-2xl) var(--space-lg); }
.cp-empty__icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--color-surface-sunken); color: var(--color-text-tertiary); margin-bottom: var(--space-xs); }
.cp-empty__icon--danger { background: var(--color-danger-soft); color: var(--color-danger-text); }
.cp-empty__icon--primary { background: var(--color-primary-soft); color: var(--color-primary); }
.cp-empty__title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
.cp-empty__text  { max-width: 38ch; color: var(--color-text-secondary); font-size: var(--text-body); text-wrap: pretty; }
.cp-empty .cp-btn { margin-top: var(--space-sm); }

/* ==========================================================================
   AVATAR
   ========================================================================== */
.cp-avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--color-primary-soft-2); color: var(--color-text-link);
             font-size: var(--text-sm); font-weight: var(--weight-semibold); text-transform: uppercase; user-select: none; }
.cp-avatar--sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.cp-avatar--square { border-radius: var(--radius-md); }

/* ==========================================================================
   GRÁFICOS (sempre acompanhados de valor/rótulo; cor nunca é o único sinal)
   ========================================================================== */
.cp-legend { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-md); font-size: var(--text-sm); color: var(--color-text-secondary); }
.cp-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.cp-legend__key { width: 12px; height: 12px; border-radius: 3px; background: var(--c, var(--color-data-1)); flex: none; }
.cp-legend__key--outline { background: transparent; border: 2px solid var(--c, var(--color-data-1)); }

.cp-bars { display: flex; flex-direction: column; gap: var(--space-sm); }
.cp-bars__row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; align-items: center; gap: var(--space-sm); font-size: var(--text-sm); }
.cp-bars__label { color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-bars__track { height: 10px; background: var(--color-surface-sunken); border-radius: var(--radius-full); overflow: hidden; }
.cp-bars__fill  { display: block; height: 100%; width: var(--v, 0%); background: var(--c, var(--color-data-1)); border-radius: inherit; }
.cp-bars__value { font-variant-numeric: tabular-nums; font-weight: var(--weight-semibold); min-width: 3ch; text-align: right; }
