/* ui.css — componentes compartilhados: botão, campo, card, modal, toast, vazio, selo. */

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--toque); padding: 0 var(--s-5);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-size: var(--fs-md); font-weight: var(--fw-semi); white-space: nowrap;
  transition: background var(--dur-1), border-color var(--dur-1), transform var(--dur-1);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-p { background: var(--acc); color: var(--acc-ink); }
.btn-p:hover:not(:disabled) { background: var(--acc-hover); }
.btn-g { background: var(--surf-2); border-color: var(--brd); color: var(--txt); }
.btn-g:hover:not(:disabled) { background: var(--surf-3); border-color: var(--brd-2); }
.btn-d { background: var(--err-solid); color: var(--err-ink); }
.btn-d:hover:not(:disabled) { filter: brightness(1.1); }
.btn-w { background: color-mix(in srgb, var(--warn) 16%, transparent); border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); }
.btn-link { min-height: var(--toque); padding: 0 var(--s-2); color: var(--acc-txt); font-weight: var(--fw-medium); border-radius: var(--r-sm); }
.btn-link:hover { text-decoration: underline; }
.btn-link:disabled { color: var(--txt-3); text-decoration: none; cursor: default; }
.btn-sm { padding: 0 var(--s-4); font-size: var(--fs-sm); }
.btn-bloco { width: 100%; }

.btn-ic {
  display: inline-grid; place-items: center;
  width: var(--toque); height: var(--toque);
  border-radius: var(--r-md); color: var(--txt-2);
  transition: background var(--dur-1), color var(--dur-1);
}
.btn-ic:hover { background: var(--surf-2); color: var(--txt); }

/* ---------- Campos ---------- */
.field { display: grid; gap: var(--s-2); margin-bottom: var(--s-4); }
.field > label, .field > .lbl { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--txt-2); }
.field .obr { color: var(--err); }
.field .dica { color: var(--txt-3); font-weight: var(--fw-regular); }
.field-nota { font-size: var(--fs-sm); color: var(--txt-2); }

.inp, .inp-wrap {
  width: 100%; min-height: 46px;
  background: var(--surf); border: 1px solid var(--brd-2); border-radius: var(--r-md);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.inp { padding: 0 var(--s-4); }
textarea.inp { padding: var(--s-3) var(--s-4); min-height: 120px; resize: vertical; }
.inp::placeholder, .inp-wrap input::placeholder { color: var(--txt-3); }
.inp:focus, .inp-wrap:focus-within {
  outline: none; border-color: var(--acc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 28%, transparent);
}
.inp-wrap { display: flex; align-items: center; gap: var(--s-3); padding-left: var(--s-4); color: var(--txt-3); }
.inp-wrap input { flex: 1; min-width: 0; height: 44px; background: none; border: 0; outline: none; color: var(--txt); }
.inp-wrap .btn-ic { margin-right: 2px; }

.inp-codigo {
  text-align: center; font-family: var(--font-mono); font-size: var(--fs-2xl);
  letter-spacing: 0.4em; padding-left: 0.4em; min-height: 64px;
}

.check { display: flex; gap: var(--s-3); align-items: flex-start; font-size: var(--fs-sm); color: var(--txt-2); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--acc); flex: none; }

/* Grupo de opções (radiogroup "como conheceu") */
.cc-opcoes { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cc-op {
  min-height: var(--toque); padding: 0 var(--s-4);
  border: 1px solid var(--brd-2); border-radius: var(--r-full);
  background: var(--surf); color: var(--txt-2); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  transition: all var(--dur-1);
}
.cc-op:hover { border-color: var(--acc); color: var(--txt); }
.cc-op[aria-checked="true"] {
  background: color-mix(in srgb, var(--acc) 16%, transparent);
  border-color: var(--acc); color: var(--acc-txt);
}

/* ---------- Mensagens inline ---------- */
.msg-err, .msg-ok {
  display: none; padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4);
  border-radius: var(--r-md); font-size: var(--fs-sm); border: 1px solid;
}
.msg-err { color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.msg-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.msg-err.on, .msg-ok.on { display: block; }

/* ---------- Card, selo, vazio, esqueleto ---------- */
.card { background: var(--surf); border: 1px solid var(--brd); border-radius: var(--r-lg); padding: var(--s-6); }

.selo {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 2px var(--s-2); border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: var(--fw-semi); letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--acc) 16%, transparent); color: var(--acc-txt);
}
.selo:empty { display: none; }
.selo-off { background: var(--surf-3); color: var(--txt-2); }
.selo-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.selo-warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.selo-info { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.selo-err { background: color-mix(in srgb, var(--err) 16%, transparent); color: var(--err); }
.selo { white-space: nowrap; }

/* Avatar com inicial (a foto, se houver, cobre a letra) */
.av {
  position: relative; display: grid; place-items: center; flex: none; overflow: hidden;
  width: 40px; height: 40px; border-radius: var(--r-full);
  background: var(--surf-3); color: var(--txt-2); font-weight: var(--fw-bold);
}
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.av-sm { width: 24px; height: 24px; font-size: var(--fs-xs); }
.av-lg { width: 48px; height: 48px; font-size: var(--fs-lg); }
.av-sm .ic { width: 14px; height: 14px; }

.ponto { width: 8px; height: 8px; flex: none; border-radius: var(--r-full); }
.ponto-warn { background: var(--warn); }
.ponto-err { background: var(--err); }

/* Chave liga/desliga */
.sw {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: 44px; height: 26px; border-radius: var(--r-full); background: var(--surf-3); border: 1px solid var(--brd-2);
  transition: background var(--dur-1), border-color var(--dur-1);
}
.sw::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: var(--r-full);
  background: var(--txt-2); transition: transform var(--dur-2) var(--ease), background var(--dur-1);
}
.sw:checked { background: var(--acc); border-color: var(--acc); }
.sw:checked::after { transform: translateX(18px); background: var(--acc-ink); }
.sw:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-perigo { background: none; border-color: color-mix(in srgb, var(--err) 45%, transparent); color: var(--err); }
.btn-perigo:hover:not(:disabled) { background: color-mix(in srgb, var(--err) 12%, transparent); }
select.inp { cursor: pointer; }

.empty {
  display: grid; justify-items: center; gap: var(--s-3);
  padding: var(--s-8) var(--s-5); text-align: center; color: var(--txt-2);
  border: 1px dashed var(--brd-2); border-radius: var(--r-lg);
}
.empty .ic { width: 32px; height: 32px; color: var(--txt-3); stroke-width: 1.5; }
.empty-err { border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.empty-err .ic { color: var(--err); }

.skel {
  border-radius: var(--r-md); min-height: 18px;
  background: linear-gradient(90deg, var(--surf-2) 25%, var(--surf-3) 50%, var(--surf-2) 75%);
  background-size: 200% 100%; animation: skel 1.3s linear infinite;
}
@keyframes skel { to { background-position: -200% 0; } }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: none; align-items: center; justify-content: center;
  padding: var(--s-4); background: var(--overlay);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  overflow-y: auto;
}
.modal.open { display: flex; }
.modal.gate { z-index: var(--z-gate); }
.modal-card {
  position: relative; width: min(100%, 460px); margin: auto;
  background: var(--surf); border: 1px solid var(--brd); border-radius: var(--r-xl);
  padding: var(--s-7) var(--s-6) var(--s-6); box-shadow: var(--sh-3);
  animation: modal-in var(--dur-3) var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.96) translateY(8px); } }
.modal-card h2 { font-size: var(--fs-xl); margin-bottom: var(--s-2); padding-right: var(--s-7); }
.modal-desc { color: var(--txt-2); margin-bottom: var(--s-5); white-space: pre-line; }
.modal-x { position: absolute; top: var(--s-3); right: var(--s-3); }
.modal-acoes { display: flex; gap: var(--s-3); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--s-5); }
.modal-ic {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--s-4);
  border-radius: var(--r-lg); color: var(--acc-txt);
  background: color-mix(in srgb, var(--acc) 14%, transparent);
}
.modal-ic .ic { width: 28px; height: 28px; }
.modal-lista { margin: 0 0 var(--s-5); padding: 0; list-style: none; display: grid; gap: var(--s-2); color: var(--txt-2); }
.modal-lista li { display: flex; gap: var(--s-2); align-items: flex-start; }
.modal-lista .ic { color: var(--ok); margin-top: 2px; }

@media (max-width: 760px) {
  .card { padding: var(--s-4); }
  .modal-acoes .btn { flex: 1; }
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: var(--s-4); right: var(--s-4); bottom: var(--s-6); z-index: var(--z-toast);
  display: none; align-items: center; gap: var(--s-3);
  width: fit-content; max-width: min(calc(100vw - var(--s-7)), 520px); margin-inline: auto;
  padding: var(--s-3) var(--s-5);
  background: var(--surf-3); color: var(--txt);
  border: 1px solid var(--brd-2); border-left-width: 4px; border-radius: var(--r-md);
  box-shadow: var(--sh-2); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  animation: toast-in var(--dur-3) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
#toast .ic { width: 18px; height: 18px; stroke-width: 2.4; }
#toast.toast-success { border-left-color: var(--ok); } #toast.toast-success .ic { color: var(--ok); }
#toast.toast-error { border-left-color: var(--err); } #toast.toast-error .ic { color: var(--err); }
#toast.toast-warn { border-left-color: var(--warn); } #toast.toast-warn .ic { color: var(--warn); }
#toast.toast-info { border-left-color: var(--info); } #toast.toast-info .ic { color: var(--info); }

/* ---------- Seletor próprio (js/seletor.js) ---------- */
.sel-proprio > select { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.sel-btn {
  display: inline-flex; align-items: center; max-width: 100%; min-height: var(--toque);
  padding: 0 28px 0 var(--s-3); border-radius: var(--r-sm);
  color: var(--txt); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  transition: background var(--dur-1);
}
.sel-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-btn:hover, .sel.aberto .sel-btn { background: var(--surf-3); }
.sel.aberto::after { transform: translateY(-20%) rotate(225deg); }
.sel::after { transition: transform var(--dur-2) var(--ease); }

.sel-pop {
  position: fixed; z-index: calc(var(--z-modal) + 50); overflow-y: auto;
  padding: var(--s-1); display: grid; gap: 2px;
  background: var(--surf-3); border: 1px solid var(--brd-2); border-radius: var(--r-md); box-shadow: var(--sh-2);
  transform-origin: top right; animation: sel-in var(--dur-1) var(--ease);
}
.sel-pop.sobe { transform-origin: bottom right; }
@keyframes sel-in { from { opacity: 0; transform: scale(0.97) translateY(-4px); } }
.sel-op {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-sm);
  color: var(--txt-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap; cursor: pointer;
}
.sel-op.foco { background: var(--surf-2); color: var(--txt); }
.sel-op[aria-selected="true"] { color: var(--acc-txt); }
.sel-op .ic { width: 16px; height: 16px; }

/* ---------- Números em destaque ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2); }
.stat { display: grid; gap: 2px; padding: var(--s-3); border: 1px solid var(--brd); border-radius: var(--r-md); background: var(--surf); }
.stat b { font-family: var(--font-display); font-size: var(--fs-xl); line-height: var(--lh-tight); letter-spacing: var(--ls-display); }
.stat b .ic { width: 22px; height: 22px; color: var(--ok); }
.stat span { font-size: var(--fs-xs); color: var(--txt-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-forte { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; }
.stat-forte b { font-size: var(--fs-2xl); color: var(--acc-txt); }
.stat-forte span { font-size: var(--fs-sm); color: var(--txt-2); order: -1; }

/* ---------- Barra de uso / progresso ---------- */
.barra { height: 8px; border-radius: var(--r-full); background: var(--surf-3); overflow: hidden; }
.barra span { display: block; height: 100%; border-radius: var(--r-full); background: linear-gradient(90deg, var(--brand-1), var(--brand-2)); transition: width var(--dur-3) var(--ease); }
.barra-warn span { background: var(--warn); }
.barra-err span { background: var(--err); }

/* ---------- Lista de escolha (dentro de uiCaixa) ---------- */
.caixa-corpo { display: grid; gap: var(--s-3); }
.lista-check { list-style: none; margin: 0; padding: var(--s-1); max-height: 320px; overflow-y: auto; display: grid; gap: 2px; border: 1px solid var(--brd); border-radius: var(--r-md); background: var(--surf-2); }
.lista-check label { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: 0 var(--s-3); border-radius: var(--r-sm); cursor: pointer; }
.lista-check label:hover { background: var(--surf-3); }
.lista-check input, .check-forte input { width: 18px; height: 18px; flex: none; accent-color: var(--acc); }
.lista-check .lc-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.lista-check small { font-size: var(--fs-xs); color: var(--txt-3); white-space: nowrap; }
.lista-check.travada { opacity: 0.5; pointer-events: none; }
.lc-topo { display: flex; align-items: center; justify-content: space-between; font-size: var(--fs-sm); color: var(--txt-2); }
.lc-conta { font-size: var(--fs-sm); color: var(--txt-3); }
.check-forte { align-items: flex-start; padding: var(--s-3); border: 1px solid var(--brd); border-radius: var(--r-md); background: var(--surf-2); color: var(--txt); }
.check-forte b, .check-forte small { display: block; }
.check-forte small { color: var(--txt-3); font-size: var(--fs-xs); }
.busca-cheia { width: 100%; }

/* Avatares empilhados */
.pilha { display: inline-flex; }
.pilha .av { border: 2px solid var(--surf-2); margin-left: -8px; }
.pilha .av:first-child { margin-left: 0; }
.pilha-mais { font-size: 10px; }
.av-marca { background: color-mix(in srgb, var(--acc) 14%, transparent); color: var(--acc-txt); }

/* Cabeçalho de página com ação à direita */
.ph-acao { align-items: center; justify-content: space-between; flex-wrap: wrap; }
.ph-acao h1 { width: auto; }
.ph-acao > div:first-child { display: grid; gap: var(--s-2); min-width: 0; }
.ph-acao p { flex: none; }
.card-intro { margin: calc(var(--s-2) * -1) 0 var(--s-4); font-size: var(--fs-sm); color: var(--txt-2); }
.card-intro code { padding: 1px var(--s-2); border-radius: var(--r-sm); background: var(--surf-3); font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--txt); }
.nota-loop { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--fs-sm); color: var(--txt-2); }
.nota-loop .ic { width: 16px; height: 16px; margin-top: 2px; color: var(--acc-txt); }

/* Barras por estado e segmento com texto */
.barra-ok span { background: var(--ok); }
.barra-info span { background: var(--info); }
.seg { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--brd); border-radius: var(--r-md); background: var(--surf); }
.seg-op { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); color: var(--txt-3); transition: background var(--dur-1), color var(--dur-1); }
.seg-op .ic { width: 18px; height: 18px; }
.seg-op:hover { color: var(--txt); }
.seg-op[aria-pressed="true"] { background: var(--surf-3); color: var(--acc-txt); }
.seg-txt .seg-op { width: auto; padding: 0 var(--s-4); font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap; }
.mono { font-family: var(--font-mono); }
.av-xl { width: 60px; height: 60px; font-size: var(--fs-xl); }
.chk { width: 18px; height: 18px; accent-color: var(--acc); cursor: pointer; }
.btn-quieto { display: inline-flex; align-items: center; gap: var(--s-2); }
.btn-quieto .ic { width: 16px; height: 16px; }
.btn-quieto[aria-pressed="true"] { color: var(--acc-txt); }
.link-mini { color: var(--acc-txt); font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Tabela de dados ---------- */
.tabela-wrap { border: 1px solid var(--brd); border-radius: var(--r-md); background: var(--surf-2); overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tabela th { padding: var(--s-3); text-align: left; font-size: var(--fs-xs); font-weight: var(--fw-semi); color: var(--txt-3); white-space: nowrap; border-bottom: 1px solid var(--brd); }
.tabela td { padding: var(--s-2) var(--s-3); vertical-align: middle; border-top: 1px solid var(--brd); }
.tabela tbody tr:first-child td { border-top: 0; }
.tabela tbody tr { transition: background var(--dur-1); }
.tabela tbody tr:hover { background: color-mix(in srgb, var(--surf-3) 55%, transparent); }
.tabela tr.marcada { background: color-mix(in srgb, var(--acc) 9%, transparent); }
.td-chk { width: 44px; padding-left: var(--s-4) !important; }
.td-x { width: 48px; text-align: right; }
.td-data { white-space: nowrap; color: var(--txt-2); font-variant-numeric: tabular-nums; }
.bulk { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); margin-bottom: var(--s-3); border-radius: var(--r-md); background: color-mix(in srgb, var(--acc) 12%, transparent); border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent); font-size: var(--fs-sm); }

/* ---------- Abas ---------- */
.abas { display: flex; gap: var(--s-1); margin-bottom: var(--s-5); border-bottom: 1px solid var(--brd); overflow-x: auto; scrollbar-width: none; }
.abas::-webkit-scrollbar { display: none; }
.abas [role="tab"] { position: relative; min-height: 44px; padding: 0 var(--s-4); color: var(--txt-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; transition: color var(--dur-1), background var(--dur-1); }
.abas [role="tab"]:hover { color: var(--txt); background: var(--surf-2); }
.abas [role="tab"][aria-selected="true"] { color: var(--txt); font-weight: var(--fw-semi); }
.abas [role="tab"][aria-selected="true"]::after { content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 2px; border-radius: var(--r-full); background: var(--acc); }
.rotulo { display: block; font-size: var(--fs-xs); font-weight: var(--fw-semi); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--txt-3); }
.secao-t { font-size: var(--fs-lg); margin: var(--s-6) 0 var(--s-4); }
.td-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cx-status-ok { color: var(--ok); }
.stepper { display: inline-flex; align-items: center; gap: var(--s-1); flex: none; }
.stepper .btn-ic { border: 1px solid var(--brd-2); font-size: var(--fs-lg); line-height: 1; color: var(--txt); }
.stepper b { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
.cupom { display: inline-flex; gap: var(--s-2); flex: none; }
.cupom .inp-mini { width: 132px; text-transform: uppercase; }
.cfg-row > .cupom, .cfg-row > .stepper { max-width: none; }

/* Seletor em formato de campo (largura cheia, com borda), pra usar em formulários */
.sel-campo { display: flex; margin: 0; min-height: 46px; border: 1px solid var(--brd-2); border-radius: var(--r-md); background: var(--surf); transition: border-color var(--dur-1); }
.sel-campo:hover, .sel-campo.aberto { border-color: var(--acc); }
.sel-campo select, .sel-campo .sel-btn { flex: 1; width: 100%; min-height: 44px; padding: 0 36px 0 var(--s-4); text-align: left; text-align-last: left; justify-content: flex-start; font-size: var(--fs-md); border-radius: var(--r-md); }
.sel-campo .sel-btn:hover, .sel-campo.aberto .sel-btn { background: none; }
.sel-campo::after { right: 16px; }

/* Alvos pequenos por desenho ganham área de toque invisível de 40 px */
.chip-x button, .chip-id, .post-capa { position: relative; }
.chip-x button::after, .chip-id::after { content: ""; position: absolute; inset: -6px; }
.post-capa::after { content: ""; position: absolute; inset: 0 -5px; }
