/* ContestMap — estilos */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --header-bg: #0f1b2d;
  --header-text: #e6edf6;
  --new-row: #fef9c3;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

/* Modo escuro: o JavaScript define data-mode="light|dark" em <html>;
   sem JavaScript vale a preferência do sistema. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode]) {
    --bg: #0b1220; --panel: #111a2b; --panel-2: #0e1626; --text: #e2e8f0; --muted: #94a3b8;
    --border: #1f2c42; --accent: #3b93f0; --accent-text: #06101f; --header-bg: #070d18;
    --new-row: #3a3413; --shadow: 0 1px 3px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: #0b1220; --panel: #111a2b; --panel-2: #0e1626; --text: #e2e8f0; --muted: #94a3b8;
  --border: #1f2c42; --accent: #3b93f0; --accent-text: #06101f; --header-bg: #070d18;
  --new-row: #3a3413; --shadow: 0 1px 3px rgba(0, 0, 0, .4); color-scheme: dark;
}

/* Temas de cores (escolhidos pelo dono da estação em Config → Aparência).
   Cada tema define a cor de destaque e o fundo do cabeçalho, no claro e no escuro. */
:root[data-theme="verde"]    { --accent: #15803d; --header-bg: #0f2a1c; }
:root[data-theme="vermelho"] { --accent: #c81e1e; --header-bg: #2b0d10; }
:root[data-theme="laranja"]  { --accent: #c2410c; --header-bg: #2b1508; }
:root[data-theme="roxo"]     { --accent: #6d28d9; --header-bg: #1c1233; }
:root[data-theme="petroleo"] { --accent: #0f766e; --header-bg: #0a2624; }
:root[data-theme="dourado"]  { --accent: #a16207; --header-bg: #271f07; }
:root[data-theme="grafite"]  { --accent: #374151; --header-bg: #111827; }
:root[data-mode="dark"][data-theme="verde"]    { --accent: #22c55e; --header-bg: #05140c; }
:root[data-mode="dark"][data-theme="vermelho"] { --accent: #f87171; --header-bg: #150607; }
:root[data-mode="dark"][data-theme="laranja"]  { --accent: #fb923c; --header-bg: #140a03; }
:root[data-mode="dark"][data-theme="roxo"]     { --accent: #a78bfa; --header-bg: #0d0819; }
:root[data-mode="dark"][data-theme="petroleo"] { --accent: #2dd4bf; --header-bg: #041312; }
:root[data-mode="dark"][data-theme="dourado"]  { --accent: #facc15; --header-bg: #121003; }
:root[data-mode="dark"][data-theme="grafite"]  { --accent: #9ca3af; --header-bg: #030712; }

/* linhas selecionadas/destacadas seguem a cor do tema */
:root {
  --row-hover: color-mix(in srgb, var(--accent) 7%, var(--panel));
  --row-sel: color-mix(in srgb, var(--accent) 18%, var(--panel));
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- cabeçalho */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; height: 52px;
  background: var(--header-bg); color: var(--header-text);
}
.topbar a { color: var(--header-text); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand svg { width: 22px; height: 22px; }
.topbar .spacer { flex: 1; }
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a, .topbar nav button {
  color: var(--header-text); background: none; border: 0; font: inherit; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; opacity: .85;
}
.topbar nav a:hover, .topbar nav button:hover, .topbar nav a.active { background: rgba(255,255,255,.1); opacity: 1; text-decoration: none; }
.nav-badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #f59e0b; color: #111; font-size: .72rem; font-weight: 800; line-height: 18px; text-align: center; }
.utc { font-family: var(--mono); opacity: .8; font-size: .9rem; white-space: nowrap; }

/* ---------------------------------------------------------------- componentes */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 600; font-size: .85rem; margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.row > .btn { flex: 0 0 auto; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.error { color: var(--danger); font-size: .88rem; min-height: 1.2em; margin-top: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; background: var(--panel-2); border: 1px solid var(--border);
}
.badge.public { color: var(--ok); }
.badge.delayed { color: var(--warn); }
.badge.private { color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.dot.off { background: var(--danger); }

.chip {
  display: inline-block; padding: 0 5px; border-radius: 4px; font-size: .72rem; font-weight: 700;
  color: #fff; line-height: 1.5; margin-right: 2px; white-space: nowrap;
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 5000;
  box-shadow: var(--shadow); font-size: .92rem; max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 14px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; z-index: 1; }

/* ---------------------------------------------------------------- páginas simples */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 20px; }

/* ---------------------------------------------------------------- tela do mapa */
.map-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.subbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.subbar .station-call { font-weight: 800; font-size: 1.1rem; font-family: var(--mono); }
.subbar select { width: auto; padding: 4px 8px; }
.split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
#map { height: 100%; min-height: 300px; z-index: 0; }
.list-pane { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--panel); }
.list-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.list-tools input[type=text] { width: 160px; padding: 5px 8px; }
.list-tools select { width: auto; padding: 5px 8px; }
.band-filter { display: flex; gap: 4px; flex-wrap: wrap; }
.band-filter button {
  border: 2px solid transparent; border-radius: 6px; padding: 1px 7px; font-size: .75rem; font-weight: 700;
  color: #fff; cursor: pointer; opacity: .35;
}
.band-filter button.on { opacity: 1; }
.stats { display: flex; gap: 16px; padding: 6px 12px; font-size: .85rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.stats b { color: var(--text); font-size: 1rem; }
.table-wrap { flex: 1; overflow: auto; }
#qsoTable td { font-size: .88rem; }
#qsoTable td.call { font-family: var(--mono); font-weight: 700; }
#qsoTable td.freq, #qsoTable td.time { font-family: var(--mono); }
#qsoTable tbody tr { cursor: pointer; }
#qsoTable tbody tr:hover { background: var(--row-hover); }
#qsoTable tbody tr.sel { background: var(--row-sel); }
#qsoTable tbody tr.fresh { animation: fresh 4s ease-out; }
@keyframes fresh { from { background: var(--new-row); } to { background: transparent; } }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; grid-template-rows: 50% 50%; }
  .list-pane { border-left: 0; border-top: 1px solid var(--border); }
  .topbar .utc { display: none; }
}

.overlay-msg {
  position: fixed; inset: 52px 0 0 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 2000; text-align: center; padding: 20px;
}

/* marcadores */
.cm-marker { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.4); position: relative; }
.cm-marker.approx { opacity: .6; border-style: dashed; }
.cm-marker.sel { box-shadow: 0 0 0 3px #facc15, 0 1px 6px rgba(0,0,0,.5); }
.cm-marker .n {
  position: absolute; top: -8px; right: -9px; background: #0f172a; color: #fff; border-radius: 8px;
  font: 700 9px/13px system-ui, sans-serif; padding: 0 4px; border: 1px solid #fff;
}
.cm-home { font-size: 26px; line-height: 26px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }

.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }
.pop { font-size: .88rem; }
.pop .head { display: flex; gap: 10px; align-items: flex-start; }
.pop img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.pop .call { font: 800 1.15rem var(--mono); }
.pop table { margin-top: 8px; width: 100%; border-collapse: collapse; font-size: .8rem; }
.pop td { padding: 2px 4px; border-top: 1px solid #e5e7eb; white-space: nowrap; }
.pop .kind { font-size: .75rem; color: #64748b; }

.legend { background: var(--panel); color: var(--text); padding: 6px 8px; border-radius: 8px; box-shadow: var(--shadow); font-size: .75rem; }
.legend label { display: flex; gap: 6px; align-items: center; margin: 2px 0; font-weight: 500; font-size: .8rem; cursor: pointer; }

/* ---------------------------------------------------------------- tema: botão claro/escuro */
.mode-btn { font-size: 1rem; line-height: 1; }

/* ---------------------------------------------------------------- logotipo da estação */
.st-logo { height: 38px; max-width: 120px; object-fit: contain; border-radius: 6px; background: #fff; padding: 2px; }
.list-logo { height: 22px; max-width: 60px; object-fit: contain; vertical-align: middle; margin-right: 6px; border-radius: 4px; background: #fff; }
/* fundo em vez de <img>: o Leaflet força "width: auto" nas imagens dos marcadores */
.cm-home-logo { width: 38px; height: 38px; border-radius: 50%; background: #fff center / 80% no-repeat; border: 3px solid var(--accent); box-shadow: 0 1px 6px rgba(0,0,0,.5); box-sizing: border-box; }
