:root {
  --fundo: #f4f5f7;
  --cartao: #ffffff;
  --texto: #1c1e21;
  --discreto: #6b7280;
  --borda: #e3e5e8;
  --primario: #2563eb;
  --primario-escuro: #1d4ed8;
  --ok: #15803d;
  --ok-fundo: #dcfce7;
  --ruim: #b91c1c;
  --ruim-fundo: #fee2e2;
  --aviso: #92400e;
  --aviso-fundo: #fef3c7;
  --neutro-fundo: #eef0f3;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #111316;
    --cartao: #1b1e22;
    --texto: #e8eaed;
    --discreto: #9aa0a8;
    --borda: #2c3036;
    --primario: #3b82f6;
    --primario-escuro: #2563eb;
    --ok: #4ade80;
    --ok-fundo: #14321f;
    --ruim: #f87171;
    --ruim-fundo: #3b1717;
    --aviso: #fbbf24;
    --aviso-fundo: #3a2c0b;
    --neutro-fundo: #262a30;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--texto);
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0; overflow-wrap: anywhere; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; }
.discreto { color: var(--discreto); }
.alerta { color: var(--aviso); }

/* botões */
.botao {
  font: inherit; font-weight: 500;
  padding: .5rem .9rem; border-radius: 8px;
  border: 1px solid var(--borda); background: var(--cartao); color: var(--texto);
  cursor: pointer; white-space: nowrap;
}
.botao:hover { border-color: var(--discreto); }
.botao:disabled { opacity: .6; cursor: wait; }
.botao.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.botao.primario:hover { background: var(--primario-escuro); }
.botao.perigo { background: var(--ruim); border-color: var(--ruim); color: #fff; }
.botao.perigo-texto { color: var(--ruim); }
.botao.pequeno { padding: .2rem .55rem; font-size: .85rem; }
.botao.largo { width: 100%; }

/* login */
.tela-login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.cartao-login { width: 100%; max-width: 340px; display: grid; gap: 1rem; }
.cartao-login h1 { text-align: center; }

/* estrutura */
.topo {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.25rem; background: var(--cartao); border-bottom: 1px solid var(--borda);
}
.topo h1 { display: inline; margin-right: .5rem; }
.acoes { display: flex; gap: .5rem; flex-wrap: wrap; }
main { max-width: 860px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.titulo-secao { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1rem; }
.titulo-secao h2 { margin: 0; }
#resumo-monitor { font-size: .85rem; margin: .4rem 0 1rem; }

.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 12px; padding: 1.1rem 1.25rem; }
.lista { display: grid; gap: .85rem; }
.vazio { text-align: center; }
.vazio p { margin: .25rem 0; }

/* registro */
.registro { display: grid; gap: .85rem; }
.linha-topo { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.detalhes { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .5rem 1rem; margin: 0; }
.detalhes dt { font-size: .78rem; color: var(--discreto); text-transform: uppercase; letter-spacing: .03em; }
.detalhes dd { margin: 0; overflow-wrap: anywhere; }
.cliente {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: var(--neutro-fundo); border-radius: 8px; padding: .5rem .75rem;
}
.cliente code { font-weight: 600; overflow-wrap: anywhere; }

/* selos */
.selo { display: inline-block; font-size: .8rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.selo.ok { background: var(--ok-fundo); color: var(--ok); }
.selo.ruim { background: var(--ruim-fundo); color: var(--ruim); white-space: normal; }
.selo.neutro { background: var(--neutro-fundo); color: var(--discreto); }
.selo.aviso { background: var(--aviso-fundo); color: var(--aviso); vertical-align: middle; }

/* histórico */
.historico { list-style: none; padding: 0; margin: 0; background: var(--cartao); border: 1px solid var(--borda); border-radius: 12px; }
.historico li { padding: .55rem 1rem; border-top: 1px solid var(--borda); font-size: .9rem; }
.historico li:first-child { border-top: 0; }
.historico time { color: var(--discreto); font-variant-numeric: tabular-nums; margin-right: .35rem; }

/* formulários */
.campo { display: grid; gap: .3rem; }
.campo > span { font-weight: 500; font-size: .92rem; }
.campo small { font-size: .8rem; }
input:not([type=checkbox]), textarea {
  font: inherit; width: 100%; padding: .55rem .7rem;
  border: 1px solid var(--borda); border-radius: 8px; background: var(--fundo); color: var(--texto);
}
input:focus, textarea:focus { outline: 2px solid var(--primario); outline-offset: -1px; }
.com-sufixo { display: flex; align-items: center; border: 1px solid var(--borda); border-radius: 8px; background: var(--fundo); overflow: hidden; }
.com-sufixo input { border: 0; border-radius: 0; flex: 1; min-width: 4rem; }
.com-sufixo span { padding: 0 .7rem; color: var(--discreto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.campo-check { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; }
.campo-check input { margin-top: .3rem; }
.sugestoes { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; font-size: .85rem; }
.erro { color: var(--ruim); margin: 0; min-height: 1.2em; font-size: .9rem; }
.faixa-erro { background: var(--ruim-fundo); color: var(--ruim); padding: .7rem 1rem; border-radius: 8px; }

/* diálogo */
dialog {
  border: 1px solid var(--borda); border-radius: 14px; padding: 0;
  width: min(480px, calc(100vw - 2rem)); background: var(--cartao); color: var(--texto);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.form-dialogo { padding: 1.25rem; display: grid; gap: 1rem; }
.form-dialogo h3 { font-size: 1.1rem; }
#dialogo-corpo { display: grid; gap: 1rem; }
.aviso-dialogo { margin: 0; background: var(--aviso-fundo); color: var(--aviso); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }
.acoes-dialogo { display: flex; justify-content: flex-end; gap: .5rem; }

@media (max-width: 520px) {
  .topo { padding: .8rem 1rem; }
  main { padding: .75rem .9rem 2.5rem; }
  .cartao { padding: 1rem; }
  .acoes .botao { flex: 1; }
  .registro .acoes .botao { flex: 1 1 auto; }
  .cliente code { font-size: .8rem; }
}
