:root {
  --bg-base: #0a0e14;
  --bg-elevated: #0f1419;
  --bg-row: #121821;
  --bg-row-alt: #0f1620;
  --bg-row-hover: #1a2332;
  --bg-input: #0d1117;
  --border: #1f2937;
  --border-strong: #2d3748;
  --border-accent: #3d4a5c;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #e8c547;
  --accent-dim: #b89530;
  --accent-glow: rgba(232, 197, 71, 0.18);
  --success: #00ff88;
  --success-dim: #00cc6e;
  --warning: #ff9f43;
  --danger: #ff6b35;
  --danger-glow: rgba(255, 107, 53, 0.35);
  --link: #58a6ff;
  --link-hover: #79b8ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --mono: "JetBrains Mono", "IBM Plex Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-base: #f5f7fa;
    --bg-elevated: #ffffff;
    --bg-row: #ffffff;
    --bg-row-alt: #f8fafc;
    --bg-row-hover: #eef2f7;
    --bg-input: #ffffff;
    --border: #e1e7ef;
    --border-strong: #cbd5e1;
    --border-accent: #94a3b8;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent: #b8860b;
    --accent-dim: #8b6508;
    --accent-glow: rgba(184, 134, 11, 0.15);
    --success: #16a34a;
    --success-dim: #15803d;
    --warning: #ea580c;
    --danger: #dc2626;
    --danger-glow: rgba(220, 38, 38, 0.25);
    --link: #2563eb;
    --link-hover: #1d4ed8;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
    --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
    --shadow-lg: 0 8px 24px rgba(15,23,42,0.10);
  }
}

* { box-sizing: border-box; }

html { font-size: 14px; }

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--sans);
  line-height: 1.5;
  background-image: url('../img/grid.svg');
  background-repeat: repeat;
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3, h4 { color: var(--text-primary); font-weight: 600; }
h1 { font-size: 1.6rem; margin: 0 0 0.5rem; letter-spacing: 0.01em; }

a { color: var(--link); text-decoration: none; transition: color 160ms ease; }
a:hover { color: var(--link-hover); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

code, .mono, .timestamp, .callsign, .ip, .id {
  font-family: var(--mono);
  font-size: 0.92em;
  letter-spacing: 0.02em;
}

::selection { background: var(--accent-glow); color: var(--text-primary); }

#top {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 14, 20, 0.85);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  border-bottom: 1px solid var(--border-strong);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

#top .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

#top .brand img,
#top .brand svg {
  height: 28px;
  width: auto;
  flex-shrink: 0;
}

#top .brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

#top .reflector-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px var(--accent-glow);
}

#top .reflector-meta {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-family: var(--mono);
  margin-top: 1px;
}

#top .uptime {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

#top .uptime .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

#top .uptime .dot.off {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger-glow);
}

#top .uptime strong { color: var(--text-primary); }

#menubar {
  position: sticky;
  top: 52px;
  z-index: 49;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}

#menu {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: stretch;
  min-height: 44px;
}

#menu table, #menu tr, #menu td { border: 0; padding: 0; margin: 0; background: transparent; }

.menulink {
  display: inline-flex;
  align-items: center;
  padding: 12px 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  text-decoration: none;
  position: relative;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
  white-space: nowrap;
}

.menulink:hover {
  color: var(--text-primary);
  background: var(--bg-row-hover);
}

.menulink.active,
.menulink[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: linear-gradient(180deg, transparent 0%, var(--accent-glow) 100%);
}

.menulink .count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-row-hover);
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  min-width: 22px;
  text-align: center;
}

.menulink.active .count,
.menulink[aria-current="page"] .count {
  background: var(--accent-glow);
  color: var(--accent);
}

#content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-row));
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

.panel-body { padding: 0; }

.listingtable {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  background: var(--bg-elevated);
}

.listingtable thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  padding: 10px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-row);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.listingtable tbody tr {
  transition: background-color 160ms ease, transform 200ms ease;
  border-bottom: 1px solid var(--border);
}

.listingtable tbody tr:nth-child(odd)  { background: var(--bg-row); }
.listingtable tbody tr:nth-child(even) { background: var(--bg-row-alt); }

.listingtable tbody tr:hover {
  background: var(--bg-row-hover);
}

.listingtable tbody tr.flash-new {
  animation: flash-new 3s ease-out;
}

.listingtable tbody tr.tx-active td:first-child {
  border-left: 3px solid var(--danger);
  padding-left: 9px;
}

.listingtable td {
  padding: 9px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

.listingtable td.mono { font-family: var(--mono); font-size: 0.85rem; }
.listingtable td.center { text-align: center; }
.listingtable td.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }

.listingtable .flag {
  display: inline-block;
  width: 30px;
  height: 20px;
  vertical-align: middle;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  background-color: var(--bg-row-hover);
  background-size: cover;
  background-position: center;
  position: relative;
}

.listingtable .flag[aria-label]::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--bg-base);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
  font-family: var(--sans);
  font-weight: 500;
}

.listingtable .flag-wrap:hover .flag[aria-label]::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.module-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.85rem;
  background: var(--bg-row-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.module-badge[data-module="A"] { border-color: #4ade80; color: #4ade80; }
.module-badge[data-module="B"] { border-color: #60a5fa; color: #60a5fa; }
.module-badge[data-module="C"] { border-color: #f472b6; color: #f472b6; }
.module-badge[data-module="D"] { border-color: var(--accent); color: var(--accent); }
.module-badge[data-module="E"] { border-color: #a78bfa; color: #a78bfa; }
.module-badge[data-module="F"] { border-color: #fb923c; color: #fb923c; }
.module-badge[data-module="G"] { border-color: #34d399; color: #34d399; }
.module-badge[data-module="H"] { border-color: #f87171; color: #f87171; }

.tx-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tx-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger-glow);
  animation: tx-pulse 1.2s ease-in-out infinite;
}

.tx-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
  animation: tx-pulse 1.2s ease-in-out infinite;
}

a.callsign-link {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px dotted var(--border-accent);
}

a.callsign-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.aprs-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg-row-hover);
  transition: background 160ms ease, transform 160ms ease;
}

.aprs-link:hover { background: var(--accent-glow); transform: scale(1.1); }

.aprs-link svg { width: 12px; height: 12px; fill: var(--text-secondary); }
.aprs-link:hover svg { fill: var(--accent); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.filter-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.FilterField,
.filter-form input[type="text"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 0.85rem;
  width: 150px;
  height: 32px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.FilterField::placeholder { color: var(--text-muted); }
.FilterField:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.FilterSubmit,
.filter-form input[type="submit"],
.btn {
  background: var(--bg-row-hover);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 14px;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  height: 32px;
  transition: background 160ms ease, border-color 160ms ease;
}

.FilterSubmit:hover,
.btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-dim);
  color: #1a1300;
  border-color: var(--accent-dim);
}

.filter-reset {
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 6px 10px;
}

.filter-reset:hover { color: var(--danger); }

.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  padding: 16px;
}

.module-card {
  background: var(--bg-row);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.module-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.module-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.module-card-name {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.module-card-count {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 1px 6px;
  background: var(--bg-row-hover);
  border-radius: var(--radius-sm);
}

.module-card-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.3;
  min-height: 1.5em;
}

.module-card-users {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  max-height: 70px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0 0;
  list-style: none;
}

.module-card-users li {
  padding: 1px 0;
  border-bottom: 1px dotted var(--border);
}

.module-card-users li:last-child { border-bottom: 0; }

.error {
  font-size: 0.9rem;
  color: var(--danger);
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 8px 0;
}

.contact-footer {
  margin-top: 48px;
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.contact-footer a {
  color: var(--text-secondary);
  font-family: var(--mono);
}

.contact-footer a:hover { color: var(--accent); }

.service-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
}

.service-icon.online { fill: var(--success); filter: drop-shadow(0 0 4px var(--success)); }
.service-icon.offline { fill: var(--danger); filter: drop-shadow(0 0 4px var(--danger-glow)); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.uptime-meter {
  display: inline-block;
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--success) 0%, var(--success) 60%, var(--accent) 80%, var(--danger) 100%);
  margin-right: 6px;
  vertical-align: middle;
  opacity: 0.85;
}
