:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2229;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-dim: #9aa1ae;
  --accent: #3aa0ff;
  --accent-hover: #5cb3ff;
  --danger: #ff5c5c;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
header h1 .dim { color: var(--text-dim); font-weight: 500; }

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  flex: 1;
  min-width: 200px;
}

.header-actions { margin-left: auto; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #262b34; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06131f; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }

#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  flex-shrink: 0;
}

#site-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.site-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.site-card:hover { border-color: var(--accent); }
.site-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.site-card .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.site-card .callsign { font-weight: 700; color: var(--accent); font-size: 13px; }
.site-card .name { font-weight: 600; font-size: 14px; margin: 2px 0 4px; }
.site-card .meta { color: var(--text-dim); font-size: 12px; line-height: 1.5; }

.status-pill {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
}
.status-pending { background: #3a3520; color: #e0c96a; }
.status-running { background: #1f3450; color: #6ab0ff; }
.status-done { background: #1e3a24; color: #6adf82; }
.status-error { background: #3a1e1e; color: #ff8a8a; }

.error-detail {
  margin-top: 6px;
  padding: 6px 8px;
  background: #241414;
  border: 1px solid #4a2222;
  border-radius: 6px;
  color: #ff9d9d;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}

main { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b0d11; }

#legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: rgba(23, 26, 33, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  z-index: 1000;
}
.legend-title { font-weight: 700; margin-bottom: 6px; color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
.legend-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.hidden { display: none !important; }

#modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  padding: 20px;
}
#modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
#modal h2 { margin: 0 0 4px; }
.modal-hint { color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }

#site-form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); }
input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.error { color: var(--danger); font-size: 13px; }

.popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; }

@media (max-width: 720px) {
  #layout { flex-direction: column; }
  #sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .grid2 { grid-template-columns: 1fr; }
}
