/* assets/20-components.css — componentes: cards, rótulos, botões, campos, dropzone, spinner e progresso.
 *
 * Temas claro e escuro: as cores vêm dos tokens de 00-tokens.css (o escuro é o bloco
 * `:root[data-theme="dark"]`, docs/DECISIONS.md#tema-escuro). Dash carrega assets/*.css em ordem ALFABÉTICA: os
 * prefixos numéricos são a ordem da cascata (tokens → base → Dash → ícones →
 * casco → componentes).
 */

/* ------------------------------------------------------------------ */
/* Cards — todo painel/seção "flutuante" da UI usa essa classe.        */
/* ------------------------------------------------------------------ */

.card,
.stats-panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stats-panel {
  padding: 16px;
}

.card-pad {
  padding: 18px 20px;
}

/* ------------------------------------------------------------------ */
/* Seções / labels                                                     */
/* ------------------------------------------------------------------ */

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

.field-label {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.stats-panel h4 {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.stats-panel h4:first-child {
  margin-top: 0;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text);
}

.stats-row .label {
  color: var(--text-secondary);
  margin-right: 8px;
}

/* ------------------------------------------------------------------ */
/* Botões                                                              */
/* ------------------------------------------------------------------ */

button {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
  color: var(--accent-contrast) !important;
  font-weight: 600 !important;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-dark) !important;
  border-color: var(--accent-dark) !important;
}

.btn-ghost {
  background-color: transparent !important;
  border-color: transparent !important;
  color: var(--text-secondary) !important;
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--surface-2) !important;
  border-color: var(--border) !important;
}

/* ------------------------------------------------------------------ */
/* Inputs / dropdowns                                                  */
/* ------------------------------------------------------------------ */

input, textarea {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

a {
  color: var(--accent);
}

/* ------------------------------------------------------------------ */
/* Upload dropzone                                                     */
/* ------------------------------------------------------------------ */

.dropzone {
  background-color: var(--surface-2);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover {
  border-color: var(--accent) !important;
  background-color: var(--accent-soft) !important;
}

/* ------------------------------------------------------------------ */
/* Barra de progresso — "Classificar canal ativo (IA)" avança em pedaços  */
/* (ver ui/callbacks.py) e preenche isso em tempo real, sincronizado com  */
/* o quanto do eixo X já foi classificado.                                */
/* ------------------------------------------------------------------ */

/* Spinner de carregamento — anel fino que gira, no lugar do spinner
   genérico do Dash (usado via dcc.Loading custom_spinner). */
.holter-spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: holter-spin 0.8s linear infinite;
}
/* O pequeno (16 px): na barra superior, nas listas, no "Salvar trabalho". DEPOIS da base — com a mesma especificidade
   quem decide é a ordem, e em 10-shell.css (carregado antes) ele nunca valia. */
.holter-spinner--sm { width: 16px; height: 16px; margin: 0; border-width: 2px; }

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

.progress-track {
  width: 100%;
  height: 10px;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Sinal de VIDA pras etapas longas cujo progresso não é mensurável: a detecção
   de QRS de um Holter de 24h é uma chamada única e demorada (dezenas de
   segundos), então o percentual fica parado enquanto ela roda. Uma barra
   imóvel é indistinguível de um app travado — a listra em movimento resolve
   isso sem inventar um percentual falso. Ver ui/common/components.py::
   load_progress_content. */
.progress-fill.is-working {
  background-image: linear-gradient(90deg, var(--accent), var(--accent-dark)),
    repeating-linear-gradient(45deg,
      rgba(255, 255, 255, 0.22) 0 10px,
      rgba(255, 255, 255, 0) 10px 20px);
  background-blend-mode: overlay;
  background-size: 100% 100%, 28px 28px;
  animation: holter-progress-stripes 0.8s linear infinite;
}

@keyframes holter-progress-stripes {
  to { background-position: 0 0, 28px 0; }
}

/* A linha de texto embaixo da barra (ui/common/components.py::progress_content): a etapa à esquerda e, à direita, os
   números — em algarismos TABULARES: na Inter proporcional o "1" é bem mais estreito que o "4", e o texto encostado à
   direita mudava de largura a cada tique e corria para os lados. */
.progress-caption {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: 6px;
  font-size: 12px;
  color: var(--color-text-secondary);
}
.progress-caption__value {
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill.is-working { animation: none; }
}

/* ================================================================== */
/* Kit — ui/common/kit.py (as peças novas; as classes antigas acima    */
/* seguem valendo até o último uso migrar).                            */
/* ================================================================== */

/* Botões ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  font: var(--fw-medium) 13px/1 var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.btn:hover:not(:disabled) { border-color: var(--color-brand); background: var(--color-surface-subtle); box-shadow: none; }
.btn:active:not(:disabled) { background: var(--color-surface-sunken); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--color-brand); border-color: var(--color-brand); color: var(--color-on-brand); font-weight: var(--fw-semibold); }
.btn--primary:hover:not(:disabled) { background: var(--color-brand-hover); border-color: var(--color-brand-hover); }
.btn--primary:active:not(:disabled) { background: var(--color-brand-active); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--color-text-secondary); }
.btn--ghost:hover:not(:disabled) { background: var(--color-surface-sunken); border-color: transparent; color: var(--color-text); }
.btn--danger { color: var(--tone-error-text); }
.btn--danger:hover:not(:disabled) { border-color: var(--tone-error-text); background: var(--tone-error-bg); }
.btn--sm { height: 28px; padding: 0 10px; font-size: var(--fs-sm); gap: 6px; }
.btn--icon { width: 34px; padding: 0; }
.btn--sm.btn--icon { width: 28px; }
.btn--block { width: 100%; }

/* Cabeçalhos -------------------------------------------------------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-header__title { margin: 0; font-size: var(--fs-2xl); line-height: var(--lh-tight); font-weight: var(--fw-semibold); }
.page-header__subtitle { margin: 4px 0 0; color: var(--color-text-secondary); font-size: var(--fs-md); max-width: 78ch; }
.page-header__meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.page-header__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

.section-header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: var(--space-6) 0 var(--space-3); }
.section-header__num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--color-brand); color: var(--color-on-brand);
  display: grid; place-items: center; font-size: 12px; font-weight: var(--fw-semibold); flex: none;
}
.section-header__icon { color: var(--color-brand); }
.section-header__title { margin: 0; font-size: 16px; font-weight: var(--fw-semibold); }
.section-header__hint { color: var(--color-text-muted); font-size: var(--fs-sm); }
.section-header__actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* Card com cabeçalho ------------------------------------------------ */
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) 18px;
  border-bottom: 1px solid var(--color-border);
}
.card-header__text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.card-header__title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; font-weight: var(--fw-semibold); }
.card-header__subtitle { font-size: var(--fs-xs); color: var(--color-text-muted); }
.card-header__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.card-body { padding: 16px 18px; }
.card-body--flush { padding: 0; }

/* Avisos ------------------------------------------------------------ */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.alert__icon { margin-top: 2px; }
.alert__body { min-width: 0; }
.alert__title { font-weight: var(--fw-semibold); margin-bottom: 2px; }
.alert--info { background: var(--tone-info-bg); border-color: var(--tone-info-border); color: var(--tone-info-text); }
.alert--warn { background: var(--tone-warn-bg); border-color: var(--tone-warn-border); color: var(--tone-warn-text); }
.alert--warn .alert__icon { color: var(--tone-warn-icon); }
.alert--error { background: var(--tone-error-bg); border-color: var(--tone-error-border); color: var(--tone-error-text); }
.alert--success { background: var(--tone-success-bg); border-color: var(--tone-success-border); color: var(--tone-success-text); }
.alert--ai { background: var(--tone-ai-bg); border-color: var(--tone-ai-border); color: var(--tone-ai-text); }
.alert--compact { padding: 6px 10px; font-size: var(--fs-xs); }

/* Selos ------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  background: var(--color-surface-sunken);
  color: var(--color-text-secondary);
}
.badge__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.badge--brand { background: var(--color-brand-subtle); color: var(--color-brand-text); }
.badge--info { background: var(--tone-info-bg); color: var(--tone-info-text); }
.badge--success { background: var(--tone-success-bg); color: var(--tone-success-text); }
.badge--warn { background: var(--tone-warn-badge-bg); color: var(--tone-warn-text); }
.badge--error { background: var(--tone-error-bg); color: var(--tone-error-text); }
.badge--ai { background: var(--tone-ai-bg); color: var(--tone-ai-text); }

/* Estado vazio ------------------------------------------------------ */
.empty-state {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-5);
  color: var(--color-text-secondary);
}
.empty-state__icon {
  width: 46px; height: 46px; border-radius: var(--radius-lg);
  background: var(--color-surface-sunken); color: var(--color-text-muted);
  display: grid; place-items: center;
}
.empty-state__title { margin: 0; font-size: var(--fs-lg); }
.empty-state__body { margin: 0; max-width: 56ch; font-size: var(--fs-sm); color: var(--color-text-muted); }
.empty-state__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: 4px; }

/* Placeholder de carga ---------------------------------------------- */
.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--h, 320px);
  text-align: center;
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-surface-subtle);
}
.loading-box__text { margin-top: 12px; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--color-text-secondary); }

/* KPI --------------------------------------------------------------- */
.kpi {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--color-surface-subtle);
  min-width: 0;
}
.kpi__label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--color-text-muted); }
.kpi__value { margin-top: 2px; font-size: 19px; line-height: 1.25; font-weight: var(--fw-semibold); color: var(--color-heading); letter-spacing: var(--ls-tight); }
.kpi__unit { font-size: 12px; font-weight: var(--fw-medium); color: var(--color-text-secondary); letter-spacing: 0; }
.kpi__sub { margin-top: 1px; font-size: 11px; line-height: 1.35; color: var(--color-text-secondary); }

/* Campo e ajuda ----------------------------------------------------- */
.field { display: grid; gap: 5px; align-content: start; min-width: 0; }
.field__label { font-size: 12px; font-weight: var(--fw-semibold); color: var(--color-text-secondary); }
.field__help, .help-text { font-size: var(--fs-xs); line-height: 1.45; color: var(--color-text-muted); }
.help-text { margin: 2px 0 10px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }

/* Botões segmentados (dcc.RadioItems) ----------------------------- */
/* A escolha de uma JANELA de tempo: a da tira do Visualizador (10/20/30 s) e a do recorte dos cards das abas de
 * revisão (ui/common/review.py::window_field). A bolinha do rádio some; o estado é o preenchimento. */
.segmented {
  display: inline-flex !important;
  flex-direction: row !important;
  gap: 0 !important;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented > .dash-options-list-option {
  display: inline-flex;
  align-items: center;
  height: 28px;
  margin: 0;
  padding: 0 10px;
  border-right: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}
.segmented > .dash-options-list-option:last-child { border-right: 0; }
.segmented > .dash-options-list-option:hover { background: var(--color-surface-sunken); }
.segmented > .dash-options-list-option[aria-selected="true"] {
  background: var(--color-brand-subtle);
  color: var(--color-brand-text);
}
.segmented > .dash-options-list-option:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.segmented .dash-options-list-option-wrapper {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
