/**
 * Componentes compartilhados v2 (AB#486). Somente variáveis de tokens.css — sem cores literais.
 * Referência: project/design/redesign-v2/redesign.css (formulários, superfícies, status, timeline, resumo, tabela, chip)
 * e design/redesign-v2/Catalogo.dc.html (switch). Sem tab bar/action bar (R8).
 */

/* ---- Campos ---- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label, .field-label { font-size: 14px; line-height: 20px; font-weight: 600; color: var(--ink); }
.input,
.textarea,
.field input:where(:not([type="checkbox"], [type="radio"], [type="file"], [type="range"])),
.field select,
.field textarea {
  width: 100%;
  height: var(--h-input);
  padding: 0 14px;
  border: 1px solid var(--control);
  border-radius: var(--r-input);
  background: var(--inset);
  font: 400 16px/24px var(--font-sans);
  color: var(--ink);
}
.textarea,
.field textarea { height: auto; min-height: 104px; padding: 12px 14px; resize: vertical; }
.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"],
.field select[aria-invalid="true"] { border-color: var(--bad); }
.input.num, .textarea.num { font-variant-numeric: tabular-nums; }
.field-help { font-size: 13px; line-height: 18px; color: var(--text2); }
.field-error { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--bad); }

/* ---- Segmentado ---- */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-seg);
  background: var(--inset);
}
.seg button {
  height: var(--h-opt);
  border: 0;
  border-radius: var(--r-opt);
  background: transparent;
  font: 600 14px/20px var(--font-sans);
  color: var(--text2);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--ink); box-shadow: var(--shadow); }

/* ---- Check e choice ---- */
.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font: inherit;
}
.check[aria-checked="true"] { border-color: var(--brand); background: var(--wash); }
.check .box {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1.5px solid var(--control);
  background: var(--raised);
  color: var(--on-brand);
}
.check .box svg { display: none; }
.check[aria-checked="true"] .box { background: var(--brand); border-color: var(--brand); }
.check[aria-checked="true"] .box svg { display: block; }
.choice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--raised);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.choice[aria-pressed="true"] { border: 2px solid var(--brand); padding: 15px; background: var(--wash); }

/* ---- Stepper ---- */
.stepper { display: inline-flex; align-items: center; gap: 4px; padding: 4px; border-radius: var(--r-pill); background: var(--inset); }
.stepper button {
  width: var(--h-step);
  height: var(--h-step);
  border: 0;
  border-radius: var(--r-pill);
  background: var(--raised);
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.stepper button:disabled { opacity: 0.5; cursor: not-allowed; }
.stepper .num { min-width: 32px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Switch ---- */
.sw {
  position: relative;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--line);
  cursor: pointer;
  flex: none;
}
.sw::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--on-grad);
  box-shadow: var(--shadow);
  transition: translate var(--motion-fast);
}
.sw[aria-checked="true"] { background: var(--brand); }
.sw[aria-checked="true"]::after { translate: 18px 0; }
.sw:disabled, .sw[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* ---- Chip ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--raised);
  font: 600 13px/18px var(--font-sans);
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  transition: none;
}
.chip:hover { background: var(--inset); color: var(--ink); border-color: var(--line); transform: none; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--page); }

/* ---- Superfícies ---- */
.card { background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-card); padding: 24px; box-shadow: none; }
/* .card.stack sem gap inline ficava com o título, o conteúdo e o CTA colados (achado do PO: painel
   de resumo, Subtotal/Total encostado no botão Continuar). 16px = "dentro do cartão" (LY1). Inline
   style continua ganhando onde já existe um gap explícito diferente. */
.card.stack { gap: 16px; }
.card-flat { background: var(--inset); border-radius: 18px; padding: 16px; }
.hr { height: 1px; background: var(--line); border: 0; }
.list > * + * { border-top: 1px solid var(--line); }
.lrow { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 4px; }
.row-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--wash); color: var(--brand); }
.avatar-ini { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-pill); background: var(--wash); color: var(--brand); font-size: 14px; font-weight: 800; }
@media (max-width: 767px) {
  .card { padding: 18px; }
}

/* ---- Badge (ponto + texto) ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-pill); background: currentColor; }
.b-wait { background: var(--warn-bg); color: var(--warn); }
.b-prod { background: var(--info-bg); color: var(--info); }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-neutral { background: var(--inset); color: var(--text2); }

/* ---- Progresso em segmentos e timeline ---- */
.pbar { display: flex; gap: 8px; }
.pbar span { flex: 1; height: 4px; border-radius: var(--r-pill); background: var(--line); }
.pbar span.on { background: var(--brand); }
.tl { display: flex; flex-direction: column; }
.tl li { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: 0 14px; padding-bottom: 20px; }
.tl li::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 2px; width: 2px; background: var(--line); }
.tl li:last-child::before { display: none; }
.tl li.done::before { background: var(--brand); }
.tl-dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-pill); border: 2px solid var(--line); background: var(--page); color: var(--on-brand); }
.tl li.done .tl-dot { background: var(--brand); border-color: var(--brand); }
.tl li.now .tl-dot { border-color: var(--brand); box-shadow: 0 0 0 4px var(--wash); }
.tl-title { font-size: 15px; line-height: 28px; font-weight: 600; color: var(--subtle); }
.tl li.done .tl-title { color: var(--ink); }
.tl li.now .tl-title { color: var(--ink); font-weight: 800; }
.tl-meta { grid-column: 2; font-size: 13px; line-height: 18px; color: var(--text2); }

/* ---- Resumo ---- */
.sum { display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 20px; }
.sum-row { display: flex; justify-content: space-between; gap: 16px; }
.sum-row dt { color: var(--text2); }
.sum-row dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.sum-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 1px solid var(--line); }

/* ---- Tabela e lista móvel ---- */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--raised); }
.table-wrap table, .table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.table-wrap th, .table th { padding: 12px 16px; text-align: left; font-size: 12px; line-height: 16px; font-weight: 700; color: var(--text2); background: var(--inset); white-space: nowrap; border-bottom: 0; }
.table-wrap td, .table td { padding: 14px 16px; border-top: 1px solid var(--line); border-bottom: 0; vertical-align: middle; }
.table-wrap tbody tr:hover td, .table tbody tr:hover td { background: color-mix(in srgb, var(--inset) 60%, transparent); }
.mlist { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 18px; background: var(--raised); }
.mlist > * + * { border-top: 1px solid var(--line); }
.mlist-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.mlist-row:hover { background: var(--inset); }

/* ---- Menu da conta (base visual; lógica na Story AB#545) ---- */
.umenu-wrap { position: relative; display: inline-flex; }
.umenu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 264px;
  max-width: calc(100vw - 32px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--raised);
  box-shadow: var(--paper-shadow);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.umenu-head { display: flex; flex-direction: column; padding: 10px 12px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.umenu a, .umenu button.mi {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font: 600 14px/20px var(--font-sans);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.umenu a:hover, .umenu button.mi:hover { background: var(--inset); }
.umenu .mi-strong { color: var(--brand); }
.umenu .mi-danger { color: var(--bad); }
.umenu .sep { height: 1px; margin: 6px 4px; background: var(--line); }

.link { color: var(--brand); font-weight: 700; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Utilitários do redesign v2 */
/* Gap padrão de 12px (D13): .row era usado em dezenas de lugares sem gap inline — qualquer um
   esquecido deixava os filhos se tocando (achado do PO, ex.: "Editar"/"Desfazer colagem" colados
   em order.js). Inline style continua ganhando onde já existe um gap explícito diferente. */
.row { display: flex; align-items: center; gap: 12px; }
.pg-reset h1, .pg-reset h2, .pg-reset h3, .pg-reset p, .pg-reset ol, .pg-reset ul, .pg-reset dl, .pg-reset dd { margin: 0; }
.pg-reset ol, .pg-reset ul { padding: 0; list-style: none; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
