/* GlicOk — mobile first: o estilo base é o do celular; telas maiores só acrescentam (min-width). */
:root {
  --fundo: #f6f4f2;
  --cartao: #ffffff;
  --texto: #1f2933;
  --texto-suave: #5b6770;
  --borda: #e3dedb;
  --marca: #b91c1c;
  --marca-escura: #991b1b;
  --ok: #15803d;
  --ok-fundo: #dcfce7;
  --alerta: #b45309;
  --alerta-fundo: #fef3c7;
  --ruim: #b91c1c;
  --ruim-fundo: #fee2e2;
  --cabecalho-tabela: #eceae8;
  --campo: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #15171a;
    --cartao: #1f2226;
    --texto: #eceff1;
    --texto-suave: #a5afb7;
    --borda: #343a40;
    --marca: #ef4444;
    --marca-escura: #dc2626;
    --ok: #4ade80;
    --ok-fundo: #12361f;
    --alerta: #fbbf24;
    --alerta-fundo: #3b2f0e;
    --ruim: #f87171;
    --ruim-fundo: #43191b;
    --cabecalho-tabela: #2b3036;
    --campo: #15171a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fundo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 1.4rem; color: var(--texto-suave); font-weight: 600; }

/* ---------- Senha ---------- */
.entrada { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.entrada-caixa { width: 100%; max-width: 380px; background: var(--cartao); border: 1px solid var(--borda); border-radius: 16px; padding: 24px 18px; text-align: center; }
.entrada-logo { width: 72px; height: 72px; }
.entrada h1 { font-size: 1.9rem; margin: .3rem 0 .6rem; color: var(--marca); }
.entrada form { text-align: left; }

/* ---------- Topo ---------- */
.topo {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  background: var(--cartao); border-bottom: 1px solid var(--borda);
}
.topo-marca { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.25rem; color: var(--marca); }
.topo-usuario { display: flex; align-items: center; gap: 8px; color: var(--texto-suave); font-size: .95rem; min-width: 0; }
.topo-usuario span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

.conteudo {
  display: grid; gap: 12px; margin: 0 auto; max-width: 860px;
  padding: 12px; padding-bottom: calc(28px + env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
}

/* ---------- Cartões ---------- */
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 14px; padding: 16px 14px; min-width: 0; }
.cartao-topo { display: grid; gap: 10px; margin-bottom: .6rem; }
.cartao-topo h2 { margin: 0; }

/* Resumo */
.resumo-rotulo { color: var(--texto-suave); font-size: .95rem; margin-bottom: .2rem; }
.resumo-grande { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.resumo-valor { font-size: 3rem; font-weight: 800; line-height: 1; }
.selo { display: inline-block; padding: 8px 14px; border-radius: 12px; font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.selo.dentro { background: var(--ok-fundo); color: var(--ok); }
.selo.fora { background: var(--ruim-fundo); color: var(--ruim); }
.resumo-detalhes { margin-top: .8rem; color: var(--texto-suave); font-size: .98rem; }
.resumo-detalhes strong { color: var(--texto); }
.resumo-detalhes span { display: block; }
.sep { display: none; font-style: normal; }
.aviso-poucos { margin-top: .8rem; padding: 10px 12px; border-radius: 10px; background: var(--alerta-fundo); color: var(--alerta); font-size: .95rem; }

/* Formulário */
label { display: block; font-weight: 600; margin: .9rem 0 .35rem; font-size: 1rem; }
input, select {
  width: 100%; min-height: 50px; padding: 12px; font-size: 1.05rem; border: 1px solid var(--borda); border-radius: 12px;
  background: var(--campo); color: var(--texto); font-family: inherit;
}
#valor { font-size: 1.7rem; font-weight: 700; text-align: center; min-height: 60px; }
input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--marca) 45%, transparent); outline-offset: 1px; }
.campo { min-width: 0; }
.campo-linha { display: grid; grid-template-columns: 1fr; }
.campo-com-botao { display: flex; gap: 8px; align-items: flex-end; }
.campo-com-botao .campo, .campo-com-botao > input { flex: 1; min-width: 0; }
.erro { color: var(--ruim); background: var(--ruim-fundo); padding: 10px 12px; border-radius: 10px; margin: .8rem 0 0; font-size: .95rem; }
.acoes { display: grid; gap: 8px; margin-top: 1rem; }

.btn { border: 1px solid var(--borda); background: var(--cartao); color: var(--texto); padding: 12px 16px; min-height: 48px; border-radius: 12px; font-size: 1rem; cursor: pointer; font-family: inherit; }
.btn.principal { background: var(--marca); border-color: var(--marca); color: #fff; font-weight: 700; }
.btn.principal:hover { background: var(--marca-escura); }
.btn.leve { background: transparent; }
.btn.grande { width: 100%; min-height: 54px; font-size: 1.1rem; }
.btn.mini { padding: 8px 10px; min-height: 40px; font-size: .92rem; }
.btn.perigo { color: var(--ruim); }
.btn:disabled { opacity: .6; cursor: default; }

/* Períodos: três botões do mesmo tamanho */
.periodos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.per { border: 1px solid var(--borda); background: transparent; color: var(--texto); padding: 10px 6px; min-height: 44px; border-radius: 12px; font-size: 1rem; cursor: pointer; font-family: inherit; }
.per.ativo { background: var(--marca); border-color: var(--marca); color: #fff; font-weight: 700; }

/* Gráficos */
.grafico { position: relative; height: 230px; }
.grafico.baixo { height: 250px; }
.grafico .vazio { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; text-align: center; }
.duplo { display: grid; grid-template-columns: 1fr; }
.estat { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: .4rem 0 0; }
.estat .chip { background: var(--fundo); border: 1px solid var(--borda); border-radius: 10px; padding: 8px 12px; font-size: .92rem; }
.estat .chip strong { display: block; font-size: 1.25rem; line-height: 1.2; }

/* Tabela com cabeçalho — cabe na largura do celular, sem rolar para o lado */
.tabela-rolagem { margin-top: .6rem; border: 1px solid var(--borda); border-radius: 10px; overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tabela th { background: var(--cabecalho-tabela); font-weight: 700; text-align: left; padding: 9px 6px; font-size: .88rem; }
.tabela td:first-child strong { white-space: nowrap; }
.tabela td { padding: 9px 6px; border-top: 1px solid var(--borda); vertical-align: top; }
.tabela .num { text-align: right; }
.tabela td.acoes-cel { width: 1%; }
.tabela td.acoes-cel .btn { display: block; width: 100%; margin-bottom: 6px; }
.tabela td.acoes-cel .btn:last-child { margin-bottom: 0; }
.tabela small { display: block; color: var(--texto-suave); font-size: .85rem; line-height: 1.3; overflow-wrap: anywhere; }
.tag { white-space: nowrap; display: block; width: fit-content; margin: 2px 0 0 auto; font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.tag.ok { background: var(--ok-fundo); color: var(--ok); }
.tag.baixa { background: var(--ruim-fundo); color: var(--ruim); }
.tag.alta { background: var(--alerta-fundo); color: var(--alerta); }
.vazio { color: var(--texto-suave); }
.nota { color: var(--texto-suave); font-size: .9rem; margin: .8rem 0 0; }
.meta-form { display: grid; gap: 8px; }

/* Aviso rápido */
#aviso {
  position: fixed; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 20;
  background: #1f2933; color: #fff; padding: 14px 16px; border-radius: 12px; font-size: 1rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}

/* ---------- Tablet e computador: só acrescenta ---------- */
@media (min-width: 640px) {
  .conteudo { gap: 16px; padding-top: 16px; }
  .cartao { padding: 18px 20px; }
  .resumo-grande { flex-direction: row; align-items: center; gap: 20px; }
  .resumo-valor { font-size: 3.4rem; }
  .resumo-detalhes span { display: inline; }
  .sep { display: inline; }
  .campo-linha { grid-template-columns: 1fr 1fr; gap: 12px; }
  .acoes { grid-template-columns: auto auto; justify-content: start; }
  .btn.grande { width: auto; min-width: 200px; }
  .cartao-topo { grid-template-columns: 1fr auto; align-items: center; }
  .estat { display: flex; flex-wrap: wrap; }
  .estat .chip strong { display: inline; font-size: 1.1rem; }
  .grafico { height: 280px; }
  .tabela { font-size: 1rem; }
  .tabela th, .tabela td { padding: 10px 12px; }
  .tabela td.acoes-cel { width: auto; white-space: nowrap; }
  .tabela td.acoes-cel .btn { display: inline-block; width: auto; margin: 0 4px 0 0; }
  .meta-form { grid-template-columns: 1fr auto; align-items: end; }
  #aviso { left: 50%; right: auto; transform: translateX(-50%); max-width: 520px; }
}

@media (min-width: 760px) {
  .duplo { grid-template-columns: 1fr 1fr; gap: 16px; }
}
