:root {
  color-scheme: dark;
  --fundo: #0e1117;
  --cartao: #161b24;
  --campo: #1e2530;
  --campo-hover: #262e3b;
  --cabecalho: #1b212c;
  --texto: #e6e8ec;
  --suave: #9aa3b2;
  --borda: #2c3442;
  --primaria: #e63946;
  --primaria-escura: #c62f3b;
  --ok: #3ccf7a;
  --aviso-fundo: #2e2612;
  --aviso-borda: #8a6d1f;
  --erro-fundo: #3a1a1d;
  --erro-borda: #8c3a40;
  --ok-fundo: #12301f;
  --ok-borda: #2f7a4b;
  --realce: #22304a;
  --raio: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--fundo); color: var(--texto); font-size: 15px; }
h1 { font-size: 1.6rem; margin: .3rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .6rem; }
code { background: var(--campo); padding: 0 .3em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--borda); margin: 1rem 0; }

input, textarea, select, button {
  font: inherit; color: inherit; border-radius: 8px; border: 1px solid var(--borda);
}
input, textarea, select { width: 100%; padding: .55rem .65rem; background: var(--campo); }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid #3d6bb3; border-color: #5b8ad6; }
label { display: block; font-size: .88rem; color: var(--suave); margin: .6rem 0; }
label > input, label > select, label > textarea, label > .campo-status { margin-top: .25rem; color: var(--texto); }

button { background: var(--campo); padding: .55rem .9rem; cursor: pointer; font-weight: 500; }
button:hover:not(:disabled) { background: var(--campo-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primario { background: var(--primaria); border-color: var(--primaria); color: #fff; }
button.primario:hover:not(:disabled) { background: var(--primaria-escura); }
button.largo { width: 100%; margin-top: .6rem; }
button.fantasma { border: 0; background: none; font-size: 1.2rem; }
button.confirmar { background: var(--aviso-fundo); border-color: var(--aviso-borda); color: #ffd98a; }
button.mini { padding: .2rem .5rem; font-size: .85rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-cartao { width: min(380px, 100%); }
.login-cartao input { margin: .6rem 0; }

#app { display: flex; min-height: 100vh; }
#lateral {
  width: 330px; flex-shrink: 0; background: var(--cartao); border-right: 1px solid var(--borda);
  padding: 1rem 1.1rem; overflow-y: auto; height: 100vh; position: sticky; top: 0;
}
main { flex: 1; min-width: 0; padding: 1.2rem 1.5rem 3rem; max-width: 1400px; margin: 0 auto; }
.topo { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.abas { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; flex: 1; }
.abas button.ativa { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.icone-lateral {
  border: 0; background: none; color: var(--suave); font-size: 1.35rem; line-height: 1;
  padding: .35rem .55rem; border-radius: 6px;
}
.icone-lateral:hover:not(:disabled) { background: var(--campo); color: var(--texto); }
#abrir-lateral { position: fixed; top: .6rem; left: .6rem; z-index: 1400; }
#fechar-lateral { float: right; margin: -.3rem -.4rem 0 0; }
body.lateral-fechada #lateral { display: none; }
body:not(.lateral-fechada) #abrir-lateral { display: none; }

.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.dica { color: var(--suave); font-size: .85rem; margin: .3rem 0; }
.msg { padding: .6rem .8rem; border-radius: 8px; margin: .5rem 0; white-space: pre-line; font-size: .92rem; }
.msg.aviso { background: var(--aviso-fundo); border: 1px solid var(--aviso-borda); }
.msg.erro { background: var(--erro-fundo); border: 1px solid var(--erro-borda); }
.msg.ok { background: var(--ok-fundo); border: 1px solid var(--ok-borda); }
.msg ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.msg .fechar { float: right; border: 0; background: none; padding: 0 .2rem; }

.campo-status { position: relative; display: flex; align-items: center; gap: .4rem; }
#marca-partida { font-size: 1.3rem; min-width: 1.6rem; text-align: center; }

.grade-2 { display: grid; grid-template-columns: 1fr 70px; gap: .5rem; }
.grade-rotas { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }
.grade-avulso { display: grid; grid-template-columns: 2fr 3fr 1.2fr; gap: .6rem; }
.grade-textos { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.botoes { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0; }
.botoes > button { flex: 1 1 180px; }
.linha-radio { display: flex; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; align-items: center; }
.linha-radio label { display: inline-flex; align-items: center; gap: .3rem; margin: 0; color: var(--texto); }
.linha-radio input { width: auto; }
details { margin: .6rem 0; }
summary { cursor: pointer; font-weight: 500; margin-bottom: .4rem; }

.tabela-rolagem { overflow-x: auto; border: 1px solid var(--borda); border-radius: 8px; margin: .6rem 0; }
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: .88rem; }
th, td { border-bottom: 1px solid var(--borda); padding: .25rem .35rem; text-align: left; vertical-align: middle; }
th { background: var(--cabecalho); position: sticky; top: 0; font-weight: 600; white-space: nowrap; }
td select { min-width: 7.5rem; }
td input, td select { padding: .3rem .4rem; border-color: transparent; background: transparent; min-width: 8.5rem; }
td input:hover, td select:hover { border-color: var(--borda); background: var(--campo); }
td.ro { color: var(--suave); white-space: nowrap; }
td.estreita input { width: 4.8rem; min-width: 4.8rem; }
td.larga input { min-width: 380px; }
td.check { text-align: center; width: 2.4rem; }
td.check input { width: auto; min-width: 0; }
tr.problema td { background: #2a2414; }

.bloco-texto {
  background: #0a0d12; color: #e6e8ec; border: 1px solid var(--borda); padding: .8rem; border-radius: 8px;
  white-space: pre-wrap; word-break: break-word; font-size: .85rem; max-height: 420px; overflow: auto; margin: 0;
}
.cartao-texto { border: 1px solid var(--borda); border-radius: 8px; padding: .6rem; }
.cartao-texto header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.locais-avulso { margin: .4rem 0 .6rem; font-size: .9rem; color: var(--texto-suave, inherit); }
.locais-avulso #otm-locais { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin-top: .3rem; }
.locais-avulso .check-local { display: inline-flex; flex-direction: row; align-items: center; gap: .3rem; cursor: pointer; color: inherit; white-space: nowrap; width: auto; margin: 0; }
.locais-avulso .check-local input { width: auto; margin: 0; }
.cartao-texto .botoes-copiar { display: flex; gap: .3rem; flex-shrink: 0; }
.etiqueta { background: var(--campo); border-radius: 6px; padding: .1rem .45rem; font-size: .8rem; margin-left: .3rem; }

.mapa { height: 440px; border-radius: 10px; margin: 1rem 0; border: 1px solid var(--borda); }
.pino { border-radius: 50%; color: #fff; border: 2px solid #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; box-shadow: 0 2px 5px rgba(0,0,0,.45); }

.sugestoes {
  position: absolute; z-index: 1000; background: var(--campo); border: 1px solid var(--borda); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.5); max-height: 280px; overflow-y: auto; margin: 0; padding: .2rem 0; list-style: none;
}
.sugestoes li { padding: .45rem .7rem; cursor: pointer; font-size: .9rem; }
.sugestoes li:hover, .sugestoes li.ativa { background: var(--realce); }
.sugestoes li small { color: var(--suave); }

.escolha { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; margin: .4rem 0; }
.escolha label { margin: 0; }

#carregando {
  position: fixed; inset: 0; background: rgba(8,10,14,.72); display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 2000; gap: .7rem;
}
.roda { width: 42px; height: 42px; border: 4px solid #333a47; border-top-color: var(--primaria); border-radius: 50%; animation: gira 0.8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
#toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: #2a3240; color: #fff; border: 1px solid var(--borda);
  padding: .7rem 1.1rem; border-radius: 8px; z-index: 2100; max-width: 90vw;
}

@media (max-width: 900px) {
  #lateral { position: fixed; left: 0; top: 0; z-index: 1500; box-shadow: 2px 0 12px rgba(0,0,0,.6); max-width: 88vw; }
  main { padding: .8rem .7rem 3rem; }
  .abas button { padding: .5rem .3rem; font-size: .85rem; }
  .grade-avulso { grid-template-columns: 1fr; }
  .grade-textos { grid-template-columns: 1fr; }
}

/* Mapa escuro: o Leaflet usa fundos claros nos controlos e popups. */
.leaflet-container { background: #1b1f27; }
/* Mapa do OpenStreetMap escurecido: só as imagens do mapa, não os pinos nem as linhas. */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.6); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--cartao); color: var(--texto); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--campo); color: var(--texto); border-color: var(--borda); }
.leaflet-control-attribution { background: rgba(14,17,23,.75) !important; color: var(--suave); }
.leaflet-control-attribution a { color: #8ab4f8; }
a { color: #8ab4f8; }

/* Títulos de coluna clicáveis para ordenar */
th.ordenavel { cursor: pointer; user-select: none; }
th.ordenavel:hover { background: var(--campo-hover); }
th .seta { color: var(--primaria); font-size: .8em; }

/* Página /etiquetas-dia */
.pagina-dia { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.topo-dia { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.topo-dia h1 { margin: 0; }
.grade-locais { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; }
.botao-local { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: 1.2rem .8rem; font-size: 1.1rem; }
.botao-local .qtd-local { font-size: .85rem; color: var(--suave); font-weight: 400; }
.botao-local.ativa { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.botao-local.ativa .qtd-local { color: #ffe3e5; }
.tabela-leitura td { padding: .45rem .5rem; }


/* Topo da tela principal (sem barra lateral) */
.acoes-topo { display: flex; gap: .5rem; flex-shrink: 0; }
.botao-link {
  display: inline-flex; align-items: center; padding: .55rem .9rem; border: 1px solid var(--borda);
  border-radius: 8px; background: var(--campo); color: var(--texto); text-decoration: none; font-weight: 500;
}
.botao-link:hover { background: var(--campo-hover); }
.linha-partida { display: flex; gap: .5rem; flex-wrap: wrap; }
.linha-partida input { flex: 1 1 320px; }
@media (max-width: 900px) {
  .topo { flex-wrap: wrap; }
  .acoes-topo { width: 100%; justify-content: flex-end; }
}

/* Painel /admin */
.pagina-admin { max-width: 900px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.pagina-admin .topo-dia { flex-wrap: wrap; margin-bottom: .3rem; }
.grade-regiao { display: grid; grid-template-columns: 2fr 80px 1fr; gap: .6rem; }
.grade-locais-admin { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .4rem 1rem; }
@media (max-width: 600px) { .grade-regiao { grid-template-columns: 1fr 80px; } }

/* Links discretos no topo (Admin · Sair), centralizados, como texto */
.links-topo { display: flex; justify-content: center; align-items: center; gap: .5rem; margin: 0 0 .7rem; font-size: .85rem; }
.link-texto {
  background: none; border: 0; padding: 0; color: var(--suave); font: inherit; font-weight: 400;
  text-decoration: none; cursor: pointer;
}
.link-texto:hover:not(:disabled) { background: none; color: var(--texto); text-decoration: underline; }
.links-topo .separador { color: var(--borda); }

.busca-dia { margin-top: .9rem; }
.busca-dia input { font-size: 1rem; padding: .7rem .8rem; }

/* Mapa do Google: o escuro vem do estilo do Google; nenhum filtro sobre as imagens dele. */
.mapa-google .leaflet-tile-pane { filter: none; }
.lista-situacao { list-style: none; padding: 0; margin: .4rem 0; display: grid; gap: .35rem; }
.sugestoes li.credito-google { cursor: default; font-size: .75rem; color: var(--suave); text-align: right; padding: .2rem .7rem; }
.sugestoes li.credito-google:hover { background: none; }
