:root {
  --bg: #0b1020;
  --panel: #151b30;
  --panel-2: #1b2340;
  --line: #26304d;
  --text: #e6e9f2;
  --muted: #98a2bf;
  --accent: #3b82f6;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --purple: #a855f7;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- */
/* Botões e controles                                                */
/* ---------------------------------------------------------------- */

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #232c50; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2f6fe0; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #4a2330; }
.btn.danger:hover { background: #2a1620; }
.btn.active { border-color: var(--accent); background: #1e2a4d; }

input, select {
  background: #0f1526;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* Checkbox e radio não devem herdar o width:100% dos campos de texto — senão
   esticam e desalinham (ex.: lista de destinatários do comunicado). */
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
label input, label select { margin-top: 5px; font-weight: 400; color: var(--text); }
label small { font-weight: 400; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }
.error { color: var(--bad); font-size: 13px; margin: 12px 0 0; }

/* ---------------------------------------------------------------- */
/* Tela de acesso                                                    */
/* ---------------------------------------------------------------- */

.auth {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
/* Fundo dividido: motocross à esquerda, kart à direita, com escurecimento
   para o card ficar legível por cima. */
.auth-bg { position: absolute; inset: 0; display: flex; z-index: 0; }
.auth-bg .half { flex: 1; background-size: cover; background-position: center; }
.auth-bg .moto { background-image: url('/img/moto-hero.webp?v27'); }
.auth-bg .kart { background-image: url('/img/kart-hero.webp?v27'); }
.auth-bg::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(11, 16, 32, .66), rgba(11, 16, 32, .88));
}
.auth-card {
  position: relative; z-index: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; font-weight: 700; }
.auth-card h1 span, .brand span { color: var(--accent); }
.auth-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }

.install-cta {
  display: block; text-align: center; text-decoration: none;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  font-weight: 600; font-size: 13.5px; padding: 10px; border-radius: 10px; margin: 0 0 16px;
}
.install-cta:hover { border-color: var(--accent); }

.tabs { display: flex; gap: 4px; background: #0f1526; padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.tab {
  flex: 1; background: transparent; border: 0; color: var(--muted);
  padding: 8px; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--panel-2); color: var(--text); }

.auth-form { display: grid; gap: 14px; }

/* ---------------------------------------------------------------- */
/* Layout principal                                                  */
/* ---------------------------------------------------------------- */

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 500;
}
.brand { font-weight: 700; font-size: 16px; }

/* Seletor de modalidade (Motocross | Kart) no topo. */
.modality-switch {
  display: flex; gap: 4px; background: #0f1526; padding: 4px;
  border-radius: 999px; border: 1px solid var(--line);
}
.modality-switch button {
  background: transparent; border: 0; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer; white-space: nowrap; line-height: 1;
}
.modality-switch button.active {
  background: var(--panel-2); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user { color: var(--muted); font-size: 13px; cursor: pointer; }
.user:hover { color: var(--text); text-decoration: underline; }
#profile-view .grid .full { grid-column: 1 / -1; }
.pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.pill.ok { color: var(--good); border-color: #1e4030; }
.pill.off { color: var(--muted); }

.layout { display: grid; grid-template-columns: 330px 1fr; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

/* Item de grid nasce com min-width:auto, ou seja, nunca encolhe abaixo do
   min-content do conteúdo. Sem isto a largura mínima da tabela de voltas
   (colunas com white-space:nowrap) estica a coluna inteira e a PÁGINA passa a
   rolar na horizontal — em vez de a tabela rolar dentro do próprio quadro. */
.sidebar, .content { min-width: 0; }

.sidebar { display: grid; gap: 14px; position: sticky; top: 72px; }
@media (max-width: 980px) { .sidebar { position: static; } }

.circuits-all { display: block; width: 100%; margin-top: 8px; }

/* ---- Layout adaptativo no celular ---------------------------------------
   Em tela pequena o que importa é ver o circuito/ranking. O envio de treino
   vai para o fim, os circuitos aparecem compactos (só as 2 pistas mais
   recentes, com botão "ver todos") e o conteúdo (ranking do último circuito
   usado) fica logo abaixo. display:contents solta os painéis da sidebar para o
   layout intercalá-los com o conteúdo por 'order'. */
@media (max-width: 640px) {
  .layout { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
  .sidebar { display: contents; }
  #panel-circuits     { order: 1; }
  .content            { order: 2; }
  #panel-participants { display: none; }   /* no celular não é necessário */
  #panel-sessions     { order: 4; }
  #panel-import       { order: 5; }

  /* Circuitos ocupando a largura total da tela (sai da margem do layout). */
  #panel-circuits {
    margin-left: calc(-16px - env(safe-area-inset-left));
    margin-right: calc(-16px - env(safe-area-inset-right));
    border-radius: 0; border-left: 0; border-right: 0;
  }

  #panel-circuits.compact #circuit-list > li:nth-child(n+3) { display: none; }
  #panel-circuits.compact .hint { display: none; }

  #panel-import .drop { padding: 14px; }
  #panel-import .drop small { display: none; }

  /* Topbar em linhas limpas: marca, seletor de modalidade e ações, cada um na
     sua faixa e bem distribuído (em vez de tudo espremido numa linha só). */
  .topbar { padding: 10px 12px; row-gap: 8px; }
  .brand { order: 1; width: 100%; font-size: 16px; }
  .brand em { display: none; }                 /* a modalidade já aparece no seletor */
  .modality-switch { order: 2; width: 100%; justify-content: center; }
  .topbar-right { order: 3; width: 100%; justify-content: flex-start; gap: 8px; }
  .topbar-right .user { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; }

  /* Cards do ranking: 'Melhor volta' em destaque na largura toda e os demais
     em duas colunas, em vez de cinco espremidos. Especificidade .content .cards
     para vencer a regra base (que vem depois no arquivo). */
  .content .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .content .cards .card.best { grid-column: 1 / -1; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel.inline { margin-top: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.panel h3 { margin: 0; font-size: 14px; }

/* Guia "Como trazer seu treino" (recolhível nativo). */
.import-help { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.import-help > summary {
  cursor: pointer; list-style: none; font-size: 13px; font-weight: 600; color: var(--accent);
  display: flex; align-items: center; gap: 6px;
}
.import-help > summary::-webkit-details-marker { display: none; }
.import-help > summary::before { content: '▸'; font-size: 10px; color: var(--muted); transition: transform .15s; }
.import-help[open] > summary::before { transform: rotate(90deg); }
.import-help .help-body { margin-top: 10px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.import-help .help-body p { margin: 0 0 8px; }
.import-help .help-body b { color: var(--text); font-weight: 600; }
.import-help .dica { color: var(--warn); }
.wa-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 4px;
  background: #25d366; color: #05320f; font-weight: 700; font-size: 13px;
  padding: 8px 14px; border-radius: 8px; text-decoration: none;
}
.wa-link:hover { filter: brightness(1.05); }
.wa-inline { color: var(--good); text-decoration: none; }
.wa-inline:hover { text-decoration: underline; }

/* Painel recolhível (cabeçalho clicável). */
.panel-toggle { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 7px; }
.panel-toggle:hover { color: var(--text); }
.panel-toggle .chevron { font-size: 10px; color: var(--muted); transition: transform .15s ease; display: inline-block; }
.panel.collapsible:not(.collapsed) .panel-toggle .chevron { transform: rotate(90deg); }
.panel.collapsible.collapsed > h2 { margin-bottom: 0; }
.panel.collapsible.collapsed > .list { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.count { color: var(--muted); font-weight: 400; }

.drop {
  display: grid; place-items: center; gap: 4px; text-align: center;
  border: 2px dashed var(--line); border-radius: 10px; padding: 22px 14px;
  cursor: pointer; transition: border-color .15s, background .15s; margin-bottom: 10px;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #10193166; }
.drop small { color: var(--muted); font-size: 12px; }

.log { margin-top: 10px; font-size: 12px; display: grid; gap: 4px; }
.log .ok { color: var(--good); }
.log .fail { color: var(--bad); }

/* Filtro de sessoes sem circuito. Fica acima da lista e fora do painel
   dobravel: e o unico controle da tela cujo assunto e trabalho pendente. */
.filtro-sessoes {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 8px; font-size: 0.9rem; color: var(--muted); cursor: pointer;
}
.filtro-sessoes input { margin: 0; }

/* Marca a sessao que ainda nao cronometra nada por falta de circuito. */
.tag-sem-circuito {
  display: inline-block; padding: 1px 6px; margin-left: 6px;
  border-radius: 999px; background: var(--surface-2, rgba(128,128,128,.22));
  font-size: 0.78em;
}

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 46vh; overflow-y: auto; }
.list li {
  padding: 9px 11px; border-radius: 8px; border: 1px solid transparent;
  background: #0f1526; cursor: pointer; font-size: 13px;
}
.list li:hover { border-color: var(--line); }
.list li.active { border-color: var(--accent); background: #14203c; }
.list li .t { font-weight: 600; display: block; }
.list li .s { color: var(--muted); font-size: 11.5px; }
.list.compact li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list .del { color: var(--muted); background: none; border: 0; cursor: pointer; font-size: 15px; padding: 0 4px; }
.list .del:hover { color: var(--bad); }
.list .none { color: var(--muted); font-size: 12.5px; padding: 6px 2px; cursor: default; background: none; }

.empty { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }
/* Hero da modalidade ativa (troca com o seletor Motocross|Kart). */
.mode-hero {
  width: 100%; max-width: 620px; aspect-ratio: 16 / 7;
  margin: 0 auto 22px; border-radius: 14px;
  background-size: cover; background-position: center;
  border: 1px solid var(--line); box-shadow: 0 14px 34px rgba(0, 0, 0, .42);
}

.session-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.session-title { display: flex; align-items: flex-start; gap: 12px; }
.btn-back { flex: 0 0 auto; }
.session-header h2 { margin: 0 0 4px; font-size: 19px; }
.session-header .meta { margin: 0; color: var(--muted); font-size: 12.5px; }
.session-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.session-actions select { width: auto; min-width: 180px; }

/* ---------------------------------------------------------------- */
/* Mapa                                                              */
/* ---------------------------------------------------------------- */

.map-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
#map { height: 460px; background: #0f1526; }
/* No celular 460px come quase a tela toda; 55vh deixa a tabela de voltas
   aparecer junto com o mapa. */
@media (max-width: 640px) { #map { height: 55vh; min-height: 300px; } }
#map.picking { cursor: crosshair; }
.map-tools { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }

.leaflet-container { background: #0f1526; }
/* Os tiles do OSM são claros demais para o tema escuro; escurece sem perder leitura. */
.leaflet-tile-pane { filter: brightness(.62) saturate(.7) hue-rotate(185deg) invert(0); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--text); }
.leaflet-bar a { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: #232c50; }

.map-legend {
  background: rgba(21,27,48,.92); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 11.5px; color: var(--muted); line-height: 1.7;
}
.map-legend .bar { height: 7px; border-radius: 4px; margin: 4px 0 3px;
  background: linear-gradient(90deg, #2563eb, #22c55e, #eab308, #ef4444); }
.map-legend .ends { display: flex; justify-content: space-between; }

/* ---------------------------------------------------------------- */
/* Resumo e tabela de voltas                                         */
/* ---------------------------------------------------------------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-top: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.card .v { font-size: 20px; font-weight: 700; margin-top: 3px; font-family: var(--mono); }
.card .n { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.card.best .v { color: var(--purple); }
.card.theo .v { color: var(--good); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }

.toggle { display: flex; gap: 3px; background: #0f1526; padding: 3px; border-radius: 8px; }
.tgl { background: transparent; border: 0; color: var(--muted); padding: 5px 12px; border-radius: 6px;
       font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.tgl.active { background: var(--panel-2); color: var(--text); }

.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-size: 11px;
     text-transform: uppercase; letter-spacing: .05em; z-index: 1; }
th:first-child, td:first-child { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #0f1526; }
tbody tr.sel { background: #14203c; }
td.time { font-family: var(--mono); font-weight: 600; }
tr.best td.time { color: var(--purple); }
td.pos { color: var(--bad); }
td.neg { color: var(--good); }
td.bestsec { color: var(--purple); font-weight: 600; }
td.dim { color: var(--muted); }

.notice { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius);
          background: #1e1a10; border: 1px solid #4a3a18; color: #e8c98a; font-size: 13px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 20px; font-size: 13px; z-index: 9999; max-width: 90vw;
}
.toast.bad { border-color: #4a2330; color: #fca5a5; }
.toast.good { border-color: #1e4030; color: #86efac; }

/* ---------------------------------------------------------------- */
/* Marca                                                             */
/* ---------------------------------------------------------------- */

.auth-card .tagline {
  margin: -2px 0 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--warn);
}
.auth-card .byline {
  margin: 22px 0 0;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--muted);
}
.brand em {
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--warn);
  vertical-align: 2px;
  margin-left: 4px;
}

/* ---------------------------------------------------------------- */
/* Participantes                                                     */
/* ---------------------------------------------------------------- */

.stack { display: block; margin: 10px 0 0; }
.stack select { margin-top: 5px; }
.stack-form { display: grid; gap: 7px; margin-top: 10px; }

.list .who { display: flex; flex-direction: column; min-width: 0; }
.list .who b { font-weight: 600; }
.list .who span { color: var(--muted); font-size: 11.5px; }
.list .tagme {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); border: 1px solid #234070; border-radius: 4px; padding: 1px 5px; margin-left: 6px;
}
.list .acts { display: flex; gap: 2px; flex: 0 0 auto; }
.list .acts button { color: var(--muted); background: none; border: 0; cursor: pointer; font-size: 13px; padding: 2px 4px; }
.list .acts button:hover { color: var(--text); }
.list .acts button.del:hover { color: var(--bad); }

/* ---------------------------------------------------------------- */
/* Ranking                                                           */
/* ---------------------------------------------------------------- */

.filtros { gap: 10px; }
.inline-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.inline-label input { width: auto; padding: 5px 8px; font-size: 12.5px; }

#ranking-table td.pos { font-weight: 700; font-size: 15px; width: 46px; }
#ranking-table tr.p1 td.pos { color: #fbbf24; }
#ranking-table tr.p2 td.pos { color: #cbd5e1; }
#ranking-table tr.p3 td.pos { color: #d97757; }
#ranking-table tr.p1 td.time { color: var(--purple); }
#ranking-table td.rider b { font-weight: 600; }
#ranking-table td.rider span { color: var(--muted); font-size: 11.5px; display: block; }
#ranking-sessions td.dim { color: var(--muted); }

/* Barra de filtros do ranking: os controles ficam juntos e cabem em coluna
   quando a tela é estreita. */
.filtro-bar { padding: 12px 16px; }
.filtro-bar .filtros { gap: 14px; }
.filtro-bar .inline-label { flex-direction: column; align-items: flex-start; gap: 4px; }
.filtro-bar .inline-label select { width: auto; min-width: 150px; padding: 6px 9px; font-size: 12.5px; }
.filtros-toggle { display: none; }   /* botão só aparece no celular */
@media (max-width: 640px) {
  /* No celular os filtros ficam recolhidos: o botão abre/fecha (senão a barra
     empilhada empurra o ranking pra muito longe). */
  .filtros-toggle { display: block; width: 100%; }
  .filtro-bar .filtros { display: none; flex-direction: column; align-items: stretch; }
  .filtro-bar.open .filtros { display: flex; margin-top: 10px; }
  .filtro-bar .inline-label { width: 100%; }
  .filtro-bar .inline-label select, .filtro-bar .inline-label input { width: 100%; }
}

#ranking-cards { margin-top: 16px; }
#ranking-sessions tr.best td.time { color: var(--purple); font-weight: 700; }
#ranking-sessions td .tagme { color: var(--purple); border-color: #4a2a6b; }
#ranking-table tr.sel { background: #14203c; }
.session-actions #ranking-circuit-select { min-width: 200px; }

/* Modo de mesclagem de circuitos */
.merge-banner {
  background: #1e2a4d; border: 1px solid var(--accent); border-radius: 8px;
  padding: 9px 11px; margin-bottom: 10px; font-size: 12.5px; line-height: 1.6;
}
.merge-banner .btn { margin-left: 6px; }
.list li.merge-src { border-color: var(--warn); background: #241d10; }
.list li.merge-target { border-color: #2a3a63; }
.list li.merge-target:hover { border-color: var(--accent); background: #14203c; }

/* Área de administração */
.notice.info { background: #101c31; border-color: #24406b; color: #a9c4ea; }
.acts-cell { white-space: nowrap; }
.acts-cell .btn { margin-left: 4px; padding: 4px 9px; font-size: 12px; }
#admin-table td.rider .s { color: var(--muted); font-size: 11.5px; }
#admin-table tr.sel { background: #14203c; }

/* Circuito compartilhado (de outra conta) */
.tag-shared {
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--good); border: 1px solid #1e4030; border-radius: 4px; padding: 1px 5px; margin-left: 6px;
}

/* Qualidade da gravação */
.card.warn .v { color: var(--warn); text-transform: capitalize; }
.warn-mark { color: var(--warn); margin-left: 5px; cursor: help; font-size: 12px; }
#laps-table tr.unreliable td.time { color: var(--warn); }
#ranking-sessions tr.lowq td:first-child::after,
#ranking-table tr.lowq td.time::after { content: ' ⚠'; color: var(--warn); font-size: 11px; }
/* Aviso de gravação limitada usa a cor de alerta */
#quality-notice.notice { background: #1e1a10; border-color: #4a3a18; color: #e8c98a; }

/* Links textuais nos formulários de acesso */
.linkish { background: none; border: 0; color: var(--accent); font: inherit; font-size: 13px;
  cursor: pointer; padding: 4px; text-align: center; }
.linkish:hover { text-decoration: underline; }
.okmsg { color: var(--good); font-size: 13px; margin: 12px 0 0; line-height: 1.5; }

/* Conexões entre pilotos */
.badge { display:inline-block; min-width:16px; padding:0 5px; margin-left:4px; border-radius:9px;
  background:var(--bad); color:#fff; font-size:11px; font-weight:700; text-align:center; }
.conn-list { display:grid; gap:8px; margin-top:10px; }
.conn-row { display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap;
  background:#0f1526; border:1px solid var(--line); border-radius:8px; padding:10px 12px; font-size:13px; }
.conn-acts { display:flex; gap:6px; }
#connections-view .panel h3 { margin-bottom:2px; }
.tag-conn { font-size:10px; font-weight:700; letter-spacing:.05em; text-transform:uppercase;
  color:#a9c4ea; border:1px solid #24406b; border-radius:4px; padding:1px 5px; margin-left:6px; }
#conn-search { margin: 8px 0 4px; }

/* ---------------------------------------------------------------- */
/* PWA no iPhone: respeitar as áreas seguras (notch e barra inferior) */
/* ---------------------------------------------------------------- */
.topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
.auth { padding-top: calc(24px + env(safe-area-inset-top)); }
.layout { padding-left: calc(16px + env(safe-area-inset-left));
          padding-right: calc(16px + env(safe-area-inset-right)); }
.toast { bottom: calc(22px + env(safe-area-inset-bottom)); }
/* fundo do tema atrás da status bar translúcida */
html { background: var(--bg); }

/* Esconde visualmente sem display:none — necessário para o input de arquivo
   disparar o "change" no Safari do iPhone. */
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0; opacity: 0;
}

/* Bloco de importação automática do Strava (webhook) */
.strava-webhook { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.strava-webhook .muted { color: var(--muted, #93a0c0); margin: 4px 0; }
.strava-webhook .small { font-size: 12px; }

/* Campo "Setores" na barra de ferramentas do mapa */
.tool-sectors { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted, #93a0c0); }
.tool-sectors input { width: 52px; padding: 5px 6px; }

/* Número do setor sobre o traçado (legenda no mapa). O seletor duplo vence o
   .leaflet-div-icon padrão do Leaflet (fundo branco + borda). */
.leaflet-div-icon.sector-label {
  background: #f59e0b;
  color: #201400;
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 13px/1 system-ui, -apple-system, sans-serif;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .55);
}

/* Selo oficial "Powered by Strava" (atribuição de marca exigida). Espaco de
   respiro ao redor e sem alterar cor/proporcao da imagem. */
.powered-strava { display: inline-block; margin: 12px auto 0; line-height: 0; opacity: 0.95; }
.powered-strava::before {
  content: "Data Source by";
  display: block;
  line-height: 1.2;
  font-size: 11px;
  text-align: center;
  color: var(--muted, #93a0c0);
  margin-bottom: 5px;
}
.powered-strava img { width: 120px; height: auto; display: block; }
.auth-card .powered-strava { margin-top: 14px; }
#strava-box .powered-strava { margin-top: 14px; }
#strava-box .powered-strava img { width: 110px; }

/* Rodapé do app logado — mantém o selo do Strava sempre visível. */
.app-footer {
  display: flex;
  justify-content: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .07);
}
.app-footer .powered-strava { margin: 0; }

/* Bloco de esporte da sincronização automática do Strava, no perfil */
.pf-strava { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.pf-strava h3 { margin: 0 0 4px; font-size: 15px; }
.pf-strava .meta { margin: 0 0 8px; }
.pf-strava select { max-width: 220px; }

/* Comunicado por e-mail (admin) */
#broadcast-panel textarea { width: 100%; resize: vertical; font: inherit; }
.bc-recipients { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 10px 0; }
.bc-recipients .bc-label { color: var(--muted, #93a0c0); font-size: 13px; }
.bc-recipients label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.bc-user-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 10px; }
.bc-user { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 8px; cursor: pointer; }
.bc-user:hover { background: rgba(255,255,255,.05); }
.bc-user em { color: var(--muted, #93a0c0); font-style: normal; font-size: 12px; }

/* ---------------------------------------------------------------- */
/* Esquemas de cores — aplicados SÓ no celular (telas grandes ficam  */
/* no tema padrão, por isso as sobreposições vivem no media query).  */
/* Escolhido no perfil; body[data-theme="..."] setado pelo app.js.   */
/* ---------------------------------------------------------------- */
.pf-theme { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.pf-theme h3 { margin: 0 0 4px; font-size: 15px; }
.pf-theme .meta { margin: 0 0 8px; }
.pf-theme select { max-width: 260px; }

@media (max-width: 640px) {
  /* Claro — melhor sob sol forte */
  body[data-theme="claro"] {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel-2: #eaeefb;
    --line: #c8d1e6;
    --text: #12172a;
    --muted: #47516e;
    --accent: #2563eb;
  }
  body[data-theme="claro"] input,
  body[data-theme="claro"] select,
  body[data-theme="claro"] textarea { background: #ffffff; color: var(--text); }
  body[data-theme="claro"] .btn:hover { background: #e2e8f6; }
  body[data-theme="claro"] .btn.active { background: #dbe4fb; }
  /* Barras com cor escura fixa (abas do login, seletor de modalidade) */
  body[data-theme="claro"] .tabs,
  body[data-theme="claro"] .modality-switch { background: #e6ebf7; }

  /* Alto contraste — legibilidade máxima */
  body[data-theme="contraste"] {
    --bg: #000000;
    --panel: #0b0b0d;
    --panel-2: #17181c;
    --line: #55607a;
    --text: #ffffff;
    --muted: #cfd8ee;
    --accent: #4d8dff;
  }
  body[data-theme="contraste"] input,
  body[data-theme="contraste"] select,
  body[data-theme="contraste"] textarea { background: #000000; color: #fff; }
  body[data-theme="contraste"] .btn:hover { background: #23242a; }
  body[data-theme="contraste"] .btn.active { background: #12213f; }
}

/* Bloco de relatórios por e-mail, no perfil */
.pf-report { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.pf-report h3 { margin: 0 0 4px; font-size: 15px; }
.pf-report .meta { margin: 0 0 10px; }
.pf-report label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); margin: 6px 0; cursor: pointer; }
.pf-report label.stack { margin-top: 10px; }
.pf-report select { max-width: 260px; }

/* Logo do app na tela de login (substitui o wordmark de texto) */
.auth-logo { display: block; width: 200px; max-width: 72%; height: auto; margin: 2px auto 12px; }
