/* ==========================================================================
   App shell: header, stepper, main content wrapper, sticky action bar
   ========================================================================== */

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Gate (login / CS-selection) ---------- */
.app-gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-5);
}

/* `display: flex` above otherwise wins the specificity tie against the
   browser's default `[hidden] { display: none }` and the gate stays visible
   underneath the wizard. */
.app-gate[hidden] {
  display: none;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--color-header-from), var(--color-header-to));
  color: var(--color-text-inverse);
  padding: var(--space-4) var(--space-5);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
}

.app-header__inner {
  max-width: var(--layout-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.app-header__logo {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-lg);
}

.app-header__title {
  font-size: var(--text-md);
  font-weight: 700;
  white-space: nowrap;
  line-height: 1;
}

.app-header__title small {
  font-weight: 400;
  color: #93C5FD;
  margin-left: 2px;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.app-header__user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  background: none;
  border: none;
  padding: 2px 4px;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  max-width: 180px;
}

.app-header__user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.app-header__user-role {
  font-size: 0.6875rem;
  color: #93C5FD;
}

.header-btn__badge {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: 0.6875rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.header-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--color-text-inverse);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-xs);
}

.header-icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.header-icon-btn.is-spinning svg {
  animation: spin 0.6s linear;
}

/* ---------- Stepper ---------- */
.stepper-wrap {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: calc(var(--z-header) - 1);
}

.stepper {
  max-width: var(--layout-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  gap: var(--space-2);
}

.stepper__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  background: none;
  flex: none;
}

.stepper__item[data-state="active"] {
  border-color: var(--color-primary-border);
  background: var(--color-primary-light);
}

.stepper__circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex: none;
  border: 2px solid var(--color-border-strong);
  color: var(--color-text-faint);
  background: var(--color-surface);
}

.stepper__item[data-state="active"] .stepper__circle {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.stepper__item[data-state="done"] .stepper__circle {
  border-color: var(--color-success);
  background: var(--color-success);
  color: var(--color-text-inverse);
}

.stepper__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-faint);
  white-space: nowrap;
}

.stepper__item[data-state="active"] .stepper__label {
  color: var(--color-primary);
}

.stepper__item[data-state="done"] .stepper__label {
  color: var(--color-text-secondary);
}

.stepper__chevron {
  color: var(--color-border-strong);
  flex: none;
}

/* ---------- Main content ---------- */
.app-main {
  flex: 1;
  max-width: var(--layout-max-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-10);
}

/* ---------- Sticky bottom action bar ---------- */
.action-bar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-action-bar);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-up);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

.action-bar__summary {
  text-align: center;
}

.action-bar__summary-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
}

.action-bar__summary-value {
  font-weight: 700;
  color: var(--color-primary);
  font-size: var(--text-base);
}

/* ==========================================================================
   Mobile e tablet (<= 1024px)

   Três coisas mudam, e todas pelo mesmo motivo: em tela estreita o app precisa
   caber sem rolagem lateral e sem empilhar o que é navegação.
   ========================================================================== */
@media (max-width: 1024px) {
  /* 1. Barra superior em UMA linha. O nome do programa sai (o ícone já identifica
     o app, e ele continua clicando para o menu) e o nome/papel do usuário também —
     essa informação já vive no drawer, que é para onde o botão ao lado leva. Sem
     isso, os dois blocos de texto forçavam o flex-wrap e a barra virava duas linhas. */
  .app-header {
    padding: var(--space-3) var(--space-4);
  }

  .app-header__inner {
    flex-wrap: nowrap;
    gap: var(--space-2);
  }

  .app-header__title,
  .app-header__user {
    display: none;
  }

  .app-header__logo {
    width: 34px;
    height: 34px;
  }

  .app-header__actions {
    flex-wrap: nowrap;
    gap: var(--space-2);
    margin-left: auto;
  }

  .header-icon-btn {
    width: 34px;
    height: 34px;
  }

  /* 2. Voltar e Avançar lado a lado embaixo, dividindo a largura em partes iguais;
     o resumo ("X EPIs selecionados") sobe para uma linha própria acima deles. Antes,
     cada filho ocupava 100% e os dois botões ficavam empilhados, empurrando a ação
     principal para fora da área visível em telas curtas. */
  .action-bar {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .action-bar__summary {
    order: -1;
    width: 100%;
  }

  .action-bar > .btn {
    flex: 1 1 0;
    min-width: 0;
    /* O rótulo pode ser longo ("Confirmar e Iniciar Assinatura Facial (12)") — deixa quebrar em
       duas linhas em vez de vazar por cima do botão vizinho, que é o que `.btn`'s
       `white-space: nowrap` (pensado para botões de largura livre) causava aqui: o texto
       continuava numa linha só e pintava por cima do outro botão, já que um <button> não corta
       overflow sozinho. */
    padding: 8px 10px;
    font-size: var(--text-xs);
    white-space: normal;
    text-align: center;
    line-height: 1.25;
  }

  /* 3. Menos espaço morto: mais conteúdo por tela e alvos de toque mais próximos. */
  .app-main {
    padding: var(--space-4) var(--space-3) var(--space-8);
  }

  .stepper {
    padding: var(--space-2) var(--space-3);
    gap: 2px;
  }

  .stepper__item {
    padding: 4px 8px 4px 4px;
  }

  .stepper__circle {
    width: 22px;
    height: 22px;
  }

  .stepper__label {
    font-size: var(--text-xs);
  }
}

/* Abaixo de 560px o rótulo do passo não cabe junto do círculo sem espremer o
   stepper inteiro — sobra o número, que é o que localiza a etapa. O passo atual
   mantém o rótulo, para não virar uma fileira de números sem contexto. */
@media (max-width: 560px) {
  .stepper__item:not([data-state="active"]) .stepper__label {
    display: none;
  }
}
