/* Hema Tools — estilos do portal (shell) e classes utilitárias para as ferramentas.
   Tokens: _init/design-system (hema-design-system.md + tokens/hub-index.css). */

:root {
  /* marca */
  --vermelho-hema: #ee3423;
  --vermelho-texto: #c8261a;
  --azul-hema: #83d5f7;
  --marinho: #0e1e3f;
  --marinho-profundo: #0a1530;
  --tint-azul: #e6f6fd;
  --tint-verde: #e3f4ea;
  --tint-amarelo: #fdf1d6;

  /* semânticos — tema claro */
  --bg: #f1f5f8;
  --surface: #ffffff;
  --surface-alt: #f6f8fb;
  --ink: #1c2533;
  --ink-muted: #5b6577;
  --line: #dce3ea;
  --line-forte: #c5cfd9;
  --titulo: #0e1e3f;
  --accent-text: #c8261a;
  --focus: #1a7db5;
  --tint-brand: #fdecea;
  --sidebar-bg: #0e1e3f;
  --sidebar-line: #243559;
  --sidebar-ink: #a9b4c6;
  --sidebar-ativo: #16295a;
  --tabela-cab: #0e1e3f;
  --tabela-cab-ink: #ffffff;
  --campo-bg: #ffffff;
  --ok: #1e7a48;
  --ok-tint: #e3f4ea;
  --erro: #c8261a;
  --erro-tint: #fdecea;
  --alerta: #8a5a06;
  --alerta-tint: #fdf1d6;
  --sec-bg: #0e1e3f;
  --sec-ink: #ffffff;

  --fonte: 'Lexend', Arial, Helvetica, sans-serif;
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --r-pill: 999px;
  --lateral: 248px;

  color-scheme: light;
}

/* escuro grafite (hub-index .dark) */
:root[data-tema='escuro'] {
  --bg: #17191d;
  --surface: #202328;
  --surface-alt: #2a2e35;
  --ink: #eef2f8;
  --ink-muted: #aab1bc;
  --line: #3a3f48;
  --line-forte: #4a505b;
  --titulo: #eef2f8;
  --accent-text: #83d5f7;
  --focus: #83d5f7;
  --tint-brand: #3b2224;
  --sidebar-bg: #0e0f12;
  --sidebar-line: #272a30;
  --sidebar-ink: #a9b4c6;
  --sidebar-ativo: #1d2026;
  --tabela-cab: #2a2e35;
  --tabela-cab-ink: #eef2f8;
  --campo-bg: #17191d;
  --ok: #34c27a;
  --ok-tint: #1b2e24;
  --erro: #f0645c;
  --erro-tint: #3b2224;
  --alerta: #e3a02f;
  --alerta-tint: #33291a;
  --sec-bg: #eef2f8;
  --sec-ink: #17191d;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  font-family: var(--fonte);
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3 {
  margin: 0;
  color: var(--titulo);
  font-weight: 600;
}
p {
  margin: 0;
}
a {
  color: var(--accent-text);
}
img,
svg {
  display: block;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-columns: var(--lateral) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.lateral {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  border-right: 1px solid var(--sidebar-line);
  overflow: hidden;
  z-index: 30;
}
/* anel da marca, cortado pela borda inferior da barra */
.lateral-anel {
  position: absolute;
  right: -150px;
  bottom: 190px;
  width: 300px;
  height: 300px;
  pointer-events: none;
}
@media (max-height: 680px) {
  .lateral-anel {
    display: none;
  }
}
.marca {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 20px;
  border-bottom: 1px solid var(--sidebar-line);
  text-decoration: none;
  color: #fff;
  position: relative;
}
.marca img {
  width: 36px;
  height: 36px;
  flex: none;
}
.marca-nome {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.marca-sub {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--azul-hema);
}

.abas {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  position: relative;
}
.abas-rotulo {
  padding: 0 10px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sidebar-ink);
  opacity: 0.75;
}
.abas ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}
.aba {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--sidebar-ink);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  border: 1px solid transparent;
}
.aba svg {
  width: 20px;
  height: 20px;
  flex: none;
}
.aba:hover {
  color: #fff;
  background: var(--sidebar-ativo);
}
.aba[aria-current='page'] {
  color: #fff;
  background: var(--sidebar-ativo);
  border-color: var(--sidebar-line);
}
.aba[aria-current='page'] svg {
  color: var(--azul-hema);
}
.aba[aria-current='page']::before {
  content: '';
  position: absolute;
  left: -13px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--vermelho-hema);
}
.aba:focus-visible {
  outline-color: var(--azul-hema);
}
.abas-vazio {
  padding: 10px 12px;
  font-size: 14px;
}

.lateral-rodape {
  position: relative;
  border-top: 1px solid var(--sidebar-line);
  padding: 14px 12px 16px;
  display: grid;
  gap: 4px;
}
.usuario {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  min-width: 0;
}
.usuario-inicial {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--azul-hema);
  color: var(--azul-hema);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}
.usuario-texto {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.usuario .chip-papel {
  flex: none;
  padding: 1px 8px;
  background: transparent;
  border-color: var(--sidebar-line);
  color: var(--sidebar-ink);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.usuario-nome {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lateral-acao {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--sidebar-ink);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
}
.lateral-acao svg {
  width: 18px;
  height: 18px;
  flex: none;
}
.lateral-acao:hover {
  color: #fff;
  background: var(--sidebar-ativo);
}
.lateral-acao:focus-visible {
  outline-color: var(--azul-hema);
}

/* barra superior (só mobile) */
.topo-mobile {
  display: none;
}
.fundo-menu {
  display: none;
}

.principal {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.cabecalho {
  padding: 36px 40px 24px;
  display: grid;
  gap: 8px;
  max-width: 1320px;
  width: 100%;
}
.cabecalho h1 {
  font-size: 32px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.cabecalho-desc {
  color: var(--ink-muted);
  font-size: 15px;
}
#conteudo {
  padding: 0 40px 56px;
  max-width: 1320px;
  width: 100%;
  min-width: 0;
}
#conteudo:focus {
  outline: none;
}
.carregando {
  color: var(--ink-muted);
  padding: 24px 0;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .topo-mobile {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 8px 0 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-line);
    color: #fff;
  }
  .topo-mobile .marca-nome {
    font-size: 16px;
  }
  .topo-mobile img {
    width: 28px;
    height: 28px;
  }
  .topo-mobile .marca-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    margin-right: auto;
  }
  .botao-menu {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    background: none;
    color: #fff;
    border-radius: var(--r-sm);
    cursor: pointer;
  }
  .botao-menu svg {
    width: 24px;
    height: 24px;
  }
  .botao-menu:focus-visible {
    outline-color: var(--azul-hema);
  }
  .lateral {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    visibility: hidden;
  }
  .app.menu-aberto .lateral {
    transform: none;
    visibility: visible;
  }
  .app.menu-aberto .fundo-menu {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(10, 21, 48, 0.55);
  }
  .cabecalho {
    padding: 24px 16px 16px;
  }
  .cabecalho h1 {
    font-size: 26px;
  }
  #conteudo {
    padding: 0 16px 40px;
  }
}

/* ------------------------------------------------- utilitárias (contrato) */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
  min-width: 0;
}
@media (max-width: 600px) {
  .card {
    padding: 20px 16px;
    border-radius: var(--r-md);
  }
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
  color: var(--accent-text);
}

.muted {
  color: var(--ink-muted);
}
.tabular {
  font-variant-numeric: tabular-nums;
}
.ok {
  color: var(--ok);
}
.erro {
  color: var(--erro);
}

/* campo: <label class="campo"><span>Rótulo</span><input></label> ou div.campo com label + input */
.campo {
  display: grid;
  gap: 6px;
  min-width: 0;
  align-content: start;
}
.campo > label,
.campo > span:first-child,
.campo > legend {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-text);
  padding: 0;
}
.campo input:not([type='radio']):not([type='checkbox']),
.campo select,
.campo textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-forte);
  border-radius: var(--r-sm);
  background: var(--campo-bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
}
.campo textarea {
  resize: vertical;
  min-height: 96px;
}
.campo input:hover,
.campo select:hover,
.campo textarea:hover {
  border-color: var(--ink-muted);
}
.campo input:focus-visible,
.campo select:focus-visible,
.campo textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}
.campo input[aria-invalid='true'],
.campo textarea[aria-invalid='true'] {
  border-color: var(--erro);
}
.campo input::placeholder,
.campo textarea::placeholder {
  color: var(--ink-muted);
  opacity: 0.75;
}
.campo .dica {
  font-size: 13px;
  color: var(--ink-muted);
  min-height: 1.4em;
}
fieldset.campo {
  border: 0;
  margin: 0;
  padding: 0;
}

/* linha: grid responsivo de campos */
.linha {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 16px 20px;
  align-items: start;
}

/* botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: none;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}
/* primário: branco sobre #EE3423 só com texto 600 >= 19px (contraste) */
.btn-primario {
  background: var(--vermelho-hema);
  color: #fff;
  font-size: 19px;
  font-weight: 600;
  padding: 12px 28px;
  min-height: 50px;
}
.btn-primario:hover:not(:disabled) {
  background: var(--vermelho-texto);
}
.btn-secundario {
  background: var(--sec-bg);
  color: var(--sec-ink);
}
.btn-secundario:hover:not(:disabled) {
  background: var(--marinho-profundo);
}
:root[data-tema='escuro'] .btn-secundario:hover:not(:disabled) {
  background: #fff;
}
.btn-fantasma {
  border-color: var(--line-forte);
  color: var(--titulo);
}
.btn-fantasma:hover:not(:disabled) {
  border-color: var(--titulo);
  background: var(--surface-alt);
}
.btn-pequeno {
  min-height: 34px;
  padding: 6px 14px;
  font-size: 14px;
}

/* chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--surface-alt);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}
.chip.ok {
  background: var(--ok-tint);
  border-color: transparent;
  color: var(--ok);
}
.chip.erro {
  background: var(--erro-tint);
  border-color: transparent;
  color: var(--erro);
}

/* aviso (caixa de mensagem) */
.aviso {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--alerta);
  border-radius: var(--r-sm);
  background: var(--alerta-tint);
  color: var(--ink);
  font-size: 14px;
  white-space: pre-line;
}
.aviso.ok {
  border-left-color: var(--ok);
  background: var(--ok-tint);
  color: var(--ink);
}
.aviso.erro {
  border-left-color: var(--erro);
  background: var(--erro-tint);
  color: var(--ink);
}

/* tabela: envolver em .tabela-rolagem para rolar dentro do card */
.tabela-rolagem {
  position: relative; /* contém .sr-only das células (senão alarga a página) */
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  -webkit-overflow-scrolling: touch;
}
.tabela {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.tabela th {
  background: var(--tabela-cab);
  color: var(--tabela-cab-ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: left;
  padding: 12px 14px;
  white-space: nowrap;
}
.tabela td {
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  vertical-align: top;
}
.tabela tbody tr:nth-child(even) td {
  background: var(--surface-alt);
}
.tabela tbody tr:first-child td {
  border-top: 0;
}
.tabela .num,
.tabela th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tabela-rolagem > .tabela th:first-child {
  border-top-left-radius: calc(var(--r-md) - 1px);
}
.tabela-rolagem > .tabela th:last-child {
  border-top-right-radius: calc(var(--r-md) - 1px);
}

/* toast (window.toast(msg, tipo)) */
.toasts {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  display: grid;
  gap: 8px;
  justify-items: end;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 12px 18px 12px 14px;
  border-radius: var(--r-md);
  background: var(--marinho);
  color: #fff;
  border: 1px solid var(--sidebar-line);
  font-size: 14px;
  font-weight: 500;
  animation: toast-entra 0.22s ease;
}
.toast::before {
  content: '';
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--azul-hema);
}
.toast.ok::before {
  background: #34c27a;
}
.toast.erro::before {
  background: var(--vermelho-hema);
}
.toast.aviso::before {
  background: #f9b533;
}
.toast.sai {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
@keyframes toast-entra {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (max-width: 600px) {
  .toasts {
    left: 16px;
    right: 16px;
    bottom: 16px;
    justify-items: stretch;
  }
  .toast {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
